1 #include "gamemode_freezetag.qh"
6 const float SP_FREEZETAG_REVIVALS = 4;
7 void freezetag_ScoreRules(float teams)
9 ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, true); // SFL_SORT_PRIO_PRIMARY
10 ScoreInfo_SetLabel_PlayerScore(SP_FREEZETAG_REVIVALS, "revivals", 0);
11 ScoreRules_basics_end();
14 void freezetag_count_alive_players()
17 total_players = redalive = bluealive = yellowalive = pinkalive = 0;
22 case NUM_TEAM_1: ++total_players; if(e.health >= 1 && e.frozen != 1) ++redalive; break;
23 case NUM_TEAM_2: ++total_players; if(e.health >= 1 && e.frozen != 1) ++bluealive; break;
24 case NUM_TEAM_3: ++total_players; if(e.health >= 1 && e.frozen != 1) ++yellowalive; break;
25 case NUM_TEAM_4: ++total_players; if(e.health >= 1 && e.frozen != 1) ++pinkalive; break;
28 FOR_EACH_REALCLIENT(e)
30 e.redalive_stat = redalive;
31 e.bluealive_stat = bluealive;
32 e.yellowalive_stat = yellowalive;
33 e.pinkalive_stat = pinkalive;
36 eliminatedPlayers.SendFlags |= 1;
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 freezetag_CheckTeams()
43 static float prev_missing_teams_mask;
44 if(FREEZETAG_ALIVE_TEAMS_OK())
46 if(prev_missing_teams_mask > 0)
47 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
48 prev_missing_teams_mask = -1;
51 if(total_players == 0)
53 if(prev_missing_teams_mask > 0)
54 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
55 prev_missing_teams_mask = -1;
58 float missing_teams_mask = (!redalive) + (!bluealive) * 2;
59 if(freezetag_teams >= 3) missing_teams_mask += (!yellowalive) * 4;
60 if(freezetag_teams >= 4) missing_teams_mask += (!pinkalive) * 8;
61 if(prev_missing_teams_mask != missing_teams_mask)
63 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
64 prev_missing_teams_mask = missing_teams_mask;
69 float freezetag_getWinnerTeam()
71 float winner_team = 0;
73 winner_team = NUM_TEAM_1;
76 if(winner_team) return 0;
77 winner_team = NUM_TEAM_2;
81 if(winner_team) return 0;
82 winner_team = NUM_TEAM_3;
86 if(winner_team) return 0;
87 winner_team = NUM_TEAM_4;
91 return -1; // no player left
94 float freezetag_CheckWinner()
97 if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
99 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
100 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
103 e.freezetag_frozen_timeout = 0;
106 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
110 if(FREEZETAG_ALIVE_TEAMS() > 1)
114 winner_team = freezetag_getWinnerTeam();
117 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
118 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
119 TeamScore_AddToTeam(winner_team, ST_SCORE, +1);
121 else if(winner_team == -1)
123 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
124 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
129 e.freezetag_frozen_timeout = 0;
132 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
136 entity freezetag_LastPlayerForTeam()
138 entity pl, last_pl = world;
144 if(pl.team == self.team)
153 void freezetag_LastPlayerForTeam_Notify()
155 if(round_handler_IsActive())
156 if(round_handler_IsRoundStarted())
158 entity pl = freezetag_LastPlayerForTeam();
160 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
164 void freezetag_Add_Score(entity attacker)
168 // you froze your own dumb self
169 // counted as "suicide" already
170 PlayerScore_Add(self, SP_SCORE, -1);
172 else if(IS_PLAYER(attacker))
174 // got frozen by an enemy
175 // counted as "kill" and "death" already
176 PlayerScore_Add(self, SP_SCORE, -1);
177 PlayerScore_Add(attacker, SP_SCORE, +1);
179 // else nothing - got frozen by the game type rules themselves
182 void freezetag_Freeze(entity attacker)
187 if(autocvar_g_freezetag_frozen_maxtime > 0)
188 self.freezetag_frozen_timeout = time + autocvar_g_freezetag_frozen_maxtime;
190 Freeze(self, 0, 1, true);
192 freezetag_count_alive_players();
194 freezetag_Add_Score(attacker);
197 void freezetag_Unfreeze(entity attacker)
199 self.freezetag_frozen_time = 0;
200 self.freezetag_frozen_timeout = 0;
205 float freezetag_isEliminated(entity e)
207 if(IS_PLAYER(e) && (e.frozen == 1 || e.deadflag != DEAD_NO))
217 void() havocbot_role_ft_freeing;
218 void() havocbot_role_ft_offense;
220 void havocbot_goalrating_freeplayers(float ratingscale, vector org, float sradius)
225 FOR_EACH_PLAYER(head)
227 if ((head != self) && (head.team == self.team))
229 if (head.frozen == 1)
231 distance = vlen(head.origin - org);
232 if (distance > sradius)
234 navigation_routerating(head, ratingscale, 2000);
238 // If teamate is not frozen still seek them out as fight better
240 navigation_routerating(head, ratingscale/3, 2000);
246 void havocbot_role_ft_offense()
251 if(self.deadflag != DEAD_NO)
254 if (!self.havocbot_role_timeout)
255 self.havocbot_role_timeout = time + random() * 10 + 20;
257 // Count how many players on team are unfrozen.
259 FOR_EACH_PLAYER(head)
261 if ((head.team == self.team) && (head.frozen != 1))
265 // If only one left on team or if role has timed out then start trying to free players.
266 if (((unfrozen == 0) && (!self.frozen)) || (time > self.havocbot_role_timeout))
268 dprint("changing role to freeing\n");
269 self.havocbot_role = havocbot_role_ft_freeing;
270 self.havocbot_role_timeout = 0;
274 if (time > self.bot_strategytime)
276 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
278 navigation_goalrating_start();
279 havocbot_goalrating_items(10000, self.origin, 10000);
280 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
281 havocbot_goalrating_freeplayers(9000, self.origin, 10000);
282 //havocbot_goalrating_waypoints(1, self.origin, 1000);
283 navigation_goalrating_end();
287 void havocbot_role_ft_freeing()
289 if(self.deadflag != DEAD_NO)
292 if (!self.havocbot_role_timeout)
293 self.havocbot_role_timeout = time + random() * 10 + 20;
295 if (time > self.havocbot_role_timeout)
297 dprint("changing role to offense\n");
298 self.havocbot_role = havocbot_role_ft_offense;
299 self.havocbot_role_timeout = 0;
303 if (time > self.bot_strategytime)
305 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
307 navigation_goalrating_start();
308 havocbot_goalrating_items(8000, self.origin, 10000);
309 havocbot_goalrating_enemyplayers(10000, self.origin, 10000);
310 havocbot_goalrating_freeplayers(20000, self.origin, 10000);
311 //havocbot_goalrating_waypoints(1, self.origin, 1000);
312 navigation_goalrating_end();
321 MUTATOR_HOOKFUNCTION(freezetag_RemovePlayer)
323 self.health = 0; // neccessary to update correctly alive stats
325 freezetag_LastPlayerForTeam_Notify();
326 freezetag_Unfreeze(world);
327 freezetag_count_alive_players();
331 MUTATOR_HOOKFUNCTION(freezetag_PlayerDies)
333 if(round_handler_IsActive())
334 if(round_handler_CountdownRunning())
337 freezetag_Unfreeze(world);
338 freezetag_count_alive_players();
339 return 1; // let the player die so that he can respawn whenever he wants
342 // Cases DEATH_TEAMCHANGE and DEATH_AUTOTEAMCHANGE are needed to fix a bug whe
343 // you succeed changing team through the menu: you both really die (gibbing) and get frozen
344 if(ITEM_DAMAGE_NEEDKILL(frag_deathtype)
345 || frag_deathtype == DEATH_TEAMCHANGE || frag_deathtype == DEATH_AUTOTEAMCHANGE)
347 // let the player die, he will be automatically frozen when he respawns
350 freezetag_Add_Score(frag_attacker);
351 freezetag_count_alive_players();
352 freezetag_LastPlayerForTeam_Notify();
355 freezetag_Unfreeze(world); // remove ice
356 self.health = 0; // Unfreeze resets health
357 self.freezetag_frozen_timeout = -2; // freeze on respawn
364 freezetag_Freeze(frag_attacker);
365 freezetag_LastPlayerForTeam_Notify();
367 if(frag_attacker == frag_target || frag_attacker == world)
369 if(IS_PLAYER(frag_target))
370 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_SELF);
371 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_SELF, frag_target.netname);
375 if(IS_PLAYER(frag_target))
376 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_FROZEN, frag_attacker.netname);
377 if(IS_PLAYER(frag_attacker))
378 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_FREEZETAG_FREEZE, frag_target.netname);
379 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_FREEZE, frag_target.netname, frag_attacker.netname);
385 MUTATOR_HOOKFUNCTION(freezetag_PlayerSpawn)
387 if(self.freezetag_frozen_timeout == -1) // if PlayerSpawn is called by reset_map_players
388 return 1; // do nothing, round is starting right now
390 if(self.freezetag_frozen_timeout == -2) // player was dead
392 freezetag_Freeze(world);
396 freezetag_count_alive_players();
398 if(round_handler_IsActive())
399 if(round_handler_IsRoundStarted())
401 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
402 freezetag_Freeze(world);
408 MUTATOR_HOOKFUNCTION(freezetag_reset_map_players)
410 FOR_EACH_PLAYER(self)
413 self.freezetag_frozen_timeout = -1;
415 self.freezetag_frozen_timeout = 0;
417 freezetag_count_alive_players();
421 MUTATOR_HOOKFUNCTION(freezetag_GiveFragsForKill)
423 frag_score = 0; // no frags counted in Freeze Tag
427 MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink)
437 self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
440 if(round_handler_IsActive())
441 if(!round_handler_IsRoundStarted())
447 //if(self.freezetag_frozen_timeout > 0 && time < self.freezetag_frozen_timeout)
448 //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);
450 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
454 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
456 FOR_EACH_PLAYER(other)
458 if(other.frozen == 0)
459 if(other.deadflag == DEAD_NO)
460 if(SAME_TEAM(other, self))
461 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
466 other.reviving = true;
471 if(n && self.frozen == 1) // OK, there is at least one teammate reviving us
473 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
474 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
476 if(self.revive_progress >= 1)
478 freezetag_Unfreeze(self);
479 freezetag_count_alive_players();
483 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_AUTO_REVIVED, autocvar_g_freezetag_frozen_maxtime);
484 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_AUTO_REVIVED, self.netname, autocvar_g_freezetag_frozen_maxtime);
488 // EVERY team mate nearby gets a point (even if multiple!)
489 FOR_EACH_PLAYER(other)
493 PlayerScore_Add(other, SP_FREEZETAG_REVIVALS, +1);
494 PlayerScore_Add(other, SP_SCORE, +1);
496 nades_GiveBonus(other,autocvar_g_nades_bonus_score_low);
500 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
501 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
502 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED, self.netname, o.netname);
505 FOR_EACH_PLAYER(other)
509 other.revive_progress = self.revive_progress;
510 other.reviving = false;
514 else if(!n && self.frozen == 1) // only if no teammate is nearby will we reset
516 self.revive_progress = bound(0, self.revive_progress - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
517 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
519 else if(!n && !self.frozen)
521 self.revive_progress = 0; // thawing nobody
527 MUTATOR_HOOKFUNCTION(freezetag_SetStartItems)
529 start_items &= ~IT_UNLIMITED_AMMO;
530 //start_health = warmup_start_health = cvar("g_lms_start_health");
531 //start_armorvalue = warmup_start_armorvalue = cvar("g_lms_start_armor");
532 start_ammo_shells = warmup_start_ammo_shells = cvar("g_lms_start_ammo_shells");
533 start_ammo_nails = warmup_start_ammo_nails = cvar("g_lms_start_ammo_nails");
534 start_ammo_rockets = warmup_start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
535 start_ammo_cells = warmup_start_ammo_cells = cvar("g_lms_start_ammo_cells");
536 start_ammo_plasma = warmup_start_ammo_plasma = cvar("g_lms_start_ammo_plasma");
537 start_ammo_fuel = warmup_start_ammo_fuel = cvar("g_lms_start_ammo_fuel");
542 MUTATOR_HOOKFUNCTION(freezetag_BotRoles)
547 self.havocbot_role = havocbot_role_ft_freeing;
549 self.havocbot_role = havocbot_role_ft_offense;
555 MUTATOR_HOOKFUNCTION(freezetag_GetTeamCount)
557 ret_float = freezetag_teams;
561 void freezetag_Initialize()
563 freezetag_teams = autocvar_g_freezetag_teams_override;
564 if(freezetag_teams < 2)
565 freezetag_teams = autocvar_g_freezetag_teams;
566 freezetag_teams = bound(2, freezetag_teams, 4);
567 freezetag_ScoreRules(freezetag_teams);
569 round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null);
570 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
572 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
573 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
574 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
575 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
577 EliminatedPlayers_Init(freezetag_isEliminated);
580 MUTATOR_DEFINITION(gamemode_freezetag)
582 MUTATOR_HOOK(MakePlayerObserver, freezetag_RemovePlayer, CBC_ORDER_ANY);
583 MUTATOR_HOOK(ClientDisconnect, freezetag_RemovePlayer, CBC_ORDER_ANY);
584 MUTATOR_HOOK(PlayerDies, freezetag_PlayerDies, CBC_ORDER_ANY);
585 MUTATOR_HOOK(PlayerSpawn, freezetag_PlayerSpawn, CBC_ORDER_ANY);
586 MUTATOR_HOOK(reset_map_players, freezetag_reset_map_players, CBC_ORDER_ANY);
587 MUTATOR_HOOK(GiveFragsForKill, freezetag_GiveFragsForKill, CBC_ORDER_FIRST);
588 MUTATOR_HOOK(PlayerPreThink, freezetag_PlayerPreThink, CBC_ORDER_FIRST);
589 MUTATOR_HOOK(SetStartItems, freezetag_SetStartItems, CBC_ORDER_ANY);
590 MUTATOR_HOOK(HavocBot_ChooseRole, freezetag_BotRoles, CBC_ORDER_ANY);
591 MUTATOR_HOOK(GetTeamCount, freezetag_GetTeamCount, CBC_ORDER_EXCLUSIVE);
595 if(time > 1) // game loads at time 1
596 error("This is a game type and it cannot be added at runtime.");
597 freezetag_Initialize();
600 MUTATOR_ONROLLBACK_OR_REMOVE
602 // we actually cannot roll back freezetag_Initialize here
603 // BUT: we don't need to! If this gets called, adding always
609 print("This is a game type and it cannot be removed at runtime.");