1 #include "gamemode_freezetag.qh"
5 float autocvar_g_freezetag_frozen_maxtime;
6 bool autocvar_g_freezetag_revive_nade;
7 float autocvar_g_freezetag_revive_nade_health;
8 int autocvar_g_freezetag_point_leadlimit;
9 int autocvar_g_freezetag_point_limit;
10 float autocvar_g_freezetag_revive_extra_size;
11 float autocvar_g_freezetag_revive_speed;
12 float autocvar_g_freezetag_revive_clearspeed;
13 float autocvar_g_freezetag_round_timelimit;
14 int autocvar_g_freezetag_teams;
15 int autocvar_g_freezetag_teams_override;
16 bool autocvar_g_freezetag_team_spawns;
17 float autocvar_g_freezetag_warmup;
19 const float SP_FREEZETAG_REVIVALS = 4;
20 void freezetag_ScoreRules(float teams)
22 ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, true); // SFL_SORT_PRIO_PRIMARY
23 ScoreInfo_SetLabel_PlayerScore(SP_FREEZETAG_REVIVALS, "revivals", 0);
24 ScoreRules_basics_end();
27 void freezetag_count_alive_players()
30 total_players = redalive = bluealive = yellowalive = pinkalive = 0;
35 case NUM_TEAM_1: ++total_players; if(e.health >= 1 && e.frozen != 1) ++redalive; break;
36 case NUM_TEAM_2: ++total_players; if(e.health >= 1 && e.frozen != 1) ++bluealive; break;
37 case NUM_TEAM_3: ++total_players; if(e.health >= 1 && e.frozen != 1) ++yellowalive; break;
38 case NUM_TEAM_4: ++total_players; if(e.health >= 1 && e.frozen != 1) ++pinkalive; break;
41 FOR_EACH_REALCLIENT(e)
43 e.redalive_stat = redalive;
44 e.bluealive_stat = bluealive;
45 e.yellowalive_stat = yellowalive;
46 e.pinkalive_stat = pinkalive;
49 eliminatedPlayers.SendFlags |= 1;
51 #define FREEZETAG_ALIVE_TEAMS() ((redalive > 0) + (bluealive > 0) + (yellowalive > 0) + (pinkalive > 0))
52 #define FREEZETAG_ALIVE_TEAMS_OK() (FREEZETAG_ALIVE_TEAMS() == freezetag_teams)
54 float freezetag_CheckTeams()
56 static float prev_missing_teams_mask;
57 if(FREEZETAG_ALIVE_TEAMS_OK())
59 if(prev_missing_teams_mask > 0)
60 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
61 prev_missing_teams_mask = -1;
64 if(total_players == 0)
66 if(prev_missing_teams_mask > 0)
67 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
68 prev_missing_teams_mask = -1;
71 float missing_teams_mask = (!redalive) + (!bluealive) * 2;
72 if(freezetag_teams >= 3) missing_teams_mask += (!yellowalive) * 4;
73 if(freezetag_teams >= 4) missing_teams_mask += (!pinkalive) * 8;
74 if(prev_missing_teams_mask != missing_teams_mask)
76 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
77 prev_missing_teams_mask = missing_teams_mask;
82 float freezetag_getWinnerTeam()
84 float winner_team = 0;
86 winner_team = NUM_TEAM_1;
89 if(winner_team) return 0;
90 winner_team = NUM_TEAM_2;
94 if(winner_team) return 0;
95 winner_team = NUM_TEAM_3;
99 if(winner_team) return 0;
100 winner_team = NUM_TEAM_4;
104 return -1; // no player left
107 float freezetag_CheckWinner()
110 if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
112 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
113 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
116 e.freezetag_frozen_timeout = 0;
119 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
123 if(FREEZETAG_ALIVE_TEAMS() > 1)
127 winner_team = freezetag_getWinnerTeam();
130 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
131 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
132 TeamScore_AddToTeam(winner_team, ST_SCORE, +1);
134 else if(winner_team == -1)
136 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
137 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
142 e.freezetag_frozen_timeout = 0;
145 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
149 entity freezetag_LastPlayerForTeam()
151 entity pl, last_pl = world;
157 if(pl.team == self.team)
166 void freezetag_LastPlayerForTeam_Notify()
168 if(round_handler_IsActive())
169 if(round_handler_IsRoundStarted())
171 entity pl = freezetag_LastPlayerForTeam();
173 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
177 void freezetag_Add_Score(entity attacker)
181 // you froze your own dumb self
182 // counted as "suicide" already
183 PlayerScore_Add(self, SP_SCORE, -1);
185 else if(IS_PLAYER(attacker))
187 // got frozen by an enemy
188 // counted as "kill" and "death" already
189 PlayerScore_Add(self, SP_SCORE, -1);
190 PlayerScore_Add(attacker, SP_SCORE, +1);
192 // else nothing - got frozen by the game type rules themselves
195 void freezetag_Freeze(entity attacker)
200 if(autocvar_g_freezetag_frozen_maxtime > 0)
201 self.freezetag_frozen_timeout = time + autocvar_g_freezetag_frozen_maxtime;
203 Freeze(self, 0, 1, true);
205 freezetag_count_alive_players();
207 freezetag_Add_Score(attacker);
210 void freezetag_Unfreeze(entity attacker)
212 self.freezetag_frozen_time = 0;
213 self.freezetag_frozen_timeout = 0;
218 float freezetag_isEliminated(entity e)
220 if(IS_PLAYER(e) && (e.frozen == 1 || e.deadflag != DEAD_NO))
230 void() havocbot_role_ft_freeing;
231 void() havocbot_role_ft_offense;
233 void havocbot_goalrating_freeplayers(float ratingscale, vector org, float sradius)
238 FOR_EACH_PLAYER(head)
240 if ((head != self) && (head.team == self.team))
242 if (head.frozen == 1)
244 distance = vlen(head.origin - org);
245 if (distance > sradius)
247 navigation_routerating(head, ratingscale, 2000);
251 // If teamate is not frozen still seek them out as fight better
253 navigation_routerating(head, ratingscale/3, 2000);
259 void havocbot_role_ft_offense()
264 if(self.deadflag != DEAD_NO)
267 if (!self.havocbot_role_timeout)
268 self.havocbot_role_timeout = time + random() * 10 + 20;
270 // Count how many players on team are unfrozen.
272 FOR_EACH_PLAYER(head)
274 if ((head.team == self.team) && (head.frozen != 1))
278 // If only one left on team or if role has timed out then start trying to free players.
279 if (((unfrozen == 0) && (!self.frozen)) || (time > self.havocbot_role_timeout))
281 LOG_TRACE("changing role to freeing\n");
282 self.havocbot_role = havocbot_role_ft_freeing;
283 self.havocbot_role_timeout = 0;
287 if (time > self.bot_strategytime)
289 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
291 navigation_goalrating_start();
292 havocbot_goalrating_items(10000, self.origin, 10000);
293 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
294 havocbot_goalrating_freeplayers(9000, self.origin, 10000);
295 //havocbot_goalrating_waypoints(1, self.origin, 1000);
296 navigation_goalrating_end();
300 void havocbot_role_ft_freeing()
302 if(self.deadflag != DEAD_NO)
305 if (!self.havocbot_role_timeout)
306 self.havocbot_role_timeout = time + random() * 10 + 20;
308 if (time > self.havocbot_role_timeout)
310 LOG_TRACE("changing role to offense\n");
311 self.havocbot_role = havocbot_role_ft_offense;
312 self.havocbot_role_timeout = 0;
316 if (time > self.bot_strategytime)
318 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
320 navigation_goalrating_start();
321 havocbot_goalrating_items(8000, self.origin, 10000);
322 havocbot_goalrating_enemyplayers(10000, self.origin, 10000);
323 havocbot_goalrating_freeplayers(20000, self.origin, 10000);
324 //havocbot_goalrating_waypoints(1, self.origin, 1000);
325 navigation_goalrating_end();
334 void ft_RemovePlayer()
336 self.health = 0; // neccessary to update correctly alive stats
338 freezetag_LastPlayerForTeam_Notify();
339 freezetag_Unfreeze(world);
340 freezetag_count_alive_players();
343 MUTATOR_HOOKFUNCTION(ft, ClientDisconnect)
349 MUTATOR_HOOKFUNCTION(ft, MakePlayerObserver)
355 MUTATOR_HOOKFUNCTION(ft, PlayerDies)
357 if(round_handler_IsActive())
358 if(round_handler_CountdownRunning())
361 freezetag_Unfreeze(world);
362 freezetag_count_alive_players();
363 return 1; // let the player die so that he can respawn whenever he wants
366 // Cases DEATH_TEAMCHANGE and DEATH_AUTOTEAMCHANGE are needed to fix a bug whe
367 // you succeed changing team through the menu: you both really die (gibbing) and get frozen
368 if(ITEM_DAMAGE_NEEDKILL(frag_deathtype)
369 || frag_deathtype == DEATH_TEAMCHANGE.m_id || frag_deathtype == DEATH_AUTOTEAMCHANGE.m_id)
371 // let the player die, he will be automatically frozen when he respawns
374 freezetag_Add_Score(frag_attacker);
375 freezetag_count_alive_players();
376 freezetag_LastPlayerForTeam_Notify();
379 freezetag_Unfreeze(world); // remove ice
380 self.health = 0; // Unfreeze resets health
381 self.freezetag_frozen_timeout = -2; // freeze on respawn
388 freezetag_Freeze(frag_attacker);
389 freezetag_LastPlayerForTeam_Notify();
391 if(frag_attacker == frag_target || frag_attacker == world)
393 if(IS_PLAYER(frag_target))
394 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_SELF);
395 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_SELF, frag_target.netname);
399 if(IS_PLAYER(frag_target))
400 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_FROZEN, frag_attacker.netname);
401 if(IS_PLAYER(frag_attacker))
402 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_FREEZETAG_FREEZE, frag_target.netname);
403 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_FREEZE, frag_target.netname, frag_attacker.netname);
409 MUTATOR_HOOKFUNCTION(ft, PlayerSpawn)
411 if(self.freezetag_frozen_timeout == -1) // if PlayerSpawn is called by reset_map_players
412 return 1; // do nothing, round is starting right now
414 if(self.freezetag_frozen_timeout == -2) // player was dead
416 freezetag_Freeze(world);
420 freezetag_count_alive_players();
422 if(round_handler_IsActive())
423 if(round_handler_IsRoundStarted())
425 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
426 freezetag_Freeze(world);
432 MUTATOR_HOOKFUNCTION(ft, reset_map_players)
438 e.freezetag_frozen_timeout = -1;
441 e.freezetag_frozen_timeout = 0;
443 freezetag_count_alive_players();
447 MUTATOR_HOOKFUNCTION(ft, GiveFragsForKill, CBC_ORDER_FIRST)
449 frag_score = 0; // no frags counted in Freeze Tag
453 MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST)
463 self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
466 if(round_handler_IsActive())
467 if(!round_handler_IsRoundStarted())
473 //if(self.freezetag_frozen_timeout > 0 && time < self.freezetag_frozen_timeout)
474 //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);
476 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
480 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
482 FOR_EACH_PLAYER(other)
484 if(other.frozen == 0)
485 if(other.deadflag == DEAD_NO)
486 if(SAME_TEAM(other, self))
487 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
492 other.reviving = true;
497 if(n && self.frozen == 1) // OK, there is at least one teammate reviving us
499 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
500 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
502 if(self.revive_progress >= 1)
504 freezetag_Unfreeze(self);
505 freezetag_count_alive_players();
509 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_AUTO_REVIVED, autocvar_g_freezetag_frozen_maxtime);
510 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_AUTO_REVIVED, self.netname, autocvar_g_freezetag_frozen_maxtime);
514 // EVERY team mate nearby gets a point (even if multiple!)
515 FOR_EACH_PLAYER(other)
519 PlayerScore_Add(other, SP_FREEZETAG_REVIVALS, +1);
520 PlayerScore_Add(other, SP_SCORE, +1);
522 nades_GiveBonus(other,autocvar_g_nades_bonus_score_low);
526 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
527 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
528 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED, self.netname, o.netname);
531 FOR_EACH_PLAYER(other)
535 other.revive_progress = self.revive_progress;
536 other.reviving = false;
540 else if(!n && self.frozen == 1) // only if no teammate is nearby will we reset
542 self.revive_progress = bound(0, self.revive_progress - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
543 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
545 else if(!n && !self.frozen)
547 self.revive_progress = 0; // thawing nobody
553 MUTATOR_HOOKFUNCTION(ft, SetStartItems)
555 start_items &= ~IT_UNLIMITED_AMMO;
556 //start_health = warmup_start_health = cvar("g_lms_start_health");
557 //start_armorvalue = warmup_start_armorvalue = cvar("g_lms_start_armor");
558 start_ammo_shells = warmup_start_ammo_shells = cvar("g_lms_start_ammo_shells");
559 start_ammo_nails = warmup_start_ammo_nails = cvar("g_lms_start_ammo_nails");
560 start_ammo_rockets = warmup_start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
561 start_ammo_cells = warmup_start_ammo_cells = cvar("g_lms_start_ammo_cells");
562 start_ammo_plasma = warmup_start_ammo_plasma = cvar("g_lms_start_ammo_plasma");
563 start_ammo_fuel = warmup_start_ammo_fuel = cvar("g_lms_start_ammo_fuel");
568 MUTATOR_HOOKFUNCTION(ft, HavocBot_ChooseRole)
573 self.havocbot_role = havocbot_role_ft_freeing;
575 self.havocbot_role = havocbot_role_ft_offense;
581 MUTATOR_HOOKFUNCTION(ft, GetTeamCount, CBC_ORDER_EXCLUSIVE)
583 ret_float = freezetag_teams;
587 void freezetag_Initialize()
589 freezetag_teams = autocvar_g_freezetag_teams_override;
590 if(freezetag_teams < 2)
591 freezetag_teams = autocvar_g_freezetag_teams;
592 freezetag_teams = bound(2, freezetag_teams, 4);
593 freezetag_ScoreRules(freezetag_teams);
595 round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null);
596 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
598 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
599 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
600 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
601 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
603 EliminatedPlayers_Init(freezetag_isEliminated);
606 REGISTER_MUTATOR(ft, g_freezetag)
609 SetLimits(autocvar_g_freezetag_point_limit, autocvar_g_freezetag_point_leadlimit, -1, -1);
611 if(autocvar_g_freezetag_team_spawns)
612 have_team_spawns = -1; // request team spawns
616 if(time > 1) // game loads at time 1
617 error("This is a game type and it cannot be added at runtime.");
618 freezetag_Initialize();
621 MUTATOR_ONROLLBACK_OR_REMOVE
623 // we actually cannot roll back freezetag_Initialize here
624 // BUT: we don't need to! If this gets called, adding always
630 LOG_INFO("This is a game type and it cannot be removed at runtime.");