1 #include "gamemode_ca.qh"
3 float autocvar_g_ca_damage2score_multiplier;
4 bool autocvar_g_ca_spectate_enemies;
6 void CA_count_alive_players()
8 total_players = redalive = bluealive = yellowalive = pinkalive = 0;
9 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
12 case NUM_TEAM_1: ++total_players; if(!IS_DEAD(it)) ++redalive; break;
13 case NUM_TEAM_2: ++total_players; if(!IS_DEAD(it)) ++bluealive; break;
14 case NUM_TEAM_3: ++total_players; if(!IS_DEAD(it)) ++yellowalive; break;
15 case NUM_TEAM_4: ++total_players; if(!IS_DEAD(it)) ++pinkalive; break;
18 FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
19 it.redalive_stat = redalive;
20 it.bluealive_stat = bluealive;
21 it.yellowalive_stat = yellowalive;
22 it.pinkalive_stat = pinkalive;
26 float CA_GetWinnerTeam()
28 float winner_team = 0;
30 winner_team = NUM_TEAM_1;
33 if(winner_team) return 0;
34 winner_team = NUM_TEAM_2;
38 if(winner_team) return 0;
39 winner_team = NUM_TEAM_3;
43 if(winner_team) return 0;
44 winner_team = NUM_TEAM_4;
48 return -1; // no player left
51 void nades_Clear(entity player);
53 #define CA_ALIVE_TEAMS() ((redalive > 0) + (bluealive > 0) + (yellowalive > 0) + (pinkalive > 0))
54 #define CA_ALIVE_TEAMS_OK() (CA_ALIVE_TEAMS() == NumTeams(ca_teams))
55 float CA_CheckWinner()
57 if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
59 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_OVER);
60 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_OVER);
61 allowed_to_spawn = false;
62 round_handler_Init(5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit);
63 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(nades_Clear(it)));
67 CA_count_alive_players();
68 if(CA_ALIVE_TEAMS() > 1)
71 int winner_team = CA_GetWinnerTeam();
74 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
75 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
76 TeamScore_AddToTeam(winner_team, ST_CA_ROUNDS, +1);
78 else if(winner_team == -1)
80 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_TIED);
81 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_TIED);
84 allowed_to_spawn = false;
85 round_handler_Init(5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit);
87 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(nades_Clear(it)));
94 allowed_to_spawn = boolean(warmup_stage);
99 static int prev_missing_teams_mask;
100 allowed_to_spawn = true;
101 CA_count_alive_players();
102 if(CA_ALIVE_TEAMS_OK())
104 if(prev_missing_teams_mask > 0)
105 Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_TEAMS);
106 prev_missing_teams_mask = -1;
109 if(total_players == 0)
111 if(prev_missing_teams_mask > 0)
112 Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_TEAMS);
113 prev_missing_teams_mask = -1;
116 int missing_teams_mask = 0;
117 if(ca_teams & BIT(0))
118 missing_teams_mask += (!redalive) * 1;
119 if(ca_teams & BIT(1))
120 missing_teams_mask += (!bluealive) * 2;
121 if(ca_teams & BIT(2))
122 missing_teams_mask += (!yellowalive) * 4;
123 if(ca_teams & BIT(3))
124 missing_teams_mask += (!pinkalive) * 8;
125 if(prev_missing_teams_mask != missing_teams_mask)
127 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
128 prev_missing_teams_mask = missing_teams_mask;
133 bool ca_isEliminated(entity e)
135 if(e.caplayer == 1 && (IS_DEAD(e) || e.frags == FRAGS_LMS_LOSER))
137 if(e.caplayer == 0.5)
142 /** Returns next available player to spectate if g_ca_spectate_enemies == 0 */
143 entity CA_SpectateNext(entity player, entity start)
145 if (SAME_TEAM(start, player)) return start;
146 // continue from current player
147 for (entity e = start; (e = find(e, classname, STR_PLAYER)); )
149 if (SAME_TEAM(player, e)) return e;
151 // restart from begining
152 for (entity e = NULL; (e = find(e, classname, STR_PLAYER)); )
154 if (SAME_TEAM(player, e)) return e;
160 MUTATOR_HOOKFUNCTION(ca, PlayerSpawn)
162 entity player = M_ARGV(0, entity);
166 eliminatedPlayers.SendFlags |= 1;
169 MUTATOR_HOOKFUNCTION(ca, ForbidSpawn)
171 entity player = M_ARGV(0, entity);
173 // spectators / observers that weren't playing can join; they are
174 // immediately forced to observe in the PutClientInServer hook
175 // this way they are put in a team and can play in the next round
176 if (!allowed_to_spawn && player.caplayer)
181 MUTATOR_HOOKFUNCTION(ca, PutClientInServer)
183 entity player = M_ARGV(0, entity);
185 if (!allowed_to_spawn && IS_PLAYER(player)) // this is true even when player is trying to join
187 TRANSMUTE(Observer, player);
188 if (player.jointime != time && !player.caplayer) // not when connecting
190 player.caplayer = 0.5;
191 Send_Notification(NOTIF_ONE_ONLY, player, MSG_INFO, INFO_CA_JOIN_LATE);
196 MUTATOR_HOOKFUNCTION(ca, reset_map_players)
198 FOREACH_CLIENT(true, {
200 if (!it.caplayer && IS_BOT_CLIENT(it))
207 TRANSMUTE(Player, it);
209 PutClientInServer(it);
215 MUTATOR_HOOKFUNCTION(ca, ClientConnect)
217 entity player = M_ARGV(0, entity);
219 TRANSMUTE(Observer, player);
223 MUTATOR_HOOKFUNCTION(ca, reset_map_global)
225 allowed_to_spawn = true;
229 MUTATOR_HOOKFUNCTION(ca, GetTeamCount, CBC_ORDER_EXCLUSIVE)
231 M_ARGV(0, float) = ca_teams;
234 entity ca_LastPlayerForTeam(entity this)
236 entity last_pl = NULL;
237 FOREACH_CLIENT(IS_PLAYER(it) && it != this, {
239 if (SAME_TEAM(this, it))
248 void ca_LastPlayerForTeam_Notify(entity this)
250 if (round_handler_IsActive())
251 if (round_handler_IsRoundStarted())
253 entity pl = ca_LastPlayerForTeam(this);
255 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
259 MUTATOR_HOOKFUNCTION(ca, PlayerDies)
261 entity frag_target = M_ARGV(2, entity);
263 ca_LastPlayerForTeam_Notify(frag_target);
264 if (!allowed_to_spawn)
265 frag_target.respawn_flags = RESPAWN_SILENT;
267 eliminatedPlayers.SendFlags |= 1;
271 MUTATOR_HOOKFUNCTION(ca, ClientDisconnect)
273 entity player = M_ARGV(0, entity);
275 if (player.caplayer == 1)
276 ca_LastPlayerForTeam_Notify(player);
280 MUTATOR_HOOKFUNCTION(ca, ForbidPlayerScore_Clear)
285 MUTATOR_HOOKFUNCTION(ca, MakePlayerObserver)
287 entity player = M_ARGV(0, entity);
289 if (!IS_DEAD(player))
290 ca_LastPlayerForTeam_Notify(player);
291 if (player.killindicator_teamchange == -2)
294 player.frags = FRAGS_LMS_LOSER;
296 player.frags = FRAGS_SPECTATOR;
298 eliminatedPlayers.SendFlags |= 1;
299 return true; // prevent team reset
302 MUTATOR_HOOKFUNCTION(ca, ForbidThrowCurrentWeapon)
307 MUTATOR_HOOKFUNCTION(ca, GiveFragsForKill, CBC_ORDER_FIRST)
309 M_ARGV(2, float) = 0; // score will be given to the winner team when the round ends
313 MUTATOR_HOOKFUNCTION(ca, SetStartItems)
315 start_items &= ~IT_UNLIMITED_AMMO;
316 start_health = warmup_start_health = cvar("g_lms_start_health");
317 start_armorvalue = warmup_start_armorvalue = cvar("g_lms_start_armor");
318 start_ammo_shells = warmup_start_ammo_shells = cvar("g_lms_start_ammo_shells");
319 start_ammo_nails = warmup_start_ammo_nails = cvar("g_lms_start_ammo_nails");
320 start_ammo_rockets = warmup_start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
321 start_ammo_cells = warmup_start_ammo_cells = cvar("g_lms_start_ammo_cells");
322 start_ammo_plasma = warmup_start_ammo_plasma = cvar("g_lms_start_ammo_plasma");
323 start_ammo_fuel = warmup_start_ammo_fuel = cvar("g_lms_start_ammo_fuel");
326 MUTATOR_HOOKFUNCTION(ca, PlayerDamage_Calculate)
328 entity frag_attacker = M_ARGV(1, entity);
329 entity frag_target = M_ARGV(2, entity);
330 float frag_deathtype = M_ARGV(3, float);
331 float frag_damage = M_ARGV(4, float);
332 float frag_mirrordamage = M_ARGV(5, float);
334 if (IS_PLAYER(frag_target))
335 if (!IS_DEAD(frag_target))
336 if (frag_target == frag_attacker || SAME_TEAM(frag_target, frag_attacker) || frag_deathtype == DEATH_FALL.m_id)
339 frag_mirrordamage = 0;
341 M_ARGV(4, float) = frag_damage;
342 M_ARGV(5, float) = frag_mirrordamage;
345 MUTATOR_HOOKFUNCTION(ca, FilterItem)
347 entity item = M_ARGV(0, entity);
349 if (autocvar_g_powerups <= 0)
350 if (item.flags & FL_POWERUP)
353 if (autocvar_g_pickup_items <= 0)
357 MUTATOR_HOOKFUNCTION(ca, PlayerDamage_SplitHealthArmor)
359 entity frag_attacker = M_ARGV(1, entity);
360 entity frag_target = M_ARGV(2, entity);
361 float frag_damage = M_ARGV(7, float);
362 float damage_take = M_ARGV(4, float);
363 float damage_save = M_ARGV(5, float);
365 float excess = max(0, frag_damage - damage_take - damage_save);
367 if (frag_target != frag_attacker && IS_PLAYER(frag_attacker))
368 PlayerTeamScore_Add(frag_attacker, SP_SCORE, ST_SCORE, (frag_damage - excess) * autocvar_g_ca_damage2score_multiplier);
371 MUTATOR_HOOKFUNCTION(ca, PlayerRegen)
373 // no regeneration in CA
377 MUTATOR_HOOKFUNCTION(ca, Scores_CountFragsRemaining)
379 // announce remaining frags
383 MUTATOR_HOOKFUNCTION(ca, SpectateSet)
385 entity client = M_ARGV(0, entity);
386 entity targ = M_ARGV(1, entity);
388 if (!autocvar_g_ca_spectate_enemies && client.caplayer)
389 if (DIFF_TEAM(targ, client))
393 MUTATOR_HOOKFUNCTION(ca, SpectateNext)
395 entity client = M_ARGV(0, entity);
397 if (!autocvar_g_ca_spectate_enemies && client.caplayer)
399 entity targ = M_ARGV(1, entity);
400 M_ARGV(1, entity) = CA_SpectateNext(client, targ);
405 MUTATOR_HOOKFUNCTION(ca, SpectatePrev)
407 entity client = M_ARGV(0, entity);
408 entity targ = M_ARGV(1, entity);
409 entity first = M_ARGV(2, entity);
411 if (!autocvar_g_ca_spectate_enemies && client.caplayer)
413 do { targ = targ.chain; }
414 while(targ && DIFF_TEAM(targ, client));
418 for (targ = first; targ && DIFF_TEAM(targ, client); targ = targ.chain);
420 if (targ == client.enemy)
421 return MUT_SPECPREV_RETURN;
425 M_ARGV(1, entity) = targ;
427 return MUT_SPECPREV_FOUND;
430 MUTATOR_HOOKFUNCTION(ca, Bot_FixCount, CBC_ORDER_EXCLUSIVE)
432 FOREACH_CLIENT(IS_REAL_CLIENT(it), {
433 if (IS_PLAYER(it) || it.caplayer == 1)
440 MUTATOR_HOOKFUNCTION(ca, ClientCommand_Spectate)
442 entity player = M_ARGV(0, entity);
446 // they're going to spec, we can do other checks
447 if (autocvar_sv_spectate && (IS_SPEC(player) || IS_OBSERVER(player)))
448 Send_Notification(NOTIF_ONE_ONLY, player, MSG_INFO, INFO_CA_LEAVE);
449 return MUT_SPECCMD_FORCE;
452 return MUT_SPECCMD_CONTINUE;
455 MUTATOR_HOOKFUNCTION(ca, WantWeapon)
457 M_ARGV(2, bool) = true; // all weapons
460 MUTATOR_HOOKFUNCTION(ca, GetPlayerStatus)
462 entity player = M_ARGV(0, entity);
464 return player.caplayer == 1;
467 MUTATOR_HOOKFUNCTION(ca, SetWeaponArena)
469 // most weapons arena
470 if (M_ARGV(0, string) == "0" || M_ARGV(0, string) == "") M_ARGV(0, string) = "most";