1 .float freezetag_frozen_time;
2 .float freezetag_frozen_timeout;
3 .float freezetag_revive_progress;
5 #define ICE_MAX_ALPHA 1
6 #define ICE_MIN_ALPHA 0.1
9 void freezetag_count_alive_players()
12 total_players = redalive = bluealive = yellowalive = pinkalive = 0;
14 if(e.team == NUM_TEAM_1 && e.health >= 1)
17 if (!e.freezetag_frozen) ++redalive;
19 else if(e.team == NUM_TEAM_2 && e.health >= 1)
22 if (!e.freezetag_frozen) ++bluealive;
24 else if(e.team == NUM_TEAM_3 && e.health >= 1)
27 if (!e.freezetag_frozen) ++yellowalive;
29 else if(e.team == NUM_TEAM_4 && e.health >= 1)
32 if (!e.freezetag_frozen) ++pinkalive;
35 FOR_EACH_REALCLIENT(e) {
36 e.redalive_stat = redalive;
37 e.bluealive_stat = bluealive;
38 e.yellowalive_stat = yellowalive;
39 e.pinkalive_stat = pinkalive;
42 #define FREEZETAG_ALIVE_TEAMS() ((redalive > 0) + (bluealive > 0) + (yellowalive > 0) + (pinkalive > 0))
43 #define FREEZETAG_ALIVE_TEAMS_OK() (FREEZETAG_ALIVE_TEAMS() == freezetag_teams)
45 float prev_missing_teams_mask;
46 float freezetag_CheckTeams()
48 if(FREEZETAG_ALIVE_TEAMS_OK())
50 if(prev_missing_teams_mask > 0)
51 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
52 prev_missing_teams_mask = -1;
55 if(total_players == 0)
57 if(prev_missing_teams_mask > 0)
58 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
59 prev_missing_teams_mask = -1;
62 float missing_teams_mask = (!redalive) + (!bluealive) * 2;
63 if(freezetag_teams >= 3) missing_teams_mask += (!yellowalive) * 4;
64 if(freezetag_teams >= 4) missing_teams_mask += (!pinkalive) * 8;
65 if(prev_missing_teams_mask != missing_teams_mask)
67 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
68 prev_missing_teams_mask = missing_teams_mask;
73 float freezetag_getWinnerTeam()
75 float winner_team = 0;
77 winner_team = NUM_TEAM_1;
80 if(winner_team) return 0;
81 winner_team = NUM_TEAM_2;
85 if(winner_team) return 0;
86 winner_team = NUM_TEAM_3;
90 if(winner_team) return 0;
91 winner_team = NUM_TEAM_4;
95 return -1; // no player left
98 float freezetag_CheckWinner()
101 if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
103 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
104 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
107 e.freezetag_frozen_timeout = 0;
108 e.freezetag_revive_progress = 0;
110 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
114 if(FREEZETAG_ALIVE_TEAMS() > 1)
118 winner_team = freezetag_getWinnerTeam();
121 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
122 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
123 TeamScore_AddToTeam(winner_team, ST_SCORE, +1);
125 else if(winner_team == -1)
127 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
128 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
133 e.freezetag_frozen_timeout = 0;
134 e.freezetag_revive_progress = 0;
136 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
140 entity freezetag_LastPlayerForTeam()
142 entity pl, last_pl = world;
146 if(!pl.freezetag_frozen)
148 if(pl.team == self.team)
157 void freezetag_LastPlayerForTeam_Notify()
159 if(round_handler_IsActive())
160 if(round_handler_IsRoundStarted())
162 entity pl = freezetag_LastPlayerForTeam();
164 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
168 // this is needed to allow the player to turn his view around (fixangle can't
169 // be used to freeze his view, as that also changes the angles), while not
170 // turning that ice object with the player
171 void freezetag_Ice_Think()
173 setorigin(self, self.owner.origin - '0 0 16');
174 self.nextthink = time;
177 void freezetag_Add_Score(entity attacker)
181 // you froze your own dumb self
182 // counted as "suicide" already
183 PlayerScore_Add(self, SP_SCORE, -1);
185 else if(IS_PLAYER(attacker))
187 // got frozen by an enemy
188 // counted as "kill" and "death" already
189 PlayerScore_Add(self, SP_SCORE, -1);
190 PlayerScore_Add(attacker, SP_SCORE, +1);
192 // else nothing - got frozen by the game type rules themselves
195 void freezetag_Freeze(entity attacker)
197 if(self.freezetag_frozen)
199 self.freezetag_frozen = 1;
200 self.freezetag_frozen_time = time;
201 self.freezetag_revive_progress = 0;
203 if(autocvar_g_freezetag_frozen_maxtime > 0)
204 self.freezetag_frozen_timeout = time + autocvar_g_freezetag_frozen_maxtime;
206 freezetag_count_alive_players();
211 ice.classname = "freezetag_ice";
212 ice.think = freezetag_Ice_Think;
213 ice.nextthink = time;
214 ice.frame = floor(random() * 21); // ice model has 20 different looking frames
215 ice.alpha = ICE_MAX_ALPHA;
216 ice.colormod = Team_ColorRGB(self.team);
217 ice.glowmod = ice.colormod;
218 setmodel(ice, "models/ice/ice.md3");
220 self.freezetag_ice = ice;
222 RemoveGrapplingHook(self);
225 WaypointSprite_Spawn("freezetag_frozen", 0, 0, self, '0 0 64', world, self.team, self, waypointsprite_attached, TRUE, RADARICON_WAYPOINT, '0.25 0.90 1');
227 freezetag_Add_Score(attacker);
230 void freezetag_Unfreeze(entity attacker)
232 self.freezetag_frozen = 0;
233 self.freezetag_frozen_time = 0;
234 self.freezetag_frozen_timeout = 0;
235 self.freezetag_revive_progress = 0;
237 remove(self.freezetag_ice);
238 self.freezetag_ice = world;
240 if(self.waypointsprite_attached)
241 WaypointSprite_Kill(self.waypointsprite_attached);
249 void() havocbot_role_ft_freeing;
250 void() havocbot_role_ft_offense;
252 void havocbot_goalrating_freeplayers(float ratingscale, vector org, float sradius)
257 FOR_EACH_PLAYER(head)
259 if ((head != self) && (head.team == self.team))
261 if (head.freezetag_frozen)
263 distance = vlen(head.origin - org);
264 if (distance > sradius)
266 navigation_routerating(head, ratingscale, 2000);
270 // If teamate is not frozen still seek them out as fight better
272 navigation_routerating(head, ratingscale/3, 2000);
278 void havocbot_role_ft_offense()
283 if(self.deadflag != DEAD_NO)
286 if (!self.havocbot_role_timeout)
287 self.havocbot_role_timeout = time + random() * 10 + 20;
289 // Count how many players on team are unfrozen.
291 FOR_EACH_PLAYER(head)
293 if ((head.team == self.team) && (!head.freezetag_frozen))
297 // If only one left on team or if role has timed out then start trying to free players.
298 if (((unfrozen == 0) && (!self.freezetag_frozen)) || (time > self.havocbot_role_timeout))
300 dprint("changing role to freeing\n");
301 self.havocbot_role = havocbot_role_ft_freeing;
302 self.havocbot_role_timeout = 0;
306 if (time > self.bot_strategytime)
308 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
310 navigation_goalrating_start();
311 havocbot_goalrating_items(10000, self.origin, 10000);
312 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
313 havocbot_goalrating_freeplayers(9000, self.origin, 10000);
314 //havocbot_goalrating_waypoints(1, self.origin, 1000);
315 navigation_goalrating_end();
319 void havocbot_role_ft_freeing()
321 if(self.deadflag != DEAD_NO)
324 if (!self.havocbot_role_timeout)
325 self.havocbot_role_timeout = time + random() * 10 + 20;
327 if (time > self.havocbot_role_timeout)
329 dprint("changing role to offense\n");
330 self.havocbot_role = havocbot_role_ft_offense;
331 self.havocbot_role_timeout = 0;
335 if (time > self.bot_strategytime)
337 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
339 navigation_goalrating_start();
340 havocbot_goalrating_items(8000, self.origin, 10000);
341 havocbot_goalrating_enemyplayers(10000, self.origin, 10000);
342 havocbot_goalrating_freeplayers(20000, self.origin, 10000);
343 //havocbot_goalrating_waypoints(1, self.origin, 1000);
344 navigation_goalrating_end();
353 MUTATOR_HOOKFUNCTION(freezetag_RemovePlayer)
355 self.health = 0; // neccessary to update correctly alive stats
356 if(!self.freezetag_frozen)
357 freezetag_LastPlayerForTeam_Notify();
358 freezetag_Unfreeze(world);
359 freezetag_count_alive_players();
363 MUTATOR_HOOKFUNCTION(freezetag_PlayerDies)
365 if(round_handler_IsActive())
366 if(round_handler_CountdownRunning())
368 if(self.freezetag_frozen)
369 freezetag_Unfreeze(world);
370 freezetag_count_alive_players();
371 return 1; // let the player die so that he can respawn whenever he wants
374 // Cases DEATH_TEAMCHANGE and DEATH_AUTOTEAMCHANGE are needed to fix a bug whe
375 // you succeed changing team through the menu: you both really die (gibbing) and get frozen
376 if(ITEM_DAMAGE_NEEDKILL(frag_deathtype)
377 || frag_deathtype == DEATH_TEAMCHANGE || frag_deathtype == DEATH_AUTOTEAMCHANGE)
379 // let the player die, he will be automatically frozen when he respawns
380 if(!self.freezetag_frozen)
382 freezetag_Add_Score(frag_attacker);
383 freezetag_count_alive_players();
384 freezetag_LastPlayerForTeam_Notify();
387 freezetag_Unfreeze(world); // remove ice
388 self.freezetag_frozen_timeout = -2; // freeze on respawn
392 if(self.freezetag_frozen)
395 freezetag_Freeze(frag_attacker);
396 freezetag_LastPlayerForTeam_Notify();
398 if(frag_attacker == frag_target || frag_attacker == world)
400 if(IS_PLAYER(frag_target))
401 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_SELF);
402 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_SELF, frag_target.netname);
406 if(IS_PLAYER(frag_target))
407 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_FROZEN, frag_attacker.netname);
408 if(IS_PLAYER(frag_attacker))
409 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_FREEZETAG_FREEZE, frag_target.netname);
410 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_FREEZE, frag_target.netname, frag_attacker.netname);
413 frag_target.health = 1; // "respawn" the player :P
418 MUTATOR_HOOKFUNCTION(freezetag_PlayerSpawn)
420 if(self.freezetag_frozen_timeout == -1) // if PlayerSpawn is called by reset_map_players
421 return 1; // do nothing, round is starting right now
423 if(self.freezetag_frozen_timeout == -2) // player was dead
425 freezetag_Freeze(world);
429 freezetag_count_alive_players();
431 if(round_handler_IsActive())
432 if(round_handler_IsRoundStarted())
434 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
435 freezetag_Freeze(world);
441 MUTATOR_HOOKFUNCTION(freezetag_reset_map_players)
443 FOR_EACH_PLAYER(self)
446 if (self.freezetag_frozen)
447 freezetag_Unfreeze(world);
448 self.freezetag_frozen_timeout = -1;
450 self.freezetag_frozen_timeout = 0;
452 freezetag_count_alive_players();
456 MUTATOR_HOOKFUNCTION(freezetag_GiveFragsForKill)
458 frag_score = 0; // no frags counted in Freeze Tag
462 .float reviving; // temp var
463 MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink)
470 if(self.freezetag_frozen)
473 self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
476 if(round_handler_IsActive())
477 if(!round_handler_IsRoundStarted())
482 if(self.freezetag_frozen_timeout > 0 && time < self.freezetag_frozen_timeout)
483 self.freezetag_ice.alpha = ICE_MIN_ALPHA + (ICE_MAX_ALPHA - ICE_MIN_ALPHA) * (self.freezetag_frozen_timeout - time) / (self.freezetag_frozen_timeout - self.freezetag_frozen_time);
485 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
489 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
491 FOR_EACH_PLAYER(other) if(self != other)
493 if(other.freezetag_frozen == 0)
495 if(other.team == self.team)
497 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
501 if(self.freezetag_frozen)
502 other.reviving = TRUE;
510 if(n && self.freezetag_frozen) // OK, there is at least one teammate reviving us
512 self.freezetag_revive_progress = bound(0, self.freezetag_revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
514 self.health = max(1, self.freezetag_revive_progress * warmup_start_health);
516 self.health = max(1, self.freezetag_revive_progress * start_health);
518 if(self.freezetag_revive_progress >= 1)
520 freezetag_Unfreeze(self);
521 freezetag_count_alive_players();
525 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_AUTO_REVIVED, autocvar_g_freezetag_frozen_maxtime);
526 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_AUTO_REVIVED, self.netname, autocvar_g_freezetag_frozen_maxtime);
530 // EVERY team mate nearby gets a point (even if multiple!)
531 FOR_EACH_PLAYER(other)
535 PlayerScore_Add(other, SP_FREEZETAG_REVIVALS, +1);
536 PlayerScore_Add(other, SP_SCORE, +1);
540 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
541 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
542 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED, self.netname, o.netname);
545 FOR_EACH_PLAYER(other)
549 other.freezetag_revive_progress = self.freezetag_revive_progress;
550 other.reviving = FALSE;
554 else if(!n && self.freezetag_frozen) // only if no teammate is nearby will we reset
556 self.freezetag_revive_progress = bound(0, self.freezetag_revive_progress - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
558 self.health = max(1, self.freezetag_revive_progress * warmup_start_health);
560 self.health = max(1, self.freezetag_revive_progress * start_health);
564 self.freezetag_revive_progress = 0; // thawing nobody
570 MUTATOR_HOOKFUNCTION(freezetag_PlayerPhysics)
572 if(self.freezetag_frozen)
574 if(autocvar_sv_dodging_frozen && IS_REAL_CLIENT(self))
576 self.movement_x = bound(-5, self.movement_x, 5);
577 self.movement_y = bound(-5, self.movement_y, 5);
578 self.movement_z = bound(-5, self.movement_z, 5);
581 self.movement = '0 0 0';
583 self.disableclientprediction = 1;
588 MUTATOR_HOOKFUNCTION(freezetag_PlayerDamage_Calculate)
590 if(frag_target.freezetag_frozen && frag_deathtype != DEATH_HURTTRIGGER)
592 if(autocvar_g_freezetag_revive_falldamage > 0)
593 if(frag_deathtype == DEATH_FALL)
594 if(frag_damage >= autocvar_g_freezetag_revive_falldamage)
596 freezetag_Unfreeze(frag_target);
597 frag_target.health = autocvar_g_freezetag_revive_falldamage_health;
598 pointparticles(particleeffectnum("iceorglass"), frag_target.origin, '0 0 0', 3);
599 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED_FALL, frag_target.netname);
600 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_REVIVE_FALL);
604 frag_force = frag_force * autocvar_g_freezetag_frozen_force;
609 MUTATOR_HOOKFUNCTION(freezetag_PlayerJump)
611 if(self.freezetag_frozen)
612 return TRUE; // no jumping in freezetag when frozen
617 MUTATOR_HOOKFUNCTION(freezetag_ForbidThrowCurrentWeapon)
619 if (self.freezetag_frozen)
624 MUTATOR_HOOKFUNCTION(freezetag_ItemTouch)
626 if (other.freezetag_frozen)
627 return MUT_ITEMTOUCH_RETURN;
628 return MUT_ITEMTOUCH_CONTINUE;
631 MUTATOR_HOOKFUNCTION(freezetag_BotRoles)
636 self.havocbot_role = havocbot_role_ft_freeing;
638 self.havocbot_role = havocbot_role_ft_offense;
644 MUTATOR_HOOKFUNCTION(freezetag_SpectateCopy)
646 self.freezetag_frozen = other.freezetag_frozen;
647 self.freezetag_revive_progress = other.freezetag_revive_progress;
651 MUTATOR_HOOKFUNCTION(freezetag_GetTeamCount)
653 ret_float = freezetag_teams;
657 MUTATOR_HOOKFUNCTION(freezetag_VehicleTouch)
659 if(other.freezetag_frozen)
665 void freezetag_Initialize()
667 precache_model("models/ice/ice.md3");
669 freezetag_teams = autocvar_g_freezetag_teams_override;
670 if(freezetag_teams < 2)
671 freezetag_teams = autocvar_g_freezetag_teams;
672 freezetag_teams = bound(2, freezetag_teams, 4);
673 ScoreRules_freezetag(freezetag_teams);
675 round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null);
676 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
678 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
679 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
680 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
681 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
683 addstat(STAT_FROZEN, AS_INT, freezetag_frozen);
684 addstat(STAT_REVIVE_PROGRESS, AS_FLOAT, freezetag_revive_progress);
687 MUTATOR_DEFINITION(gamemode_freezetag)
689 MUTATOR_HOOK(MakePlayerObserver, freezetag_RemovePlayer, CBC_ORDER_ANY);
690 MUTATOR_HOOK(ClientDisconnect, freezetag_RemovePlayer, CBC_ORDER_ANY);
691 MUTATOR_HOOK(PlayerDies, freezetag_PlayerDies, CBC_ORDER_ANY);
692 MUTATOR_HOOK(PlayerSpawn, freezetag_PlayerSpawn, CBC_ORDER_ANY);
693 MUTATOR_HOOK(reset_map_players, freezetag_reset_map_players, CBC_ORDER_ANY);
694 MUTATOR_HOOK(GiveFragsForKill, freezetag_GiveFragsForKill, CBC_ORDER_FIRST);
695 MUTATOR_HOOK(PlayerPreThink, freezetag_PlayerPreThink, CBC_ORDER_FIRST);
696 MUTATOR_HOOK(PlayerPhysics, freezetag_PlayerPhysics, CBC_ORDER_FIRST);
697 MUTATOR_HOOK(PlayerDamage_Calculate, freezetag_PlayerDamage_Calculate, CBC_ORDER_ANY);
698 MUTATOR_HOOK(PlayerJump, freezetag_PlayerJump, CBC_ORDER_ANY);
699 MUTATOR_HOOK(ForbidThrowCurrentWeapon, freezetag_ForbidThrowCurrentWeapon, CBC_ORDER_ANY);
700 MUTATOR_HOOK(ItemTouch, freezetag_ItemTouch, CBC_ORDER_ANY);
701 MUTATOR_HOOK(HavocBot_ChooseRule, freezetag_BotRoles, CBC_ORDER_ANY);
702 MUTATOR_HOOK(SpectateCopy, freezetag_SpectateCopy, CBC_ORDER_ANY);
703 MUTATOR_HOOK(GetTeamCount, freezetag_GetTeamCount, CBC_ORDER_EXCLUSIVE);
704 MUTATOR_HOOK(VehicleTouch, freezetag_VehicleTouch, CBC_ORDER_ANY);
708 if(time > 1) // game loads at time 1
709 error("This is a game type and it cannot be added at runtime.");
710 freezetag_Initialize();
713 MUTATOR_ONROLLBACK_OR_REMOVE
715 // we actually cannot roll back freezetag_Initialize here
716 // BUT: we don't need to! If this gets called, adding always
722 print("This is a game type and it cannot be removed at runtime.");