+#include "gamemode_freezetag.qh"
#ifndef GAMEMODE_FREEZETAG_H
#define GAMEMODE_FREEZETAG_H
freezetag_Initialize();
ActivateTeamplay();
- SetLimits(autocvar_g_freezetag_point_limit, autocvar_g_freezetag_point_leadlimit, -1, -1);
+ SetLimits(autocvar_g_freezetag_point_limit, autocvar_g_freezetag_point_leadlimit, autocvar_timelimit_override, -1);
if (autocvar_g_freezetag_team_spawns)
have_team_spawns = -1; // request team spawns
void freezetag_count_alive_players()
{
- entity e;
total_players = redalive = bluealive = yellowalive = pinkalive = 0;
- FOR_EACH_PLAYER(e)
- {
- switch(e.team)
+ FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+ switch(it.team)
{
- case NUM_TEAM_1: ++total_players; if(e.health >= 1 && e.frozen != 1) ++redalive; break;
- case NUM_TEAM_2: ++total_players; if(e.health >= 1 && e.frozen != 1) ++bluealive; break;
- case NUM_TEAM_3: ++total_players; if(e.health >= 1 && e.frozen != 1) ++yellowalive; break;
- case NUM_TEAM_4: ++total_players; if(e.health >= 1 && e.frozen != 1) ++pinkalive; break;
+ case NUM_TEAM_1: ++total_players; if(it.health >= 1 && STAT(FROZEN, it) != 1) ++redalive; break;
+ case NUM_TEAM_2: ++total_players; if(it.health >= 1 && STAT(FROZEN, it) != 1) ++bluealive; break;
+ case NUM_TEAM_3: ++total_players; if(it.health >= 1 && STAT(FROZEN, it) != 1) ++yellowalive; break;
+ case NUM_TEAM_4: ++total_players; if(it.health >= 1 && STAT(FROZEN, it) != 1) ++pinkalive; break;
}
- }
- FOR_EACH_REALCLIENT(e)
- {
- e.redalive_stat = redalive;
- e.bluealive_stat = bluealive;
- e.yellowalive_stat = yellowalive;
- e.pinkalive_stat = pinkalive;
- }
+ ));
+ FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(
+ it.redalive_stat = redalive;
+ it.bluealive_stat = bluealive;
+ it.yellowalive_stat = yellowalive;
+ it.pinkalive_stat = pinkalive;
+ ));
eliminatedPlayers.SendFlags |= 1;
}
if(FREEZETAG_ALIVE_TEAMS_OK())
{
if(prev_missing_teams_mask > 0)
- Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
+ Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_MISSING_TEAMS);
prev_missing_teams_mask = -1;
return 1;
}
if(total_players == 0)
{
if(prev_missing_teams_mask > 0)
- Kill_Notification(NOTIF_ALL, world, MSG_CENTER_CPID, CPID_MISSING_TEAMS);
+ Kill_Notification(NOTIF_ALL, world, MSG_CENTER, CPID_MISSING_TEAMS);
prev_missing_teams_mask = -1;
return 0;
}
float freezetag_CheckWinner()
{
- entity e;
if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
{
Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
- FOR_EACH_PLAYER(e)
- {
- e.freezetag_frozen_timeout = 0;
- nades_Clear(e);
- }
+ FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+ it.freezetag_frozen_timeout = 0;
+ nades_Clear(it);
+ ));
round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
return 1;
}
if(FREEZETAG_ALIVE_TEAMS() > 1)
return 0;
- float winner_team;
- winner_team = freezetag_getWinnerTeam();
+ int winner_team = freezetag_getWinnerTeam();
if(winner_team > 0)
{
- Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
- Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
+ Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
+ Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
TeamScore_AddToTeam(winner_team, ST_SCORE, +1);
}
else if(winner_team == -1)
Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
}
- FOR_EACH_PLAYER(e)
- {
- e.freezetag_frozen_timeout = 0;
- nades_Clear(e);
- }
+ FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+ it.freezetag_frozen_timeout = 0;
+ nades_Clear(it);
+ ));
round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
return 1;
}
entity freezetag_LastPlayerForTeam()
{SELFPARAM();
- entity pl, last_pl = world;
- FOR_EACH_PLAYER(pl)
- {
- if(pl.health >= 1)
- if(!pl.frozen)
- if(pl != self)
- if(pl.team == self.team)
+ entity last_pl = world;
+ FOREACH_CLIENT(IS_PLAYER(it) && it != self, LAMBDA(
+ if(it.health >= 1)
+ if(!STAT(FROZEN, it))
+ if(SAME_TEAM(it, self))
if(!last_pl)
- last_pl = pl;
+ last_pl = it;
else
return world;
- }
+ ));
return last_pl;
}
void freezetag_Freeze(entity attacker)
{SELFPARAM();
- if(self.frozen)
+ if(STAT(FROZEN, self))
return;
if(autocvar_g_freezetag_frozen_maxtime > 0)
float freezetag_isEliminated(entity e)
{
- if(IS_PLAYER(e) && (e.frozen == 1 || e.deadflag != DEAD_NO))
+ if(IS_PLAYER(e) && (STAT(FROZEN, e) == 1 || IS_DEAD(e)))
return true;
return false;
}
// Bot player logic
// ================
-void() havocbot_role_ft_freeing;
-void() havocbot_role_ft_offense;
-
-void havocbot_goalrating_freeplayers(float ratingscale, vector org, float sradius)
-{SELFPARAM();
- entity head;
- float distance;
+void(entity this) havocbot_role_ft_freeing;
+void(entity this) havocbot_role_ft_offense;
- FOR_EACH_PLAYER(head)
- {
- if ((head != self) && (head.team == self.team))
+void havocbot_goalrating_freeplayers(entity this, float ratingscale, vector org, float sradius)
+{
+ FOREACH_CLIENT(IS_PLAYER(it) && it != this && SAME_TEAM(it, this), LAMBDA(
+ if (STAT(FROZEN, it) == 1)
{
- if (head.frozen == 1)
- {
- distance = vlen(head.origin - org);
- if (distance > sradius)
- continue;
- navigation_routerating(head, ratingscale, 2000);
- }
- else
- {
- // If teamate is not frozen still seek them out as fight better
- // in a group.
- navigation_routerating(head, ratingscale/3, 2000);
- }
+ if(vdist(it.origin - org, >, sradius))
+ continue;
+ navigation_routerating(this, it, ratingscale, 2000);
}
- }
+ else
+ {
+ // If teamate is not frozen still seek them out as fight better
+ // in a group.
+ navigation_routerating(this, it, ratingscale/3, 2000);
+ }
+ ));
}
-void havocbot_role_ft_offense()
-{SELFPARAM();
- entity head;
- float unfrozen;
-
- if(self.deadflag != DEAD_NO)
+void havocbot_role_ft_offense(entity this)
+{
+ if(IS_DEAD(this))
return;
- if (!self.havocbot_role_timeout)
- self.havocbot_role_timeout = time + random() * 10 + 20;
+ if (!this.havocbot_role_timeout)
+ this.havocbot_role_timeout = time + random() * 10 + 20;
// Count how many players on team are unfrozen.
- unfrozen = 0;
- FOR_EACH_PLAYER(head)
- {
- if ((head.team == self.team) && (head.frozen != 1))
- unfrozen++;
- }
+ int unfrozen = 0;
+ FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, this) && !(STAT(FROZEN, it) != 1), LAMBDA(unfrozen++));
// If only one left on team or if role has timed out then start trying to free players.
- if (((unfrozen == 0) && (!self.frozen)) || (time > self.havocbot_role_timeout))
+ if (((unfrozen == 0) && (!STAT(FROZEN, this))) || (time > this.havocbot_role_timeout))
{
LOG_TRACE("changing role to freeing\n");
- self.havocbot_role = havocbot_role_ft_freeing;
- self.havocbot_role_timeout = 0;
+ this.havocbot_role = havocbot_role_ft_freeing;
+ this.havocbot_role_timeout = 0;
return;
}
- if (time > self.bot_strategytime)
+ if (time > this.bot_strategytime)
{
- self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
-
- navigation_goalrating_start();
- havocbot_goalrating_items(10000, self.origin, 10000);
- havocbot_goalrating_enemyplayers(20000, self.origin, 10000);
- havocbot_goalrating_freeplayers(9000, self.origin, 10000);
- //havocbot_goalrating_waypoints(1, self.origin, 1000);
- navigation_goalrating_end();
+ this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
+
+ navigation_goalrating_start(this);
+ havocbot_goalrating_items(this, 10000, this.origin, 10000);
+ havocbot_goalrating_enemyplayers(this, 20000, this.origin, 10000);
+ havocbot_goalrating_freeplayers(this, 9000, this.origin, 10000);
+ //havocbot_goalrating_waypoints(1, this.origin, 1000);
+ navigation_goalrating_end(this);
}
}
-void havocbot_role_ft_freeing()
-{SELFPARAM();
- if(self.deadflag != DEAD_NO)
+void havocbot_role_ft_freeing(entity this)
+{
+ if(IS_DEAD(this))
return;
- if (!self.havocbot_role_timeout)
- self.havocbot_role_timeout = time + random() * 10 + 20;
+ if (!this.havocbot_role_timeout)
+ this.havocbot_role_timeout = time + random() * 10 + 20;
- if (time > self.havocbot_role_timeout)
+ if (time > this.havocbot_role_timeout)
{
LOG_TRACE("changing role to offense\n");
- self.havocbot_role = havocbot_role_ft_offense;
- self.havocbot_role_timeout = 0;
+ this.havocbot_role = havocbot_role_ft_offense;
+ this.havocbot_role_timeout = 0;
return;
}
- if (time > self.bot_strategytime)
+ if (time > this.bot_strategytime)
{
- self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
-
- navigation_goalrating_start();
- havocbot_goalrating_items(8000, self.origin, 10000);
- havocbot_goalrating_enemyplayers(10000, self.origin, 10000);
- havocbot_goalrating_freeplayers(20000, self.origin, 10000);
- //havocbot_goalrating_waypoints(1, self.origin, 1000);
- navigation_goalrating_end();
+ this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
+
+ navigation_goalrating_start(this);
+ havocbot_goalrating_items(this, 8000, this.origin, 10000);
+ havocbot_goalrating_enemyplayers(this, 10000, this.origin, 10000);
+ havocbot_goalrating_freeplayers(this, 20000, this.origin, 10000);
+ //havocbot_goalrating_waypoints(1, this.origin, 1000);
+ navigation_goalrating_end(this);
}
}
void ft_RemovePlayer()
{SELFPARAM();
self.health = 0; // neccessary to update correctly alive stats
- if(!self.frozen)
+ if(!STAT(FROZEN, self))
freezetag_LastPlayerForTeam_Notify();
freezetag_Unfreeze(world);
freezetag_count_alive_players();
}
MUTATOR_HOOKFUNCTION(ft, ClientDisconnect)
-{SELFPARAM();
+{
ft_RemovePlayer();
return 1;
}
MUTATOR_HOOKFUNCTION(ft, MakePlayerObserver)
-{SELFPARAM();
+{
ft_RemovePlayer();
return false;
}
MUTATOR_HOOKFUNCTION(ft, PlayerDies)
-{SELFPARAM();
+{
if(round_handler_IsActive())
if(round_handler_CountdownRunning())
{
- if(self.frozen)
- freezetag_Unfreeze(world);
+ if(STAT(FROZEN, frag_target))
+ WITHSELF(frag_target, freezetag_Unfreeze(world));
freezetag_count_alive_players();
return 1; // let the player die so that he can respawn whenever he wants
}
|| frag_deathtype == DEATH_TEAMCHANGE.m_id || frag_deathtype == DEATH_AUTOTEAMCHANGE.m_id)
{
// let the player die, he will be automatically frozen when he respawns
- if(self.frozen != 1)
+ if(STAT(FROZEN, frag_target) != 1)
{
freezetag_Add_Score(frag_attacker);
freezetag_count_alive_players();
freezetag_LastPlayerForTeam_Notify();
}
else
- freezetag_Unfreeze(world); // remove ice
- self.health = 0; // Unfreeze resets health
- self.freezetag_frozen_timeout = -2; // freeze on respawn
+ WITHSELF(frag_target, freezetag_Unfreeze(world)); // remove ice
+ frag_target.health = 0; // Unfreeze resets health
+ frag_target.freezetag_frozen_timeout = -2; // freeze on respawn
return 1;
}
- if(self.frozen)
+ if(STAT(FROZEN, frag_target))
return 1;
- freezetag_Freeze(frag_attacker);
+ WITHSELF(frag_target, freezetag_Freeze(frag_attacker));
freezetag_LastPlayerForTeam_Notify();
if(frag_attacker == frag_target || frag_attacker == world)
}
MUTATOR_HOOKFUNCTION(ft, PlayerSpawn)
-{SELFPARAM();
- if(self.freezetag_frozen_timeout == -1) // if PlayerSpawn is called by reset_map_players
+{
+ entity player = M_ARGV(0, entity);
+
+ if(player.freezetag_frozen_timeout == -1) // if PlayerSpawn is called by reset_map_players
return 1; // do nothing, round is starting right now
- if(self.freezetag_frozen_timeout == -2) // player was dead
+ if(player.freezetag_frozen_timeout == -2) // player was dead
{
- freezetag_Freeze(world);
+ WITHSELF(player, freezetag_Freeze(world));
return 1;
}
if(round_handler_IsActive())
if(round_handler_IsRoundStarted())
{
- Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
- freezetag_Freeze(world);
+ Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_FREEZETAG_SPAWN_LATE);
+ WITHSELF(player, freezetag_Freeze(world));
}
return 1;
}
MUTATOR_HOOKFUNCTION(ft, reset_map_players)
-{SELFPARAM();
- entity e;
- FOR_EACH_PLAYER(e)
- {
- e.killcount = 0;
- e.freezetag_frozen_timeout = -1;
- setself(e);
- PutClientInServer();
- e.freezetag_frozen_timeout = 0;
- }
+{
+ FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+ it.killcount = 0;
+ it.freezetag_frozen_timeout = -1;
+ WITHSELF(it, PutClientInServer());
+ it.freezetag_frozen_timeout = 0;
+ ));
freezetag_count_alive_players();
return 1;
}
MUTATOR_HOOKFUNCTION(ft, PlayerPreThink, CBC_ORDER_FIRST)
{SELFPARAM();
- float n;
-
if(gameover)
return 1;
- if(self.frozen == 1)
+ if(STAT(FROZEN, self) == 1)
{
// keep health = 1
self.pauseregen_finished = time + autocvar_g_balance_pause_health_regen;
if(!round_handler_IsRoundStarted())
return 1;
+ int n;
+
entity o;
o = world;
- //if(self.frozen)
+ //if(STAT(FROZEN, self))
//if(self.freezetag_frozen_timeout > 0 && time < self.freezetag_frozen_timeout)
//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);
{
vector revive_extra_size = '1 1 1' * autocvar_g_freezetag_revive_extra_size;
n = 0;
- FOR_EACH_PLAYER(other)
- if(self != other)
- if(other.frozen == 0)
- if(other.deadflag == DEAD_NO)
- if(SAME_TEAM(other, self))
- if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, other.absmin, other.absmax))
- {
- if(!o)
- o = other;
- if(self.frozen == 1)
- other.reviving = true;
- ++n;
- }
+ FOREACH_CLIENT(IS_PLAYER(it) && it != self, LAMBDA(
+ if(STAT(FROZEN, it) == 0)
+ if(!IS_DEAD(it))
+ if(SAME_TEAM(it, self))
+ if(boxesoverlap(self.absmin - revive_extra_size, self.absmax + revive_extra_size, it.absmin, it.absmax))
+ {
+ if(!o)
+ o = it;
+ if(STAT(FROZEN, self) == 1)
+ it.reviving = true;
+ ++n;
+ }
+ ));
+
}
- if(n && self.frozen == 1) // OK, there is at least one teammate reviving us
+ if(n && STAT(FROZEN, self) == 1) // OK, there is at least one teammate reviving us
{
self.revive_progress = bound(0, self.revive_progress + frametime * max(1/60, autocvar_g_freezetag_revive_speed), 1);
self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
}
// EVERY team mate nearby gets a point (even if multiple!)
- FOR_EACH_PLAYER(other)
- {
- if(other.reviving)
- {
- PlayerScore_Add(other, SP_FREEZETAG_REVIVALS, +1);
- PlayerScore_Add(other, SP_SCORE, +1);
-
- nades_GiveBonus(other,autocvar_g_nades_bonus_score_low);
- }
- }
+ FOREACH_CLIENT(IS_PLAYER(it) && it.reviving, LAMBDA(
+ PlayerScore_Add(it, SP_FREEZETAG_REVIVALS, +1);
+ PlayerScore_Add(it, SP_SCORE, +1);
+ nades_GiveBonus(it,autocvar_g_nades_bonus_score_low);
+ ));
Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_FREEZETAG_REVIVED, o.netname);
Send_Notification(NOTIF_ONE, o, MSG_CENTER, CENTER_FREEZETAG_REVIVE, self.netname);
Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_FREEZETAG_REVIVED, self.netname, o.netname);
}
- FOR_EACH_PLAYER(other)
- {
- if(other.reviving)
- {
- other.revive_progress = self.revive_progress;
- other.reviving = false;
- }
- }
+ FOREACH_CLIENT(IS_PLAYER(it) && it.reviving, LAMBDA(
+ it.revive_progress = self.revive_progress;
+ it.reviving = false;
+ ));
}
- else if(!n && self.frozen == 1) // only if no teammate is nearby will we reset
+ else if(!n && STAT(FROZEN, self) == 1) // only if no teammate is nearby will we reset
{
self.revive_progress = bound(0, self.revive_progress - frametime * autocvar_g_freezetag_revive_clearspeed, 1);
self.health = max(1, self.revive_progress * ((warmup_stage) ? warmup_start_health : start_health));
}
- else if(!n && !self.frozen)
+ else if(!n && !STAT(FROZEN, self))
{
self.revive_progress = 0; // thawing nobody
}
MUTATOR_HOOKFUNCTION(ft, HavocBot_ChooseRole)
{SELFPARAM();
- if (!self.deadflag)
+ if (!IS_DEAD(self))
{
if (random() < 0.5)
self.havocbot_role = havocbot_role_ft_freeing;
round_handler_Spawn(freezetag_CheckTeams, freezetag_CheckWinner, func_null);
round_handler_Init(5, autocvar_g_freezetag_warmup, autocvar_g_freezetag_round_timelimit);
- addstat(STAT_REDALIVE, AS_INT, redalive_stat);
- addstat(STAT_BLUEALIVE, AS_INT, bluealive_stat);
- addstat(STAT_YELLOWALIVE, AS_INT, yellowalive_stat);
- addstat(STAT_PINKALIVE, AS_INT, pinkalive_stat);
-
EliminatedPlayers_Init(freezetag_isEliminated);
}