From: Mario Date: Thu, 24 Dec 2015 05:57:14 +0000 (+1000) Subject: Kill FOR_EACH_REALPLAYER X-Git-Tag: xonotic-v0.8.2~1400 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=9415698cb6eb43d8beb667ecbf8c756b00626dfd;p=xonotic%2Fxonotic-data.pk3dir.git Kill FOR_EACH_REALPLAYER --- diff --git a/qcsrc/common/mutators/mutator/sandbox/sandbox.qc b/qcsrc/common/mutators/mutator/sandbox/sandbox.qc index e1decc8a0..6b97a28f1 100644 --- a/qcsrc/common/mutators/mutator/sandbox/sandbox.qc +++ b/qcsrc/common/mutators/mutator/sandbox/sandbox.qc @@ -73,8 +73,6 @@ void sandbox_ObjectFunction_Touch() void sandbox_ObjectFunction_Think() {SELFPARAM(); - entity e; - // decide if and how this object can be grabbed if(autocvar_g_sandbox_readonly) self.grab = 0; // no grabbing @@ -86,15 +84,16 @@ void sandbox_ObjectFunction_Think() // Object owner is stored via player UID, but we also need the owner as an entity (if the player is available on the server). // Therefore, scan for all players, and update the owner as long as the player is present. We must always do this, // since if the owning player disconnects, the object's owner should also be reset. - FOR_EACH_REALPLAYER(e) // bots can't have objects - { - if(self.crypto_idfp == e.crypto_idfp) + + // bots can't have objects + FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA( + if(self.crypto_idfp == it.crypto_idfp) { - self.realowner = e; + self.realowner = it; break; } self.realowner = world; - } + )); self.nextthink = time; @@ -225,12 +224,7 @@ void sandbox_ObjectRemove(entity e) sandbox_ObjectAttach_Remove(e); // detach child objects // if the object being removed has been selected for attachment by a player, unset it - entity head; - FOR_EACH_REALPLAYER(head) // bots can't have objects - { - if(head.object_attach == e) - head.object_attach = world; - } + FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it.object_attach == e, LAMBDA(it.object_attach = world)); if(e.material) { strunzone(e.material); e.material = string_null; } if(e.crypto_idfp) { strunzone(e.crypto_idfp); e.crypto_idfp = string_null; } diff --git a/qcsrc/common/sounds/all.qc b/qcsrc/common/sounds/all.qc index 0ec413c37..c5685df3a 100644 --- a/qcsrc/common/sounds/all.qc +++ b/qcsrc/common/sounds/all.qc @@ -128,11 +128,7 @@ float spamsound(entity e, int chan, string samp, float vol, float _atten) void play2team(float t, string filename) { if (autocvar_bot_sound_monopoly) return; - entity head; - FOR_EACH_REALPLAYER(head) - { - if (head.team == t) play2(head, filename); - } + FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it.team == t, LAMBDA(play2(it, filename))); } void play2all(string samp) diff --git a/qcsrc/common/triggers/target/changelevel.qc b/qcsrc/common/triggers/target/changelevel.qc index 51e360e0c..dc227f176 100644 --- a/qcsrc/common/triggers/target/changelevel.qc +++ b/qcsrc/common/triggers/target/changelevel.qc @@ -13,16 +13,14 @@ void target_changelevel_use() activator.chlevel_targ = self; - entity head; int plnum = 0; int realplnum = 0; // let's not count bots - FOR_EACH_REALPLAYER(head) - { + FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA( ++realplnum; - if(head.chlevel_targ == self) + if(it.chlevel_targ == self) ++plnum; - } + )); if(plnum < ceil(realplnum * min(1, self.count))) // 70% of players return; } diff --git a/qcsrc/server/_all.qh b/qcsrc/server/_all.qh index 6049d41d2..287e6c0a1 100644 --- a/qcsrc/server/_all.qh +++ b/qcsrc/server/_all.qh @@ -27,7 +27,7 @@ const string STR_OBSERVER = "observer"; // NOTE: FOR_EACH_PLAYER deprecated! Use the following instead: FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(yourcode)); // NOTE: FOR_EACH_SPEC deprecated! Use the following instead: FOREACH_CLIENT(IS_SPEC(it), LAMBDA(yourcode)); // NOTE: FOR_EACH_OBSERVER deprecated! Use the following instead: FOREACH_CLIENT(IS_OBSERVER(it), LAMBDA(yourcode)); -#define FOR_EACH_REALPLAYER(v) FOR_EACH_REALCLIENT(v) if (IS_PLAYER(v)) +// NOTE: FOR_EACH_REALPLAYER deprecated! Use the following instead: FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA(yourcode)); #define FOREACH_CLIENT(cond, body) \ MACRO_BEGIN { \ diff --git a/qcsrc/server/bot/waypoints.qc b/qcsrc/server/bot/waypoints.qc index f85c8e1cd..ba1f7c88d 100644 --- a/qcsrc/server/bot/waypoints.qc +++ b/qcsrc/server/bot/waypoints.qc @@ -1134,16 +1134,12 @@ void botframe_deleteuselesswaypoints() void botframe_autowaypoints() { - entity p; - FOR_EACH_REALPLAYER(p) - { - if(p.deadflag) - continue; + FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it.deadflag == DEAD_NO, LAMBDA( // going back is broken, so only fix waypoints to walk TO the player //botframe_autowaypoints_fix(p, false, botframe_autowaypoints_lastwp0); - botframe_autowaypoints_fix(p, true, botframe_autowaypoints_lastwp1); + botframe_autowaypoints_fix(it, true, botframe_autowaypoints_lastwp1); //te_explosion(p.botframe_autowaypoints_lastwp0.origin); - } + )); if (autocvar_g_waypointeditor_auto >= 2) { botframe_deleteuselesswaypoints(); diff --git a/qcsrc/server/cl_player.qc b/qcsrc/server/cl_player.qc index 82fed046a..403c28f3f 100644 --- a/qcsrc/server/cl_player.qc +++ b/qcsrc/server/cl_player.qc @@ -660,7 +660,6 @@ int Say(entity source, float teamsay, entity privatesay, string msgin, bool floo string msgstr, colorstr, cmsgstr, namestr, fullmsgstr, sourcemsgstr, fullcmsgstr, sourcecmsgstr, colorprefix; float flood; var .float flood_field; - entity head; float ret; string privatemsgprefix = string_null; float privatemsgprefixlen = 0; @@ -905,10 +904,7 @@ int Say(entity source, float teamsay, entity privatesay, string msgin, bool floo { sprint(source, sourcemsgstr); dedicated_print(msgstr); // send to server console too - FOR_EACH_REALCLIENT(head) - if(head != source) - if(head.active_minigame == source.active_minigame) - sprint(head, msgstr); + FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != source && it.active_minigame == source.active_minigame, LAMBDA(sprint(it, msgstr))); } else if(teamsay > 0) // team message, only sent to team mates { @@ -916,29 +912,23 @@ int Say(entity source, float teamsay, entity privatesay, string msgin, bool floo dedicated_print(msgstr); // send to server console too if(sourcecmsgstr != "") centerprint(source, sourcecmsgstr); - FOR_EACH_REALPLAYER(head) if(head.team == source.team) - if(head != source) - { - sprint(head, msgstr); - if(cmsgstr != "") - centerprint(head, cmsgstr); - } + FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it != source && it.team == source.team, LAMBDA( + sprint(it, msgstr); + if(cmsgstr != "") + centerprint(it, cmsgstr); + )); } else if(teamsay < 0) // spectator message, only sent to spectators { sprint(source, sourcemsgstr); dedicated_print(msgstr); // send to server console too - FOR_EACH_REALCLIENT(head) if (!IS_PLAYER(head)) - if(head != source) - sprint(head, msgstr); + FOREACH_CLIENT(!IS_PLAYER(it) && IS_REAL_CLIENT(it) && it != source, LAMBDA(sprint(it, msgstr))); } else if(sourcemsgstr != msgstr) // trimmed/server fixed message, sent to all players { sprint(source, sourcemsgstr); dedicated_print(msgstr); // send to server console too - FOR_EACH_REALCLIENT(head) - if(head != source) - sprint(head, msgstr); + FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != source, LAMBDA(sprint(it, msgstr))); } else bprint(msgstr); // entirely normal message, sent to all players -- bprint sends to server console too. diff --git a/qcsrc/server/command/sv_cmd.qc b/qcsrc/server/command/sv_cmd.qc index b7602451d..521dad5b5 100644 --- a/qcsrc/server/command/sv_cmd.qc +++ b/qcsrc/server/command/sv_cmd.qc @@ -194,16 +194,14 @@ void GameCommand_allspec(float request, float argc) { case CMD_REQUEST_COMMAND: { - entity client; string reason = argv(1); float i = 0; - FOR_EACH_REALPLAYER(client) - { - if (client.caplayer) client.caplayer = 0; - WITH(entity, self, client, PutObserverInServer()); + FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA( + if (it.caplayer) it.caplayer = 0; + WITH(entity, self, it, PutObserverInServer()); ++i; - } + )); if (i) bprint(strcat("Successfully forced all (", ftos(i), ") players to spectate", (reason ? strcat(" for reason: '", reason, "'") : ""), ".\n")); else LOG_INFO("No players found to spectate.\n"); return; @@ -553,16 +551,14 @@ void GameCommand_defer_clear_all(float request) { case CMD_REQUEST_COMMAND: { - entity client; float i = 0; float argc; - FOR_EACH_CLIENT(client) - { - argc = tokenize_console(strcat("defer_clear ", ftos(etof(client)))); + FOREACH_CLIENT(true, LAMBDA( + argc = tokenize_console(strcat("defer_clear ", ftos(etof(it)))); GameCommand_defer_clear(CMD_REQUEST_COMMAND, argc); ++i; - } + )); if (i) LOG_INFO(strcat("Successfully stuffed defer clear to all clients (", ftos(i), ")\n")); // should a message be added if no players were found? return; } @@ -1161,18 +1157,14 @@ void GameCommand_nospectators(float request) case CMD_REQUEST_COMMAND: { blockSpectators = 1; - entity plr; - FOR_EACH_REALCLIENT(plr) // give every spectator seconds time to become a player - { - if (IS_SPEC(plr) || IS_OBSERVER(plr)) + // give every spectator seconds time to become a player + FOREACH_CLIENT(IS_REAL_CLIENT(it) && (IS_SPEC(it) || IS_OBSERVER(it)) && !it.caplayer, LAMBDA( + if(!it.caplayer) { - if (!plr.caplayer) - { - plr.spectatortime = time; - Send_Notification(NOTIF_ONE_ONLY, plr, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime); - } + it.spectatortime = time; + Send_Notification(NOTIF_ONE_ONLY, it, MSG_INFO, INFO_SPECTATE_WARNING, autocvar_g_maxplayers_spectator_blocktime); } - } + )); bprint(strcat("^7All spectators will be automatically kicked when not joining the game after ", ftos(autocvar_g_maxplayers_spectator_blocktime), " seconds!\n")); return; } @@ -1368,17 +1360,14 @@ void GameCommand_shuffleteams(float request) { if (teamplay) { - entity tmp_player; int i; float x, t_teams, t_players, team_color; // count the total amount of players and total amount of teams t_players = 0; t_teams = 0; - FOR_EACH_CLIENT(tmp_player) - if (IS_PLAYER(tmp_player) || tmp_player.caplayer) - { - CheckAllowedTeams(tmp_player); + FOREACH_CLIENT(IS_PLAYER(it) || it.caplayer, LAMBDA( + CheckAllowedTeams(it); if (c1 >= 0) t_teams = max(1, t_teams); if (c2 >= 0) t_teams = max(2, t_teams); @@ -1386,12 +1375,10 @@ void GameCommand_shuffleteams(float request) if (c4 >= 0) t_teams = max(4, t_teams); ++t_players; - } + )); // build a list of the players in a random order - FOR_EACH_CLIENT(tmp_player) - if (IS_PLAYER(tmp_player) || tmp_player.caplayer) - { + FOREACH_CLIENT(IS_PLAYER(it) || it.caplayer, LAMBDA( for ( ; ; ) { i = bound(1, floor(random() * maxclients) + 1, maxclients); @@ -1402,11 +1389,11 @@ void GameCommand_shuffleteams(float request) } else { - shuffleteams_players[i] = etof(tmp_player); + shuffleteams_players[i] = etof(it); break; } } - } + )); // finally, from the list made earlier, re-join the players in different order. for (int i = 1; i <= t_teams; ++i) diff --git a/qcsrc/server/race.qc b/qcsrc/server/race.qc index 08ac0624d..dbc59457b 100644 --- a/qcsrc/server/race.qc +++ b/qcsrc/server/race.qc @@ -357,7 +357,6 @@ void race_deleteTime(string map, float pos) void race_SendTime(entity e, float cp, float t, float tvalid) { float snew, l; - entity p; if(g_race_qualifying) t += e.race_penalty_accumulator; @@ -427,9 +426,7 @@ void race_SendTime(entity e, float cp, float t, float tvalid) race_checkpoint_recordholders[cp] = strzone(e.netname); if(g_race_qualifying) { - FOR_EACH_REALPLAYER(p) - if(p.race_checkpoint == cp) - race_SendNextCheckpoint(p, 0); + FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && it.race_checkpoint == cp, LAMBDA(race_SendNextCheckpoint(it, 0))); } } }