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 == NUM_TEAM_1)
15 if (e.health >= 1) ++redalive;
17 else if(e.team == NUM_TEAM_2)
20 if (e.health >= 1) ++bluealive;
22 else if(e.team == NUM_TEAM_3)
25 if (e.health >= 1) ++yellowalive;
27 else if(e.team == NUM_TEAM_4)
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 = NUM_TEAM_1;
48 if(winner_team) return 0;
49 winner_team = NUM_TEAM_2;
53 if(winner_team) return 0;
54 winner_team = NUM_TEAM_3;
58 if(winner_team) return 0;
59 winner_team = NUM_TEAM_4;
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_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
73 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
74 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
75 allowed_to_spawn = FALSE;
76 round_handler_Init(5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit);
82 CA_count_alive_players();
83 if(CA_ALIVE_TEAMS() > 1)
86 float winner_team = CA_GetWinnerTeam();
89 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
90 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
91 TeamScore_AddToTeam(winner_team, ST_CA_ROUNDS, +1);
93 else if(winner_team == -1)
95 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
96 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
99 allowed_to_spawn = FALSE;
100 round_handler_Init(5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit);
111 allowed_to_spawn = TRUE;
113 allowed_to_spawn = FALSE;
116 float prev_missing_teams_mask;
117 float CA_CheckTeams()
119 allowed_to_spawn = TRUE;
120 CA_count_alive_players();
121 if(CA_ALIVE_TEAMS_OK())
123 if(prev_missing_teams_mask > 0)
124 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
125 prev_missing_teams_mask = -1;
128 if(total_players == 0)
130 if(prev_missing_teams_mask > 0)
131 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
132 prev_missing_teams_mask = -1;
135 float missing_teams_mask = (!redalive) + (!bluealive) * 2;
136 if(ca_teams >= 3) missing_teams_mask += (!yellowalive) * 4;
137 if(ca_teams >= 4) missing_teams_mask += (!pinkalive) * 8;
138 if(prev_missing_teams_mask != missing_teams_mask)
140 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
141 prev_missing_teams_mask = missing_teams_mask;
146 MUTATOR_HOOKFUNCTION(ca_PlayerSpawn)
152 MUTATOR_HOOKFUNCTION(ca_PutClientInServer)
154 if(!allowed_to_spawn)
155 if(IS_PLAYER(self)) // this is true even when player is trying to join
157 self.classname = "observer";
158 if(self.jointime != time) //not when connecting
162 if(IS_REAL_CLIENT(self))
163 Send_Notification(NOTIF_ONE_ONLY, self, MSG_INFO, INFO_CA_JOIN_LATE);
169 MUTATOR_HOOKFUNCTION(ca_reset_map_players)
171 FOR_EACH_CLIENT(self)
174 if(!self.caplayer && IS_BOT_CLIENT(self))
181 self.classname = "player";
189 MUTATOR_HOOKFUNCTION(ca_ClientConnect)
191 self.classname = "observer";
195 MUTATOR_HOOKFUNCTION(ca_reset_map_global)
197 allowed_to_spawn = TRUE;
201 MUTATOR_HOOKFUNCTION(ca_GetTeamCount)
203 ret_float = ca_teams;
207 entity ca_LastPlayerForTeam()
209 entity pl, last_pl = world;
214 if(pl.team == self.team)
223 void ca_LastPlayerForTeam_Notify()
225 if(round_handler_IsActive())
226 if(round_handler_IsRoundStarted())
228 entity pl = ca_LastPlayerForTeam();
230 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
234 MUTATOR_HOOKFUNCTION(ca_PlayerDies)
236 ca_LastPlayerForTeam_Notify();
237 if(!allowed_to_spawn)
238 self.respawn_flags = RESPAWN_SILENT;
242 MUTATOR_HOOKFUNCTION(ca_ClientDisconnect)
244 if(self.caplayer == 1)
245 ca_LastPlayerForTeam_Notify();
249 MUTATOR_HOOKFUNCTION(ca_ForbidPlayerScore_Clear)
254 MUTATOR_HOOKFUNCTION(ca_MakePlayerObserver)
256 if(self.caplayer == 1)
257 ca_LastPlayerForTeam_Notify();
258 if(self.killindicator_teamchange == -2)
261 self.frags = FRAGS_LMS_LOSER;
265 MUTATOR_HOOKFUNCTION(ca_ForbidThrowCurrentWeapon)
270 MUTATOR_HOOKFUNCTION(ca_GiveFragsForKill)
272 frag_score = 0; // score will be given to the winner team when the round ends
276 MUTATOR_HOOKFUNCTION(ca_SetStartItems)
278 start_items &= ~IT_UNLIMITED_AMMO;
279 start_health = warmup_start_health = cvar("g_lms_start_health");
280 start_armorvalue = warmup_start_armorvalue = cvar("g_lms_start_armor");
281 start_ammo_shells = warmup_start_ammo_shells = cvar("g_lms_start_ammo_shells");
282 start_ammo_nails = warmup_start_ammo_nails = cvar("g_lms_start_ammo_nails");
283 start_ammo_rockets = warmup_start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
284 start_ammo_cells = warmup_start_ammo_cells = cvar("g_lms_start_ammo_cells");
285 start_ammo_fuel = warmup_start_ammo_fuel = cvar("g_lms_start_ammo_fuel");
290 MUTATOR_HOOKFUNCTION(ca_PlayerDamage)
292 if(IS_PLAYER(frag_target))
293 if(frag_target.deadflag == DEAD_NO)
294 if(frag_target == frag_attacker || SAME_TEAM(frag_target, frag_attacker) || frag_deathtype == DEATH_FALL)
297 frag_mirrordamage = 0;
302 MUTATOR_HOOKFUNCTION(ca_FilterItem)
304 if(autocvar_g_powerups <= 0)
305 if(self.flags & FL_POWERUP)
308 if(autocvar_g_pickup_items <= 0)
314 MUTATOR_HOOKFUNCTION(ca_PlayerDamage_SplitHealthArmor)
316 float excess = max(0, frag_damage - damage_take - damage_save);
318 if(frag_target != frag_attacker && IS_PLAYER(frag_attacker))
319 PlayerTeamScore_Add(frag_attacker, SP_SCORE, ST_SCORE, (frag_damage - excess) * autocvar_g_ca_damage2score_multiplier);
324 MUTATOR_HOOKFUNCTION(ca_PlayerRegen)
326 // no regeneration in CA
332 allowed_to_spawn = TRUE;
334 ca_teams = autocvar_g_ca_teams_override;
336 ca_teams = autocvar_g_ca_teams;
337 ca_teams = bound(2, ca_teams, 4);
338 ret_float = ca_teams;
339 ScoreRules_ca(ca_teams);
341 round_handler_Spawn(CA_CheckTeams, CA_CheckWinner, CA_RoundStart);
342 round_handler_Init(5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit);
344 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
345 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
346 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
347 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
350 MUTATOR_DEFINITION(gamemode_ca)
352 MUTATOR_HOOK(PlayerSpawn, ca_PlayerSpawn, CBC_ORDER_ANY);
353 MUTATOR_HOOK(PutClientInServer, ca_PutClientInServer, CBC_ORDER_ANY);
354 MUTATOR_HOOK(MakePlayerObserver, ca_MakePlayerObserver, CBC_ORDER_ANY);
355 MUTATOR_HOOK(ClientConnect, ca_ClientConnect, CBC_ORDER_ANY);
356 MUTATOR_HOOK(reset_map_global, ca_reset_map_global, CBC_ORDER_ANY);
357 MUTATOR_HOOK(reset_map_players, ca_reset_map_players, CBC_ORDER_ANY);
358 MUTATOR_HOOK(GetTeamCount, ca_GetTeamCount, CBC_ORDER_EXCLUSIVE);
359 MUTATOR_HOOK(PlayerDies, ca_PlayerDies, CBC_ORDER_ANY);
360 MUTATOR_HOOK(ClientDisconnect, ca_ClientDisconnect, CBC_ORDER_ANY);
361 MUTATOR_HOOK(ForbidPlayerScore_Clear, ca_ForbidPlayerScore_Clear, CBC_ORDER_ANY);
362 MUTATOR_HOOK(ForbidThrowCurrentWeapon, ca_ForbidThrowCurrentWeapon, CBC_ORDER_ANY);
363 MUTATOR_HOOK(GiveFragsForKill, ca_GiveFragsForKill, CBC_ORDER_FIRST);
364 MUTATOR_HOOK(SetStartItems, ca_SetStartItems, CBC_ORDER_ANY);
365 MUTATOR_HOOK(PlayerDamage_Calculate, ca_PlayerDamage, CBC_ORDER_ANY);
366 MUTATOR_HOOK(FilterItem, ca_FilterItem, CBC_ORDER_ANY);
367 MUTATOR_HOOK(PlayerDamage_SplitHealthArmor, ca_PlayerDamage_SplitHealthArmor, CBC_ORDER_ANY);
368 MUTATOR_HOOK(PlayerRegen, ca_PlayerRegen, CBC_ORDER_ANY);
372 if(time > 1) // game loads at time 1
373 error("This is a game type and it cannot be added at runtime.");
379 print("This is a game type and it cannot be removed at runtime.");