bool ctf_CaptureShield_CheckStatus(entity p)
{
int s, s2, s3, s4, se, se2, se3, se4, sr, ser;
- entity e;
int players_worseeq, players_total;
if(ctf_captureshield_max_ratio <= 0)
return false;
players_total = players_worseeq = 0;
- FOR_EACH_PLAYER(e)
- {
- if(DIFF_TEAM(e, p))
+ FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+ if(DIFF_TEAM(it, p))
continue;
- se = PlayerScore_Add(e, SP_CTF_CAPS, 0);
- se2 = PlayerScore_Add(e, SP_CTF_PICKUPS, 0);
- se3 = PlayerScore_Add(e, SP_CTF_RETURNS, 0);
- se4 = PlayerScore_Add(e, SP_CTF_FCKILLS, 0);
+ se = PlayerScore_Add(it, SP_CTF_CAPS, 0);
+ se2 = PlayerScore_Add(it, SP_CTF_PICKUPS, 0);
+ se3 = PlayerScore_Add(it, SP_CTF_RETURNS, 0);
+ se4 = PlayerScore_Add(it, SP_CTF_FCKILLS, 0);
ser = ((se - se2) + (se3 + se4));
if(ser <= sr)
++players_worseeq;
++players_total;
- }
+ ));
// player is in the worse half, if >= half the players are better than him, or consequently, if < half of the players are worse
// use this rule here
void ctf_Handle_Retrieve(entity flag, entity player)
{
- entity tmp_player; // temporary entity which the FOR_EACH_PLAYER loop uses to scan players
entity sender = flag.pass_sender;
// transfer flag to player
_sound(player, CH_TRIGGER, flag.snd_flag_pass, VOL_BASE, ATTEN_NORM);
ctf_EventLog("receive", flag.team, player);
- FOR_EACH_REALPLAYER(tmp_player)
- {
- if(tmp_player == sender)
- Send_Notification(NOTIF_ONE, tmp_player, MSG_CENTER, ((flag.team) ? APP_TEAM_ENT_4(flag, CENTER_CTF_PASS_SENT_) : CENTER_CTF_PASS_SENT_NEUTRAL), player.netname);
- else if(tmp_player == player)
- Send_Notification(NOTIF_ONE, tmp_player, MSG_CENTER, ((flag.team) ? APP_TEAM_ENT_4(flag, CENTER_CTF_PASS_RECEIVED_) : CENTER_CTF_PASS_RECEIVED_NEUTRAL), sender.netname);
- else if(SAME_TEAM(tmp_player, sender))
- Send_Notification(NOTIF_ONE, tmp_player, MSG_CENTER, ((flag.team) ? APP_TEAM_ENT_4(flag, CENTER_CTF_PASS_OTHER_) : CENTER_CTF_PASS_OTHER_NEUTRAL), sender.netname, player.netname);
- }
+ FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA(
+ if(it == sender)
+ Send_Notification(NOTIF_ONE, it, MSG_CENTER, ((flag.team) ? APP_TEAM_ENT_4(flag, CENTER_CTF_PASS_SENT_) : CENTER_CTF_PASS_SENT_NEUTRAL), player.netname);
+ else if(it == player)
+ Send_Notification(NOTIF_ONE, it, MSG_CENTER, ((flag.team) ? APP_TEAM_ENT_4(flag, CENTER_CTF_PASS_RECEIVED_) : CENTER_CTF_PASS_RECEIVED_NEUTRAL), sender.netname);
+ else if(SAME_TEAM(it, sender))
+ Send_Notification(NOTIF_ONE, it, MSG_CENTER, ((flag.team) ? APP_TEAM_ENT_4(flag, CENTER_CTF_PASS_OTHER_) : CENTER_CTF_PASS_OTHER_NEUTRAL), sender.netname, player.netname);
+ ));
// create new waypoint
ctf_FlagcarrierWaypoints(player);
{
// declarations
float pickup_dropped_score; // used to calculate dropped pickup score
- entity tmp_entity; // temporary entity
// attach the flag to the player
flag.owner = player;
Send_Notification(NOTIF_TEAM_EXCEPT, player, MSG_CHOICE, ((flag.team) ? APP_TEAM_ENT_4(flag, CHOICE_CTF_PICKUP_TEAM_) : CHOICE_CTF_PICKUP_TEAM_NEUTRAL), Team_ColorCode(player.team), player.netname);
if(!flag.team)
- FOR_EACH_PLAYER(tmp_entity)
- if(tmp_entity != player)
- if(DIFF_TEAM(player, tmp_entity))
- Send_Notification(NOTIF_ONE, tmp_entity, MSG_CHOICE, CHOICE_CTF_PICKUP_ENEMY_NEUTRAL, Team_ColorCode(player.team), player.netname);
+ FOREACH_CLIENT(IS_PLAYER(it) && it != player && DIFF_TEAM(it, player), LAMBDA(Send_Notification(NOTIF_ONE, it, MSG_CHOICE, CHOICE_CTF_PICKUP_ENEMY_NEUTRAL, Team_ColorCode(player.team), player.netname)));
if(flag.team)
- FOR_EACH_PLAYER(tmp_entity)
- if(tmp_entity != player)
- if(CTF_SAMETEAM(flag, tmp_entity))
- if(SAME_TEAM(player, tmp_entity))
- Send_Notification(NOTIF_ONE, tmp_entity, MSG_CHOICE, APP_TEAM_ENT_4(flag, CHOICE_CTF_PICKUP_TEAM_), Team_ColorCode(player.team), player.netname);
- else
- Send_Notification(NOTIF_ONE, tmp_entity, MSG_CHOICE, ((SAME_TEAM(flag, player)) ? CHOICE_CTF_PICKUP_ENEMY_TEAM : CHOICE_CTF_PICKUP_ENEMY), Team_ColorCode(player.team), player.netname);
+ FOREACH_CLIENT(IS_PLAYER(it) && it != player, LAMBDA(
+ if(CTF_SAMETEAM(flag, it))
+ if(SAME_TEAM(player, it))
+ Send_Notification(NOTIF_ONE, it, MSG_CHOICE, APP_TEAM_ENT_4(flag, CHOICE_CTF_PICKUP_TEAM_), Team_ColorCode(player.team), player.netname);
+ else
+ Send_Notification(NOTIF_ONE, it, MSG_CHOICE, ((SAME_TEAM(flag, player)) ? CHOICE_CTF_PICKUP_ENEMY_TEAM : CHOICE_CTF_PICKUP_ENEMY), Team_ColorCode(player.team), player.netname);
+ ));
_sound(player, CH_TRIGGER, flag.snd_flag_taken, VOL_BASE, ATTEN_NONE);
if (!wpforenemy_announced)
{
- FOR_EACH_REALPLAYER(tmp_entity)
- Send_Notification(NOTIF_ONE, tmp_entity, MSG_CENTER, ((tmp_entity.flagcarried) ? CENTER_CTF_STALEMATE_CARRIER : CENTER_CTF_STALEMATE_OTHER));
+ FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA(Send_Notification(NOTIF_ONE, it, MSG_CENTER, ((it.flagcarried) ? CENTER_CTF_STALEMATE_CARRIER : CENTER_CTF_STALEMATE_OTHER))));
wpforenemy_announced = true;
}
// captureshield
if(self == ctf_worldflaglist) // only for the first flag
- FOR_EACH_CLIENT(tmp_entity)
- ctf_CaptureShield_Update(tmp_entity, 1); // release shield only
+ FOREACH_CLIENT(true, LAMBDA(ctf_CaptureShield_Update(it, 1))); // release shield only
// sanity checks
if(self.mins != CTF_FLAG.m_mins || self.maxs != CTF_FLAG.m_maxs) { // reset the flag boundaries in case it got squished
}
int num_perteam = 0;
- entity tmp_entity; FOR_EACH_PLAYER(tmp_entity) if(SAME_TEAM(toucher, tmp_entity)) { ++num_perteam; }
+ FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(toucher, it), LAMBDA(++num_perteam));
// special touch behaviors
if(toucher.frozen) { return; }
return 0;
int c = 0;
- entity head;
- FOR_EACH_PLAYER(head)
- {
- if(DIFF_TEAM(head, bot) || head.deadflag != DEAD_NO || head == bot)
+ FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+ if(DIFF_TEAM(it, bot) || it.deadflag != DEAD_NO || it == bot)
continue;
- if(vlen(head.origin - org) < tc_radius)
+ if(vlen(it.origin - org) < tc_radius)
++c;
- }
+ ));
return c;
}
void havocbot_ctf_reset_role(entity bot)
{
float cdefense, cmiddle, coffense;
- entity mf, ef, head;
+ entity mf, ef;
float c;
if(bot.deadflag != DEAD_NO)
// if there is only me on the team switch to offense
c = 0;
- FOR_EACH_PLAYER(head)
- if(SAME_TEAM(head, bot))
- ++c;
+ FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, bot), LAMBDA(++c));
if(c==1)
{
navigation_goalrating_start();
// if enemies are closer to our base, go there
- entity head, closestplayer = world;
+ entity closestplayer = world;
float distance, bestdistance = 10000;
- FOR_EACH_PLAYER(head)
- {
- if(head.deadflag!=DEAD_NO)
- continue;
-
- distance = vlen(org - head.origin);
+ FOREACH_CLIENT(IS_PLAYER(it) && it.deadflag == DEAD_NO, LAMBDA(
+ distance = vlen(org - it.origin);
if(distance<bestdistance)
{
- closestplayer = head;
+ closestplayer = it;
bestdistance = distance;
}
- }
+ ));
if(closestplayer)
if(DIFF_TEAM(closestplayer, self))
if(!g_ctf)
return true;
- entity _player;
int _team = 0;
bool found = false;
}
}
- FOR_EACH_PLAYER(_player)
- {
- if(_player.flagcarried && (_player.team == _team || _team == 0))
+ FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+ if(it.flagcarried && (it.team == _team || _team == 0))
{
found = true;
- if(_team == 0 && IS_SPEC(self) && self.enemy == _player)
- continue; // already spectating a fc, try to find the other fc
- return superspec_Spectate(_player);
+ if(_team == 0 && IS_SPEC(self) && self.enemy == it)
+ continue; // already spectating this fc, try another
+ return superspec_Spectate(it);
}
- }
+ ));
if(!found)
superspec_msg("", "", self, "No active flag carrier\n", 1);
total_pps = 0, pps_red = 0, pps_blue = 0, pps_yellow = 0, pps_pink = 0;
for(head = world; (head = find(head, classname, "dom_controlpoint")) != world; )
- {
+ FOREACH_ENTITY_CLASS("dom_controlpoint", true, LAMBDA(
if (autocvar_g_domination_point_amt)
points = autocvar_g_domination_point_amt;
else
- points = head.frags;
+ points = it.frags;
if (autocvar_g_domination_point_rate)
wait_time = autocvar_g_domination_point_rate;
else
- wait_time = head.wait;
- switch(head.goalentity.team)
+ wait_time = it.wait;
+ switch(it.goalentity.team)
{
- case NUM_TEAM_1:
- pps_red += points/wait_time;
- break;
- case NUM_TEAM_2:
- pps_blue += points/wait_time;
- break;
- case NUM_TEAM_3:
- pps_yellow += points/wait_time;
- break;
- case NUM_TEAM_4:
- pps_pink += points/wait_time;
- break;
+ case NUM_TEAM_1: pps_red += points/wait_time; break;
+ case NUM_TEAM_2: pps_blue += points/wait_time; break;
+ case NUM_TEAM_3: pps_yellow += points/wait_time; break;
+ case NUM_TEAM_4: pps_pink += points/wait_time; break;
}
total_pps += points/wait_time;
- }
+ ));
WaypointSprite_UpdateTeamRadar(self.sprite, RADARICON_DOMPOINT, colormapPaletteColor(self.goalentity.team - 1, 0));
WaypointSprite_Ping(self.sprite);
self.captime = time;
- FOR_EACH_REALCLIENT(head)
- set_dom_state(head);
+ FOREACH_CLIENT(IS_REAL_CLIENT(it), LAMBDA(set_dom_state(it)));
}
void AnimateDomPoint()
void Domination_RoundStart()
{
- entity e;
- FOR_EACH_PLAYER(e)
- e.player_blocked = 0;
+ FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(it.player_blocked = false));
}
//go to best items, or control points you don't own
MUTATOR_HOOKFUNCTION(dom, reset_map_players)
{SELFPARAM();
total_pps = 0, pps_red = 0, pps_blue = 0, pps_yellow = 0, pps_pink = 0;
- entity e;
- FOR_EACH_PLAYER(e)
- {
- setself(e);
+ FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+ setself(it);
PutClientInServer();
self.player_blocked = 1;
if(IS_REAL_CLIENT(self))
set_dom_state(self);
- }
+ ));
return 1;
}
float Invasion_CheckWinner()
{
- entity head;
if(round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0)
{
- FOR_EACH_MONSTER(head)
- Monster_Remove(head);
+ FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(Monster_Remove(it)));
Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_OVER);
Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_OVER);
float total_alive_monsters = 0, supermonster_count = 0, red_alive = 0, blue_alive = 0, yellow_alive = 0, pink_alive = 0;
- FOR_EACH_MONSTER(head) if(head.health > 0)
- {
- if((get_monsterinfo(head.monsterid)).spawnflags & MON_FLAG_SUPERMONSTER)
- ++supermonster_count;
- ++total_alive_monsters;
-
- if(teamplay)
- switch(head.team)
+ FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(
+ if(it.health > 0)
{
- case NUM_TEAM_1: ++red_alive; break;
- case NUM_TEAM_2: ++blue_alive; break;
- case NUM_TEAM_3: ++yellow_alive; break;
- case NUM_TEAM_4: ++pink_alive; break;
+ if((get_monsterinfo(it.monsterid)).spawnflags & MON_FLAG_SUPERMONSTER)
+ ++supermonster_count;
+ ++total_alive_monsters;
+
+ if(teamplay)
+ switch(it.team)
+ {
+ case NUM_TEAM_1: ++red_alive; break;
+ case NUM_TEAM_2: ++blue_alive; break;
+ case NUM_TEAM_3: ++yellow_alive; break;
+ case NUM_TEAM_4: ++pink_alive; break;
+ }
}
- }
+ ));
if((total_alive_monsters + inv_numkilled) < inv_maxspawned && inv_maxcurrent < inv_maxspawned)
{
else { winner_team = NUM_TEAM_4; }
}
else
- FOR_EACH_PLAYER(head)
{
- float cs = PlayerScore_Add(head, SP_KILLS, 0);
- if(cs > winning_score)
- {
- winning_score = cs;
- winner = head;
- }
+ FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+ float cs = PlayerScore_Add(it, SP_KILLS, 0);
+ if(cs > winning_score)
+ {
+ winning_score = cs;
+ winner = it;
+ }
+ ));
}
- FOR_EACH_MONSTER(head)
- Monster_Remove(head);
+ FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(Monster_Remove(it)));
if(teamplay)
{
return 1;
}
-float Invasion_CheckPlayers()
+bool Invasion_CheckPlayers()
{
return true;
}
void Invasion_RoundStart()
{
- entity e;
- float numplayers = 0;
- FOR_EACH_PLAYER(e)
- {
- e.player_blocked = 0;
+ int numplayers = 0;
+ FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+ it.player_blocked = false;
++numplayers;
- }
+ ));
if(inv_roundcnt < inv_maxrounds)
inv_roundcnt += 1; // a limiter to stop crazy counts
float kh_KeyCarrier_waypointsprite_visible_for_player(entity e) // runs all the time
{SELFPARAM();
- if(!IS_PLAYER(e) || self.team != e.team)
+ if(!IS_PLAYER(e) || DIFF_TEAM(self, e))
if(!kh_tracking_enabled)
return false;
void kh_update_state()
{
- entity player;
entity key;
float s;
float f;
s |= pow(32, key.count) * f;
}
- FOR_EACH_CLIENT(player)
- {
- player.kh_state = s;
- }
+ FOREACH_CLIENT(true, LAMBDA(it.kh_state = s));
FOR_EACH_KH_KEY(key)
{
void kh_LoserTeam(float teem, entity lostkey) // runs when a player pushes a flag carrier off the map
{
- entity player, key, attacker;
+ entity key, attacker;
float players;
float keys;
float f;
float of, fragsleft, i, j, thisteam;
of = autocvar_g_balance_keyhunt_score_destroyed_ownfactor;
- FOR_EACH_PLAYER(player)
- if(player.team != teem)
- ++players;
+ FOREACH_CLIENT(IS_PLAYER(it) && it.team != teem, LAMBDA(++players));
FOR_EACH_KH_KEY(key)
if(key.owner && key.team != teem)
continue;
players = 0;
- FOR_EACH_PLAYER(player)
- if(player.team == thisteam)
- ++players;
+ FOREACH_CLIENT(IS_PLAYER(it) && it.team == thisteam, LAMBDA(++players));
DistributeEvenly_Init(fragsleft, j);
fragsleft = DistributeEvenly_Get(j - 1);
DistributeEvenly_Init(DistributeEvenly_Get(1), players);
- FOR_EACH_PLAYER(player)
- if(player.team == thisteam)
- {
- f = DistributeEvenly_Get(1);
- kh_Scores_Event(player, world, "destroyed", f, 0);
- }
+ FOREACH_CLIENT(IS_PLAYER(it) && it.team == thisteam, LAMBDA(
+ f = DistributeEvenly_Get(1);
+ kh_Scores_Event(it, world, "destroyed", f, 0);
+ ));
--j;
}
void kh_Key_Think() // runs all the time
{SELFPARAM();
- entity head;
- //entity player; // needed by FOR_EACH_PLAYER
-
if(intermission_running)
return;
if(kh_interferemsg_time && time > kh_interferemsg_time)
{
kh_interferemsg_time = 0;
- FOR_EACH_PLAYER(head)
- {
- if(head.team == kh_interferemsg_team)
- if(head.kh_next)
- Send_Notification(NOTIF_ONE, head, MSG_CENTER, CENTER_KEYHUNT_MEET);
+ FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+ if(it.team == kh_interferemsg_team)
+ if(it.kh_next)
+ Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_KEYHUNT_MEET);
else
- Send_Notification(NOTIF_ONE, head, MSG_CENTER, CENTER_KEYHUNT_HELP);
+ Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_KEYHUNT_HELP);
else
- Send_Notification(NOTIF_ONE, head, MSG_CENTER, APP_TEAM_NUM_4(kh_interferemsg_team, CENTER_KEYHUNT_INTERFERE_));
- }
+ Send_Notification(NOTIF_ONE, it, MSG_CENTER, APP_TEAM_NUM_4(kh_interferemsg_team, CENTER_KEYHUNT_INTERFERE_));
+ ));
}
self.nextthink = time + 0.05;
{
float t_team = kh_Team_ByID(num);
float players = 0;
- entity tmp_player;
- FOR_EACH_PLAYER(tmp_player)
- if(tmp_player.deadflag == DEAD_NO)
- if(!tmp_player.BUTTON_CHAT)
- if(tmp_player.team == t_team)
- ++players;
+ FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+ if(it.deadflag == DEAD_NO && !it.BUTTON_CHAT && it.team == t_team)
+ ++players;
+ ));
if (!players) { return t_team; }
}
void kh_StartRound() // runs at the start of each round
{
float i, players, teem;
- entity player;
if(time < game_starttime)
{
teem = kh_Team_ByID(i);
players = 0;
entity my_player = world;
- FOR_EACH_PLAYER(player)
- if(player.deadflag == DEAD_NO)
- if(!player.BUTTON_CHAT)
- if(player.team == teem)
- {
- ++players;
- if(random() * players <= 1)
- my_player = player;
- }
+ FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+ if(it.deadflag == DEAD_NO && !it.BUTTON_CHAT && it.team == teem)
+ {
+ ++players;
+ if(random() * players <= 1)
+ my_player = it;
+ }
+ ));
kh_Key_Spawn(my_player, 360 * i / kh_teams, i);
}
float WinningCondition_Race(float fraglimit)
{
float wc;
- entity p;
float n, c;
n = 0;
c = 0;
- FOR_EACH_PLAYER(p)
- {
+ FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
++n;
- if(p.race_completed)
+ if(it.race_completed)
++c;
- }
+ ));
if(n && (n == c))
return WINNING_YES;
wc = WinningCondition_Scores(fraglimit, 0);
race_ClearRecords();
PlayerScore_Sort(race_place, 0, 1, 0);
- entity e;
- FOR_EACH_CLIENT(e)
- {
- if(e.race_place)
+ FOREACH_CLIENT(true, LAMBDA(
+ if(it.race_place)
{
- s = PlayerScore_Add(e, SP_RACE_FASTEST, 0);
+ s = PlayerScore_Add(it, SP_RACE_FASTEST, 0);
if(!s)
- e.race_place = 0;
+ it.race_place = 0;
}
- race_EventLog(ftos(e.race_place), e);
- }
+ race_EventLog(ftos(it.race_place), it);
+ ));
if(g_race_qualifying == 2)
{
void Portal_Think()
{SELFPARAM();
- entity e, o;
+ entity o;
vector g;
#ifdef PORTALS_ARE_NOT_SOLID
fixedmakevectors(self.mangle);
- FOR_EACH_PLAYER(e)
- {
- if(e != o)
- if(IS_INDEPENDENT_PLAYER(e) || IS_INDEPENDENT_PLAYER(o))
+ FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+ if(it != o)
+ if(IS_INDEPENDENT_PLAYER(it) || IS_INDEPENDENT_PLAYER(o))
continue; // cannot go through someone else's portal
- if(e != o || time >= self.portal_activatetime)
- Portal_Think_TryTeleportPlayer(e, g);
+ if(it != o || time >= self.portal_activatetime)
+ Portal_Think_TryTeleportPlayer(it, g);
- if(e.hook)
- Portal_Think_TryTeleportPlayer(e.hook, g);
- }
+ if(it.hook)
+ Portal_Think_TryTeleportPlayer(it.hook, g);
+ ));
self.solid = SOLID_TRIGGER;
self.aiment = o;
#endif