From 4ae58b4170bc0f05e27baea53262ccbfc22e7fd4 Mon Sep 17 00:00:00 2001 From: Night Owl Date: Sun, 2 Jul 2017 05:37:14 +0500 Subject: [PATCH] Fix weapon reload bug. Use macros instead of magic numbers. --- dlls/crossbow.cpp | 4 ++-- dlls/egon.cpp | 2 +- dlls/glock.cpp | 8 ++++---- dlls/python.cpp | 4 ++-- dlls/rpg.cpp | 9 ++------- dlls/shotgun.cpp | 2 +- 6 files changed, 12 insertions(+), 17 deletions(-) diff --git a/dlls/crossbow.cpp b/dlls/crossbow.cpp index d749c785..12d0ff8c 100644 --- a/dlls/crossbow.cpp +++ b/dlls/crossbow.cpp @@ -481,7 +481,7 @@ void CCrossbow::SecondaryAttack() void CCrossbow::Reload( void ) { - if( m_pPlayer->ammo_bolts <= 0 ) + if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 || m_iClip == CROSSBOW_MAX_CLIP ) return; if( m_pPlayer->pev->fov != 0 ) @@ -489,7 +489,7 @@ void CCrossbow::Reload( void ) SecondaryAttack(); } - if( DefaultReload( 5, CROSSBOW_RELOAD, 4.5 ) ) + if( DefaultReload( CROSSBOW_MAX_CLIP, CROSSBOW_RELOAD, 4.5 ) ) { EMIT_SOUND_DYN( ENT( m_pPlayer->pev ), CHAN_ITEM, "weapons/xbow_reload1.wav", RANDOM_FLOAT( 0.95, 1.0 ), ATTN_NORM, 0, 93 + RANDOM_LONG( 0, 0xF ) ); } diff --git a/dlls/egon.cpp b/dlls/egon.cpp index 9a4de49b..b83c9086 100644 --- a/dlls/egon.cpp +++ b/dlls/egon.cpp @@ -143,7 +143,7 @@ float CEgon::GetDischargeInterval( void ) BOOL CEgon::HasAmmo( void ) { - if( m_pPlayer->ammo_uranium <= 0 ) + if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 ) return FALSE; return TRUE; diff --git a/dlls/glock.cpp b/dlls/glock.cpp index 1f4517e7..4e679750 100644 --- a/dlls/glock.cpp +++ b/dlls/glock.cpp @@ -169,15 +169,15 @@ void CGlock::GlockFire( float flSpread, float flCycleTime, BOOL fUseAutoAim ) void CGlock::Reload( void ) { - if( m_pPlayer->ammo_9mm <= 0 ) - return; + if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 || m_iClip == GLOCK_MAX_CLIP ) + return; int iResult; if( m_iClip == 0 ) - iResult = DefaultReload( 17, GLOCK_RELOAD, 1.5 ); + iResult = DefaultReload( GLOCK_MAX_CLIP, GLOCK_RELOAD, 1.5 ); else - iResult = DefaultReload( 17, GLOCK_RELOAD_NOT_EMPTY, 1.5 ); + iResult = DefaultReload( GLOCK_MAX_CLIP, GLOCK_RELOAD_NOT_EMPTY, 1.5 ); if( iResult ) { diff --git a/dlls/python.cpp b/dlls/python.cpp index 7bb71325..b7e48386 100644 --- a/dlls/python.cpp +++ b/dlls/python.cpp @@ -212,7 +212,7 @@ void CPython::PrimaryAttack() void CPython::Reload( void ) { - if( m_pPlayer->ammo_357 <= 0 ) + if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 || m_iClip == PYTHON_MAX_CLIP ) return; if( m_pPlayer->pev->fov != 0 ) @@ -227,7 +227,7 @@ void CPython::Reload( void ) #else bUseScope = g_pGameRules->IsMultiplayer(); #endif - if( DefaultReload( 6, PYTHON_RELOAD, 2.0, bUseScope ) ) + if( DefaultReload( PYTHON_MAX_CLIP, PYTHON_RELOAD, 2.0, bUseScope ) ) { m_flSoundDelay = 1.5; } diff --git a/dlls/rpg.cpp b/dlls/rpg.cpp index 95c9132a..fb2b39c8 100644 --- a/dlls/rpg.cpp +++ b/dlls/rpg.cpp @@ -278,13 +278,8 @@ void CRpg::Reload( void ) { int iResult = 0; - if( m_iClip == 1 ) - { - // don't bother with any of this if don't need to reload. - return; - } - - if( m_pPlayer->ammo_rockets <= 0 ) + // don't bother with any of this if don't need to reload. + if( m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] <= 0 || m_iClip == RPG_MAX_CLIP ) return; // because the RPG waits to autoreload when no missiles are active while the LTD is on, the diff --git a/dlls/shotgun.cpp b/dlls/shotgun.cpp index 595561e2..d6be007a 100644 --- a/dlls/shotgun.cpp +++ b/dlls/shotgun.cpp @@ -320,7 +320,7 @@ void CShotgun::WeaponIdle( void ) } else if( m_fInSpecialReload != 0 ) { - if( m_iClip != 8 && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] ) + if( m_iClip != SHOTGUN_MAX_CLIP && m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] ) { Reload(); }