From 235a09d92a1f52d8bedd9c300371f64b11821f75 Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 7 Apr 2012 13:07:25 +0000 Subject: [PATCH] - Added Xaser's weapon patch to check +reload and +zoom in A_WeaponReady. SVN r3530 (trunk) --- src/d_event.h | 4 +- src/d_player.h | 2 + src/g_shared/a_pickups.h | 2 + src/g_shared/a_weapons.cpp | 22 +++++ src/namedef.h | 2 + src/p_pspr.cpp | 139 ++++++++++++++++++++++++++++- wadsrc/static/actors/constants.txt | 2 + wadsrc/static/menudef.txt | 2 + 8 files changed, 172 insertions(+), 3 deletions(-) diff --git a/src/d_event.h b/src/d_event.h index c7ab5b1b81..5bd4b02e05 100644 --- a/src/d_event.h +++ b/src/d_event.h @@ -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, diff --git a/src/d_player.h b/src/d_player.h index 4993fecdfd..fa91f8255b 100644 --- a/src/d_player.h +++ b/src/d_player.h @@ -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 diff --git a/src/g_shared/a_pickups.h b/src/g_shared/a_pickups.h index 176c0a7b5f..e89cf7be15 100644 --- a/src/g_shared/a_pickups.h +++ b/src/g_shared/a_pickups.h @@ -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 (); diff --git a/src/g_shared/a_weapons.cpp b/src/g_shared/a_weapons.cpp index 5673c9f0ee..a1400f04c3 100644 --- a/src/g_shared/a_weapons.cpp +++ b/src/g_shared/a_weapons.cpp @@ -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 diff --git a/src/namedef.h b/src/namedef.h index 36a7564411..b69f1fb3f0 100644 --- a/src/namedef.h +++ b/src/namedef.h @@ -198,6 +198,8 @@ xx(AltFire) xx(AltHold) xx(Flash) xx(AltFlash) +xx(Reload) +xx(Zoom) // State names used by ASwitchableDecoration xx(Active) diff --git a/src/p_pspr.cpp b/src/p_pspr.cpp index 99c6427fd3..1bccfeb5b6 100644 --- a/src/p_pspr.cpp +++ b/src/p_pspr.cpp @@ -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); + } } } diff --git a/wadsrc/static/actors/constants.txt b/wadsrc/static/actors/constants.txt index 36e58f20b7..c0ce68c045 100644 --- a/wadsrc/static/actors/constants.txt +++ b/wadsrc/static/actors/constants.txt @@ -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; diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index 27e131faf1..ffeaf4cd0e 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -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"