From ccaec795675b92c36da77e8d1e42e176f60b4e21 Mon Sep 17 00:00:00 2001 From: oy Date: Fri, 30 Dec 2011 22:47:26 +0100 Subject: [PATCH] made it possible to automatically swap teams between rounds --- src/game/server/gamecontext.cpp | 38 ++++++++++++++++-------------- src/game/server/gamecontext.h | 3 +++ src/game/server/gamecontroller.cpp | 4 ++++ src/game/variables.h | 1 + 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp index 53b109b88..0cd8e801d 100644 --- a/src/game/server/gamecontext.cpp +++ b/src/game/server/gamecontext.cpp @@ -387,6 +387,22 @@ void CGameContext::SendTuningParams(int ClientID) Server()->SendMsg(&Msg, MSGFLAG_VITAL, ClientID); } +void CGameContext::SwapTeams() +{ + if(!m_pController->IsTeamplay()) + return; + + SendChat(-1, CGameContext::CHAT_ALL, "Teams were swapped"); + + for(int i = 0; i < MAX_CLIENTS; ++i) + { + if(m_apPlayers[i] && m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS) + m_apPlayers[i]->SetTeam(m_apPlayers[i]->GetTeam()^1, false); + } + + (void)m_pController->CheckTeamBalance(); +} + void CGameContext::OnTick() { // check tuning @@ -1044,17 +1060,14 @@ void CGameContext::ConSetTeam(IConsole::IResult *pResult, void *pUserData) CGameContext *pSelf = (CGameContext *)pUserData; int ClientID = clamp(pResult->GetInteger(0), 0, (int)MAX_CLIENTS-1); int Team = clamp(pResult->GetInteger(1), -1, 1); - int Delay = 0; - if(pResult->NumArguments() > 2) - Delay = pResult->GetInteger(2); + int Delay = pResult->NumArguments()>2 ? pResult->GetInteger(2) : 0; + if(!pSelf->m_apPlayers[ClientID]) + return; char aBuf[256]; str_format(aBuf, sizeof(aBuf), "moved client %d to team %d", ClientID, Team); pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); - if(!pSelf->m_apPlayers[ClientID]) - return; - pSelf->m_apPlayers[ClientID]->m_TeamChangeTick = pSelf->Server()->Tick()+pSelf->Server()->TickSpeed()*Delay*60; pSelf->m_apPlayers[ClientID]->SetTeam(Team); (void)pSelf->m_pController->CheckTeamBalance(); @@ -1079,18 +1092,7 @@ void CGameContext::ConSetTeamAll(IConsole::IResult *pResult, void *pUserData) void CGameContext::ConSwapTeams(IConsole::IResult *pResult, void *pUserData) { CGameContext *pSelf = (CGameContext *)pUserData; - if(!pSelf->m_pController->IsTeamplay()) - return; - - pSelf->SendChat(-1, CGameContext::CHAT_ALL, "Teams were swapped"); - - for(int i = 0; i < MAX_CLIENTS; ++i) - { - if(pSelf->m_apPlayers[i] && pSelf->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS) - pSelf->m_apPlayers[i]->SetTeam(pSelf->m_apPlayers[i]->GetTeam()^1, false); - } - - (void)pSelf->m_pController->CheckTeamBalance(); + pSelf->SwapTeams(); } void CGameContext::ConShuffleTeams(IConsole::IResult *pResult, void *pUserData) diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h index b899f2d8a..fe07637e5 100644 --- a/src/game/server/gamecontext.h +++ b/src/game/server/gamecontext.h @@ -143,6 +143,9 @@ public: void CheckPureTuning(); void SendTuningParams(int ClientID); + // + void SwapTeams(); + // engine events virtual void OnInit(); virtual void OnConsoleInit(); diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp index 3d5829914..5eb49c004 100644 --- a/src/game/server/gamecontroller.cpp +++ b/src/game/server/gamecontroller.cpp @@ -245,7 +245,11 @@ void IGameController::CycleMap() return; if(m_RoundCount < g_Config.m_SvRoundsPerMap-1) + { + if(g_Config.m_SvRoundSwap) + GameServer()->SwapTeams(); return; + } // handle maprotation const char *pMapRotation = g_Config.m_SvMaprotation; diff --git a/src/game/variables.h b/src/game/variables.h index 3a587ef3b..4faa109d3 100644 --- a/src/game/variables.h +++ b/src/game/variables.h @@ -60,6 +60,7 @@ MACRO_CONFIG_STR(SvMotd, sv_motd, 900, "", CFGFLAG_SERVER, "Message of the day t MACRO_CONFIG_INT(SvTeamdamage, sv_teamdamage, 0, 0, 1, CFGFLAG_SERVER, "Team damage") MACRO_CONFIG_STR(SvMaprotation, sv_maprotation, 768, "", CFGFLAG_SERVER, "Maps to rotate between") MACRO_CONFIG_INT(SvRoundsPerMap, sv_rounds_per_map, 1, 1, 100, CFGFLAG_SERVER, "Number of rounds on each map before rotating") +MACRO_CONFIG_INT(SvRoundSwap, sv_round_swap, 1, 0, 1, CFGFLAG_SERVER, "Swap teams between rounds") MACRO_CONFIG_INT(SvPowerups, sv_powerups, 1, 0, 1, CFGFLAG_SERVER, "Allow powerups like ninja") MACRO_CONFIG_INT(SvScorelimit, sv_scorelimit, 20, 0, 1000, CFGFLAG_SERVER, "Score limit (0 disables)") MACRO_CONFIG_INT(SvTimelimit, sv_timelimit, 0, 0, 1000, CFGFLAG_SERVER, "Time limit in minutes (0 disables)")