Skip to content

Commit

Permalink
reload while using armory
Browse files Browse the repository at this point in the history
  • Loading branch information
pierow committed Nov 12, 2021
1 parent 6351afa commit ea279fb
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 11 deletions.
19 changes: 17 additions & 2 deletions main/source/mod/AvHBasePlayerWeapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1087,14 +1087,29 @@ bool AvHBasePlayerWeapon::Resupply()
this->m_pPlayer->m_rgAmmo[m_iPrimaryAmmoType] = min(theCurrentPrimary + theAmountToAdd, theMaxPrimary);

const float theDelay = 1.0f;
//bugfix - don't let resupply shorten reload time
this->m_pPlayer->m_flNextAttack = max(this->m_pPlayer->m_flNextAttack,UTIL_WeaponTimeBase() + theDelay);

if (this->m_iId != AVH_WEAPON_SONIC && this->m_iId != AVH_WEAPON_GRENADE_GUN)
{
this->m_flNextPrimaryAttack = max(this->m_flNextPrimaryAttack, (UTIL_WeaponTimeBase() + (theDelay * 2)));// Delay*2 because nextprimary attack gets decremented twice.
}
else
{
bool startingReload = (this->m_pPlayer->pev->button & IN_RELOAD && (this->m_iClip < this->GetClipSize()));
//Some edge cases here but it allows staged reload to start or continue while resupplying and adds resupply delay if not reloading.
if ((this->m_fInSpecialReload == 0 && !startingReload) || (this->m_fInSpecialReload >= 2 && this->m_iClip >= (this->GetClipSize() - 1)))
this->m_flNextPrimaryAttack = max(this->m_flNextPrimaryAttack, (UTIL_WeaponTimeBase() + (theDelay * 2)));
}
this->mTimeOfLastResupply = UTIL_WeaponTimeBase() + theDelay;
}

return theResupplied;
}

float AvHBasePlayerWeapon::GetResupplyTimer() const
{
return this->mTimeOfLastResupply;
}

void AvHBasePlayerWeapon::SendWeaponAnim(int inAnimation, int skiplocal, int body)
{
if(inAnimation >= 0)
Expand Down
2 changes: 2 additions & 0 deletions main/source/mod/AvHBasePlayerWeapon.h
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class AvHBasePlayerWeapon : public CBasePlayerWeapon

virtual float GetRateOfFire() const;

virtual float GetResupplyTimer() const;

virtual char* GetPlayerModel() const;

virtual char* GetPrimeSound() const;
Expand Down
29 changes: 20 additions & 9 deletions main/source/mod/AvHMarineWeapon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,30 @@ void AvHReloadableMarineWeapon::Reload(void)
if (this->m_fInSpecialReload == kSpecialReloadPump)
{
//pump the shotgun to end the reload if attack is pressed during a reload
//ALERT(at_console, "reloadpump3\n");
this->SendWeaponAnim(this->GetEndReloadAnimation());

//float theEndReloadAnimationTime = this->GetEndReloadAnimationTime();
//this->m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + theEndReloadAnimationTime;
//this->m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + theEndReloadAnimationTime;
//this->m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + theEndReloadAnimationTime;

//+1 is the average of the gotoreload and shellreload times previously used to limit primary attack and matches the marine putting his hand on the gun. Actual time is half these values in seconds because timers get decremented twice.
const float theEndReloadTime = 1.0f;

//this->m_pPlayer->m_flNextAttack = UTIL_WeaponTimeBase() + 1.0f;
this->m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + 1.0f;
this->m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + 1.0f;
this->m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + 1.0f;

//Server code is a bug fix for being able to beat the resupply shoot delay timer.
//Only the server tracks resupply time but it has 500ms here to update the client's m_flNextPrimaryAttack. If it's buggy then remove it and the resupply code that adds to primary attack, network the resupply timer, and check it alongside m_flNextPrimaryAttack in AvHBasePlayerWeapon::ProcessValidAttack.
#ifdef AVH_SERVER
float resupplyTimer = this->GetResupplyTimer();
if (resupplyTimer > 0.0f)
{
this->m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + max(theEndReloadTime,(resupplyTimer * 2.0f));
this->m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + max(theEndReloadTime,(resupplyTimer * 2.0f));
this->m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + max(theEndReloadTime,(resupplyTimer * 2.0f));
}
else
#endif
{
this->m_flTimeWeaponIdle = UTIL_WeaponTimeBase() + theEndReloadTime;
this->m_flNextPrimaryAttack = UTIL_WeaponTimeBase() + theEndReloadTime;
this->m_flNextSecondaryAttack = UTIL_WeaponTimeBase() + theEndReloadTime;
}

this->m_pPlayer->SetAnimation(PLAYER_RELOAD_END);
this->m_fInSpecialReload = kSpecialReloadNone;
Expand Down

0 comments on commit ea279fb

Please sign in to comment.