From 42ec2e03603c6dfb27eb79282987e37fb13328bd Mon Sep 17 00:00:00 2001 From: tmp64 Date: Tue, 1 Oct 2024 09:53:15 +0700 Subject: [PATCH] Server: RPG: Fix reloading when laser is on --- src/game/server/rpg.cpp | 37 +++++++++++++++---------------------- src/game/server/weapons.h | 4 ++++ 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/game/server/rpg.cpp b/src/game/server/rpg.cpp index 220c1d92..9d65f328 100644 --- a/src/game/server/rpg.cpp +++ b/src/game/server/rpg.cpp @@ -152,12 +152,7 @@ void CRpgRocket ::RocketTouch(CBaseEntity *pOther) { //ALERT( at_console, "RpgRocket RocketTouch, m_pLauncher: %u\n", GetLauncher() ); - if (GetLauncher()) - { - // my launcher is still around, tell it I'm dead. - GetLauncher()->m_cActiveRockets--; - } - + ReleaseLauncher(); STOP_SOUND(edict(), CHAN_VOICE, "weapons/rocket1.wav"); ExplodeTouch(pOther); } @@ -168,14 +163,7 @@ void CRpgRocket::Explode(TraceResult *pTrace, int bitsDamageType) //ALERT( at_console, "RpgRocket Explode, m_pLauncher: %u\n", GetLauncher() ); STOP_SOUND(edict(), CHAN_VOICE, "weapons/rocket1.wav"); - - if (GetLauncher()) - { - // my launcher is still around, tell it I'm dead. - GetLauncher()->m_cActiveRockets--; - m_hLauncher = nullptr; - } - + ReleaseLauncher(); CGrenade::Explode(pTrace, bitsDamageType); } @@ -228,6 +216,17 @@ CRpg *CRpgRocket::GetLauncher() return (CRpg *)((CBaseEntity *)m_hLauncher); } +void CRpgRocket::ReleaseLauncher() +{ + if (GetLauncher()) + { + // my launcher is still around, tell it I'm dead. + ASSERT(GetLauncher()->m_cActiveRockets > 0); + GetLauncher()->m_cActiveRockets--; + m_hLauncher = nullptr; + } +} + void CRpgRocket ::FollowThink(void) { CBaseEntity *pOther = NULL; @@ -303,12 +302,7 @@ void CRpgRocket ::FollowThink(void) pev->velocity = pev->velocity * 0.2 + vecTarget * flSpeed * 0.798; if (pev->waterlevel == 0 && pev->velocity.Length() < 1500) { - if (GetLauncher()) - { - // my launcher is still around, tell it I'm dead. - GetLauncher()->m_cActiveRockets--; - m_hLauncher = nullptr; - } + ReleaseLauncher(); Detonate(); } } @@ -321,8 +315,7 @@ void CRpgRocket ::FollowThink(void) if (flDistance > 8192.0f || gpGlobals->time - m_flIgniteTime > 6.0f) { //ALERT( at_console, "RPG too far (%f)!\n", flDistance ); - GetLauncher()->m_cActiveRockets--; - m_hLauncher = NULL; + ReleaseLauncher(); } //ALERT( at_console, "%.0f, m_pLauncher: %u, flDistance: %f\n", flSpeed, GetLauncher(), flDistance ); diff --git a/src/game/server/weapons.h b/src/game/server/weapons.h index 3a0f6166..2214572c 100644 --- a/src/game/server/weapons.h +++ b/src/game/server/weapons.h @@ -747,6 +747,10 @@ class CRpgRocket : public CGrenade int m_iTrail; float m_flIgniteTime; EHANDLE m_hLauncher; // pointer back to the launcher that fired me. + +private: + //! Notifies the launcher that this rocket is dead. + void ReleaseLauncher(); }; class CGauss : public CBasePlayerWeapon