diff --git a/game/neo/scripts/game_sounds_weapons.txt b/game/neo/scripts/game_sounds_weapons.txt index 73d25518bd..41d27c8024 100644 --- a/game/neo/scripts/game_sounds_weapons.txt +++ b/game/neo/scripts/game_sounds_weapons.txt @@ -729,6 +729,35 @@ "wave" "weapons/srs/srs_reload.wav" } +// SRS reload in per-step pieces (sv_neo_reload_experimental). + +"weapon_srs.reload_unload" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/srs/srs_reload_unload.wav" +} + +"weapon_srs.reload_load" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/srs/srs_reload_load.wav" +} + +"weapon_srs.reload_cycle" +{ + "channel" "CHAN_ITEM" + "soundlevel" "SNDLVL_NORM" + "volume" "1.0" + "pitch" "PITCH_NORM" + "wave" ")weapons/srs/srs_reload_cycle.wav" +} + //------------------- "weapon_srs.npc_reload" diff --git a/game/neo/scripts/weapon_srs.txt b/game/neo/scripts/weapon_srs.txt index 3538bca8ef..9a20b07450 100644 --- a/game/neo/scripts/weapon_srs.txt +++ b/game/neo/scripts/weapon_srs.txt @@ -1,3 +1,5 @@ +#base "weapon_srs_reload_phases.txt" + // SRS WeaponData @@ -16,6 +18,11 @@ WeaponData "Penetration" "65.0" "CycleTime" "1.4" "ReloadReadyBeforeEnd" "0.583" // the reload is done at the last reload click, this long before its animation ends + + // Reload phases (sv_neo_reload_experimental): the rows come from neoAssets, timed from its Blender markers + "ReloadPhases" {} + // Chamber capacity is gameplay data; the phase timing comes from neoAssets. + "ChamberedRound" "1" "TPMuzzleFlashScale" "0.25" diff --git a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h index 469bbab87c..8be431e901 100644 --- a/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h +++ b/src/game/shared/neo/weapons/weapon_neobasecombatweapon.h @@ -305,10 +305,10 @@ class CNEOBaseCombatWeapon : public CBaseHL2MPCombatWeapon bool IsReloadPastUnload() const; // Clip1 includes the chambered round; the magazine can hold GetMaxClip1() more. - bool HasChamberSlot() const; - bool IsRoundChambered() const; - int RoundsInMagazine() const; - int MagazineCapacity() const; + virtual bool HasChamberSlot() const; + virtual bool IsRoundChambered() const; + virtual int RoundsInMagazine() const; + virtual int MagazineCapacity() const; protected: bool IsReloadPhaseSystemEnabled() const; diff --git a/src/game/shared/neo/weapons/weapon_srs.cpp b/src/game/shared/neo/weapons/weapon_srs.cpp index ae21ebf7ee..0a6eb32911 100644 --- a/src/game/shared/neo/weapons/weapon_srs.cpp +++ b/src/game/shared/neo/weapons/weapon_srs.cpp @@ -10,8 +10,12 @@ BEGIN_NETWORK_TABLE(CWeaponSRS, DT_WeaponSRS) DEFINE_NEO_BASE_WEP_NETWORK_TABLE #ifdef CLIENT_DLL RecvPropBool(RECVINFO(m_bNeedsBolting)), + RecvPropTime(RECVINFO(m_flBoltHomeTime)), + RecvPropTime(RECVINFO(m_flBoltStartTime)), #else SendPropBool(SENDINFO(m_bNeedsBolting)), + SendPropTime(SENDINFO(m_flBoltHomeTime)), + SendPropTime(SENDINFO(m_flBoltStartTime)), #endif END_NETWORK_TABLE() @@ -19,6 +23,8 @@ END_NETWORK_TABLE() BEGIN_PREDICTION_DATA(CWeaponSRS) DEFINE_NEO_BASE_WEP_PREDICTION DEFINE_PRED_FIELD(m_bNeedsBolting, FIELD_BOOLEAN, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD(m_flBoltHomeTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE), + DEFINE_PRED_FIELD(m_flBoltStartTime, FIELD_FLOAT, FTYPEDESC_INSENDTABLE), END_PREDICTION_DATA() #endif @@ -28,6 +34,9 @@ LINK_ENTITY_TO_CLASS(weapon_srs, CWeaponSRS); PRECACHE_WEAPON_REGISTER(weapon_srs); +// The bolt cycle after a shot; the 3_cycle row of its phase table gives when the bolt is home with the next round +static constexpr const char *VM_SEQ_CHARGE = "charge"; + CWeaponSRS::CWeaponSRS() { m_flSoonestAttack = gpGlobals->curtime; @@ -35,6 +44,8 @@ CWeaponSRS::CWeaponSRS() m_nNumShotsFired = 0; m_bNeedsBolting = false; + m_flBoltHomeTime = 0.0f; + m_flBoltStartTime = 0.0f; m_weaponSeeds = { "srspx", @@ -52,6 +63,11 @@ void CWeaponSRS::PrimaryAttack() return BaseClass::PrimaryAttack(); } + if (BoltPhasesBlockShot()) + { + return; + } + const bool tryingToShootTooFast = (gpGlobals->curtime < m_flLastAttackTime + GetFireRate()); if (tryingToShootTooFast) @@ -60,6 +76,7 @@ void CWeaponSRS::PrimaryAttack() } m_bNeedsBolting = true; + BoltPhasesOnShot(); BaseClass::PrimaryAttack(); } @@ -70,6 +87,11 @@ void CWeaponSRS::ItemPreFrame() return BaseClass::ItemPreFrame(); } + if (BoltPhasesDelayCycle()) + { + return BaseClass::ItemPreFrame(); + } + if (m_flLastAttackTime + 0.08f <= gpGlobals->curtime) { // Primary attack animation finished, begin chambering a round if (auto* pOwner = ToNEOPlayer(GetOwner())) { @@ -83,6 +105,7 @@ void CWeaponSRS::ItemPreFrame() SendWeaponAnim(ACT_VM_PULLBACK); WeaponSound(SPECIAL1); m_bNeedsBolting = false; + BoltPhasesOnCycle(); } BaseClass::ItemPreFrame(); @@ -92,20 +115,141 @@ bool CWeaponSRS::Deploy() { // This is on purpose; the player is allowed to cancel the bolting animation // with a quick-switch input. - m_bNeedsBolting = false; + m_bNeedsBolting = BoltPhasesKeepCycle(); - return BaseClass::Deploy(); + const bool bDeployed = BaseClass::Deploy(); + BoltPhasesOnDeploy(); + return bDeployed; } bool CWeaponSRS::Reload() { + if (BoltPhasesBlockReload()) + { + return false; + } + // The reloading animation already contains the bolting motion; // we don't want to bolt twice. m_bNeedsBolting = false; + BoltPhasesOnReload(); return BaseClass::Reload(); } +bool CWeaponSRS::IsBoltPending() const +{ + return m_bNeedsBolting || gpGlobals->curtime < m_flBoltHomeTime; +} + +bool CWeaponSRS::Holster(CBaseCombatWeapon *pSwitchingTo) +{ + BoltPhasesOnHolster(); + return BaseClass::Holster(pSwitchingTo); +} + +bool CWeaponSRS::IsRoundChambered() const +{ + if (HasChamberSlot() && IsBoltPending()) + { + return false; + } + + return BaseClass::IsRoundChambered(); +} + +// An unchambered gun completes its bolt cycle before it can fire; the press is ignored +bool CWeaponSRS::BoltPhasesBlockShot() const +{ + return HasChamberSlot() && IsBoltPending(); +} + +// With rounds left, the chamber holds the shot's spent case until the bolt is home. A reload before then would +// count the case as a chambered round, at the unload and as the round kept through the magazine change +bool CWeaponSRS::BoltPhasesBlockReload() const +{ + return HasChamberSlot() && IsBoltPending() && m_iClip1 > 0; +} + +void CWeaponSRS::BoltPhasesOnShot() +{ + if (!IsReloadPhaseSystemEnabled()) + { + return; + } + + m_flBoltHomeTime = 0.0f; + m_flBoltStartTime = 0.0f; +} + +// A bolt cycle resumed by a draw waits for the draw to end +bool CWeaponSRS::BoltPhasesDelayCycle() const +{ + return IsReloadPhaseSystemEnabled() && m_flBoltStartTime > gpGlobals->curtime; +} + +// The round counts as chambered once the bolt is home +void CWeaponSRS::BoltPhasesOnCycle() +{ + if (!IsReloadPhaseSystemEnabled()) + { + return; + } + + const CNEOWeaponInfo &info = GetNEOWpnData(); + const int iTable = info.FindReloadTable(VM_SEQ_CHARGE); + if (iTable >= 0 && info.m_reloadTables[iTable].iNumRows > 0) + { + m_flBoltHomeTime = gpGlobals->curtime + info.m_reloadTables[iTable].rows[0].flAmmo; + } +} + +// The round does not count as chambered before the bolt is home, so a cut-short cycle resumes after the draw. +// Returns whether the draw keeps the cycle +bool CWeaponSRS::BoltPhasesKeepCycle() +{ + if (!IsReloadPhaseSystemEnabled()) + { + return false; + } + + m_flBoltHomeTime = 0.0f; + m_flBoltStartTime = 0.0f; + return m_bNeedsBolting; +} + +void CWeaponSRS::BoltPhasesOnDeploy() +{ + if (!IsReloadPhaseSystemEnabled() || !m_bNeedsBolting) + { + return; + } + + m_flBoltStartTime = m_flNextPrimaryAttack; +} + +void CWeaponSRS::BoltPhasesOnReload() +{ + if (!IsReloadPhaseSystemEnabled()) + { + return; + } + + m_flBoltHomeTime = 0.0f; +} + +// Time passes while holstered, so note that the bolt is not home for the next draw +void CWeaponSRS::BoltPhasesOnHolster() +{ + if (!IsReloadPhaseSystemEnabled() || !IsBoltPending()) + { + return; + } + + m_bNeedsBolting = true; + m_flBoltHomeTime = 0.0f; +} + bool CWeaponSRS::CanBePickedUpByClass(int classId) { return classId != NEO_CLASS_JUGGERNAUT; diff --git a/src/game/shared/neo/weapons/weapon_srs.h b/src/game/shared/neo/weapons/weapon_srs.h index b6c632f153..a7ef6f9422 100644 --- a/src/game/shared/neo/weapons/weapon_srs.h +++ b/src/game/shared/neo/weapons/weapon_srs.h @@ -37,6 +37,8 @@ class CWeaponSRS : public CNEOBaseCombatWeapon virtual bool Deploy() override; virtual void PrimaryAttack() override; virtual bool Reload(void) OVERRIDE; + virtual bool Holster(CBaseCombatWeapon *pSwitchingTo) OVERRIDE; + bool IsRoundChambered() const OVERRIDE; NEO_WEP_BITS_UNDERLYING_TYPE WeaponIndex() const override { return NEO_WIDX_SRS; } virtual NEO_WEP_BITS_UNDERLYING_TYPE GetNeoWepBits(void) const override { return NEO_WEP_SRS | NEO_WEP_SCOPEDWEAPON | NEO_WEP_FIREARM; } @@ -53,7 +55,25 @@ class CWeaponSRS : public CNEOBaseCombatWeapon private: CWeaponSRS(const CWeaponSRS &other); + // Whether the bolt cycle after a shot has not finished yet + bool IsBoltPending() const; + + // Bolt phases (sv_neo_reload_experimental); each hook does nothing with the flag off + bool BoltPhasesBlockShot() const; + bool BoltPhasesBlockReload() const; + void BoltPhasesOnShot(); + bool BoltPhasesDelayCycle() const; + void BoltPhasesOnCycle(); + bool BoltPhasesKeepCycle(); + void BoltPhasesOnDeploy(); + void BoltPhasesOnReload(); + void BoltPhasesOnHolster(); + CNetworkVar(bool, m_bNeedsBolting); + // The bolt is home, and a round chambered, at this time; 0: no bolt cycle is running + CNetworkVar(float, m_flBoltHomeTime); + // A bolt cycle resumed by a draw starts no earlier than this time + CNetworkVar(float, m_flBoltStartTime); }; #endif // NEO_WEAPON_SRS_H