From 88161eac14e30a782a7819792269542e6eed87c1 Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin Date: Sun, 3 Nov 2019 22:59:33 +0500 Subject: [PATCH] Add "cl_autowepswitch" cvar implementation. --- cl_dll/hud.cpp | 1 + dlls/client.cpp | 1 + dlls/gamerules.cpp | 5 +++++ dlls/gamerules.h | 2 +- dlls/multiplay_gamerules.cpp | 5 +++++ dlls/player.cpp | 14 ++++++++++++++ dlls/player.h | 6 +++++- dlls/singleplay_gamerules.cpp | 5 +++++ dlls/teamplay_gamerules.cpp | 2 ++ 9 files changed, 39 insertions(+), 2 deletions(-) diff --git a/cl_dll/hud.cpp b/cl_dll/hud.cpp index 62c32b41..d408c415 100644 --- a/cl_dll/hud.cpp +++ b/cl_dll/hud.cpp @@ -191,6 +191,7 @@ void CHud::Init( void ) m_iFOV = 0; CVAR_CREATE( "zoom_sensitivity_ratio", "1.2", 0 ); + CVAR_CREATE( "cl_autowepswitch", "1", FCVAR_ARCHIVE | FCVAR_USERINFO ); default_fov = CVAR_CREATE( "default_fov", "90", 0 ); m_pCvarStealMouse = CVAR_CREATE( "hud_capturemouse", "1", FCVAR_ARCHIVE ); m_pCvarDraw = CVAR_CREATE( "hud_draw", "1", FCVAR_ARCHIVE ); diff --git a/dlls/client.cpp b/dlls/client.cpp index f96302d0..a8031df0 100644 --- a/dlls/client.cpp +++ b/dlls/client.cpp @@ -196,6 +196,7 @@ void ClientPutInServer( edict_t *pEntity ) pPlayer = GetClassPtr( (CBasePlayer *)pev ); pPlayer->SetCustomDecalFrames( -1 ); // Assume none; + pPlayer->SetPrefsFromUserinfo( g_engfuncs.pfnGetInfoKeyBuffer( pEntity ) ); // Allocate a CBasePlayer for pev, and call spawn pPlayer->Spawn(); diff --git a/dlls/gamerules.cpp b/dlls/gamerules.cpp index f59788c4..bfbbf59e 100644 --- a/dlls/gamerules.cpp +++ b/dlls/gamerules.cpp @@ -303,6 +303,11 @@ void CGameRules::RefreshSkillData ( void ) gSkillData.plrArm = GetSkillCvar( "sk_player_arm" ); } +void CGameRules::ClientUserInfoChanged( CBasePlayer *pPlayer, char *infobuffer ) +{ + pPlayer->SetPrefsFromUserinfo( infobuffer ); +} + //========================================================= // instantiate the proper game rules object //========================================================= diff --git a/dlls/gamerules.h b/dlls/gamerules.h index 04c6eea5..22c73a47 100644 --- a/dlls/gamerules.h +++ b/dlls/gamerules.h @@ -98,7 +98,7 @@ public: virtual BOOL AllowAutoTargetCrosshair( void ) { return TRUE; }; virtual BOOL ClientCommand( CBasePlayer *pPlayer, const char *pcmd ) { return FALSE; }; // handles the user commands; returns TRUE if command handled properly - virtual void ClientUserInfoChanged( CBasePlayer *pPlayer, char *infobuffer ) {} // the player has changed userinfo; can change it now + virtual void ClientUserInfoChanged( CBasePlayer *pPlayer, char *infobuffer ); // the player has changed userinfo; can change it now // Client kills/scoring virtual int IPointsForKill( CBasePlayer *pAttacker, CBasePlayer *pKilled ) = 0;// how many points do I award whoever kills this player? diff --git a/dlls/multiplay_gamerules.cpp b/dlls/multiplay_gamerules.cpp index 8305a07f..90dc4f3b 100644 --- a/dlls/multiplay_gamerules.cpp +++ b/dlls/multiplay_gamerules.cpp @@ -319,6 +319,11 @@ BOOL CHalfLifeMultiplay::FShouldSwitchWeapon( CBasePlayer *pPlayer, CBasePlayerI return TRUE; } + if( !pPlayer->m_iAutoWepSwitch ) + { + return FALSE; + } + if( !pPlayer->m_pActiveItem->CanHolster() ) { // can't put away the active item. diff --git a/dlls/player.cpp b/dlls/player.cpp index 43d1d28e..a47fda24 100644 --- a/dlls/player.cpp +++ b/dlls/player.cpp @@ -2876,6 +2876,8 @@ void CBasePlayer::Spawn( void ) m_flNextChatTime = gpGlobals->time; + m_iAutoWepSwitch = 1; + g_pGameRules->PlayerSpawn( this ); } @@ -4158,6 +4160,18 @@ int CBasePlayer::Illumination( void ) return iIllum; } +void CBasePlayer::SetPrefsFromUserinfo( char *infobuffer ) +{ + const char *pszKeyVal; + + pszKeyVal = g_engfuncs.pfnInfoKeyValue( infobuffer, "cl_autowepswitch" ); + + if( pszKeyVal[0] != '\0' ) + m_iAutoWepSwitch = atoi( pszKeyVal ); + else + m_iAutoWepSwitch = 1; +} + void CBasePlayer::EnableControl( BOOL fControl ) { if( !fControl ) diff --git a/dlls/player.h b/dlls/player.h index 15f1538a..571a025d 100644 --- a/dlls/player.h +++ b/dlls/player.h @@ -312,7 +312,7 @@ public: float m_flPlayAftershock; float m_flNextAmmoBurn;// while charging, when to absorb another unit of player's ammo? - //Player ID + // Player ID void InitStatusBar( void ); void UpdateStatusBar( void ); int m_izSBarState[SBAR_END]; @@ -321,8 +321,12 @@ public: char m_SbarString0[SBAR_STRING_SIZE]; char m_SbarString1[SBAR_STRING_SIZE]; + void SetPrefsFromUserinfo( char *infobuffer ); + float m_flNextChatTime; + int m_iAutoWepSwitch; + Vector m_vecLastViewAngles; bool m_bSentBhopcap; // If false, the player just joined and needs a bhopcap message. diff --git a/dlls/singleplay_gamerules.cpp b/dlls/singleplay_gamerules.cpp index 9a46e722..7f722e30 100644 --- a/dlls/singleplay_gamerules.cpp +++ b/dlls/singleplay_gamerules.cpp @@ -75,6 +75,11 @@ BOOL CHalfLifeRules::FShouldSwitchWeapon( CBasePlayer *pPlayer, CBasePlayerItem return TRUE; } + if( !pPlayer->m_iAutoWepSwitch ) + { + return FALSE; + } + if( !pPlayer->m_pActiveItem->CanHolster() ) { return FALSE; diff --git a/dlls/teamplay_gamerules.cpp b/dlls/teamplay_gamerules.cpp index d3b5c5e3..ea733fa4 100644 --- a/dlls/teamplay_gamerules.cpp +++ b/dlls/teamplay_gamerules.cpp @@ -357,6 +357,8 @@ void CHalfLifeTeamplay::ClientUserInfoChanged( CBasePlayer *pPlayer, char *infob // recound stuff RecountTeams( TRUE ); + + pPlayer->SetPrefsFromUserinfo( infobuffer ); } extern int gmsgDeathMsg;