]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/gamemodes/gamemode/clanarena/sv_clanarena.qc
Merge branch 'drjaska/round_enddelay' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / clanarena / sv_clanarena.qc
1 #include "sv_clanarena.qh"
2
3 float autocvar_g_ca_damage2score = 100;
4 int autocvar_g_ca_prevent_stalemate;
5
6 float autocvar_g_ca_start_health = 200;
7 float autocvar_g_ca_start_armor = 200;
8 float autocvar_g_ca_start_ammo_shells = 60;
9 float autocvar_g_ca_start_ammo_nails = 320;
10 float autocvar_g_ca_start_ammo_rockets = 160;
11 float autocvar_g_ca_start_ammo_cells = 180;
12 float autocvar_g_ca_start_ammo_plasma = 180;
13 float autocvar_g_ca_start_ammo_fuel = 0;
14
15 .float ca_damage_counter;
16 .int prev_team;
17
18 void CA_count_alive_players()
19 {
20         total_players = 0;
21         for (int i = 1; i <= NUM_TEAMS; ++i)
22         {
23                 Team_SetNumberOfAlivePlayers(Team_GetTeamFromIndex(i), 0);
24         }
25         FOREACH_CLIENT(IS_PLAYER(it) && Entity_HasValidTeam(it),
26         {
27                 ++total_players;
28                 if (IS_DEAD(it))
29                 {
30                         continue;
31                 }
32                 entity team_ = Entity_GetTeam(it);
33                 int num_alive = Team_GetNumberOfAlivePlayers(team_);
34                 ++num_alive;
35                 Team_SetNumberOfAlivePlayers(team_, num_alive);
36         });
37         FOREACH_CLIENT(IS_REAL_CLIENT(it),
38         {
39                 STAT(REDALIVE, it) = Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(1));
40                 STAT(BLUEALIVE, it) = Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(2));
41                 STAT(YELLOWALIVE, it) = Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(3));
42                 STAT(PINKALIVE, it) = Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(4));
43         });
44 }
45
46 void nades_Clear(entity player);
47
48 int CA_PreventStalemate()
49 {
50         //bprint("PreventStalemate running\n");
51
52         // g_ca_prevent_stalemate:
53         // Run survivor count check with 1 aka bit 0b0001
54         // Run total health check with 2 aka bit 0b0010
55         // With a value like 3 which has both bits both are ran
56
57         bool prevent_stalemate_by_survivors = (autocvar_g_ca_prevent_stalemate & BIT(0));
58         bool prevent_stalemate_by_health    = (autocvar_g_ca_prevent_stalemate & BIT(1));
59
60         // Check which team has more alive players
61         if (prevent_stalemate_by_survivors)
62         {
63                 int winnerTeam = 0;
64                 int secondTeam = 0;
65
66                 for(int i = 1; i <= AVAILABLE_TEAMS; ++i)
67                 {
68                         if(!winnerTeam || Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(i)) > Team_GetNumberOfAlivePlayers(Team_GetTeam(winnerTeam)))
69                         {
70                                 secondTeam = winnerTeam;
71                                 winnerTeam = Team_IndexToTeam(i);
72                         }
73                         else
74                         {
75                                 if(!secondTeam || Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(i)) > Team_GetNumberOfAlivePlayers(Team_GetTeam(secondTeam)))
76                                         secondTeam = Team_IndexToTeam(i);
77                         }
78                 }
79
80                 if(Team_GetNumberOfAlivePlayers(Team_GetTeam(winnerTeam)) != Team_GetNumberOfAlivePlayers(Team_GetTeam(secondTeam)))
81                 {
82                         bprint(sprintf("Stalemate broken by alive players. Best team: %s%s (%d)^7 - Trailing team: %s%s (%d)\n",
83                                 Team_ColorCode(winnerTeam), Team_ColorName(winnerTeam), Team_GetNumberOfAlivePlayers(Team_GetTeam(winnerTeam)),
84                                 Team_ColorCode(secondTeam), Team_ColorName(secondTeam), Team_GetNumberOfAlivePlayers(Team_GetTeam(secondTeam))));
85                         return winnerTeam;
86                 }
87         }
88
89         // Check which team has more health
90         if (prevent_stalemate_by_health)
91         {
92                 int winnerTeam = 0;
93                 int secondTeam = 0;
94                 int winnerTeamHealth = 0;
95                 int secondTeamHealth = 0;
96                 int teamIndex, teamHealth;
97
98                 for(int i = 1; i <= AVAILABLE_TEAMS; ++i)
99                 {
100                         teamIndex = i;
101                         teamHealth = 0;
102
103                         // Add up health for the players in this team
104                         FOREACH_CLIENT(IS_PLAYER(it) && Entity_HasValidTeam(it) && it.team == Team_IndexToTeam(teamIndex),
105                         {
106                                 if (IS_DEAD(it))
107                                         continue;
108                                 teamHealth += GetResource(it, RES_HEALTH) + GetResource(it, RES_ARMOR);
109                         });
110
111                         // Set the winner teams
112                         if(!winnerTeam || teamHealth > winnerTeamHealth)
113                         {
114                                 secondTeam = winnerTeam;
115                                 secondTeamHealth = winnerTeamHealth;
116                                 winnerTeam = Team_IndexToTeam(i);
117                                 winnerTeamHealth = teamHealth;
118                         }
119                         else
120                         {
121                                 if(!secondTeam || teamHealth > secondTeamHealth)
122                                 {
123                                         secondTeam = Team_IndexToTeam(i);
124                                         secondTeamHealth = teamHealth;
125                                 }
126                         }
127                 }
128
129                 if(winnerTeamHealth != secondTeamHealth)
130                 {
131                         bprint(sprintf("Stalemate broken by team health. Best team: %s%s (%d)^7 - Trailing team: %s%s (%d)\n",
132                                 Team_ColorCode(winnerTeam), Team_ColorName(winnerTeam), winnerTeamHealth,
133                                 Team_ColorCode(secondTeam), Team_ColorName(secondTeam), secondTeamHealth));
134                         return winnerTeam;
135                 }
136         }
137
138         return -2; // Equality. Can't avoid the stalemate.
139 }
140
141 float autocvar_g_ca_round_enddelay = 1;
142 float CA_CheckWinner()
143 {
144         int winner_team = 0;
145
146         if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
147         {
148                 // attempt to prevent stalemate by survivor count AND/OR total team health?
149                 bool prevent_stalemate_by_survivors = (autocvar_g_ca_prevent_stalemate & BIT(0));
150                 bool prevent_stalemate_by_health    = (autocvar_g_ca_prevent_stalemate & BIT(1));
151
152                 if(prevent_stalemate_by_survivors || prevent_stalemate_by_health)
153                         winner_team = CA_PreventStalemate();
154                 else
155                         winner_team = -2;
156         }
157
158         CA_count_alive_players();
159         if (!winner_team)
160                 winner_team = Team_GetWinnerAliveTeam();
161         if (!winner_team)
162         {
163                 // Dr. Jaska:
164                 // reset delay time here only for consistency
165                 // CA players currently have no known ways to resurrect
166                 round_handler_ResetEndDelayTime();
167                 return 0;
168         }
169
170         // delay round ending a bit
171         if (autocvar_g_ca_round_enddelay
172                 && round_handler_GetEndTime() > 0
173                 && round_handler_GetEndTime() - time > 0) // don't delay past timelimit
174         {
175                 if (round_handler_GetEndDelayTime() == -1)
176                 {
177                         round_handler_SetEndDelayTime(min(time + autocvar_g_ca_round_enddelay, round_handler_GetEndTime()));
178                         return 0;
179                 }
180                 else if (round_handler_GetEndDelayTime() >= time)
181                 {
182                         return 0;
183                 }
184         }
185
186         if(winner_team > 0)
187         {
188                 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
189                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
190                 TeamScore_AddToTeam(winner_team, ST_CA_ROUNDS, +1);
191         }
192         else if(winner_team == -1)
193         {
194                 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_TIED);
195                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_TIED);
196         }
197         else if(winner_team == -2)
198         {
199                 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_OVER);
200                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_OVER);
201         }
202
203         allowed_to_spawn = false;
204         game_stopped = true;
205         round_handler_Init(5, autocvar_g_ca_warmup, autocvar_g_ca_round_timelimit);
206
207         FOREACH_CLIENT(IS_PLAYER(it), { nades_Clear(it); });
208
209         return 1;
210 }
211
212 void CA_RoundStart()
213 {
214         allowed_to_spawn = boolean(warmup_stage);
215         if (!warmup_stage)
216                 FOREACH_CLIENT(IS_PLAYER(it), it.prev_team = it.team);
217 }
218
219 bool CA_CheckTeams()
220 {
221         static int prev_missing_teams_mask;
222         allowed_to_spawn = true;
223         CA_count_alive_players();
224         if (Team_GetNumberOfAliveTeams() == NumTeams(ca_teams))
225         {
226                 if(prev_missing_teams_mask > 0)
227                         Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_TEAMS);
228                 prev_missing_teams_mask = -1;
229                 return true;
230         }
231         if(total_players == 0)
232         {
233                 if(prev_missing_teams_mask > 0)
234                         Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_TEAMS);
235                 prev_missing_teams_mask = -1;
236                 return false;
237         }
238         int missing_teams_mask = 0;
239         for (int i = 1; i <= NUM_TEAMS; ++i)
240         {
241                 if ((ca_teams & Team_IndexToBit(i)) &&
242                         (Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(i)) == 0))
243                 {
244                         missing_teams_mask |= Team_IndexToBit(i);
245                 }
246         }
247         if(prev_missing_teams_mask != missing_teams_mask)
248         {
249                 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
250                 prev_missing_teams_mask = missing_teams_mask;
251         }
252         return false;
253 }
254
255 bool ca_isEliminated(entity e)
256 {
257         if(INGAME_JOINED(e) && (IS_DEAD(e) || e.frags == FRAGS_PLAYER_OUT_OF_GAME))
258                 return true;
259         if(INGAME_JOINING(e))
260                 return true;
261         return false;
262 }
263
264 /** Returns next available player to spectate if g_ca_spectate_enemies == 0 */
265 entity CA_SpectateNext(entity player, entity start)
266 {
267         if (SAME_TEAM(start, player)) return start;
268         // continue from current player
269         for (entity e = start; (e = find(e, classname, STR_PLAYER)); )
270         {
271                 if (SAME_TEAM(player, e)) return e;
272         }
273         // restart from the beginning
274         for (entity e = NULL; (e = find(e, classname, STR_PLAYER)); )
275         {
276                 if (SAME_TEAM(player, e)) return e;
277         }
278         return start;
279 }
280
281
282 MUTATOR_HOOKFUNCTION(ca, PlayerSpawn)
283 {
284         entity player = M_ARGV(0, entity);
285
286         INGAME_STATUS_SET(player, INGAME_STATUS_JOINED);
287         if (time <= game_starttime) // reset on game restart, not on round start
288                 player.ca_damage_counter = 0;
289         if (!warmup_stage)
290                 eliminatedPlayers.SendFlags |= 1;
291 }
292
293 MUTATOR_HOOKFUNCTION(ca, ForbidSpawn)
294 {
295         entity player = M_ARGV(0, entity);
296
297         // spectators / observers that weren't playing can join; they are
298         // immediately forced to observe in the PutClientInServer hook
299         // this way they are put in a team and can play in the next round
300         if (!allowed_to_spawn && INGAME(player))
301                 return true;
302         return false;
303 }
304
305 MUTATOR_HOOKFUNCTION(ca, PutClientInServer)
306 {
307         entity player = M_ARGV(0, entity);
308
309         if (!allowed_to_spawn && IS_PLAYER(player)) // this is true even when player is trying to join
310         {
311                 TRANSMUTE(Observer, player);
312                 if (CS(player).jointime != time && !INGAME(player)) // not when connecting
313                 {
314                         INGAME_STATUS_SET(player, INGAME_STATUS_JOINING);
315                         Send_Notification(NOTIF_ONE_ONLY, player, MSG_INFO, INFO_CA_JOIN_LATE);
316                 }
317         }
318
319         if (!warmup_stage)
320                 eliminatedPlayers.SendFlags |= 1;
321 }
322
323 MUTATOR_HOOKFUNCTION(ca, reset_map_players)
324 {
325         g_ca_spectate_enemies = autocvar_g_ca_spectate_enemies;
326         observe_blocked_if_eliminated = (g_ca_spectate_enemies == -1);
327         // we can avoid sending observe_blocked_if_eliminated to all clients here (with ClientData_Touch)
328         // since it will get sent whenever the client spectates someone anyway
329
330         FOREACH_CLIENT(true, {
331                 CS(it).killcount = 0;
332                 if (INGAME(it) || IS_BOT_CLIENT(it))
333                 {
334                         TRANSMUTE(Player, it);
335                         INGAME_STATUS_SET(it, INGAME_STATUS_JOINED);
336                         PutClientInServer(it);
337                 }
338                 it.prev_team = 0;
339         });
340         return true;
341 }
342
343 MUTATOR_HOOKFUNCTION(ca, reset_map_global)
344 {
345         allowed_to_spawn = true;
346         return true;
347 }
348
349 MUTATOR_HOOKFUNCTION(ca, MatchEnd_BeforeScores)
350 {
351         MatchEnd_RestoreSpectatorAndTeamStatus(prev_team);
352         return true;
353 }
354
355 MUTATOR_HOOKFUNCTION(ca, TeamBalance_CheckAllowedTeams, CBC_ORDER_EXCLUSIVE)
356 {
357         M_ARGV(0, float) = ca_teams;
358         return true;
359 }
360
361 entity ca_LastPlayerForTeam(entity this)
362 {
363         entity last_pl = NULL;
364         FOREACH_CLIENT(IS_PLAYER(it) && it != this, {
365                 if (!IS_DEAD(it) && SAME_TEAM(this, it))
366                 {
367                         if (!last_pl)
368                                 last_pl = it;
369                         else
370                                 return NULL;
371                 }
372         });
373         return last_pl;
374 }
375
376 void ca_LastPlayerForTeam_Notify(entity this)
377 {
378         if (!warmup_stage && round_handler_IsActive() && round_handler_IsRoundStarted())
379         {
380                 entity pl = ca_LastPlayerForTeam(this);
381                 if (pl)
382                         Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
383         }
384 }
385
386 MUTATOR_HOOKFUNCTION(ca, PlayerDies)
387 {
388         entity frag_target = M_ARGV(2, entity);
389
390         ca_LastPlayerForTeam_Notify(frag_target);
391         if (!allowed_to_spawn)
392         {
393                 frag_target.respawn_flags = RESPAWN_SILENT;
394                 // prevent unwanted sudden rejoin as spectator and movement of spectator camera
395                 frag_target.respawn_time = time + 2;
396         }
397         frag_target.respawn_flags |= RESPAWN_FORCE;
398         if (!warmup_stage)
399                 eliminatedPlayers.SendFlags |= 1;
400         return true;
401 }
402
403
404 MUTATOR_HOOKFUNCTION(ca, ClientDisconnect)
405 {
406         entity player = M_ARGV(0, entity);
407
408         if (IS_PLAYER(player) && !IS_DEAD(player))
409                 ca_LastPlayerForTeam_Notify(player);
410         return true;
411 }
412
413 MUTATOR_HOOKFUNCTION(ca, MakePlayerObserver)
414 {
415         entity player = M_ARGV(0, entity);
416
417         bool is_forced = M_ARGV(1, bool);
418         if (is_forced && INGAME(player))
419                 INGAME_STATUS_CLEAR(player);
420
421         if (IS_PLAYER(player) && !IS_DEAD(player))
422                 ca_LastPlayerForTeam_Notify(player);
423         if (player.killindicator_teamchange == -2) // player wants to spectate
424         {
425                 entcs_update_players(player);
426                 INGAME_STATUS_CLEAR(player);
427         }
428         if (INGAME(player))
429         {
430                 player.frags = FRAGS_PLAYER_OUT_OF_GAME;
431                 player.would_spectate = observe_blocked_if_eliminated; // if blocked from observing force to spectate now
432         }
433         if (!warmup_stage)
434                 eliminatedPlayers.SendFlags |= 1;
435         if (!INGAME(player))
436                 return false;  // allow team reset
437         return true;  // prevent team reset
438 }
439
440 MUTATOR_HOOKFUNCTION(ca, ForbidThrowCurrentWeapon)
441 {
442         return true;
443 }
444
445 MUTATOR_HOOKFUNCTION(ca, GiveFragsForKill, CBC_ORDER_FIRST)
446 {
447         M_ARGV(2, float) = 0; // score will be given to the winner team when the round ends
448         return true;
449 }
450
451 MUTATOR_HOOKFUNCTION(ca, SetStartItems)
452 {
453         start_items       &= ~(IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS);
454         if(!cvar("g_use_ammunition"))
455                 start_items |= IT_UNLIMITED_AMMO;
456
457         start_health       = warmup_start_health       = autocvar_g_ca_start_health;
458         start_armorvalue   = warmup_start_armorvalue   = autocvar_g_ca_start_armor;
459         start_ammo_shells  = warmup_start_ammo_shells  = autocvar_g_ca_start_ammo_shells;
460         start_ammo_nails   = warmup_start_ammo_nails   = autocvar_g_ca_start_ammo_nails;
461         start_ammo_rockets = warmup_start_ammo_rockets = autocvar_g_ca_start_ammo_rockets;
462         start_ammo_cells   = warmup_start_ammo_cells   = autocvar_g_ca_start_ammo_cells;
463         start_ammo_plasma  = warmup_start_ammo_plasma  = autocvar_g_ca_start_ammo_plasma;
464         start_ammo_fuel    = warmup_start_ammo_fuel    = autocvar_g_ca_start_ammo_fuel;
465 }
466
467 MUTATOR_HOOKFUNCTION(ca, Damage_Calculate)
468 {
469         entity frag_attacker = M_ARGV(1, entity);
470         entity frag_target = M_ARGV(2, entity);
471         float frag_deathtype = M_ARGV(3, float);
472         float frag_damage = M_ARGV(4, float);
473         float frag_mirrordamage = M_ARGV(5, float);
474
475         if (IS_PLAYER(frag_target))
476         if (!IS_DEAD(frag_target))
477         if (frag_target == frag_attacker || SAME_TEAM(frag_target, frag_attacker) || frag_deathtype == DEATH_FALL.m_id)
478                 frag_damage = 0;
479
480         frag_mirrordamage = 0;
481
482         M_ARGV(4, float) = frag_damage;
483         M_ARGV(5, float) = frag_mirrordamage;
484 }
485
486 MUTATOR_HOOKFUNCTION(ca, FilterItem)
487 {
488         entity item = M_ARGV(0, entity);
489
490         if (autocvar_g_powerups <= 0)
491         if (item.itemdef.instanceOfPowerup)
492                 return true;
493
494         if (autocvar_g_pickup_items <= 0)
495                 return true;
496 }
497
498 MUTATOR_HOOKFUNCTION(ca, PlayerDamage_SplitHealthArmor)
499 {
500         if (time < game_starttime || (round_handler_IsActive() && !round_handler_IsRoundStarted()))
501                 return;
502
503         entity frag_attacker = M_ARGV(1, entity);
504         entity frag_target = M_ARGV(2, entity);
505         float frag_deathtype = M_ARGV(6, float);
506         float frag_damage = M_ARGV(7, float);
507         float damage_take = bound(0, M_ARGV(4, float), GetResource(frag_target, RES_HEALTH));
508         float damage_save = bound(0, M_ARGV(5, float), GetResource(frag_target, RES_ARMOR));
509
510         float excess = max(0, frag_damage - damage_take - damage_save);
511
512         if (autocvar_g_ca_damage2score <= 0 || frag_damage - excess == 0) return;
513
514         entity scorer = NULL;
515         float scorer_damage = 0;
516
517         if (IS_PLAYER(frag_attacker))
518         {
519                 if (DIFF_TEAM(frag_target, frag_attacker))
520                         scorer_damage = frag_damage - excess;
521                 else // friendly fire
522                         scorer_damage = -(frag_damage - excess);
523
524                 scorer = frag_attacker;
525         }
526         else
527         {
528                 //handle (environmental hazard) suiciding, check first if player has a registered attacker who most likely pushed them there to avoid punishing pushed players as pushers are already rewarded
529                 //deathtypes:
530                 //kill = suicide, drown = drown in water/liquid, hurttrigger = out of the map void or hurt triggers inside maps like electric sparks
531                 //camp = campcheck, lava = lava, slime = slime
532                 //team change / rebalance suicides are currently not included
533                 if (frag_deathtype == DEATH_KILL.m_id ||
534                         frag_deathtype == DEATH_DROWN.m_id ||
535                         frag_deathtype == DEATH_HURTTRIGGER.m_id ||
536                         frag_deathtype == DEATH_CAMP.m_id ||
537                         frag_deathtype == DEATH_LAVA.m_id ||
538                         frag_deathtype == DEATH_SLIME.m_id ||
539                         frag_deathtype == DEATH_SWAMP.m_id)
540                 {
541                         scorer_damage = -(frag_damage - excess);
542                         scorer = frag_target;
543                 }
544         }
545
546         if (scorer)
547                 GameRules_scoring_add_float2int(scorer, SCORE, scorer_damage, ca_damage_counter, autocvar_g_ca_damage2score);
548 }
549
550 MUTATOR_HOOKFUNCTION(ca, CalculateRespawnTime)
551 {
552         // no respawn calculations needed, player is forced to spectate anyway
553         return true;
554 }
555
556 MUTATOR_HOOKFUNCTION(ca, PlayerRegen)
557 {
558         // no regeneration in CA
559         return true;
560 }
561
562 MUTATOR_HOOKFUNCTION(ca, Scores_CountFragsRemaining)
563 {
564         // announce remaining frags
565         return true;
566 }
567
568 MUTATOR_HOOKFUNCTION(ca, SpectateSet)
569 {
570         entity client = M_ARGV(0, entity);
571         entity targ = M_ARGV(1, entity);
572
573         if (g_ca_spectate_enemies != 1 && INGAME(client))
574         if (DIFF_TEAM(targ, client))
575                 return true;
576 }
577
578 MUTATOR_HOOKFUNCTION(ca, SpectateNext)
579 {
580         entity client = M_ARGV(0, entity);
581
582         if (g_ca_spectate_enemies != 1 && INGAME(client)
583                 && Team_GetNumberOfAlivePlayers(Entity_GetTeam(client)))
584         {
585                 entity targ = M_ARGV(1, entity);
586                 M_ARGV(1, entity) = CA_SpectateNext(client, targ);
587                 return true;
588         }
589 }
590
591 MUTATOR_HOOKFUNCTION(ca, SpectatePrev)
592 {
593         entity client = M_ARGV(0, entity);
594         entity targ = M_ARGV(1, entity);
595         entity first = M_ARGV(2, entity);
596
597         if (g_ca_spectate_enemies != 1 && INGAME(client)
598                 && Team_GetNumberOfAlivePlayers(Entity_GetTeam(client)))
599         {
600                 do { targ = targ.chain; }
601                 while(targ && DIFF_TEAM(targ, client));
602
603                 if (!targ)
604                 {
605                         for (targ = first; targ && DIFF_TEAM(targ, client); targ = targ.chain);
606
607                         if (targ == client.enemy)
608                                 return MUT_SPECPREV_RETURN;
609                 }
610         }
611         else
612                 return MUT_SPECPREV_CONTINUE;
613
614         M_ARGV(1, entity) = targ;
615
616         return MUT_SPECPREV_FOUND;
617 }
618
619 MUTATOR_HOOKFUNCTION(ca, Bot_FixCount, CBC_ORDER_EXCLUSIVE)
620 {
621         FOREACH_CLIENT(IS_REAL_CLIENT(it), {
622                 if (IS_PLAYER(it) || INGAME_JOINED(it))
623                         ++M_ARGV(0, int);
624                 ++M_ARGV(1, int);
625         });
626         return true;
627 }
628
629 MUTATOR_HOOKFUNCTION(ca, ClientCommand_Spectate)
630 {
631         entity player = M_ARGV(0, entity);
632
633         if (INGAME(player))
634         {
635                 // they're going to spec, we can do other checks
636                 if (autocvar_sv_spectate && (IS_SPEC(player) || IS_OBSERVER(player)))
637                         Send_Notification(NOTIF_ONE_ONLY, player, MSG_INFO, INFO_CA_LEAVE);
638                 return MUT_SPECCMD_FORCE;
639         }
640
641         return MUT_SPECCMD_CONTINUE;
642 }
643
644 MUTATOR_HOOKFUNCTION(ca, HideTeamNagger)
645 {
646         return true; // doesn't work well with the whole spectator as player thing
647 }
648
649 MUTATOR_HOOKFUNCTION(ca, SetWeaponArena)
650 {
651         if (M_ARGV(0, string) == "0" || M_ARGV(0, string) == "")
652                 M_ARGV(0, string) = autocvar_g_ca_weaponarena;
653 }
654
655 MUTATOR_HOOKFUNCTION(ca, SV_ParseServerCommand)
656 {
657         string cmd_name = M_ARGV(0, string);
658         if (cmd_name == "shuffleteams")
659                 shuffleteams_on_reset_map = !allowed_to_spawn;
660         return false;
661 }