From 3117a9f99023c2fc46267dd73a77351436ea1795 Mon Sep 17 00:00:00 2001 From: pierow Date: Sun, 20 Aug 2023 17:39:48 -0400 Subject: [PATCH] add cl_weaponswap -refactored from alienbird's autoswap with new features --- main/source/cl_dll/hud.cpp | 1 + main/source/mod/AvHBasePlayerWeapon.cpp | 3 ++- main/source/mod/AvHGamerules.cpp | 32 +++++++++++++++++++++---- main/source/mod/AvHPlayer.h | 5 ++++ 4 files changed, 35 insertions(+), 6 deletions(-) diff --git a/main/source/cl_dll/hud.cpp b/main/source/cl_dll/hud.cpp index befe55df..c23557d7 100644 --- a/main/source/cl_dll/hud.cpp +++ b/main/source/cl_dll/hud.cpp @@ -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 diff --git a/main/source/mod/AvHBasePlayerWeapon.cpp b/main/source/mod/AvHBasePlayerWeapon.cpp index 4f13d5e0..2fdf60de 100644 --- a/main/source/mod/AvHBasePlayerWeapon.cpp +++ b/main/source/mod/AvHBasePlayerWeapon.cpp @@ -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); } diff --git a/main/source/mod/AvHGamerules.cpp b/main/source/mod/AvHGamerules.cpp index 0b05c287..8a5a7e85 100644 --- a/main/source/mod/AvHGamerules.cpp +++ b/main/source/mod/AvHGamerules.cpp @@ -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) @@ -636,10 +636,22 @@ BOOL AvHGamerules::CanHavePlayerItem(CBasePlayer *pPlayer, CBasePlayerItem *pWea int theCurrentFlag = (theWeaponFlags & (PRIMARY_WEAPON | SECONDARY_WEAPON)); CBasePlayerItem* theCurrentItem = NULL; bool theHasWeaponWithFlag = pPlayer->HasItemWithFlag(theCurrentFlag, theCurrentItem); - + if(theHasWeaponWithFlag) { - if(theCurrentItem->iWeight() < pWeapon->iWeight()) + int playerAutoSwapWeapon = 1; + bool newWeaponCanFire = true; + + AvHPlayer* thePlayer = dynamic_cast(pPlayer); + if(thePlayer) + playerAutoSwapWeapon = thePlayer->GetAutoWeapSwapValue(); + + AvHBasePlayerWeapon* theNewWeapon = dynamic_cast(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(pPlayer); + if (thePlayer) { + thePlayer->SetAutoWeapSwapValue(atoi(theAutoWeapSwapValue)); + } + } } void AvHGamerules::ChangePlayerTeam( CBasePlayer *pPlayer, const char *pTeamName, BOOL bKill, BOOL bGib ) diff --git a/main/source/mod/AvHPlayer.h b/main/source/mod/AvHPlayer.h index 4038ccc0..71825390 100644 --- a/main/source/mod/AvHPlayer.h +++ b/main/source/mod/AvHPlayer.h @@ -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