2012-12-24 18:14:43 +00:00
|
|
|
// WL_AGENT.C
|
|
|
|
|
|
|
|
#include "wl_def.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================================================================
|
|
|
|
|
|
|
|
LOCAL CONSTANTS
|
|
|
|
|
|
|
|
=============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define MAXMOUSETURN 10
|
|
|
|
|
|
|
|
|
|
|
|
#define MOVESCALE 150l
|
|
|
|
#define BACKMOVESCALE 100l
|
|
|
|
#define ANGLESCALE 20
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================================================================
|
|
|
|
|
|
|
|
GLOBAL VARIABLES
|
|
|
|
|
|
|
|
=============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
/* player state info */
|
2012-12-24 18:14:43 +00:00
|
|
|
int32_t thrustspeed;
|
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
/* player coordinates scaled to unsigned */
|
|
|
|
word plux,pluy;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
|
|
|
short anglefrac;
|
|
|
|
|
|
|
|
objtype *LastAttacker;
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================================================================
|
|
|
|
|
|
|
|
LOCAL VARIABLES
|
|
|
|
|
|
|
|
=============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
void T_Player (objtype *ob);
|
|
|
|
void T_Attack (objtype *ob);
|
|
|
|
|
|
|
|
statetype s_player = {false,0,0,(statefunc) T_Player,NULL,NULL};
|
|
|
|
statetype s_attack = {false,0,0,(statefunc) T_Attack,NULL,NULL};
|
|
|
|
|
|
|
|
struct atkinf
|
|
|
|
{
|
2015-03-27 14:42:13 +00:00
|
|
|
int8_t tics,attack,frame; /* attack is 1 for gun, 2 for knife */
|
2012-12-24 18:14:43 +00:00
|
|
|
} attackinfo[4][14] =
|
|
|
|
{
|
|
|
|
{ {6,0,1},{6,2,2},{6,0,3},{6,-1,4} },
|
|
|
|
{ {6,0,1},{6,1,2},{6,0,3},{6,-1,4} },
|
|
|
|
{ {6,0,1},{6,1,2},{6,3,3},{6,-1,4} },
|
|
|
|
{ {6,0,1},{6,1,2},{6,4,3},{6,-1,4} },
|
|
|
|
};
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
void Attack (void);
|
|
|
|
void Use (void);
|
|
|
|
void Search (objtype *ob);
|
|
|
|
void SelectWeapon (void);
|
|
|
|
void SelectItem (void);
|
|
|
|
|
|
|
|
boolean TryMove (objtype *ob);
|
|
|
|
void T_Player (objtype *ob);
|
|
|
|
|
|
|
|
void ClipMove (objtype *ob, int32_t xmove, int32_t ymove);
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================================================================
|
|
|
|
|
|
|
|
CONTROL STUFF
|
|
|
|
|
|
|
|
=============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
======================
|
|
|
|
=
|
|
|
|
= CheckWeaponChange
|
|
|
|
=
|
|
|
|
= Keys 1-4 change weapons
|
|
|
|
=
|
|
|
|
======================
|
|
|
|
*/
|
|
|
|
|
2016-03-23 23:17:23 +00:00
|
|
|
static void CheckWeaponChange (void)
|
2012-12-24 18:14:43 +00:00
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
int newWeapon = -1;
|
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
/* must use knife with no ammo */
|
|
|
|
if (!gamestate.ammo)
|
2015-03-26 11:33:55 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
if(buttonstate[bt_nextweapon] && !buttonheld[bt_nextweapon])
|
|
|
|
{
|
|
|
|
newWeapon = gamestate.weapon + 1;
|
|
|
|
if(newWeapon > gamestate.bestweapon) newWeapon = 0;
|
|
|
|
}
|
|
|
|
else if(buttonstate[bt_prevweapon] && !buttonheld[bt_prevweapon])
|
|
|
|
{
|
|
|
|
newWeapon = gamestate.weapon - 1;
|
|
|
|
if(newWeapon < 0) newWeapon = gamestate.bestweapon;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
unsigned i;
|
|
|
|
for(i = wp_knife; i <= gamestate.bestweapon; i++)
|
|
|
|
{
|
|
|
|
if (buttonstate[bt_readyknife + i - wp_knife])
|
|
|
|
{
|
|
|
|
newWeapon = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(newWeapon != -1)
|
|
|
|
{
|
|
|
|
gamestate.weapon = gamestate.chosenweapon = (weapontype) newWeapon;
|
|
|
|
DrawWeapon();
|
|
|
|
}
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=======================
|
|
|
|
=
|
|
|
|
= ControlMovement
|
|
|
|
=
|
|
|
|
= Takes controlx,controly, and buttonstate[bt_strafe]
|
|
|
|
=
|
|
|
|
= Changes the player's angle and position
|
|
|
|
=
|
|
|
|
= There is an angle hack because when going 70 fps, the roundoff becomes
|
|
|
|
= significant
|
|
|
|
=
|
|
|
|
=======================
|
|
|
|
*/
|
|
|
|
|
2016-03-23 23:17:23 +00:00
|
|
|
static void ControlMovement (objtype *ob)
|
2012-12-24 18:14:43 +00:00
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
int32_t oldx,oldy;
|
|
|
|
int angle;
|
|
|
|
int angleunits;
|
|
|
|
|
|
|
|
thrustspeed = 0;
|
|
|
|
|
|
|
|
oldx = player->x;
|
|
|
|
oldy = player->y;
|
|
|
|
|
2015-04-28 05:00:17 +00:00
|
|
|
(void)oldx;
|
|
|
|
(void)oldy;
|
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
if(buttonstate[bt_strafeleft])
|
|
|
|
{
|
|
|
|
angle = ob->angle + ANGLES/4;
|
|
|
|
if(angle >= ANGLES)
|
|
|
|
angle -= ANGLES;
|
|
|
|
if(buttonstate[bt_run])
|
|
|
|
Thrust(angle, RUNMOVE * MOVESCALE * tics);
|
|
|
|
else
|
|
|
|
Thrust(angle, BASEMOVE * MOVESCALE * tics);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(buttonstate[bt_straferight])
|
|
|
|
{
|
|
|
|
angle = ob->angle - ANGLES/4;
|
|
|
|
if(angle < 0)
|
|
|
|
angle += ANGLES;
|
|
|
|
if(buttonstate[bt_run])
|
|
|
|
Thrust(angle, RUNMOVE * MOVESCALE * tics );
|
|
|
|
else
|
|
|
|
Thrust(angle, BASEMOVE * MOVESCALE * tics);
|
|
|
|
}
|
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
/* side to side move */
|
2015-03-26 11:33:55 +00:00
|
|
|
if (buttonstate[bt_strafe])
|
|
|
|
{
|
2015-03-27 14:42:13 +00:00
|
|
|
/* strafing */
|
2015-03-26 11:33:55 +00:00
|
|
|
if (controlx > 0)
|
|
|
|
{
|
|
|
|
angle = ob->angle - ANGLES/4;
|
|
|
|
if (angle < 0)
|
2012-12-24 18:14:43 +00:00
|
|
|
angle += ANGLES;
|
2015-03-27 14:42:13 +00:00
|
|
|
Thrust (angle,controlx*MOVESCALE); /* move to left */
|
2015-03-26 11:33:55 +00:00
|
|
|
}
|
|
|
|
else if (controlx < 0)
|
|
|
|
{
|
|
|
|
angle = ob->angle + ANGLES/4;
|
|
|
|
if (angle >= ANGLES)
|
2012-12-24 18:14:43 +00:00
|
|
|
angle -= ANGLES;
|
2015-03-27 14:42:13 +00:00
|
|
|
Thrust (angle,-controlx*MOVESCALE); /* move to right */
|
2015-03-26 11:33:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-03-27 14:42:13 +00:00
|
|
|
/* not strafing */
|
2015-03-26 11:33:55 +00:00
|
|
|
anglefrac += controlx;
|
|
|
|
angleunits = anglefrac/ANGLESCALE;
|
|
|
|
anglefrac -= angleunits*ANGLESCALE;
|
|
|
|
ob->angle -= angleunits;
|
|
|
|
|
|
|
|
if (ob->angle >= ANGLES)
|
|
|
|
ob->angle -= ANGLES;
|
|
|
|
if (ob->angle < 0)
|
|
|
|
ob->angle += ANGLES;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
/* forward/backwards move */
|
2015-03-26 11:33:55 +00:00
|
|
|
if (controly < 0)
|
2015-03-27 14:42:13 +00:00
|
|
|
Thrust (ob->angle,-controly*MOVESCALE); /* move forwards */
|
2015-03-26 11:33:55 +00:00
|
|
|
else if (controly > 0)
|
|
|
|
{
|
|
|
|
angle = ob->angle + ANGLES/2;
|
|
|
|
if (angle >= ANGLES)
|
|
|
|
angle -= ANGLES;
|
2015-03-27 14:42:13 +00:00
|
|
|
Thrust (angle,controly*BACKMOVESCALE); /* move backwards */
|
2015-03-26 11:33:55 +00:00
|
|
|
}
|
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
/* watching the BJ actor */
|
|
|
|
if (gamestate.victoryflag)
|
2015-03-26 11:33:55 +00:00
|
|
|
return;
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================================================================
|
|
|
|
|
|
|
|
STATUS WINDOW STUFF
|
|
|
|
|
|
|
|
=============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
=
|
|
|
|
= StatusDrawPic
|
|
|
|
=
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
|
|
|
|
void StatusDrawPic (unsigned x, unsigned y, unsigned picnum)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
LatchDrawPicScaledCoord ((screenWidth-scaleFactor*320)/16 + scaleFactor*x,
|
|
|
|
screenHeight-scaleFactor*(STATUSLINES-y),picnum);
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void StatusDrawFace(unsigned picnum)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
StatusDrawPic(17, 4, picnum);
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
=
|
|
|
|
= DrawFace
|
|
|
|
=
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
|
|
|
|
void DrawFace (void)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
if(viewsize == 21 && ingame)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (SD_SoundPlaying() == GETGATLINGSND)
|
|
|
|
StatusDrawFace(GOTGATLINGPIC);
|
|
|
|
else if (gamestate.health)
|
|
|
|
{
|
2012-12-24 18:14:43 +00:00
|
|
|
#ifdef SPEAR
|
2015-03-26 11:33:55 +00:00
|
|
|
if (godmode)
|
|
|
|
StatusDrawFace(GODMODEFACE1PIC+gamestate.faceframe);
|
|
|
|
else
|
2012-12-24 18:14:43 +00:00
|
|
|
#endif
|
2015-03-26 11:33:55 +00:00
|
|
|
StatusDrawFace(FACE1APIC+3*((100-gamestate.health)/16)+gamestate.faceframe);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-12-24 18:14:43 +00:00
|
|
|
#ifndef SPEAR
|
2015-03-26 11:33:55 +00:00
|
|
|
if (LastAttacker && LastAttacker->obclass == needleobj)
|
|
|
|
StatusDrawFace(MUTANTBJPIC);
|
|
|
|
else
|
2012-12-24 18:14:43 +00:00
|
|
|
#endif
|
2015-03-26 11:33:55 +00:00
|
|
|
StatusDrawFace(FACE8APIC);
|
|
|
|
}
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
=
|
|
|
|
= UpdateFace
|
|
|
|
=
|
|
|
|
= Calls draw face if time to change
|
|
|
|
=
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
int facecount = 0;
|
|
|
|
int facetimes = 0;
|
|
|
|
|
|
|
|
void UpdateFace (void)
|
|
|
|
{
|
2015-03-27 14:42:13 +00:00
|
|
|
/* don't make demo depend on sound playback */
|
2015-03-26 11:33:55 +00:00
|
|
|
if(demoplayback || demorecord)
|
|
|
|
{
|
|
|
|
if(facetimes > 0)
|
|
|
|
{
|
|
|
|
facetimes--;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(SD_SoundPlaying() == GETGATLINGSND)
|
|
|
|
return;
|
|
|
|
|
|
|
|
facecount += tics;
|
|
|
|
if (facecount > US_RndT())
|
|
|
|
{
|
|
|
|
gamestate.faceframe = (US_RndT()>>6);
|
|
|
|
if (gamestate.faceframe==3)
|
|
|
|
gamestate.faceframe = 1;
|
|
|
|
|
|
|
|
facecount = 0;
|
|
|
|
DrawFace ();
|
|
|
|
}
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
=
|
|
|
|
= LatchNumber
|
|
|
|
=
|
|
|
|
= right justifies and pads with blanks
|
|
|
|
=
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void LatchNumber (int x, int y, unsigned width, int32_t number)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
unsigned length,c;
|
|
|
|
char str[20];
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
ltoa (number,str,10);
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
length = (unsigned) strlen (str);
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
while (length<width)
|
|
|
|
{
|
|
|
|
StatusDrawPic (x,y,N_BLANKPIC);
|
|
|
|
x++;
|
|
|
|
width--;
|
|
|
|
}
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
c = length <= width ? 0 : length-width;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
while (c<length)
|
|
|
|
{
|
|
|
|
StatusDrawPic (x,y,str[c]-'0'+ N_0PIC);
|
|
|
|
x++;
|
|
|
|
c++;
|
|
|
|
}
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
=
|
|
|
|
= DrawHealth
|
|
|
|
=
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
void DrawHealth (void)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
if(viewsize == 21 && ingame)
|
|
|
|
return;
|
|
|
|
LatchNumber (21,16,3,gamestate.health);
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
=
|
|
|
|
= TakeDamage
|
|
|
|
=
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
void TakeDamage (int points,objtype *attacker)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
LastAttacker = attacker;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
if (gamestate.victoryflag)
|
|
|
|
return;
|
2016-03-23 23:55:30 +00:00
|
|
|
if (gamestate.difficulty == GD_BABY)
|
2015-03-26 11:33:55 +00:00
|
|
|
points>>=2;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
if (!godmode)
|
|
|
|
gamestate.health -= points;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
if (gamestate.health<=0)
|
|
|
|
{
|
|
|
|
gamestate.health = 0;
|
2015-03-28 12:27:05 +00:00
|
|
|
playstate = EX_DIED;
|
2015-03-26 11:33:55 +00:00
|
|
|
killerobj = attacker;
|
|
|
|
}
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
if (godmode != 2)
|
|
|
|
StartDamageFlash (points);
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
DrawHealth ();
|
|
|
|
DrawFace ();
|
2012-12-24 18:14:43 +00:00
|
|
|
|
|
|
|
#ifdef SPEAR
|
2015-03-27 14:42:13 +00:00
|
|
|
/* MAKE BJ'S EYES BUG IF MAJOR DAMAGE! */
|
2015-03-26 11:33:55 +00:00
|
|
|
if (points > 30 && gamestate.health!=0 && !godmode && viewsize != 21)
|
|
|
|
{
|
|
|
|
StatusDrawFace(BJOUCHPIC);
|
|
|
|
facecount = 0;
|
|
|
|
}
|
2012-12-24 18:14:43 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
=
|
|
|
|
= HealSelf
|
|
|
|
=
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
void HealSelf (int points)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
gamestate.health += points;
|
|
|
|
if (gamestate.health>100)
|
|
|
|
gamestate.health = 100;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
DrawHealth ();
|
|
|
|
DrawFace ();
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
=
|
|
|
|
= DrawLevel
|
|
|
|
=
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
void DrawLevel (void)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
if(viewsize == 21 && ingame)
|
|
|
|
return;
|
2012-12-24 18:14:43 +00:00
|
|
|
#ifdef SPEAR
|
2015-03-26 11:33:55 +00:00
|
|
|
if (gamestate.mapon == 20)
|
|
|
|
LatchNumber (2,16,2,18);
|
|
|
|
else
|
2012-12-24 18:14:43 +00:00
|
|
|
#endif
|
2015-03-26 11:33:55 +00:00
|
|
|
LatchNumber (2,16,2,gamestate.mapon+1);
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
=
|
|
|
|
= DrawLives
|
|
|
|
=
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
void DrawLives (void)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
if(viewsize == 21 && ingame)
|
|
|
|
return;
|
|
|
|
LatchNumber (14,16,1,gamestate.lives);
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
=
|
|
|
|
= GiveExtraMan
|
|
|
|
=
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
void GiveExtraMan (void)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
if (gamestate.lives<9)
|
|
|
|
gamestate.lives++;
|
|
|
|
DrawLives ();
|
|
|
|
SD_PlaySound (BONUS1UPSND);
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
=
|
|
|
|
= DrawScore
|
|
|
|
=
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
void DrawScore (void)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
if(viewsize == 21 && ingame)
|
|
|
|
return;
|
|
|
|
LatchNumber (6,16,6,gamestate.score);
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
=
|
|
|
|
= GivePoints
|
|
|
|
=
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
void GivePoints (int32_t points)
|
|
|
|
{
|
|
|
|
gamestate.score += points;
|
|
|
|
while (gamestate.score >= gamestate.nextextra)
|
|
|
|
{
|
|
|
|
gamestate.nextextra += EXTRAPOINTS;
|
|
|
|
GiveExtraMan ();
|
|
|
|
}
|
|
|
|
DrawScore ();
|
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
=
|
|
|
|
= DrawWeapon
|
|
|
|
=
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
|
|
|
|
void DrawWeapon (void)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
if(viewsize == 21 && ingame)
|
|
|
|
return;
|
|
|
|
StatusDrawPic (32,8,KNIFEPIC+gamestate.weapon);
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
=
|
|
|
|
= DrawKeys
|
|
|
|
=
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
|
|
|
|
void DrawKeys (void)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
if(viewsize == 21 && ingame)
|
|
|
|
return;
|
|
|
|
if (gamestate.keys & 1)
|
|
|
|
StatusDrawPic (30,4,GOLDKEYPIC);
|
|
|
|
else
|
|
|
|
StatusDrawPic (30,4,NOKEYPIC);
|
|
|
|
|
|
|
|
if (gamestate.keys & 2)
|
|
|
|
StatusDrawPic (30,20,SILVERKEYPIC);
|
|
|
|
else
|
|
|
|
StatusDrawPic (30,20,NOKEYPIC);
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
=
|
|
|
|
= GiveWeapon
|
|
|
|
=
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
|
|
|
|
void GiveWeapon (int weapon)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
GiveAmmo (6);
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
if (gamestate.bestweapon<weapon)
|
|
|
|
gamestate.bestweapon = gamestate.weapon
|
|
|
|
= gamestate.chosenweapon = (weapontype) weapon;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
DrawWeapon ();
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
=
|
|
|
|
= DrawAmmo
|
|
|
|
=
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
void DrawAmmo (void)
|
|
|
|
{
|
|
|
|
if(viewsize == 21 && ingame) return;
|
|
|
|
LatchNumber (27,16,2,gamestate.ammo);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
=
|
|
|
|
= GiveAmmo
|
|
|
|
=
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
void GiveAmmo (int ammo)
|
|
|
|
{
|
2015-03-27 14:42:13 +00:00
|
|
|
/* knife was out */
|
|
|
|
if (!gamestate.ammo)
|
|
|
|
{
|
|
|
|
if (!gamestate.attackframe)
|
|
|
|
{
|
|
|
|
gamestate.weapon = gamestate.chosenweapon;
|
|
|
|
DrawWeapon ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gamestate.ammo += ammo;
|
|
|
|
if (gamestate.ammo > 99)
|
|
|
|
gamestate.ammo = 99;
|
|
|
|
DrawAmmo ();
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
==================
|
|
|
|
=
|
|
|
|
= GiveKey
|
|
|
|
=
|
|
|
|
==================
|
|
|
|
*/
|
|
|
|
|
|
|
|
void GiveKey (int key)
|
|
|
|
{
|
|
|
|
gamestate.keys |= (1<<key);
|
|
|
|
DrawKeys ();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================================================================
|
|
|
|
|
|
|
|
MOVEMENT
|
|
|
|
|
|
|
|
=============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
=
|
|
|
|
= GetBonus
|
|
|
|
=
|
|
|
|
===================
|
|
|
|
*/
|
|
|
|
void GetBonus (statobj_t *check)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
switch (check->itemnumber)
|
|
|
|
{
|
|
|
|
case bo_firstaid:
|
|
|
|
if (gamestate.health == 100)
|
|
|
|
return;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
SD_PlaySound (HEALTH2SND);
|
|
|
|
HealSelf (25);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case bo_key1:
|
|
|
|
case bo_key2:
|
|
|
|
case bo_key3:
|
|
|
|
case bo_key4:
|
|
|
|
GiveKey (check->itemnumber - bo_key1);
|
|
|
|
SD_PlaySound (GETKEYSND);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case bo_cross:
|
|
|
|
SD_PlaySound (BONUS1SND);
|
|
|
|
GivePoints (100);
|
|
|
|
gamestate.treasurecount++;
|
|
|
|
break;
|
|
|
|
case bo_chalice:
|
|
|
|
SD_PlaySound (BONUS2SND);
|
|
|
|
GivePoints (500);
|
|
|
|
gamestate.treasurecount++;
|
|
|
|
break;
|
|
|
|
case bo_bible:
|
|
|
|
SD_PlaySound (BONUS3SND);
|
|
|
|
GivePoints (1000);
|
|
|
|
gamestate.treasurecount++;
|
|
|
|
break;
|
|
|
|
case bo_crown:
|
|
|
|
SD_PlaySound (BONUS4SND);
|
|
|
|
GivePoints (5000);
|
|
|
|
gamestate.treasurecount++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case bo_clip:
|
|
|
|
if (gamestate.ammo == 99)
|
|
|
|
return;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
SD_PlaySound (GETAMMOSND);
|
|
|
|
GiveAmmo (8);
|
|
|
|
break;
|
|
|
|
case bo_clip2:
|
|
|
|
if (gamestate.ammo == 99)
|
|
|
|
return;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
SD_PlaySound (GETAMMOSND);
|
|
|
|
GiveAmmo (4);
|
|
|
|
break;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
|
|
|
#ifdef SPEAR
|
2015-03-26 11:33:55 +00:00
|
|
|
case bo_25clip:
|
|
|
|
if (gamestate.ammo == 99)
|
|
|
|
return;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
SD_PlaySound (GETAMMOBOXSND);
|
|
|
|
GiveAmmo (25);
|
|
|
|
break;
|
2012-12-24 18:14:43 +00:00
|
|
|
#endif
|
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
case bo_machinegun:
|
|
|
|
SD_PlaySound (GETMACHINESND);
|
|
|
|
GiveWeapon (wp_machinegun);
|
|
|
|
break;
|
|
|
|
case bo_chaingun:
|
|
|
|
SD_PlaySound (GETGATLINGSND);
|
|
|
|
facetimes = 38;
|
|
|
|
GiveWeapon (wp_chaingun);
|
|
|
|
|
|
|
|
if(viewsize != 21)
|
|
|
|
StatusDrawFace (GOTGATLINGPIC);
|
|
|
|
facecount = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case bo_fullheal:
|
|
|
|
SD_PlaySound (BONUS1UPSND);
|
|
|
|
HealSelf (99);
|
|
|
|
GiveAmmo (25);
|
|
|
|
GiveExtraMan ();
|
|
|
|
gamestate.treasurecount++;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case bo_food:
|
|
|
|
if (gamestate.health == 100)
|
|
|
|
return;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
SD_PlaySound (HEALTH1SND);
|
|
|
|
HealSelf (10);
|
|
|
|
break;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
case bo_alpo:
|
|
|
|
if (gamestate.health == 100)
|
|
|
|
return;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
SD_PlaySound (HEALTH1SND);
|
|
|
|
HealSelf (4);
|
|
|
|
break;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
case bo_gibs:
|
|
|
|
if (gamestate.health >10)
|
|
|
|
return;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
SD_PlaySound (SLURPIESND);
|
|
|
|
HealSelf (1);
|
|
|
|
break;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
|
|
|
#ifdef SPEAR
|
2015-03-26 11:33:55 +00:00
|
|
|
case bo_spear:
|
|
|
|
spearflag = true;
|
|
|
|
spearx = player->x;
|
|
|
|
speary = player->y;
|
|
|
|
spearangle = player->angle;
|
2015-03-28 12:27:05 +00:00
|
|
|
playstate = EX_COMPLETED;
|
2012-12-24 18:14:43 +00:00
|
|
|
#endif
|
2015-03-26 11:33:55 +00:00
|
|
|
}
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
StartBonusFlash ();
|
2015-03-27 14:42:13 +00:00
|
|
|
check->shapenum = -1; /* remove from list */
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
=
|
|
|
|
= TryMove
|
|
|
|
=
|
|
|
|
= returns true if move ok
|
|
|
|
= debug: use pointers to optimize
|
|
|
|
===================
|
|
|
|
*/
|
|
|
|
|
|
|
|
boolean TryMove (objtype *ob)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
int xl,yl,xh,yh,x,y;
|
|
|
|
objtype *check;
|
|
|
|
int32_t deltax,deltay;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
xl = (ob->x-PLAYERSIZE) >>TILESHIFT;
|
|
|
|
yl = (ob->y-PLAYERSIZE) >>TILESHIFT;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
xh = (ob->x+PLAYERSIZE) >>TILESHIFT;
|
|
|
|
yh = (ob->y+PLAYERSIZE) >>TILESHIFT;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
|
|
|
#define PUSHWALLMINDIST PLAYERSIZE
|
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
/* check for solid walls */
|
2015-03-26 11:33:55 +00:00
|
|
|
for (y=yl;y<=yh;y++)
|
|
|
|
{
|
|
|
|
for (x=xl;x<=xh;x++)
|
|
|
|
{
|
|
|
|
check = actorat[x][y];
|
|
|
|
if (check && !ISPOINTER(check))
|
|
|
|
{
|
2015-03-27 14:42:13 +00:00
|
|
|
/* back of moving pushwall? */
|
|
|
|
if(tilemap[x][y]==64 && x==pwallx && y==pwally)
|
2012-12-24 18:14:43 +00:00
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
switch(pwalldir)
|
|
|
|
{
|
2016-03-23 23:55:30 +00:00
|
|
|
case DI_NORTH:
|
2015-03-26 11:33:55 +00:00
|
|
|
if(ob->y-PUSHWALLMINDIST<=(pwally<<TILESHIFT)+((63-pwallpos)<<10))
|
|
|
|
return false;
|
|
|
|
break;
|
2016-03-23 23:55:30 +00:00
|
|
|
case DI_WEST:
|
2015-03-26 11:33:55 +00:00
|
|
|
if(ob->x-PUSHWALLMINDIST<=(pwallx<<TILESHIFT)+((63-pwallpos)<<10))
|
|
|
|
return false;
|
|
|
|
break;
|
2016-03-23 23:55:30 +00:00
|
|
|
case DI_EAST:
|
2015-03-26 11:33:55 +00:00
|
|
|
if(ob->x+PUSHWALLMINDIST>=(pwallx<<TILESHIFT)+(pwallpos<<10))
|
|
|
|
return false;
|
|
|
|
break;
|
2016-03-23 23:55:30 +00:00
|
|
|
case DI_SOUTH:
|
2015-03-26 11:33:55 +00:00
|
|
|
if(ob->y+PUSHWALLMINDIST>=(pwally<<TILESHIFT)+(pwallpos<<10))
|
|
|
|
return false;
|
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
2015-03-26 11:33:55 +00:00
|
|
|
else return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
/* check for actors */
|
2015-03-26 11:33:55 +00:00
|
|
|
if (yl>0)
|
|
|
|
yl--;
|
|
|
|
if (yh<MAPSIZE-1)
|
|
|
|
yh++;
|
|
|
|
if (xl>0)
|
|
|
|
xl--;
|
|
|
|
if (xh<MAPSIZE-1)
|
|
|
|
xh++;
|
|
|
|
|
|
|
|
for (y=yl;y<=yh;y++)
|
|
|
|
{
|
|
|
|
for (x=xl;x<=xh;x++)
|
|
|
|
{
|
|
|
|
check = actorat[x][y];
|
|
|
|
if (ISPOINTER(check) && check != player && (check->flags & FL_SHOOTABLE) )
|
|
|
|
{
|
|
|
|
deltax = ob->x - check->x;
|
|
|
|
if (deltax < -MINACTORDIST || deltax > MINACTORDIST)
|
|
|
|
continue;
|
|
|
|
deltay = ob->y - check->y;
|
|
|
|
if (deltay < -MINACTORDIST || deltay > MINACTORDIST)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
=
|
|
|
|
= ClipMove
|
|
|
|
=
|
|
|
|
===================
|
|
|
|
*/
|
|
|
|
|
|
|
|
void ClipMove (objtype *ob, int32_t xmove, int32_t ymove)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
int32_t basex,basey;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
basex = ob->x;
|
|
|
|
basey = ob->y;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
ob->x = basex+xmove;
|
|
|
|
ob->y = basey+ymove;
|
|
|
|
if (TryMove (ob))
|
|
|
|
return;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-25 10:11:12 +00:00
|
|
|
#if 0
|
2015-03-27 14:42:13 +00:00
|
|
|
/* walk through walls */
|
2015-03-26 11:33:55 +00:00
|
|
|
if (noclip && ob->x > 2*TILEGLOBAL && ob->y > 2*TILEGLOBAL
|
|
|
|
&& ob->x < (((int32_t)(mapwidth-1))<<TILESHIFT)
|
|
|
|
&& ob->y < (((int32_t)(mapheight-1))<<TILESHIFT) )
|
2015-03-27 14:42:13 +00:00
|
|
|
return;
|
2012-12-24 18:14:43 +00:00
|
|
|
#endif
|
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
if (!SD_SoundPlaying())
|
|
|
|
SD_PlaySound (HITWALLSND);
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
ob->x = basex+xmove;
|
|
|
|
ob->y = basey;
|
|
|
|
if (TryMove (ob))
|
|
|
|
return;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
ob->x = basex;
|
|
|
|
ob->y = basey+ymove;
|
|
|
|
if (TryMove (ob))
|
|
|
|
return;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
ob->x = basex;
|
|
|
|
ob->y = basey;
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//==========================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
=
|
|
|
|
= VictoryTile
|
|
|
|
=
|
|
|
|
===================
|
|
|
|
*/
|
|
|
|
|
|
|
|
void VictoryTile (void)
|
|
|
|
{
|
|
|
|
#ifndef SPEAR
|
|
|
|
SpawnBJVictory ();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
gamestate.victoryflag = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
===================
|
|
|
|
=
|
|
|
|
= Thrust
|
|
|
|
=
|
|
|
|
===================
|
|
|
|
*/
|
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
/* For player movement in demos exactly as
|
|
|
|
* in the original Wolf3D v1.4 source code */
|
2012-12-24 18:14:43 +00:00
|
|
|
static fixed FixedByFracOrig(fixed a, fixed b)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
int sign = 0;
|
|
|
|
if(b == 65536)
|
|
|
|
b = 65535;
|
|
|
|
else
|
|
|
|
if(b == -65536) b = 65535, sign = 1;
|
|
|
|
else
|
|
|
|
if(b < 0) b = (-b), sign = 1;
|
|
|
|
|
|
|
|
if(a < 0)
|
|
|
|
{
|
|
|
|
a = -a;
|
|
|
|
sign = !sign;
|
|
|
|
}
|
|
|
|
fixed res = (fixed)(((int64_t) a * b) >> 16);
|
|
|
|
|
|
|
|
if(sign)
|
|
|
|
res = -res;
|
|
|
|
return res;
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Thrust (int angle, int32_t speed)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
int32_t xmove,ymove;
|
|
|
|
unsigned offset;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
|
|
|
#ifdef SPEAR
|
2015-03-27 14:42:13 +00:00
|
|
|
/* ZERO FUNNY COUNTER IF MOVED! */
|
2015-03-26 11:33:55 +00:00
|
|
|
if (speed)
|
|
|
|
funnyticount = 0;
|
2012-12-24 18:14:43 +00:00
|
|
|
#endif
|
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
thrustspeed += speed;
|
2015-03-27 14:42:13 +00:00
|
|
|
|
|
|
|
/* moving bounds speed */
|
2015-03-26 11:33:55 +00:00
|
|
|
if (speed >= MINDIST*2)
|
|
|
|
speed = MINDIST*2-1;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
xmove = DEMOCHOOSE_ORIG_SDL(
|
|
|
|
FixedByFracOrig(speed, costable[angle]),
|
|
|
|
FixedMul(speed,costable[angle]));
|
|
|
|
ymove = DEMOCHOOSE_ORIG_SDL(
|
|
|
|
-FixedByFracOrig(speed, sintable[angle]),
|
|
|
|
-FixedMul(speed,sintable[angle]));
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
ClipMove(player,xmove,ymove);
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
/* scale to tile values */
|
|
|
|
player->tilex = (short)(player->x >> TILESHIFT);
|
2015-03-26 11:33:55 +00:00
|
|
|
player->tiley = (short)(player->y >> TILESHIFT);
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
offset = (player->tiley<<mapshift)+player->tilex;
|
|
|
|
player->areanumber = *(mapsegs[0] + offset) -AREATILE;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
if (*(mapsegs[1] + offset) == EXITTILE)
|
|
|
|
VictoryTile ();
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================================================================
|
|
|
|
|
|
|
|
ACTIONS
|
|
|
|
|
|
|
|
=============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
=
|
|
|
|
= Cmd_Fire
|
|
|
|
=
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Cmd_Fire (void)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
buttonheld[bt_attack] = true;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
gamestate.weaponframe = 0;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
player->state = &s_attack;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
gamestate.attackframe = 0;
|
|
|
|
gamestate.attackcount =
|
|
|
|
attackinfo[gamestate.weapon][gamestate.attackframe].tics;
|
|
|
|
gamestate.weaponframe =
|
|
|
|
attackinfo[gamestate.weapon][gamestate.attackframe].frame;
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
=
|
|
|
|
= Cmd_Use
|
|
|
|
=
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
void Cmd_Use (void)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
int checkx,checky,doornum,dir;
|
|
|
|
boolean elevatorok;
|
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
/* find which cardinal direction the player is facing */
|
2015-03-26 11:33:55 +00:00
|
|
|
if (player->angle < ANGLES/8 || player->angle > 7*ANGLES/8)
|
|
|
|
{
|
2016-03-23 23:55:30 +00:00
|
|
|
checkx = player->tilex + 1;
|
|
|
|
checky = player->tiley;
|
|
|
|
dir = DI_EAST;
|
2015-03-26 11:33:55 +00:00
|
|
|
elevatorok = true;
|
|
|
|
}
|
|
|
|
else if (player->angle < 3*ANGLES/8)
|
|
|
|
{
|
|
|
|
checkx = player->tilex;
|
|
|
|
checky = player->tiley-1;
|
2016-03-23 23:55:30 +00:00
|
|
|
dir = DI_NORTH;
|
2015-03-26 11:33:55 +00:00
|
|
|
elevatorok = false;
|
|
|
|
}
|
|
|
|
else if (player->angle < 5*ANGLES/8)
|
|
|
|
{
|
|
|
|
checkx = player->tilex - 1;
|
|
|
|
checky = player->tiley;
|
2016-03-23 23:55:30 +00:00
|
|
|
dir = DI_WEST;
|
2015-03-26 11:33:55 +00:00
|
|
|
elevatorok = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
checkx = player->tilex;
|
|
|
|
checky = player->tiley + 1;
|
2016-03-23 23:55:30 +00:00
|
|
|
dir = DI_SOUTH;
|
2015-03-26 11:33:55 +00:00
|
|
|
elevatorok = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
doornum = tilemap[checkx][checky];
|
|
|
|
if (*(mapsegs[1]+(checky<<mapshift)+checkx) == PUSHABLETILE)
|
|
|
|
{
|
2015-03-27 14:42:13 +00:00
|
|
|
/* pushable wall */
|
2015-03-26 11:33:55 +00:00
|
|
|
PushWall (checkx,checky,dir);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!buttonheld[bt_use] && doornum == ELEVATORTILE && elevatorok)
|
|
|
|
{
|
2015-03-27 14:42:13 +00:00
|
|
|
/* use elevator */
|
2015-03-26 11:33:55 +00:00
|
|
|
buttonheld[bt_use] = true;
|
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
tilemap[checkx][checky]++; /* flip switch */
|
2015-03-26 11:33:55 +00:00
|
|
|
if (*(mapsegs[0]+(player->tiley<<mapshift)+player->tilex) == ALTELEVATORTILE)
|
2015-03-28 12:27:05 +00:00
|
|
|
playstate = EX_SECRETLEVEL;
|
2015-03-26 11:33:55 +00:00
|
|
|
else
|
2015-03-28 12:27:05 +00:00
|
|
|
playstate = EX_COMPLETED;
|
2015-03-26 11:33:55 +00:00
|
|
|
SD_PlaySound (LEVELDONESND);
|
|
|
|
SD_WaitSoundDone();
|
|
|
|
}
|
|
|
|
else if (!buttonheld[bt_use] && doornum & 0x80)
|
|
|
|
{
|
|
|
|
buttonheld[bt_use] = true;
|
|
|
|
OperateDoor (doornum & ~0x80);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
SD_PlaySound (DONOTHINGSND);
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
=============================================================================
|
|
|
|
|
|
|
|
PLAYER CONTROL
|
|
|
|
|
|
|
|
=============================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
=
|
|
|
|
= SpawnPlayer
|
|
|
|
=
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
void SpawnPlayer (int tilex, int tiley, int dir)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
player->obclass = playerobj;
|
|
|
|
player->active = ac_yes;
|
|
|
|
player->tilex = tilex;
|
|
|
|
player->tiley = tiley;
|
|
|
|
player->areanumber = (byte) *(mapsegs[0]+(player->tiley<<mapshift)+player->tilex);
|
|
|
|
player->x = ((int32_t)tilex<<TILESHIFT)+TILEGLOBAL/2;
|
|
|
|
player->y = ((int32_t)tiley<<TILESHIFT)+TILEGLOBAL/2;
|
|
|
|
player->state = &s_player;
|
|
|
|
player->angle = (1-dir)*90;
|
|
|
|
if (player->angle<0)
|
|
|
|
player->angle += ANGLES;
|
|
|
|
player->flags = FL_NEVERMARK;
|
2015-03-27 14:42:13 +00:00
|
|
|
Thrust (0,0); /* set some variables */
|
2015-03-26 11:33:55 +00:00
|
|
|
|
|
|
|
InitAreas ();
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
=
|
|
|
|
= T_KnifeAttack
|
|
|
|
=
|
|
|
|
= Update player hands, and try to do damage when the proper frame is reached
|
|
|
|
=
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
void KnifeAttack (objtype *ob)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
objtype *check,*closest;
|
|
|
|
int32_t dist;
|
|
|
|
|
|
|
|
SD_PlaySound (ATKKNIFESND);
|
2015-03-27 14:42:13 +00:00
|
|
|
|
|
|
|
/* actually fire */
|
2015-03-26 11:33:55 +00:00
|
|
|
dist = 0x7fffffff;
|
|
|
|
closest = NULL;
|
|
|
|
for (check=ob->next; check; check=check->next)
|
|
|
|
{
|
|
|
|
if ( (check->flags & FL_SHOOTABLE) && (check->flags & FL_VISABLE)
|
2012-12-24 18:14:43 +00:00
|
|
|
&& abs(check->viewx-centerx) < shootdelta)
|
2015-03-26 11:33:55 +00:00
|
|
|
{
|
|
|
|
if (check->transx < dist)
|
|
|
|
{
|
|
|
|
dist = check->transx;
|
|
|
|
closest = check;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
if (!closest || dist > 0x18000l) /* missed */
|
2015-03-26 11:33:55 +00:00
|
|
|
return;
|
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
/* hit something */
|
2015-03-26 11:33:55 +00:00
|
|
|
DamageActor (closest,US_RndT() >> 4);
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GunAttack (objtype *ob)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
objtype *check,*closest,*oldclosest;
|
|
|
|
int damage;
|
|
|
|
int dx,dy,dist;
|
|
|
|
int32_t viewdist;
|
|
|
|
|
|
|
|
switch (gamestate.weapon)
|
|
|
|
{
|
|
|
|
case wp_pistol:
|
|
|
|
SD_PlaySound (ATKPISTOLSND);
|
|
|
|
break;
|
|
|
|
case wp_machinegun:
|
|
|
|
SD_PlaySound (ATKMACHINEGUNSND);
|
|
|
|
break;
|
|
|
|
case wp_chaingun:
|
|
|
|
SD_PlaySound (ATKGATLINGSND);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
madenoise = true;
|
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
/* find potential targets */
|
2015-03-26 11:33:55 +00:00
|
|
|
viewdist = 0x7fffffffl;
|
|
|
|
closest = NULL;
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
oldclosest = closest;
|
|
|
|
|
|
|
|
for (check=ob->next ; check ; check=check->next)
|
|
|
|
{
|
|
|
|
if ((check->flags & FL_SHOOTABLE) && (check->flags & FL_VISABLE)
|
|
|
|
&& abs(check->viewx-centerx) < shootdelta)
|
|
|
|
{
|
|
|
|
if (check->transx < viewdist)
|
2012-12-24 18:14:43 +00:00
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
viewdist = check->transx;
|
|
|
|
closest = check;
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
2015-03-26 11:33:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
/* no more targets, all missed. */
|
2015-03-26 11:33:55 +00:00
|
|
|
if (closest == oldclosest)
|
2015-03-27 14:42:13 +00:00
|
|
|
return;
|
2015-03-26 11:33:55 +00:00
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
/* trace a line from player to enemey */
|
2015-03-26 11:33:55 +00:00
|
|
|
if (CheckLine(closest))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
/* hit something */
|
2015-03-26 11:33:55 +00:00
|
|
|
dx = ABS(closest->tilex - player->tilex);
|
|
|
|
dy = ABS(closest->tiley - player->tiley);
|
|
|
|
dist = dx>dy ? dx:dy;
|
|
|
|
if (dist<2)
|
|
|
|
damage = US_RndT() / 4;
|
|
|
|
else if (dist<4)
|
|
|
|
damage = US_RndT() / 6;
|
|
|
|
else
|
|
|
|
{
|
2015-03-27 14:42:13 +00:00
|
|
|
if ( (US_RndT() / 12) < dist) /* missed */
|
2015-03-26 11:33:55 +00:00
|
|
|
return;
|
|
|
|
damage = US_RndT() / 6;
|
|
|
|
}
|
|
|
|
DamageActor (closest,damage);
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
=
|
|
|
|
= VictorySpin
|
|
|
|
=
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
void VictorySpin (void)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
int32_t desty;
|
|
|
|
|
|
|
|
if (player->angle > 270)
|
|
|
|
{
|
|
|
|
player->angle -= (short)(tics * 3);
|
|
|
|
if (player->angle < 270)
|
|
|
|
player->angle = 270;
|
|
|
|
}
|
|
|
|
else if (player->angle < 270)
|
|
|
|
{
|
|
|
|
player->angle += (short)(tics * 3);
|
|
|
|
if (player->angle > 270)
|
|
|
|
player->angle = 270;
|
|
|
|
}
|
|
|
|
|
|
|
|
desty = (((int32_t)player->tiley-5)<<TILESHIFT)-0x3000;
|
|
|
|
|
|
|
|
if (player->y > desty)
|
|
|
|
{
|
|
|
|
player->y -= tics*4096;
|
|
|
|
if (player->y < desty)
|
|
|
|
player->y = desty;
|
|
|
|
}
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
=
|
|
|
|
= T_Attack
|
|
|
|
=
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
void T_Attack (objtype *ob)
|
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
struct atkinf *cur;
|
|
|
|
|
|
|
|
UpdateFace ();
|
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
/* watching the BJ actor */
|
|
|
|
if (gamestate.victoryflag)
|
2015-03-26 11:33:55 +00:00
|
|
|
{
|
|
|
|
VictorySpin ();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( buttonstate[bt_use] && !buttonheld[bt_use] )
|
|
|
|
buttonstate[bt_use] = false;
|
|
|
|
|
|
|
|
if ( buttonstate[bt_attack] && !buttonheld[bt_attack])
|
|
|
|
buttonstate[bt_attack] = false;
|
|
|
|
|
|
|
|
ControlMovement (ob);
|
2015-03-27 14:42:13 +00:00
|
|
|
|
|
|
|
/* watching the BJ actor */
|
|
|
|
if (gamestate.victoryflag)
|
2015-03-26 11:33:55 +00:00
|
|
|
return;
|
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
/* scale to fit in unsigned */
|
|
|
|
plux = (word) (player->x >> UNSIGNEDSHIFT);
|
2015-03-26 11:33:55 +00:00
|
|
|
pluy = (word) (player->y >> UNSIGNEDSHIFT);
|
2015-03-27 14:42:13 +00:00
|
|
|
/* scale to tile values */
|
|
|
|
player->tilex = (short)(player->x >> TILESHIFT);
|
2015-03-26 11:33:55 +00:00
|
|
|
player->tiley = (short)(player->y >> TILESHIFT);
|
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
/* change frame and fire */
|
2015-03-26 11:33:55 +00:00
|
|
|
gamestate.attackcount -= (short) tics;
|
|
|
|
while (gamestate.attackcount <= 0)
|
|
|
|
{
|
|
|
|
cur = &attackinfo[gamestate.weapon][gamestate.attackframe];
|
|
|
|
switch (cur->attack)
|
|
|
|
{
|
|
|
|
case -1:
|
|
|
|
ob->state = &s_player;
|
|
|
|
if (!gamestate.ammo)
|
|
|
|
{
|
|
|
|
gamestate.weapon = wp_knife;
|
|
|
|
DrawWeapon ();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (gamestate.weapon != gamestate.chosenweapon)
|
|
|
|
{
|
|
|
|
gamestate.weapon = gamestate.chosenweapon;
|
|
|
|
DrawWeapon ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
gamestate.attackframe = gamestate.weaponframe = 0;
|
|
|
|
return;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
case 4:
|
|
|
|
if (!gamestate.ammo)
|
|
|
|
break;
|
|
|
|
if (buttonstate[bt_attack])
|
|
|
|
gamestate.attackframe -= 2;
|
|
|
|
case 1:
|
2015-03-27 14:42:13 +00:00
|
|
|
/* can only happen with chain gun */
|
2015-03-26 11:33:55 +00:00
|
|
|
if (!gamestate.ammo)
|
2015-03-27 14:42:13 +00:00
|
|
|
{
|
2015-03-26 11:33:55 +00:00
|
|
|
gamestate.attackframe++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
GunAttack (ob);
|
|
|
|
if (!ammocheat)
|
|
|
|
gamestate.ammo--;
|
|
|
|
DrawAmmo ();
|
|
|
|
break;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
case 2:
|
|
|
|
KnifeAttack (ob);
|
|
|
|
break;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
case 3:
|
|
|
|
if (gamestate.ammo && buttonstate[bt_attack])
|
|
|
|
gamestate.attackframe -= 2;
|
|
|
|
break;
|
|
|
|
}
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
gamestate.attackcount += cur->tics;
|
|
|
|
gamestate.attackframe++;
|
|
|
|
gamestate.weaponframe =
|
|
|
|
attackinfo[gamestate.weapon][gamestate.attackframe].frame;
|
|
|
|
}
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//===========================================================================
|
|
|
|
|
|
|
|
/*
|
|
|
|
===============
|
|
|
|
=
|
|
|
|
= T_Player
|
|
|
|
=
|
|
|
|
===============
|
|
|
|
*/
|
|
|
|
|
|
|
|
void T_Player (objtype *ob)
|
|
|
|
{
|
2015-03-27 14:42:13 +00:00
|
|
|
/* watching the BJ actor */
|
|
|
|
if (gamestate.victoryflag)
|
2015-03-26 11:33:55 +00:00
|
|
|
{
|
2015-03-27 14:42:13 +00:00
|
|
|
VictorySpin();
|
2015-03-26 11:33:55 +00:00
|
|
|
return;
|
|
|
|
}
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
UpdateFace ();
|
|
|
|
CheckWeaponChange ();
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
if (buttonstate[bt_use])
|
2015-03-26 11:33:55 +00:00
|
|
|
Cmd_Use ();
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
if ( buttonstate[bt_attack] && !buttonheld[bt_attack])
|
|
|
|
Cmd_Fire ();
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-26 11:33:55 +00:00
|
|
|
ControlMovement (ob);
|
2015-03-27 14:42:13 +00:00
|
|
|
|
|
|
|
/* watching the BJ actor */
|
|
|
|
if (gamestate.victoryflag)
|
2015-03-26 11:33:55 +00:00
|
|
|
return;
|
2012-12-24 18:14:43 +00:00
|
|
|
|
2015-03-27 14:42:13 +00:00
|
|
|
/* scale to fit in unsigned */
|
|
|
|
plux = (word) (player->x >> UNSIGNEDSHIFT);
|
2015-03-26 11:33:55 +00:00
|
|
|
pluy = (word) (player->y >> UNSIGNEDSHIFT);
|
2015-03-27 14:42:13 +00:00
|
|
|
/* scale to tile values */
|
|
|
|
player->tilex = (short)(player->x >> TILESHIFT);
|
2015-03-26 11:33:55 +00:00
|
|
|
player->tiley = (short)(player->y >> TILESHIFT);
|
2012-12-24 18:14:43 +00:00
|
|
|
}
|