1 #ifndef GAMEMODE_FREEZETAG_H
2 #define GAMEMODE_FREEZETAG_H
4 .float freezetag_frozen_time;
5 .float freezetag_frozen_timeout;
6 const float ICE_MAX_ALPHA = 1;
7 const float ICE_MIN_ALPHA = 0.1;
10 .float reviving; // temp var
15 float autocvar_g_freezetag_frozen_maxtime;
16 bool autocvar_g_freezetag_revive_nade;
17 float autocvar_g_freezetag_revive_nade_health;
18 int autocvar_g_freezetag_point_leadlimit;
19 int autocvar_g_freezetag_point_limit;
20 float autocvar_g_freezetag_revive_extra_size;
21 float autocvar_g_freezetag_revive_speed;
22 float autocvar_g_freezetag_revive_clearspeed;
23 float autocvar_g_freezetag_round_timelimit;
24 int autocvar_g_freezetag_teams;
25 int autocvar_g_freezetag_teams_override;
26 bool autocvar_g_freezetag_team_spawns;
27 float autocvar_g_freezetag_warmup;
29 const float SP_FREEZETAG_REVIVALS = 4;
30 void freezetag_ScoreRules(float teams)
32 ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, true); // SFL_SORT_PRIO_PRIMARY
33 ScoreInfo_SetLabel_PlayerScore(SP_FREEZETAG_REVIVALS, "revivals", 0);
34 ScoreRules_basics_end();
37 void freezetag_count_alive_players()
40 total_players = redalive = bluealive = yellowalive = pinkalive = 0;
45 case NUM_TEAM_1: ++total_players; if(e.health >= 1 && e.frozen != 1) ++redalive; break;
46 case NUM_TEAM_2: ++total_players; if(e.health >= 1 && e.frozen != 1) ++bluealive; break;
47 case NUM_TEAM_3: ++total_players; if(e.health >= 1 && e.frozen != 1) ++yellowalive; break;
48 case NUM_TEAM_4: ++total_players; if(e.health >= 1 && e.frozen != 1) ++pinkalive; break;
51 FOR_EACH_REALCLIENT(e)
53 e.redalive_stat = redalive;
54 e.bluealive_stat = bluealive;
55 e.yellowalive_stat = yellowalive;
56 e.pinkalive_stat = pinkalive;
59 eliminatedPlayers.SendFlags |= 1;
61 #define FREEZETAG_ALIVE_TEAMS() ((redalive > 0) + (bluealive > 0) + (yellowalive > 0) + (pinkalive > 0))
62 #define FREEZETAG_ALIVE_TEAMS_OK() (FREEZETAG_ALIVE_TEAMS() == freezetag_teams)
64 float freezetag_CheckTeams()
66 static float prev_missing_teams_mask;
67 if(FREEZETAG_ALIVE_TEAMS_OK())
69 if(prev_missing_teams_mask > 0)
70 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
71 prev_missing_teams_mask = -1;
74 if(total_players == 0)
76 if(prev_missing_teams_mask > 0)
77 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
78 prev_missing_teams_mask = -1;
81 float missing_teams_mask = (!redalive) + (!bluealive) * 2;
82 if(freezetag_teams >= 3) missing_teams_mask += (!yellowalive) * 4;
83 if(freezetag_teams >= 4) missing_teams_mask += (!pinkalive) * 8;
84 if(prev_missing_teams_mask != missing_teams_mask)
86 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
87 prev_missing_teams_mask = missing_teams_mask;
92 float freezetag_getWinnerTeam()
94 float winner_team = 0;
96 winner_team = NUM_TEAM_1;
99 if(winner_team) return 0;
100 winner_team = NUM_TEAM_2;
104 if(winner_team) return 0;
105 winner_team = NUM_TEAM_3;
109 if(winner_team) return 0;
110 winner_team = NUM_TEAM_4;
114 return -1; // no player left
117 float freezetag_CheckWinner()
120 if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
122 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
123 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
126 e.freezetag_frozen_timeout = 0;
129 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
133 if(FREEZETAG_ALIVE_TEAMS() > 1)
137 winner_team = freezetag_getWinnerTeam();
140 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
141 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
142 TeamScore_AddToTeam(winner_team, ST_SCORE, +1);
144 else if(winner_team == -1)
146 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
147 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
152 e.freezetag_frozen_timeout = 0;
155 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
159 entity freezetag_LastPlayerForTeam()
161 entity pl, last_pl = world;
167 if(pl.team == self.team)
176 void freezetag_LastPlayerForTeam_Notify()
178 if(round_handler_IsActive())
179 if(round_handler_IsRoundStarted())
181 entity pl = freezetag_LastPlayerForTeam();
183 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
187 void freezetag_Add_Score(entity attacker)
191 // you froze your own dumb self
192 // counted as "suicide" already
193 PlayerScore_Add(self, SP_SCORE, -1);
195 else if(IS_PLAYER(attacker))
197 // got frozen by an enemy
198 // counted as "kill" and "death" already
199 PlayerScore_Add(self, SP_SCORE, -1);
200 PlayerScore_Add(attacker, SP_SCORE, +1);
202 // else nothing - got frozen by the game type rules themselves
205 void freezetag_Freeze(entity attacker)
210 if(autocvar_g_freezetag_frozen_maxtime > 0)
211 self.freezetag_frozen_timeout = time + autocvar_g_freezetag_frozen_maxtime;
213 Freeze(self, 0, 1, true);
215 freezetag_count_alive_players();
217 freezetag_Add_Score(attacker);
220 void freezetag_Unfreeze(entity attacker)
222 self.freezetag_frozen_time = 0;
223 self.freezetag_frozen_timeout = 0;
228 float freezetag_isEliminated(entity e)
230 if(IS_PLAYER(e) && (e.frozen == 1 || e.deadflag != DEAD_NO))
240 void() havocbot_role_ft_freeing;
241 void() havocbot_role_ft_offense;
243 void havocbot_goalrating_freeplayers(float ratingscale, vector org, float sradius)
248 FOR_EACH_PLAYER(head)
250 if ((head != self) && (head.team == self.team))
252 if (head.frozen == 1)
254 distance = vlen(head.origin - org);
255 if (distance > sradius)
257 navigation_routerating(head, ratingscale, 2000);
261 // If teamate is not frozen still seek them out as fight better
263 navigation_routerating(head, ratingscale/3, 2000);
269 void havocbot_role_ft_offense()
274 if(self.deadflag != DEAD_NO)
277 if (!self.havocbot_role_timeout)
278 self.havocbot_role_timeout = time + random() * 10 + 20;
280 // Count how many players on team are unfrozen.
282 FOR_EACH_PLAYER(head)
284 if ((head.team == self.team) && (head.frozen != 1))
288 // If only one left on team or if role has timed out then start trying to free players.
289 if (((unfrozen == 0) && (!self.frozen)) || (time > self.havocbot_role_timeout))
291 LOG_TRACE("changing role to freeing\n");
292 self.havocbot_role = havocbot_role_ft_freeing;
293 self.havocbot_role_timeout = 0;
297 if (time > self.bot_strategytime)
299 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
301 navigation_goalrating_start();
302 havocbot_goalrating_items(10000, self.origin, 10000);
303 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
304 havocbot_goalrating_freeplayers(9000, self.origin, 10000);
305 //havocbot_goalrating_waypoints(1, self.origin, 1000);
306 navigation_goalrating_end();
310 void havocbot_role_ft_freeing()
312 if(self.deadflag != DEAD_NO)
315 if (!self.havocbot_role_timeout)
316 self.havocbot_role_timeout = time + random() * 10 + 20;
318 if (time > self.havocbot_role_timeout)
320 LOG_TRACE("changing role to offense\n");
321 self.havocbot_role = havocbot_role_ft_offense;
322 self.havocbot_role_timeout = 0;
326 if (time > self.bot_strategytime)
328 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
330 navigation_goalrating_start();
331 havocbot_goalrating_items(8000, self.origin, 10000);
332 havocbot_goalrating_enemyplayers(10000, self.origin, 10000);
333 havocbot_goalrating_freeplayers(20000, self.origin, 10000);
334 //havocbot_goalrating_waypoints(1, self.origin, 1000);
335 navigation_goalrating_end();
344 void ft_RemovePlayer()
346 self.health = 0; // neccessary to update correctly alive stats
348 freezetag_LastPlayerForTeam_Notify();
349 freezetag_Unfreeze(world);
350 freezetag_count_alive_players();
353 MUTATOR_HOOKFUNCTION(ft, ClientDisconnect)
359 MUTATOR_HOOKFUNCTION(ft, MakePlayerObserver)
365 MUTATOR_HOOKFUNCTION(ft, PlayerDies)
367 if(round_handler_IsActive())
368 if(round_handler_CountdownRunning())
371 freezetag_Unfreeze(world);
372 freezetag_count_alive_players();
373 return 1; // let the player die so that he can respawn whenever he wants
376 // Cases DEATH_TEAMCHANGE and DEATH_AUTOTEAMCHANGE are needed to fix a bug whe
377 // you succeed changing team through the menu: you both really die (gibbing) and get frozen
378 if(ITEM_DAMAGE_NEEDKILL(frag_deathtype)
379 || frag_deathtype == DEATH_TEAMCHANGE.m_id || frag_deathtype == DEATH_AUTOTEAMCHANGE.m_id)
381 // let the player die, he will be automatically frozen when he respawns
384 freezetag_Add_Score(frag_attacker);
385 freezetag_count_alive_players();
386 freezetag_LastPlayerForTeam_Notify();
389 freezetag_Unfreeze(world); // remove ice
390 self.health = 0; // Unfreeze resets health
391 self.freezetag_frozen_timeout = -2; // freeze on respawn
398 freezetag_Freeze(frag_attacker);
399 freezetag_LastPlayerForTeam_Notify();
401 if(frag_attacker == frag_target || frag_attacker == world)
403 if(IS_PLAYER(frag_target))
404 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_SELF);
405 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_SELF, frag_target.netname);
409 if(IS_PLAYER(frag_target))
410 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_FROZEN, frag_attacker.netname);
411 if(IS_PLAYER(frag_attacker))
412 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_FREEZETAG_FREEZE, frag_target.netname);
413 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_FREEZE, frag_target.netname, frag_attacker.netname);
419 MUTATOR_HOOKFUNCTION(ft, PlayerSpawn)
421 if(self.freezetag_frozen_timeout == -1) // if PlayerSpawn is called by reset_map_players
422 return 1; // do nothing, round is starting right now
424 if(self.freezetag_frozen_timeout == -2) // player was dead
426 freezetag_Freeze(world);
430 freezetag_count_alive_players();
432 if(round_handler_IsActive())
433 if(round_handler_IsRoundStarted())
435 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
436 freezetag_Freeze(world);
442 MUTATOR_HOOKFUNCTION(ft, reset_map_players)
448 e.freezetag_frozen_timeout = -1;
451 e.freezetag_frozen_timeout = 0;
453 freezetag_count_alive_players();
457 MUTATOR_HOOKFUNCTION(ft, GiveFragsForKill, CBC_ORDER_FIRST)
459 frag_score = 0; // no frags counted in Freeze Tag
463 MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST)
473 self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
476 if(round_handler_IsActive())
477 if(!round_handler_IsRoundStarted())
483 //if(self.freezetag_frozen_timeout > 0 && time < self.freezetag_frozen_timeout)
484 //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);
486 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
490 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
492 FOR_EACH_PLAYER(other)
494 if(other.frozen == 0)
495 if(other.deadflag == DEAD_NO)
496 if(SAME_TEAM(other, self))
497 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
502 other.reviving = true;
507 if(n && self.frozen == 1) // OK, there is at least one teammate reviving us
509 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
510 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
512 if(self.revive_progress >= 1)
514 freezetag_Unfreeze(self);
515 freezetag_count_alive_players();
519 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_AUTO_REVIVED, autocvar_g_freezetag_frozen_maxtime);
520 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_AUTO_REVIVED, self.netname, autocvar_g_freezetag_frozen_maxtime);
524 // EVERY team mate nearby gets a point (even if multiple!)
525 FOR_EACH_PLAYER(other)
529 PlayerScore_Add(other, SP_FREEZETAG_REVIVALS, +1);
530 PlayerScore_Add(other, SP_SCORE, +1);
532 nades_GiveBonus(other,autocvar_g_nades_bonus_score_low);
536 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
537 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
538 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED, self.netname, o.netname);
541 FOR_EACH_PLAYER(other)
545 other.revive_progress = self.revive_progress;
546 other.reviving = false;
550 else if(!n && self.frozen == 1) // only if no teammate is nearby will we reset
552 self.revive_progress = bound(0, self.revive_progress - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
553 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
555 else if(!n && !self.frozen)
557 self.revive_progress = 0; // thawing nobody
563 MUTATOR_HOOKFUNCTION(ft, SetStartItems)
565 start_items &= ~IT_UNLIMITED_AMMO;
566 //start_health = warmup_start_health = cvar("g_lms_start_health");
567 //start_armorvalue = warmup_start_armorvalue = cvar("g_lms_start_armor");
568 start_ammo_shells = warmup_start_ammo_shells = cvar("g_lms_start_ammo_shells");
569 start_ammo_nails = warmup_start_ammo_nails = cvar("g_lms_start_ammo_nails");
570 start_ammo_rockets = warmup_start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
571 start_ammo_cells = warmup_start_ammo_cells = cvar("g_lms_start_ammo_cells");
572 start_ammo_plasma = warmup_start_ammo_plasma = cvar("g_lms_start_ammo_plasma");
573 start_ammo_fuel = warmup_start_ammo_fuel = cvar("g_lms_start_ammo_fuel");
578 MUTATOR_HOOKFUNCTION(ft, HavocBot_ChooseRole)
583 self.havocbot_role = havocbot_role_ft_freeing;
585 self.havocbot_role = havocbot_role_ft_offense;
591 MUTATOR_HOOKFUNCTION(ft, GetTeamCount, CBC_ORDER_EXCLUSIVE)
593 ret_float = freezetag_teams;
597 MUTATOR_HOOKFUNCTION(ft, SetWeaponArena)
599 // most weapons arena
600 if(ret_string == "0" || ret_string == "")
605 void freezetag_Initialize()
607 freezetag_teams = autocvar_g_freezetag_teams_override;
608 if(freezetag_teams < 2)
609 freezetag_teams = autocvar_g_freezetag_teams;
610 freezetag_teams = bound(2, freezetag_teams, 4);
611 freezetag_ScoreRules(freezetag_teams);
613 round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null);
614 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
616 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
617 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
618 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
619 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
621 EliminatedPlayers_Init(freezetag_isEliminated);
624 REGISTER_MUTATOR(ft, g_freezetag)
627 SetLimits(autocvar_g_freezetag_point_limit, autocvar_g_freezetag_point_leadlimit, -1, -1);
629 if(autocvar_g_freezetag_team_spawns)
630 have_team_spawns = -1; // request team spawns
634 if(time > 1) // game loads at time 1
635 error("This is a game type and it cannot be added at runtime.");
636 freezetag_Initialize();
639 MUTATOR_ONROLLBACK_OR_REMOVE
641 // we actually cannot roll back freezetag_Initialize here
642 // BUT: we don't need to! If this gets called, adding always
648 LOG_INFO("This is a game type and it cannot be removed at runtime.");