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)
13 if (time > 1) // game loads at time 1
14 error("This is a game type and it cannot be added at runtime.");
15 freezetag_Initialize();
18 SetLimits(autocvar_g_freezetag_point_limit, autocvar_g_freezetag_point_leadlimit, -1, -1);
20 if (autocvar_g_freezetag_team_spawns)
21 have_team_spawns = -1; // request team spawns
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
48 float autocvar_g_freezetag_revive_extra_size;
49 float autocvar_g_freezetag_revive_speed;
50 bool autocvar_g_freezetag_revive_nade;
51 float autocvar_g_freezetag_revive_nade_health;
56 float autocvar_g_freezetag_frozen_maxtime;
57 float autocvar_g_freezetag_revive_clearspeed;
58 float autocvar_g_freezetag_round_timelimit;
59 int autocvar_g_freezetag_teams;
60 int autocvar_g_freezetag_teams_override;
61 float autocvar_g_freezetag_warmup;
63 const float SP_FREEZETAG_REVIVALS = 4;
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()
74 total_players = redalive = bluealive = yellowalive = pinkalive = 0;
79 case NUM_TEAM_1: ++total_players; if(e.health >= 1 && e.frozen != 1) ++redalive; break;
80 case NUM_TEAM_2: ++total_players; if(e.health >= 1 && e.frozen != 1) ++bluealive; break;
81 case NUM_TEAM_3: ++total_players; if(e.health >= 1 && e.frozen != 1) ++yellowalive; break;
82 case NUM_TEAM_4: ++total_players; if(e.health >= 1 && e.frozen != 1) ++pinkalive; break;
85 FOR_EACH_REALCLIENT(e)
87 e.redalive_stat = redalive;
88 e.bluealive_stat = bluealive;
89 e.yellowalive_stat = yellowalive;
90 e.pinkalive_stat = pinkalive;
93 eliminatedPlayers.SendFlags |= 1;
95 #define FREEZETAG_ALIVE_TEAMS() ((redalive > 0) + (bluealive > 0) + (yellowalive > 0) + (pinkalive > 0))
96 #define FREEZETAG_ALIVE_TEAMS_OK() (FREEZETAG_ALIVE_TEAMS() == freezetag_teams)
98 float freezetag_CheckTeams()
100 static float prev_missing_teams_mask;
101 if(FREEZETAG_ALIVE_TEAMS_OK())
103 if(prev_missing_teams_mask > 0)
104 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
105 prev_missing_teams_mask = -1;
108 if(total_players == 0)
110 if(prev_missing_teams_mask > 0)
111 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
112 prev_missing_teams_mask = -1;
115 float missing_teams_mask = (!redalive) + (!bluealive) * 2;
116 if(freezetag_teams >= 3) missing_teams_mask += (!yellowalive) * 4;
117 if(freezetag_teams >= 4) missing_teams_mask += (!pinkalive) * 8;
118 if(prev_missing_teams_mask != missing_teams_mask)
120 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
121 prev_missing_teams_mask = missing_teams_mask;
126 float freezetag_getWinnerTeam()
128 float winner_team = 0;
130 winner_team = NUM_TEAM_1;
133 if(winner_team) return 0;
134 winner_team = NUM_TEAM_2;
138 if(winner_team) return 0;
139 winner_team = NUM_TEAM_3;
143 if(winner_team) return 0;
144 winner_team = NUM_TEAM_4;
148 return -1; // no player left
151 float freezetag_CheckWinner()
154 if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
156 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
157 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
160 e.freezetag_frozen_timeout = 0;
163 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
167 if(FREEZETAG_ALIVE_TEAMS() > 1)
171 winner_team = freezetag_getWinnerTeam();
174 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
175 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
176 TeamScore_AddToTeam(winner_team, ST_SCORE, +1);
178 else if(winner_team == -1)
180 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
181 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
186 e.freezetag_frozen_timeout = 0;
189 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
193 entity freezetag_LastPlayerForTeam()
195 entity pl, last_pl = world;
201 if(pl.team == self.team)
210 void freezetag_LastPlayerForTeam_Notify()
212 if(round_handler_IsActive())
213 if(round_handler_IsRoundStarted())
215 entity pl = freezetag_LastPlayerForTeam();
217 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
221 void freezetag_Add_Score(entity attacker)
225 // you froze your own dumb self
226 // counted as "suicide" already
227 PlayerScore_Add(self, SP_SCORE, -1);
229 else if(IS_PLAYER(attacker))
231 // got frozen by an enemy
232 // counted as "kill" and "death" already
233 PlayerScore_Add(self, SP_SCORE, -1);
234 PlayerScore_Add(attacker, SP_SCORE, +1);
236 // else nothing - got frozen by the game type rules themselves
239 void freezetag_Freeze(entity attacker)
244 if(autocvar_g_freezetag_frozen_maxtime > 0)
245 self.freezetag_frozen_timeout = time + autocvar_g_freezetag_frozen_maxtime;
247 Freeze(self, 0, 1, true);
249 freezetag_count_alive_players();
251 freezetag_Add_Score(attacker);
254 void freezetag_Unfreeze(entity attacker)
256 self.freezetag_frozen_time = 0;
257 self.freezetag_frozen_timeout = 0;
262 float freezetag_isEliminated(entity e)
264 if(IS_PLAYER(e) && (e.frozen == 1 || e.deadflag != DEAD_NO))
274 void() havocbot_role_ft_freeing;
275 void() havocbot_role_ft_offense;
277 void havocbot_goalrating_freeplayers(float ratingscale, vector org, float sradius)
282 FOR_EACH_PLAYER(head)
284 if ((head != self) && (head.team == self.team))
286 if (head.frozen == 1)
288 distance = vlen(head.origin - org);
289 if (distance > sradius)
291 navigation_routerating(head, ratingscale, 2000);
295 // If teamate is not frozen still seek them out as fight better
297 navigation_routerating(head, ratingscale/3, 2000);
303 void havocbot_role_ft_offense()
308 if(self.deadflag != DEAD_NO)
311 if (!self.havocbot_role_timeout)
312 self.havocbot_role_timeout = time + random() * 10 + 20;
314 // Count how many players on team are unfrozen.
316 FOR_EACH_PLAYER(head)
318 if ((head.team == self.team) && (head.frozen != 1))
322 // If only one left on team or if role has timed out then start trying to free players.
323 if (((unfrozen == 0) && (!self.frozen)) || (time > self.havocbot_role_timeout))
325 LOG_TRACE("changing role to freeing\n");
326 self.havocbot_role = havocbot_role_ft_freeing;
327 self.havocbot_role_timeout = 0;
331 if (time > self.bot_strategytime)
333 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
335 navigation_goalrating_start();
336 havocbot_goalrating_items(10000, self.origin, 10000);
337 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
338 havocbot_goalrating_freeplayers(9000, self.origin, 10000);
339 //havocbot_goalrating_waypoints(1, self.origin, 1000);
340 navigation_goalrating_end();
344 void havocbot_role_ft_freeing()
346 if(self.deadflag != DEAD_NO)
349 if (!self.havocbot_role_timeout)
350 self.havocbot_role_timeout = time + random() * 10 + 20;
352 if (time > self.havocbot_role_timeout)
354 LOG_TRACE("changing role to offense\n");
355 self.havocbot_role = havocbot_role_ft_offense;
356 self.havocbot_role_timeout = 0;
360 if (time > self.bot_strategytime)
362 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
364 navigation_goalrating_start();
365 havocbot_goalrating_items(8000, self.origin, 10000);
366 havocbot_goalrating_enemyplayers(10000, self.origin, 10000);
367 havocbot_goalrating_freeplayers(20000, self.origin, 10000);
368 //havocbot_goalrating_waypoints(1, self.origin, 1000);
369 navigation_goalrating_end();
378 void ft_RemovePlayer()
380 self.health = 0; // neccessary to update correctly alive stats
382 freezetag_LastPlayerForTeam_Notify();
383 freezetag_Unfreeze(world);
384 freezetag_count_alive_players();
387 MUTATOR_HOOKFUNCTION(ft, ClientDisconnect)
393 MUTATOR_HOOKFUNCTION(ft, MakePlayerObserver)
399 MUTATOR_HOOKFUNCTION(ft, PlayerDies)
401 if(round_handler_IsActive())
402 if(round_handler_CountdownRunning())
405 freezetag_Unfreeze(world);
406 freezetag_count_alive_players();
407 return 1; // let the player die so that he can respawn whenever he wants
410 // Cases DEATH_TEAMCHANGE and DEATH_AUTOTEAMCHANGE are needed to fix a bug whe
411 // you succeed changing team through the menu: you both really die (gibbing) and get frozen
412 if(ITEM_DAMAGE_NEEDKILL(frag_deathtype)
413 || frag_deathtype == DEATH_TEAMCHANGE.m_id || frag_deathtype == DEATH_AUTOTEAMCHANGE.m_id)
415 // let the player die, he will be automatically frozen when he respawns
418 freezetag_Add_Score(frag_attacker);
419 freezetag_count_alive_players();
420 freezetag_LastPlayerForTeam_Notify();
423 freezetag_Unfreeze(world); // remove ice
424 self.health = 0; // Unfreeze resets health
425 self.freezetag_frozen_timeout = -2; // freeze on respawn
432 freezetag_Freeze(frag_attacker);
433 freezetag_LastPlayerForTeam_Notify();
435 if(frag_attacker == frag_target || frag_attacker == world)
437 if(IS_PLAYER(frag_target))
438 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_SELF);
439 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_SELF, frag_target.netname);
443 if(IS_PLAYER(frag_target))
444 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_FROZEN, frag_attacker.netname);
445 if(IS_PLAYER(frag_attacker))
446 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_FREEZETAG_FREEZE, frag_target.netname);
447 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_FREEZE, frag_target.netname, frag_attacker.netname);
453 MUTATOR_HOOKFUNCTION(ft, PlayerSpawn)
455 if(self.freezetag_frozen_timeout == -1) // if PlayerSpawn is called by reset_map_players
456 return 1; // do nothing, round is starting right now
458 if(self.freezetag_frozen_timeout == -2) // player was dead
460 freezetag_Freeze(world);
464 freezetag_count_alive_players();
466 if(round_handler_IsActive())
467 if(round_handler_IsRoundStarted())
469 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
470 freezetag_Freeze(world);
476 MUTATOR_HOOKFUNCTION(ft, reset_map_players)
482 e.freezetag_frozen_timeout = -1;
485 e.freezetag_frozen_timeout = 0;
487 freezetag_count_alive_players();
491 MUTATOR_HOOKFUNCTION(ft, GiveFragsForKill, CBC_ORDER_FIRST)
493 frag_score = 0; // no frags counted in Freeze Tag
497 MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST)
507 self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
510 if(round_handler_IsActive())
511 if(!round_handler_IsRoundStarted())
517 //if(self.freezetag_frozen_timeout > 0 && time < self.freezetag_frozen_timeout)
518 //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);
520 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
524 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
526 FOR_EACH_PLAYER(other)
528 if(other.frozen == 0)
529 if(other.deadflag == DEAD_NO)
530 if(SAME_TEAM(other, self))
531 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
536 other.reviving = true;
541 if(n && self.frozen == 1) // OK, there is at least one teammate reviving us
543 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
544 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
546 if(self.revive_progress >= 1)
548 freezetag_Unfreeze(self);
549 freezetag_count_alive_players();
553 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_AUTO_REVIVED, autocvar_g_freezetag_frozen_maxtime);
554 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_AUTO_REVIVED, self.netname, autocvar_g_freezetag_frozen_maxtime);
558 // EVERY team mate nearby gets a point (even if multiple!)
559 FOR_EACH_PLAYER(other)
563 PlayerScore_Add(other, SP_FREEZETAG_REVIVALS, +1);
564 PlayerScore_Add(other, SP_SCORE, +1);
566 nades_GiveBonus(other,autocvar_g_nades_bonus_score_low);
570 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
571 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
572 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED, self.netname, o.netname);
575 FOR_EACH_PLAYER(other)
579 other.revive_progress = self.revive_progress;
580 other.reviving = false;
584 else if(!n && self.frozen == 1) // only if no teammate is nearby will we reset
586 self.revive_progress = bound(0, self.revive_progress - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
587 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
589 else if(!n && !self.frozen)
591 self.revive_progress = 0; // thawing nobody
597 MUTATOR_HOOKFUNCTION(ft, SetStartItems)
599 start_items &= ~IT_UNLIMITED_AMMO;
600 //start_health = warmup_start_health = cvar("g_lms_start_health");
601 //start_armorvalue = warmup_start_armorvalue = cvar("g_lms_start_armor");
602 start_ammo_shells = warmup_start_ammo_shells = cvar("g_lms_start_ammo_shells");
603 start_ammo_nails = warmup_start_ammo_nails = cvar("g_lms_start_ammo_nails");
604 start_ammo_rockets = warmup_start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
605 start_ammo_cells = warmup_start_ammo_cells = cvar("g_lms_start_ammo_cells");
606 start_ammo_plasma = warmup_start_ammo_plasma = cvar("g_lms_start_ammo_plasma");
607 start_ammo_fuel = warmup_start_ammo_fuel = cvar("g_lms_start_ammo_fuel");
612 MUTATOR_HOOKFUNCTION(ft, HavocBot_ChooseRole)
617 self.havocbot_role = havocbot_role_ft_freeing;
619 self.havocbot_role = havocbot_role_ft_offense;
625 MUTATOR_HOOKFUNCTION(ft, GetTeamCount, CBC_ORDER_EXCLUSIVE)
627 ret_float = freezetag_teams;
631 MUTATOR_HOOKFUNCTION(ft, SetWeaponArena)
633 // most weapons arena
634 if(ret_string == "0" || ret_string == "")
639 void freezetag_Initialize()
641 freezetag_teams = autocvar_g_freezetag_teams_override;
642 if(freezetag_teams < 2)
643 freezetag_teams = autocvar_g_freezetag_teams;
644 freezetag_teams = bound(2, freezetag_teams, 4);
645 freezetag_ScoreRules(freezetag_teams);
647 round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null);
648 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
650 EliminatedPlayers_Init(freezetag_isEliminated);