]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/gamemodes/gamemode/freezetag/sv_freezetag.qc
Fix #2079: "Progress indicator sometimes missing when reviving teammates in FT"
[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 || 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 #define FREEZETAG_ALIVE_TEAMS_OK() (Team_GetNumberOfAliveTeams() == NumTeams(freezetag_teams))
47
48 bool freezetag_CheckTeams()
49 {
50         static float prev_missing_teams_mask;
51         if(FREEZETAG_ALIVE_TEAMS_OK())
52         {
53                 if(prev_missing_teams_mask > 0)
54                         Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_TEAMS);
55                 prev_missing_teams_mask = -1;
56                 return true;
57         }
58         if(total_players == 0)
59         {
60                 if(prev_missing_teams_mask > 0)
61                         Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_TEAMS);
62                 prev_missing_teams_mask = -1;
63                 return false;
64         }
65         int missing_teams_mask = 0;
66         for (int i = 1; i <= NUM_TEAMS; ++i)
67         {
68                 if ((freezetag_teams & Team_IndexToBit(i)) &&
69                         (Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(i)) == 0))
70                 {
71                         missing_teams_mask |= Team_IndexToBit(i);
72                 }
73         }
74         if(prev_missing_teams_mask != missing_teams_mask)
75         {
76                 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
77                 prev_missing_teams_mask = missing_teams_mask;
78         }
79         return false;
80 }
81
82 int freezetag_getWinnerTeam()
83 {
84         int winner_team = 0;
85         if (Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(1)) >= 1)
86         {
87                 winner_team = NUM_TEAM_1;
88         }
89         for (int i = 2; i <= NUM_TEAMS; ++i)
90         {
91                 if (Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(i)) >= 1)
92                 {
93                         if (winner_team != 0)
94                         {
95                                 return 0;
96                         }
97                         winner_team = Team_IndexToTeam(i);
98                 }
99         }
100         if (winner_team)
101         {
102                 return winner_team;
103         }
104         return -1; // no player left
105 }
106
107 void nades_Clear(entity);
108 void nades_GiveBonus(entity player, float score);
109
110 bool freezetag_CheckWinner()
111 {
112         if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
113         {
114                 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_OVER);
115                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_OVER);
116                 FOREACH_CLIENT(IS_PLAYER(it), {
117                         it.freezetag_frozen_timeout = 0;
118                         nades_Clear(it);
119                 });
120                 game_stopped = true;
121                 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
122                 return true;
123         }
124
125         if (Team_GetNumberOfAliveTeams() > 1)
126         {
127                 return false;
128         }
129
130         int winner_team = freezetag_getWinnerTeam();
131         if(winner_team > 0)
132         {
133                 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
134                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
135                 TeamScore_AddToTeam(winner_team, ST_SCORE, +1);
136         }
137         else if(winner_team == -1)
138         {
139                 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_TIED);
140                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_TIED);
141         }
142
143         FOREACH_CLIENT(IS_PLAYER(it), {
144                 it.freezetag_frozen_timeout = 0;
145                 nades_Clear(it);
146         });
147
148         game_stopped = true;
149         round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
150         return true;
151 }
152
153 entity freezetag_LastPlayerForTeam(entity this)
154 {
155         entity last_pl = NULL;
156         FOREACH_CLIENT(IS_PLAYER(it) && it != this && SAME_TEAM(it, this), {
157                 if (STAT(FROZEN, it) != FROZEN_NORMAL && GetResourceAmount(it, RESOURCE_HEALTH) >= 1)
158                 {
159                         if (!last_pl)
160                                 last_pl = it;
161                         else
162                                 return NULL;
163                 }
164         });
165         return last_pl;
166 }
167
168 void freezetag_LastPlayerForTeam_Notify(entity this)
169 {
170         if(round_handler_IsActive())
171         if(round_handler_IsRoundStarted())
172         {
173                 entity pl = freezetag_LastPlayerForTeam(this);
174                 if(pl)
175                         Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
176         }
177 }
178
179 void freezetag_Add_Score(entity targ, entity attacker)
180 {
181         if(attacker == targ)
182         {
183                 // you froze your own dumb targ
184                 // counted as "suicide" already
185                 GameRules_scoring_add(targ, SCORE, -1);
186         }
187         else if(IS_PLAYER(attacker))
188         {
189                 // got frozen by an enemy
190                 // counted as "kill" and "death" already
191                 GameRules_scoring_add(targ, SCORE, -1);
192                 GameRules_scoring_add(attacker, SCORE, +1);
193         }
194         // else nothing - got frozen by the game type rules themselves
195 }
196
197 // to be called when the player is frozen by freezetag (on death, spectator join etc), gives the score
198 void freezetag_Freeze(entity targ, entity attacker)
199 {
200         if(STAT(FROZEN, targ))
201                 return;
202
203         if(autocvar_g_freezetag_frozen_maxtime > 0)
204                 targ.freezetag_frozen_timeout = time + autocvar_g_freezetag_frozen_maxtime;
205
206         Freeze(targ, 0, 1, true);
207
208         freezetag_count_alive_players();
209
210         freezetag_Add_Score(targ, attacker);
211 }
212
213 bool freezetag_isEliminated(entity e)
214 {
215         if(IS_PLAYER(e) && (STAT(FROZEN, e) == FROZEN_NORMAL || IS_DEAD(e)))
216                 return true;
217         return false;
218 }
219
220
221 // ================
222 // Bot player logic
223 // ================
224
225 void(entity this) havocbot_role_ft_freeing;
226 void(entity this) havocbot_role_ft_offense;
227
228 void havocbot_goalrating_ft_freeplayers(entity this, float ratingscale, vector org, float sradius)
229 {
230         entity best_pl = NULL;
231         float best_dist2 = FLOAT_MAX;
232         FOREACH_CLIENT(IS_PLAYER(it) && it != this && SAME_TEAM(it, this), {
233                 if (STAT(FROZEN, it) == FROZEN_NORMAL)
234                 {
235                         if(vdist(it.origin - org, >, sradius))
236                                 continue;
237                         navigation_routerating(this, it, ratingscale, 2000);
238                 }
239                 else if (best_dist2
240                         && GetResourceAmount(it, RESOURCE_HEALTH) < GetResourceAmount(this, RESOURCE_HEALTH) + 30
241                         && vlen2(it.origin - org) < best_dist2)
242                 {
243                         // If teamate is not frozen still seek them out as fight better
244                         // in a group.
245                         best_dist2 = vlen2(it.origin - org);
246                         if (best_dist2 < 700 ** 2)
247                         {
248                                 best_pl = NULL;
249                                 best_dist2 = 0; // already close to a teammate
250                         }
251                         else
252                                 best_pl = it;
253                 }
254         });
255         if (best_pl)
256                 navigation_routerating(this, best_pl, ratingscale / 2, 2000);
257 }
258
259 void havocbot_role_ft_offense(entity this)
260 {
261         if(IS_DEAD(this))
262                 return;
263
264         if (!this.havocbot_role_timeout)
265                 this.havocbot_role_timeout = time + random() * 10 + 20;
266
267         // Count how many players on team are unfrozen.
268         int unfrozen = 0;
269         FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, this) && STAT(FROZEN, it) != FROZEN_NORMAL, {
270                 unfrozen++;
271         });
272
273         // If only one left on team or if role has timed out then start trying to free players.
274         if ((!unfrozen && STAT(FROZEN, this) != FROZEN_NORMAL) || time > this.havocbot_role_timeout)
275         {
276                 LOG_TRACE("changing role to freeing");
277                 this.havocbot_role = havocbot_role_ft_freeing;
278                 this.havocbot_role_timeout = 0;
279                 return;
280         }
281
282         if (navigation_goalrating_timeout(this))
283         {
284                 navigation_goalrating_start(this);
285                 havocbot_goalrating_items(this, 12000, this.origin, 10000);
286                 havocbot_goalrating_enemyplayers(this, 10000, this.origin, 10000);
287                 havocbot_goalrating_ft_freeplayers(this, 9000, this.origin, 10000);
288                 havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
289                 navigation_goalrating_end(this);
290
291                 navigation_goalrating_timeout_set(this);
292         }
293 }
294
295 void havocbot_role_ft_freeing(entity this)
296 {
297         if(IS_DEAD(this))
298                 return;
299
300         if (!this.havocbot_role_timeout)
301                 this.havocbot_role_timeout = time + random() * 10 + 20;
302
303         if (time > this.havocbot_role_timeout)
304         {
305                 LOG_TRACE("changing role to offense");
306                 this.havocbot_role = havocbot_role_ft_offense;
307                 this.havocbot_role_timeout = 0;
308                 return;
309         }
310
311         if (navigation_goalrating_timeout(this))
312         {
313                 navigation_goalrating_start(this);
314                 havocbot_goalrating_items(this, 10000, this.origin, 10000);
315                 havocbot_goalrating_enemyplayers(this, 5000, this.origin, 10000);
316                 havocbot_goalrating_ft_freeplayers(this, 20000, this.origin, 10000);
317                 havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
318                 navigation_goalrating_end(this);
319
320                 navigation_goalrating_timeout_set(this);
321         }
322 }
323
324
325 // ==============
326 // Hook Functions
327 // ==============
328
329 void ft_RemovePlayer(entity this)
330 {
331         if (STAT(FROZEN, this) != FROZEN_NORMAL)
332                 freezetag_LastPlayerForTeam_Notify(this);
333         Unfreeze(this, false);
334
335         SetResourceAmountExplicit(this, RESOURCE_HEALTH, 0); // neccessary to correctly count alive players
336         freezetag_count_alive_players();
337 }
338
339 MUTATOR_HOOKFUNCTION(ft, ClientDisconnect)
340 {
341         entity player = M_ARGV(0, entity);
342
343         ft_RemovePlayer(player);
344         return true;
345 }
346
347 MUTATOR_HOOKFUNCTION(ft, MakePlayerObserver)
348 {
349         entity player = M_ARGV(0, entity);
350
351         ft_RemovePlayer(player);
352 }
353
354 MUTATOR_HOOKFUNCTION(ft, PlayerDies)
355 {
356         entity frag_attacker = M_ARGV(1, entity);
357         entity frag_target = M_ARGV(2, entity);
358         float frag_deathtype = M_ARGV(3, float);
359
360         if(round_handler_IsActive())
361         if(round_handler_CountdownRunning())
362         {
363                 if (STAT(FROZEN, frag_target) == FROZEN_NORMAL)
364                         Unfreeze(frag_target, true);
365                 freezetag_count_alive_players();
366                 return true; // let the player die so that he can respawn whenever he wants
367         }
368
369         // Cases DEATH_TEAMCHANGE and DEATH_AUTOTEAMCHANGE are needed to fix a bug whe
370         // you succeed changing team through the menu: you both really die (gibbing) and get frozen
371         if(ITEM_DAMAGE_NEEDKILL(frag_deathtype)
372                 || frag_deathtype == DEATH_TEAMCHANGE.m_id || frag_deathtype == DEATH_AUTOTEAMCHANGE.m_id)
373         {
374                 // let the player die, he will be automatically frozen when he respawns
375                 if (STAT(FROZEN, frag_target) != FROZEN_NORMAL)
376                 {
377                         freezetag_Add_Score(frag_target, frag_attacker);
378                         freezetag_count_alive_players();
379                         freezetag_LastPlayerForTeam_Notify(frag_target);
380                 }
381                 else
382                         Unfreeze(frag_target, false); // remove ice
383                 frag_target.freezetag_frozen_timeout = -2; // freeze on respawn
384                 return true;
385         }
386
387         if (STAT(FROZEN, frag_target) == FROZEN_NORMAL)
388                 return true;
389
390         freezetag_Freeze(frag_target, frag_attacker);
391         freezetag_LastPlayerForTeam_Notify(frag_target);
392
393         if(frag_attacker == frag_target || frag_attacker == NULL)
394         {
395                 if(IS_PLAYER(frag_target))
396                         Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_SELF);
397                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_SELF, frag_target.netname);
398         }
399         else
400         {
401                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_FREEZE, frag_target.netname, frag_attacker.netname);
402         }
403
404         return true;
405 }
406
407 MUTATOR_HOOKFUNCTION(ft, PlayerSpawn)
408 {
409         entity player = M_ARGV(0, entity);
410
411         if(player.freezetag_frozen_timeout == -1) // if PlayerSpawn is called by reset_map_players
412                 return true; // do nothing, round is starting right now
413
414         if(player.freezetag_frozen_timeout == -2) // player was dead
415         {
416                 freezetag_Freeze(player, NULL);
417                 return true;
418         }
419
420         freezetag_count_alive_players();
421
422         if(round_handler_IsActive())
423         if(round_handler_IsRoundStarted())
424         {
425                 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
426                 freezetag_Freeze(player, NULL);
427         }
428
429         return true;
430 }
431
432 MUTATOR_HOOKFUNCTION(ft, reset_map_players)
433 {
434         FOREACH_CLIENT(IS_PLAYER(it), {
435                 CS(it).killcount = 0;
436                 it.freezetag_frozen_timeout = -1;
437                 PutClientInServer(it);
438                 it.freezetag_frozen_timeout = 0;
439         });
440         freezetag_count_alive_players();
441         return true;
442 }
443
444 MUTATOR_HOOKFUNCTION(ft, GiveFragsForKill, CBC_ORDER_FIRST)
445 {
446         M_ARGV(2, float) = 0; // no frags counted in Freeze Tag
447         return true;
448 }
449
450 MUTATOR_HOOKFUNCTION(ft, Unfreeze)
451 {
452         entity targ = M_ARGV(0, entity);
453         targ.freezetag_frozen_time = 0;
454         targ.freezetag_frozen_timeout = 0;
455 }
456
457 #ifdef IS_REVIVING
458         #undef IS_REVIVING
459 #endif
460
461 // returns true if player is reviving it
462 #define IS_REVIVING(player, it, revive_extra_size) \
463         (it != player && !STAT(FROZEN, it) && !IS_DEAD(it) && SAME_TEAM(it, player) \
464         && boxesoverlap(player.absmin - revive_extra_size, player.absmax + revive_extra_size, it.absmin, it.absmax))
465
466 MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST)
467 {
468         if(game_stopped)
469                 return true;
470
471         if(round_handler_IsActive())
472         if(!round_handler_IsRoundStarted())
473                 return true;
474
475         int n;
476         entity o = NULL;
477         vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
478         entity player = M_ARGV(0, entity);
479         //if (STAT(FROZEN, player) == FROZEN_NORMAL)
480         //if(player.freezetag_frozen_timeout > 0 && time < player.freezetag_frozen_timeout)
481                 //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);
482
483         if(player.freezetag_frozen_timeout > 0 && time >= player.freezetag_frozen_timeout)
484                 n = -1;
485         else
486         {
487                 n = 0;
488                 FOREACH_CLIENT(IS_PLAYER(it) && IS_REVIVING(player, it, revive_extra_size), {
489                         if(!o)
490                                 o = it;
491                         ++n;
492                 });
493         }
494
495         if (n && STAT(FROZEN, player) == FROZEN_NORMAL) // OK, there is at least one teammate reviving us
496         {
497                 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
498                 SetResourceAmountExplicit(player, RESOURCE_HEALTH, max(1, STAT(REVIVE_PROGRESS, player) * ((warmup_stage) ? warmup_start_health : start_health)));
499
500                 if(STAT(REVIVE_PROGRESS, player) >= 1)
501                 {
502                         Unfreeze(player, false);
503                         freezetag_count_alive_players();
504
505                         if(n == -1)
506                         {
507                                 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_AUTO_REVIVED, autocvar_g_freezetag_frozen_maxtime);
508                                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_AUTO_REVIVED, player.netname, autocvar_g_freezetag_frozen_maxtime);
509                                 return true;
510                         }
511
512                         // EVERY team mate nearby gets a point (even if multiple!)
513                         FOREACH_CLIENT(IS_PLAYER(it) && IS_REVIVING(player, it, revive_extra_size), {
514                                 GameRules_scoring_add(it, FREEZETAG_REVIVALS, +1);
515                                 GameRules_scoring_add(it, SCORE, +1);
516                                 nades_GiveBonus(it, autocvar_g_nades_bonus_score_low);
517                         });
518
519                         Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
520                         Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, player.netname);
521                         Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_REVIVED, player.netname, o.netname);
522                 }
523
524                 FOREACH_CLIENT(IS_PLAYER(it) && IS_REVIVING(player, it, revive_extra_size), {
525                         STAT(REVIVE_PROGRESS, it) = STAT(REVIVE_PROGRESS, player);
526                 });
527         }
528         else if (!n && STAT(FROZEN, player) == FROZEN_NORMAL) // 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) == FROZEN_NORMAL)
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 }