about summary refs log tree commit diff
path: root/src/game/server
diff options
context:
space:
mode:
authorBeaR <cinaera@web.de>2011-09-04 11:13:30 +0200
committeroy <Tom_Adams@web.de>2011-12-30 21:52:01 +0100
commitafb1d5e20158de57e7e6fcb49be5204b02a8fe12 (patch)
treebfc2c26a0cf00ba19f9da52fb4d26d700afbaab1 /src/game/server
parent8052ddf0ff3fcf09cb1679e20b0dc8818f05cf91 (diff)
downloadzcatch-afb1d5e20158de57e7e6fcb49be5204b02a8fe12.tar.gz
zcatch-afb1d5e20158de57e7e6fcb49be5204b02a8fe12.zip
Swap and Shuffle Teams
Diffstat (limited to 'src/game/server')
-rw-r--r--src/game/server/gamecontext.cpp65
-rw-r--r--src/game/server/gamecontext.h2
2 files changed, 67 insertions, 0 deletions
diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp
index ca429d79..707126b1 100644
--- a/src/game/server/gamecontext.cpp
+++ b/src/game/server/gamecontext.cpp
@@ -1076,6 +1076,69 @@ void CGameContext::ConSetTeamAll(IConsole::IResult *pResult, void *pUserData)
 	(void)pSelf->m_pController->CheckTeamBalance();
 }
 
+void CGameContext::ConSwapTeams(IConsole::IResult *pResult, void *pUserData)
+{
+	CGameContext *pSelf = (CGameContext *)pUserData;
+	
+	char aBuf[256];
+	str_format(aBuf, sizeof(aBuf), "swaped the current teams");
+	pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
+
+	for(int i = 0; i < MAX_CLIENTS; ++i)
+	{
+		if(pSelf->m_apPlayers[i] && pSelf->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS)
+		{
+			int Team = pSelf->m_apPlayers[i]->GetTeam();
+			if(Team == TEAM_RED)
+				pSelf->m_apPlayers[i]->SetTeam(TEAM_BLUE);
+			else
+				pSelf->m_apPlayers[i]->SetTeam(TEAM_RED);
+		}
+	}
+
+	(void)pSelf->m_pController->CheckTeamBalance();
+
+
+
+}
+
+void CGameContext::ConShuffleTeams(IConsole::IResult *pResult, void *pUserData)
+{
+	CGameContext *pSelf = (CGameContext *)pUserData;
+	int counterRed = 0;
+	int counterBlue = 0;
+	int PlayerTeam = (g_Config.m_SvMaxClients-g_Config.m_SvSpectatorSlots)/2;
+	
+	char aBuf[256];
+	str_format(aBuf, sizeof(aBuf), "shuffled the current teams");
+	pSelf->Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf);
+
+
+	for(int i = 0; i < MAX_CLIENTS; ++i)
+	{
+		if(pSelf->m_apPlayers[i] && pSelf->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS)
+		{
+			if( counterRed == PlayerTeam )
+				pSelf->m_apPlayers[i]->SetTeam(TEAM_BLUE);
+			else if( counterBlue == PlayerTeam )
+				pSelf->m_apPlayers[i]->SetTeam(TEAM_RED);
+			else
+			{	
+				if(rand() % 2)
+				{
+					pSelf->m_apPlayers[i]->SetTeam(TEAM_BLUE);
+					++counterBlue;
+				}
+				else
+				{
+					pSelf->m_apPlayers[i]->SetTeam(TEAM_RED);
+					++counterRed;
+				}
+			}
+		}
+	}
+}
+
 void CGameContext::ConAddVote(IConsole::IResult *pResult, void *pUserData)
 {
 	CGameContext *pSelf = (CGameContext *)pUserData;
@@ -1335,6 +1398,8 @@ void CGameContext::OnConsoleInit()
 	Console()->Register("say", "r", CFGFLAG_SERVER, ConSay, this, "Say in chat");
 	Console()->Register("set_team", "ii?i", CFGFLAG_SERVER, ConSetTeam, this, "Set team of player to team");
 	Console()->Register("set_team_all", "i", CFGFLAG_SERVER, ConSetTeamAll, this, "Set team of all players to team");
+	Console()->Register("swap_teams", "", CFGFLAG_SERVER, ConSwapTeams, this, "Swap the current teams");
+	Console()->Register("shuffle_teams", "", CFGFLAG_SERVER, ConShuffleTeams, this, "Shuffle the current teams");
 
 	Console()->Register("add_vote", "sr", CFGFLAG_SERVER, ConAddVote, this, "Add a voting option");
 	Console()->Register("remove_vote", "s", CFGFLAG_SERVER, ConRemoveVote, this, "remove a voting option");
diff --git a/src/game/server/gamecontext.h b/src/game/server/gamecontext.h
index 6288850d..b899f2d8 100644
--- a/src/game/server/gamecontext.h
+++ b/src/game/server/gamecontext.h
@@ -54,6 +54,8 @@ class CGameContext : public IGameServer
 	static void ConSay(IConsole::IResult *pResult, void *pUserData);
 	static void ConSetTeam(IConsole::IResult *pResult, void *pUserData);
 	static void ConSetTeamAll(IConsole::IResult *pResult, void *pUserData);
+	static void ConSwapTeams(IConsole::IResult *pResult, void *pUserData);
+	static void ConShuffleTeams(IConsole::IResult *pResult, void *pUserData);
 	static void ConAddVote(IConsole::IResult *pResult, void *pUserData);
 	static void ConRemoveVote(IConsole::IResult *pResult, void *pUserData);
 	static void ConForceVote(IConsole::IResult *pResult, void *pUserData);