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 #define SP_FREEZETAG_REVIVALS 4
9 void freezetag_ScoreRules(float teams)
11 ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, TRUE); // SFL_SORT_PRIO_PRIMARY
12 ScoreInfo_SetLabel_PlayerScore(SP_FREEZETAG_REVIVALS, "revivals", 0);
13 ScoreRules_basics_end();
16 void freezetag_count_alive_players()
19 total_players = redalive = bluealive = yellowalive = pinkalive = 0;
24 case NUM_TEAM_1: ++total_players; if(e.health >= 1 && e.frozen != 1) ++redalive; break;
25 case NUM_TEAM_2: ++total_players; if(e.health >= 1 && e.frozen != 1) ++bluealive; break;
26 case NUM_TEAM_3: ++total_players; if(e.health >= 1 && e.frozen != 1) ++yellowalive; break;
27 case NUM_TEAM_4: ++total_players; if(e.health >= 1 && e.frozen != 1) ++pinkalive; break;
30 FOR_EACH_REALCLIENT(e)
32 e.redalive_stat = redalive;
33 e.bluealive_stat = bluealive;
34 e.yellowalive_stat = yellowalive;
35 e.pinkalive_stat = pinkalive;
38 #define FREEZETAG_ALIVE_TEAMS() ((redalive > 0) + (bluealive > 0) + (yellowalive > 0) + (pinkalive > 0))
39 #define FREEZETAG_ALIVE_TEAMS_OK() (FREEZETAG_ALIVE_TEAMS() == freezetag_teams)
41 float prev_total_players;
42 float freezetag_CheckTeams()
44 if(FREEZETAG_ALIVE_TEAMS_OK())
46 if(prev_total_players > 0)
47 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
48 prev_total_players = -1;
51 if(prev_total_players != total_players)
53 float p1 = 0, p2 = 0, p3 = 0, p4 = 0;
54 if(!redalive) p1 = NUM_TEAM_1;
55 if(!bluealive) p2 = NUM_TEAM_2;
56 if(freezetag_teams >= 3)
57 if(!yellowalive) p3 = NUM_TEAM_3;
58 if(freezetag_teams >= 4)
59 if(!pinkalive) p4 = NUM_TEAM_4;
60 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, p1, p2, p3, p4);
61 prev_total_players = total_players;
66 float freezetag_getWinnerTeam()
68 float winner_team = 0;
70 winner_team = NUM_TEAM_1;
73 if(winner_team) return 0;
74 winner_team = NUM_TEAM_2;
78 if(winner_team) return 0;
79 winner_team = NUM_TEAM_3;
83 if(winner_team) return 0;
84 winner_team = NUM_TEAM_4;
88 return -1; // no player left
91 float freezetag_CheckWinner()
94 if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
96 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
97 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
100 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);
126 e.freezetag_frozen_timeout = 0;
129 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
133 void freezetag_Add_Score(entity attacker)
137 // you froze your own dumb self
138 // counted as "suicide" already
139 PlayerScore_Add(self, SP_SCORE, -1);
141 else if(IS_PLAYER(attacker))
143 // got frozen by an enemy
144 // counted as "kill" and "death" already
145 PlayerScore_Add(self, SP_SCORE, -1);
146 PlayerScore_Add(attacker, SP_SCORE, +1);
148 // else nothing - got frozen by the game type rules themselves
151 void freezetag_Freeze(entity attacker)
156 if(autocvar_g_freezetag_frozen_maxtime > 0)
157 self.freezetag_frozen_timeout = time + autocvar_g_freezetag_frozen_maxtime;
159 Freeze(self, 0, 1, TRUE);
161 freezetag_count_alive_players();
163 freezetag_Add_Score(attacker);
166 void freezetag_Unfreeze(entity attacker)
168 self.freezetag_frozen_time = 0;
169 self.freezetag_frozen_timeout = 0;
179 void() havocbot_role_ft_freeing;
180 void() havocbot_role_ft_offense;
182 void havocbot_goalrating_freeplayers(float ratingscale, vector org, float sradius)
187 FOR_EACH_PLAYER(head)
189 if ((head != self) && (head.team == self.team))
191 if (head.frozen == 1)
193 distance = vlen(head.origin - org);
194 if (distance > sradius)
196 navigation_routerating(head, ratingscale, 2000);
200 // If teamate is not frozen still seek them out as fight better
202 navigation_routerating(head, ratingscale/3, 2000);
208 void havocbot_role_ft_offense()
213 if(self.deadflag != DEAD_NO)
216 if (!self.havocbot_role_timeout)
217 self.havocbot_role_timeout = time + random() * 10 + 20;
219 // Count how many players on team are unfrozen.
221 FOR_EACH_PLAYER(head)
223 if ((head.team == self.team) && (head.frozen != 1))
227 // If only one left on team or if role has timed out then start trying to free players.
228 if (((unfrozen == 0) && (!self.frozen)) || (time > self.havocbot_role_timeout))
230 dprint("changing role to freeing\n");
231 self.havocbot_role = havocbot_role_ft_freeing;
232 self.havocbot_role_timeout = 0;
236 if (time > self.bot_strategytime)
238 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
240 navigation_goalrating_start();
241 havocbot_goalrating_items(10000, self.origin, 10000);
242 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
243 havocbot_goalrating_freeplayers(9000, self.origin, 10000);
244 //havocbot_goalrating_waypoints(1, self.origin, 1000);
245 navigation_goalrating_end();
249 void havocbot_role_ft_freeing()
251 if(self.deadflag != DEAD_NO)
254 if (!self.havocbot_role_timeout)
255 self.havocbot_role_timeout = time + random() * 10 + 20;
257 if (time > self.havocbot_role_timeout)
259 dprint("changing role to offense\n");
260 self.havocbot_role = havocbot_role_ft_offense;
261 self.havocbot_role_timeout = 0;
265 if (time > self.bot_strategytime)
267 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
269 navigation_goalrating_start();
270 havocbot_goalrating_items(8000, self.origin, 10000);
271 havocbot_goalrating_enemyplayers(10000, self.origin, 10000);
272 havocbot_goalrating_freeplayers(20000, self.origin, 10000);
273 //havocbot_goalrating_waypoints(1, self.origin, 1000);
274 navigation_goalrating_end();
283 MUTATOR_HOOKFUNCTION(freezetag_RemovePlayer)
285 self.health = 0; // neccessary to update correctly alive stats
286 freezetag_Unfreeze(world);
287 freezetag_count_alive_players();
291 MUTATOR_HOOKFUNCTION(freezetag_PlayerDies)
293 if(round_handler_IsActive())
294 if(round_handler_CountdownRunning())
297 freezetag_Unfreeze(world);
298 freezetag_count_alive_players();
299 return 1; // let the player die so that he can respawn whenever he wants
302 // Cases DEATH_TEAMCHANGE and DEATH_AUTOTEAMCHANGE are needed to fix a bug whe
303 // you succeed changing team through the menu: you both really die (gibbing) and get frozen
304 if(ITEM_DAMAGE_NEEDKILL(frag_deathtype)
305 || frag_deathtype == DEATH_TEAMCHANGE || frag_deathtype == DEATH_AUTOTEAMCHANGE)
307 // let the player die, he will be automatically frozen when he respawns
310 freezetag_Add_Score(frag_attacker);
311 freezetag_count_alive_players();
314 freezetag_Unfreeze(world); // remove ice
315 self.health = 0; // Unfreeze resets health
316 self.freezetag_frozen_timeout = -2; // freeze on respawn
323 freezetag_Freeze(frag_attacker);
325 if(frag_attacker == frag_target || frag_attacker == world)
327 if(IS_PLAYER(frag_target))
328 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_SELF);
329 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_SELF, frag_target.netname);
333 if(IS_PLAYER(frag_target))
334 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_FROZEN, frag_attacker.netname);
335 if(IS_PLAYER(frag_attacker))
336 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_FREEZETAG_FREEZE, frag_target.netname);
337 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_FREEZE, frag_target.netname, frag_attacker.netname);
343 MUTATOR_HOOKFUNCTION(freezetag_PlayerSpawn)
345 if(self.freezetag_frozen_timeout == -1) // if PlayerSpawn is called by reset_map_players
346 return 1; // do nothing, round is starting right now
348 if(self.freezetag_frozen_timeout == -2) // player was dead
350 freezetag_Freeze(world);
354 freezetag_count_alive_players();
356 if(round_handler_IsActive())
357 if(round_handler_IsRoundStarted())
359 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
360 freezetag_Freeze(world);
366 MUTATOR_HOOKFUNCTION(freezetag_reset_map_players)
368 FOR_EACH_PLAYER(self)
371 self.freezetag_frozen_timeout = -1;
373 self.freezetag_frozen_timeout = 0;
375 freezetag_count_alive_players();
379 MUTATOR_HOOKFUNCTION(freezetag_GiveFragsForKill)
381 frag_score = 0; // no frags counted in Freeze Tag
385 .float reviving; // temp var
386 MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink)
396 self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
399 if(round_handler_IsActive())
400 if(!round_handler_IsRoundStarted())
406 //if(self.freezetag_frozen_timeout > 0 && time < self.freezetag_frozen_timeout)
407 //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);
409 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
413 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
415 FOR_EACH_PLAYER(other)
417 if(other.frozen == 0)
418 if(other.deadflag == DEAD_NO)
419 if(SAME_TEAM(other, self))
420 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
425 other.reviving = TRUE;
430 if(n && self.frozen == 1) // OK, there is at least one teammate reviving us
432 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
433 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
435 if(self.revive_progress >= 1)
437 freezetag_Unfreeze(self);
438 freezetag_count_alive_players();
442 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_AUTO_REVIVED, autocvar_g_freezetag_frozen_maxtime);
443 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_AUTO_REVIVED, self.netname, autocvar_g_freezetag_frozen_maxtime);
447 // EVERY team mate nearby gets a point (even if multiple!)
448 FOR_EACH_PLAYER(other)
452 PlayerScore_Add(other, SP_FREEZETAG_REVIVALS, +1);
453 PlayerScore_Add(other, SP_SCORE, +1);
455 nades_GiveBonus(other,autocvar_g_nades_bonus_score_low);
459 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
460 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
461 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED, self.netname, o.netname);
464 FOR_EACH_PLAYER(other)
468 other.revive_progress = self.revive_progress;
469 other.reviving = FALSE;
473 else if(!n && self.frozen == 1) // only if no teammate is nearby will we reset
475 self.revive_progress = bound(0, self.revive_progress - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
476 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
478 else if(!n && !self.frozen)
480 self.revive_progress = 0; // thawing nobody
486 MUTATOR_HOOKFUNCTION(freezetag_BotRoles)
491 self.havocbot_role = havocbot_role_ft_freeing;
493 self.havocbot_role = havocbot_role_ft_offense;
499 MUTATOR_HOOKFUNCTION(freezetag_GetTeamCount)
501 ret_float = freezetag_teams;
505 void freezetag_Initialize()
507 freezetag_teams = autocvar_g_freezetag_teams_override;
508 if(freezetag_teams < 2)
509 freezetag_teams = autocvar_g_freezetag_teams;
510 freezetag_teams = bound(2, freezetag_teams, 4);
511 freezetag_ScoreRules(freezetag_teams);
513 round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null);
514 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
516 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
517 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
518 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
519 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
522 MUTATOR_DEFINITION(gamemode_freezetag)
524 MUTATOR_HOOK(MakePlayerObserver, freezetag_RemovePlayer, CBC_ORDER_ANY);
525 MUTATOR_HOOK(ClientDisconnect, freezetag_RemovePlayer, CBC_ORDER_ANY);
526 MUTATOR_HOOK(PlayerDies, freezetag_PlayerDies, CBC_ORDER_ANY);
527 MUTATOR_HOOK(PlayerSpawn, freezetag_PlayerSpawn, CBC_ORDER_ANY);
528 MUTATOR_HOOK(reset_map_players, freezetag_reset_map_players, CBC_ORDER_ANY);
529 MUTATOR_HOOK(GiveFragsForKill, freezetag_GiveFragsForKill, CBC_ORDER_FIRST);
530 MUTATOR_HOOK(PlayerPreThink, freezetag_PlayerPreThink, CBC_ORDER_FIRST);
531 MUTATOR_HOOK(HavocBot_ChooseRole, freezetag_BotRoles, CBC_ORDER_ANY);
532 MUTATOR_HOOK(GetTeamCount, freezetag_GetTeamCount, CBC_ORDER_EXCLUSIVE);
536 if(time > 1) // game loads at time 1
537 error("This is a game type and it cannot be added at runtime.");
538 freezetag_Initialize();
541 MUTATOR_ONROLLBACK_OR_REMOVE
543 // we actually cannot roll back freezetag_Initialize here
544 // BUT: we don't need to! If this gets called, adding always
550 print("This is a game type and it cannot be removed at runtime.");