]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/gamemodes/gamemode/freezetag/sv_freezetag.qc
Resolve "CA uses LMS start values" and same for FT
[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                         it.freezetag_revive_time = 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_FT_ROUNDS, +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                 it.freezetag_revive_time = 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) != FROZEN_NORMAL && GetResource(it, RES_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 self
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         targ.freezetag_frozen_time = time;
205         if (autocvar_g_freezetag_revive_auto && autocvar_g_freezetag_frozen_maxtime > 0)
206                 targ.freezetag_frozen_timeout = time + autocvar_g_freezetag_frozen_maxtime;
207
208         Freeze(targ, 0, FROZEN_NORMAL, true);
209
210         freezetag_count_alive_players();
211
212         freezetag_Add_Score(targ, attacker);
213 }
214
215 bool freezetag_isEliminated(entity e)
216 {
217         if(IS_PLAYER(e) && (STAT(FROZEN, e) == FROZEN_NORMAL || IS_DEAD(e)))
218                 return true;
219         return false;
220 }
221
222
223 // ================
224 // Bot player logic
225 // ================
226
227 void(entity this) havocbot_role_ft_freeing;
228 void(entity this) havocbot_role_ft_offense;
229
230 void havocbot_goalrating_ft_freeplayers(entity this, float ratingscale, vector org, float sradius)
231 {
232         entity best_pl = NULL;
233         float best_dist2 = FLOAT_MAX;
234         FOREACH_CLIENT(IS_PLAYER(it) && it != this && SAME_TEAM(it, this), {
235                 if (STAT(FROZEN, it) == FROZEN_NORMAL)
236                 {
237                         if(vdist(it.origin - org, >, sradius))
238                                 continue;
239                         navigation_routerating(this, it, ratingscale, 2000);
240                 }
241                 else if (best_dist2
242                         && GetResource(it, RES_HEALTH) < GetResource(this, RES_HEALTH) + 30
243                         && vlen2(it.origin - org) < best_dist2)
244                 {
245                         // If teamate is not frozen still seek them out as fight better
246                         // in a group.
247                         best_dist2 = vlen2(it.origin - org);
248                         if (best_dist2 < 700 ** 2)
249                         {
250                                 best_pl = NULL;
251                                 best_dist2 = 0; // already close to a teammate
252                         }
253                         else
254                                 best_pl = it;
255                 }
256         });
257         if (best_pl)
258                 navigation_routerating(this, best_pl, ratingscale / 2, 2000);
259 }
260
261 void havocbot_role_ft_offense(entity this)
262 {
263         if(IS_DEAD(this))
264                 return;
265
266         if (!this.havocbot_role_timeout)
267                 this.havocbot_role_timeout = time + random() * 10 + 20;
268
269         // Count how many players on team are unfrozen.
270         int unfrozen = 0;
271         FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, this) && STAT(FROZEN, it) != FROZEN_NORMAL, {
272                 unfrozen++;
273         });
274
275         // If only one left on team or if role has timed out then start trying to free players.
276         if ((!unfrozen && STAT(FROZEN, this) != FROZEN_NORMAL) || time > this.havocbot_role_timeout)
277         {
278                 LOG_TRACE("changing role to freeing");
279                 this.havocbot_role = havocbot_role_ft_freeing;
280                 this.havocbot_role_timeout = 0;
281                 return;
282         }
283
284         if (navigation_goalrating_timeout(this))
285         {
286                 navigation_goalrating_start(this);
287                 havocbot_goalrating_items(this, 12000, this.origin, 10000);
288                 havocbot_goalrating_enemyplayers(this, 10000, this.origin, 10000);
289                 havocbot_goalrating_ft_freeplayers(this, 9000, this.origin, 10000);
290                 havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
291                 navigation_goalrating_end(this);
292
293                 navigation_goalrating_timeout_set(this);
294         }
295 }
296
297 void havocbot_role_ft_freeing(entity this)
298 {
299         if(IS_DEAD(this))
300                 return;
301
302         if (!this.havocbot_role_timeout)
303                 this.havocbot_role_timeout = time + random() * 10 + 20;
304
305         if (time > this.havocbot_role_timeout)
306         {
307                 LOG_TRACE("changing role to offense");
308                 this.havocbot_role = havocbot_role_ft_offense;
309                 this.havocbot_role_timeout = 0;
310                 return;
311         }
312
313         if (navigation_goalrating_timeout(this))
314         {
315                 navigation_goalrating_start(this);
316                 havocbot_goalrating_items(this, 10000, this.origin, 10000);
317                 havocbot_goalrating_enemyplayers(this, 5000, this.origin, 10000);
318                 havocbot_goalrating_ft_freeplayers(this, 20000, this.origin, 10000);
319                 havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
320                 navigation_goalrating_end(this);
321
322                 navigation_goalrating_timeout_set(this);
323         }
324 }
325
326
327 // ==============
328 // Hook Functions
329 // ==============
330
331 void ft_RemovePlayer(entity this)
332 {
333         if (STAT(FROZEN, this) != FROZEN_NORMAL)
334                 freezetag_LastPlayerForTeam_Notify(this);
335         Unfreeze(this, false);
336
337         SetResourceExplicit(this, RES_HEALTH, 0); // neccessary to correctly count alive players
338         freezetag_count_alive_players();
339 }
340
341 MUTATOR_HOOKFUNCTION(ft, ClientDisconnect)
342 {
343         entity player = M_ARGV(0, entity);
344
345         ft_RemovePlayer(player);
346         return true;
347 }
348
349 MUTATOR_HOOKFUNCTION(ft, MakePlayerObserver)
350 {
351         entity player = M_ARGV(0, entity);
352
353         ft_RemovePlayer(player);
354 }
355
356 MUTATOR_HOOKFUNCTION(ft, PlayerDies)
357 {
358         entity frag_attacker = M_ARGV(1, entity);
359         entity frag_target = M_ARGV(2, entity);
360         float frag_deathtype = M_ARGV(3, float);
361
362         if(round_handler_IsActive())
363         if(round_handler_CountdownRunning())
364         {
365                 if (STAT(FROZEN, frag_target) == FROZEN_NORMAL)
366                         Unfreeze(frag_target, true);
367                 freezetag_count_alive_players();
368                 frag_target.respawn_time = time;
369                 frag_target.respawn_flags |= RESPAWN_FORCE;
370                 return true;
371         }
372
373         frag_target.respawn_time = time + 1;
374         frag_target.respawn_flags |= RESPAWN_FORCE;
375
376         // Cases DEATH_TEAMCHANGE and DEATH_AUTOTEAMCHANGE are needed to fix a bug whe
377         // you succeed changing team through the menu: you both really die (gibbing) and get frozen
378         if(ITEM_DAMAGE_NEEDKILL(frag_deathtype)
379                 || frag_deathtype == DEATH_TEAMCHANGE.m_id || frag_deathtype == DEATH_AUTOTEAMCHANGE.m_id)
380         {
381                 // let the player die, he will be automatically frozen when he respawns
382                 if (STAT(FROZEN, frag_target) != FROZEN_NORMAL)
383                 {
384                         freezetag_Add_Score(frag_target, frag_attacker);
385                         freezetag_count_alive_players();
386                         freezetag_LastPlayerForTeam_Notify(frag_target);
387                 }
388                 else
389                         Unfreeze(frag_target, false); // remove ice
390                 frag_target.freezetag_frozen_timeout = -2; // freeze on respawn
391                 return true;
392         }
393
394         if (STAT(FROZEN, frag_target) == FROZEN_NORMAL)
395                 return true;
396
397         freezetag_Freeze(frag_target, frag_attacker);
398         freezetag_LastPlayerForTeam_Notify(frag_target);
399
400         if(frag_attacker == frag_target || frag_attacker == NULL)
401         {
402                 if(IS_PLAYER(frag_target))
403                         Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_SELF);
404                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_SELF, frag_target.netname);
405         }
406         else
407         {
408                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_FREEZE, frag_target.netname, frag_attacker.netname);
409         }
410
411         return true;
412 }
413
414 MUTATOR_HOOKFUNCTION(ft, PlayerSpawn)
415 {
416         entity player = M_ARGV(0, entity);
417
418         if(player.freezetag_frozen_timeout == -1) // if PlayerSpawn is called by reset_map_players
419                 return true; // do nothing, round is starting right now
420
421         if(player.freezetag_frozen_timeout == -2) // player was dead
422         {
423                 freezetag_Freeze(player, NULL);
424                 return true;
425         }
426
427         freezetag_count_alive_players();
428
429         if(round_handler_IsActive())
430         if(round_handler_IsRoundStarted())
431         {
432                 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
433                 freezetag_Freeze(player, NULL);
434         }
435
436         return true;
437 }
438
439 MUTATOR_HOOKFUNCTION(ft, reset_map_players)
440 {
441         FOREACH_CLIENT(IS_PLAYER(it), {
442                 CS(it).killcount = 0;
443                 it.freezetag_revive_time = 0;
444                 it.freezetag_frozen_timeout = -1;
445                 PutClientInServer(it);
446                 it.freezetag_frozen_timeout = 0;
447         });
448         freezetag_count_alive_players();
449         return true;
450 }
451
452 MUTATOR_HOOKFUNCTION(ft, GiveFragsForKill, CBC_ORDER_FIRST)
453 {
454         M_ARGV(2, float) = 0; // no frags counted in Freeze Tag
455         return true;
456 }
457
458 MUTATOR_HOOKFUNCTION(ft, Unfreeze)
459 {
460         entity targ = M_ARGV(0, entity);
461         targ.freezetag_frozen_time = 0;
462         targ.freezetag_frozen_timeout = 0;
463 }
464
465 MUTATOR_HOOKFUNCTION(ft, Damage_Calculate)
466 {
467         entity frag_attacker = M_ARGV(1, entity);
468         entity frag_target = M_ARGV(2, entity);
469         //float frag_deathtype = M_ARGV(3, float);
470         //float frag_damage = M_ARGV(4, float);
471         vector frag_force = M_ARGV(6, vector);
472
473         if (STAT(FROZEN, frag_target) == FROZEN_NORMAL && autocvar_g_freezetag_revive_auto_reducible
474                 && autocvar_g_freezetag_frozen_maxtime > 0 && autocvar_g_freezetag_revive_auto)
475         {
476                 float t = 0;
477                 if ((autocvar_g_freezetag_revive_auto_reducible < 0 || DIFF_TEAM(frag_attacker, frag_target))
478                         && frag_target.freezetag_frozen_timeout > time)
479                 {
480                         if (fabs(autocvar_g_freezetag_revive_auto_reducible) == 1)
481                                 t = vlen(frag_force) * autocvar_g_freezetag_revive_auto_reducible_forcefactor;
482                         frag_target.freezetag_frozen_timeout -= t;
483                         if (frag_target.freezetag_frozen_timeout < time)
484                                 frag_target.freezetag_frozen_timeout = time;
485                 }
486         }
487 }
488
489 #ifdef IS_REVIVING
490         #undef IS_REVIVING
491 #endif
492
493 // returns true if player is reviving it
494 #define IS_REVIVING(player, it, revive_extra_size) \
495         (it != player && !STAT(FROZEN, it) && !IS_DEAD(it) && SAME_TEAM(it, player) \
496         && boxesoverlap(player.absmin - revive_extra_size, player.absmax + revive_extra_size, it.absmin, it.absmax))
497
498 MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST)
499 {
500         if(game_stopped)
501                 return true;
502
503         if(round_handler_IsActive())
504         if(!round_handler_IsRoundStarted())
505                 return true;
506
507         entity player = M_ARGV(0, entity);
508         //if (STAT(FROZEN, player) == FROZEN_NORMAL)
509         //if(player.freezetag_frozen_timeout > 0 && time < player.freezetag_frozen_timeout)
510                 //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);
511
512         if (!(frametime && IS_PLAYER(player)))
513                 return true;
514
515         entity reviving_players_last = NULL;
516         entity reviving_players_first = NULL;
517
518         int n = 0;
519         vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
520         FOREACH_CLIENT(IS_PLAYER(it) && IS_REVIVING(player, it, revive_extra_size), {
521                 if (autocvar_g_freezetag_revive_time_to_score > 0 && STAT(FROZEN, player) == FROZEN_NORMAL)
522                 {
523                         it.freezetag_revive_time += frametime / autocvar_g_freezetag_revive_time_to_score;
524                         while (it.freezetag_revive_time > 1)
525                         {
526                                 GameRules_scoring_add(it, SCORE, +1);
527                                 it.freezetag_revive_time -= 1;
528                         }
529                 }
530                 if (reviving_players_last)
531                         reviving_players_last.chain = it;
532                 reviving_players_last = it;
533                 if (!reviving_players_first)
534                         reviving_players_first = it;
535                 ++n;
536         });
537         if (reviving_players_last)
538                 reviving_players_last.chain = NULL;
539
540         // allow normal revival during automatic revival
541         // (not allowing it IS_REVIVING should check freezetag_frozen_timeout too)
542         if (!n && player.freezetag_frozen_timeout > 0 && time >= player.freezetag_frozen_timeout)
543                 n = -1;
544
545         float base_progress = 0;
546         if  (STAT(FROZEN, player) == FROZEN_NORMAL && autocvar_g_freezetag_revive_auto
547                 && autocvar_g_freezetag_frozen_maxtime > 0 && autocvar_g_freezetag_revive_auto_progress)
548         {
549                 // NOTE if auto-revival is in progress, manual revive speed is reduced so that it always takes the same amount of time
550                 base_progress = bound(0, (1 - (player.freezetag_frozen_timeout - time) / autocvar_g_freezetag_frozen_maxtime), 1);
551         }
552
553         if (!n) // no teammate nearby
554         {
555                 float clearspeed = autocvar_g_freezetag_revive_clearspeed;
556                 if (autocvar_g_freezetag_revive_time_to_score > 0)
557                         clearspeed = 0; // prevent stacking points by entering and exiting the revival zone many times
558                 if (STAT(FROZEN, player) == FROZEN_NORMAL)
559                         STAT(REVIVE_PROGRESS, player) = bound(base_progress, STAT(REVIVE_PROGRESS, player) - frametime * clearspeed * (1 - base_progress), 1);
560                 else if (!STAT(FROZEN, player))
561                         STAT(REVIVE_PROGRESS, player) = base_progress; // thawing nobody
562         }
563         else if (STAT(FROZEN, player) == FROZEN_NORMAL) // OK, there is at least one teammate reviving us
564         {
565                 STAT(REVIVE_PROGRESS, player) = bound(base_progress, STAT(REVIVE_PROGRESS, player) + frametime * max(1/60, autocvar_g_freezetag_revive_speed * (1 - base_progress)), 1);
566
567                 if(STAT(REVIVE_PROGRESS, player) >= 1)
568                 {
569                         float frozen_time = time - player.freezetag_frozen_time;
570                         Unfreeze(player, false);
571                         SetResourceExplicit(player, RES_HEALTH, ((warmup_stage) ? warmup_start_health : start_health));
572                         freezetag_count_alive_players();
573
574                         if(n == -1)
575                         {
576                                 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_AUTO_REVIVED, frozen_time);
577                                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_AUTO_REVIVED, player.netname, frozen_time);
578                                 return true;
579                         }
580
581                         // EVERY team mate nearby gets a point (even if multiple!)
582                         for(entity it = reviving_players_first; it; it = it.chain)
583                         {
584                                 GameRules_scoring_add(it, FREEZETAG_REVIVALS, +1);
585                                 GameRules_scoring_add(it, SCORE, +1);
586                                 nades_GiveBonus(it, autocvar_g_nades_bonus_score_low);
587                         }
588
589                         entity first = reviving_players_first;
590                         Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_REVIVED, first.netname);
591                         Send_Notification(NOTIF_ONE, first, MSG_CENTER, CENTER_FREEZETAG_REVIVE, player.netname);
592                         Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_REVIVED, player.netname, first.netname);
593                 }
594
595                 for(entity it = reviving_players_first; it; it = it.chain)
596                         STAT(REVIVE_PROGRESS, it) = STAT(REVIVE_PROGRESS, player);
597         }
598
599         if (STAT(FROZEN, player) == FROZEN_NORMAL)
600         {
601                 entity player_wp = player.waypointsprite_attached;
602                 if (n > 0 || (n == 0 && STAT(REVIVE_PROGRESS, player) > 0.95))
603                 {
604                         WaypointSprite_UpdateSprites(player_wp, WP_Reviving, WP_Null, WP_Null);
605                         WaypointSprite_UpdateTeamRadar(player_wp, RADARICON_WAYPOINT, WP_REVIVING_COLOR);
606                 }
607                 else
608                 {
609                         WaypointSprite_UpdateSprites(player_wp, WP_Frozen, WP_Null, WP_Null);
610                         WaypointSprite_UpdateTeamRadar(player_wp, RADARICON_WAYPOINT, WP_FROZEN_COLOR);
611                 }
612
613                 WaypointSprite_UpdateMaxHealth(player_wp, 1);
614                 WaypointSprite_UpdateHealth(player_wp, STAT(REVIVE_PROGRESS, player));
615         }
616
617         return true;
618 }
619
620 MUTATOR_HOOKFUNCTION(ft, SetStartItems)
621 {
622         start_items &= ~(IT_UNLIMITED_AMMO | IT_UNLIMITED_SUPERWEAPONS);
623         start_health       = warmup_start_health       = cvar("g_ft_start_health");
624         start_armorvalue   = warmup_start_armorvalue   = cvar("g_ft_start_armor");
625         start_ammo_shells  = warmup_start_ammo_shells  = cvar("g_ft_start_ammo_shells");
626         start_ammo_nails   = warmup_start_ammo_nails   = cvar("g_ft_start_ammo_nails");
627         start_ammo_rockets = warmup_start_ammo_rockets = cvar("g_ft_start_ammo_rockets");
628         start_ammo_cells   = warmup_start_ammo_cells   = cvar("g_ft_start_ammo_cells");
629         start_ammo_plasma  = warmup_start_ammo_plasma  = cvar("g_ft_start_ammo_plasma");
630         start_ammo_fuel    = warmup_start_ammo_fuel    = cvar("g_ft_start_ammo_fuel");
631 }
632
633 MUTATOR_HOOKFUNCTION(ft, HavocBot_ChooseRole)
634 {
635         entity bot = M_ARGV(0, entity);
636
637         if (!IS_DEAD(bot))
638         {
639                 if (random() < 0.5)
640                         bot.havocbot_role = havocbot_role_ft_freeing;
641                 else
642                         bot.havocbot_role = havocbot_role_ft_offense;
643         }
644
645         // if bots spawn all at once assign them a more appropriated role after a while
646         if (time < CS(bot).jointime + 1)
647                 bot.havocbot_role_timeout = time + 10 + random() * 10;
648
649         return true;
650 }
651
652 MUTATOR_HOOKFUNCTION(ft, TeamBalance_CheckAllowedTeams, CBC_ORDER_EXCLUSIVE)
653 {
654         M_ARGV(0, float) = freezetag_teams;
655         return true;
656 }
657
658 MUTATOR_HOOKFUNCTION(ft, SetWeaponArena)
659 {
660         if(M_ARGV(0, string) == "0" || M_ARGV(0, string) == "")
661                 M_ARGV(0, string) = autocvar_g_freezetag_weaponarena;
662 }
663
664 MUTATOR_HOOKFUNCTION(ft, FragCenterMessage)
665 {
666         entity frag_attacker = M_ARGV(0, entity);
667         entity frag_target = M_ARGV(1, entity);
668         //float frag_deathtype = M_ARGV(2, float);
669         int kill_count_to_attacker = M_ARGV(3, int);
670         int kill_count_to_target = M_ARGV(4, int);
671
672         if(STAT(FROZEN, frag_target) == FROZEN_NORMAL)
673                 return; // target was already frozen, so this is just pushing them off the cliff
674
675         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));
676         Send_Notification(NOTIF_ONE, frag_target, MSG_CHOICE, CHOICE_FRAGGED_FREEZE, frag_attacker.netname, kill_count_to_target,
677                 GetResource(frag_attacker, RES_HEALTH), GetResource(frag_attacker, RES_ARMOR), (IS_BOT_CLIENT(frag_attacker) ? -1 : CS(frag_attacker).ping));
678
679         return true;
680 }
681
682 MUTATOR_HOOKFUNCTION(ft, SV_ParseServerCommand)
683 {
684         string cmd_name = M_ARGV(0, string);
685         if (cmd_name == "shuffleteams")
686                 shuffleteams_on_reset_map = !(round_handler_IsActive() && !round_handler_IsRoundStarted());
687         return false;
688 }
689
690 MUTATOR_HOOKFUNCTION(ft, Scores_CountFragsRemaining)
691 {
692         // announce remaining frags
693         return true;
694 }
695
696 void freezetag_Initialize()
697 {
698         freezetag_teams = autocvar_g_freezetag_teams_override;
699         if(freezetag_teams < 2)
700                 freezetag_teams = cvar("g_freezetag_teams"); // read the cvar directly as it gets written earlier in the same frame
701
702         freezetag_teams = BITS(bound(2, freezetag_teams, 4));
703         GameRules_scoring(freezetag_teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, {
704                 field_team(ST_FT_ROUNDS, "rounds", SFL_SORT_PRIO_PRIMARY);
705                 field(SP_FREEZETAG_REVIVALS, "revivals", 0);
706         });
707
708         round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null);
709         round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
710
711         EliminatedPlayers_Init(freezetag_isEliminated);
712 }