Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/game/shared/tf/tf_weaponbase_gun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions src/game/shared/tf/tf_weaponbase_gun.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 );

Expand Down