1 #include "gamemode_freezetag.qh"
3 float autocvar_g_freezetag_frozen_maxtime;
4 float autocvar_g_freezetag_revive_clearspeed;
5 float autocvar_g_freezetag_round_timelimit;
6 //int autocvar_g_freezetag_teams;
7 int autocvar_g_freezetag_teams_override;
8 float autocvar_g_freezetag_warmup;
10 void freezetag_count_alive_players()
12 total_players = redalive = bluealive = yellowalive = pinkalive = 0;
13 FOREACH_CLIENT(IS_PLAYER(it), {
16 case NUM_TEAM_1: ++total_players; if(it.health >= 1 && STAT(FROZEN, it) != 1) ++redalive; break;
17 case NUM_TEAM_2: ++total_players; if(it.health >= 1 && STAT(FROZEN, it) != 1) ++bluealive; break;
18 case NUM_TEAM_3: ++total_players; if(it.health >= 1 && STAT(FROZEN, it) != 1) ++yellowalive; break;
19 case NUM_TEAM_4: ++total_players; if(it.health >= 1 && STAT(FROZEN, it) != 1) ++pinkalive; break;
22 FOREACH_CLIENT(IS_REAL_CLIENT(it), {
23 STAT(REDALIVE, it) = redalive;
24 STAT(BLUEALIVE, it) = bluealive;
25 STAT(YELLOWALIVE, it) = yellowalive;
26 STAT(PINKALIVE, it) = pinkalive;
29 eliminatedPlayers.SendFlags |= 1;
31 #define FREEZETAG_ALIVE_TEAMS() ((redalive > 0) + (bluealive > 0) + (yellowalive > 0) + (pinkalive > 0))
32 #define FREEZETAG_ALIVE_TEAMS_OK() (FREEZETAG_ALIVE_TEAMS() == NumTeams(freezetag_teams))
34 float freezetag_CheckTeams()
36 static float prev_missing_teams_mask;
37 if(FREEZETAG_ALIVE_TEAMS_OK())
39 if(prev_missing_teams_mask > 0)
40 Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_TEAMS);
41 prev_missing_teams_mask = -1;
44 if(total_players == 0)
46 if(prev_missing_teams_mask > 0)
47 Kill_Notification(NOTIF_ALL, NULL, MSG_CENTER, CPID_MISSING_TEAMS);
48 prev_missing_teams_mask = -1;
51 int missing_teams_mask = 0;
52 if(freezetag_teams & BIT(0))
53 missing_teams_mask += (!redalive) * 1;
54 if(freezetag_teams & BIT(1))
55 missing_teams_mask += (!bluealive) * 2;
56 if(freezetag_teams & BIT(2))
57 missing_teams_mask += (!yellowalive) * 4;
58 if(freezetag_teams & BIT(3))
59 missing_teams_mask += (!pinkalive) * 8;
60 if(prev_missing_teams_mask != missing_teams_mask)
62 Send_Notification(NOTIF_ALL, NULL, 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 void nades_Clear(entity);
94 void nades_GiveBonus(entity player, float score);
96 float freezetag_CheckWinner()
98 if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
100 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_OVER);
101 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_OVER);
102 FOREACH_CLIENT(IS_PLAYER(it), {
103 it.freezetag_frozen_timeout = 0;
107 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
111 if(FREEZETAG_ALIVE_TEAMS() > 1)
114 int winner_team = freezetag_getWinnerTeam();
117 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
118 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
119 TeamScore_AddToTeam(winner_team, ST_SCORE, +1);
121 else if(winner_team == -1)
123 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_TIED);
124 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_TIED);
127 FOREACH_CLIENT(IS_PLAYER(it), {
128 it.freezetag_frozen_timeout = 0;
133 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
137 entity freezetag_LastPlayerForTeam(entity this)
139 entity last_pl = NULL;
140 FOREACH_CLIENT(IS_PLAYER(it) && it != this, {
142 if(!STAT(FROZEN, it))
143 if(SAME_TEAM(it, this))
152 void freezetag_LastPlayerForTeam_Notify(entity this)
154 if(round_handler_IsActive())
155 if(round_handler_IsRoundStarted())
157 entity pl = freezetag_LastPlayerForTeam(this);
159 Send_Notification(NOTIF_ONE, pl, MSG_CENTER, CENTER_ALONE);
163 void freezetag_Add_Score(entity targ, entity attacker)
167 // you froze your own dumb targ
168 // counted as "suicide" already
169 GameRules_scoring_add(targ, SCORE, -1);
171 else if(IS_PLAYER(attacker))
173 // got frozen by an enemy
174 // counted as "kill" and "death" already
175 GameRules_scoring_add(targ, SCORE, -1);
176 GameRules_scoring_add(attacker, SCORE, +1);
178 // else nothing - got frozen by the game type rules themselves
181 void freezetag_Freeze(entity targ, entity attacker)
183 if(STAT(FROZEN, targ))
186 if(autocvar_g_freezetag_frozen_maxtime > 0)
187 targ.freezetag_frozen_timeout = time + autocvar_g_freezetag_frozen_maxtime;
189 Freeze(targ, 0, 1, true);
191 freezetag_count_alive_players();
193 freezetag_Add_Score(targ, attacker);
196 void freezetag_Unfreeze(entity this)
198 this.freezetag_frozen_time = 0;
199 this.freezetag_frozen_timeout = 0;
204 float freezetag_isEliminated(entity e)
206 if(IS_PLAYER(e) && (STAT(FROZEN, e) == 1 || IS_DEAD(e)))
216 void(entity this) havocbot_role_ft_freeing;
217 void(entity this) havocbot_role_ft_offense;
219 void havocbot_goalrating_freeplayers(entity this, float ratingscale, vector org, float sradius)
222 FOREACH_CLIENT(IS_PLAYER(it) && it != this && SAME_TEAM(it, this), {
223 if (STAT(FROZEN, it) == 1)
225 if(vdist(it.origin - org, >, sradius))
227 navigation_routerating(this, it, ratingscale, 2000);
229 else if(vdist(it.origin - org, >, 400)) // avoid gathering all teammates in one place
231 // If teamate is not frozen still seek them out as fight better
233 t = 0.2 * 150 / (this.health + this.armorvalue);
234 navigation_routerating(this, it, t * ratingscale, 2000);
239 void havocbot_role_ft_offense(entity this)
244 if (!this.havocbot_role_timeout)
245 this.havocbot_role_timeout = time + random() * 10 + 20;
247 // Count how many players on team are unfrozen.
249 FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, this) && !(STAT(FROZEN, it) != 1), { unfrozen++; });
251 // If only one left on team or if role has timed out then start trying to free players.
252 if (((unfrozen == 0) && (!STAT(FROZEN, this))) || (time > this.havocbot_role_timeout))
254 LOG_TRACE("changing role to freeing");
255 this.havocbot_role = havocbot_role_ft_freeing;
256 this.havocbot_role_timeout = 0;
260 if (navigation_goalrating_timeout(this))
262 navigation_goalrating_start(this);
263 havocbot_goalrating_items(this, 10000, this.origin, 10000);
264 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 10000);
265 havocbot_goalrating_freeplayers(this, 9000, this.origin, 10000);
266 havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
267 navigation_goalrating_end(this);
269 navigation_goalrating_timeout_set(this);
273 void havocbot_role_ft_freeing(entity this)
278 if (!this.havocbot_role_timeout)
279 this.havocbot_role_timeout = time + random() * 10 + 20;
281 if (time > this.havocbot_role_timeout)
283 LOG_TRACE("changing role to offense");
284 this.havocbot_role = havocbot_role_ft_offense;
285 this.havocbot_role_timeout = 0;
289 if (navigation_goalrating_timeout(this))
291 navigation_goalrating_start(this);
292 havocbot_goalrating_items(this, 8000, this.origin, 10000);
293 havocbot_goalrating_enemyplayers(this, 10000, this.origin, 10000);
294 havocbot_goalrating_freeplayers(this, 20000, this.origin, 10000);
295 havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
296 navigation_goalrating_end(this);
298 navigation_goalrating_timeout_set(this);
307 void ft_RemovePlayer(entity this)
309 this.health = 0; // neccessary to update correctly alive stats
310 if(!STAT(FROZEN, this))
311 freezetag_LastPlayerForTeam_Notify(this);
312 freezetag_Unfreeze(this);
313 freezetag_count_alive_players();
316 MUTATOR_HOOKFUNCTION(ft, ClientDisconnect)
318 entity player = M_ARGV(0, entity);
320 ft_RemovePlayer(player);
324 MUTATOR_HOOKFUNCTION(ft, MakePlayerObserver)
326 entity player = M_ARGV(0, entity);
328 ft_RemovePlayer(player);
331 MUTATOR_HOOKFUNCTION(ft, PlayerDies)
333 entity frag_attacker = M_ARGV(1, entity);
334 entity frag_target = M_ARGV(2, entity);
335 float frag_deathtype = M_ARGV(3, float);
337 if(round_handler_IsActive())
338 if(round_handler_CountdownRunning())
340 if(STAT(FROZEN, frag_target))
341 freezetag_Unfreeze(frag_target);
342 freezetag_count_alive_players();
343 return true; // let the player die so that he can respawn whenever he wants
346 // Cases DEATH_TEAMCHANGE and DEATH_AUTOTEAMCHANGE are needed to fix a bug whe
347 // you succeed changing team through the menu: you both really die (gibbing) and get frozen
348 if(ITEM_DAMAGE_NEEDKILL(frag_deathtype)
349 || frag_deathtype == DEATH_TEAMCHANGE.m_id || frag_deathtype == DEATH_AUTOTEAMCHANGE.m_id)
351 // let the player die, he will be automatically frozen when he respawns
352 if(STAT(FROZEN, frag_target) != 1)
354 freezetag_Add_Score(frag_target, frag_attacker);
355 freezetag_count_alive_players();
356 freezetag_LastPlayerForTeam_Notify(frag_target);
359 freezetag_Unfreeze(frag_target); // remove ice
360 frag_target.health = 0; // Unfreeze resets health
361 frag_target.freezetag_frozen_timeout = -2; // freeze on respawn
365 if(STAT(FROZEN, frag_target))
368 freezetag_Freeze(frag_target, frag_attacker);
369 freezetag_LastPlayerForTeam_Notify(frag_target);
371 if(frag_attacker == frag_target || frag_attacker == NULL)
373 if(IS_PLAYER(frag_target))
374 Send_Notification(NOTIF_ONE, frag_target, MSG_CENTER, CENTER_FREEZETAG_SELF);
375 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_SELF, frag_target.netname);
379 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_FREEZE, frag_target.netname, frag_attacker.netname);
385 MUTATOR_HOOKFUNCTION(ft, PlayerSpawn)
387 entity player = M_ARGV(0, entity);
389 if(player.freezetag_frozen_timeout == -1) // if PlayerSpawn is called by reset_map_players
390 return true; // do nothing, round is starting right now
392 if(player.freezetag_frozen_timeout == -2) // player was dead
394 freezetag_Freeze(player, NULL);
398 freezetag_count_alive_players();
400 if(round_handler_IsActive())
401 if(round_handler_IsRoundStarted())
403 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
404 freezetag_Freeze(player, NULL);
410 MUTATOR_HOOKFUNCTION(ft, reset_map_players)
412 FOREACH_CLIENT(IS_PLAYER(it), {
413 CS(it).killcount = 0;
414 it.freezetag_frozen_timeout = -1;
415 PutClientInServer(it);
416 it.freezetag_frozen_timeout = 0;
418 freezetag_count_alive_players();
422 MUTATOR_HOOKFUNCTION(ft, GiveFragsForKill, CBC_ORDER_FIRST)
424 M_ARGV(2, float) = 0; // no frags counted in Freeze Tag
428 MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST)
433 if(round_handler_IsActive())
434 if(!round_handler_IsRoundStarted())
439 entity player = M_ARGV(0, entity);
440 //if(STAT(FROZEN, player))
441 //if(player.freezetag_frozen_timeout > 0 && time < player.freezetag_frozen_timeout)
442 //player.iceblock.alpha = ICE_MIN_ALPHA + (ICE_MAX_ALPHA - ICE_MIN_ALPHA) * (player.freezetag_frozen_timeout - time) / (player.freezetag_frozen_timeout - player.freezetag_frozen_time);
444 if(player.freezetag_frozen_timeout > 0 && time >= player.freezetag_frozen_timeout)
448 vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
450 FOREACH_CLIENT(IS_PLAYER(it) && it != player, {
451 if(STAT(FROZEN, it) == 0)
453 if(SAME_TEAM(it, player))
454 if(boxesoverlap(player.absmin - revive_extra_size, player.absmax + revive_extra_size, it.absmin, it.absmax))
458 if(STAT(FROZEN, player) == 1)
466 if(n && STAT(FROZEN, player) == 1) // OK, there is at least one teammate reviving us
468 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
469 player.health = max(1, STAT(REVIVE_PROGRESS, player) * ((warmup_stage) ? warmup_start_health : start_health));
471 if(STAT(REVIVE_PROGRESS, player) >= 1)
473 freezetag_Unfreeze(player);
474 freezetag_count_alive_players();
478 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_AUTO_REVIVED, autocvar_g_freezetag_frozen_maxtime);
479 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_AUTO_REVIVED, player.netname, autocvar_g_freezetag_frozen_maxtime);
483 // EVERY team mate nearby gets a point (even if multiple!)
484 FOREACH_CLIENT(IS_PLAYER(it) && it.reviving, {
485 GameRules_scoring_add(it, FREEZETAG_REVIVALS, +1);
486 GameRules_scoring_add(it, SCORE, +1);
487 nades_GiveBonus(it,autocvar_g_nades_bonus_score_low);
490 Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
491 Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, player.netname);
492 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_FREEZETAG_REVIVED, player.netname, o.netname);
495 FOREACH_CLIENT(IS_PLAYER(it) && it.reviving, {
496 STAT(REVIVE_PROGRESS, it) = STAT(REVIVE_PROGRESS, player);
500 else if(!n && STAT(FROZEN, player) == 1) // only if no teammate is nearby will we reset
502 STAT(REVIVE_PROGRESS, player) = bound(0, STAT(REVIVE_PROGRESS, player) - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
503 player.health = max(1, STAT(REVIVE_PROGRESS, player) * ((warmup_stage) ? warmup_start_health : start_health));
505 else if(!n && !STAT(FROZEN, player))
507 STAT(REVIVE_PROGRESS, player) = 0; // thawing nobody
513 MUTATOR_HOOKFUNCTION(ft, SetStartItems)
515 start_items &= ~IT_UNLIMITED_AMMO;
516 //start_health = warmup_start_health = cvar("g_lms_start_health");
517 //start_armorvalue = warmup_start_armorvalue = cvar("g_lms_start_armor");
518 start_ammo_shells = warmup_start_ammo_shells = cvar("g_lms_start_ammo_shells");
519 start_ammo_nails = warmup_start_ammo_nails = cvar("g_lms_start_ammo_nails");
520 start_ammo_rockets = warmup_start_ammo_rockets = cvar("g_lms_start_ammo_rockets");
521 start_ammo_cells = warmup_start_ammo_cells = cvar("g_lms_start_ammo_cells");
522 start_ammo_plasma = warmup_start_ammo_plasma = cvar("g_lms_start_ammo_plasma");
523 start_ammo_fuel = warmup_start_ammo_fuel = cvar("g_lms_start_ammo_fuel");
526 MUTATOR_HOOKFUNCTION(ft, HavocBot_ChooseRole)
528 entity bot = M_ARGV(0, entity);
533 bot.havocbot_role = havocbot_role_ft_freeing;
535 bot.havocbot_role = havocbot_role_ft_offense;
541 MUTATOR_HOOKFUNCTION(ft, CheckAllowedTeams, CBC_ORDER_EXCLUSIVE)
543 M_ARGV(0, float) = freezetag_teams;
546 MUTATOR_HOOKFUNCTION(ft, SetWeaponArena)
548 // most weapons arena
549 if(M_ARGV(0, string) == "0" || M_ARGV(0, string) == "")
550 M_ARGV(0, string) = "most";
553 MUTATOR_HOOKFUNCTION(ft, FragCenterMessage)
555 entity frag_attacker = M_ARGV(0, entity);
556 entity frag_target = M_ARGV(1, entity);
557 //float frag_deathtype = M_ARGV(2, float);
558 int kill_count_to_attacker = M_ARGV(3, int);
559 int kill_count_to_target = M_ARGV(4, int);
561 if(STAT(FROZEN, frag_target))
562 return; // target was already frozen, so this is just pushing them off the cliff
564 Send_Notification(NOTIF_ONE, frag_attacker, MSG_CHOICE, CHOICE_FRAG_FREEZE, frag_target.netname, kill_count_to_attacker, (IS_BOT_CLIENT(frag_target) ? -1 : CS(frag_target).ping));
565 Send_Notification(NOTIF_ONE, frag_target, MSG_CHOICE, CHOICE_FRAGGED_FREEZE, frag_attacker.netname, kill_count_to_target, frag_attacker.health, frag_attacker.armorvalue, (IS_BOT_CLIENT(frag_attacker) ? -1 : CS(frag_attacker).ping));
570 void freezetag_Initialize()
572 freezetag_teams = autocvar_g_freezetag_teams_override;
573 if(freezetag_teams < 2)
574 freezetag_teams = cvar("g_freezetag_teams"); // read the cvar directly as it gets written earlier in the same frame
576 freezetag_teams = BITS(bound(2, freezetag_teams, 4));
577 GameRules_scoring(freezetag_teams, SFL_SORT_PRIO_PRIMARY, SFL_SORT_PRIO_PRIMARY, {
578 field(SP_FREEZETAG_REVIVALS, "revivals", 0);
581 round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null);
582 round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
584 EliminatedPlayers_Init(freezetag_isEliminated);