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;
16 case NUM_TEAM_1: ++total_players; if(e.health >= 1 && e.frozen != 1) ++redalive; break;
17 case NUM_TEAM_2: ++total_players; if(e.health >= 1 && e.frozen != 1) ++bluealive; break;
18 case NUM_TEAM_3: ++total_players; if(e.health >= 1 && e.frozen != 1) ++yellowalive; break;
19 case NUM_TEAM_4: ++total_players; if(e.health >= 1 && e.frozen != 1) ++pinkalive; break;
22 FOR_EACH_REALCLIENT(e)
24 e.redalive_stat = redalive;
25 e.bluealive_stat = bluealive;
26 e.yellowalive_stat = yellowalive;
27 e.pinkalive_stat = pinkalive;
30 #define FREEZETAG_ALIVE_TEAMS() ((redalive > 0) + (bluealive > 0) + (yellowalive > 0) + (pinkalive > 0))
31 #define FREEZETAG_ALIVE_TEAMS_OK() (FREEZETAG_ALIVE_TEAMS() == freezetag_teams)
33 float prev_total_players;
34 float freezetag_CheckTeams()
36 if(FREEZETAG_ALIVE_TEAMS_OK())
38 if(prev_total_players > 0)
39 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
40 prev_total_players = -1;
43 if(prev_total_players != total_players)
45 float p1 = 0, p2 = 0, p3 = 0, p4 = 0;
46 if(!redalive) p1 = NUM_TEAM_1;
47 if(!bluealive) p2 = NUM_TEAM_2;
48 if(freezetag_teams >= 3)
49 if(!yellowalive) p3 = NUM_TEAM_3;
50 if(freezetag_teams >= 4)
51 if(!pinkalive) p4 = NUM_TEAM_4;
52 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, p1, p2, p3, p4);
53 prev_total_players = total_players;
58 float freezetag_getWinnerTeam()
60 float winner_team = 0;
62 winner_team = NUM_TEAM_1;
65 if(winner_team) return 0;
66 winner_team = NUM_TEAM_2;
70 if(winner_team) return 0;
71 winner_team = NUM_TEAM_3;
75 if(winner_team) return 0;
76 winner_team = NUM_TEAM_4;
80 return -1; // no player left
83 float freezetag_CheckWinner()
86 if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
88 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
89 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
92 e.freezetag_frozen_timeout = 0;
95 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
99 if(FREEZETAG_ALIVE_TEAMS() > 1)
103 winner_team = freezetag_getWinnerTeam();
106 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
107 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
108 TeamScore_AddToTeam(winner_team, ST_SCORE, +1);
110 else if(winner_team == -1)
112 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
113 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
118 e.freezetag_frozen_timeout = 0;
121 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
125 void freezetag_Add_Score(entity attacker)
129 // you froze your own dumb self
130 // counted as "suicide" already
131 PlayerScore_Add(self, SP_SCORE, -1);
133 else if(IS_PLAYER(attacker))
135 // got frozen by an enemy
136 // counted as "kill" and "death" already
137 PlayerScore_Add(self, SP_SCORE, -1);
138 PlayerScore_Add(attacker, SP_SCORE, +1);
140 // else nothing - got frozen by the game type rules themselves
143 void freezetag_Freeze(entity attacker)
148 if(autocvar_g_freezetag_frozen_maxtime > 0)
149 self.freezetag_frozen_timeout = time + autocvar_g_freezetag_frozen_maxtime;
151 Freeze(self, 0, 1, TRUE);
153 freezetag_count_alive_players();
155 freezetag_Add_Score(attacker);
158 void freezetag_Unfreeze(entity attacker)
160 self.freezetag_frozen_time = 0;
161 self.freezetag_frozen_timeout = 0;
171 void() havocbot_role_ft_freeing;
172 void() havocbot_role_ft_offense;
174 void havocbot_goalrating_freeplayers(float ratingscale, vector org, float sradius)
179 FOR_EACH_PLAYER(head)
181 if ((head != self) && (head.team == self.team))
183 if (head.frozen == 1)
185 distance = vlen(head.origin - org);
186 if (distance > sradius)
188 navigation_routerating(head, ratingscale, 2000);
192 // If teamate is not frozen still seek them out as fight better
194 navigation_routerating(head, ratingscale/3, 2000);
200 void havocbot_role_ft_offense()
205 if(self.deadflag != DEAD_NO)
208 if (!self.havocbot_role_timeout)
209 self.havocbot_role_timeout = time + random() * 10 + 20;
211 // Count how many players on team are unfrozen.
213 FOR_EACH_PLAYER(head)
215 if ((head.team == self.team) && (head.frozen != 1))
219 // If only one left on team or if role has timed out then start trying to free players.
220 if (((unfrozen == 0) && (!self.frozen)) || (time > self.havocbot_role_timeout))
222 dprint("changing role to freeing\n");
223 self.havocbot_role = havocbot_role_ft_freeing;
224 self.havocbot_role_timeout = 0;
228 if (time > self.bot_strategytime)
230 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
232 navigation_goalrating_start();
233 havocbot_goalrating_items(10000, self.origin, 10000);
234 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
235 havocbot_goalrating_freeplayers(9000, self.origin, 10000);
236 //havocbot_goalrating_waypoints(1, self.origin, 1000);
237 navigation_goalrating_end();
241 void havocbot_role_ft_freeing()
243 if(self.deadflag != DEAD_NO)
246 if (!self.havocbot_role_timeout)
247 self.havocbot_role_timeout = time + random() * 10 + 20;
249 if (time > self.havocbot_role_timeout)
251 dprint("changing role to offense\n");
252 self.havocbot_role = havocbot_role_ft_offense;
253 self.havocbot_role_timeout = 0;
257 if (time > self.bot_strategytime)
259 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
261 navigation_goalrating_start();
262 havocbot_goalrating_items(8000, self.origin, 10000);
263 havocbot_goalrating_enemyplayers(10000, self.origin, 10000);
264 havocbot_goalrating_freeplayers(20000, self.origin, 10000);
265 //havocbot_goalrating_waypoints(1, self.origin, 1000);
266 navigation_goalrating_end();
275 MUTATOR_HOOKFUNCTION(freezetag_RemovePlayer)
277 self.health = 0; // neccessary to update correctly alive stats
278 freezetag_Unfreeze(world);
279 freezetag_count_alive_players();
283 MUTATOR_HOOKFUNCTION(freezetag_PlayerDies)
285 if(round_handler_IsActive())
286 if(round_handler_CountdownRunning())
289 freezetag_Unfreeze(world);
290 freezetag_count_alive_players();
291 return 1; // let the player die so that he can respawn whenever he wants
294 // Cases DEATH_TEAMCHANGE and DEATH_AUTOTEAMCHANGE are needed to fix a bug whe
295 // you succeed changing team through the menu: you both really die (gibbing) and get frozen
296 if(ITEM_DAMAGE_NEEDKILL(frag_deathtype)
297 || frag_deathtype == DEATH_TEAMCHANGE || frag_deathtype == DEATH_AUTOTEAMCHANGE)
299 // let the player die, he will be automatically frozen when he respawns
302 freezetag_Add_Score(frag_attacker);
303 freezetag_count_alive_players();
306 freezetag_Unfreeze(world); // remove ice
307 self.health = 0; // Unfreeze resets health
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 self.freezetag_frozen_timeout = -1;
365 self.freezetag_frozen_timeout = 0;
367 freezetag_count_alive_players();
371 MUTATOR_HOOKFUNCTION(freezetag_GiveFragsForKill)
373 frag_score = 0; // no frags counted in Freeze Tag
377 .float reviving; // temp var
378 MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink)
388 self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
391 if(round_handler_IsActive())
392 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)
409 if(other.frozen == 0)
410 if(other.deadflag == DEAD_NO)
411 if(SAME_TEAM(other, self))
412 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
417 other.reviving = TRUE;
422 if(n && self.frozen == 1) // OK, there is at least one teammate reviving us
424 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
425 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
427 if(self.revive_progress >= 1)
429 freezetag_Unfreeze(self);
430 freezetag_count_alive_players();
434 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_AUTO_REVIVED, autocvar_g_freezetag_frozen_maxtime);
435 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_AUTO_REVIVED, self.netname, autocvar_g_freezetag_frozen_maxtime);
439 // EVERY team mate nearby gets a point (even if multiple!)
440 FOR_EACH_PLAYER(other)
444 PlayerScore_Add(other, SP_FREEZETAG_REVIVALS, +1);
445 PlayerScore_Add(other, SP_SCORE, +1);
447 nades_GiveBonus(other,autocvar_g_nades_bonus_score_low);
451 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
452 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
453 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED, self.netname, o.netname);
456 FOR_EACH_PLAYER(other)
460 other.revive_progress = self.revive_progress;
461 other.reviving = FALSE;
465 else if(!n && self.frozen == 1) // only if no teammate is nearby will we reset
467 self.revive_progress = bound(0, self.revive_progress - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
468 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
470 else if(!n && !self.frozen)
472 self.revive_progress = 0; // thawing nobody
478 MUTATOR_HOOKFUNCTION(freezetag_BotRoles)
483 self.havocbot_role = havocbot_role_ft_freeing;
485 self.havocbot_role = havocbot_role_ft_offense;
491 MUTATOR_HOOKFUNCTION(freezetag_GetTeamCount)
493 ret_float = freezetag_teams;
497 void freezetag_Initialize()
499 freezetag_teams = autocvar_g_freezetag_teams_override;
500 if(freezetag_teams < 2)
501 freezetag_teams = autocvar_g_freezetag_teams;
502 freezetag_teams = bound(2, freezetag_teams, 4);
503 ScoreRules_freezetag(freezetag_teams);
505 round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null);
506 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
508 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
509 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
510 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
511 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
514 MUTATOR_DEFINITION(gamemode_freezetag)
516 MUTATOR_HOOK(MakePlayerObserver, freezetag_RemovePlayer, CBC_ORDER_ANY);
517 MUTATOR_HOOK(ClientDisconnect, freezetag_RemovePlayer, CBC_ORDER_ANY);
518 MUTATOR_HOOK(PlayerDies, freezetag_PlayerDies, CBC_ORDER_ANY);
519 MUTATOR_HOOK(PlayerSpawn, freezetag_PlayerSpawn, CBC_ORDER_ANY);
520 MUTATOR_HOOK(reset_map_players, freezetag_reset_map_players, CBC_ORDER_ANY);
521 MUTATOR_HOOK(GiveFragsForKill, freezetag_GiveFragsForKill, CBC_ORDER_FIRST);
522 MUTATOR_HOOK(PlayerPreThink, freezetag_PlayerPreThink, CBC_ORDER_FIRST);
523 MUTATOR_HOOK(HavocBot_ChooseRole, freezetag_BotRoles, CBC_ORDER_ANY);
524 MUTATOR_HOOK(GetTeamCount, freezetag_GetTeamCount, CBC_ORDER_EXCLUSIVE);
528 if(time > 1) // game loads at time 1
529 error("This is a game type and it cannot be added at runtime.");
530 freezetag_Initialize();
533 MUTATOR_ONROLLBACK_OR_REMOVE
535 // we actually cannot roll back freezetag_Initialize here
536 // BUT: we don't need to! If this gets called, adding always
542 print("This is a game type and it cannot be removed at runtime.");