1 #include "gamemode_freezetag.qh"
2 #ifndef GAMEMODE_FREEZETAG_H
3 #define GAMEMODE_FREEZETAG_H
5 int autocvar_g_freezetag_point_limit;
6 int autocvar_g_freezetag_point_leadlimit;
7 bool autocvar_g_freezetag_team_spawns;
8 void freezetag_Initialize();
10 REGISTER_MUTATOR(ft, false)
14 if (time > 1) // game loads at time 1
15 error("This is a game type and it cannot be added at runtime.");
16 freezetag_Initialize();
19 SetLimits(autocvar_g_freezetag_point_limit, autocvar_g_freezetag_point_leadlimit, -1, -1);
21 if (autocvar_g_freezetag_team_spawns)
22 have_team_spawns = -1; // request team spawns
25 MUTATOR_ONROLLBACK_OR_REMOVE
27 // we actually cannot roll back freezetag_Initialize here
28 // BUT: we don't need to! If this gets called, adding always
34 LOG_INFO("This is a game type and it cannot be removed at runtime.");
41 .float freezetag_frozen_time;
42 .float freezetag_frozen_timeout;
43 const float ICE_MAX_ALPHA = 1;
44 const float ICE_MIN_ALPHA = 0.1;
45 float freezetag_teams;
47 .float reviving; // temp var
49 float autocvar_g_freezetag_revive_extra_size;
50 float autocvar_g_freezetag_revive_speed;
51 bool autocvar_g_freezetag_revive_nade;
52 float autocvar_g_freezetag_revive_nade_health;
57 float autocvar_g_freezetag_frozen_maxtime;
58 float autocvar_g_freezetag_revive_clearspeed;
59 float autocvar_g_freezetag_round_timelimit;
60 int autocvar_g_freezetag_teams;
61 int autocvar_g_freezetag_teams_override;
62 float autocvar_g_freezetag_warmup;
64 void freezetag_ScoreRules(float teams)
66 ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, true); // SFL_SORT_PRIO_PRIMARY
67 ScoreInfo_SetLabel_PlayerScore(SP_FREEZETAG_REVIVALS, "revivals", 0);
68 ScoreRules_basics_end();
71 void freezetag_count_alive_players()
73 total_players = redalive = bluealive = yellowalive = pinkalive = 0;
74 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
77 case NUM_TEAM_1: ++total_players; if(it.health >= 1 && STAT(FROZEN, it) != 1) ++redalive; break;
78 case NUM_TEAM_2: ++total_players; if(it.health >= 1 && STAT(FROZEN, it) != 1) ++bluealive; break;
79 case NUM_TEAM_3: ++total_players; if(it.health >= 1 && STAT(FROZEN, it) != 1) ++yellowalive; break;
80 case NUM_TEAM_4: ++total_players; if(it.health >= 1 && STAT(FROZEN, it) != 1) ++pinkalive; break;
83 FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
84 it.redalive_stat = redalive;
85 it.bluealive_stat = bluealive;
86 it.yellowalive_stat = yellowalive;
87 it.pinkalive_stat = pinkalive;
90 eliminatedPlayers.SendFlags |= 1;
92 #define FREEZETAG_ALIVE_TEAMS() ((redalive > 0) + (bluealive > 0) + (yellowalive > 0) + (pinkalive > 0))
93 #define FREEZETAG_ALIVE_TEAMS_OK() (FREEZETAG_ALIVE_TEAMS() == freezetag_teams)
95 float freezetag_CheckTeams()
97 static float prev_missing_teams_mask;
98 if(FREEZETAG_ALIVE_TEAMS_OK())
100 if(prev_missing_teams_mask > 0)
101 Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_MISSING_TEAMS);
102 prev_missing_teams_mask = -1;
105 if(total_players == 0)
107 if(prev_missing_teams_mask > 0)
108 Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_MISSING_TEAMS);
109 prev_missing_teams_mask = -1;
112 float missing_teams_mask = (!redalive) + (!bluealive) * 2;
113 if(freezetag_teams >= 3) missing_teams_mask += (!yellowalive) * 4;
114 if(freezetag_teams >= 4) missing_teams_mask += (!pinkalive) * 8;
115 if(prev_missing_teams_mask != missing_teams_mask)
117 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
118 prev_missing_teams_mask = missing_teams_mask;
123 float freezetag_getWinnerTeam()
125 float winner_team = 0;
127 winner_team = NUM_TEAM_1;
130 if(winner_team) return 0;
131 winner_team = NUM_TEAM_2;
135 if(winner_team) return 0;
136 winner_team = NUM_TEAM_3;
140 if(winner_team) return 0;
141 winner_team = NUM_TEAM_4;
145 return -1; // no player left
148 float freezetag_CheckWinner()
150 if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
152 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
153 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
154 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
155 it.freezetag_frozen_timeout = 0;
158 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
162 if(FREEZETAG_ALIVE_TEAMS() > 1)
165 int winner_team = freezetag_getWinnerTeam();
168 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
169 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
170 TeamScore_AddToTeam(winner_team, ST_SCORE, +1);
172 else if(winner_team == -1)
174 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
175 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
178 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
179 it.freezetag_frozen_timeout = 0;
182 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
186 entity freezetag_LastPlayerForTeam()
188 entity last_pl = world;
189 FOREACH_CLIENT(IS_PLAYER(it) && it != self, LAMBDA(
191 if(!STAT(FROZEN, it))
192 if(SAME_TEAM(it, self))
201 void freezetag_LastPlayerForTeam_Notify()
203 if(round_handler_IsActive())
204 if(round_handler_IsRoundStarted())
206 entity pl = freezetag_LastPlayerForTeam();
208 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
212 void freezetag_Add_Score(entity attacker)
216 // you froze your own dumb self
217 // counted as "suicide" already
218 PlayerScore_Add(self, SP_SCORE, -1);
220 else if(IS_PLAYER(attacker))
222 // got frozen by an enemy
223 // counted as "kill" and "death" already
224 PlayerScore_Add(self, SP_SCORE, -1);
225 PlayerScore_Add(attacker, SP_SCORE, +1);
227 // else nothing - got frozen by the game type rules themselves
230 void freezetag_Freeze(entity attacker)
232 if(STAT(FROZEN, self))
235 if(autocvar_g_freezetag_frozen_maxtime > 0)
236 self.freezetag_frozen_timeout = time + autocvar_g_freezetag_frozen_maxtime;
238 Freeze(self, 0, 1, true);
240 freezetag_count_alive_players();
242 freezetag_Add_Score(attacker);
245 void freezetag_Unfreeze(entity attacker)
247 self.freezetag_frozen_time = 0;
248 self.freezetag_frozen_timeout = 0;
253 float freezetag_isEliminated(entity e)
255 if(IS_PLAYER(e) && (STAT(FROZEN, e) == 1 || IS_DEAD(e)))
265 void(entity this) havocbot_role_ft_freeing;
266 void(entity this) havocbot_role_ft_offense;
268 void havocbot_goalrating_freeplayers(entity this, float ratingscale, vector org, float sradius)
270 FOREACH_CLIENT(IS_PLAYER(it) && it != this && SAME_TEAM(it, this), LAMBDA(
271 if (STAT(FROZEN, it) == 1)
273 if(vdist(it.origin - org, >, sradius))
275 navigation_routerating(this, it, ratingscale, 2000);
279 // If teamate is not frozen still seek them out as fight better
281 navigation_routerating(this, it, ratingscale/3, 2000);
286 void havocbot_role_ft_offense(entity this)
291 if (!this.havocbot_role_timeout)
292 this.havocbot_role_timeout = time + random() * 10 + 20;
294 // Count how many players on team are unfrozen.
296 FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, this) && !(STAT(FROZEN, it) != 1), LAMBDA(unfrozen++));
298 // If only one left on team or if role has timed out then start trying to free players.
299 if (((unfrozen == 0) && (!STAT(FROZEN, this))) || (time > this.havocbot_role_timeout))
301 LOG_TRACE("changing role to freeing\n");
302 this.havocbot_role = havocbot_role_ft_freeing;
303 this.havocbot_role_timeout = 0;
307 if (time > this.bot_strategytime)
309 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
311 navigation_goalrating_start(this);
312 havocbot_goalrating_items(this, 10000, this.origin, 10000);
313 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 10000);
314 havocbot_goalrating_freeplayers(this, 9000, this.origin, 10000);
315 //havocbot_goalrating_waypoints(1, this.origin, 1000);
316 navigation_goalrating_end(this);
320 void havocbot_role_ft_freeing(entity this)
325 if (!this.havocbot_role_timeout)
326 this.havocbot_role_timeout = time + random() * 10 + 20;
328 if (time > this.havocbot_role_timeout)
330 LOG_TRACE("changing role to offense\n");
331 this.havocbot_role = havocbot_role_ft_offense;
332 this.havocbot_role_timeout = 0;
336 if (time > this.bot_strategytime)
338 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
340 navigation_goalrating_start(this);
341 havocbot_goalrating_items(this, 8000, this.origin, 10000);
342 havocbot_goalrating_enemyplayers(this, 10000, this.origin, 10000);
343 havocbot_goalrating_freeplayers(this, 20000, this.origin, 10000);
344 //havocbot_goalrating_waypoints(1, this.origin, 1000);
345 navigation_goalrating_end(this);
354 void ft_RemovePlayer()
356 self.health = 0; // neccessary to update correctly alive stats
357 if(!STAT(FROZEN, self))
358 freezetag_LastPlayerForTeam_Notify();
359 freezetag_Unfreeze(world);
360 freezetag_count_alive_players();
363 MUTATOR_HOOKFUNCTION(ft, ClientDisconnect)
369 MUTATOR_HOOKFUNCTION(ft, MakePlayerObserver)
375 MUTATOR_HOOKFUNCTION(ft, PlayerDies)
378 if(round_handler_IsActive())
379 if(round_handler_CountdownRunning())
381 if(STAT(FROZEN, frag_target))
382 WITHSELF(frag_target, freezetag_Unfreeze(world));
383 freezetag_count_alive_players();
384 return 1; // let the player die so that he can respawn whenever he wants
387 // Cases DEATH_TEAMCHANGE and DEATH_AUTOTEAMCHANGE are needed to fix a bug whe
388 // you succeed changing team through the menu: you both really die (gibbing) and get frozen
389 if(ITEM_DAMAGE_NEEDKILL(frag_deathtype)
390 || frag_deathtype == DEATH_TEAMCHANGE.m_id || frag_deathtype == DEATH_AUTOTEAMCHANGE.m_id)
392 // let the player die, he will be automatically frozen when he respawns
393 if(STAT(FROZEN, frag_target) != 1)
395 freezetag_Add_Score(frag_attacker);
396 freezetag_count_alive_players();
397 freezetag_LastPlayerForTeam_Notify();
400 WITHSELF(frag_target, freezetag_Unfreeze(world)); // remove ice
401 frag_target.health = 0; // Unfreeze resets health
402 frag_target.freezetag_frozen_timeout = -2; // freeze on respawn
406 if(STAT(FROZEN, frag_target))
409 WITHSELF(frag_target, freezetag_Freeze(frag_attacker));
410 freezetag_LastPlayerForTeam_Notify();
412 if(frag_attacker == frag_target || frag_attacker == world)
414 if(IS_PLAYER(frag_target))
415 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_SELF);
416 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_SELF, frag_target.netname);
420 if(IS_PLAYER(frag_target))
421 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_FROZEN, frag_attacker.netname);
422 if(IS_PLAYER(frag_attacker))
423 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_FREEZETAG_FREEZE, frag_target.netname);
424 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_FREEZE, frag_target.netname, frag_attacker.netname);
430 MUTATOR_HOOKFUNCTION(ft, PlayerSpawn)
432 if(self.freezetag_frozen_timeout == -1) // if PlayerSpawn is called by reset_map_players
433 return 1; // do nothing, round is starting right now
435 if(self.freezetag_frozen_timeout == -2) // player was dead
437 freezetag_Freeze(world);
441 freezetag_count_alive_players();
443 if(round_handler_IsActive())
444 if(round_handler_IsRoundStarted())
446 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
447 freezetag_Freeze(world);
453 MUTATOR_HOOKFUNCTION(ft, reset_map_players)
455 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
457 it.freezetag_frozen_timeout = -1;
460 it.freezetag_frozen_timeout = 0;
462 freezetag_count_alive_players();
466 MUTATOR_HOOKFUNCTION(ft, GiveFragsForKill, CBC_ORDER_FIRST)
468 frag_score = 0; // no frags counted in Freeze Tag
472 MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST)
477 if(STAT(FROZEN, self) == 1)
480 self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
483 if(round_handler_IsActive())
484 if(!round_handler_IsRoundStarted())
491 //if(STAT(FROZEN, self))
492 //if(self.freezetag_frozen_timeout > 0 && time < self.freezetag_frozen_timeout)
493 //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);
495 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
499 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
501 FOREACH_CLIENT(IS_PLAYER(it) && it != self, LAMBDA(
502 if(STAT(FROZEN, it) == 0)
504 if(SAME_TEAM(it, self))
505 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, it.absmin, it.absmax))
509 if(STAT(FROZEN, self) == 1)
517 if(n && STAT(FROZEN, self) == 1) // OK, there is at least one teammate reviving us
519 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
520 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
522 if(self.revive_progress >= 1)
524 freezetag_Unfreeze(self);
525 freezetag_count_alive_players();
529 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_AUTO_REVIVED, autocvar_g_freezetag_frozen_maxtime);
530 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_AUTO_REVIVED, self.netname, autocvar_g_freezetag_frozen_maxtime);
534 // EVERY team mate nearby gets a point (even if multiple!)
535 FOREACH_CLIENT(IS_PLAYER(it) && it.reviving, LAMBDA(
536 PlayerScore_Add(it, SP_FREEZETAG_REVIVALS, +1);
537 PlayerScore_Add(it, SP_SCORE, +1);
538 nades_GiveBonus(it,autocvar_g_nades_bonus_score_low);
541 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
542 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
543 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED, self.netname, o.netname);
546 FOREACH_CLIENT(IS_PLAYER(it) && it.reviving, LAMBDA(
547 it.revive_progress = self.revive_progress;
551 else if(!n && STAT(FROZEN, self) == 1) // only if no teammate is nearby will we reset
553 self.revive_progress = bound(0, self.revive_progress - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
554 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
556 else if(!n && !STAT(FROZEN, self))
558 self.revive_progress = 0; // thawing nobody
564 MUTATOR_HOOKFUNCTION(ft, SetStartItems)
566 start_items &= ~IT_UNLIMITED_AMMO;
567 //start_health = warmup_start_health = cvar("g_lms_start_health");
568 //start_armorvalue = warmup_start_armorvalue = cvar("g_lms_start_armor");
569 start_ammo_shells = warmup_start_ammo_shells = cvar("g_lms_start_ammo_shells");
570 start_ammo_nails = warmup_start_ammo_nails = cvar("g_lms_start_ammo_nails");
571 start_ammo_rockets = warmup_start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
572 start_ammo_cells = warmup_start_ammo_cells = cvar("g_lms_start_ammo_cells");
573 start_ammo_plasma = warmup_start_ammo_plasma = cvar("g_lms_start_ammo_plasma");
574 start_ammo_fuel = warmup_start_ammo_fuel = cvar("g_lms_start_ammo_fuel");
579 MUTATOR_HOOKFUNCTION(ft, HavocBot_ChooseRole)
584 self.havocbot_role = havocbot_role_ft_freeing;
586 self.havocbot_role = havocbot_role_ft_offense;
592 MUTATOR_HOOKFUNCTION(ft, GetTeamCount, CBC_ORDER_EXCLUSIVE)
594 ret_float = freezetag_teams;
598 MUTATOR_HOOKFUNCTION(ft, SetWeaponArena)
600 // most weapons arena
601 if(ret_string == "0" || ret_string == "")
606 void freezetag_Initialize()
608 freezetag_teams = autocvar_g_freezetag_teams_override;
609 if(freezetag_teams < 2)
610 freezetag_teams = autocvar_g_freezetag_teams;
611 freezetag_teams = bound(2, freezetag_teams, 4);
612 freezetag_ScoreRules(freezetag_teams);
614 round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null);
615 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
617 EliminatedPlayers_Init(freezetag_isEliminated);