diff --git a/mp/src/game/shared/ff/ff_sh_gamerules.cpp b/mp/src/game/shared/ff/ff_sh_gamerules.cpp index ec44aeeb..49f66e59 100644 --- a/mp/src/game/shared/ff/ff_sh_gamerules.cpp +++ b/mp/src/game/shared/ff/ff_sh_gamerules.cpp @@ -32,6 +32,7 @@ #include "ff_sv_dll_interface.h" #include "hl2mp_cvars.h" #include "ff_sh_team_manager.h" + #include #ifdef DEBUG #include "hl2mp_bot_temp.h" @@ -193,7 +194,57 @@ char *sTeamNames[] = "#FF_TEAM_CUSTOM7", "#FF_TEAM_CUSTOM8", }; -#endif + + +void CFF_SH_Rules::AddTeam( const char *pTeamName, const int iNum ) +{ + CFF_SH_TeamManager *pTeam = static_cast(CreateEntityByName( "ff_team_manager" )); + if ( pTeam ) + { + pTeam->Init( pTeamName, iNum ); + g_Teams.AddToTail( pTeam ); + } +} + +// add a new team and use next available unused team number +void CFF_SH_Rules::AddTeam( const char *pTeamName ) +{ + CFF_SH_TeamManager *pTeam = static_cast(CreateEntityByName( "ff_team_manager" )); + if ( !pTeam ) + return; + + int iNum = 0; + + for ( int i = 0; i < g_Teams.Count(); ++i ) + iNum = max ( g_Teams[i]->GetTeamNumber(), iNum ); + + pTeam->Init( pTeamName, ++iNum ); + g_Teams.AddToTail( pTeam ); +} + +void CFF_SH_Rules::RemoveTeam( const char *pTeamName ) +{ + int foundIdx = -1; + for ( int i = 0; i < g_Teams.Count(); ++i ) + { + if ( g_Teams[i] && FStrEq( pTeamName, g_Teams[i]->GetName( ) ) ) + { + foundIdx = i; + break; + } + } + + if ( foundIdx != -1 ) + g_Teams.Remove( foundIdx ); +} + +void CFF_SH_Rules::RemoveTeam( const int iIndex ) +{ + if ( iIndex >= 0 && iIndex < g_Teams.Count( ) ) + g_Teams.Remove( iIndex ); +} + +#endif // GAME_DLL CFF_SH_Rules::CFF_SH_Rules() { diff --git a/mp/src/game/shared/ff/ff_sh_gamerules.h b/mp/src/game/shared/ff/ff_sh_gamerules.h index 12d1b908..3c489a6b 100644 --- a/mp/src/game/shared/ff/ff_sh_gamerules.h +++ b/mp/src/game/shared/ff/ff_sh_gamerules.h @@ -123,7 +123,7 @@ public: void CleanUpMap(); void CheckRestartGame(); void RestartGame(); - + #ifndef CLIENT_DLL virtual Vector VecItemRespawnSpot( CItem *pItem ); virtual QAngle VecItemRespawnAngles( CItem *pItem ); @@ -138,6 +138,11 @@ public: const char *GetChatFormat( bool bTeamOnly, CBasePlayer *pPlayer ); bool IsSpawnPointValid( CBaseEntity *pSpot, CBasePlayer *pPlayer ); + void AddTeam( const char *pTeamName, const int iNum ); + void AddTeam( const char *pTeamName ); + void RemoveTeam( const char *pTeamName ); + void RemoveTeam( const int iIndex ); + #endif virtual void ClientDisconnected( edict_t *pClient );