]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Kill most cases of FOR_EACH_CLIENT and deprecate FOR_EACH_MONSTER
authorMario <mario@smbclan.net>
Thu, 24 Dec 2015 06:32:27 +0000 (16:32 +1000)
committerMario <mario@smbclan.net>
Thu, 24 Dec 2015 06:32:27 +0000 (16:32 +1000)
qcsrc/common/ent_cs.qc
qcsrc/common/playerstats.qc
qcsrc/server/_all.qh
qcsrc/server/bot/scripting.qc
qcsrc/server/command/common.qc
qcsrc/server/mutators/mutator/gamemode_cts.qc
qcsrc/server/weapons/accuracy.qc

index 4aa31ed01e8d02d119331b6cc2245ec998ba5df6..6367f4068191f768c6808bfe0fa7c9db090c8247 100644 (file)
                e.nextthink = time;
                Net_LinkEntity(e, false, 0, entcs_send);
                if (!IS_REAL_CLIENT(player)) return;
-               FOR_EACH_CLIENT(e)
-               {
-                       assert(e.entcs);
-                       _entcs_send(e.entcs, msg_entity = player, BITS(23), MSG_ONE);
-               }
+               FOREACH_CLIENT(true, LAMBDA(
+                       assert(it.entcs);
+                       _entcs_send(it.entcs, msg_entity = player, BITS(23), MSG_ONE);
+               ));
        }
 
        void entcs_detach(entity player)
index f4657d968ef1fdc30eb92c7073845c4d85256d38..ffd4fca7165589c2ce25602df0e2e2ab54c602d1 100644 (file)
@@ -163,35 +163,33 @@ void PlayerStats_GameReport(float finished)
        PlayerScore_Sort(scoreboard_pos, 1, 1, 1);
        if(teamplay) { PlayerScore_TeamStats(); }
 
-       entity p;
-       FOR_EACH_CLIENT(p)
-       {
+       FOREACH_CLIENT(true, LAMBDA(
                // add personal score rank
-               PS_GR_P_ADDVAL(p, PLAYERSTATS_RANK, p.score_dummyfield);
+               PS_GR_P_ADDVAL(it, PLAYERSTATS_RANK, it.score_dummyfield);
 
                // scoreboard data
-               if(p.scoreboard_pos)
+               if(it.scoreboard_pos)
                {
                        // scoreboard is valid!
-                       PS_GR_P_ADDVAL(p, PLAYERSTATS_SCOREBOARD_VALID, 1);
+                       PS_GR_P_ADDVAL(it, PLAYERSTATS_SCOREBOARD_VALID, 1);
 
                        // add scoreboard position
-                       PS_GR_P_ADDVAL(p, PLAYERSTATS_SCOREBOARD_POS, p.scoreboard_pos);
+                       PS_GR_P_ADDVAL(it, PLAYERSTATS_SCOREBOARD_POS, it.scoreboard_pos);
 
                        // add scoreboard data
-                       PlayerScore_PlayerStats(p);
+                       PlayerScore_PlayerStats(it);
 
                        // if the match ended normally, add winning info
                        if(finished)
                        {
-                               PS_GR_P_ADDVAL(p, PLAYERSTATS_WINS, p.winning);
-                               PS_GR_P_ADDVAL(p, PLAYERSTATS_MATCHES, 1);
+                               PS_GR_P_ADDVAL(it, PLAYERSTATS_WINS, it.winning);
+                               PS_GR_P_ADDVAL(it, PLAYERSTATS_MATCHES, 1);
                        }
                }
 
                // collect final player information
-               PlayerStats_GameReport_FinalizePlayer(p);
-       }
+               PlayerStats_GameReport_FinalizePlayer(it);
+       ));
 
        if(autocvar_g_playerstats_gamereport_uri != "")
        {
index 287e6c0a1b22eded656884c729d2def334b58cab..2920a7659fec842c6b08e29b68129dbd52cc3ee6 100644 (file)
@@ -39,7 +39,7 @@ const string STR_OBSERVER = "observer";
                } \
        } MACRO_END
 
-#define FOR_EACH_MONSTER(v) for (v = world; (v = findflags(v, flags, FL_MONSTER)) != world; )
+// NOTE: FOR_EACH_MONSTER deprecated! Use the following instead: FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(yourcode));
 
 #include "../common/effects/all.qh"
 #include "../common/models/all.qh"
index 4f14d2f3bb40cf875812664a9738108e9720117a..f42adceef1d56ca6f36ca5429c67aea12b932469 100644 (file)
@@ -524,8 +524,6 @@ float bot_cmd_wait_until()
 
 float bot_cmd_barrier()
 {SELFPARAM();
-       entity cl;
-
        // 0 = no barrier, 1 = waiting, 2 = waiting finished
 
        if(self.bot_barrier == 0) // initialization
@@ -537,18 +535,16 @@ float bot_cmd_barrier()
 
        if(self.bot_barrier == 1) // find other bots
        {
-               FOR_EACH_CLIENT(cl) if(cl.isbot)
-               {
-                       if(cl.bot_cmdqueuebuf_allocated)
-                               if(cl.bot_barrier != 1)
-                                       return CMD_STATUS_EXECUTING; // not all are at the barrier yet
-               }
+               FOREACH_CLIENT(it.isbot, LAMBDA(
+                       if(it.bot_cmdqueuebuf_allocated)
+                       if(it.bot_barrier != 1)
+                               return CMD_STATUS_EXECUTING; // not all are at the barrier yet
+               ));
 
                // all bots hit the barrier!
-               FOR_EACH_CLIENT(cl) if(cl.isbot)
-               {
-                       cl.bot_barrier = 2; // acknowledge barrier
-               }
+
+               // acknowledge barrier
+               FOREACH_CLIENT(it.isbot, LAMBDA(it.bot_barrier = 2));
 
                bot_barriertime = time;
        }
@@ -1148,21 +1144,18 @@ void bot_setcurrentcommand()
 
 void bot_resetqueues()
 {
-       entity cl;
-
-       FOR_EACH_CLIENT(cl) if(cl.isbot)
-       {
-               cl.bot_cmd_execution_index = 0;
-               bot_clearqueue(cl);
+       FOREACH_CLIENT(it.isbot, LAMBDA(
+               it.bot_cmd_execution_index = 0;
+               bot_clearqueue(it);
                // also, cancel all barriers
-               cl.bot_barrier = 0;
-               for(int i = 0; i < cl.bot_places_count; ++i)
+               it.bot_barrier = 0;
+               for(int i = 0; i < it.bot_places_count; ++i)
                {
-                       strunzone(cl.(bot_placenames[i]));
-                       cl.(bot_placenames[i]) = string_null;
+                       strunzone(it.(bot_placenames[i]));
+                       it.(bot_placenames[i]) = string_null;
                }
-               cl.bot_places_count = 0;
-       }
+               it.bot_places_count = 0;
+       ));
 
        bot_barriertime = time;
 }
index a252b1f501130a5e2705d1efe391d78f980d4411..42420ee2dd7359e393f708ec8664ce239cb0749c 100644 (file)
@@ -367,10 +367,10 @@ void CommonCommand_editmob(int request, entity caller, int argc)
 
                                        if (arg_lower == "list") { print_to(caller, monsterlist_reply); return; }
 
-                                       FOR_EACH_MONSTER(mon)
-                                       {
-                                               if (mon.realowner == caller) ++tmp_moncount;
-                                       }
+                                       FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(
+                                               if(it.realowner == caller)
+                                                       ++tmp_moncount;
+                                       ));
 
                                        if (!autocvar_g_monsters) { print_to(caller, "Monsters are disabled"); return; }
                                        if (autocvar_g_monsters_max <= 0 || autocvar_g_monsters_max_perplayer <= 0) { print_to(caller, "Monster spawning is disabled"); return; }
@@ -438,13 +438,11 @@ void CommonCommand_editmob(int request, entity caller, int argc)
                                        if (MUTATOR_CALLHOOK(AllowMobButcher)) { LOG_INFO(ret_string, "\n"); return; }
 
                                        int tmp_remcount = 0;
-                                       entity tmp_entity;
 
-                                       FOR_EACH_MONSTER(tmp_entity)
-                                       {
-                                               Monster_Remove(tmp_entity);
+                                       FOREACH_ENTITY_FLAGS(flags, FL_MONSTER, LAMBDA(
+                                               Monster_Remove(it);
                                                ++tmp_remcount;
-                                       }
+                                       ));
 
                                        monsters_total = monsters_killed = totalspawned = 0;
 
index 9a3481ea7ba2553e189c371a3dd1bfd3d915739a..16de70e8c85fc3ab0646bfeb17375809d39ba212 100644 (file)
@@ -192,17 +192,15 @@ MUTATOR_HOOKFUNCTION(cts, reset_map_global)
        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;
                }
-               cts_EventLog(ftos(e.race_place), e);
-       }
+               cts_EventLog(ftos(it.race_place), it);
+       ));
 
        if(g_race_qualifying == 2)
        {
index b92a21da2d6352f63ba88b08884c21e7a39a0327..ed7db1e73ca3db89fdfa4ff779a0e1348ff888d8 100644 (file)
@@ -85,9 +85,7 @@ void accuracy_add(entity this, int w, int fired, int hit)
        if (b == accuracy_byte(a.accuracy_hit[w], a.accuracy_fired[w])) return; // no change
        int sf = 1 << (w % 24);
        a.SendFlags |= sf;
-       entity e; FOR_EACH_CLIENT(e) if (IS_SPEC(e)) if (e.enemy == this) {
-               e.accuracy.SendFlags |= sf;
-       }
+       FOREACH_CLIENT(IS_SPEC(it) && it.enemy == this, LAMBDA(it.accuracy.SendFlags |= sf));
 }
 
 bool accuracy_isgooddamage(entity attacker, entity targ)