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