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