1 #ifndef GAMEMODE_FREEZETAG_H
2 #define GAMEMODE_FREEZETAG_H
4 int autocvar_g_freezetag_point_limit;
5 int autocvar_g_freezetag_point_leadlimit;
6 bool autocvar_g_freezetag_team_spawns;
7 void freezetag_Initialize();
9 REGISTER_MUTATOR(ft, false)
12 SetLimits(autocvar_g_freezetag_point_limit, autocvar_g_freezetag_point_leadlimit, -1, -1);
14 if (autocvar_g_freezetag_team_spawns)
15 have_team_spawns = -1; // request team spawns
19 if (time > 1) // game loads at time 1
20 error("This is a game type and it cannot be added at runtime.");
21 freezetag_Initialize();
24 MUTATOR_ONROLLBACK_OR_REMOVE
26 // we actually cannot roll back freezetag_Initialize here
27 // BUT: we don't need to! If this gets called, adding always
33 LOG_INFO("This is a game type and it cannot be removed at runtime.");
40 .float freezetag_frozen_time;
41 .float freezetag_frozen_timeout;
42 const float ICE_MAX_ALPHA = 1;
43 const float ICE_MIN_ALPHA = 0.1;
44 float freezetag_teams;
46 .float reviving; // temp var
51 float autocvar_g_freezetag_frozen_maxtime;
52 bool autocvar_g_freezetag_revive_nade;
53 float autocvar_g_freezetag_revive_nade_health;
54 float autocvar_g_freezetag_revive_extra_size;
55 float autocvar_g_freezetag_revive_speed;
56 float autocvar_g_freezetag_revive_clearspeed;
57 float autocvar_g_freezetag_round_timelimit;
58 int autocvar_g_freezetag_teams;
59 int autocvar_g_freezetag_teams_override;
60 float autocvar_g_freezetag_warmup;
62 const float SP_FREEZETAG_REVIVALS = 4;
63 void freezetag_ScoreRules(float teams)
65 ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, true); // SFL_SORT_PRIO_PRIMARY
66 ScoreInfo_SetLabel_PlayerScore(SP_FREEZETAG_REVIVALS, "revivals", 0);
67 ScoreRules_basics_end();
70 void freezetag_count_alive_players()
73 total_players = redalive = bluealive = yellowalive = pinkalive = 0;
78 case NUM_TEAM_1: ++total_players; if(e.health >= 1 && e.frozen != 1) ++redalive; break;
79 case NUM_TEAM_2: ++total_players; if(e.health >= 1 && e.frozen != 1) ++bluealive; break;
80 case NUM_TEAM_3: ++total_players; if(e.health >= 1 && e.frozen != 1) ++yellowalive; break;
81 case NUM_TEAM_4: ++total_players; if(e.health >= 1 && e.frozen != 1) ++pinkalive; break;
84 FOR_EACH_REALCLIENT(e)
86 e.redalive_stat = redalive;
87 e.bluealive_stat = bluealive;
88 e.yellowalive_stat = yellowalive;
89 e.pinkalive_stat = pinkalive;
92 eliminatedPlayers.SendFlags |= 1;
94 #define FREEZETAG_ALIVE_TEAMS() ((redalive > 0) + (bluealive > 0) + (yellowalive > 0) + (pinkalive > 0))
95 #define FREEZETAG_ALIVE_TEAMS_OK() (FREEZETAG_ALIVE_TEAMS() == freezetag_teams)
97 float freezetag_CheckTeams()
99 static float prev_missing_teams_mask;
100 if(FREEZETAG_ALIVE_TEAMS_OK())
102 if(prev_missing_teams_mask > 0)
103 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
104 prev_missing_teams_mask = -1;
107 if(total_players == 0)
109 if(prev_missing_teams_mask > 0)
110 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
111 prev_missing_teams_mask = -1;
114 float missing_teams_mask = (!redalive) + (!bluealive) * 2;
115 if(freezetag_teams >= 3) missing_teams_mask += (!yellowalive) * 4;
116 if(freezetag_teams >= 4) missing_teams_mask += (!pinkalive) * 8;
117 if(prev_missing_teams_mask != missing_teams_mask)
119 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
120 prev_missing_teams_mask = missing_teams_mask;
125 float freezetag_getWinnerTeam()
127 float winner_team = 0;
129 winner_team = NUM_TEAM_1;
132 if(winner_team) return 0;
133 winner_team = NUM_TEAM_2;
137 if(winner_team) return 0;
138 winner_team = NUM_TEAM_3;
142 if(winner_team) return 0;
143 winner_team = NUM_TEAM_4;
147 return -1; // no player left
150 float freezetag_CheckWinner()
153 if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
155 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
156 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
159 e.freezetag_frozen_timeout = 0;
162 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
166 if(FREEZETAG_ALIVE_TEAMS() > 1)
170 winner_team = freezetag_getWinnerTeam();
173 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
174 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
175 TeamScore_AddToTeam(winner_team, ST_SCORE, +1);
177 else if(winner_team == -1)
179 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
180 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
185 e.freezetag_frozen_timeout = 0;
188 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
192 entity freezetag_LastPlayerForTeam()
194 entity pl, last_pl = world;
200 if(pl.team == self.team)
209 void freezetag_LastPlayerForTeam_Notify()
211 if(round_handler_IsActive())
212 if(round_handler_IsRoundStarted())
214 entity pl = freezetag_LastPlayerForTeam();
216 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
220 void freezetag_Add_Score(entity attacker)
224 // you froze your own dumb self
225 // counted as "suicide" already
226 PlayerScore_Add(self, SP_SCORE, -1);
228 else if(IS_PLAYER(attacker))
230 // got frozen by an enemy
231 // counted as "kill" and "death" already
232 PlayerScore_Add(self, SP_SCORE, -1);
233 PlayerScore_Add(attacker, SP_SCORE, +1);
235 // else nothing - got frozen by the game type rules themselves
238 void freezetag_Freeze(entity attacker)
243 if(autocvar_g_freezetag_frozen_maxtime > 0)
244 self.freezetag_frozen_timeout = time + autocvar_g_freezetag_frozen_maxtime;
246 Freeze(self, 0, 1, true);
248 freezetag_count_alive_players();
250 freezetag_Add_Score(attacker);
253 void freezetag_Unfreeze(entity attacker)
255 self.freezetag_frozen_time = 0;
256 self.freezetag_frozen_timeout = 0;
261 float freezetag_isEliminated(entity e)
263 if(IS_PLAYER(e) && (e.frozen == 1 || e.deadflag != DEAD_NO))
273 void() havocbot_role_ft_freeing;
274 void() havocbot_role_ft_offense;
276 void havocbot_goalrating_freeplayers(float ratingscale, vector org, float sradius)
281 FOR_EACH_PLAYER(head)
283 if ((head != self) && (head.team == self.team))
285 if (head.frozen == 1)
287 distance = vlen(head.origin - org);
288 if (distance > sradius)
290 navigation_routerating(head, ratingscale, 2000);
294 // If teamate is not frozen still seek them out as fight better
296 navigation_routerating(head, ratingscale/3, 2000);
302 void havocbot_role_ft_offense()
307 if(self.deadflag != DEAD_NO)
310 if (!self.havocbot_role_timeout)
311 self.havocbot_role_timeout = time + random() * 10 + 20;
313 // Count how many players on team are unfrozen.
315 FOR_EACH_PLAYER(head)
317 if ((head.team == self.team) && (head.frozen != 1))
321 // If only one left on team or if role has timed out then start trying to free players.
322 if (((unfrozen == 0) && (!self.frozen)) || (time > self.havocbot_role_timeout))
324 LOG_TRACE("changing role to freeing\n");
325 self.havocbot_role = havocbot_role_ft_freeing;
326 self.havocbot_role_timeout = 0;
330 if (time > self.bot_strategytime)
332 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
334 navigation_goalrating_start();
335 havocbot_goalrating_items(10000, self.origin, 10000);
336 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
337 havocbot_goalrating_freeplayers(9000, self.origin, 10000);
338 //havocbot_goalrating_waypoints(1, self.origin, 1000);
339 navigation_goalrating_end();
343 void havocbot_role_ft_freeing()
345 if(self.deadflag != DEAD_NO)
348 if (!self.havocbot_role_timeout)
349 self.havocbot_role_timeout = time + random() * 10 + 20;
351 if (time > self.havocbot_role_timeout)
353 LOG_TRACE("changing role to offense\n");
354 self.havocbot_role = havocbot_role_ft_offense;
355 self.havocbot_role_timeout = 0;
359 if (time > self.bot_strategytime)
361 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
363 navigation_goalrating_start();
364 havocbot_goalrating_items(8000, self.origin, 10000);
365 havocbot_goalrating_enemyplayers(10000, self.origin, 10000);
366 havocbot_goalrating_freeplayers(20000, self.origin, 10000);
367 //havocbot_goalrating_waypoints(1, self.origin, 1000);
368 navigation_goalrating_end();
377 void ft_RemovePlayer()
379 self.health = 0; // neccessary to update correctly alive stats
381 freezetag_LastPlayerForTeam_Notify();
382 freezetag_Unfreeze(world);
383 freezetag_count_alive_players();
386 MUTATOR_HOOKFUNCTION(ft, ClientDisconnect)
392 MUTATOR_HOOKFUNCTION(ft, MakePlayerObserver)
398 MUTATOR_HOOKFUNCTION(ft, PlayerDies)
400 if(round_handler_IsActive())
401 if(round_handler_CountdownRunning())
404 freezetag_Unfreeze(world);
405 freezetag_count_alive_players();
406 return 1; // let the player die so that he can respawn whenever he wants
409 // Cases DEATH_TEAMCHANGE and DEATH_AUTOTEAMCHANGE are needed to fix a bug whe
410 // you succeed changing team through the menu: you both really die (gibbing) and get frozen
411 if(ITEM_DAMAGE_NEEDKILL(frag_deathtype)
412 || frag_deathtype == DEATH_TEAMCHANGE.m_id || frag_deathtype == DEATH_AUTOTEAMCHANGE.m_id)
414 // let the player die, he will be automatically frozen when he respawns
417 freezetag_Add_Score(frag_attacker);
418 freezetag_count_alive_players();
419 freezetag_LastPlayerForTeam_Notify();
422 freezetag_Unfreeze(world); // remove ice
423 self.health = 0; // Unfreeze resets health
424 self.freezetag_frozen_timeout = -2; // freeze on respawn
431 freezetag_Freeze(frag_attacker);
432 freezetag_LastPlayerForTeam_Notify();
434 if(frag_attacker == frag_target || frag_attacker == world)
436 if(IS_PLAYER(frag_target))
437 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_SELF);
438 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_SELF, frag_target.netname);
442 if(IS_PLAYER(frag_target))
443 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_FROZEN, frag_attacker.netname);
444 if(IS_PLAYER(frag_attacker))
445 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_FREEZETAG_FREEZE, frag_target.netname);
446 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_FREEZE, frag_target.netname, frag_attacker.netname);
452 MUTATOR_HOOKFUNCTION(ft, PlayerSpawn)
454 if(self.freezetag_frozen_timeout == -1) // if PlayerSpawn is called by reset_map_players
455 return 1; // do nothing, round is starting right now
457 if(self.freezetag_frozen_timeout == -2) // player was dead
459 freezetag_Freeze(world);
463 freezetag_count_alive_players();
465 if(round_handler_IsActive())
466 if(round_handler_IsRoundStarted())
468 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
469 freezetag_Freeze(world);
475 MUTATOR_HOOKFUNCTION(ft, reset_map_players)
481 e.freezetag_frozen_timeout = -1;
484 e.freezetag_frozen_timeout = 0;
486 freezetag_count_alive_players();
490 MUTATOR_HOOKFUNCTION(ft, GiveFragsForKill, CBC_ORDER_FIRST)
492 frag_score = 0; // no frags counted in Freeze Tag
496 MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST)
506 self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
509 if(round_handler_IsActive())
510 if(!round_handler_IsRoundStarted())
516 //if(self.freezetag_frozen_timeout > 0 && time < self.freezetag_frozen_timeout)
517 //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);
519 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
523 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
525 FOR_EACH_PLAYER(other)
527 if(other.frozen == 0)
528 if(other.deadflag == DEAD_NO)
529 if(SAME_TEAM(other, self))
530 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
535 other.reviving = true;
540 if(n && self.frozen == 1) // OK, there is at least one teammate reviving us
542 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
543 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
545 if(self.revive_progress >= 1)
547 freezetag_Unfreeze(self);
548 freezetag_count_alive_players();
552 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_AUTO_REVIVED, autocvar_g_freezetag_frozen_maxtime);
553 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_AUTO_REVIVED, self.netname, autocvar_g_freezetag_frozen_maxtime);
557 // EVERY team mate nearby gets a point (even if multiple!)
558 FOR_EACH_PLAYER(other)
562 PlayerScore_Add(other, SP_FREEZETAG_REVIVALS, +1);
563 PlayerScore_Add(other, SP_SCORE, +1);
565 nades_GiveBonus(other,autocvar_g_nades_bonus_score_low);
569 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
570 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
571 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED, self.netname, o.netname);
574 FOR_EACH_PLAYER(other)
578 other.revive_progress = self.revive_progress;
579 other.reviving = false;
583 else if(!n && self.frozen == 1) // only if no teammate is nearby will we reset
585 self.revive_progress = bound(0, self.revive_progress - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
586 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
588 else if(!n && !self.frozen)
590 self.revive_progress = 0; // thawing nobody
596 MUTATOR_HOOKFUNCTION(ft, SetStartItems)
598 start_items &= ~IT_UNLIMITED_AMMO;
599 //start_health = warmup_start_health = cvar("g_lms_start_health");
600 //start_armorvalue = warmup_start_armorvalue = cvar("g_lms_start_armor");
601 start_ammo_shells = warmup_start_ammo_shells = cvar("g_lms_start_ammo_shells");
602 start_ammo_nails = warmup_start_ammo_nails = cvar("g_lms_start_ammo_nails");
603 start_ammo_rockets = warmup_start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
604 start_ammo_cells = warmup_start_ammo_cells = cvar("g_lms_start_ammo_cells");
605 start_ammo_plasma = warmup_start_ammo_plasma = cvar("g_lms_start_ammo_plasma");
606 start_ammo_fuel = warmup_start_ammo_fuel = cvar("g_lms_start_ammo_fuel");
611 MUTATOR_HOOKFUNCTION(ft, HavocBot_ChooseRole)
616 self.havocbot_role = havocbot_role_ft_freeing;
618 self.havocbot_role = havocbot_role_ft_offense;
624 MUTATOR_HOOKFUNCTION(ft, GetTeamCount, CBC_ORDER_EXCLUSIVE)
626 ret_float = freezetag_teams;
630 MUTATOR_HOOKFUNCTION(ft, SetWeaponArena)
632 // most weapons arena
633 if(ret_string == "0" || ret_string == "")
638 void freezetag_Initialize()
640 freezetag_teams = autocvar_g_freezetag_teams_override;
641 if(freezetag_teams < 2)
642 freezetag_teams = autocvar_g_freezetag_teams;
643 freezetag_teams = bound(2, freezetag_teams, 4);
644 freezetag_ScoreRules(freezetag_teams);
646 round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null);
647 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
649 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
650 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
651 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
652 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
654 EliminatedPlayers_Init(freezetag_isEliminated);