add cl_weaponswap

-refactored from alienbird's autoswap with new features
This commit is contained in:
pierow 2023-08-20 17:39:48 -04:00
parent ff051cab8e
commit 3117a9f990
4 changed files with 35 additions and 6 deletions

View file

@ -219,6 +219,7 @@ void CHud :: Init( void )
CVAR_CREATE( "cl_icong", "149", FCVAR_ARCHIVE);
CVAR_CREATE( "cl_iconb", "221", FCVAR_ARCHIVE);
CVAR_CREATE("cl_weaponswap", "2", FCVAR_ARCHIVE | FCVAR_USERINFO);
m_pSpriteList = NULL;
// Clear any old HUD list

View file

@ -502,7 +502,8 @@ bool AvHBasePlayerWeapon::GetHasMuzzleFlash() const
bool AvHBasePlayerWeapon::GetIsCapableOfFiring() const
{
return !this->UsesAmmo() || (this->m_iClip > 0);
//return !this->UsesAmmo() || (this->m_iClip > 0);
return !this->UsesAmmo() || (this->m_iClip > 0 || this->m_iDefaultAmmo > 0);
}

View file

@ -517,9 +517,9 @@ void AvHGamerules::RewardPlayerForKill(AvHPlayer* inPlayer, CBaseEntity* inTarge
}
else
{
int theMin = BALANCE_VAR(kKillRewardMin);
int theMax = BALANCE_VAR(kKillRewardMax);
theResourceValue = RANDOM_LONG(theMin, theMax);
int theMin = BALANCE_VAR(kKillRewardMin);
int theMax = BALANCE_VAR(kKillRewardMax);
theResourceValue = RANDOM_LONG(theMin, theMax);
}
if(theResourceValue > 0)
@ -639,7 +639,19 @@ BOOL AvHGamerules::CanHavePlayerItem(CBasePlayer *pPlayer, CBasePlayerItem *pWea
if(theHasWeaponWithFlag)
{
if(theCurrentItem->iWeight() < pWeapon->iWeight())
int playerAutoSwapWeapon = 1;
bool newWeaponCanFire = true;
AvHPlayer* thePlayer = dynamic_cast<AvHPlayer*>(pPlayer);
if(thePlayer)
playerAutoSwapWeapon = thePlayer->GetAutoWeapSwapValue();
AvHBasePlayerWeapon* theNewWeapon = dynamic_cast<AvHBasePlayerWeapon*>(pWeapon);
if (theNewWeapon)
newWeaponCanFire = theNewWeapon->GetIsCapableOfFiring();
//if (theCurrentItem->iWeight() < pWeapon->iWeight())
if(theCurrentItem->iWeight() < pWeapon->iWeight() && (playerAutoSwapWeapon == 1 || (playerAutoSwapWeapon == 2 && newWeaponCanFire)))
{
theCanHaveIt = TRUE;
}
@ -851,6 +863,16 @@ void AvHGamerules::ClientKill( edict_t *pEntity )
void AvHGamerules::ClientUserInfoChanged(CBasePlayer *pPlayer, char *infobuffer)
{
// NOTE: Not currently calling down to parent CHalfLifeTeamplay
const char* theAutoWeapSwapValue = g_engfuncs.pfnInfoKeyValue(infobuffer, "cl_weaponswap");
if (theAutoWeapSwapValue) {
AvHPlayer* thePlayer = dynamic_cast<AvHPlayer*>(pPlayer);
if (thePlayer) {
thePlayer->SetAutoWeapSwapValue(atoi(theAutoWeapSwapValue));
}
}
}
void AvHGamerules::ChangePlayerTeam( CBasePlayer *pPlayer, const char *pTeamName, BOOL bKill, BOOL bGib )

View file

@ -477,6 +477,9 @@ public:
void SetUsedKilled(bool bKilled ) { mUsedKilled = bKilled; }
void ClearOrders() { mClientOrders.clear(); }
int GetAutoWeapSwapValue() { return mAutoWeapSwapValue; }
void SetAutoWeapSwapValue(int autoSwap) { mAutoWeapSwapValue = autoSwap; }
// : 0000953
bool JoinTeamCooledDown(float inCoolDownTime);
//
@ -861,6 +864,8 @@ private:
bool mUsedKilled;
int mAutoWeapSwapValue;
//TODO: remove this system from AvHPlayer and create an
// explicit balance forwarding class registered to each
// client instead. This functionality is tangential to