4 int autocvar_g_ca_point_limit;
5 int autocvar_g_ca_point_leadlimit;
6 float autocvar_g_ca_round_timelimit;
7 bool autocvar_g_ca_team_spawns;
8 int autocvar_g_ca_teams;
9 int autocvar_g_ca_teams_override;
10 float autocvar_g_ca_warmup;
14 bool allowed_to_spawn;
16 const int ST_CA_ROUNDS = 1;
19 bool CA_CheckWinner();
21 bool ca_isEliminated(entity e);
23 REGISTER_MUTATOR(ca, false)
27 // game loads at time 1
28 if (time > 1) error("This is a game type and it cannot be added at runtime.");
30 allowed_to_spawn = true;
32 ca_teams = autocvar_g_ca_teams_override;
33 if (ca_teams < 2) ca_teams = autocvar_g_ca_teams;
34 ca_teams = bound(2, ca_teams, 4);
37 ScoreRules_basics(ca_teams, SFL_SORT_PRIO_PRIMARY, 0, true);
38 ScoreInfo_SetLabel_TeamScore(ST_CA_ROUNDS, "rounds", SFL_SORT_PRIO_PRIMARY);
39 ScoreRules_basics_end();
41 round_handler_Spawn(CA_CheckTeams, CA_CheckWinner, CA_RoundStart);
42 round_handler_Init(5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit);
44 EliminatedPlayers_Init(ca_isEliminated);
47 SetLimits(autocvar_g_ca_point_limit, autocvar_g_ca_point_leadlimit, -1, -1);
49 if (autocvar_g_ca_team_spawns)
50 have_team_spawns = -1; // request team spawns
55 LOG_INFO("This is a game type and it cannot be removed at runtime.");
62 // should be removed in the future, as other code should not have to care
63 .float caplayer; // 0.5 if scheduled to join the next round
67 float autocvar_g_ca_damage2score_multiplier;
68 bool autocvar_g_ca_spectate_enemies;
70 void CA_count_alive_players()
72 total_players = redalive = bluealive = yellowalive = pinkalive = 0;
73 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
76 case NUM_TEAM_1: ++total_players; if(!IS_DEAD(it)) ++redalive; break;
77 case NUM_TEAM_2: ++total_players; if(!IS_DEAD(it)) ++bluealive; break;
78 case NUM_TEAM_3: ++total_players; if(!IS_DEAD(it)) ++yellowalive; break;
79 case NUM_TEAM_4: ++total_players; if(!IS_DEAD(it)) ++pinkalive; break;
82 FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
83 it.redalive_stat = redalive;
84 it.bluealive_stat = bluealive;
85 it.yellowalive_stat = yellowalive;
86 it.pinkalive_stat = pinkalive;
90 float CA_GetWinnerTeam()
92 float winner_team = 0;
94 winner_team = NUM_TEAM_1;
97 if(winner_team) return 0;
98 winner_team = NUM_TEAM_2;
102 if(winner_team) return 0;
103 winner_team = NUM_TEAM_3;
107 if(winner_team) return 0;
108 winner_team = NUM_TEAM_4;
112 return -1; // no player left
115 #define CA_ALIVE_TEAMS() ((redalive > 0) + (bluealive > 0) + (yellowalive > 0) + (pinkalive > 0))
116 #define CA_ALIVE_TEAMS_OK() (CA_ALIVE_TEAMS() == ca_teams)
117 float CA_CheckWinner()
119 if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
121 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
122 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
123 allowed_to_spawn = false;
124 round_handler_Init(5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit);
125 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(nades_Clear(it)));
129 CA_count_alive_players();
130 if(CA_ALIVE_TEAMS() > 1)
133 int winner_team = CA_GetWinnerTeam();
136 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
137 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
138 TeamScore_AddToTeam(winner_team, ST_CA_ROUNDS, +1);
140 else if(winner_team == -1)
142 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
143 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
146 allowed_to_spawn = false;
147 round_handler_Init(5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit);
149 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(nades_Clear(it)));
156 allowed_to_spawn = boolean(warmup_stage);
161 static int prev_missing_teams_mask;
162 allowed_to_spawn = true;
163 CA_count_alive_players();
164 if(CA_ALIVE_TEAMS_OK())
166 if(prev_missing_teams_mask > 0)
167 Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_MISSING_TEAMS);
168 prev_missing_teams_mask = -1;
171 if(total_players == 0)
173 if(prev_missing_teams_mask > 0)
174 Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_MISSING_TEAMS);
175 prev_missing_teams_mask = -1;
178 int missing_teams_mask = (!redalive) + (!bluealive) * 2;
179 if(ca_teams >= 3) missing_teams_mask += (!yellowalive) * 4;
180 if(ca_teams >= 4) missing_teams_mask += (!pinkalive) * 8;
181 if(prev_missing_teams_mask != missing_teams_mask)
183 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
184 prev_missing_teams_mask = missing_teams_mask;
189 bool ca_isEliminated(entity e)
191 if(e.caplayer == 1 && (IS_DEAD(e) || e.frags == FRAGS_LMS_LOSER))
193 if(e.caplayer == 0.5)
198 /** Returns next available player to spectate if g_ca_spectate_enemies == 0 */
199 entity CA_SpectateNext(entity player, entity start)
201 if (SAME_TEAM(start, player)) return start;
202 // continue from current player
203 for (entity e = start; (e = find(e, classname, STR_PLAYER)); )
205 if (SAME_TEAM(player, e)) return e;
207 // restart from begining
208 for (entity e = NULL; (e = find(e, classname, STR_PLAYER)); )
210 if (SAME_TEAM(player, e)) return e;
216 MUTATOR_HOOKFUNCTION(ca, PlayerSpawn)
221 eliminatedPlayers.SendFlags |= 1;
224 MUTATOR_HOOKFUNCTION(ca, PutClientInServer)
227 if (!allowed_to_spawn && IS_PLAYER(this)) // this is true even when player is trying to join
229 this.classname = STR_OBSERVER;
230 if (this.jointime != time && !this.caplayer) // not when connecting
233 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_CA_JOIN_LATE);
238 MUTATOR_HOOKFUNCTION(ca, reset_map_players)
240 FOREACH_CLIENT(true, {
242 if (!it.caplayer && IS_BOT_CLIENT(it))
249 it.classname = STR_PLAYER;
251 WITH(entity, self, it, PutClientInServer());
257 MUTATOR_HOOKFUNCTION(ca, ClientConnect)
260 this.classname = STR_OBSERVER;
264 MUTATOR_HOOKFUNCTION(ca, reset_map_global)
266 allowed_to_spawn = true;
270 MUTATOR_HOOKFUNCTION(ca, GetTeamCount, CBC_ORDER_EXCLUSIVE)
272 ret_float = ca_teams;
276 entity ca_LastPlayerForTeam()
279 entity last_pl = NULL;
280 FOREACH_CLIENT(IS_PLAYER(it) && it != this, {
282 if (SAME_TEAM(this, it))
291 void ca_LastPlayerForTeam_Notify()
293 if (round_handler_IsActive())
294 if (round_handler_IsRoundStarted())
296 entity pl = ca_LastPlayerForTeam();
298 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
302 MUTATOR_HOOKFUNCTION(ca, PlayerDies)
304 ca_LastPlayerForTeam_Notify();
305 if (!allowed_to_spawn)
306 frag_target.respawn_flags = RESPAWN_SILENT;
308 eliminatedPlayers.SendFlags |= 1;
312 MUTATOR_HOOKFUNCTION(ca, ClientDisconnect)
315 if (this.caplayer == 1)
316 ca_LastPlayerForTeam_Notify();
320 MUTATOR_HOOKFUNCTION(ca, ForbidPlayerScore_Clear)
325 MUTATOR_HOOKFUNCTION(ca, MakePlayerObserver)
328 if (this.caplayer == 1)
329 ca_LastPlayerForTeam_Notify();
330 if (this.killindicator_teamchange == -2)
333 this.frags = FRAGS_LMS_LOSER;
335 eliminatedPlayers.SendFlags |= 1;
336 return true; // prevent team reset
339 MUTATOR_HOOKFUNCTION(ca, ForbidThrowCurrentWeapon)
344 MUTATOR_HOOKFUNCTION(ca, GiveFragsForKill, CBC_ORDER_FIRST)
346 frag_score = 0; // score will be given to the winner team when the round ends
350 MUTATOR_HOOKFUNCTION(ca, SetStartItems)
352 start_items &= ~IT_UNLIMITED_AMMO;
353 start_health = warmup_start_health = cvar("g_lms_start_health");
354 start_armorvalue = warmup_start_armorvalue = cvar("g_lms_start_armor");
355 start_ammo_shells = warmup_start_ammo_shells = cvar("g_lms_start_ammo_shells");
356 start_ammo_nails = warmup_start_ammo_nails = cvar("g_lms_start_ammo_nails");
357 start_ammo_rockets = warmup_start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
358 start_ammo_cells = warmup_start_ammo_cells = cvar("g_lms_start_ammo_cells");
359 start_ammo_plasma = warmup_start_ammo_plasma = cvar("g_lms_start_ammo_plasma");
360 start_ammo_fuel = warmup_start_ammo_fuel = cvar("g_lms_start_ammo_fuel");
365 MUTATOR_HOOKFUNCTION(ca, PlayerDamage_Calculate)
367 if (IS_PLAYER(frag_target))
368 if (!IS_DEAD(frag_target))
369 if (frag_target == frag_attacker || SAME_TEAM(frag_target, frag_attacker) || frag_deathtype == DEATH_FALL.m_id)
372 frag_mirrordamage = 0;
377 MUTATOR_HOOKFUNCTION(ca, FilterItem)
380 if (autocvar_g_powerups <= 0)
381 if (this.flags & FL_POWERUP)
384 if (autocvar_g_pickup_items <= 0)
390 MUTATOR_HOOKFUNCTION(ca, PlayerDamage_SplitHealthArmor)
392 float excess = max(0, frag_damage - damage_take - damage_save);
394 if (frag_target != frag_attacker && IS_PLAYER(frag_attacker))
395 PlayerTeamScore_Add(frag_attacker, SP_SCORE, ST_SCORE, (frag_damage - excess) * autocvar_g_ca_damage2score_multiplier);
400 MUTATOR_HOOKFUNCTION(ca, PlayerRegen)
402 // no regeneration in CA
406 MUTATOR_HOOKFUNCTION(ca, Scores_CountFragsRemaining)
408 // announce remaining frags
412 MUTATOR_HOOKFUNCTION(ca, SpectateSet)
415 if (!autocvar_g_ca_spectate_enemies && this.caplayer)
416 if (DIFF_TEAM(spec_player, this))
421 MUTATOR_HOOKFUNCTION(ca, SpectateNext)
424 if (!autocvar_g_ca_spectate_enemies && this.caplayer)
426 spec_player = CA_SpectateNext(this, spec_player);
432 MUTATOR_HOOKFUNCTION(ca, SpectatePrev)
435 if (!autocvar_g_ca_spectate_enemies && this.caplayer)
437 do { spec_player = spec_player.chain; }
438 while(spec_player && DIFF_TEAM(spec_player, this));
442 for (spec_player = spec_first; spec_player && DIFF_TEAM(spec_player, this); spec_player = spec_player.chain);
444 if (spec_player == this.enemy)
445 return MUT_SPECPREV_RETURN;
449 return MUT_SPECPREV_FOUND;
452 MUTATOR_HOOKFUNCTION(ca, Bot_FixCount, CBC_ORDER_EXCLUSIVE)
454 FOREACH_CLIENT(IS_REAL_CLIENT(it), {
455 if (IS_PLAYER(it) || it.caplayer == 1)
456 ++bot_activerealplayers;
462 MUTATOR_HOOKFUNCTION(ca, ClientCommand_Spectate)
467 // they're going to spec, we can do other checks
468 if (autocvar_sv_spectate && (IS_SPEC(this) || IS_OBSERVER(this)))
469 Send_Notification(NOTIF_ONE_ONLY, this, MSG_INFO, INFO_CA_LEAVE);
470 return MUT_SPECCMD_FORCE;
473 return MUT_SPECCMD_CONTINUE;
476 MUTATOR_HOOKFUNCTION(ca, WantWeapon)
482 MUTATOR_HOOKFUNCTION(ca, GetPlayerStatus)
484 return set_player.caplayer == 1;
487 MUTATOR_HOOKFUNCTION(ca, SetWeaponArena)
489 // most weapons arena
490 if (ret_string == "0" || ret_string == "") ret_string = "most";