Skip to content

Commit

Permalink
Fix Hornet gun not playing attack animation when firing after recharg…
Browse files Browse the repository at this point in the history
…ing the only available ammo

Resolves #530
  • Loading branch information
SamVanheer committed Aug 31, 2023
1 parent 6df33d5 commit f04365c
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/game/server/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1939,6 +1939,8 @@ int GetWeaponData(edict_t* player, weapon_data_t* info)
if (!pl)
return 1;

pl->m_LastWeaponDataUpdateTime = gpGlobals->time;

// go through all of the weapons and make a list of the ones to pack
for (i = 0; i < MAX_WEAPON_SLOTS; i++)
{
Expand Down
3 changes: 3 additions & 0 deletions src/game/server/entities/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,9 @@ class CBasePlayer : public CBaseMonster
// Not saved, used to update client.
std::uint64_t m_ClientWeaponBits;

// Not saved, tracks the last time the engine called GetWeaponData.
float m_LastWeaponDataUpdateTime{0};

std::uint32_t m_HudFlags = 0;

// shared ammo slots
Expand Down
25 changes: 24 additions & 1 deletion src/game/shared/entities/items/weapons/CHgun.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ void CHgun::PrimaryAttack()
m_flRechargeTime = gpGlobals->time + 0.5;
#endif

const bool wasLastShot = m_pPlayer->GetAmmoCountByIndex(m_iPrimaryAmmoType) == 1;

m_pPlayer->AdjustAmmoByIndex(m_iPrimaryAmmoType, -1);

m_pPlayer->m_iWeaponVolume = QUIET_GUN_VOLUME;
Expand All @@ -133,8 +135,13 @@ void CHgun::PrimaryAttack()
flags = 0;
#endif

PLAYBACK_EVENT_FULL(flags, m_pPlayer->edict(), m_usHornetFire, 0.0, g_vecZero, g_vecZero, 0.0, 0.0, 0, 0, 0, 0);
if (wasLastShot &&
m_pPlayer->m_LastWeaponDataUpdateTime != 0 && m_pPlayer->m_LastWeaponDataUpdateTime < m_LastRechargeTime)
{
flags &= ~FEV_NOTHOST;
}

PLAYBACK_EVENT_FULL(flags, m_pPlayer->edict(), m_usHornetFire, 0.0, g_vecZero, g_vecZero, 0.0, 0.0, 0, 0, 0, 0);


// player "shoot" animation
Expand Down Expand Up @@ -220,6 +227,14 @@ void CHgun::SecondaryAttack()
flags = 0;
#endif

const bool wasLastShot = m_pPlayer->GetAmmoCountByIndex(m_iPrimaryAmmoType) == 1;

if (wasLastShot &&
m_pPlayer->m_LastWeaponDataUpdateTime != 0 && m_pPlayer->m_LastWeaponDataUpdateTime < m_LastRechargeTime)
{
flags &= ~FEV_NOTHOST;
}

PLAYBACK_EVENT_FULL(flags, m_pPlayer->edict(), m_usHornetFire, 0.0, g_vecZero, g_vecZero, 0.0, 0.0, 0, 0, 0, 0);

m_pPlayer->AdjustAmmoByIndex(m_iPrimaryAmmoType, -1);
Expand All @@ -241,13 +256,21 @@ void CHgun::Reload()
if (m_pPlayer->GetAmmoCountByIndex(m_iPrimaryAmmoType) >= HORNET_MAX_CARRY)
return;

bool updatedAmmo = false;

while (ammoCount < HORNET_MAX_CARRY && m_flRechargeTime < gpGlobals->time)
{
++ammoCount;
m_flRechargeTime += 0.5;
updatedAmmo = true;
}

m_pPlayer->SetAmmoCountByIndex(m_iPrimaryAmmoType, ammoCount);

if (updatedAmmo)
{
m_LastRechargeTime = gpGlobals->time;
}
#endif
}

Expand Down
1 change: 1 addition & 0 deletions src/game/shared/entities/items/weapons/CHgun.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class CHgun : public CBasePlayerWeapon
float m_flNextAnimTime;

float m_flRechargeTime;
float m_LastRechargeTime;

int m_iFirePhase = 0; // don't save me.

Expand Down

0 comments on commit f04365c

Please sign in to comment.