1 #include "gamemode_freezetag.qh"
5 const float SP_FREEZETAG_REVIVALS = 4;
6 void freezetag_ScoreRules(float teams)
8 ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, true); // SFL_SORT_PRIO_PRIMARY
9 ScoreInfo_SetLabel_PlayerScore(SP_FREEZETAG_REVIVALS, "revivals", 0);
10 ScoreRules_basics_end();
13 void freezetag_count_alive_players()
16 total_players = redalive = bluealive = yellowalive = pinkalive = 0;
21 case NUM_TEAM_1: ++total_players; if(e.health >= 1 && e.frozen != 1) ++redalive; break;
22 case NUM_TEAM_2: ++total_players; if(e.health >= 1 && e.frozen != 1) ++bluealive; break;
23 case NUM_TEAM_3: ++total_players; if(e.health >= 1 && e.frozen != 1) ++yellowalive; break;
24 case NUM_TEAM_4: ++total_players; if(e.health >= 1 && e.frozen != 1) ++pinkalive; break;
27 FOR_EACH_REALCLIENT(e)
29 e.redalive_stat = redalive;
30 e.bluealive_stat = bluealive;
31 e.yellowalive_stat = yellowalive;
32 e.pinkalive_stat = pinkalive;
35 eliminatedPlayers.SendFlags |= 1;
37 #define FREEZETAG_ALIVE_TEAMS() ((redalive > 0) + (bluealive > 0) + (yellowalive > 0) + (pinkalive > 0))
38 #define FREEZETAG_ALIVE_TEAMS_OK() (FREEZETAG_ALIVE_TEAMS() == freezetag_teams)
40 float freezetag_CheckTeams()
42 static float prev_missing_teams_mask;
43 if(FREEZETAG_ALIVE_TEAMS_OK())
45 if(prev_missing_teams_mask > 0)
46 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
47 prev_missing_teams_mask = -1;
50 if(total_players == 0)
52 if(prev_missing_teams_mask > 0)
53 Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
54 prev_missing_teams_mask = -1;
57 float missing_teams_mask = (!redalive) + (!bluealive) * 2;
58 if(freezetag_teams >= 3) missing_teams_mask += (!yellowalive) * 4;
59 if(freezetag_teams >= 4) missing_teams_mask += (!pinkalive) * 8;
60 if(prev_missing_teams_mask != missing_teams_mask)
62 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_MISSING_TEAMS, missing_teams_mask);
63 prev_missing_teams_mask = missing_teams_mask;
68 float freezetag_getWinnerTeam()
70 float winner_team = 0;
72 winner_team = NUM_TEAM_1;
75 if(winner_team) return 0;
76 winner_team = NUM_TEAM_2;
80 if(winner_team) return 0;
81 winner_team = NUM_TEAM_3;
85 if(winner_team) return 0;
86 winner_team = NUM_TEAM_4;
90 return -1; // no player left
93 float freezetag_CheckWinner()
96 if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
98 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
99 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
102 e.freezetag_frozen_timeout = 0;
105 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
109 if(FREEZETAG_ALIVE_TEAMS() > 1)
113 winner_team = freezetag_getWinnerTeam();
116 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
117 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
118 TeamScore_AddToTeam(winner_team, ST_SCORE, +1);
120 else if(winner_team == -1)
122 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
123 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
128 e.freezetag_frozen_timeout = 0;
131 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
135 entity freezetag_LastPlayerForTeam()
137 entity pl, last_pl = world;
143 if(pl.team == self.team)
152 void freezetag_LastPlayerForTeam_Notify()
154 if(round_handler_IsActive())
155 if(round_handler_IsRoundStarted())
157 entity pl = freezetag_LastPlayerForTeam();
159 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
163 void freezetag_Add_Score(entity attacker)
167 // you froze your own dumb self
168 // counted as "suicide" already
169 PlayerScore_Add(self, SP_SCORE, -1);
171 else if(IS_PLAYER(attacker))
173 // got frozen by an enemy
174 // counted as "kill" and "death" already
175 PlayerScore_Add(self, SP_SCORE, -1);
176 PlayerScore_Add(attacker, SP_SCORE, +1);
178 // else nothing - got frozen by the game type rules themselves
181 void freezetag_Freeze(entity attacker)
186 if(autocvar_g_freezetag_frozen_maxtime > 0)
187 self.freezetag_frozen_timeout = time + autocvar_g_freezetag_frozen_maxtime;
189 Freeze(self, 0, 1, true);
191 freezetag_count_alive_players();
193 freezetag_Add_Score(attacker);
196 void freezetag_Unfreeze(entity attacker)
198 self.freezetag_frozen_time = 0;
199 self.freezetag_frozen_timeout = 0;
204 float freezetag_isEliminated(entity e)
206 if(IS_PLAYER(e) && (e.frozen == 1 || e.deadflag != DEAD_NO))
216 void() havocbot_role_ft_freeing;
217 void() havocbot_role_ft_offense;
219 void havocbot_goalrating_freeplayers(float ratingscale, vector org, float sradius)
224 FOR_EACH_PLAYER(head)
226 if ((head != self) && (head.team == self.team))
228 if (head.frozen == 1)
230 distance = vlen(head.origin - org);
231 if (distance > sradius)
233 navigation_routerating(head, ratingscale, 2000);
237 // If teamate is not frozen still seek them out as fight better
239 navigation_routerating(head, ratingscale/3, 2000);
245 void havocbot_role_ft_offense()
250 if(self.deadflag != DEAD_NO)
253 if (!self.havocbot_role_timeout)
254 self.havocbot_role_timeout = time + random() * 10 + 20;
256 // Count how many players on team are unfrozen.
258 FOR_EACH_PLAYER(head)
260 if ((head.team == self.team) && (head.frozen != 1))
264 // If only one left on team or if role has timed out then start trying to free players.
265 if (((unfrozen == 0) && (!self.frozen)) || (time > self.havocbot_role_timeout))
267 LOG_TRACE("changing role to freeing\n");
268 self.havocbot_role = havocbot_role_ft_freeing;
269 self.havocbot_role_timeout = 0;
273 if (time > self.bot_strategytime)
275 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
277 navigation_goalrating_start();
278 havocbot_goalrating_items(10000, self.origin, 10000);
279 havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
280 havocbot_goalrating_freeplayers(9000, self.origin, 10000);
281 //havocbot_goalrating_waypoints(1, self.origin, 1000);
282 navigation_goalrating_end();
286 void havocbot_role_ft_freeing()
288 if(self.deadflag != DEAD_NO)
291 if (!self.havocbot_role_timeout)
292 self.havocbot_role_timeout = time + random() * 10 + 20;
294 if (time > self.havocbot_role_timeout)
296 LOG_TRACE("changing role to offense\n");
297 self.havocbot_role = havocbot_role_ft_offense;
298 self.havocbot_role_timeout = 0;
302 if (time > self.bot_strategytime)
304 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
306 navigation_goalrating_start();
307 havocbot_goalrating_items(8000, self.origin, 10000);
308 havocbot_goalrating_enemyplayers(10000, self.origin, 10000);
309 havocbot_goalrating_freeplayers(20000, self.origin, 10000);
310 //havocbot_goalrating_waypoints(1, self.origin, 1000);
311 navigation_goalrating_end();
320 MUTATOR_HOOKFUNCTION(freezetag_RemovePlayer)
322 self.health = 0; // neccessary to update correctly alive stats
324 freezetag_LastPlayerForTeam_Notify();
325 freezetag_Unfreeze(world);
326 freezetag_count_alive_players();
330 MUTATOR_HOOKFUNCTION(freezetag_PlayerDies)
332 if(round_handler_IsActive())
333 if(round_handler_CountdownRunning())
336 freezetag_Unfreeze(world);
337 freezetag_count_alive_players();
338 return 1; // let the player die so that he can respawn whenever he wants
341 // Cases DEATH_TEAMCHANGE and DEATH_AUTOTEAMCHANGE are needed to fix a bug whe
342 // you succeed changing team through the menu: you both really die (gibbing) and get frozen
343 if(ITEM_DAMAGE_NEEDKILL(frag_deathtype)
344 || frag_deathtype == DEATH_TEAMCHANGE || frag_deathtype == DEATH_AUTOTEAMCHANGE)
346 // let the player die, he will be automatically frozen when he respawns
349 freezetag_Add_Score(frag_attacker);
350 freezetag_count_alive_players();
351 freezetag_LastPlayerForTeam_Notify();
354 freezetag_Unfreeze(world); // remove ice
355 self.health = 0; // Unfreeze resets health
356 self.freezetag_frozen_timeout = -2; // freeze on respawn
363 freezetag_Freeze(frag_attacker);
364 freezetag_LastPlayerForTeam_Notify();
366 if(frag_attacker == frag_target || frag_attacker == world)
368 if(IS_PLAYER(frag_target))
369 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_SELF);
370 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_SELF, frag_target.netname);
374 if(IS_PLAYER(frag_target))
375 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_FROZEN, frag_attacker.netname);
376 if(IS_PLAYER(frag_attacker))
377 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CENTER, CENTER_FREEZETAG_FREEZE, frag_target.netname);
378 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_FREEZE, frag_target.netname, frag_attacker.netname);
384 MUTATOR_HOOKFUNCTION(freezetag_PlayerSpawn)
386 if(self.freezetag_frozen_timeout == -1) // if PlayerSpawn is called by reset_map_players
387 return 1; // do nothing, round is starting right now
389 if(self.freezetag_frozen_timeout == -2) // player was dead
391 freezetag_Freeze(world);
395 freezetag_count_alive_players();
397 if(round_handler_IsActive())
398 if(round_handler_IsRoundStarted())
400 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
401 freezetag_Freeze(world);
407 MUTATOR_HOOKFUNCTION(freezetag_reset_map_players)
413 e.freezetag_frozen_timeout = -1;
416 e.freezetag_frozen_timeout = 0;
418 freezetag_count_alive_players();
422 MUTATOR_HOOKFUNCTION(freezetag_GiveFragsForKill)
424 frag_score = 0; // no frags counted in Freeze Tag
428 MUTATOR_HOOKFUNCTION(freezetag_PlayerPreThink)
438 self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
441 if(round_handler_IsActive())
442 if(!round_handler_IsRoundStarted())
448 //if(self.freezetag_frozen_timeout > 0 && time < self.freezetag_frozen_timeout)
449 //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);
451 if(self.freezetag_frozen_timeout > 0 && time >= self.freezetag_frozen_timeout)
455 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
457 FOR_EACH_PLAYER(other)
459 if(other.frozen == 0)
460 if(other.deadflag == DEAD_NO)
461 if(SAME_TEAM(other, self))
462 if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
467 other.reviving = true;
472 if(n && self.frozen == 1) // OK, there is at least one teammate reviving us
474 self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
475 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
477 if(self.revive_progress >= 1)
479 freezetag_Unfreeze(self);
480 freezetag_count_alive_players();
484 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_AUTO_REVIVED, autocvar_g_freezetag_frozen_maxtime);
485 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_AUTO_REVIVED, self.netname, autocvar_g_freezetag_frozen_maxtime);
489 // EVERY team mate nearby gets a point (even if multiple!)
490 FOR_EACH_PLAYER(other)
494 PlayerScore_Add(other, SP_FREEZETAG_REVIVALS, +1);
495 PlayerScore_Add(other, SP_SCORE, +1);
497 nades_GiveBonus(other,autocvar_g_nades_bonus_score_low);
501 Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
502 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
503 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED, self.netname, o.netname);
506 FOR_EACH_PLAYER(other)
510 other.revive_progress = self.revive_progress;
511 other.reviving = false;
515 else if(!n && self.frozen == 1) // only if no teammate is nearby will we reset
517 self.revive_progress = bound(0, self.revive_progress - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
518 self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
520 else if(!n && !self.frozen)
522 self.revive_progress = 0; // thawing nobody
528 MUTATOR_HOOKFUNCTION(freezetag_SetStartItems)
530 start_items &= ~IT_UNLIMITED_AMMO;
531 //start_health = warmup_start_health = cvar("g_lms_start_health");
532 //start_armorvalue = warmup_start_armorvalue = cvar("g_lms_start_armor");
533 start_ammo_shells = warmup_start_ammo_shells = cvar("g_lms_start_ammo_shells");
534 start_ammo_nails = warmup_start_ammo_nails = cvar("g_lms_start_ammo_nails");
535 start_ammo_rockets = warmup_start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
536 start_ammo_cells = warmup_start_ammo_cells = cvar("g_lms_start_ammo_cells");
537 start_ammo_plasma = warmup_start_ammo_plasma = cvar("g_lms_start_ammo_plasma");
538 start_ammo_fuel = warmup_start_ammo_fuel = cvar("g_lms_start_ammo_fuel");
543 MUTATOR_HOOKFUNCTION(freezetag_BotRoles)
548 self.havocbot_role = havocbot_role_ft_freeing;
550 self.havocbot_role = havocbot_role_ft_offense;
556 MUTATOR_HOOKFUNCTION(freezetag_GetTeamCount)
558 ret_float = freezetag_teams;
562 void freezetag_Initialize()
564 freezetag_teams = autocvar_g_freezetag_teams_override;
565 if(freezetag_teams < 2)
566 freezetag_teams = autocvar_g_freezetag_teams;
567 freezetag_teams = bound(2, freezetag_teams, 4);
568 freezetag_ScoreRules(freezetag_teams);
570 round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null);
571 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
573 addstat(STAT_REDALIVE, AS_INT, redalive_stat);
574 addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
575 addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
576 addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
578 EliminatedPlayers_Init(freezetag_isEliminated);
581 MUTATOR_DEFINITION(gamemode_freezetag)
583 MUTATOR_HOOK(MakePlayerObserver, freezetag_RemovePlayer, CBC_ORDER_ANY);
584 MUTATOR_HOOK(ClientDisconnect, freezetag_RemovePlayer, CBC_ORDER_ANY);
585 MUTATOR_HOOK(PlayerDies, freezetag_PlayerDies, CBC_ORDER_ANY);
586 MUTATOR_HOOK(PlayerSpawn, freezetag_PlayerSpawn, CBC_ORDER_ANY);
587 MUTATOR_HOOK(reset_map_players, freezetag_reset_map_players, CBC_ORDER_ANY);
588 MUTATOR_HOOK(GiveFragsForKill, freezetag_GiveFragsForKill, CBC_ORDER_FIRST);
589 MUTATOR_HOOK(PlayerPreThink, freezetag_PlayerPreThink, CBC_ORDER_FIRST);
590 MUTATOR_HOOK(SetStartItems, freezetag_SetStartItems, CBC_ORDER_ANY);
591 MUTATOR_HOOK(HavocBot_ChooseRole, freezetag_BotRoles, CBC_ORDER_ANY);
592 MUTATOR_HOOK(GetTeamCount, freezetag_GetTeamCount, CBC_ORDER_EXCLUSIVE);
596 if(time > 1) // game loads at time 1
597 error("This is a game type and it cannot be added at runtime.");
598 freezetag_Initialize();
601 MUTATOR_ONROLLBACK_OR_REMOVE
603 // we actually cannot roll back freezetag_Initialize here
604 // BUT: we don't need to! If this gets called, adding always
610 LOG_INFO("This is a game type and it cannot be removed at runtime.");