1 void CA_count_alive_players()
4 total_players = redalive = bluealive = yellowalive = pinkalive = 0;
6 if(e.team == COLOR_TEAM1)
9 if (e.health >= 1) ++redalive;
11 else if(e.team == COLOR_TEAM2)
14 if (e.health >= 1) ++bluealive;
16 else if(e.team == COLOR_TEAM3)
19 if (e.health >= 1) ++yellowalive;
21 else if(e.team == COLOR_TEAM4)
24 if (e.health >= 1) ++pinkalive;
27 FOR_EACH_REALCLIENT(e) {
28 e.redalive_stat = redalive;
29 e.bluealive_stat = bluealive;
30 e.yellowalive_stat = yellowalive;
31 e.pinkalive_stat = pinkalive;
35 float CA_GetWinnerTeam()
39 winner_team = COLOR_TEAM1;
42 if(winner_team) return 0;
43 winner_team = COLOR_TEAM2;
47 if(winner_team) return 0;
48 winner_team = COLOR_TEAM3;
52 if(winner_team) return 0;
53 winner_team = COLOR_TEAM4;
57 return -1; // no player left
60 float CA_CheckWinner()
62 // TODO round tied if(time - warmup > autocvar_g_ca_round_timelimit
65 allowed_to_spawn = TRUE;
67 allowed_to_spawn = FALSE;
69 CA_count_alive_players();
70 if(CA_ALIVE_TEAMS() > 1)
76 winner_team = CA_GetWinnerTeam();
79 teamname = ColoredTeamName(winner_team);
80 FOR_EACH_REALCLIENT(e)
81 centerprint(e, strcat(teamname, " wins the round"));
82 bprint(teamname, " wins the round.\n");
83 TeamScore_AddToTeam(winner_team, ST_SCORE, +1);
85 else if(winner_team == -1)
87 FOR_EACH_REALCLIENT(e)
88 centerprint(e, "Round tied");
89 bprint("Round tied.\n");
92 allowed_to_spawn = TRUE;
96 float prev_total_players;
100 allowed_to_spawn = TRUE;
101 CA_count_alive_players();
102 if(CA_ALIVE_TEAMS_OK())
104 if(prev_total_players != -1)
106 FOR_EACH_REALCLIENT(e)
107 Send_CSQC_Centerprint_Generic_Expire(e, CPID_WAITING_PLAYERS);
109 prev_total_players = -1;
112 if(prev_total_players != total_players)
114 string teams_missing;
115 if(!redalive) teams_missing = strcat(teams_missing, ColoredTeamName(COLOR_TEAM1), ", ");
116 if(!bluealive) teams_missing = strcat(teams_missing, ColoredTeamName(COLOR_TEAM2), ", ");
118 if(!yellowalive) teams_missing = strcat(teams_missing, ColoredTeamName(COLOR_TEAM3), ", ");
120 if(!pinkalive) teams_missing = strcat(teams_missing, ColoredTeamName(COLOR_TEAM4), ", ");
121 teams_missing = substring(teams_missing, 0, strlen(teams_missing)-2);
123 FOR_EACH_REALCLIENT(e)
124 Send_CSQC_Centerprint_Generic(e, CPID_WAITING_PLAYERS, strcat("Waiting for players to join...\n\nNeed active players for: ", teams_missing), -1, 0);
125 prev_total_players = total_players;
130 MUTATOR_HOOKFUNCTION(ca_PlayerSpawn)
132 self.caplayer = TRUE;
136 MUTATOR_HOOKFUNCTION(ca_reset_map_players)
138 FOR_EACH_CLIENT(self)
142 self.classname = "player";
149 MUTATOR_HOOKFUNCTION(ca_reset_map_global)
151 allowed_to_spawn = TRUE;
155 MUTATOR_HOOKFUNCTION(ca_GetTeamCount)
157 ca_teams = autocvar_g_ca_teams_override;
159 ca_teams = autocvar_g_ca_teams;
160 ca_teams = bound(2, ca_teams, 4);
161 ret_float = ca_teams;
165 MUTATOR_HOOKFUNCTION(ca_PlayerPreThink)
167 if(!allowed_to_spawn)
168 self.stat_respawn_time = 0;
172 MUTATOR_HOOKFUNCTION(ca_ForbidPlayerScore_Clear)
179 allowed_to_spawn = TRUE;
181 round_handler_Spawn(CA_CheckTeams, CA_CheckWinner, 5, autocvar_g_ca_warmup);
183 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
184 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
185 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
186 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
189 MUTATOR_DEFINITION(gamemode_ca)
191 MUTATOR_HOOK(PlayerSpawn, ca_PlayerSpawn, CBC_ORDER_ANY);
192 MUTATOR_HOOK(reset_map_global, ca_reset_map_global, CBC_ORDER_ANY);
193 MUTATOR_HOOK(reset_map_players, ca_reset_map_players, CBC_ORDER_ANY);
194 MUTATOR_HOOK(GetTeamCount, ca_GetTeamCount, CBC_ORDER_EXCLUSIVE);
195 MUTATOR_HOOK(PlayerPreThink, ca_PlayerPreThink, CBC_ORDER_ANY);
196 MUTATOR_HOOK(ForbidPlayerScore_Clear, ca_ForbidPlayerScore_Clear, CBC_ORDER_ANY);
200 if(time > 1) // game loads at time 1
201 error("This is a game type and it cannot be added at runtime.");
207 error("This is a game type and it cannot be removed at runtime.");