2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
//**************************************************************************
|
|
|
|
//**
|
|
|
|
//** p_pspr.c : Heretic 2 : Raven Software, Corp.
|
|
|
|
//**
|
|
|
|
//** $RCSfile: p_pspr.c,v $
|
|
|
|
//** $Revision: 1.105 $
|
|
|
|
//** $Date: 96/01/06 03:23:35 $
|
|
|
|
//** $Author: bgokey $
|
|
|
|
//**
|
|
|
|
//**************************************************************************
|
|
|
|
|
|
|
|
// HEADER FILES ------------------------------------------------------------
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "doomdef.h"
|
|
|
|
#include "d_event.h"
|
|
|
|
#include "c_cvars.h"
|
|
|
|
#include "m_random.h"
|
2011-06-13 10:30:30 +00:00
|
|
|
#include "p_enemy.h"
|
2006-02-24 04:48:15 +00:00
|
|
|
#include "p_local.h"
|
|
|
|
#include "s_sound.h"
|
|
|
|
#include "doomstat.h"
|
|
|
|
#include "gi.h"
|
|
|
|
#include "p_pspr.h"
|
|
|
|
#include "templates.h"
|
2007-05-28 14:46:49 +00:00
|
|
|
#include "thingdef/thingdef.h"
|
2008-09-14 23:54:38 +00:00
|
|
|
#include "g_level.h"
|
2011-07-06 14:20:54 +00:00
|
|
|
#include "farchive.h"
|
2012-04-01 02:49:04 +00:00
|
|
|
#include "d_player.h"
|
2011-07-06 14:20:54 +00:00
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
// MACROS ------------------------------------------------------------------
|
|
|
|
|
|
|
|
#define LOWERSPEED FRACUNIT*6
|
|
|
|
#define RAISESPEED FRACUNIT*6
|
|
|
|
|
|
|
|
// TYPES -------------------------------------------------------------------
|
|
|
|
|
|
|
|
// EXTERNAL FUNCTION PROTOTYPES --------------------------------------------
|
|
|
|
|
|
|
|
// PUBLIC FUNCTION PROTOTYPES ----------------------------------------------
|
|
|
|
|
|
|
|
// PRIVATE FUNCTION PROTOTYPES ---------------------------------------------
|
|
|
|
|
|
|
|
// EXTERNAL DATA DECLARATIONS ----------------------------------------------
|
|
|
|
|
|
|
|
// PUBLIC DATA DEFINITIONS -------------------------------------------------
|
|
|
|
|
|
|
|
// [SO] 1=Weapons states are all 1 tick
|
|
|
|
// 2=states with a function 1 tick, others 0 ticks.
|
|
|
|
CVAR(Int, sv_fastweapons, false, CVAR_SERVERINFO);
|
|
|
|
|
|
|
|
// PRIVATE DATA DEFINITIONS ------------------------------------------------
|
|
|
|
|
|
|
|
static FRandom pr_wpnreadysnd ("WpnReadySnd");
|
|
|
|
static FRandom pr_gunshot ("GunShot");
|
|
|
|
|
|
|
|
// CODE --------------------------------------------------------------------
|
|
|
|
|
2012-04-01 02:49:04 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PROC P_NewPspriteTick
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void P_NewPspriteTick()
|
|
|
|
{
|
|
|
|
// This function should be called after the beginning of a tick, before any possible
|
|
|
|
// prprite-event, or near the end, after any possible psprite event.
|
|
|
|
// Because data is reset for every tick (which it must be) this has no impact on savegames.
|
|
|
|
for (int i = 0; i<MAXPLAYERS; i++)
|
|
|
|
{
|
|
|
|
if (playeringame[i])
|
|
|
|
{
|
|
|
|
pspdef_t *pspdef = players[i].psprites;
|
|
|
|
for (int j = 0;j < NUMPSPRITES; j++)
|
|
|
|
{
|
|
|
|
pspdef[j].processPending = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PROC P_SetPsprite
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2010-04-19 02:46:50 +00:00
|
|
|
void P_SetPsprite (player_t *player, int position, FState *state, bool nofunction)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
pspdef_t *psp;
|
|
|
|
|
2010-04-19 02:46:50 +00:00
|
|
|
if (position == ps_weapon && !nofunction)
|
|
|
|
{ // A_WeaponReady will re-set these as needed
|
2013-01-25 03:09:17 +00:00
|
|
|
player->WeaponState &= ~(WF_WEAPONREADY | WF_WEAPONREADYALT | WF_WEAPONBOBBING | WF_WEAPONSWITCHOK | WF_WEAPONRELOADOK | WF_WEAPONZOOMOK);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
psp = &player->psprites[position];
|
2012-04-01 02:49:04 +00:00
|
|
|
psp->processPending = false; // Do not subsequently perform periodic processing within the same tick.
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if (state == NULL)
|
|
|
|
{ // Object removed itself.
|
|
|
|
psp->state = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
psp->state = state;
|
|
|
|
|
2010-04-21 01:40:03 +00:00
|
|
|
if (state->sprite != SPR_FIXED)
|
|
|
|
{ // okay to change sprite and/or frame
|
|
|
|
if (!state->GetSameFrame())
|
|
|
|
{ // okay to change frame
|
|
|
|
psp->frame = state->GetFrame();
|
|
|
|
}
|
|
|
|
if (state->sprite != SPR_NOCHANGE)
|
|
|
|
{ // okay to change sprite
|
|
|
|
psp->sprite = state->sprite;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
if (sv_fastweapons >= 2 && position == ps_weapon)
|
2008-08-12 14:30:07 +00:00
|
|
|
psp->tics = state->ActionFunc == NULL? 0 : 1;
|
2006-02-24 04:48:15 +00:00
|
|
|
else if (sv_fastweapons)
|
|
|
|
psp->tics = 1; // great for producing decals :)
|
|
|
|
else
|
|
|
|
psp->tics = state->GetTics(); // could be 0
|
|
|
|
|
2006-10-29 11:01:00 +00:00
|
|
|
if (state->GetMisc1())
|
|
|
|
{ // Set coordinates.
|
|
|
|
psp->sx = state->GetMisc1()<<FRACBITS;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2006-10-29 11:01:00 +00:00
|
|
|
if (state->GetMisc2())
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2006-10-29 11:01:00 +00:00
|
|
|
psp->sy = state->GetMisc2()<<FRACBITS;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2006-10-29 11:01:00 +00:00
|
|
|
|
2010-04-19 02:46:50 +00:00
|
|
|
if (!nofunction && player->mo != NULL)
|
2008-08-12 14:30:07 +00:00
|
|
|
{
|
2009-01-06 00:03:18 +00:00
|
|
|
if (state->CallAction(player->mo, player->ReadyWeapon))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-12 14:30:07 +00:00
|
|
|
if (!psp->state)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
2008-08-12 14:30:07 +00:00
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
state = psp->state->GetNextState();
|
|
|
|
} while (!psp->tics); // An initial state of 0 could cycle through.
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PROC P_BringUpWeapon
|
|
|
|
//
|
|
|
|
// Starts bringing the pending weapon up from the bottom of the screen.
|
|
|
|
// This is only called to start the rising, not throughout it.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void P_BringUpWeapon (player_t *player)
|
|
|
|
{
|
|
|
|
FState *newstate;
|
|
|
|
AWeapon *weapon;
|
|
|
|
|
|
|
|
if (player->PendingWeapon == WP_NOCHANGE)
|
|
|
|
{
|
|
|
|
player->psprites[ps_weapon].sy = WEAPONTOP;
|
|
|
|
P_SetPsprite (player, ps_weapon, player->ReadyWeapon->GetReadyState());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
weapon = player->PendingWeapon;
|
|
|
|
|
|
|
|
// If the player has a tome of power, use this weapon's powered up
|
|
|
|
// version, if one is available.
|
|
|
|
if (weapon != NULL &&
|
|
|
|
weapon->SisterWeapon &&
|
|
|
|
weapon->SisterWeapon->WeaponFlags & WIF_POWERED_UP &&
|
2011-11-07 00:43:41 +00:00
|
|
|
player->mo->FindInventory (RUNTIME_CLASS(APowerWeaponLevel2), true))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
weapon = weapon->SisterWeapon;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (weapon != NULL)
|
|
|
|
{
|
|
|
|
if (weapon->UpSound)
|
|
|
|
{
|
2008-06-15 02:25:09 +00:00
|
|
|
S_Sound (player->mo, CHAN_WEAPON, weapon->UpSound, 1, ATTN_NORM);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
newstate = weapon->GetUpState ();
|
2009-08-29 15:50:03 +00:00
|
|
|
player->refire = 0;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
newstate = NULL;
|
|
|
|
}
|
|
|
|
player->PendingWeapon = WP_NOCHANGE;
|
|
|
|
player->ReadyWeapon = weapon;
|
|
|
|
player->psprites[ps_weapon].sy = player->cheats & CF_INSTANTWEAPSWITCH
|
|
|
|
? WEAPONTOP : WEAPONBOTTOM;
|
|
|
|
P_SetPsprite (player, ps_weapon, newstate);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PROC P_FireWeapon
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2009-10-16 16:04:19 +00:00
|
|
|
void P_FireWeapon (player_t *player, FState *state)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
AWeapon *weapon;
|
|
|
|
|
|
|
|
// [SO] 9/2/02: People were able to do an awful lot of damage
|
|
|
|
// when they were observers...
|
|
|
|
if (!player->isbot && bot_observer)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
weapon = player->ReadyWeapon;
|
|
|
|
if (weapon == NULL || !weapon->CheckAmmo (AWeapon::PrimaryFire, true))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-07-16 10:23:14 +00:00
|
|
|
player->mo->PlayAttacking ();
|
2006-02-24 04:48:15 +00:00
|
|
|
weapon->bAltFire = false;
|
2009-10-16 16:04:19 +00:00
|
|
|
if (state == NULL)
|
|
|
|
{
|
|
|
|
state = weapon->GetAtkState(!!player->refire);
|
|
|
|
}
|
|
|
|
P_SetPsprite (player, ps_weapon, state);
|
2006-02-24 04:48:15 +00:00
|
|
|
if (!(weapon->WeaponFlags & WIF_NOALERT))
|
|
|
|
{
|
|
|
|
P_NoiseAlert (player->mo, player->mo, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PROC P_FireWeaponAlt
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2009-10-16 16:04:19 +00:00
|
|
|
void P_FireWeaponAlt (player_t *player, FState *state)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
AWeapon *weapon;
|
|
|
|
|
|
|
|
// [SO] 9/2/02: People were able to do an awful lot of damage
|
|
|
|
// when they were observers...
|
|
|
|
if (!player->isbot && bot_observer)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
weapon = player->ReadyWeapon;
|
2006-10-31 14:53:21 +00:00
|
|
|
if (weapon == NULL || weapon->FindState(NAME_AltFire) == NULL || !weapon->CheckAmmo (AWeapon::AltFire, true))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2006-07-16 10:23:14 +00:00
|
|
|
player->mo->PlayAttacking ();
|
2006-02-24 04:48:15 +00:00
|
|
|
weapon->bAltFire = true;
|
2006-10-31 14:53:21 +00:00
|
|
|
|
2009-10-16 16:04:19 +00:00
|
|
|
if (state == NULL)
|
|
|
|
{
|
|
|
|
state = weapon->GetAltAtkState(!!player->refire);
|
|
|
|
}
|
2006-10-31 14:53:21 +00:00
|
|
|
|
2009-10-16 16:04:19 +00:00
|
|
|
P_SetPsprite (player, ps_weapon, state);
|
2006-02-24 04:48:15 +00:00
|
|
|
if (!(weapon->WeaponFlags & WIF_NOALERT))
|
|
|
|
{
|
|
|
|
P_NoiseAlert (player->mo, player->mo, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-07 13:07:25 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PROC P_ReloadWeapon
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void P_ReloadWeapon (player_t *player, FState *state)
|
|
|
|
{
|
|
|
|
AWeapon *weapon;
|
|
|
|
if (!player->isbot && bot_observer)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
weapon = player->ReadyWeapon;
|
|
|
|
if (weapon == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state == NULL)
|
|
|
|
{
|
|
|
|
state = weapon->GetRelState();
|
|
|
|
}
|
|
|
|
// [XA] don't change state if still null, so if the modder sets
|
|
|
|
// WRF_RELOAD to true but forgets to define the Reload state, the weapon
|
|
|
|
// won't disappear. ;)
|
|
|
|
if (state != NULL)
|
|
|
|
P_SetPsprite (player, ps_weapon, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PROC P_ZoomWeapon
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void P_ZoomWeapon (player_t *player, FState *state)
|
|
|
|
{
|
|
|
|
AWeapon *weapon;
|
|
|
|
if (!player->isbot && bot_observer)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
weapon = player->ReadyWeapon;
|
|
|
|
if (weapon == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state == NULL)
|
|
|
|
{
|
|
|
|
state = weapon->GetZoomState();
|
|
|
|
}
|
|
|
|
// [XA] don't change state if still null. Same reasons as above.
|
|
|
|
if (state != NULL)
|
|
|
|
P_SetPsprite (player, ps_weapon, state);
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PROC P_DropWeapon
|
|
|
|
//
|
|
|
|
// The player died, so put the weapon away.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void P_DropWeapon (player_t *player)
|
|
|
|
{
|
2013-02-05 02:27:35 +00:00
|
|
|
if (player == NULL)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Since the weapon is dropping, stop blocking switching.
|
|
|
|
player->WeaponState &= ~WF_DISABLESWITCH;
|
2006-02-24 04:48:15 +00:00
|
|
|
if (player->ReadyWeapon != NULL)
|
|
|
|
{
|
|
|
|
P_SetPsprite (player, ps_weapon, player->ReadyWeapon->GetDownState());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//============================================================================
|
|
|
|
//
|
|
|
|
// P_BobWeapon
|
|
|
|
//
|
|
|
|
// [RH] Moved this out of A_WeaponReady so that the weapon can bob every
|
|
|
|
// tic and not just when A_WeaponReady is called. Not all weapons execute
|
|
|
|
// A_WeaponReady every tic, and it looks bad if they don't bob smoothly.
|
|
|
|
//
|
2012-05-02 20:58:29 +00:00
|
|
|
// [XA] Added new bob styles and exposed bob properties. Thanks, Ryan Cordell!
|
|
|
|
//
|
2006-02-24 04:48:15 +00:00
|
|
|
//============================================================================
|
|
|
|
|
|
|
|
void P_BobWeapon (player_t *player, pspdef_t *psp, fixed_t *x, fixed_t *y)
|
|
|
|
{
|
|
|
|
static fixed_t curbob;
|
|
|
|
|
|
|
|
AWeapon *weapon;
|
|
|
|
fixed_t bobtarget;
|
|
|
|
|
|
|
|
weapon = player->ReadyWeapon;
|
|
|
|
|
|
|
|
if (weapon == NULL || weapon->WeaponFlags & WIF_DONTBOB)
|
|
|
|
{
|
|
|
|
*x = *y = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-05-02 20:58:29 +00:00
|
|
|
// [XA] Get the current weapon's bob properties.
|
|
|
|
int bobstyle = weapon->BobStyle;
|
|
|
|
int bobspeed = (weapon->BobSpeed * 128) >> 16;
|
|
|
|
fixed_t rangex = weapon->BobRangeX;
|
|
|
|
fixed_t rangey = weapon->BobRangeY;
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
// Bob the weapon based on movement speed.
|
2012-05-02 20:58:29 +00:00
|
|
|
int angle = (bobspeed*35/TICRATE*level.time)&FINEMASK;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
// [RH] Smooth transitions between bobbing and not-bobbing frames.
|
|
|
|
// This also fixes the bug where you can "stick" a weapon off-center by
|
|
|
|
// shooting it when it's at the peak of its swing.
|
2013-01-25 03:18:45 +00:00
|
|
|
bobtarget = (player->WeaponState & WF_WEAPONBOBBING) ? player->bob : 0;
|
2006-02-24 04:48:15 +00:00
|
|
|
if (curbob != bobtarget)
|
|
|
|
{
|
|
|
|
if (abs (bobtarget - curbob) <= 1*FRACUNIT)
|
|
|
|
{
|
|
|
|
curbob = bobtarget;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fixed_t zoom = MAX<fixed_t> (1*FRACUNIT, abs (curbob - bobtarget) / 40);
|
|
|
|
if (curbob > bobtarget)
|
|
|
|
{
|
|
|
|
curbob -= zoom;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
curbob += zoom;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (curbob != 0)
|
|
|
|
{
|
2012-05-02 20:58:29 +00:00
|
|
|
fixed_t bobx = FixedMul(player->bob, rangex);
|
|
|
|
fixed_t boby = FixedMul(player->bob, rangey);
|
|
|
|
switch (bobstyle)
|
|
|
|
{
|
|
|
|
case AWeapon::BobNormal:
|
|
|
|
*x = FixedMul(bobx, finecosine[angle]);
|
|
|
|
*y = FixedMul(boby, finesine[angle & (FINEANGLES/2-1)]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AWeapon::BobInverse:
|
|
|
|
*x = FixedMul(bobx, finecosine[angle]);
|
|
|
|
*y = boby - FixedMul(boby, finesine[angle & (FINEANGLES/2-1)]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AWeapon::BobAlpha:
|
|
|
|
*x = FixedMul(bobx, finesine[angle]);
|
|
|
|
*y = FixedMul(boby, finesine[angle & (FINEANGLES/2-1)]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AWeapon::BobInverseAlpha:
|
|
|
|
*x = FixedMul(bobx, finesine[angle]);
|
|
|
|
*y = boby - FixedMul(boby, finesine[angle & (FINEANGLES/2-1)]);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AWeapon::BobSmooth:
|
|
|
|
*x = FixedMul(bobx, finecosine[angle]);
|
|
|
|
*y = (boby - FixedMul(boby, finecosine[angle*2 & (FINEANGLES-1)])) / 2;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case AWeapon::BobInverseSmooth:
|
|
|
|
*x = FixedMul(bobx, finecosine[angle]);
|
|
|
|
*y = (FixedMul(boby, finecosine[angle*2 & (FINEANGLES-1)]) + boby) / 2;
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
*x = 0;
|
|
|
|
*y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-06 15:48:31 +00:00
|
|
|
//============================================================================
|
2006-02-24 04:48:15 +00:00
|
|
|
//
|
|
|
|
// PROC A_WeaponReady
|
|
|
|
//
|
2009-07-16 22:40:04 +00:00
|
|
|
// Readies a weapon for firing or bobbing with its three ancillary functions,
|
|
|
|
// DoReadyWeaponToSwitch(), DoReadyWeaponToFire() and DoReadyWeaponToBob().
|
2012-04-07 13:07:25 +00:00
|
|
|
// [XA] Added DoReadyWeaponToReload() and DoReadyWeaponToZoom()
|
2006-02-24 04:48:15 +00:00
|
|
|
//
|
2009-07-06 15:48:31 +00:00
|
|
|
//============================================================================
|
2006-02-24 04:48:15 +00:00
|
|
|
|
2013-02-05 02:27:35 +00:00
|
|
|
void DoReadyWeaponToSwitch (AActor *self)
|
2009-07-16 22:40:04 +00:00
|
|
|
{
|
|
|
|
// Prepare for switching action.
|
|
|
|
player_t *player;
|
|
|
|
if (self && (player = self->player))
|
2013-01-25 03:18:45 +00:00
|
|
|
player->WeaponState |= WF_WEAPONSWITCHOK;
|
2009-07-16 22:40:04 +00:00
|
|
|
}
|
|
|
|
|
2013-02-05 02:27:35 +00:00
|
|
|
void DoReadyWeaponDisableSwitch (AActor *self, INTBOOL disable)
|
|
|
|
{
|
|
|
|
// Discard all switch attempts?
|
|
|
|
player_t *player;
|
|
|
|
if (self && (player = self->player))
|
|
|
|
{
|
|
|
|
if (disable)
|
|
|
|
{
|
|
|
|
player->WeaponState |= WF_DISABLESWITCH;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
player->WeaponState &= ~WF_DISABLESWITCH;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void DoReadyWeaponToFire (AActor *self, bool prim, bool alt)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2009-07-06 15:48:31 +00:00
|
|
|
player_t *player;
|
2006-02-24 04:48:15 +00:00
|
|
|
AWeapon *weapon;
|
|
|
|
|
2009-07-06 15:48:31 +00:00
|
|
|
if (!self || !(player = self->player) || !(weapon = player->ReadyWeapon))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Change player from attack state
|
2008-08-10 20:48:55 +00:00
|
|
|
if (self->InStateSequence(self->state, self->MissileState) ||
|
|
|
|
self->InStateSequence(self->state, self->MeleeState))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
static_cast<APlayerPawn *>(self)->PlayIdle ();
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Play ready sound, if any.
|
2006-10-31 14:53:21 +00:00
|
|
|
if (weapon->ReadySound && player->psprites[ps_weapon].state == weapon->FindState(NAME_Ready))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
if (!(weapon->WeaponFlags & WIF_READYSNDHALF) || pr_wpnreadysnd() < 128)
|
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
S_Sound (self, CHAN_WEAPON, weapon->ReadySound, 1, ATTN_NORM);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-06 15:48:31 +00:00
|
|
|
// Prepare for firing action.
|
2013-01-25 03:18:45 +00:00
|
|
|
player->WeaponState |= ((prim ? WF_WEAPONREADY : 0) | (alt ? WF_WEAPONREADYALT : 0));
|
2009-07-06 15:48:31 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-05 02:27:35 +00:00
|
|
|
void DoReadyWeaponToBob (AActor *self)
|
2009-07-06 15:48:31 +00:00
|
|
|
{
|
2009-07-16 22:40:04 +00:00
|
|
|
if (self && self->player && self->player->ReadyWeapon)
|
2009-07-06 15:48:31 +00:00
|
|
|
{
|
2009-07-16 22:40:04 +00:00
|
|
|
// Prepare for bobbing action.
|
2013-01-25 03:18:45 +00:00
|
|
|
self->player->WeaponState |= WF_WEAPONBOBBING;
|
2009-07-16 22:40:04 +00:00
|
|
|
self->player->psprites[ps_weapon].sx = 0;
|
|
|
|
self->player->psprites[ps_weapon].sy = WEAPONTOP;
|
2009-07-06 15:48:31 +00:00
|
|
|
}
|
2009-07-16 22:40:04 +00:00
|
|
|
}
|
2009-07-06 15:48:31 +00:00
|
|
|
|
2013-02-05 02:27:35 +00:00
|
|
|
void DoReadyWeaponToReload (AActor *self)
|
2012-04-07 13:07:25 +00:00
|
|
|
{
|
|
|
|
// Prepare for reload action.
|
|
|
|
player_t *player;
|
|
|
|
if (self && (player = self->player))
|
2013-01-25 03:18:45 +00:00
|
|
|
player->WeaponState |= WF_WEAPONRELOADOK;
|
2012-04-07 13:07:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-02-05 02:27:35 +00:00
|
|
|
void DoReadyWeaponToZoom (AActor *self)
|
2012-04-07 13:07:25 +00:00
|
|
|
{
|
|
|
|
// Prepare for reload action.
|
|
|
|
player_t *player;
|
|
|
|
if (self && (player = self->player))
|
2013-01-25 03:18:45 +00:00
|
|
|
player->WeaponState |= WF_WEAPONZOOMOK;
|
2012-04-07 13:07:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-07-16 22:40:04 +00:00
|
|
|
// This function replaces calls to A_WeaponReady in other codepointers.
|
2013-02-05 02:27:35 +00:00
|
|
|
void DoReadyWeapon(AActor *self)
|
2009-07-16 22:40:04 +00:00
|
|
|
{
|
|
|
|
DoReadyWeaponToBob(self);
|
|
|
|
DoReadyWeaponToFire(self);
|
|
|
|
DoReadyWeaponToSwitch(self);
|
2012-04-07 13:07:25 +00:00
|
|
|
DoReadyWeaponToReload(self);
|
|
|
|
DoReadyWeaponToZoom(self);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2009-07-06 15:48:31 +00:00
|
|
|
enum EWRF_Options
|
|
|
|
{
|
|
|
|
WRF_NoBob = 1,
|
2009-07-16 22:40:04 +00:00
|
|
|
WRF_NoSwitch = 2,
|
|
|
|
WRF_NoPrimary = 4,
|
|
|
|
WRF_NoSecondary = 8,
|
2013-01-27 03:02:00 +00:00
|
|
|
WRF_NoFire = WRF_NoPrimary + WRF_NoSecondary,
|
2012-04-07 13:07:25 +00:00
|
|
|
WRF_AllowReload = 16,
|
|
|
|
WRF_AllowZoom = 32,
|
2013-02-05 02:27:35 +00:00
|
|
|
WRF_DisableSwitch = 64,
|
2009-07-06 15:48:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
DEFINE_ACTION_FUNCTION_PARAMS(AInventory, A_WeaponReady)
|
|
|
|
{
|
|
|
|
ACTION_PARAM_START(1);
|
|
|
|
ACTION_PARAM_INT(paramflags, 0);
|
|
|
|
|
2013-01-27 03:02:00 +00:00
|
|
|
if (!(paramflags & WRF_NoSwitch)) DoReadyWeaponToSwitch(self);
|
|
|
|
if ((paramflags & WRF_NoFire) != WRF_NoFire) DoReadyWeaponToFire(self, !(paramflags & WRF_NoPrimary), !(paramflags & WRF_NoSecondary));
|
|
|
|
if (!(paramflags & WRF_NoBob)) DoReadyWeaponToBob(self);
|
|
|
|
if ((paramflags & WRF_AllowReload)) DoReadyWeaponToReload(self);
|
|
|
|
if ((paramflags & WRF_AllowZoom)) DoReadyWeaponToZoom(self);
|
2013-02-05 02:27:35 +00:00
|
|
|
|
|
|
|
DoReadyWeaponDisableSwitch(self, paramflags & WRF_DisableSwitch);
|
2009-07-06 15:48:31 +00:00
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PROC P_CheckWeaponFire
|
|
|
|
//
|
2009-07-16 22:40:04 +00:00
|
|
|
// The player can fire the weapon.
|
2006-02-24 04:48:15 +00:00
|
|
|
// [RH] This was in A_WeaponReady before, but that only works well when the
|
|
|
|
// weapon's ready frames have a one tic delay.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void P_CheckWeaponFire (player_t *player)
|
|
|
|
{
|
|
|
|
AWeapon *weapon = player->ReadyWeapon;
|
|
|
|
|
|
|
|
if (weapon == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Check for fire. Some weapons do not auto fire.
|
2013-01-25 03:18:45 +00:00
|
|
|
if ((player->WeaponState & WF_WEAPONREADY) && (player->cmd.ucmd.buttons & BT_ATTACK))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
if (!player->attackdown || !(weapon->WeaponFlags & WIF_NOAUTOFIRE))
|
|
|
|
{
|
|
|
|
player->attackdown = true;
|
2009-10-16 16:04:19 +00:00
|
|
|
P_FireWeapon (player, NULL);
|
2006-02-24 04:48:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2013-01-25 03:32:20 +00:00
|
|
|
else if ((player->WeaponState & WF_WEAPONREADYALT) && (player->cmd.ucmd.buttons & BT_ALTATTACK))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
if (!player->attackdown || !(weapon->WeaponFlags & WIF_NOAUTOFIRE))
|
|
|
|
{
|
|
|
|
player->attackdown = true;
|
2009-10-16 16:04:19 +00:00
|
|
|
P_FireWeaponAlt (player, NULL);
|
2006-02-24 04:48:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
player->attackdown = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-07-16 22:40:04 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PROC P_CheckWeaponSwitch
|
|
|
|
//
|
|
|
|
// The player can change to another weapon at this time.
|
|
|
|
// [GZ] This was cut from P_CheckWeaponFire.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void P_CheckWeaponSwitch (player_t *player)
|
|
|
|
{
|
2013-02-05 02:27:35 +00:00
|
|
|
if (player == NULL)
|
2013-01-25 02:05:48 +00:00
|
|
|
{
|
|
|
|
return;
|
2009-07-16 22:40:04 +00:00
|
|
|
}
|
2013-02-05 02:27:35 +00:00
|
|
|
if ((player->WeaponState & WF_DISABLESWITCH) || // Weapon changing has been disabled.
|
|
|
|
player->morphTics != 0) // Morphed classes cannot change weapons.
|
|
|
|
{ // ...so throw away any pending weapon requests.
|
2009-12-16 22:42:15 +00:00
|
|
|
player->PendingWeapon = WP_NOCHANGE;
|
|
|
|
}
|
2013-02-05 02:27:35 +00:00
|
|
|
|
|
|
|
// Put the weapon away if the player has a pending weapon or has died, and
|
|
|
|
// we're at a place in the state sequence where dropping the weapon is okay.
|
|
|
|
if ((player->PendingWeapon != WP_NOCHANGE || player->health <= 0) &&
|
|
|
|
player->WeaponState & WF_WEAPONSWITCHOK)
|
|
|
|
{
|
|
|
|
P_DropWeapon(player);
|
|
|
|
}
|
2009-07-16 22:40:04 +00:00
|
|
|
}
|
|
|
|
|
2012-04-07 13:07:25 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PROC P_CheckWeaponReload
|
|
|
|
//
|
|
|
|
// The player can reload the weapon.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void P_CheckWeaponReload (player_t *player)
|
|
|
|
{
|
|
|
|
AWeapon *weapon = player->ReadyWeapon;
|
|
|
|
|
|
|
|
if (weapon == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Check for reload.
|
2013-01-25 03:18:45 +00:00
|
|
|
if ((player->WeaponState & WF_WEAPONRELOADOK) && (player->cmd.ucmd.buttons & BT_RELOAD))
|
2012-04-07 13:07:25 +00:00
|
|
|
{
|
|
|
|
P_ReloadWeapon (player, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PROC P_CheckWeaponZoom
|
|
|
|
//
|
|
|
|
// The player can use the weapon's zoom function.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void P_CheckWeaponZoom (player_t *player)
|
|
|
|
{
|
|
|
|
AWeapon *weapon = player->ReadyWeapon;
|
|
|
|
|
|
|
|
if (weapon == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Check for zoom.
|
2013-01-25 03:18:45 +00:00
|
|
|
if ((player->WeaponState & WF_WEAPONZOOMOK) && (player->cmd.ucmd.buttons & BT_ZOOM))
|
2012-04-07 13:07:25 +00:00
|
|
|
{
|
|
|
|
P_ZoomWeapon (player, NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PROC A_ReFire
|
|
|
|
//
|
|
|
|
// The player can re-fire the weapon without lowering it entirely.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2009-10-16 16:04:19 +00:00
|
|
|
DEFINE_ACTION_FUNCTION_PARAMS(AInventory, A_ReFire)
|
|
|
|
{
|
|
|
|
ACTION_PARAM_START(1)
|
|
|
|
ACTION_PARAM_STATE(state, 0);
|
|
|
|
|
|
|
|
A_ReFire(self, state);
|
|
|
|
}
|
|
|
|
|
|
|
|
void A_ReFire(AActor *self, FState *state)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
player_t *player = self->player;
|
2013-02-07 20:38:41 +00:00
|
|
|
bool pending;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (NULL == player)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2013-02-07 20:38:41 +00:00
|
|
|
pending = player->PendingWeapon == WP_NOCHANGE && (player->WeaponState & WF_WEAPONSWITCHOK);
|
|
|
|
if ((player->cmd.ucmd.buttons & BT_ATTACK)
|
|
|
|
&& !player->ReadyWeapon->bAltFire && !pending && player->health > 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
player->refire++;
|
2009-10-16 16:04:19 +00:00
|
|
|
P_FireWeapon (player, state);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
2013-02-07 20:38:41 +00:00
|
|
|
else if ((player->cmd.ucmd.buttons & BT_ALTATTACK)
|
|
|
|
&& player->ReadyWeapon->bAltFire && !pending && player->health > 0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
player->refire++;
|
2009-10-16 16:04:19 +00:00
|
|
|
P_FireWeaponAlt (player, state);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
player->refire = 0;
|
|
|
|
player->ReadyWeapon->CheckAmmo (player->ReadyWeapon->bAltFire
|
|
|
|
? AWeapon::AltFire : AWeapon::PrimaryFire, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-10 20:48:55 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AInventory, A_ClearReFire)
|
2008-06-30 23:30:06 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
player_t *player = self->player;
|
2008-06-30 23:30:06 +00:00
|
|
|
|
|
|
|
if (NULL != player)
|
|
|
|
{
|
|
|
|
player->refire = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PROC A_CheckReload
|
|
|
|
//
|
|
|
|
// Present in Doom, but unused. Also present in Strife, and actually used.
|
|
|
|
// This and what I call A_XBowReFire are actually the same thing in Strife,
|
|
|
|
// not two separate functions as I have them here.
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2008-08-10 20:48:55 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AInventory, A_CheckReload)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
if (self->player != NULL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
self->player->ReadyWeapon->CheckAmmo (
|
|
|
|
self->player->ReadyWeapon->bAltFire ? AWeapon::AltFire
|
2006-02-24 04:48:15 +00:00
|
|
|
: AWeapon::PrimaryFire, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PROC A_Lower
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2008-08-10 20:48:55 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AInventory, A_Lower)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
player_t *player = self->player;
|
2006-02-24 04:48:15 +00:00
|
|
|
pspdef_t *psp;
|
|
|
|
|
|
|
|
if (NULL == player)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
psp = &player->psprites[ps_weapon];
|
2013-01-27 04:08:00 +00:00
|
|
|
if (player->morphTics || player->cheats & CF_INSTANTWEAPSWITCH)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
psp->sy = WEAPONBOTTOM;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
psp->sy += LOWERSPEED;
|
|
|
|
}
|
|
|
|
if (psp->sy < WEAPONBOTTOM)
|
|
|
|
{ // Not lowered all the way yet
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (player->playerstate == PST_DEAD)
|
|
|
|
{ // Player is dead, so don't bring up a pending weapon
|
|
|
|
psp->sy = WEAPONBOTTOM;
|
2013-01-18 18:19:05 +00:00
|
|
|
|
|
|
|
// Player is dead, so keep the weapon off screen
|
2006-02-24 04:48:15 +00:00
|
|
|
P_SetPsprite (player, ps_weapon, NULL);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// [RH] Clear the flash state. Only needed for Strife.
|
|
|
|
P_SetPsprite (player, ps_flash, NULL);
|
|
|
|
P_BringUpWeapon (player);
|
|
|
|
}
|
|
|
|
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PROC A_Raise
|
|
|
|
//
|
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2008-08-10 20:48:55 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AInventory, A_Raise)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
if (self == NULL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2008-08-10 20:48:55 +00:00
|
|
|
player_t *player = self->player;
|
2006-02-24 04:48:15 +00:00
|
|
|
pspdef_t *psp;
|
|
|
|
|
|
|
|
if (NULL == player)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (player->PendingWeapon != WP_NOCHANGE)
|
|
|
|
{
|
2013-01-25 03:32:49 +00:00
|
|
|
P_DropWeapon(player);
|
2006-02-24 04:48:15 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
psp = &player->psprites[ps_weapon];
|
|
|
|
psp->sy -= RAISESPEED;
|
|
|
|
if (psp->sy > WEAPONTOP)
|
|
|
|
{ // Not raised all the way yet
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
psp->sy = WEAPONTOP;
|
|
|
|
if (player->ReadyWeapon != NULL)
|
|
|
|
{
|
|
|
|
P_SetPsprite (player, ps_weapon, player->ReadyWeapon->GetReadyState());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
player->psprites[ps_weapon].state = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// A_GunFlash
|
|
|
|
//
|
2011-05-26 23:29:36 +00:00
|
|
|
enum GF_Flags
|
|
|
|
{
|
|
|
|
GFF_NOEXTCHANGE = 1,
|
|
|
|
};
|
|
|
|
|
2009-10-16 16:04:19 +00:00
|
|
|
DEFINE_ACTION_FUNCTION_PARAMS(AInventory, A_GunFlash)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2011-05-26 23:29:36 +00:00
|
|
|
ACTION_PARAM_START(2)
|
2009-10-16 16:04:19 +00:00
|
|
|
ACTION_PARAM_STATE(flash, 0);
|
2011-05-26 23:29:36 +00:00
|
|
|
ACTION_PARAM_INT(Flags, 1);
|
2009-10-16 16:04:19 +00:00
|
|
|
|
2008-08-10 20:48:55 +00:00
|
|
|
player_t *player = self->player;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (NULL == player)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2011-05-26 23:29:36 +00:00
|
|
|
if(!(Flags & GFF_NOEXTCHANGE)) player->mo->PlayAttacking2 ();
|
2006-10-31 14:53:21 +00:00
|
|
|
|
2009-10-16 16:04:19 +00:00
|
|
|
if (flash == NULL)
|
|
|
|
{
|
|
|
|
if (player->ReadyWeapon->bAltFire) flash = player->ReadyWeapon->FindState(NAME_AltFlash);
|
|
|
|
if (flash == NULL) flash = player->ReadyWeapon->FindState(NAME_Flash);
|
|
|
|
}
|
2006-10-31 14:53:21 +00:00
|
|
|
P_SetPsprite (player, ps_flash, flash);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// WEAPON ATTACKS
|
|
|
|
//
|
|
|
|
|
|
|
|
//
|
|
|
|
// P_BulletSlope
|
|
|
|
// Sets a slope so a near miss is at aproximately
|
|
|
|
// the height of the intended target
|
|
|
|
//
|
|
|
|
|
2008-04-10 14:38:43 +00:00
|
|
|
angle_t P_BulletSlope (AActor *mo, AActor **pLineTarget)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
static const int angdiff[3] = { -1<<26, 1<<26, 0 };
|
|
|
|
int i;
|
|
|
|
angle_t an;
|
2008-04-10 14:38:43 +00:00
|
|
|
angle_t pitch;
|
|
|
|
AActor *linetarget;
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
// see which target is to be aimed at
|
|
|
|
i = 2;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
an = mo->angle + angdiff[i];
|
2008-04-10 14:38:43 +00:00
|
|
|
pitch = P_AimLineAttack (mo, an, 16*64*FRACUNIT, &linetarget);
|
2006-02-24 04:48:15 +00:00
|
|
|
|
|
|
|
if (mo->player != NULL &&
|
2007-12-11 04:03:40 +00:00
|
|
|
level.IsFreelookAllowed() &&
|
2009-01-10 09:40:47 +00:00
|
|
|
mo->player->userinfo.GetAimDist() <= ANGLE_1/2)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (linetarget == NULL && --i >= 0);
|
2008-06-26 17:25:55 +00:00
|
|
|
if (pLineTarget != NULL)
|
|
|
|
{
|
|
|
|
*pLineTarget = linetarget;
|
|
|
|
}
|
2008-04-10 14:38:43 +00:00
|
|
|
return pitch;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// P_GunShot
|
|
|
|
//
|
2008-04-10 14:38:43 +00:00
|
|
|
void P_GunShot (AActor *mo, bool accurate, const PClass *pufftype, angle_t pitch)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
angle_t angle;
|
|
|
|
int damage;
|
|
|
|
|
|
|
|
damage = 5*(pr_gunshot()%3+1);
|
|
|
|
angle = mo->angle;
|
|
|
|
|
|
|
|
if (!accurate)
|
|
|
|
{
|
|
|
|
angle += pr_gunshot.Random2 () << 18;
|
|
|
|
}
|
|
|
|
|
2012-05-13 01:06:28 +00:00
|
|
|
P_LineAttack (mo, angle, PLAYERMISSILERANGE, pitch, damage, NAME_Hitscan, pufftype);
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
|
2008-08-10 20:48:55 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AInventory, A_Light0)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
if (self->player != NULL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
self->player->extralight = 0;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-10 20:48:55 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AInventory, A_Light1)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
if (self->player != NULL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
self->player->extralight = 1;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-10 20:48:55 +00:00
|
|
|
DEFINE_ACTION_FUNCTION(AInventory, A_Light2)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
if (self->player != NULL)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
2008-08-10 20:48:55 +00:00
|
|
|
self->player->extralight = 2;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-08-12 14:30:07 +00:00
|
|
|
DEFINE_ACTION_FUNCTION_PARAMS(AInventory, A_Light)
|
2006-05-13 12:41:15 +00:00
|
|
|
{
|
2008-08-13 22:54:24 +00:00
|
|
|
ACTION_PARAM_START(1);
|
|
|
|
ACTION_PARAM_INT(light, 0);
|
2006-05-13 12:41:15 +00:00
|
|
|
|
2008-08-13 22:54:24 +00:00
|
|
|
if (self->player != NULL)
|
2006-05-13 12:41:15 +00:00
|
|
|
{
|
2008-08-13 22:54:24 +00:00
|
|
|
self->player->extralight = clamp<int>(light, 0, 20);
|
2006-05-13 12:41:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
//------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PROC P_SetupPsprites
|
|
|
|
//
|
|
|
|
// Called at start of level for each player
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
2013-01-03 02:08:08 +00:00
|
|
|
void P_SetupPsprites(player_t *player, bool startweaponup)
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
// Remove all psprites
|
|
|
|
for (i = 0; i < NUMPSPRITES; i++)
|
|
|
|
{
|
|
|
|
player->psprites[i].state = NULL;
|
|
|
|
}
|
|
|
|
// Spawn the ready weapon
|
2013-01-03 02:08:08 +00:00
|
|
|
player->PendingWeapon = !startweaponup ? player->ReadyWeapon : WP_NOCHANGE;
|
2006-02-24 04:48:15 +00:00
|
|
|
P_BringUpWeapon (player);
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// PROC P_MovePsprites
|
|
|
|
//
|
|
|
|
// Called every tic by player thinking routine
|
|
|
|
//
|
|
|
|
//------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void P_MovePsprites (player_t *player)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
pspdef_t *psp;
|
|
|
|
FState *state;
|
|
|
|
|
|
|
|
// [RH] If you don't have a weapon, then the psprites should be NULL.
|
2006-10-31 14:53:21 +00:00
|
|
|
if (player->ReadyWeapon == NULL && (player->health > 0 || player->mo->DamageType != NAME_Fire))
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
P_SetPsprite (player, ps_weapon, NULL);
|
|
|
|
P_SetPsprite (player, ps_flash, NULL);
|
|
|
|
if (player->PendingWeapon != WP_NOCHANGE)
|
|
|
|
{
|
|
|
|
P_BringUpWeapon (player);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
psp = &player->psprites[0];
|
|
|
|
for (i = 0; i < NUMPSPRITES; i++, psp++)
|
|
|
|
{
|
2012-04-01 02:49:04 +00:00
|
|
|
if ((state = psp->state) != NULL && psp->processPending) // a null state means not active
|
2006-02-24 04:48:15 +00:00
|
|
|
{
|
|
|
|
// drop tic count and possibly change state
|
|
|
|
if (psp->tics != -1) // a -1 tic count never changes
|
|
|
|
{
|
|
|
|
psp->tics--;
|
2009-05-26 01:16:39 +00:00
|
|
|
|
|
|
|
// [BC] Apply double firing speed.
|
2013-02-05 01:45:23 +00:00
|
|
|
if ( psp->tics && (player->cheats & CF_DOUBLEFIRINGSPEED))
|
2009-05-26 01:16:39 +00:00
|
|
|
psp->tics--;
|
|
|
|
|
2006-02-24 04:48:15 +00:00
|
|
|
if(!psp->tics)
|
|
|
|
{
|
|
|
|
P_SetPsprite (player, i, psp->state->GetNextState());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
player->psprites[ps_flash].sx = player->psprites[ps_weapon].sx;
|
|
|
|
player->psprites[ps_flash].sy = player->psprites[ps_weapon].sy;
|
2013-01-25 03:18:45 +00:00
|
|
|
if (player->WeaponState & WF_WEAPONSWITCHOK)
|
2013-01-25 02:05:48 +00:00
|
|
|
{
|
|
|
|
P_CheckWeaponSwitch (player);
|
|
|
|
}
|
2013-01-25 03:18:45 +00:00
|
|
|
if (player->WeaponState & (WF_WEAPONREADY | WF_WEAPONREADYALT))
|
2009-09-03 19:51:55 +00:00
|
|
|
{
|
|
|
|
P_CheckWeaponFire (player);
|
|
|
|
}
|
2013-01-25 03:18:45 +00:00
|
|
|
if (player->WeaponState & WF_WEAPONRELOADOK)
|
2012-04-07 13:07:25 +00:00
|
|
|
{
|
|
|
|
P_CheckWeaponReload (player);
|
|
|
|
}
|
2013-01-25 03:18:45 +00:00
|
|
|
if (player->WeaponState & WF_WEAPONZOOMOK)
|
2012-04-07 13:07:25 +00:00
|
|
|
{
|
|
|
|
P_CheckWeaponZoom (player);
|
|
|
|
}
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FArchive &operator<< (FArchive &arc, pspdef_t &def)
|
|
|
|
{
|
2010-12-12 15:43:35 +00:00
|
|
|
arc << def.state << def.tics << def.sx << def.sy
|
|
|
|
<< def.sprite << def.frame;
|
2010-04-21 01:40:03 +00:00
|
|
|
return arc;
|
2006-02-24 04:48:15 +00:00
|
|
|
}
|