waeponarena {all,most}_available
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / freezetag / sv_freezetag.qc
1 #include "sv_freezetag.qh"
2
3 #include <server/resources.qh>
4
5 float autocvar_g_freezetag_frozen_maxtime;
6 float autocvar_g_freezetag_revive_clearspeed;
7 float autocvar_g_freezetag_round_timelimit;
8 //int autocvar_g_freezetag_teams;
9 int autocvar_g_freezetag_teams_override;
10 float autocvar_g_freezetag_warmup;
11
12 void freezetag_count_alive_players()
13 {
14         total_players = 0;
15         for (int i = 1; i <= NUM_TEAMS; ++i)
16         {
17                 Team_SetNumberOfAlivePlayers(Team_GetTeamFromIndex(i), 0);
18         }
19         FOREACH_CLIENT(IS_PLAYER(it) && Entity_HasValidTeam(it),
20         {
21                 ++total_players;
22                 if (GetResource(it, RES_HEALTH) < 1 || STAT(FROZEN, it) == FROZEN_NORMAL)
23                 {
24                         continue;
25                 }
26                 entity team_ = Entity_GetTeam(it);
27                 int num_alive = Team_GetNumberOfAlivePlayers(team_);
28                 ++num_alive;
29                 Team_SetNumberOfAlivePlayers(team_, num_alive);
30         });
31         FOREACH_CLIENT(IS_REAL_CLIENT(it),
32         {
33                 STAT(REDALIVE, it) = Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(
34                         1));
35                 STAT(BLUEALIVE, it) = Team_GetNumberOfAlivePlayers(
36                         Team_GetTeamFromIndex(2));
37                 STAT(YELLOWALIVE, it) = Team_GetNumberOfAlivePlayers(
38                         Team_GetTeamFromIndex(3));
39                 STAT(PINKALIVE, it) = Team_GetNumberOfAlivePlayers(
40                         Team_GetTeamFromIndex(4));
41         });
42
43         eliminatedPlayers.SendFlags |= 1;
44 }
45
46 bool freezetag_CheckTeams()
47 {
48         static float prev_missing_teams_mask;
49         if (Team_GetNumberOfAliveTeams() == NumTeams(freezetag_teams))
50         {
51                 if(prev_missing_teams_mask > 0)
52                         Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_TEAMS);
53                 prev_missing_teams_mask = -1;
54                 return true;
55         }
56         if(total_players == 0)
57         {
58                 if(prev_missing_teams_mask > 0)
59                         Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_TEAMS);
60                 prev_missing_teams_mask = -1;
61                 return false;
62         }
63         int missing_teams_mask = 0;
64         for (int i = 1; i <= NUM_TEAMS; ++i)
65         {
66                 if ((freezetag_teams & Team_IndexToBit(i)) &&
67                         (Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(i)) == 0))
68                 {
69                         missing_teams_mask |= Team_IndexToBit(i);
70                 }
71         }
72         if(prev_missing_teams_mask != missing_teams_mask)
73         {
74                 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
75                 prev_missing_teams_mask = missing_teams_mask;
76         }
77         return false;
78 }
79
80 int freezetag_getWinnerTeam()
81 {
82         int winner_team = 0;
83         if (Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(1)) >= 1)
84         {
85                 winner_team = NUM_TEAM_1;
86         }
87         for (int i = 2; i <= NUM_TEAMS; ++i)
88         {
89                 if (Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(i)) >= 1)
90                 {
91                         if (winner_team != 0)
92                         {
93                                 return 0;
94                         }
95                         winner_team = Team_IndexToTeam(i);
96                 }
97         }
98         if (winner_team)
99         {
100                 return winner_team;
101         }
102         return -1; // no player left
103 }
104
105 void nades_Clear(entity);
106 void nades_GiveBonus(entity player, float score);
107
108 bool freezetag_CheckWinner()
109 {
110         if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
111         {
112                 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_OVER);
113                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_OVER);
114                 FOREACH_CLIENT(IS_PLAYER(it), {
115                         it.freezetag_frozen_timeout = 0;
116                         nades_Clear(it);
117                 });
118                 game_stopped = true;
119                 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
120                 return true;
121         }
122
123         if (Team_GetNumberOfAliveTeams() > 1)
124         {
125                 return false;
126         }
127
128         int winner_team = freezetag_getWinnerTeam();
129         if(winner_team > 0)
130         {
131                 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
132                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
133                 TeamScore_AddToTeam(winner_team, ST_SCORE, +1);
134         }
135         else if(winner_team == -1)
136         {
137                 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_TIED);
138                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_TIED);
139         }
140
141         FOREACH_CLIENT(IS_PLAYER(it), {
142                 it.freezetag_frozen_timeout = 0;
143                 nades_Clear(it);
144         });
145
146         game_stopped = true;
147         round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
148         return true;
149 }
150
151 entity freezetag_LastPlayerForTeam(entity this)
152 {
153         entity last_pl = NULL;
154         FOREACH_CLIENT(IS_PLAYER(it) && it != this && SAME_TEAM(it, this), {
155                 if (STAT(FROZEN, it) != FROZEN_NORMAL && GetResource(it, RES_HEALTH) >= 1)
156                 {
157                         if (!last_pl)
158                                 last_pl = it;
159                         else
160                                 return NULL;
161                 }
162         });
163         return last_pl;
164 }
165
166 void freezetag_LastPlayerForTeam_Notify(entity this)
167 {
168         if(round_handler_IsActive())
169         if(round_handler_IsRoundStarted())
170         {
171                 entity pl = freezetag_LastPlayerForTeam(this);
172                 if(pl)
173                         Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
174         }
175 }
176
177 void freezetag_Add_Score(entity targ, entity attacker)
178 {
179         if(attacker == targ)
180         {
181                 // you froze your own dumb targ
182                 // counted as "suicide" already
183                 GameRules_scoring_add(targ, SCORE, -1);
184         }
185         else if(IS_PLAYER(attacker))
186         {
187                 // got frozen by an enemy
188                 // counted as "kill" and "death" already
189                 GameRules_scoring_add(targ, SCORE, -1);
190                 GameRules_scoring_add(attacker, SCORE, +1);
191         }
192         // else nothing - got frozen by the game type rules themselves
193 }
194
195 // to be called when the player is frozen by freezetag (on death, spectator join etc), gives the score
196 void freezetag_Freeze(entity targ, entity attacker)
197 {
198         if(STAT(FROZEN, targ))
199                 return;
200
201         if(autocvar_g_freezetag_frozen_maxtime > 0)
202                 targ.freezetag_frozen_timeout = time + autocvar_g_freezetag_frozen_maxtime;
203
204         Freeze(targ, 0, FROZEN_NORMAL, true);
205
206         freezetag_count_alive_players();
207
208         freezetag_Add_Score(targ, attacker);
209 }
210
211 bool freezetag_isEliminated(entity e)
212 {
213         if(IS_PLAYER(e) && (STAT(FROZEN, e) == FROZEN_NORMAL || IS_DEAD(e)))
214                 return true;
215         return false;
216 }
217
218
219 // ================
220 // Bot player logic
221 // ================
222
223 void(entity this) havocbot_role_ft_freeing;
224 void(entity this) havocbot_role_ft_offense;
225
226 void havocbot_goalrating_ft_freeplayers(entity this, float ratingscale, vector org, float sradius)
227 {
228         entity best_pl = NULL;
229         float best_dist2 = FLOAT_MAX;
230         FOREACH_CLIENT(IS_PLAYER(it) && it != this && SAME_TEAM(it, this), {
231                 if (STAT(FROZEN, it) == FROZEN_NORMAL)
232                 {
233                         if(vdist(it.origin - org, >, sradius))
234                                 continue;
235                         navigation_routerating(this, it, ratingscale, 2000);
236                 }
237                 else if (best_dist2
238                         && GetResource(it, RES_HEALTH) < GetResource(this, RES_HEALTH) + 30
239                         && vlen2(it.origin - org) < best_dist2)
240                 {
241                         // If teamate is not frozen still seek them out as fight better
242                         // in a group.
243                         best_dist2 = vlen2(it.origin - org);
244                         if (best_dist2 < 700 ** 2)
245                         {
246                                 best_pl = NULL;
247                                 best_dist2 = 0; // already close to a teammate
248                         }
249                         else
250                                 best_pl = it;
251                 }
252         });
253         if (best_pl)
254                 navigation_routerating(this, best_pl, ratingscale / 2, 2000);
255 }
256
257 void havocbot_role_ft_offense(entity this)
258 {
259         if(IS_DEAD(this))
260                 return;
261
262         if (!this.havocbot_role_timeout)
263                 this.havocbot_role_timeout = time + random() * 10 + 20;
264
265         // Count how many players on team are unfrozen.
266         int unfrozen = 0;
267         FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, this) && STAT(FROZEN, it) != FROZEN_NORMAL, {
268                 unfrozen++;
269         });
270
271         // If only one left on team or if role has timed out then start trying to free players.
272         if ((!unfrozen && STAT(FROZEN, this) != FROZEN_NORMAL) || time > this.havocbot_role_timeout)
273         {
274                 LOG_TRACE("changing role to freeing");
275                 this.havocbot_role = havocbot_role_ft_freeing;
276                 this.havocbot_role_timeout = 0;
277                 return;
278         }
279
280         if (navigation_goalrating_timeout(this))
281         {
282                 navigation_goalrating_start(this);
283                 havocbot_goalrating_items(this, 12000, this.origin, 10000);
284                 havocbot_goalrating_enemyplayers(this, 10000, this.origin, 10000);
285                 havocbot_goalrating_ft_freeplayers(this, 9000, this.origin, 10000);
286                 havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
287                 navigation_goalrating_end(this);
288
289                 navigation_goalrating_timeout_set(this);
290         }
291 }
292
293 void havocbot_role_ft_freeing(entity this)
294 {
295         if(IS_DEAD(this))
296                 return;
297
298         if (!this.havocbot_role_timeout)
299                 this.havocbot_role_timeout = time + random() * 10 + 20;
300
301         if (time > this.havocbot_role_timeout)
302         {
303                 LOG_TRACE("changing role to offense");
304                 this.havocbot_role = havocbot_role_ft_offense;
305                 this.havocbot_role_timeout = 0;
306                 return;
307         }
308
309         if (navigation_goalrating_timeout(this))
310         {
311                 navigation_goalrating_start(this);
312                 havocbot_goalrating_items(this, 10000, this.origin, 10000);
313                 havocbot_goalrating_enemyplayers(this, 5000, this.origin, 10000);
314                 havocbot_goalrating_ft_freeplayers(this, 20000, this.origin, 10000);
315                 havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
316                 navigation_goalrating_end(this);
317
318                 navigation_goalrating_timeout_set(this);
319         }
320 }
321
322
323 // ==============
324 // Hook Functions
325 // ==============
326
327 void ft_RemovePlayer(entity this)
328 {
329         if (STAT(FROZEN, this) != FROZEN_NORMAL)
330                 freezetag_LastPlayerForTeam_Notify(this);
331         Unfreeze(this, false);
332
333         SetResourceExplicit(this, RES_HEALTH, 0); // neccessary to correctly count alive players
334         freezetag_count_alive_players();
335 }
336
337 MUTATOR_HOOKFUNCTION(ft, ClientDisconnect)
338 {
339         entity player = M_ARGV(0, entity);
340
341         ft_RemovePlayer(player);
342         return true;
343 }
344
345 MUTATOR_HOOKFUNCTION(ft, MakePlayerObserver)
346 {
347         entity player = M_ARGV(0, entity);
348
349         ft_RemovePlayer(player);
350 }
351
352 MUTATOR_HOOKFUNCTION(ft, PlayerDies)
353 {
354         entity frag_attacker = M_ARGV(1, entity);
355         entity frag_target = M_ARGV(2, entity);
356         float frag_deathtype = M_ARGV(3, float);
357
358         if(round_handler_IsActive())
359         if(round_handler_CountdownRunning())
360         {
361                 if (STAT(FROZEN, frag_target) == FROZEN_NORMAL)
362                         Unfreeze(frag_target, true);
363                 freezetag_count_alive_players();
364                 return true; // let the player die so that he can respawn whenever he wants
365         }
366
367         // Cases DEATH_TEAMCHANGE and DEATH_AUTOTEAMCHANGE are needed to fix a bug whe
368         // you succeed changing team through the menu: you both really die (gibbing) and get frozen
369         if(ITEM_DAMAGE_NEEDKILL(frag_deathtype)
370                 || frag_deathtype == DEATH_TEAMCHANGE.m_id || frag_deathtype == DEATH_AUTOTEAMCHANGE.m_id)
371         {
372                 // let the player die, he will be automatically frozen when he respawns
373                 if (STAT(FROZEN, frag_target) != FROZEN_NORMAL)
374                 {
375                         freezetag_Add_Score(frag_target, frag_attacker);
376                         freezetag_count_alive_players();
377                         freezetag_LastPlayerForTeam_Notify(frag_target);
378                 }
379                 else
380                         Unfreeze(frag_target, false); // remove ice
381                 frag_target.freezetag_frozen_timeout = -2; // freeze on respawn
382                 return true;
383         }
384
385         if (STAT(FROZEN, frag_target) == FROZEN_NORMAL)
386                 return true;
387
388         freezetag_Freeze(frag_target, frag_attacker);
389         freezetag_LastPlayerForTeam_Notify(frag_target);
390
391         if(frag_attacker == frag_target || frag_attacker == NULL)
392         {
393                 if(IS_PLAYER(frag_target))
394                         Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_SELF);
395                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_SELF, frag_target.netname);
396         }
397         else
398         {
399                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_FREEZE, frag_target.netname, frag_attacker.netname);
400         }
401
402         return true;
403 }
404
405 MUTATOR_HOOKFUNCTION(ft, PlayerSpawn)
406 {
407         entity player = M_ARGV(0, entity);
408
409         if(player.freezetag_frozen_timeout == -1) // if PlayerSpawn is called by reset_map_players
410                 return true; // do nothing, round is starting right now
411
412         if(player.freezetag_frozen_timeout == -2) // player was dead
413         {
414                 freezetag_Freeze(player, NULL);
415                 return true;
416         }
417
418         freezetag_count_alive_players();
419
420         if(round_handler_IsActive())
421         if(round_handler_IsRoundStarted())
422         {
423                 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
424                 freezetag_Freeze(player, NULL);
425         }
426
427         return true;
428 }
429
430 MUTATOR_HOOKFUNCTION(ft, reset_map_players)
431 {
432         FOREACH_CLIENT(IS_PLAYER(it), {
433                 CS(it).killcount = 0;
434                 it.freezetag_frozen_timeout = -1;
435                 PutClientInServer(it);
436                 it.freezetag_frozen_timeout = 0;
437         });
438         freezetag_count_alive_players();
439         return true;
440 }
441
442 MUTATOR_HOOKFUNCTION(ft, GiveFragsForKill, CBC_ORDER_FIRST)
443 {
444         M_ARGV(2, float) = 0; // no frags counted in Freeze Tag
445         return true;
446 }
447
448 MUTATOR_HOOKFUNCTION(ft, Unfreeze)
449 {
450         entity targ = M_ARGV(0, entity);
451         targ.freezetag_frozen_time = 0;
452         targ.freezetag_frozen_timeout = 0;
453 }
454
455 #ifdef IS_REVIVING
456         #undef IS_REVIVING
457 #endif
458
459 // returns true if player is reviving it
460 #define IS_REVIVING(player, it, revive_extra_size) \
461         (it != player && !STAT(FROZEN, it) && !IS_DEAD(it) && SAME_TEAM(it, player) \
462         && boxesoverlap(player.absmin - revive_extra_size, player.absmax + revive_extra_size, it.absmin, it.absmax))
463
464 MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST)
465 {
466         if(game_stopped)
467                 return true;
468
469         if(round_handler_IsActive())
470         if(!round_handler_IsRoundStarted())
471                 return true;
472
473         int n;
474         entity player = M_ARGV(0, entity);
475         //if (STAT(FROZEN, player) == FROZEN_NORMAL)
476         //if(player.freezetag_frozen_timeout > 0 && time < player.freezetag_frozen_timeout)
477                 //player.iceblock.alpha = ICE_MIN_ALPHA + (ICE_MAX_ALPHA - ICE_MIN_ALPHA) * (player.freezetag_frozen_timeout - time) / (player.freezetag_frozen_timeout - player.freezetag_frozen_time);
478
479         entity reviving_players_last = NULL;
480         entity reviving_players_first = NULL;
481
482         if(player.freezetag_frozen_timeout > 0 && time >= player.freezetag_frozen_timeout)
483                 n = -1;
484         else
485         {
486                 n = 0;
487                 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
488                 FOREACH_CLIENT(IS_PLAYER(it) && IS_REVIVING(player, it, revive_extra_size), {
489                         if (reviving_players_last)
490                                 reviving_players_last.chain = it;
491                         reviving_players_last = it;
492                         if (!reviving_players_first)
493                                 reviving_players_first = it;
494                         ++n;
495                 });
496                 if (reviving_players_last)
497                         reviving_players_last.chain = NULL;
498         }
499
500         if (!n) // no teammate nearby
501         {
502                 if (STAT(FROZEN, player) == FROZEN_NORMAL)
503                 {
504                         STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
505                         SetResourceExplicit(player, RES_HEALTH, max(1, STAT(REVIVE_PROGRESS, player) * ((warmup_stage) ? warmup_start_health : start_health)));
506                 }
507                 else if (!STAT(FROZEN, player))
508                         STAT(REVIVE_PROGRESS, player) = 0; // thawing nobody
509         }
510         else if (STAT(FROZEN, player) == FROZEN_NORMAL) // OK, there is at least one teammate reviving us
511         {
512                 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
513                 SetResourceExplicit(player, RES_HEALTH, max(1, STAT(REVIVE_PROGRESS, player) * ((warmup_stage) ? warmup_start_health : start_health)));
514
515                 if(STAT(REVIVE_PROGRESS, player) >= 1)
516                 {
517                         Unfreeze(player, false);
518                         freezetag_count_alive_players();
519
520                         if(n == -1)
521                         {
522                                 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_AUTO_REVIVED, autocvar_g_freezetag_frozen_maxtime);
523                                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_AUTO_REVIVED, player.netname, autocvar_g_freezetag_frozen_maxtime);
524                                 return true;
525                         }
526
527                         // EVERY team mate nearby gets a point (even if multiple!)
528                         for(entity it = reviving_players_first; it; it = it.chain)
529                         {
530                                 GameRules_scoring_add(it, FREEZETAG_REVIVALS, +1);
531                                 GameRules_scoring_add(it, SCORE, +1);
532                                 nades_GiveBonus(it, autocvar_g_nades_bonus_score_low);
533                         }
534
535                         entity first = reviving_players_first;
536                         Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_REVIVED, first.netname);
537                         Send_Notification(NOTIF_ONE, first, MSG_CENTER, CENTER_FREEZETAG_REVIVE, player.netname);
538                         Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_REVIVED, player.netname, first.netname);
539                 }
540
541                 for(entity it = reviving_players_first; it; it = it.chain)
542                         STAT(REVIVE_PROGRESS, it) = STAT(REVIVE_PROGRESS, player);
543         }
544
545         return true;
546 }
547
548 MUTATOR_HOOKFUNCTION(ft, SetStartItems)
549 {
550         start_items &= ~IT_UNLIMITED_AMMO;
551         //start_health       = warmup_start_health       = cvar("g_lms_start_health");
552         //start_armorvalue   = warmup_start_armorvalue   = cvar("g_lms_start_armor");
553         start_ammo_shells  = warmup_start_ammo_shells  = cvar("g_lms_start_ammo_shells");
554         start_ammo_nails   = warmup_start_ammo_nails   = cvar("g_lms_start_ammo_nails");
555         start_ammo_rockets = warmup_start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
556         start_ammo_cells   = warmup_start_ammo_cells   = cvar("g_lms_start_ammo_cells");
557         start_ammo_plasma  = warmup_start_ammo_plasma  = cvar("g_lms_start_ammo_plasma");
558         start_ammo_fuel    = warmup_start_ammo_fuel    = cvar("g_lms_start_ammo_fuel");
559 }
560
561 MUTATOR_HOOKFUNCTION(ft, HavocBot_ChooseRole)
562 {
563         entity bot = M_ARGV(0, entity);
564
565         if (!IS_DEAD(bot))
566         {
567                 if (random() < 0.5)
568                         bot.havocbot_role = havocbot_role_ft_freeing;
569                 else
570                         bot.havocbot_role = havocbot_role_ft_offense;
571         }
572
573         // if bots spawn all at once assign them a more appropriated role after a while
574         if (time < CS(bot).jointime + 1)
575                 bot.havocbot_role_timeout = time + 10 + random() * 10;
576
577         return true;
578 }
579
580 MUTATOR_HOOKFUNCTION(ft, TeamBalance_CheckAllowedTeams, CBC_ORDER_EXCLUSIVE)
581 {
582         M_ARGV(0, float) = freezetag_teams;
583         return true;
584 }
585
586 MUTATOR_HOOKFUNCTION(ft, SetWeaponArena)
587 {
588         // most weapons arena
589         if(M_ARGV(0, string) == "0" || M_ARGV(0, string) == "")
590                 M_ARGV(0, string) = autocvar_g_freezetag_weaponarena;
591 }
592
593 MUTATOR_HOOKFUNCTION(ft, FragCenterMessage)
594 {
595         entity frag_attacker = M_ARGV(0, entity);
596         entity frag_target = M_ARGV(1, entity);
597         //float frag_deathtype = M_ARGV(2, float);
598         int kill_count_to_attacker = M_ARGV(3, int);
599         int kill_count_to_target = M_ARGV(4, int);
600
601         if(STAT(FROZEN, frag_target) == FROZEN_NORMAL)
602                 return; // target was already frozen, so this is just pushing them off the cliff
603
604         Send_Notification(NOTIF_ONE, frag_attacker, MSG_CHOICE, CHOICE_FRAG_FREEZE, frag_target.netname, kill_count_to_attacker, (IS_BOT_CLIENT(frag_target) ? -1 : CS(frag_target).ping));
605         Send_Notification(NOTIF_ONE, frag_target, MSG_CHOICE, CHOICE_FRAGGED_FREEZE, frag_attacker.netname, kill_count_to_target,
606                 GetResource(frag_attacker, RES_HEALTH), GetResource(frag_attacker, RES_ARMOR), (IS_BOT_CLIENT(frag_attacker) ? -1 : CS(frag_attacker).ping));
607
608         return true;
609 }
610
611 void freezetag_Initialize()
612 {
613         freezetag_teams = autocvar_g_freezetag_teams_override;
614         if(freezetag_teams < 2)
615                 freezetag_teams = cvar("g_freezetag_teams"); // read the cvar directly as it gets written earlier in the same frame
616
617         freezetag_teams = BITS(bound(2, freezetag_teams, 4));
618         GameRules_scoring(freezetag_teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, {
619                 field(SP_FREEZETAG_REVIVALS, "revivals", 0);
620         });
621
622         round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null);
623         round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
624
625         EliminatedPlayers_Init(freezetag_isEliminated);
626 }