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 = TRUE;
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 = TRUE;
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)
150 self.caplayer = TRUE;
154 MUTATOR_HOOKFUNCTION(ca_PutClientInServer)
156 if(clienttype(self) == CLIENTTYPE_BOT)
157 self.caplayer = TRUE;
158 if(!allowed_to_spawn)
159 self.classname = "observer";
163 MUTATOR_HOOKFUNCTION(ca_reset_map_players)
165 FOR_EACH_CLIENT(self)
169 self.classname = "player";
176 MUTATOR_HOOKFUNCTION(ca_ClientConnect)
178 self.classname = "observer";
182 MUTATOR_HOOKFUNCTION(ca_reset_map_global)
184 allowed_to_spawn = TRUE;
188 MUTATOR_HOOKFUNCTION(ca_GetTeamCount)
190 ca_teams = autocvar_g_ca_teams_override;
192 ca_teams = autocvar_g_ca_teams;
193 ca_teams = bound(2, ca_teams, 4);
194 ret_float = ca_teams;
198 MUTATOR_HOOKFUNCTION(ca_PlayerPreThink)
200 if(!allowed_to_spawn)
201 self.stat_respawn_time = 0;
205 MUTATOR_HOOKFUNCTION(ca_ForbidPlayerScore_Clear)
210 MUTATOR_HOOKFUNCTION(ca_MakePlayerObserver)
213 self.frags = FRAGS_LMS_LOSER;
217 MUTATOR_HOOKFUNCTION(ca_ForbidThrowCurrentWeapon)
222 MUTATOR_HOOKFUNCTION(ca_GiveFragsForKill)
224 frag_score = 0; // score will be given to the winner team when the round ends
230 allowed_to_spawn = TRUE;
232 round_handler_Spawn(CA_CheckTeams, CA_CheckWinner, CA_RoundStart, 5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit);
234 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
235 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
236 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
237 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
240 MUTATOR_DEFINITION(gamemode_ca)
242 MUTATOR_HOOK(PlayerSpawn, ca_PlayerSpawn, CBC_ORDER_ANY);
243 MUTATOR_HOOK(PutClientInServer, ca_PutClientInServer, CBC_ORDER_ANY);
244 MUTATOR_HOOK(MakePlayerObserver, ca_MakePlayerObserver, CBC_ORDER_ANY);
245 MUTATOR_HOOK(ClientConnect, ca_ClientConnect, CBC_ORDER_ANY);
246 MUTATOR_HOOK(reset_map_global, ca_reset_map_global, CBC_ORDER_ANY);
247 MUTATOR_HOOK(reset_map_players, ca_reset_map_players, CBC_ORDER_ANY);
248 MUTATOR_HOOK(GetTeamCount, ca_GetTeamCount, CBC_ORDER_EXCLUSIVE);
249 MUTATOR_HOOK(PlayerPreThink, ca_PlayerPreThink, CBC_ORDER_ANY);
250 MUTATOR_HOOK(ForbidPlayerScore_Clear, ca_ForbidPlayerScore_Clear, CBC_ORDER_ANY);
251 MUTATOR_HOOK(ForbidThrowCurrentWeapon, ca_ForbidThrowCurrentWeapon, CBC_ORDER_ANY);
252 MUTATOR_HOOK(GiveFragsForKill, ca_GiveFragsForKill, CBC_ORDER_FIRST);
256 if(time > 1) // game loads at time 1
257 error("This is a game type and it cannot be added at runtime.");
263 print("This is a game type and it cannot be removed at runtime.");