about summary refs log tree commit diff
path: root/src/game/server
diff options
context:
space:
mode:
authoroy <Tom_Adams@web.de>2011-01-03 12:50:38 +0100
committeroy <Tom_Adams@web.de>2011-01-03 12:50:38 +0100
commita72848e78032014adb1bf053c4556bf1072b0c2d (patch)
tree5a9da24803f3432c79229b87abe77b6235668e19 /src/game/server
parentb29b6d0bcff3d22fe5dac3453689fb8d315cf3ee (diff)
downloadzcatch-a72848e78032014adb1bf053c4556bf1072b0c2d.tar.gz
zcatch-a72848e78032014adb1bf053c4556bf1072b0c2d.zip
added constants for teams by Choupom
Diffstat (limited to 'src/game/server')
-rw-r--r--src/game/server/entities/character.cpp4
-rw-r--r--src/game/server/gamecontext.cpp8
-rw-r--r--src/game/server/gamecontroller.cpp66
-rw-r--r--src/game/server/gamemodes/ctf.cpp6
-rw-r--r--src/game/server/player.cpp6
5 files changed, 45 insertions, 45 deletions
diff --git a/src/game/server/entities/character.cpp b/src/game/server/entities/character.cpp
index e29b778b..e6bb0680 100644
--- a/src/game/server/entities/character.cpp
+++ b/src/game/server/entities/character.cpp
@@ -521,7 +521,7 @@ void CCharacter::OnDirectInput(CNetObj_PlayerInput *pNewInput)
 	mem_copy(&m_LatestPrevInput, &m_LatestInput, sizeof(m_LatestInput));
 	mem_copy(&m_LatestInput, pNewInput, sizeof(m_LatestInput));
 	
-	if(m_NumInputs > 2 && m_pPlayer->GetTeam() != -1)
+	if(m_NumInputs > 2 && m_pPlayer->GetTeam() != TEAM_SPECTATORS)
 	{
 		HandleWeaponSwitch();
 		FireWeapon();
@@ -628,7 +628,7 @@ void CCharacter::TickDefered()
 	if(Events&COREEVENT_HOOK_HIT_NOHOOK) GameServer()->CreateSound(m_Pos, SOUND_HOOK_NOATTACH, Mask);
 
 	
-	if(m_pPlayer->GetTeam() == -1)
+	if(m_pPlayer->GetTeam() == TEAM_SPECTATORS)
 	{
 		m_Pos.x = m_Input.m_TargetX;
 		m_Pos.y = m_Input.m_TargetY;
diff --git a/src/game/server/gamecontext.cpp b/src/game/server/gamecontext.cpp
index 5834d074..4f494f75 100644
--- a/src/game/server/gamecontext.cpp
+++ b/src/game/server/gamecontext.cpp
@@ -414,7 +414,7 @@ void CGameContext::OnTick()
 				bool aVoteChecked[MAX_CLIENTS] = {0};
 				for(int i = 0; i < MAX_CLIENTS; i++)
 				{
-					if(!m_apPlayers[i] || m_apPlayers[i]->GetTeam() == -1 || aVoteChecked[i])	// don't count in votes by spectators
+					if(!m_apPlayers[i] || m_apPlayers[i]->GetTeam() == TEAM_SPECTATORS || aVoteChecked[i])	// don't count in votes by spectators
 						continue;
 					
 					int ActVote = m_apPlayers[i]->m_Vote;
@@ -513,7 +513,7 @@ void CGameContext::OnClientEnter(int ClientId)
 void CGameContext::OnClientConnected(int ClientId)
 {
 	// Check which team the player should be on
-	const int StartTeam = g_Config.m_SvTournamentMode ? -1 : m_pController->GetAutoTeam(ClientId);
+	const int StartTeam = g_Config.m_SvTournamentMode ? TEAM_SPECTATORS : m_pController->GetAutoTeam(ClientId);
 
 	m_apPlayers[ClientId] = new(ClientId) CPlayer(this, ClientId, StartTeam);
 	//players[client_id].init(client_id);
@@ -595,7 +595,7 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId)
 
 		int64 Now = Server()->Tick();
 		p->m_Last_VoteTry = Now;
-		if(p->GetTeam() == -1)
+		if(p->GetTeam() == TEAM_SPECTATORS)
 		{
 			SendChatTarget(ClientId, "Spectators aren't allowed to start a vote.");
 			return;
@@ -732,7 +732,7 @@ void CGameContext::OnMessage(int MsgId, CUnpacker *pUnpacker, int ClientId)
 			if(m_pController->CanChangeTeam(p, pMsg->m_Team))
 			{
 				p->m_Last_SetTeam = Server()->Tick();
-				if(p->GetTeam() == -1 || pMsg->m_Team == -1)
+				if(p->GetTeam() == TEAM_SPECTATORS || pMsg->m_Team == TEAM_SPECTATORS)
 					m_VoteUpdate = true;
 				p->SetTeam(pMsg->m_Team);
 				(void)m_pController->CheckTeamBalance();
diff --git a/src/game/server/gamecontroller.cpp b/src/game/server/gamecontroller.cpp
index e6f60141..3e8af96c 100644
--- a/src/game/server/gamecontroller.cpp
+++ b/src/game/server/gamecontroller.cpp
@@ -23,8 +23,8 @@ IGameController::IGameController(class CGameContext *pGameServer)
 	m_RoundStartTick = Server()->Tick();
 	m_RoundCount = 0;
 	m_GameFlags = 0;
-	m_aTeamscore[0] = 0;
-	m_aTeamscore[1] = 0;
+	m_aTeamscore[TEAM_RED] = 0;
+	m_aTeamscore[TEAM_BLUE] = 0;
 	m_aMapWish[0] = 0;
 	
 	m_UnbalancedTick = -1;
@@ -81,7 +81,7 @@ bool IGameController::CanSpawn(CPlayer *pPlayer, vec2 *pOutPos)
 	CSpawnEval Eval;
 	
 	// spectators can't spawn
-	if(pPlayer->GetTeam() == -1)
+	if(pPlayer->GetTeam() == TEAM_SPECTATORS)
 		return false;
 	
 	if(IsTeamplay())
@@ -174,9 +174,9 @@ const char *IGameController::GetTeamName(int Team)
 {
 	if(IsTeamplay())
 	{
-		if(Team == 0)
+		if(Team == TEAM_RED)
 			return "red team";
-		else if(Team == 1)
+		else if(Team == TEAM_BLUE)
 			return "blue team";
 	}
 	else
@@ -198,8 +198,8 @@ void IGameController::StartRound()
 	m_SuddenDeath = 0;
 	m_GameOverTick = -1;
 	GameServer()->m_World.m_Paused = false;
-	m_aTeamscore[0] = 0;
-	m_aTeamscore[1] = 0;
+	m_aTeamscore[TEAM_RED] = 0;
+	m_aTeamscore[TEAM_BLUE] = 0;
 	m_ForceBalanced = false;
 	char aBuf[256];
 	str_format(aBuf, sizeof(aBuf), "start round type='%s' teamplay='%d'", m_pGameType, m_GameFlags&GAMEFLAG_TEAMS);
@@ -303,7 +303,7 @@ void IGameController::OnPlayerInfoChange(class CPlayer *pP)
 	const int aTeamColors[2] = {65387, 10223467};
 	if(IsTeamplay())
 	{
-		if(pP->GetTeam() >= 0 || pP->GetTeam() <= 1)
+		if(pP->GetTeam() >= TEAM_RED && pP->GetTeam() <= TEAM_BLUE)
 		{
 			pP->m_TeeInfos.m_UseCustomColor = 1;
 			pP->m_TeeInfos.m_ColorBody = aTeamColors[pP->GetTeam()];
@@ -412,7 +412,7 @@ void IGameController::Tick()
 		float aPScore[MAX_CLIENTS] = {0.0f};
 		for(int i = 0; i < MAX_CLIENTS; i++)
 		{
-			if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != -1)
+			if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS)
 			{
 				aT[GameServer()->m_apPlayers[i]->GetTeam()]++;
 				aPScore[i] = GameServer()->m_apPlayers[i]->m_Score*Server()->TickSpeed()*60.0f/
@@ -462,7 +462,7 @@ void IGameController::Tick()
 	{
 		for(int i = 0; i < MAX_CLIENTS; ++i)
 		{
-			if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != -1 && !Server()->IsAuthed(i))
+			if(GameServer()->m_apPlayers[i] && GameServer()->m_apPlayers[i]->GetTeam() != TEAM_SPECTATORS && !Server()->IsAuthed(i))
 			{
 				if(Server()->Tick() > GameServer()->m_apPlayers[i]->m_LastActionTick+g_Config.m_SvInactiveKickTime*Server()->TickSpeed()*60)
 				{
@@ -471,7 +471,7 @@ void IGameController::Tick()
 					case 0:
 						{
 							// move player to spectator
-							GameServer()->m_apPlayers[i]->SetTeam(-1);
+							GameServer()->m_apPlayers[i]->SetTeam(TEAM_SPECTATORS);
 						}
 						break;
 					case 1:
@@ -479,12 +479,12 @@ void IGameController::Tick()
 							// move player to spectator if the reserved slots aren't filled yet, kick him otherwise
 							int Spectators = 0;
 							for(int j = 0; j < MAX_CLIENTS; ++j)
-								if(GameServer()->m_apPlayers[j] && GameServer()->m_apPlayers[j]->GetTeam() == -1)
+								if(GameServer()->m_apPlayers[j] && GameServer()->m_apPlayers[j]->GetTeam() == TEAM_SPECTATORS)
 									++Spectators;
 							if(Spectators >= g_Config.m_SvSpectatorSlots)
 								Server()->Kick(i, "Kicked for inactivity");
 							else
-								GameServer()->m_apPlayers[i]->SetTeam(-1);
+								GameServer()->m_apPlayers[i]->SetTeam(TEAM_SPECTATORS);
 						}
 						break;
 					case 2:
@@ -507,8 +507,8 @@ void IGameController::Tick()
 	{
 		if(IsTeamplay())
 		{
-			Prog = max(Prog, (m_aTeamscore[0]*100)/g_Config.m_SvScorelimit);
-			Prog = max(Prog, (m_aTeamscore[1]*100)/g_Config.m_SvScorelimit);
+			Prog = max(Prog, (m_aTeamscore[TEAM_RED]*100)/g_Config.m_SvScorelimit);
+			Prog = max(Prog, (m_aTeamscore[TEAM_BLUE]*100)/g_Config.m_SvScorelimit);
 		}
 		else
 		{
@@ -556,14 +556,14 @@ void IGameController::Snap(int SnappingClient)
 	if(SnappingClient == -1)
 	{
 		// we are recording a demo, just set the scores
-		pGameObj->m_TeamscoreRed = m_aTeamscore[0];
-		pGameObj->m_TeamscoreBlue = m_aTeamscore[1];
+		pGameObj->m_TeamscoreRed = m_aTeamscore[TEAM_RED];
+		pGameObj->m_TeamscoreBlue = m_aTeamscore[TEAM_BLUE];
 	}
 	else
 	{
 		// TODO: this little hack should be removed
-		pGameObj->m_TeamscoreRed = IsTeamplay() ? m_aTeamscore[0] : GameServer()->m_apPlayers[SnappingClient]->m_Score;
-		pGameObj->m_TeamscoreBlue = m_aTeamscore[1];
+		pGameObj->m_TeamscoreRed = IsTeamplay() ? m_aTeamscore[TEAM_RED] : GameServer()->m_apPlayers[SnappingClient]->m_Score;
+		pGameObj->m_TeamscoreBlue = m_aTeamscore[TEAM_BLUE];
 	}
 }
 
@@ -578,14 +578,14 @@ int IGameController::GetAutoTeam(int Notthisid)
 	{
 		if(GameServer()->m_apPlayers[i] && i != Notthisid)
 		{
-			if(GameServer()->m_apPlayers[i]->GetTeam() == 0 || GameServer()->m_apPlayers[i]->GetTeam() == 1)
+			if(GameServer()->m_apPlayers[i]->GetTeam() >= TEAM_RED && GameServer()->m_apPlayers[i]->GetTeam() <= TEAM_BLUE)
 				aNumplayers[GameServer()->m_apPlayers[i]->GetTeam()]++;
 		}
 	}
 
 	int Team = 0;
 	if(IsTeamplay())
-		Team = aNumplayers[0] > aNumplayers[1] ? 1 : 0;
+		Team = aNumplayers[TEAM_RED] > aNumplayers[TEAM_BLUE] ? TEAM_BLUE : TEAM_RED;
 		
 	if(CanJoinTeam(Team, Notthisid))
 		return Team;
@@ -594,7 +594,7 @@ int IGameController::GetAutoTeam(int Notthisid)
 
 bool IGameController::CanJoinTeam(int Team, int Notthisid)
 {
-	if(Team == -1 || (GameServer()->m_apPlayers[Notthisid] && GameServer()->m_apPlayers[Notthisid]->GetTeam() != -1))
+	if(Team == TEAM_SPECTATORS || (GameServer()->m_apPlayers[Notthisid] && GameServer()->m_apPlayers[Notthisid]->GetTeam() != TEAM_SPECTATORS))
 		return true;
 
 	int aNumplayers[2] = {0,0};
@@ -602,7 +602,7 @@ bool IGameController::CanJoinTeam(int Team, int Notthisid)
 	{
 		if(GameServer()->m_apPlayers[i] && i != Notthisid)
 		{
-			if(GameServer()->m_apPlayers[i]->GetTeam() >= 0 || GameServer()->m_apPlayers[i]->GetTeam() == 1)
+			if(GameServer()->m_apPlayers[i]->GetTeam() >= TEAM_RED && GameServer()->m_apPlayers[i]->GetTeam() <= TEAM_BLUE)
 				aNumplayers[GameServer()->m_apPlayers[i]->GetTeam()]++;
 		}
 	}
@@ -619,7 +619,7 @@ bool IGameController::CheckTeamBalance()
 	for(int i = 0; i < MAX_CLIENTS; i++)
 	{
 		CPlayer *pP = GameServer()->m_apPlayers[i];
-		if(pP && pP->GetTeam() != -1)
+		if(pP && pP->GetTeam() != TEAM_SPECTATORS)
 			aT[pP->GetTeam()]++;
 	}
 	
@@ -645,26 +645,26 @@ bool IGameController::CanChangeTeam(CPlayer *pPlayer, int JoinTeam)
 {
 	int aT[2] = {0, 0};
 	
-	if (!IsTeamplay() || JoinTeam == -1 || !g_Config.m_SvTeambalanceTime)
+	if (!IsTeamplay() || JoinTeam == TEAM_SPECTATORS || !g_Config.m_SvTeambalanceTime)
 		return true;
 	
 	for(int i = 0; i < MAX_CLIENTS; i++)
 	{
 		CPlayer *pP = GameServer()->m_apPlayers[i];
-		if(pP && pP->GetTeam() != -1)
+		if(pP && pP->GetTeam() != TEAM_SPECTATORS)
 			aT[pP->GetTeam()]++;
 	}
 	
 	// simulate what would happen if changed team
 	aT[JoinTeam]++;
-	if (pPlayer->GetTeam() != -1)
+	if (pPlayer->GetTeam() != TEAM_SPECTATORS)
 		aT[JoinTeam^1]--;
 	
 	// there is a player-difference of at least 2
 	if(absolute(aT[0]-aT[1]) >= 2)
 	{
 		// player wants to join team with less players
-		if ((aT[0] < aT[1] && JoinTeam == 0) || (aT[0] > aT[1] && JoinTeam == 1))
+		if ((aT[0] < aT[1] && JoinTeam == TEAM_RED) || (aT[0] > aT[1] && JoinTeam == TEAM_BLUE))
 			return true;
 		else
 			return false;
@@ -711,10 +711,10 @@ void IGameController::DoTeamScoreWincheck()
 	if(m_GameOverTick == -1 && !m_Warmup)
 	{
 		// check score win condition
-		if((g_Config.m_SvScorelimit > 0 && (m_aTeamscore[0] >= g_Config.m_SvScorelimit || m_aTeamscore[1] >= g_Config.m_SvScorelimit)) ||
+		if((g_Config.m_SvScorelimit > 0 && (m_aTeamscore[TEAM_RED] >= g_Config.m_SvScorelimit || m_aTeamscore[TEAM_BLUE] >= g_Config.m_SvScorelimit)) ||
 			(g_Config.m_SvTimelimit > 0 && (Server()->Tick()-m_RoundStartTick) >= g_Config.m_SvTimelimit*Server()->TickSpeed()*60))
 		{
-			if(m_aTeamscore[0] != m_aTeamscore[1])
+			if(m_aTeamscore[TEAM_RED] != m_aTeamscore[TEAM_BLUE])
 				EndRound();
 			else
 				m_SuddenDeath = 1;
@@ -724,9 +724,9 @@ void IGameController::DoTeamScoreWincheck()
 
 int IGameController::ClampTeam(int Team)
 {
-	if(Team < 0) // spectator
-		return -1;
+	if(Team < 0)
+		return TEAM_SPECTATORS;
 	if(IsTeamplay())
 		return Team&1;
-	return  0;
+	return 0;
 }
diff --git a/src/game/server/gamemodes/ctf.cpp b/src/game/server/gamemodes/ctf.cpp
index ad9f8e89..18905dbf 100644
--- a/src/game/server/gamemodes/ctf.cpp
+++ b/src/game/server/gamemodes/ctf.cpp
@@ -22,8 +22,8 @@ bool CGameControllerCTF::OnEntity(int Index, vec2 Pos)
 		return true;
 	
 	int Team = -1;
-	if(Index == ENTITY_FLAGSTAND_RED) Team = 0;
-	if(Index == ENTITY_FLAGSTAND_BLUE) Team = 1;
+	if(Index == ENTITY_FLAGSTAND_RED) Team = TEAM_RED;
+	if(Index == ENTITY_FLAGSTAND_BLUE) Team = TEAM_BLUE;
 	if(Team == -1 || m_apFlags[Team])
 		return false;
 		
@@ -142,7 +142,7 @@ void CGameControllerCTF::Tick()
 			int Num = GameServer()->m_World.FindEntities(F->m_Pos, CFlag::ms_PhysSize, (CEntity**)apCloseCCharacters, MAX_CLIENTS, NETOBJTYPE_CHARACTER);
 			for(int i = 0; i < Num; i++)
 			{
-				if(!apCloseCCharacters[i]->IsAlive() || apCloseCCharacters[i]->GetPlayer()->GetTeam() == -1 || GameServer()->Collision()->IntersectLine(F->m_Pos, apCloseCCharacters[i]->m_Pos, NULL, NULL))
+				if(!apCloseCCharacters[i]->IsAlive() || apCloseCCharacters[i]->GetPlayer()->GetTeam() == TEAM_SPECTATORS || GameServer()->Collision()->IntersectLine(F->m_Pos, apCloseCCharacters[i]->m_Pos, NULL, NULL))
 					continue;
 				
 				if(apCloseCCharacters[i]->GetPlayer()->GetTeam() == F->m_Team)
diff --git a/src/game/server/player.cpp b/src/game/server/player.cpp
index 03d715a4..78e7bd00 100644
--- a/src/game/server/player.cpp
+++ b/src/game/server/player.cpp
@@ -129,10 +129,10 @@ void CPlayer::OnDirectInput(CNetObj_PlayerInput *NewInput)
 	if(Character)
 		Character->OnDirectInput(NewInput);
 
-	if(!Character && m_Team >= 0 && (NewInput->m_Fire&1))
+	if(!Character && m_Team != TEAM_SPECTATORS && (NewInput->m_Fire&1))
 		m_Spawning = true;
 	
-	if(!Character && m_Team == -1)
+	if(!Character && m_Team == TEAM_SPECTATORS)
 		m_ViewPos = vec2(NewInput->m_TargetX, NewInput->m_TargetY);
 
 	// check for activity
@@ -165,7 +165,7 @@ void CPlayer::KillCharacter(int Weapon)
 
 void CPlayer::Respawn()
 {
-	if(m_Team > -1)
+	if(m_Team != TEAM_SPECTATORS)
 		m_Spawning = true;
 }