1 .float freezetag_frozen_time;
2 .float freezetag_frozen_timeout;
3 .float freezetag_revive_progress;
4 #define ICE_MAX_ALPHA 1
5 #define ICE_MIN_ALPHA 0.1
8 void freezetag_count_alive_players()
11 total_players = redalive = bluealive = yellowalive = pinkalive = 0;
13 if(e.team == NUM_TEAM_1 && e.health >= 1)
16 if (e.frozen != 1) ++redalive;
18 else if(e.team == NUM_TEAM_2 && e.health >= 1)
21 if (e.frozen != 1) ++bluealive;
23 else if(e.team == NUM_TEAM_3 && e.health >= 1)
26 if (e.frozen != 1) ++yellowalive;
28 else if(e.team == NUM_TEAM_4 && e.health >= 1)
31 if (e.frozen != 1) ++pinkalive;
34 FOR_EACH_REALCLIENT(e) {
35 e.redalive_stat = redalive;
36 e.bluealive_stat = bluealive;
37 e.yellowalive_stat = yellowalive;
38 e.pinkalive_stat = pinkalive;
41 #define FREEZETAG_ALIVE_TEAMS() ((redalive > 0) + (bluealive > 0) + (yellowalive > 0) + (pinkalive > 0))
42 #define FREEZETAG_ALIVE_TEAMS_OK() (FREEZETAG_ALIVE_TEAMS() == freezetag_teams)
44 float prev_total_players;
45 float freezetag_CheckTeams()
47 if(FREEZETAG_ALIVE_TEAMS_OK())
49 if(prev_total_players > 0)
50 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
51 prev_total_players = -1;
54 if(prev_total_players != total_players)
56 float p1 = 0, p2 = 0, p3 = 0, p4 = 0;
57 if(!redalive) p1 = NUM_TEAM_1;
58 if(!bluealive) p2 = NUM_TEAM_2;
59 if(freezetag_teams >= 3)
60 if(!yellowalive) p3 = NUM_TEAM_3;
61 if(freezetag_teams >= 4)
62 if(!pinkalive) p4 = NUM_TEAM_4;
63 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, p1, p2, p3, p4);
64 prev_total_players = total_players;
69 float freezetag_getWinnerTeam()
71 float winner_team = 0;
73 winner_team = NUM_TEAM_1;
76 if(winner_team) return 0;
77 winner_team = NUM_TEAM_2;
81 if(winner_team) return 0;
82 winner_team = NUM_TEAM_3;
86 if(winner_team) return 0;
87 winner_team = NUM_TEAM_4;
91 return -1; // no player left
94 float freezetag_CheckWinner()
97 if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
99 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
100 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
102 e.freezetag_frozen_timeout = 0;
103 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
107 if(FREEZETAG_ALIVE_TEAMS() > 1)
111 winner_team = freezetag_getWinnerTeam();
114 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
115 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
116 TeamScore_AddToTeam(winner_team, ST_SCORE, +1);
118 else if(winner_team == -1)
120 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
121 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
125 e.freezetag_frozen_timeout = 0;
126 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
130 void freezetag_Add_Score(entity attacker)
134 // you froze your own dumb self
135 // counted as "suicide" already
136 PlayerScore_Add(self, SP_SCORE, -1);
138 else if(IS_PLAYER(attacker))
140 // got frozen by an enemy
141 // counted as "kill" and "death" already
142 PlayerScore_Add(self, SP_SCORE, -1);
143 PlayerScore_Add(attacker, SP_SCORE, +1);
145 // else nothing - got frozen by the game type rules themselves
148 void freezetag_Freeze(entity attacker)
153 Freeze(self, 0, 1, TRUE);
155 freezetag_count_alive_players();
157 freezetag_Add_Score(attacker);
160 void freezetag_Unfreeze(entity attacker)
162 self.freezetag_frozen_time = 0;
163 self.freezetag_frozen_timeout = 0;
172 void() havocbot_role_ft_freeing;
173 void() havocbot_role_ft_offense;
175 void havocbot_goalrating_freeplayers(float ratingscale, vector org, float sradius)
180 FOR_EACH_PLAYER(head)
182 if ((head != self) && (head.team == self.team))
184 if (head.frozen == 1)
186 distance = vlen(head.origin - org);
187 if (distance > sradius)
189 navigation_routerating(head, ratingscale, 2000);
193 // If teamate is not frozen still seek them out as fight better
195 navigation_routerating(head, ratingscale/3, 2000);
201 void havocbot_role_ft_offense()
206 if(self.deadflag != DEAD_NO)
209 if (!self.havocbot_role_timeout)
210 self.havocbot_role_timeout = time + random() * 10 + 20;
212 // Count how many players on team are unfrozen.
214 FOR_EACH_PLAYER(head)
216 if ((head.team == self.team) && (head.frozen != 1))
220 // If only one left on team or if role has timed out then start trying to free players.
221 if (((unfrozen == 0) && (!self.frozen)) || (time > self.havocbot_role_timeout))
223 dprint("changing role to freeing\n");
224 self.havocbot_role = havocbot_role_ft_freeing;
225 self.havocbot_role_timeout = 0;
229 if (time > self.bot_strategytime)
231 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
233 navigation_goalrating_start();
234 havocbot_goalrating_items(10000, self.origin, 10000);
235 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
236 havocbot_goalrating_freeplayers(9000, self.origin, 10000);
237 //havocbot_goalrating_waypoints(1, self.origin, 1000);
238 navigation_goalrating_end();
242 void havocbot_role_ft_freeing()
244 if(self.deadflag != DEAD_NO)
247 if (!self.havocbot_role_timeout)
248 self.havocbot_role_timeout = time + random() * 10 + 20;
250 if (time > self.havocbot_role_timeout)
252 dprint("changing role to offense\n");
253 self.havocbot_role = havocbot_role_ft_offense;
254 self.havocbot_role_timeout = 0;
258 if (time > self.bot_strategytime)
260 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
262 navigation_goalrating_start();
263 havocbot_goalrating_items(8000, self.origin, 10000);
264 havocbot_goalrating_enemyplayers(10000, self.origin, 10000);
265 havocbot_goalrating_freeplayers(20000, self.origin, 10000);
266 //havocbot_goalrating_waypoints(1, self.origin, 1000);
267 navigation_goalrating_end();
276 MUTATOR_HOOKFUNCTION(freezetag_RemovePlayer)
278 self.health = 0; // neccessary to update correctly alive stats
279 freezetag_Unfreeze(world);
280 freezetag_count_alive_players();
284 MUTATOR_HOOKFUNCTION(freezetag_PlayerDies)
286 if(round_handler_IsActive())
287 if(round_handler_CountdownRunning())
290 freezetag_Unfreeze(world);
291 freezetag_count_alive_players();
292 return 1; // let the player die so that he can respawn whenever he wants
295 // Cases DEATH_TEAMCHANGE and DEATH_AUTOTEAMCHANGE are needed to fix a bug whe
296 // you succeed changing team through the menu: you both really die (gibbing) and get frozen
297 if(ITEM_DAMAGE_NEEDKILL(frag_deathtype)
298 || frag_deathtype == DEATH_TEAMCHANGE || frag_deathtype == DEATH_AUTOTEAMCHANGE)
300 // let the player die, he will be automatically frozen when he respawns
303 freezetag_Add_Score(frag_attacker);
304 freezetag_count_alive_players();
307 freezetag_Unfreeze(world); // remove ice
308 self.freezetag_frozen_timeout = -2; // freeze on respawn
315 freezetag_Freeze(frag_attacker);
317 if(frag_attacker == frag_target || frag_attacker == world)
319 if(IS_PLAYER(frag_target))
320 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_SELF);
321 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_SELF, frag_target.netname);
325 if(IS_PLAYER(frag_target))
326 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_FROZEN, frag_attacker.netname);
327 if(IS_PLAYER(frag_attacker))
328 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_FREEZETAG_FREEZE, frag_target.netname);
329 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_FREEZE, frag_target.netname, frag_attacker.netname);
335 MUTATOR_HOOKFUNCTION(freezetag_PlayerSpawn)
337 if(self.freezetag_frozen_timeout == -1) // if PlayerSpawn is called by reset_map_players
338 return 1; // do nothing, round is starting right now
340 if(self.freezetag_frozen_timeout == -2) // player was dead
342 freezetag_Freeze(world);
346 freezetag_count_alive_players();
348 if(round_handler_IsActive())
349 if(round_handler_IsRoundStarted())
351 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
352 freezetag_Freeze(world);
358 MUTATOR_HOOKFUNCTION(freezetag_reset_map_players)
360 FOR_EACH_PLAYER(self)
363 freezetag_Unfreeze(world);
364 self.freezetag_frozen_timeout = -1;
366 self.freezetag_frozen_timeout = 0;
368 freezetag_count_alive_players();
372 MUTATOR_HOOKFUNCTION(freezetag_GiveFragsForKill)
374 frag_score = 0; // no frags counted in Freeze Tag
378 .float reviving; // temp var
379 MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink)
389 self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
392 if(round_handler_IsActive())
393 if(!round_handler_IsRoundStarted())
398 if(self.freezetag_frozen_timeout > 0 && time < self.freezetag_frozen_timeout)
399 self.iceblock.alpha = ICE_MIN_ALPHA + (ICE_MAX_ALPHA - ICE_MIN_ALPHA) * (self.freezetag_frozen_timeout - time) / (self.freezetag_frozen_timeout - self.freezetag_frozen_time);
401 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
405 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
407 FOR_EACH_PLAYER(other) if(self != other)
411 if(other.team == self.team)
413 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
418 other.reviving = TRUE;
426 if(n && self.frozen == 1) // OK, there is at least one teammate reviving us
428 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
429 self.health = max(1, self.revive_progress * autocvar_g_balance_health_start);
431 if(self.revive_progress >= 1)
433 freezetag_Unfreeze(self);
434 freezetag_count_alive_players();
438 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_AUTO_REVIVED, autocvar_g_freezetag_frozen_maxtime);
439 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_AUTO_REVIVED, self.netname, autocvar_g_freezetag_frozen_maxtime);
443 // EVERY team mate nearby gets a point (even if multiple!)
444 FOR_EACH_PLAYER(other)
448 PlayerScore_Add(other, SP_FREEZETAG_REVIVALS, +1);
449 PlayerScore_Add(other, SP_SCORE, +1);
453 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
454 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
455 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED, self.netname, o.netname);
458 FOR_EACH_PLAYER(other)
462 other.revive_progress = self.revive_progress;
463 other.reviving = FALSE;
467 else if(!n && self.frozen == 1) // only if no teammate is nearby will we reset
469 self.revive_progress = bound(0, self.revive_progress - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
470 self.health = max(1, self.revive_progress * autocvar_g_balance_health_start);
472 else if(!n && !self.frozen)
474 self.revive_progress = 0; // thawing nobody
480 MUTATOR_HOOKFUNCTION(freezetag_PlayerDamage_Calculate)
482 if(frag_target.frozen == 1 && frag_deathtype != DEATH_HURTTRIGGER)
485 frag_force = frag_force * autocvar_g_freezetag_frozen_force;
490 MUTATOR_HOOKFUNCTION(freezetag_BotRoles)
492 if not(self.deadflag)
495 self.havocbot_role = havocbot_role_ft_freeing;
497 self.havocbot_role = havocbot_role_ft_offense;
503 MUTATOR_HOOKFUNCTION(freezetag_GetTeamCount)
505 freezetag_teams = autocvar_g_freezetag_teams_override;
506 if(freezetag_teams < 2)
507 freezetag_teams = autocvar_g_freezetag_teams;
508 freezetag_teams = bound(2, freezetag_teams, 4);
509 ret_float = freezetag_teams;
513 void freezetag_Initialize()
515 precache_model("models/ice/ice.md3");
516 ScoreRules_freezetag();
518 round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null);
519 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
521 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
522 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
523 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
524 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
527 MUTATOR_DEFINITION(gamemode_freezetag)
529 MUTATOR_HOOK(MakePlayerObserver, freezetag_RemovePlayer, CBC_ORDER_ANY);
530 MUTATOR_HOOK(ClientDisconnect, freezetag_RemovePlayer, CBC_ORDER_ANY);
531 MUTATOR_HOOK(PlayerDies, freezetag_PlayerDies, CBC_ORDER_ANY);
532 MUTATOR_HOOK(PlayerSpawn, freezetag_PlayerSpawn, CBC_ORDER_ANY);
533 MUTATOR_HOOK(reset_map_players, freezetag_reset_map_players, CBC_ORDER_ANY);
534 MUTATOR_HOOK(GiveFragsForKill, freezetag_GiveFragsForKill, CBC_ORDER_FIRST);
535 MUTATOR_HOOK(PlayerPreThink, freezetag_PlayerPreThink, CBC_ORDER_FIRST);
536 MUTATOR_HOOK(PlayerDamage_Calculate, freezetag_PlayerDamage_Calculate, CBC_ORDER_ANY);
537 MUTATOR_HOOK(HavocBot_ChooseRule, freezetag_BotRoles, CBC_ORDER_ANY);
538 MUTATOR_HOOK(GetTeamCount, freezetag_GetTeamCount, CBC_ORDER_EXCLUSIVE);
542 if(time > 1) // game loads at time 1
543 error("This is a game type and it cannot be added at runtime.");
544 freezetag_Initialize();
547 MUTATOR_ONROLLBACK_OR_REMOVE
549 // we actually cannot roll back freezetag_Initialize here
550 // BUT: we don't need to! If this gets called, adding always
556 print("This is a game type and it cannot be removed at runtime.");