2 float redalive, bluealive, yellowalive, pinkalive;
3 .float redalive_stat, bluealive_stat, yellowalive_stat, pinkalive_stat;
5 float allowed_to_spawn;
7 void CA_count_alive_players()
10 total_players = redalive = bluealive = yellowalive = pinkalive = 0;
12 if(e.team == COLOR_TEAM1)
15 if (e.health >= 1) ++redalive;
17 else if(e.team == COLOR_TEAM2)
20 if (e.health >= 1) ++bluealive;
22 else if(e.team == COLOR_TEAM3)
25 if (e.health >= 1) ++yellowalive;
27 else if(e.team == COLOR_TEAM4)
30 if (e.health >= 1) ++pinkalive;
33 FOR_EACH_REALCLIENT(e) {
34 e.redalive_stat = redalive;
35 e.bluealive_stat = bluealive;
36 e.yellowalive_stat = yellowalive;
37 e.pinkalive_stat = pinkalive;
41 float CA_GetWinnerTeam()
43 float winner_team = 0;
45 winner_team = COLOR_TEAM1;
48 if(winner_team) return 0;
49 winner_team = COLOR_TEAM2;
53 if(winner_team) return 0;
54 winner_team = COLOR_TEAM3;
58 if(winner_team) return 0;
59 winner_team = COLOR_TEAM4;
63 return -1; // no player left
66 #define CA_ALIVE_TEAMS() ((redalive > 0) + (bluealive > 0) + (yellowalive > 0) + (pinkalive > 0))
67 #define CA_ALIVE_TEAMS_OK() (CA_ALIVE_TEAMS() == ca_teams)
68 float CA_CheckWinner()
71 if(round_handler_GetTimeLeft() <= 0)
73 FOR_EACH_REALCLIENT(e)
74 centerprint(e, "Round over, there's no winner");
75 bprint("Round over, there's no winner.\n");
76 allowed_to_spawn = FALSE;
80 CA_count_alive_players();
81 if(CA_ALIVE_TEAMS() > 1)
86 winner_team = CA_GetWinnerTeam();
89 teamname = ColoredTeamName(winner_team);
90 FOR_EACH_REALCLIENT(e)
91 centerprint(e, strcat(teamname, " wins the round"));
92 bprint(teamname, " wins the round.\n");
93 TeamScore_AddToTeam(winner_team, ST_SCORE, +1);
95 else if(winner_team == -1)
97 FOR_EACH_REALCLIENT(e)
98 centerprint(e, "Round tied");
99 bprint("Round tied.\n");
102 allowed_to_spawn = FALSE;
109 allowed_to_spawn = TRUE;
111 allowed_to_spawn = FALSE;
114 float prev_total_players;
115 float CA_CheckTeams()
118 allowed_to_spawn = TRUE;
119 CA_count_alive_players();
120 if(CA_ALIVE_TEAMS_OK())
122 if(prev_total_players != -1)
124 FOR_EACH_REALCLIENT(e)
125 Send_CSQC_Centerprint_Generic_Expire(e, CPID_WAITING_PLAYERS);
127 prev_total_players = -1;
130 if(prev_total_players != total_players)
132 string teams_missing = "";
133 if(!redalive) teams_missing = strcat(teams_missing, ColoredTeamName(COLOR_TEAM1), ", ");
134 if(!bluealive) teams_missing = strcat(teams_missing, ColoredTeamName(COLOR_TEAM2), ", ");
136 if(!yellowalive) teams_missing = strcat(teams_missing, ColoredTeamName(COLOR_TEAM3), ", ");
138 if(!pinkalive) teams_missing = strcat(teams_missing, ColoredTeamName(COLOR_TEAM4), ", ");
139 teams_missing = substring(teams_missing, 0, strlen(teams_missing)-2);
141 FOR_EACH_REALCLIENT(e)
142 Send_CSQC_Centerprint_Generic(e, CPID_WAITING_PLAYERS, strcat("Waiting for players to join...\n\nNeed active players for: ", teams_missing), -1, 0);
143 prev_total_players = total_players;
148 MUTATOR_HOOKFUNCTION(ca_PlayerSpawn)
154 MUTATOR_HOOKFUNCTION(ca_PutClientInServer)
156 if(!allowed_to_spawn)
158 self.classname = "observer";
162 if(clienttype(self) == CLIENTTYPE_REAL)
163 sprint(self, "You will join the game in the next round.\n");
169 MUTATOR_HOOKFUNCTION(ca_reset_map_players)
171 FOR_EACH_CLIENT(self)
175 self.classname = "player";
183 MUTATOR_HOOKFUNCTION(ca_ClientConnect)
185 self.classname = "observer";
189 MUTATOR_HOOKFUNCTION(ca_reset_map_global)
191 allowed_to_spawn = TRUE;
195 MUTATOR_HOOKFUNCTION(ca_GetTeamCount)
197 ca_teams = autocvar_g_ca_teams_override;
199 ca_teams = autocvar_g_ca_teams;
200 ca_teams = bound(2, ca_teams, 4);
201 ret_float = ca_teams;
205 MUTATOR_HOOKFUNCTION(ca_PlayerPreThink)
207 if(!allowed_to_spawn)
208 self.stat_respawn_time = 0;
212 MUTATOR_HOOKFUNCTION(ca_ForbidPlayerScore_Clear)
217 MUTATOR_HOOKFUNCTION(ca_MakePlayerObserver)
219 if(self.killindicator_teamchange == -2)
222 self.frags = FRAGS_LMS_LOSER;
226 MUTATOR_HOOKFUNCTION(ca_ForbidThrowCurrentWeapon)
231 MUTATOR_HOOKFUNCTION(ca_GiveFragsForKill)
233 frag_score = 0; // score will be given to the winner team when the round ends
239 allowed_to_spawn = TRUE;
241 round_handler_Spawn(CA_CheckTeams, CA_CheckWinner, CA_RoundStart, 5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit);
243 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
244 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
245 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
246 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
249 MUTATOR_DEFINITION(gamemode_ca)
251 MUTATOR_HOOK(PlayerSpawn, ca_PlayerSpawn, CBC_ORDER_ANY);
252 MUTATOR_HOOK(PutClientInServer, ca_PutClientInServer, CBC_ORDER_ANY);
253 MUTATOR_HOOK(MakePlayerObserver, ca_MakePlayerObserver, CBC_ORDER_ANY);
254 MUTATOR_HOOK(ClientConnect, ca_ClientConnect, CBC_ORDER_ANY);
255 MUTATOR_HOOK(reset_map_global, ca_reset_map_global, CBC_ORDER_ANY);
256 MUTATOR_HOOK(reset_map_players, ca_reset_map_players, CBC_ORDER_ANY);
257 MUTATOR_HOOK(GetTeamCount, ca_GetTeamCount, CBC_ORDER_EXCLUSIVE);
258 MUTATOR_HOOK(PlayerPreThink, ca_PlayerPreThink, CBC_ORDER_ANY);
259 MUTATOR_HOOK(ForbidPlayerScore_Clear, ca_ForbidPlayerScore_Clear, CBC_ORDER_ANY);
260 MUTATOR_HOOK(ForbidThrowCurrentWeapon, ca_ForbidThrowCurrentWeapon, CBC_ORDER_ANY);
261 MUTATOR_HOOK(GiveFragsForKill, ca_GiveFragsForKill, CBC_ORDER_FIRST);
265 if(time > 1) // game loads at time 1
266 error("This is a game type and it cannot be added at runtime.");
272 print("This is a game type and it cannot be removed at runtime.");