5 const string STR_PLAYER = "player";
6 const string STR_SPECTATOR = "spectator";
7 const string STR_OBSERVER = "observer";
9 #define IS_PLAYER(v) ((v).classname == STR_PLAYER)
10 #define IS_SPEC(v) ((v).classname == STR_SPECTATOR)
11 #define IS_OBSERVER(v) ((v).classname == STR_OBSERVER)
13 #define IS_CLIENT(v) (v.flags & FL_CLIENT)
14 /** want: (IS_CLIENT(v) && !IS_REAL_CLIENT(v)) */
15 #define IS_BOT_CLIENT(v) (clienttype(v) == CLIENTTYPE_BOT)
16 #define IS_FAKE_CLIENT(v) (clienttype(v) == CLIENTTYPE_NOTACLIENT)
17 #define IS_REAL_CLIENT(v) (clienttype(v) == CLIENTTYPE_REAL)
18 /** was: (clienttype(v) == CLIENTTYPE_NOTACLIENT) */
19 #define IS_NOT_A_CLIENT(v) (!IS_CLIENT(v))
21 #define IS_MONSTER(v) (v.flags & FL_MONSTER)
22 #define IS_VEHICLE(v) (v.vehicle_flags & VHF_ISVEHICLE)
23 #define IS_TURRET(v) (v.turret_flags & TUR_FLAG_ISTURRET)
25 #define IS_MOVABLE(v) ((IS_PLAYER(v) || IS_MONSTER(v)) && !STAT(FROZEN, v))
27 // NOTE: FOR_EACH_CLIENTSLOT deprecated! Use the following instead: FOREACH_CLIENTSLOT(true, { code; });
28 // NOTE: FOR_EACH_CLIENT deprecated! Use the following instead: FOREACH_CLIENT(true, { code; });
29 // NOTE: FOR_EACH_REALCLIENT deprecated! Use the following instead: FOREACH_CLIENT(IS_REAL_CLIENT(it), { code; });
31 // NOTE: FOR_EACH_PLAYER deprecated! Use the following instead: FOREACH_CLIENT(IS_PLAYER(it), { code; });
32 // NOTE: FOR_EACH_SPEC deprecated! Use the following instead: FOREACH_CLIENT(IS_SPEC(it), { code; });
33 // NOTE: FOR_EACH_OBSERVER deprecated! Use the following instead: FOREACH_CLIENT(IS_OBSERVER(it), { code; });
34 // NOTE: FOR_EACH_REALPLAYER deprecated! Use the following instead: FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), { code; });
36 #define FOREACH_CLIENTSLOT(cond, body) \
38 for(int _i = 1; _i <= maxclients; ++_i) \
40 const noref int i = _i; \
41 ITER_CONST noref entity it = ftoe(i); \
42 if(cond) { LAMBDA(body) } \
46 #define FOREACH_CLIENT(cond, body) FOREACH_CLIENTSLOT(IS_CLIENT(it) && (cond), LAMBDA(body))
48 // using the "inside out" version of knuth-fisher-yates shuffle
49 // https://en.wikipedia.org/wiki/Fisher–Yates_shuffle
50 entity _FCR_clients[255];
51 bool _FCR_entered = false;
52 #define FOREACH_CLIENT_RANDOM(cond, body) \
54 if (_FCR_entered) LOG_FATAL("FOREACH_CLIENT_RANDOM must not be nested"); \
55 _FCR_entered = true; \
57 FOREACH_CLIENT(cond, { \
58 int _j = floor(random() * (_cnt + 1)); \
61 _FCR_clients[_cnt] = it; \
65 _FCR_clients[_cnt] = _FCR_clients[_j]; \
66 _FCR_clients[_j] = it; \
70 for (int _i = 0; _i < _cnt; ++_i) \
72 const noref int i = _i; \
73 ITER_CONST noref entity it = _FCR_clients[i]; \
74 if (cond) { LAMBDA(body) } \
76 _FCR_entered = false; \
79 // NOTE: FOR_EACH_MONSTER deprecated! Use the following instead: IL_EACH(g_monsters, true, { code; });