diff --git a/src/game/shared/tf/tf_weaponbase_gun.cpp b/src/game/shared/tf/tf_weaponbase_gun.cpp index 58d0dc2707..050c0a8fd0 100644 --- a/src/game/shared/tf/tf_weaponbase_gun.cpp +++ b/src/game/shared/tf/tf_weaponbase_gun.cpp @@ -125,7 +125,7 @@ void CTFWeaponBaseGun::PrimaryAttack( void ) if ( GetOwner() && GetAmmoPerShot() > GetOwner()->GetAmmoCount( m_iPrimaryAmmoType ) ) { WeaponSound( EMPTY ); - m_flNextPrimaryAttack = gpGlobals->curtime + flFireDelay; + m_flNextPrimaryAttack = GetCorrectedNextAttackTime( m_flNextPrimaryAttack, flFireDelay ); return; } } @@ -181,7 +181,7 @@ void CTFWeaponBaseGun::PrimaryAttack( void ) } // Set next attack times. - m_flNextPrimaryAttack = gpGlobals->curtime + flFireDelay; + m_flNextPrimaryAttack = GetCorrectedNextAttackTime( m_flNextPrimaryAttack, flFireDelay ); // Don't push out secondary attack, because our secondary fire // systems are all separate from primary fire (sniper zooming, demoman pipebomb detonating, etc) @@ -213,7 +213,20 @@ void CTFWeaponBaseGun::PrimaryAttack( void ) } pPlayer->m_Shared.OnAttack(); -} +} + +//----------------------------------------------------------------------------- +// Purpose: Calculates the next attack time that averages the attack interval correctly for continuous fire +//----------------------------------------------------------------------------- +float CTFWeaponBaseGun::GetCorrectedNextAttackTime( float flAttackTime, float flFireDelay ) const +{ + float flDiff = gpGlobals->curtime - flAttackTime; + + if ( flDiff < 0.f || flDiff > TICK_INTERVAL ) + return gpGlobals->curtime + flFireDelay; + + return flAttackTime + flFireDelay; +} //----------------------------------------------------------------------------- // Purpose: diff --git a/src/game/shared/tf/tf_weaponbase_gun.h b/src/game/shared/tf/tf_weaponbase_gun.h index e4c09ba730..d7aa764b98 100644 --- a/src/game/shared/tf/tf_weaponbase_gun.h +++ b/src/game/shared/tf/tf_weaponbase_gun.h @@ -54,6 +54,8 @@ class CTFWeaponBaseGun : public CTFWeaponBase virtual void SecondaryAttack( void ); virtual bool Holster( CBaseCombatWeapon *pSwitchingTo ); + float GetCorrectedNextAttackTime( float flAttackTime, float flFireDelay ) const; + // Derived classes call this to fire a bullet. //bool TFBaseGunFire( void );