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_missing_teams_mask;
34 float freezetag_CheckTeams()
36 if(FREEZETAG_ALIVE_TEAMS_OK())
38 if(prev_missing_teams_mask > 0)
39 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
40 prev_missing_teams_mask = -1;
43 if(total_players == 0)
45 if(prev_missing_teams_mask > 0)
46 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
47 prev_missing_teams_mask = -1;
50 float missing_teams_mask = (!redalive) + (!bluealive) * 2;
51 if(freezetag_teams >= 3) missing_teams_mask += (!yellowalive) * 4;
52 if(freezetag_teams >= 4) missing_teams_mask += (!pinkalive) * 8;
53 if(prev_missing_teams_mask != missing_teams_mask)
55 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
56 prev_missing_teams_mask = missing_teams_mask;
61 float freezetag_getWinnerTeam()
63 float winner_team = 0;
65 winner_team = NUM_TEAM_1;
68 if(winner_team) return 0;
69 winner_team = NUM_TEAM_2;
73 if(winner_team) return 0;
74 winner_team = NUM_TEAM_3;
78 if(winner_team) return 0;
79 winner_team = NUM_TEAM_4;
83 return -1; // no player left
86 float freezetag_CheckWinner()
89 if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
91 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
92 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
95 e.freezetag_frozen_timeout = 0;
98 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
102 if(FREEZETAG_ALIVE_TEAMS() > 1)
106 winner_team = freezetag_getWinnerTeam();
109 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
110 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
111 TeamScore_AddToTeam(winner_team, ST_SCORE, +1);
113 else if(winner_team == -1)
115 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
116 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
121 e.freezetag_frozen_timeout = 0;
124 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
128 entity freezetag_LastPlayerForTeam()
130 entity pl, last_pl = world;
136 if(pl.team == self.team)
145 void freezetag_LastPlayerForTeam_Notify()
147 if(round_handler_IsActive())
148 if(round_handler_IsRoundStarted())
150 entity pl = freezetag_LastPlayerForTeam();
152 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
156 void freezetag_Add_Score(entity attacker)
160 // you froze your own dumb self
161 // counted as "suicide" already
162 PlayerScore_Add(self, SP_SCORE, -1);
164 else if(IS_PLAYER(attacker))
166 // got frozen by an enemy
167 // counted as "kill" and "death" already
168 PlayerScore_Add(self, SP_SCORE, -1);
169 PlayerScore_Add(attacker, SP_SCORE, +1);
171 // else nothing - got frozen by the game type rules themselves
174 void freezetag_Freeze(entity attacker)
179 if(autocvar_g_freezetag_frozen_maxtime > 0)
180 self.freezetag_frozen_timeout = time + autocvar_g_freezetag_frozen_maxtime;
182 Freeze(self, 0, 1, TRUE);
184 freezetag_count_alive_players();
186 freezetag_Add_Score(attacker);
189 void freezetag_Unfreeze(entity attacker)
191 self.freezetag_frozen_time = 0;
192 self.freezetag_frozen_timeout = 0;
202 void() havocbot_role_ft_freeing;
203 void() havocbot_role_ft_offense;
205 void havocbot_goalrating_freeplayers(float ratingscale, vector org, float sradius)
210 FOR_EACH_PLAYER(head)
212 if ((head != self) && (head.team == self.team))
214 if (head.frozen == 1)
216 distance = vlen(head.origin - org);
217 if (distance > sradius)
219 navigation_routerating(head, ratingscale, 2000);
223 // If teamate is not frozen still seek them out as fight better
225 navigation_routerating(head, ratingscale/3, 2000);
231 void havocbot_role_ft_offense()
236 if(self.deadflag != DEAD_NO)
239 if (!self.havocbot_role_timeout)
240 self.havocbot_role_timeout = time + random() * 10 + 20;
242 // Count how many players on team are unfrozen.
244 FOR_EACH_PLAYER(head)
246 if ((head.team == self.team) && (head.frozen != 1))
250 // If only one left on team or if role has timed out then start trying to free players.
251 if (((unfrozen == 0) && (!self.frozen)) || (time > self.havocbot_role_timeout))
253 dprint("changing role to freeing\n");
254 self.havocbot_role = havocbot_role_ft_freeing;
255 self.havocbot_role_timeout = 0;
259 if (time > self.bot_strategytime)
261 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
263 navigation_goalrating_start();
264 havocbot_goalrating_items(10000, self.origin, 10000);
265 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
266 havocbot_goalrating_freeplayers(9000, self.origin, 10000);
267 //havocbot_goalrating_waypoints(1, self.origin, 1000);
268 navigation_goalrating_end();
272 void havocbot_role_ft_freeing()
274 if(self.deadflag != DEAD_NO)
277 if (!self.havocbot_role_timeout)
278 self.havocbot_role_timeout = time + random() * 10 + 20;
280 if (time > self.havocbot_role_timeout)
282 dprint("changing role to offense\n");
283 self.havocbot_role = havocbot_role_ft_offense;
284 self.havocbot_role_timeout = 0;
288 if (time > self.bot_strategytime)
290 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
292 navigation_goalrating_start();
293 havocbot_goalrating_items(8000, self.origin, 10000);
294 havocbot_goalrating_enemyplayers(10000, self.origin, 10000);
295 havocbot_goalrating_freeplayers(20000, self.origin, 10000);
296 //havocbot_goalrating_waypoints(1, self.origin, 1000);
297 navigation_goalrating_end();
306 MUTATOR_HOOKFUNCTION(freezetag_RemovePlayer)
308 self.health = 0; // neccessary to update correctly alive stats
310 freezetag_LastPlayerForTeam_Notify();
311 freezetag_Unfreeze(world);
312 freezetag_count_alive_players();
316 MUTATOR_HOOKFUNCTION(freezetag_PlayerDies)
318 if(round_handler_IsActive())
319 if(round_handler_CountdownRunning())
322 freezetag_Unfreeze(world);
323 freezetag_count_alive_players();
324 return 1; // let the player die so that he can respawn whenever he wants
327 // Cases DEATH_TEAMCHANGE and DEATH_AUTOTEAMCHANGE are needed to fix a bug whe
328 // you succeed changing team through the menu: you both really die (gibbing) and get frozen
329 if(ITEM_DAMAGE_NEEDKILL(frag_deathtype)
330 || frag_deathtype == DEATH_TEAMCHANGE || frag_deathtype == DEATH_AUTOTEAMCHANGE)
332 // let the player die, he will be automatically frozen when he respawns
335 freezetag_Add_Score(frag_attacker);
336 freezetag_count_alive_players();
337 freezetag_LastPlayerForTeam_Notify();
340 freezetag_Unfreeze(world); // remove ice
341 self.health = 0; // Unfreeze resets health
342 self.freezetag_frozen_timeout = -2; // freeze on respawn
349 freezetag_Freeze(frag_attacker);
350 freezetag_LastPlayerForTeam_Notify();
352 if(frag_attacker == frag_target || frag_attacker == world)
354 if(IS_PLAYER(frag_target))
355 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_SELF);
356 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_SELF, frag_target.netname);
360 if(IS_PLAYER(frag_target))
361 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_FROZEN, frag_attacker.netname);
362 if(IS_PLAYER(frag_attacker))
363 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_FREEZETAG_FREEZE, frag_target.netname);
364 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_FREEZE, frag_target.netname, frag_attacker.netname);
370 MUTATOR_HOOKFUNCTION(freezetag_PlayerSpawn)
372 if(self.freezetag_frozen_timeout == -1) // if PlayerSpawn is called by reset_map_players
373 return 1; // do nothing, round is starting right now
375 if(self.freezetag_frozen_timeout == -2) // player was dead
377 freezetag_Freeze(world);
381 freezetag_count_alive_players();
383 if(round_handler_IsActive())
384 if(round_handler_IsRoundStarted())
386 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
387 freezetag_Freeze(world);
393 MUTATOR_HOOKFUNCTION(freezetag_reset_map_players)
395 FOR_EACH_PLAYER(self)
398 self.freezetag_frozen_timeout = -1;
400 self.freezetag_frozen_timeout = 0;
402 freezetag_count_alive_players();
406 MUTATOR_HOOKFUNCTION(freezetag_GiveFragsForKill)
408 frag_score = 0; // no frags counted in Freeze Tag
412 .float reviving; // temp var
413 MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink)
423 self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
426 if(round_handler_IsActive())
427 if(!round_handler_IsRoundStarted())
433 //if(self.freezetag_frozen_timeout > 0 && time < self.freezetag_frozen_timeout)
434 //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);
436 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
440 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
442 FOR_EACH_PLAYER(other)
444 if(other.frozen == 0)
445 if(other.deadflag == DEAD_NO)
446 if(SAME_TEAM(other, self))
447 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
452 other.reviving = TRUE;
457 if(n && self.frozen == 1) // OK, there is at least one teammate reviving us
459 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
460 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
462 if(self.revive_progress >= 1)
464 freezetag_Unfreeze(self);
465 freezetag_count_alive_players();
469 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_AUTO_REVIVED, autocvar_g_freezetag_frozen_maxtime);
470 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_AUTO_REVIVED, self.netname, autocvar_g_freezetag_frozen_maxtime);
474 // EVERY team mate nearby gets a point (even if multiple!)
475 FOR_EACH_PLAYER(other)
479 PlayerScore_Add(other, SP_FREEZETAG_REVIVALS, +1);
480 PlayerScore_Add(other, SP_SCORE, +1);
482 nades_GiveBonus(other,autocvar_g_nades_bonus_score_low);
486 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
487 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
488 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED, self.netname, o.netname);
491 FOR_EACH_PLAYER(other)
495 other.revive_progress = self.revive_progress;
496 other.reviving = FALSE;
500 else if(!n && self.frozen == 1) // only if no teammate is nearby will we reset
502 self.revive_progress = bound(0, self.revive_progress - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
503 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
505 else if(!n && !self.frozen)
507 self.revive_progress = 0; // thawing nobody
513 MUTATOR_HOOKFUNCTION(freezetag_BotRoles)
518 self.havocbot_role = havocbot_role_ft_freeing;
520 self.havocbot_role = havocbot_role_ft_offense;
526 MUTATOR_HOOKFUNCTION(freezetag_GetTeamCount)
528 ret_float = freezetag_teams;
532 void freezetag_Initialize()
534 freezetag_teams = autocvar_g_freezetag_teams_override;
535 if(freezetag_teams < 2)
536 freezetag_teams = autocvar_g_freezetag_teams;
537 freezetag_teams = bound(2, freezetag_teams, 4);
538 ScoreRules_freezetag(freezetag_teams);
540 round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null);
541 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
543 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
544 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
545 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
546 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
549 MUTATOR_DEFINITION(gamemode_freezetag)
551 MUTATOR_HOOK(MakePlayerObserver, freezetag_RemovePlayer, CBC_ORDER_ANY);
552 MUTATOR_HOOK(ClientDisconnect, freezetag_RemovePlayer, CBC_ORDER_ANY);
553 MUTATOR_HOOK(PlayerDies, freezetag_PlayerDies, CBC_ORDER_ANY);
554 MUTATOR_HOOK(PlayerSpawn, freezetag_PlayerSpawn, CBC_ORDER_ANY);
555 MUTATOR_HOOK(reset_map_players, freezetag_reset_map_players, CBC_ORDER_ANY);
556 MUTATOR_HOOK(GiveFragsForKill, freezetag_GiveFragsForKill, CBC_ORDER_FIRST);
557 MUTATOR_HOOK(PlayerPreThink, freezetag_PlayerPreThink, CBC_ORDER_FIRST);
558 MUTATOR_HOOK(HavocBot_ChooseRole, freezetag_BotRoles, CBC_ORDER_ANY);
559 MUTATOR_HOOK(GetTeamCount, freezetag_GetTeamCount, CBC_ORDER_EXCLUSIVE);
563 if(time > 1) // game loads at time 1
564 error("This is a game type and it cannot be added at runtime.");
565 freezetag_Initialize();
568 MUTATOR_ONROLLBACK_OR_REMOVE
570 // we actually cannot roll back freezetag_Initialize here
571 // BUT: we don't need to! If this gets called, adding always
577 print("This is a game type and it cannot be removed at runtime.");