Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
utils.qh
Go to the documentation of this file.
1#pragma once
2
4
5const string STR_PLAYER = "player";
6const string STR_SPECTATOR = "spectator";
7const string STR_OBSERVER = "observer";
8
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)
12
13#define IS_CLIENT(v) (v.flags & FL_CLIENT)
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)
19#define IS_NOT_A_CLIENT(v) (!IS_CLIENT(v))
20
21#define IS_LOCAL(v) (v.netaddress == "local")
22
23#define IS_MONSTER(v) (v.flags & FL_MONSTER)
24#define IS_VEHICLE(v) (v.vehicle_flags & VHF_ISVEHICLE)
25#define IS_TURRET(v) (v.turret_flags & TUR_FLAG_ISTURRET)
26
27#define IS_MOVABLE(v) ((IS_PLAYER(v) || IS_MONSTER(v)) && !STAT(FROZEN, v) && !StatusEffects_active(STATUSEFFECT_Frozen, v))
28#define IS_DEAD(s) ((s).deadflag != DEAD_NO)
29#define IS_INVISIBLE(v) (v.alpha <= 0.25 || StatusEffects_active(STATUSEFFECT_Invisibility, v) || MUTATOR_IS_ENABLED(cloaked))
30
31#define CENTER_OR_VIEWOFS(ent) (ent.origin + (IS_PLAYER(ent) ? ent.view_ofs : ((ent.mins + ent.maxs) * 0.5)))
32
33// NOTE: FOR_EACH_CLIENTSLOT deprecated! Use the following instead: FOREACH_CLIENTSLOT(true, { code; });
34// NOTE: FOR_EACH_CLIENT deprecated! Use the following instead: FOREACH_CLIENT(true, { code; });
35// NOTE: FOR_EACH_REALCLIENT deprecated! Use the following instead: FOREACH_CLIENT(IS_REAL_CLIENT(it), { code; });
36
37// NOTE: FOR_EACH_PLAYER deprecated! Use the following instead: FOREACH_CLIENT(IS_PLAYER(it), { code; });
38// NOTE: FOR_EACH_SPEC deprecated! Use the following instead: FOREACH_CLIENT(IS_SPEC(it), { code; });
39// NOTE: FOR_EACH_OBSERVER deprecated! Use the following instead: FOREACH_CLIENT(IS_OBSERVER(it), { code; });
40// NOTE: FOR_EACH_REALPLAYER deprecated! Use the following instead: FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), { code; });
41
42#define FOREACH_CLIENTSLOT(cond, body) \
43 MACRO_BEGIN \
44 for(int _i = 1; _i <= maxclients; ++_i) \
45 { \
46 const noref int i = _i; \
47 ITER_CONST noref entity it = ftoe(i); \
48 if(cond) { LAMBDA(body) } \
49 } \
50 MACRO_END
51
52#define FOREACH_CLIENT(cond, body) FOREACH_CLIENTSLOT(IS_CLIENT(it) && (cond), LAMBDA(body))
53
54// using the "inside out" version of knuth-fisher-yates shuffle
55// https://en.wikipedia.org/wiki/Fisher–Yates_shuffle
57bool _FCR_entered = false;
58#define FOREACH_CLIENT_RANDOM(cond, body) \
59 MACRO_BEGIN \
60 if (_FCR_entered) LOG_FATAL("FOREACH_CLIENT_RANDOM must not be nested"); \
61 _FCR_entered = true; \
62 int _cnt = 0; \
63 FOREACH_CLIENT(cond, { \
64 int _j = floor(random() * (_cnt + 1)); \
65 if (_j != _cnt) \
66 _FCR_clients[_cnt] = _FCR_clients[_j]; \
67 _FCR_clients[_j] = it; \
68 ++_cnt; \
69 }); \
70 for (int _i = 0; _i < _cnt; ++_i) \
71 { \
72 const noref int i = _i; \
73 ITER_CONST noref entity it = _FCR_clients[i]; \
74 if (cond) { LAMBDA(body) } \
75 } \
76 _FCR_entered = false; \
77 MACRO_END
78
79// NOTE: FOR_EACH_MONSTER deprecated! Use the following instead: IL_EACH(g_monsters, true, { code; });
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float maxclients
const string STR_SPECTATOR
Definition utils.qh:6
const string STR_OBSERVER
Definition utils.qh:7
const string STR_PLAYER
Definition utils.qh:5
bool _FCR_entered
Definition utils.qh:57
entity _FCR_clients[255]
Definition utils.qh:56