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