X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fserver%2F_all.qh;h=1fabe4d0f965aa9abd6b564b180ad4e83637a96d;hb=84ab2535221e015193d3ba2bd51ed1242c3c49ee;hp=f277af62ab7a6953f7d2a7c96f2e914c8aa9d093;hpb=6794689f122acf95658dd7378155b9dee5293921;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/server/_all.qh b/qcsrc/server/_all.qh index f277af62a..1fabe4d0f 100644 --- a/qcsrc/server/_all.qh +++ b/qcsrc/server/_all.qh @@ -1,5 +1,4 @@ -#ifndef SERVER_ALL_H -#define SERVER_ALL_H +#pragma once int maxclients; @@ -12,42 +11,76 @@ const string STR_OBSERVER = "observer"; #define IS_OBSERVER(v) ((v).classname == STR_OBSERVER) #define IS_CLIENT(v) (v.flags & FL_CLIENT) +/** want: (IS_CLIENT(v) && !IS_REAL_CLIENT(v)) */ #define IS_BOT_CLIENT(v) (clienttype(v) == CLIENTTYPE_BOT) +#define IS_FAKE_CLIENT(v) (clienttype(v) == CLIENTTYPE_NOTACLIENT) #define IS_REAL_CLIENT(v) (clienttype(v) == CLIENTTYPE_REAL) -#define IS_NOT_A_CLIENT(v) (clienttype(v) == CLIENTTYPE_NOTACLIENT) +/** was: (clienttype(v) == CLIENTTYPE_NOTACLIENT) */ +#define IS_NOT_A_CLIENT(v) (!IS_CLIENT(v)) #define IS_MONSTER(v) (v.flags & FL_MONSTER) #define IS_VEHICLE(v) (v.vehicle_flags & VHF_ISVEHICLE) #define IS_TURRET(v) (v.turret_flags & TUR_FLAG_ISTURRET) -#define FOR_EACH_CLIENTSLOT(v) for (v = world; (v = nextent(v)) && (etof(v) <= maxclients); ) -#define FOR_EACH_CLIENT(v) FOR_EACH_CLIENTSLOT(v) if (IS_CLIENT(v)) -#define FOR_EACH_REALCLIENT(v) FOR_EACH_CLIENT(v) if (IS_REAL_CLIENT(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; }); -#define FOR_EACH_PLAYER(v) FOR_EACH_CLIENT(v) if (IS_PLAYER(v)) -#define FOR_EACH_SPEC(v) FOR_EACH_CLIENT(v) if (IS_SPEC(v)) -#define FOR_EACH_OBSERVER(v) FOR_EACH_CLIENT(v) if (IS_OBSERVER(v)) -#define FOR_EACH_REALPLAYER(v) FOR_EACH_REALCLIENT(v) if (IS_PLAYER(v)) +// NOTE: FOR_EACH_PLAYER deprecated! Use the following instead: FOREACH_CLIENT(IS_PLAYER(it), { code; }); +// NOTE: FOR_EACH_SPEC deprecated! Use the following instead: FOREACH_CLIENT(IS_SPEC(it), { code; }); +// NOTE: FOR_EACH_OBSERVER deprecated! Use the following instead: FOREACH_CLIENT(IS_OBSERVER(it), { code; }); +// NOTE: FOR_EACH_REALPLAYER deprecated! Use the following instead: FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), { code; }); -#define FOREACH_CLIENT(cond, body) \ +#define FOREACH_CLIENTSLOT(cond, body) \ MACRO_BEGIN { \ - int i = 0; \ - for (entity it = NULL; (it = nextent(it)) && (etof(it) <= maxclients); ++i) \ + for(int _i = 1; _i <= maxclients; ++_i) \ { \ - if (!IS_CLIENT(it)) continue; \ + const noref int i = _i; \ + ITER_CONST noref entity it = ftoe(i); \ + if(cond) { LAMBDA(body) } \ + } \ + } MACRO_END + +#define FOREACH_CLIENT(cond, body) FOREACH_CLIENTSLOT(IS_CLIENT(it) && (cond), 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 { \ + if (_FCR_entered) LOG_FATAL("FOREACH_CLIENT_RANDOM must not be nested"); \ + _FCR_entered = true; \ + int _cnt = 0; \ + FOREACH_CLIENT(cond, LAMBDA( \ + 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++; \ + )); \ + for (int _i = 0; _i < _cnt; ++_i) \ + { \ + const noref int i = _i; \ + ITER_CONST noref entity it = _FCR_clients[i]; \ if (cond) { LAMBDA(body) } \ } \ + _FCR_entered = false; \ } 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: IL_EACH(g_monsters, true, { code; }); -#include "../common/effects/all.qh" -#include "../common/models/all.qh" -#include "../common/sounds/all.qh" +#include +#include +#include #include "autocvars.qh" #include "constants.qh" #include "defs.qh" #include "miscfunctions.qh" - -#endif