From c0625ca8d2de95e2f5232f59dd4e930ba1349811 Mon Sep 17 00:00:00 2001 From: Dexter Date: Sun, 3 Nov 2013 23:49:42 +0000 Subject: [PATCH] make class limits respect map (lua)/cvar if set, or min if both set --- mp/src/game/shared/ff/ff_sh_team_manager.cpp | 159 ++++++++++--------- mp/src/game/shared/ff/ff_sh_team_manager.h | 3 +- 2 files changed, 90 insertions(+), 72 deletions(-) diff --git a/mp/src/game/shared/ff/ff_sh_team_manager.cpp b/mp/src/game/shared/ff/ff_sh_team_manager.cpp index 53f8f953..28da8cdc 100644 --- a/mp/src/game/shared/ff/ff_sh_team_manager.cpp +++ b/mp/src/game/shared/ff/ff_sh_team_manager.cpp @@ -9,6 +9,72 @@ #include "tier0/memdbgon.h" +#ifdef GAME_DLL + +static void ClassRestrictionChange( IConVar *var, const char *pOldString, float fOldVal ); + +// we gotta do this anyway for other classes to use em directly without having to lookup +ConVar cr_scout( "cr_scout", "0", 0, "Max number of scouts", ClassRestrictionChange ); +ConVar cr_sniper( "cr_sniper", "0", 0, "Max number of snipers", ClassRestrictionChange ); +ConVar cr_soldier( "cr_soldier", "0", 0, "Max number of soldiers", ClassRestrictionChange ); +ConVar cr_demoman( "cr_demoman", "0", 0, "Max number of demoman", ClassRestrictionChange ); +ConVar cr_medic( "cr_medic", "0", 0, "Max number of medic", ClassRestrictionChange ); +ConVar cr_hwguy( "cr_hwguy", "0", 0, "Max number of hwguy", ClassRestrictionChange ); +ConVar cr_pyro( "cr_pyro", "0", 0, "Max number of pyro", ClassRestrictionChange ); +ConVar cr_spy( "cr_spy", "0", 0, "Max number of spy", ClassRestrictionChange ); +ConVar cr_engineer( "cr_engineer", "0", 0, "Max number of engineer", ClassRestrictionChange ); +ConVar cr_civilian( "cr_civilian", "0", 0, "Max number of engineer", ClassRestrictionChange ); + +//static CUtlDict classCvarToIndexDict; +// do this so we can find correct idx to pass to team manager +// (from old CFFTeam::UpdateTeamLimits indices) +static ConVar classRestrictionCvars[] = +{ + cr_scout, + cr_sniper, + cr_soldier, + cr_demoman, + cr_medic, + cr_hwguy, + cr_pyro, + cr_spy, + cr_engineer, + cr_civilian, +}; + +// Need to update the real class limits for this map +static void ClassRestrictionChange( IConVar *var, const char *pOldString, float fOldVal ) +{ + // Update the team limits (skip unassigned and spec, they dont need limits applied ) + for ( int i = TEAM_SPECTATOR + 1; i < g_Teams.Count(); i++ ) + { + CFF_SH_TeamManager *pTeam = GetGlobalFFTeam( i ); + if ( !pTeam ) + return; + + ConVar *conVar = static_cast(var); + if ( !conVar ) + return; + + int idx = -1; + for ( int i = 0; i < CLASS_COUNT; i ++) + { + if ( Q_strcmp( conVar->GetName(), classRestrictionCvars[i].GetName() ) == 0 ) + { + idx = i; + break; + } + } + + if ( idx == -1 ) + return; + pTeam->UpdateLimit( idx ); + } +} + +#endif // GAME_DLL + + LINK_ENTITY_TO_CLASS( ff_team_manager, CFF_SH_TeamManager ); #ifdef GAME_DLL @@ -76,9 +142,29 @@ void CFF_SH_TeamManager::SetAllies( int iTeam ) void CFF_SH_TeamManager::SetClassLimit( int iClass, int iLimit ) { + // no change needed + if ( m_iClassesMap[iClass] == iLimit ) + return; + m_iClassesMap[iClass] = iLimit; - m_iClasses.Set( iClass, iLimit ); - DevMsg( "FF Team manager::SetClassLimit (team='%s') class=%i, limit=%i\n", m_szTeamname.Get(), iClass, iLimit ); + UpdateLimit( iClass ); +} + +void CFF_SH_TeamManager::UpdateLimit( int iClassIdx ) +{ + // if the map or cvar is 0 it will always use the other + int curCvar = classRestrictionCvars[iClassIdx].GetInt(); + int curMap = m_iClassesMap[iClassIdx]; + int newVal = min ( curCvar == 0 ? curMap : curCvar, curMap == 0 ? curCvar : curMap); + m_iClasses.Set( iClassIdx, newVal ); + + DevMsg("CFF_SH_TeamManager::UpdateLimit: set class idx %i limit to %i\n", iClassIdx, newVal ); +} + +void CFF_SH_TeamManager::UpdateAllLimits( void ) +{ + for ( int i = 0; i < ARRAYSIZE(m_iClassesMap); i++ ) + UpdateLimit( i ); } void CFF_SH_TeamManager::SetDeaths( int iDeaths ) @@ -141,75 +227,6 @@ int CFF_SH_TeamManager::GetTeamLimits( void ) return m_iMaxPlayers; } -#ifdef GAME_DLL - -static void ClassRestrictionChange( IConVar *var, const char *pOldString, float fOldVal ); - -// we gotta do this anyway for other classes to use em directly without having to lookup -ConVar cr_scout( "cr_scout", "0", 0, "Max number of scouts", ClassRestrictionChange ); -ConVar cr_sniper( "cr_sniper", "0", 0, "Max number of snipers", ClassRestrictionChange ); -ConVar cr_soldier( "cr_soldier", "0", 0, "Max number of soldiers", ClassRestrictionChange ); -ConVar cr_demoman( "cr_demoman", "0", 0, "Max number of demoman", ClassRestrictionChange ); -ConVar cr_medic( "cr_medic", "0", 0, "Max number of medic", ClassRestrictionChange ); -ConVar cr_hwguy( "cr_hwguy", "0", 0, "Max number of hwguy", ClassRestrictionChange ); -ConVar cr_pyro( "cr_pyro", "0", 0, "Max number of pyro", ClassRestrictionChange ); -ConVar cr_spy( "cr_spy", "0", 0, "Max number of spy", ClassRestrictionChange ); -ConVar cr_engineer( "cr_engineer", "0", 0, "Max number of engineer", ClassRestrictionChange ); -ConVar cr_civilian( "cr_civilian", "0", 0, "Max number of engineer", ClassRestrictionChange ); - -//static CUtlDict classCvarToIndexDict; -// do this so we can find correct idx to pass to team manager -// (from old CFFTeam::UpdateTeamLimits indices) -static ConVar classRestrictionCvars[] = -{ - cr_scout, - cr_sniper, - cr_soldier, - cr_demoman, - cr_medic, - cr_hwguy, - cr_pyro, - cr_spy, - cr_engineer, - cr_civilian, -}; - -// Need to update the real class limits for this map -static void ClassRestrictionChange( IConVar *var, const char *pOldString, float fOldVal ) -{ - // Update the team limits (skip unassigned and spec, they dont need limits applied ) - for ( int i = TEAM_SPECTATOR + 1; i < g_Teams.Count(); i++ ) - { - CFF_SH_TeamManager *pTeam = GetGlobalFFTeam( i ); - if ( !pTeam ) - return; - - ConVar *conVar = static_cast(var); - if ( !conVar ) - return; - - int idx = -1; - for ( int i = 0; i < CLASS_COUNT; i ++) - { - //if ( conVar == &classRestrictionCvars[i] ) - if ( Q_strcmp( conVar->GetName(), classRestrictionCvars[i].GetName() ) == 0 ) - { - idx = i; - break; - } - } - - if ( idx == -1 ) - return; - - pTeam->SetClassLimit( idx, conVar->GetInt() ); - } -} - - - -#endif // GAME_DLL - //ConCommand ff_team( "ff_team", //ConCommand ff_team( "ffdbg_dump_teams", #if defined (DEBUG) && defined (GAME_DLL) diff --git a/mp/src/game/shared/ff/ff_sh_team_manager.h b/mp/src/game/shared/ff/ff_sh_team_manager.h index 8c7e6c5d..06d833eb 100644 --- a/mp/src/game/shared/ff/ff_sh_team_manager.h +++ b/mp/src/game/shared/ff/ff_sh_team_manager.h @@ -58,7 +58,8 @@ public: void SetName( const char *pName ); void SetFortPoints( int iFortPoints ); void SetTeamLimits( int ); - //void UpdateLimits( void ); + void UpdateLimit( int idx ); + void UpdateAllLimits( void ); #endif // GAME_DLL