lowered weapon shooting fix

This commit is contained in:
celisej567 2025-01-02 23:14:39 +03:00
parent 29985681a1
commit 9027b0bdb7
4 changed files with 94 additions and 81 deletions

View File

@ -1647,118 +1647,127 @@ void CBaseCombatWeapon::ItemPreFrame( void )
//====================================================================================
// WEAPON BEHAVIOUR
//====================================================================================
void CBaseCombatWeapon::ItemPostFrame( void )
void CBaseCombatWeapon::ItemPostFrame(void)
{
CBasePlayer *pOwner = ToBasePlayer( GetOwner() );
CBasePlayer* pOwner = ToBasePlayer(GetOwner());
if (!pOwner)
return;
UpdateAutoFire();
//Track the duration of the fire
//FIXME: Check for IN_ATTACK2 as well?
//FIXME: What if we're calling ItemBusyFrame?
m_fFireDuration = ( pOwner->m_nButtons & IN_ATTACK ) ? ( m_fFireDuration + gpGlobals->frametime ) : 0.0f;
m_fFireDuration = (pOwner->m_nButtons & IN_ATTACK) ? (m_fFireDuration + gpGlobals->frametime) : 0.0f;
if ( UsesClipsForAmmo1() )
if (UsesClipsForAmmo1())
{
CheckReload();
}
bool bFired = false;
// Secondary attack has priority
if ((pOwner->m_nButtons & IN_ATTACK2) && (m_flNextSecondaryAttack <= gpGlobals->curtime))
#ifdef GAME_DLL
if (!m_bLowered)
{
if (UsesSecondaryAmmo() && pOwner->GetAmmoCount(m_iSecondaryAmmoType)<=0 )
{
if (m_flNextEmptySoundTime < gpGlobals->curtime)
{
WeaponSound(EMPTY);
m_flNextSecondaryAttack = m_flNextEmptySoundTime = gpGlobals->curtime + 0.5;
}
}
else if (pOwner->GetWaterLevel() == 3 && m_bAltFiresUnderwater == false)
{
// This weapon doesn't fire underwater
WeaponSound(EMPTY);
m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
return;
}
else
{
// FIXME: This isn't necessarily true if the weapon doesn't have a secondary fire!
// For instance, the crossbow doesn't have a 'real' secondary fire, but it still
// stops the crossbow from firing on the 360 if the player chooses to hold down their
// zoom button. (sjb) Orange Box 7/25/2007
#if !defined(CLIENT_DLL)
if( !IsX360() || !ClassMatches("weapon_crossbow") )
#endif
// Secondary attack has priority
if ((pOwner->m_nButtons & IN_ATTACK2) && (m_flNextSecondaryAttack <= gpGlobals->curtime))
{
if (UsesSecondaryAmmo() && pOwner->GetAmmoCount(m_iSecondaryAmmoType) <= 0)
{
bFired = ShouldBlockPrimaryFire();
}
SecondaryAttack();
// Secondary ammo doesn't have a reload animation
if ( UsesClipsForAmmo2() )
{
// reload clip2 if empty
if (m_iClip2 < 1)
if (m_flNextEmptySoundTime < gpGlobals->curtime)
{
pOwner->RemoveAmmo( 1, m_iSecondaryAmmoType );
m_iClip2 = m_iClip2 + 1;
WeaponSound(EMPTY);
m_flNextSecondaryAttack = m_flNextEmptySoundTime = gpGlobals->curtime + 0.5;
}
}
else if (pOwner->GetWaterLevel() == 3 && m_bAltFiresUnderwater == false)
{
// This weapon doesn't fire underwater
WeaponSound(EMPTY);
m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
return;
}
else
{
// FIXME: This isn't necessarily true if the weapon doesn't have a secondary fire!
// For instance, the crossbow doesn't have a 'real' secondary fire, but it still
// stops the crossbow from firing on the 360 if the player chooses to hold down their
// zoom button. (sjb) Orange Box 7/25/2007
#if !defined(CLIENT_DLL)
if (!IsX360() || !ClassMatches("weapon_crossbow"))
#endif
{
bFired = ShouldBlockPrimaryFire();
}
SecondaryAttack();
// Secondary ammo doesn't have a reload animation
if (UsesClipsForAmmo2())
{
// reload clip2 if empty
if (m_iClip2 < 1)
{
pOwner->RemoveAmmo(1, m_iSecondaryAmmoType);
m_iClip2 = m_iClip2 + 1;
}
}
}
}
}
if ( !bFired && (pOwner->m_nButtons & IN_ATTACK) && (m_flNextPrimaryAttack <= gpGlobals->curtime))
{
// Clip empty? Or out of ammo on a no-clip weapon?
if ( !IsMeleeWeapon() &&
(( UsesClipsForAmmo1() && m_iClip1 <= 0) || ( !UsesClipsForAmmo1() && pOwner->GetAmmoCount(m_iPrimaryAmmoType)<=0 )) )
{
HandleFireOnEmpty();
}
else if (pOwner->GetWaterLevel() == 3 && m_bFiresUnderwater == false)
{
// This weapon doesn't fire underwater
WeaponSound(EMPTY);
m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
return;
}
else
{
//NOTENOTE: There is a bug with this code with regards to the way machine guns catch the leading edge trigger
// on the player hitting the attack key. It relies on the gun catching that case in the same frame.
// However, because the player can also be doing a secondary attack, the edge trigger may be missed.
// We really need to hold onto the edge trigger and only clear the condition when the gun has fired its
// first shot. Right now that's too much of an architecture change -- jdw
// If the firing button was just pressed, or the alt-fire just released, reset the firing time
if ( ( pOwner->m_afButtonPressed & IN_ATTACK ) || ( pOwner->m_afButtonReleased & IN_ATTACK2 ) )
{
m_flNextPrimaryAttack = gpGlobals->curtime;
}
PrimaryAttack();
if ( AutoFiresFullClip() )
if (!bFired && (pOwner->m_nButtons & IN_ATTACK) && (m_flNextPrimaryAttack <= gpGlobals->curtime))
{
// Clip empty? Or out of ammo on a no-clip weapon?
if (!IsMeleeWeapon() &&
((UsesClipsForAmmo1() && m_iClip1 <= 0) || (!UsesClipsForAmmo1() && pOwner->GetAmmoCount(m_iPrimaryAmmoType) <= 0)))
{
m_bFiringWholeClip = true;
HandleFireOnEmpty();
}
else if (pOwner->GetWaterLevel() == 3 && m_bFiresUnderwater == false)
{
// This weapon doesn't fire underwater
WeaponSound(EMPTY);
m_flNextPrimaryAttack = gpGlobals->curtime + 0.2;
return;
}
else
{
//NOTENOTE: There is a bug with this code with regards to the way machine guns catch the leading edge trigger
// on the player hitting the attack key. It relies on the gun catching that case in the same frame.
// However, because the player can also be doing a secondary attack, the edge trigger may be missed.
// We really need to hold onto the edge trigger and only clear the condition when the gun has fired its
// first shot. Right now that's too much of an architecture change -- jdw
// If the firing button was just pressed, or the alt-fire just released, reset the firing time
if ((pOwner->m_afButtonPressed & IN_ATTACK) || (pOwner->m_afButtonReleased & IN_ATTACK2))
{
m_flNextPrimaryAttack = gpGlobals->curtime;
}
PrimaryAttack();
if (AutoFiresFullClip())
{
m_bFiringWholeClip = true;
}
#ifdef CLIENT_DLL
pOwner->SetFiredWeapon( true );
pOwner->SetFiredWeapon(true);
#endif
}
}
#ifdef GAME_DLL
}
#endif
// -----------------------
// Reload pressed / Clip Empty
// -----------------------
if ( ( pOwner->m_nButtons & IN_RELOAD ) && UsesClipsForAmmo1() && !m_bInReload )
if ((pOwner->m_nButtons & IN_RELOAD) && UsesClipsForAmmo1() && !m_bInReload)
{
// reload when reload is pressed, or if no buttons are down and weapon is empty.
Reload();
@ -1771,7 +1780,7 @@ void CBaseCombatWeapon::ItemPostFrame( void )
if (!((pOwner->m_nButtons & IN_ATTACK) || (pOwner->m_nButtons & IN_ATTACK2) || (CanReload() && pOwner->m_nButtons & IN_RELOAD)))
{
// no fire buttons down or reloading
if ( !ReloadOrSwitchWeapons() && ( m_bInReload == false ) )
if (!ReloadOrSwitchWeapons() && (m_bInReload == false))
{
WeaponIdle();
}

View File

@ -526,6 +526,12 @@ private:
CNetworkVar( CBaseCombatCharacterHandle, m_hOwner ); // Player carrying this weapon
protected:
#ifdef GAME_DLL
bool m_bLowered; // Whether the viewmodel is raised or lowered
float m_flRaiseTime; // If lowered, the time we should raise the viewmodel
#endif
#if defined ( TF_CLIENT_DLL ) || defined ( TF_DLL )
// Regulate crit frequency to reduce client-side seed hacking
void AddToCritBucket( float flAmount );

View File

@ -58,8 +58,6 @@ public:
protected:
bool m_bLowered; // Whether the viewmodel is raised or lowered
float m_flRaiseTime; // If lowered, the time we should raise the viewmodel
float m_flHolsterTime; // When the weapon was holstered
};

View File