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