X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2Futils.qh;h=a37029590a220137294fd26392fd0425550d58d2;hb=5de503ab3a50bb9a57dfd205bf8fb0d208273c44;hp=da5c7a56a7483839793114dd03e540615351e510;hpb=ee5353529c2fee304ac944aa19af53cc85eca7b0;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/utils.qh b/qcsrc/server/utils.qh index da5c7a56a..a37029590 100644 --- a/qcsrc/server/utils.qh +++ b/qcsrc/server/utils.qh @@ -22,6 +22,8 @@ const string STR_OBSERVER = "observer"; #define IS_VEHICLE(v) (v.vehicle_flags & VHF_ISVEHICLE) #define IS_TURRET(v) (v.turret_flags & TUR_FLAG_ISTURRET) +#define IS_MOVABLE(v) ((IS_PLAYER(v) || IS_MONSTER(v)) && !STAT(FROZEN, v)) + // NOTE: FOR_EACH_CLIENTSLOT deprecated! Use the following instead: FOREACH_CLIENTSLOT(true, { code; }); // NOTE: FOR_EACH_CLIENT deprecated! Use the following instead: FOREACH_CLIENT(true, { code; }); // NOTE: FOR_EACH_REALCLIENT deprecated! Use the following instead: FOREACH_CLIENT(IS_REAL_CLIENT(it), { code; }); @@ -32,39 +34,33 @@ const string STR_OBSERVER = "observer"; // NOTE: FOR_EACH_REALPLAYER deprecated! Use the following instead: FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), { code; }); #define FOREACH_CLIENTSLOT(cond, body) \ - MACRO_BEGIN { \ + MACRO_BEGIN \ for(int _i = 1; _i <= maxclients; ++_i) \ { \ const noref int i = _i; \ ITER_CONST noref entity it = ftoe(i); \ if(cond) { LAMBDA(body) } \ } \ - } MACRO_END + MACRO_END -#define FOREACH_CLIENT(cond, body) FOREACH_CLIENTSLOT(IS_CLIENT(it) && (cond), body) +#define FOREACH_CLIENT(cond, body) FOREACH_CLIENTSLOT(IS_CLIENT(it) && (cond), LAMBDA(body)) // using the "inside out" version of knuth-fisher-yates shuffle // https://en.wikipedia.org/wiki/Fisher–Yates_shuffle entity _FCR_clients[255]; bool _FCR_entered = false; #define FOREACH_CLIENT_RANDOM(cond, body) \ - MACRO_BEGIN { \ + MACRO_BEGIN \ if (_FCR_entered) LOG_FATAL("FOREACH_CLIENT_RANDOM must not be nested"); \ _FCR_entered = true; \ int _cnt = 0; \ FOREACH_CLIENT(cond, { \ - int _j = floor(random() * (_cnt + 1)); \ - if (_j == _cnt) \ - { \ - _FCR_clients[_cnt] = it; \ - } \ - else \ - { \ - _FCR_clients[_cnt] = _FCR_clients[_j]; \ - _FCR_clients[_j] = it; \ - } \ - _cnt++; \ - }); \ + int _j = floor(random() * (_cnt + 1)); \ + if (_j != _cnt) \ + _FCR_clients[_cnt] = _FCR_clients[_j]; \ + _FCR_clients[_j] = it; \ + ++_cnt; \ + }); \ for (int _i = 0; _i < _cnt; ++_i) \ { \ const noref int i = _i; \ @@ -72,6 +68,6 @@ bool _FCR_entered = false; if (cond) { LAMBDA(body) } \ } \ _FCR_entered = false; \ - } MACRO_END + MACRO_END // NOTE: FOR_EACH_MONSTER deprecated! Use the following instead: IL_EACH(g_monsters, true, { code; });