1 .float freezetag_frozen_time;
2 .float freezetag_frozen_timeout;
3 const float ICE_MAX_ALPHA = 1;
4 const float ICE_MIN_ALPHA = 0.1;
7 const float SP_FREEZETAG_REVIVALS = 4;
8 void freezetag_ScoreRules(float teams)
10 ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, true); // SFL_SORT_PRIO_PRIMARY
11 ScoreInfo_SetLabel_PlayerScore(SP_FREEZETAG_REVIVALS, "revivals", 0);
12 ScoreRules_basics_end();
15 void freezetag_count_alive_players()
18 total_players = redalive = bluealive = yellowalive = pinkalive = 0;
23 case NUM_TEAM_1: ++total_players; if(e.health >= 1 && e.frozen != 1) ++redalive; break;
24 case NUM_TEAM_2: ++total_players; if(e.health >= 1 && e.frozen != 1) ++bluealive; break;
25 case NUM_TEAM_3: ++total_players; if(e.health >= 1 && e.frozen != 1) ++yellowalive; break;
26 case NUM_TEAM_4: ++total_players; if(e.health >= 1 && e.frozen != 1) ++pinkalive; break;
29 FOR_EACH_REALCLIENT(e)
31 e.redalive_stat = redalive;
32 e.bluealive_stat = bluealive;
33 e.yellowalive_stat = yellowalive;
34 e.pinkalive_stat = pinkalive;
37 eliminatedPlayers.SendFlags |= 1;
39 #define FREEZETAG_ALIVE_TEAMS() ((redalive > 0) + (bluealive > 0) + (yellowalive > 0) + (pinkalive > 0))
40 #define FREEZETAG_ALIVE_TEAMS_OK() (FREEZETAG_ALIVE_TEAMS() == freezetag_teams)
42 float freezetag_CheckTeams()
44 static float prev_missing_teams_mask;
45 if(FREEZETAG_ALIVE_TEAMS_OK())
47 if(prev_missing_teams_mask > 0)
48 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
49 prev_missing_teams_mask = -1;
52 if(total_players == 0)
54 if(prev_missing_teams_mask > 0)
55 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
56 prev_missing_teams_mask = -1;
59 float missing_teams_mask = (!redalive) + (!bluealive) * 2;
60 if(freezetag_teams >= 3) missing_teams_mask += (!yellowalive) * 4;
61 if(freezetag_teams >= 4) missing_teams_mask += (!pinkalive) * 8;
62 if(prev_missing_teams_mask != missing_teams_mask)
64 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
65 prev_missing_teams_mask = missing_teams_mask;
70 float freezetag_getWinnerTeam()
72 float winner_team = 0;
74 winner_team = NUM_TEAM_1;
77 if(winner_team) return 0;
78 winner_team = NUM_TEAM_2;
82 if(winner_team) return 0;
83 winner_team = NUM_TEAM_3;
87 if(winner_team) return 0;
88 winner_team = NUM_TEAM_4;
92 return -1; // no player left
95 float freezetag_CheckWinner()
98 if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
100 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
101 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
104 e.freezetag_frozen_timeout = 0;
107 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
111 if(FREEZETAG_ALIVE_TEAMS() > 1)
115 winner_team = freezetag_getWinnerTeam();
118 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
119 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
120 TeamScore_AddToTeam(winner_team, ST_SCORE, +1);
122 else if(winner_team == -1)
124 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
125 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
130 e.freezetag_frozen_timeout = 0;
133 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
137 entity freezetag_LastPlayerForTeam()
139 entity pl, last_pl = world;
145 if(pl.team == self.team)
154 void freezetag_LastPlayerForTeam_Notify()
156 if(round_handler_IsActive())
157 if(round_handler_IsRoundStarted())
159 entity pl = freezetag_LastPlayerForTeam();
161 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
165 void freezetag_Add_Score(entity attacker)
169 // you froze your own dumb self
170 // counted as "suicide" already
171 PlayerScore_Add(self, SP_SCORE, -1);
173 else if(IS_PLAYER(attacker))
175 // got frozen by an enemy
176 // counted as "kill" and "death" already
177 PlayerScore_Add(self, SP_SCORE, -1);
178 PlayerScore_Add(attacker, SP_SCORE, +1);
180 // else nothing - got frozen by the game type rules themselves
183 void freezetag_Freeze(entity attacker)
188 if(autocvar_g_freezetag_frozen_maxtime > 0)
189 self.freezetag_frozen_timeout = time + autocvar_g_freezetag_frozen_maxtime;
191 Freeze(self, 0, 1, true);
193 freezetag_count_alive_players();
195 freezetag_Add_Score(attacker);
198 void freezetag_Unfreeze(entity attacker)
200 self.freezetag_frozen_time = 0;
201 self.freezetag_frozen_timeout = 0;
206 float freezetag_isEliminated(entity e)
208 if(IS_PLAYER(e) && (e.frozen == 1 || e.deadflag != DEAD_NO))
218 void() havocbot_role_ft_freeing;
219 void() havocbot_role_ft_offense;
221 void havocbot_goalrating_freeplayers(float ratingscale, vector org, float sradius)
226 FOR_EACH_PLAYER(head)
228 if ((head != self) && (head.team == self.team))
230 if (head.frozen == 1)
232 distance = vlen(head.origin - org);
233 if (distance > sradius)
235 navigation_routerating(head, ratingscale, 2000);
239 // If teamate is not frozen still seek them out as fight better
241 navigation_routerating(head, ratingscale/3, 2000);
247 void havocbot_role_ft_offense()
252 if(self.deadflag != DEAD_NO)
255 if (!self.havocbot_role_timeout)
256 self.havocbot_role_timeout = time + random() * 10 + 20;
258 // Count how many players on team are unfrozen.
260 FOR_EACH_PLAYER(head)
262 if ((head.team == self.team) && (head.frozen != 1))
266 // If only one left on team or if role has timed out then start trying to free players.
267 if (((unfrozen == 0) && (!self.frozen)) || (time > self.havocbot_role_timeout))
269 dprint("changing role to freeing\n");
270 self.havocbot_role = havocbot_role_ft_freeing;
271 self.havocbot_role_timeout = 0;
275 if (time > self.bot_strategytime)
277 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
279 navigation_goalrating_start();
280 havocbot_goalrating_items(10000, self.origin, 10000);
281 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
282 havocbot_goalrating_freeplayers(9000, self.origin, 10000);
283 //havocbot_goalrating_waypoints(1, self.origin, 1000);
284 navigation_goalrating_end();
288 void havocbot_role_ft_freeing()
290 if(self.deadflag != DEAD_NO)
293 if (!self.havocbot_role_timeout)
294 self.havocbot_role_timeout = time + random() * 10 + 20;
296 if (time > self.havocbot_role_timeout)
298 dprint("changing role to offense\n");
299 self.havocbot_role = havocbot_role_ft_offense;
300 self.havocbot_role_timeout = 0;
304 if (time > self.bot_strategytime)
306 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
308 navigation_goalrating_start();
309 havocbot_goalrating_items(8000, self.origin, 10000);
310 havocbot_goalrating_enemyplayers(10000, self.origin, 10000);
311 havocbot_goalrating_freeplayers(20000, self.origin, 10000);
312 //havocbot_goalrating_waypoints(1, self.origin, 1000);
313 navigation_goalrating_end();
322 MUTATOR_HOOKFUNCTION(freezetag_RemovePlayer)
324 self.health = 0; // neccessary to update correctly alive stats
326 freezetag_LastPlayerForTeam_Notify();
327 freezetag_Unfreeze(world);
328 freezetag_count_alive_players();
332 MUTATOR_HOOKFUNCTION(freezetag_PlayerDies)
334 if(round_handler_IsActive())
335 if(round_handler_CountdownRunning())
338 freezetag_Unfreeze(world);
339 freezetag_count_alive_players();
340 return 1; // let the player die so that he can respawn whenever he wants
343 // Cases DEATH_TEAMCHANGE and DEATH_AUTOTEAMCHANGE are needed to fix a bug whe
344 // you succeed changing team through the menu: you both really die (gibbing) and get frozen
345 if(ITEM_DAMAGE_NEEDKILL(frag_deathtype)
346 || frag_deathtype == DEATH_TEAMCHANGE || frag_deathtype == DEATH_AUTOTEAMCHANGE)
348 // let the player die, he will be automatically frozen when he respawns
351 freezetag_Add_Score(frag_attacker);
352 freezetag_count_alive_players();
353 freezetag_LastPlayerForTeam_Notify();
356 freezetag_Unfreeze(world); // remove ice
357 self.health = 0; // Unfreeze resets health
358 self.freezetag_frozen_timeout = -2; // freeze on respawn
365 freezetag_Freeze(frag_attacker);
366 freezetag_LastPlayerForTeam_Notify();
368 if(frag_attacker == frag_target || frag_attacker == world)
370 if(IS_PLAYER(frag_target))
371 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_SELF);
372 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_SELF, frag_target.netname);
376 if(IS_PLAYER(frag_target))
377 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_FROZEN, frag_attacker.netname);
378 if(IS_PLAYER(frag_attacker))
379 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_FREEZETAG_FREEZE, frag_target.netname);
380 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_FREEZE, frag_target.netname, frag_attacker.netname);
386 MUTATOR_HOOKFUNCTION(freezetag_PlayerSpawn)
388 if(self.freezetag_frozen_timeout == -1) // if PlayerSpawn is called by reset_map_players
389 return 1; // do nothing, round is starting right now
391 if(self.freezetag_frozen_timeout == -2) // player was dead
393 freezetag_Freeze(world);
397 freezetag_count_alive_players();
399 if(round_handler_IsActive())
400 if(round_handler_IsRoundStarted())
402 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
403 freezetag_Freeze(world);
409 MUTATOR_HOOKFUNCTION(freezetag_reset_map_players)
411 FOR_EACH_PLAYER(self)
414 self.freezetag_frozen_timeout = -1;
416 self.freezetag_frozen_timeout = 0;
418 freezetag_count_alive_players();
422 MUTATOR_HOOKFUNCTION(freezetag_GiveFragsForKill)
424 frag_score = 0; // no frags counted in Freeze Tag
428 .float reviving; // temp var
429 MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink)
439 self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
442 if(round_handler_IsActive())
443 if(!round_handler_IsRoundStarted())
449 //if(self.freezetag_frozen_timeout > 0 && time < self.freezetag_frozen_timeout)
450 //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);
452 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
456 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
458 FOR_EACH_PLAYER(other)
460 if(other.frozen == 0)
461 if(other.deadflag == DEAD_NO)
462 if(SAME_TEAM(other, self))
463 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
468 other.reviving = true;
473 if(n && self.frozen == 1) // OK, there is at least one teammate reviving us
475 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
476 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
478 if(self.revive_progress >= 1)
480 freezetag_Unfreeze(self);
481 freezetag_count_alive_players();
485 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_AUTO_REVIVED, autocvar_g_freezetag_frozen_maxtime);
486 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_AUTO_REVIVED, self.netname, autocvar_g_freezetag_frozen_maxtime);
490 // EVERY team mate nearby gets a point (even if multiple!)
491 FOR_EACH_PLAYER(other)
495 PlayerScore_Add(other, SP_FREEZETAG_REVIVALS, +1);
496 PlayerScore_Add(other, SP_SCORE, +1);
498 nades_GiveBonus(other,autocvar_g_nades_bonus_score_low);
502 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
503 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
504 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED, self.netname, o.netname);
507 FOR_EACH_PLAYER(other)
511 other.revive_progress = self.revive_progress;
512 other.reviving = false;
516 else if(!n && self.frozen == 1) // only if no teammate is nearby will we reset
518 self.revive_progress = bound(0, self.revive_progress - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
519 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
521 else if(!n && !self.frozen)
523 self.revive_progress = 0; // thawing nobody
529 MUTATOR_HOOKFUNCTION(freezetag_BotRoles)
534 self.havocbot_role = havocbot_role_ft_freeing;
536 self.havocbot_role = havocbot_role_ft_offense;
542 MUTATOR_HOOKFUNCTION(freezetag_GetTeamCount)
544 ret_float = freezetag_teams;
548 void freezetag_Initialize()
550 freezetag_teams = autocvar_g_freezetag_teams_override;
551 if(freezetag_teams < 2)
552 freezetag_teams = autocvar_g_freezetag_teams;
553 freezetag_teams = bound(2, freezetag_teams, 4);
554 freezetag_ScoreRules(freezetag_teams);
556 round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null);
557 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
559 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
560 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
561 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
562 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
564 EliminatedPlayers_Init(freezetag_isEliminated);
567 MUTATOR_DEFINITION(gamemode_freezetag)
569 MUTATOR_HOOK(MakePlayerObserver, freezetag_RemovePlayer, CBC_ORDER_ANY);
570 MUTATOR_HOOK(ClientDisconnect, freezetag_RemovePlayer, CBC_ORDER_ANY);
571 MUTATOR_HOOK(PlayerDies, freezetag_PlayerDies, CBC_ORDER_ANY);
572 MUTATOR_HOOK(PlayerSpawn, freezetag_PlayerSpawn, CBC_ORDER_ANY);
573 MUTATOR_HOOK(reset_map_players, freezetag_reset_map_players, CBC_ORDER_ANY);
574 MUTATOR_HOOK(GiveFragsForKill, freezetag_GiveFragsForKill, CBC_ORDER_FIRST);
575 MUTATOR_HOOK(PlayerPreThink, freezetag_PlayerPreThink, CBC_ORDER_FIRST);
576 MUTATOR_HOOK(HavocBot_ChooseRole, freezetag_BotRoles, CBC_ORDER_ANY);
577 MUTATOR_HOOK(GetTeamCount, freezetag_GetTeamCount, CBC_ORDER_EXCLUSIVE);
581 if(time > 1) // game loads at time 1
582 error("This is a game type and it cannot be added at runtime.");
583 freezetag_Initialize();
586 MUTATOR_ONROLLBACK_OR_REMOVE
588 // we actually cannot roll back freezetag_Initialize here
589 // BUT: we don't need to! If this gets called, adding always
595 print("This is a game type and it cannot be removed at runtime.");