]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Kill FOR_EACH_REALPLAYER
authorMario <mario@smbclan.net>
Thu, 24 Dec 2015 05:57:14 +0000 (15:57 +1000)
committerMario <mario@smbclan.net>
Thu, 24 Dec 2015 05:57:14 +0000 (15:57 +1000)
qcsrc/common/mutators/mutator/sandbox/sandbox.qc
qcsrc/common/sounds/all.qc
qcsrc/common/triggers/target/changelevel.qc
qcsrc/server/_all.qh
qcsrc/server/bot/waypoints.qc
qcsrc/server/cl_player.qc
qcsrc/server/command/sv_cmd.qc
qcsrc/server/race.qc

index e1decc8a069a093eb3198591153bfd3686317ed9..6b97a28f1da092aee3465c5c1f7084492b08fe3e 100644 (file)
@@ -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;    }
index 0ec413c37edd53c6d2572e5bcc0bce1128d63715..c5685df3a43e0adfdeb35ef4cd92c7187af72240 100644 (file)
@@ -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)
index 51e360e0c587c277dfecfd56f4a88e7a5d32d70c..dc227f17633b50c2da19ee18062e31686e0e1f59 100644 (file)
@@ -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;
        }
index 6049d41d2eb269ce44a9190685b427df6fab2007..287e6c0a1b22eded656884c729d2def334b58cab 100644 (file)
@@ -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 { \
index f85c8e1cdc7e494f34fce3dba5cbddf79265f47d..ba1f7c88db8667cb3e5baebd68c05503ce82317f 100644 (file)
@@ -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();
index 82fed046a0829f80a53ad1a515dbe1cedad75db8..403c28f3f41c87c6cc9537c24ad482313a603dc4 100644 (file)
@@ -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.
index b7602451dbb364a1dcf4447055eb3b064bee0449..521dad5b59bb3bf3797e4c7dbeaa9dddc28355b1 100644 (file)
@@ -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 <g_maxplayers_spectator_blocktime> seconds time to become a player
-                       {
-                               if (IS_SPEC(plr) || IS_OBSERVER(plr))
+                       // give every spectator <g_maxplayers_spectator_blocktime> 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)
index 08ac0624d3b0f60ad39982dbbabb096069a11cd8..dbc59457b87c427318db661d7862f9c57f64e51a 100644 (file)
@@ -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)));
                                        }
                                }
                        }