- Added Xaser's weapon patch to check +reload and +zoom in A_WeaponReady.

SVN r3530 (trunk)
This commit is contained in:
Christoph Oelckers 2012-04-07 13:07:25 +00:00
parent 34820aacd2
commit 235a09d92a
8 changed files with 172 additions and 3 deletions

View file

@ -90,8 +90,8 @@ typedef enum
BT_CROUCH = 1<<3,
BT_TURN180 = 1<<4,
BT_ALTATTACK = 1<<5, // Press your other "Fire".
BT_RELOAD = 1<<6, // Not connected to anything at the moment.
BT_ZOOM = 1<<7, // Neither is this.
BT_RELOAD = 1<<6, // [XA] Reload key. Causes state jump in A_WeaponReady.
BT_ZOOM = 1<<7, // [XA] Zoom key. Ditto.
// The rest are all ignored by the play simulation and are for scripts.
BT_SPEED = 1<<8,

View file

@ -205,6 +205,8 @@ typedef enum
CF_WEAPONREADYALT = 1 << 25, // Weapon can fire its secondary attack
CF_WEAPONSWITCHOK = 1 << 26, // It is okay to switch away from this weapon
CF_BUDDHA = 1 << 27, // [SP] Buddha mode - take damage, but don't die
CF_WEAPONRELOADOK = 1 << 28, // [XA] Okay to reload this weapon.
CF_WEAPONZOOMOK = 1 << 29, // [XA] Okay to use weapon zoom function.
} cheat_t;
#define WPIECE1 1

View file

@ -289,6 +289,8 @@ public:
virtual FState *GetReadyState ();
virtual FState *GetAtkState (bool hold);
virtual FState *GetAltAtkState (bool hold);
virtual FState *GetRelState ();
virtual FState *GetZoomState ();
virtual void PostMorphWeapon ();
virtual void EndPowerup ();

View file

@ -653,6 +653,28 @@ FState *AWeapon::GetAltAtkState (bool hold)
return state;
}
//===========================================================================
//
// AWeapon :: GetRelState
//
//===========================================================================
FState *AWeapon::GetRelState ()
{
return FindState(NAME_Reload);
}
//===========================================================================
//
// AWeapon :: GetZoomState
//
//===========================================================================
FState *AWeapon::GetZoomState ()
{
return FindState(NAME_Zoom);
}
/* Weapon giver ***********************************************************/
class AWeaponGiver : public AWeapon

View file

@ -198,6 +198,8 @@ xx(AltFire)
xx(AltHold)
xx(Flash)
xx(AltFlash)
xx(Reload)
xx(Zoom)
// State names used by ASwitchableDecoration
xx(Active)

View file

@ -95,7 +95,7 @@ void P_SetPsprite (player_t *player, int position, FState *state, bool nofunctio
if (position == ps_weapon && !nofunction)
{ // A_WeaponReady will re-set these as needed
player->cheats &= ~(CF_WEAPONREADY | CF_WEAPONREADYALT | CF_WEAPONBOBBING | CF_WEAPONSWITCHOK);
player->cheats &= ~(CF_WEAPONREADY | CF_WEAPONREADYALT | CF_WEAPONBOBBING | CF_WEAPONSWITCHOK | CF_WEAPONRELOADOK | CF_WEAPONZOOMOK);
}
psp = &player->psprites[position];
@ -282,6 +282,66 @@ void P_FireWeaponAlt (player_t *player, FState *state)
}
}
//---------------------------------------------------------------------------
//
// 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);
}
//---------------------------------------------------------------------------
//
// PROC P_DropWeapon
@ -368,6 +428,7 @@ void P_BobWeapon (player_t *player, pspdef_t *psp, fixed_t *x, fixed_t *y)
//
// Readies a weapon for firing or bobbing with its three ancillary functions,
// DoReadyWeaponToSwitch(), DoReadyWeaponToFire() and DoReadyWeaponToBob().
// [XA] Added DoReadyWeaponToReload() and DoReadyWeaponToZoom()
//
//============================================================================
@ -421,12 +482,32 @@ void DoReadyWeaponToBob (AActor * self)
}
}
void DoReadyWeaponToReload (AActor * self)
{
// Prepare for reload action.
player_t *player;
if (self && (player = self->player))
player->cheats |= CF_WEAPONRELOADOK;
return;
}
void DoReadyWeaponToZoom (AActor * self)
{
// Prepare for reload action.
player_t *player;
if (self && (player = self->player))
player->cheats |= CF_WEAPONZOOMOK;
return;
}
// This function replaces calls to A_WeaponReady in other codepointers.
void DoReadyWeapon(AActor * self)
{
DoReadyWeaponToBob(self);
DoReadyWeaponToFire(self);
DoReadyWeaponToSwitch(self);
DoReadyWeaponToReload(self);
DoReadyWeaponToZoom(self);
}
enum EWRF_Options
@ -436,6 +517,8 @@ enum EWRF_Options
WRF_NoSwitch = 2,
WRF_NoPrimary = 4,
WRF_NoSecondary = 8,
WRF_AllowReload = 16,
WRF_AllowZoom = 32,
};
DEFINE_ACTION_FUNCTION_PARAMS(AInventory, A_WeaponReady)
@ -447,6 +530,8 @@ DEFINE_ACTION_FUNCTION_PARAMS(AInventory, A_WeaponReady)
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);
}
//---------------------------------------------------------------------------
@ -520,6 +605,50 @@ void P_CheckWeaponSwitch (player_t *player)
}
}
//---------------------------------------------------------------------------
//
// 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.
if ((player->cheats & CF_WEAPONRELOADOK) && (player->cmd.ucmd.buttons & BT_RELOAD))
{
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.
if ((player->cheats & CF_WEAPONZOOMOK) && (player->cmd.ucmd.buttons & BT_ZOOM))
{
P_ZoomWeapon (player, NULL);
}
}
//---------------------------------------------------------------------------
//
// PROC A_ReFire
@ -892,6 +1021,14 @@ void P_MovePsprites (player_t *player)
{
P_CheckWeaponFire (player);
}
if (player->cheats & CF_WEAPONRELOADOK)
{
P_CheckWeaponReload (player);
}
if (player->cheats & CF_WEAPONZOOMOK)
{
P_CheckWeaponZoom (player);
}
}
}

View file

@ -95,6 +95,8 @@ const int WRF_NOFIRE = 12;
const int WRF_NOSWITCH = 2;
const int WRF_NOPRIMARY = 4;
const int WRF_NOSECONDARY = 8;
const int WRF_ALLOWRELOAD = 16;
const int WRF_ALLOWZOOM = 32;
// Morph constants
const int MRF_ADDSTAMINA = 1;

View file

@ -436,6 +436,8 @@ OptionMenu "CustomizeControls"
StaticText "Controls", 1
Control "Fire", "+attack"
Control "Secondary Fire", "+altattack"
Control "Weapon Reload", "+reload"
Control "Weapon Zoom", "+zoom"
Control "Use / Open", "+use"
Control "Move forward", "+forward"
Control "Move backward", "+back"