about summary refs log tree commit diff
path: root/src/game/server/gs_game.cpp
diff options
context:
space:
mode:
authorMagnus Auvinen <magnus.auvinen@gmail.com>2008-03-23 14:59:58 +0000
committerMagnus Auvinen <magnus.auvinen@gmail.com>2008-03-23 14:59:58 +0000
commita9b8e383ae593082617e06e74a058aa3641f733a (patch)
treeceaea67cbbb1264c35ee10beba05d38a8b75bec3 /src/game/server/gs_game.cpp
parentb0e5093bb631209fb7b511651624773e731a3cba (diff)
downloadzcatch-a9b8e383ae593082617e06e74a058aa3641f733a.tar.gz
zcatch-a9b8e383ae593082617e06e74a058aa3641f733a.zip
fixed spectator slots
Diffstat (limited to 'src/game/server/gs_game.cpp')
-rw-r--r--src/game/server/gs_game.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/game/server/gs_game.cpp b/src/game/server/gs_game.cpp
index 6482fc3d..833bad4a 100644
--- a/src/game/server/gs_game.cpp
+++ b/src/game/server/gs_game.cpp
@@ -298,7 +298,7 @@ void gameobject::snap(int snapping_client)
 	game->teamscore_blue = teamscore[1];
 }
 
-int gameobject::getteam(int notthisid)
+int gameobject::get_auto_team(int notthisid)
 {
 	int numplayers[2] = {0,0};
 	for(int i = 0; i < MAX_CLIENTS; i++)
@@ -310,7 +310,29 @@ int gameobject::getteam(int notthisid)
 		}
 	}
 
-	return numplayers[0] > numplayers[1] ? 1 : 0;
+	int team = 0;
+	if(is_teamplay)
+		team = numplayers[0] > numplayers[1] ? 1 : 0;
+		
+	if(can_join_team(team, notthisid))
+		return team;
+	return -1;
+}
+
+bool gameobject::can_join_team(int team, int notthisid)
+{
+	(void)team;
+	int numplayers[2] = {0,0};
+	for(int i = 0; i < MAX_CLIENTS; i++)
+	{
+		if(players[i].client_id != -1 && players[i].client_id != notthisid)
+		{
+			if(players[i].team >= 0 || players[i].team == 1)
+				numplayers[players[i].team]++;
+		}
+	}
+	
+	return (numplayers[0] + numplayers[1]) < config.sv_max_clients-config.sv_spectator_slots;
 }
 
 void gameobject::do_player_score_wincheck()