]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/gamemodes/gamemode/freezetag/sv_freezetag.qc
Reduce auto-revival time when frozen players are hit by enemies (time reduction depen...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / freezetag / sv_freezetag.qc
1 #include "sv_freezetag.qh"
2
3 #include <server/resources.qh>
4
5 float autocvar_g_freezetag_frozen_maxtime;
6 float autocvar_g_freezetag_revive_clearspeed;
7 float autocvar_g_freezetag_round_timelimit;
8 //int autocvar_g_freezetag_teams;
9 int autocvar_g_freezetag_teams_override;
10 float autocvar_g_freezetag_warmup;
11
12 void freezetag_count_alive_players()
13 {
14         total_players = 0;
15         for (int i = 1; i <= NUM_TEAMS; ++i)
16         {
17                 Team_SetNumberOfAlivePlayers(Team_GetTeamFromIndex(i), 0);
18         }
19         FOREACH_CLIENT(IS_PLAYER(it) && Entity_HasValidTeam(it),
20         {
21                 ++total_players;
22                 if (GetResource(it, RES_HEALTH) < 1 || STAT(FROZEN, it) == FROZEN_NORMAL)
23                 {
24                         continue;
25                 }
26                 entity team_ = Entity_GetTeam(it);
27                 int num_alive = Team_GetNumberOfAlivePlayers(team_);
28                 ++num_alive;
29                 Team_SetNumberOfAlivePlayers(team_, num_alive);
30         });
31         FOREACH_CLIENT(IS_REAL_CLIENT(it),
32         {
33                 STAT(REDALIVE, it) = Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(
34                         1));
35                 STAT(BLUEALIVE, it) = Team_GetNumberOfAlivePlayers(
36                         Team_GetTeamFromIndex(2));
37                 STAT(YELLOWALIVE, it) = Team_GetNumberOfAlivePlayers(
38                         Team_GetTeamFromIndex(3));
39                 STAT(PINKALIVE, it) = Team_GetNumberOfAlivePlayers(
40                         Team_GetTeamFromIndex(4));
41         });
42
43         eliminatedPlayers.SendFlags |= 1;
44 }
45
46 bool freezetag_CheckTeams()
47 {
48         static float prev_missing_teams_mask;
49         if (Team_GetNumberOfAliveTeams() == NumTeams(freezetag_teams))
50         {
51                 if(prev_missing_teams_mask > 0)
52                         Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_TEAMS);
53                 prev_missing_teams_mask = -1;
54                 return true;
55         }
56         if(total_players == 0)
57         {
58                 if(prev_missing_teams_mask > 0)
59                         Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_TEAMS);
60                 prev_missing_teams_mask = -1;
61                 return false;
62         }
63         int missing_teams_mask = 0;
64         for (int i = 1; i <= NUM_TEAMS; ++i)
65         {
66                 if ((freezetag_teams & Team_IndexToBit(i)) &&
67                         (Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(i)) == 0))
68                 {
69                         missing_teams_mask |= Team_IndexToBit(i);
70                 }
71         }
72         if(prev_missing_teams_mask != missing_teams_mask)
73         {
74                 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
75                 prev_missing_teams_mask = missing_teams_mask;
76         }
77         return false;
78 }
79
80 int freezetag_getWinnerTeam()
81 {
82         int winner_team = 0;
83         if (Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(1)) >= 1)
84         {
85                 winner_team = NUM_TEAM_1;
86         }
87         for (int i = 2; i <= NUM_TEAMS; ++i)
88         {
89                 if (Team_GetNumberOfAlivePlayers(Team_GetTeamFromIndex(i)) >= 1)
90                 {
91                         if (winner_team != 0)
92                         {
93                                 return 0;
94                         }
95                         winner_team = Team_IndexToTeam(i);
96                 }
97         }
98         if (winner_team)
99         {
100                 return winner_team;
101         }
102         return -1; // no player left
103 }
104
105 void nades_Clear(entity);
106 void nades_GiveBonus(entity player, float score);
107
108 bool freezetag_CheckWinner()
109 {
110         if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
111         {
112                 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_OVER);
113                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_OVER);
114                 FOREACH_CLIENT(IS_PLAYER(it), {
115                         it.freezetag_frozen_timeout = 0;
116                         nades_Clear(it);
117                 });
118                 game_stopped = true;
119                 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
120                 return true;
121         }
122
123         if (Team_GetNumberOfAliveTeams() > 1)
124         {
125                 return false;
126         }
127
128         int winner_team = freezetag_getWinnerTeam();
129         if(winner_team > 0)
130         {
131                 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
132                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
133                 TeamScore_AddToTeam(winner_team, ST_SCORE, +1);
134         }
135         else if(winner_team == -1)
136         {
137                 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_TIED);
138                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_TIED);
139         }
140
141         FOREACH_CLIENT(IS_PLAYER(it), {
142                 it.freezetag_frozen_timeout = 0;
143                 nades_Clear(it);
144         });
145
146         game_stopped = true;
147         round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
148         return true;
149 }
150
151 entity freezetag_LastPlayerForTeam(entity this)
152 {
153         entity last_pl = NULL;
154         FOREACH_CLIENT(IS_PLAYER(it) && it != this && SAME_TEAM(it, this), {
155                 if (STAT(FROZEN, it) != FROZEN_NORMAL && GetResource(it, RES_HEALTH) >= 1)
156                 {
157                         if (!last_pl)
158                                 last_pl = it;
159                         else
160                                 return NULL;
161                 }
162         });
163         return last_pl;
164 }
165
166 void freezetag_LastPlayerForTeam_Notify(entity this)
167 {
168         if(round_handler_IsActive())
169         if(round_handler_IsRoundStarted())
170         {
171                 entity pl = freezetag_LastPlayerForTeam(this);
172                 if(pl)
173                         Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
174         }
175 }
176
177 void freezetag_Add_Score(entity targ, entity attacker)
178 {
179         if(attacker == targ)
180         {
181                 // you froze your own dumb targ
182                 // counted as "suicide" already
183                 GameRules_scoring_add(targ, SCORE, -1);
184         }
185         else if(IS_PLAYER(attacker))
186         {
187                 // got frozen by an enemy
188                 // counted as "kill" and "death" already
189                 GameRules_scoring_add(targ, SCORE, -1);
190                 GameRules_scoring_add(attacker, SCORE, +1);
191         }
192         // else nothing - got frozen by the game type rules themselves
193 }
194
195 // to be called when the player is frozen by freezetag (on death, spectator join etc), gives the score
196 void freezetag_Freeze(entity targ, entity attacker)
197 {
198         if(STAT(FROZEN, targ))
199                 return;
200
201         targ.freezetag_frozen_time = time;
202         if (autocvar_g_freezetag_revive_auto && 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                 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) != FROZEN_NORMAL)
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) == FROZEN_NORMAL)
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, Damage_Calculate)
457 {
458         entity frag_attacker = M_ARGV(1, entity);
459         entity frag_target = M_ARGV(2, entity);
460         //float frag_deathtype = M_ARGV(3, float);
461         //float frag_damage = M_ARGV(4, float);
462         vector frag_force = M_ARGV(6, vector);
463
464         if (STAT(FROZEN, frag_target) == FROZEN_NORMAL && autocvar_g_freezetag_revive_auto_reducible
465                 && autocvar_g_freezetag_frozen_maxtime > 0 && autocvar_g_freezetag_revive_auto)
466         {
467                 float t = 0;
468                 if ((autocvar_g_freezetag_revive_auto_reducible > 0 || DIFF_TEAM(frag_attacker, frag_target))
469                         && frag_target.freezetag_frozen_timeout > time)
470                 {
471                         if (fabs(autocvar_g_freezetag_revive_auto_reducible) == 1)
472                                 t = vlen(frag_force) * autocvar_g_freezetag_revive_auto_reducible_forcefactor;
473                         frag_target.freezetag_frozen_timeout -= t;
474                         if (frag_target.freezetag_frozen_timeout < time)
475                                 frag_target.freezetag_frozen_timeout = time;
476                 }
477         }
478 }
479
480 #ifdef IS_REVIVING
481         #undef IS_REVIVING
482 #endif
483
484 // returns true if player is reviving it
485 #define IS_REVIVING(player, it, revive_extra_size) \
486         (it != player && !STAT(FROZEN, it) && !IS_DEAD(it) && SAME_TEAM(it, player) \
487         && boxesoverlap(player.absmin - revive_extra_size, player.absmax + revive_extra_size, it.absmin, it.absmax))
488
489 MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST)
490 {
491         if(game_stopped)
492                 return true;
493
494         if(round_handler_IsActive())
495         if(!round_handler_IsRoundStarted())
496                 return true;
497
498         int n;
499         entity player = M_ARGV(0, entity);
500         //if (STAT(FROZEN, player) == FROZEN_NORMAL)
501         //if(player.freezetag_frozen_timeout > 0 && time < player.freezetag_frozen_timeout)
502                 //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);
503
504         entity reviving_players_last = NULL;
505         entity reviving_players_first = NULL;
506
507         if(player.freezetag_frozen_timeout > 0 && time >= player.freezetag_frozen_timeout)
508                 n = -1;
509         else
510         {
511                 n = 0;
512                 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
513                 FOREACH_CLIENT(IS_PLAYER(it) && IS_REVIVING(player, it, revive_extra_size), {
514                         if (reviving_players_last)
515                                 reviving_players_last.chain = it;
516                         reviving_players_last = it;
517                         if (!reviving_players_first)
518                                 reviving_players_first = it;
519                         ++n;
520                 });
521                 if (reviving_players_last)
522                         reviving_players_last.chain = NULL;
523         }
524
525         float base_progress = 0;
526         if  (STAT(FROZEN, player) == FROZEN_NORMAL && autocvar_g_freezetag_revive_auto
527                 && autocvar_g_freezetag_frozen_maxtime > 0 && autocvar_g_freezetag_revive_auto_progress)
528         {
529                 base_progress = bound(0, (1 - (player.freezetag_frozen_timeout - time) / autocvar_g_freezetag_frozen_maxtime), 1);
530         }
531
532         if (!n) // no teammate nearby
533         {
534                 if (STAT(FROZEN, player) == FROZEN_NORMAL)
535                 {
536                         STAT(REVIVE_PROGRESS, player) = bound(base_progress, STAT(REVIVE_PROGRESS, player) - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
537                         SetResourceExplicit(player, RES_HEALTH, max(1, STAT(REVIVE_PROGRESS, player) * ((warmup_stage) ? warmup_start_health : start_health)));
538                 }
539                 else if (!STAT(FROZEN, player))
540                         STAT(REVIVE_PROGRESS, player) = base_progress; // thawing nobody
541         }
542         else if (STAT(FROZEN, player) == FROZEN_NORMAL) // OK, there is at least one teammate reviving us
543         {
544                 STAT(REVIVE_PROGRESS, player) = bound(base_progress, STAT(REVIVE_PROGRESS, player) + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
545                 SetResourceExplicit(player, RES_HEALTH, max(1, STAT(REVIVE_PROGRESS, player) * ((warmup_stage) ? warmup_start_health : start_health)));
546
547                 if(STAT(REVIVE_PROGRESS, player) >= 1)
548                 {
549                         float frozen_time = time - player.freezetag_frozen_time;
550                         Unfreeze(player, false);
551                         freezetag_count_alive_players();
552
553                         if(n == -1)
554                         {
555                                 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_AUTO_REVIVED, frozen_time);
556                                 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_AUTO_REVIVED, player.netname, frozen_time);
557                                 return true;
558                         }
559
560                         // EVERY team mate nearby gets a point (even if multiple!)
561                         for(entity it = reviving_players_first; it; it = it.chain)
562                         {
563                                 GameRules_scoring_add(it, FREEZETAG_REVIVALS, +1);
564                                 GameRules_scoring_add(it, SCORE, +1);
565                                 nades_GiveBonus(it, autocvar_g_nades_bonus_score_low);
566                         }
567
568                         entity first = reviving_players_first;
569                         Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_REVIVED, first.netname);
570                         Send_Notification(NOTIF_ONE, first, MSG_CENTER, CENTER_FREEZETAG_REVIVE, player.netname);
571                         Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_REVIVED, player.netname, first.netname);
572                 }
573
574                 for(entity it = reviving_players_first; it; it = it.chain)
575                         STAT(REVIVE_PROGRESS, it) = STAT(REVIVE_PROGRESS, player);
576         }
577
578         return true;
579 }
580
581 MUTATOR_HOOKFUNCTION(ft, SetStartItems)
582 {
583         start_items &= ~IT_UNLIMITED_AMMO;
584         //start_health       = warmup_start_health       = cvar("g_lms_start_health");
585         //start_armorvalue   = warmup_start_armorvalue   = cvar("g_lms_start_armor");
586         start_ammo_shells  = warmup_start_ammo_shells  = cvar("g_lms_start_ammo_shells");
587         start_ammo_nails   = warmup_start_ammo_nails   = cvar("g_lms_start_ammo_nails");
588         start_ammo_rockets = warmup_start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
589         start_ammo_cells   = warmup_start_ammo_cells   = cvar("g_lms_start_ammo_cells");
590         start_ammo_plasma  = warmup_start_ammo_plasma  = cvar("g_lms_start_ammo_plasma");
591         start_ammo_fuel    = warmup_start_ammo_fuel    = cvar("g_lms_start_ammo_fuel");
592 }
593
594 MUTATOR_HOOKFUNCTION(ft, HavocBot_ChooseRole)
595 {
596         entity bot = M_ARGV(0, entity);
597
598         if (!IS_DEAD(bot))
599         {
600                 if (random() < 0.5)
601                         bot.havocbot_role = havocbot_role_ft_freeing;
602                 else
603                         bot.havocbot_role = havocbot_role_ft_offense;
604         }
605
606         // if bots spawn all at once assign them a more appropriated role after a while
607         if (time < CS(bot).jointime + 1)
608                 bot.havocbot_role_timeout = time + 10 + random() * 10;
609
610         return true;
611 }
612
613 MUTATOR_HOOKFUNCTION(ft, TeamBalance_CheckAllowedTeams, CBC_ORDER_EXCLUSIVE)
614 {
615         M_ARGV(0, float) = freezetag_teams;
616         return true;
617 }
618
619 MUTATOR_HOOKFUNCTION(ft, SetWeaponArena)
620 {
621         // most weapons arena
622         if(M_ARGV(0, string) == "0" || M_ARGV(0, string) == "")
623                 M_ARGV(0, string) = "most";
624 }
625
626 MUTATOR_HOOKFUNCTION(ft, FragCenterMessage)
627 {
628         entity frag_attacker = M_ARGV(0, entity);
629         entity frag_target = M_ARGV(1, entity);
630         //float frag_deathtype = M_ARGV(2, float);
631         int kill_count_to_attacker = M_ARGV(3, int);
632         int kill_count_to_target = M_ARGV(4, int);
633
634         if(STAT(FROZEN, frag_target) == FROZEN_NORMAL)
635                 return; // target was already frozen, so this is just pushing them off the cliff
636
637         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));
638         Send_Notification(NOTIF_ONE, frag_target, MSG_CHOICE, CHOICE_FRAGGED_FREEZE, frag_attacker.netname, kill_count_to_target,
639                 GetResource(frag_attacker, RES_HEALTH), GetResource(frag_attacker, RES_ARMOR), (IS_BOT_CLIENT(frag_attacker) ? -1 : CS(frag_attacker).ping));
640
641         return true;
642 }
643
644 void freezetag_Initialize()
645 {
646         freezetag_teams = autocvar_g_freezetag_teams_override;
647         if(freezetag_teams < 2)
648                 freezetag_teams = cvar("g_freezetag_teams"); // read the cvar directly as it gets written earlier in the same frame
649
650         freezetag_teams = BITS(bound(2, freezetag_teams, 4));
651         GameRules_scoring(freezetag_teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, {
652                 field(SP_FREEZETAG_REVIVALS, "revivals", 0);
653         });
654
655         round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null);
656         round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
657
658         EliminatedPlayers_Init(freezetag_isEliminated);
659 }