]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/ent_cs.qh
Fix bots waiting for a teamed item to spawn again once they got it (e.g. megas and...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / ent_cs.qh
1 #pragma once
2
3 #ifdef CSQC
4 #include <client/defs.qh>
5 #endif
6
7 REGISTER_NET_LINKED(ENT_CLIENT_ENTCS)
8 REGISTER_NET_TEMP(CLIENT_ENTCS)
9
10 /** True when private information such as origin is available */
11 .bool m_entcs_private;
12 /** True when origin is available */
13 .bool has_origin;
14 /** True when a recent server sent origin has been received */
15 .bool has_sv_origin;
16
17 #ifdef SVQC
18 /*
19  * The point of these entities is to avoid the problems
20  * with clientprediction.
21  * If you add SendEntity to players, the engine will not
22  * do any prediction anymore, and you'd have to write the whole
23  * prediction code in CSQC, you want that? :P
24  * Data can depend on gamemode. For now, it serves as GPS entities
25  * in onslaught... YAY ;)
26  */
27
28         .entity entcs;
29
30         bool entcs_send(entity this, entity to, int sf);
31
32         void entcs_think(entity this);
33
34         void entcs_attach(entity e);
35
36         void entcs_detach(entity e);
37
38         .int m_forceupdate;
39
40 /** Force an origin update, for player sounds */
41         #define entcs_force_origin(e) ((e).entcs.m_forceupdate = BIT(2))
42
43 #endif
44
45 #ifdef CSQC
46
47         ArrayList _entcs;
48         STATIC_INIT(_entcs)
49         {
50                 AL_NEW(_entcs, 255, NULL, e);  // 255 is the engine limit on maxclients
51         }
52         SHUTDOWN(_entcs)
53         {
54                 AL_DELETE(_entcs);
55         }
56         #define entcs_receiver(...) EVAL_entcs_receiver(OVERLOAD(entcs_receiver, __VA_ARGS__))
57         #define EVAL_entcs_receiver(...) __VA_ARGS__
58         #define entcs_receiver_1(i) AL_gete(_entcs, i)
59         #define entcs_receiver_2(i, v) AL_sete(_entcs, i, v)
60         #define entcs_is_self(e) ((e).sv_entnum == player_localentnum - 1)
61
62         /**
63      * @param i zero indexed player
64      */
65     .int frags;
66         bool entcs_IsSpectating(int i)
67         {
68                 bool unconnected = !playerslots[i].gotscores;
69                 entity e = entcs_receiver(i);
70                 return unconnected || ((e) ? e.frags : stof(getplayerkeyvalue(i, "frags"))) == FRAGS_SPECTATOR;
71         }
72
73         /**
74      * @param i zero indexed player
75      */
76         int entcs_GetClientColors(int i)
77         {
78                 entity e = entcs_receiver(i);
79                 return e ? e.colormap : stof(getplayerkeyvalue(i, "colors"));
80         }
81
82         /**
83         * @param i zero indexed player
84         * @returns 0 if not teamplay
85         */
86         int entcs_GetTeamColor(int i)
87         {
88                 return (!teamplay) ? 0 : entcs_GetClientColors(i) & 15;
89         }
90
91         /**
92         * @param i zero indexed player
93         * @returns 0 if not teamplay | NUM_TEAM_##N | NUM_SPECTATOR
94         */
95         int entcs_GetTeam(int i)
96         {
97                 return entcs_IsSpectating(i) ? NUM_SPECTATOR : entcs_GetTeamColor(i);
98         }
99
100         /**
101          * Same as `entcs_GetTeam`, but returns -1 for no team in teamplay
102          */
103         int entcs_GetScoreTeam(int i)
104         {
105                 int t = entcs_GetTeam(i);
106                 if (teamplay && !t) t = -1;
107                 return t;
108         }
109
110         /**
111         * @param i zero indexed player
112         */
113         string entcs_GetName(int i)
114         {
115                 entity e = entcs_receiver(i);
116                 return ColorTranslateRGB(e ? e.netname : getplayerkeyvalue(i, "name"));
117         }
118
119     /**
120      * @param i zero indexed player
121      */
122         entity CSQCModel_server2csqc(int i);
123
124     .float alpha;
125
126     /**
127      * @param i zero indexed player
128      */
129         float entcs_GetAlpha(int i)
130         {
131                 entity e = CSQCModel_server2csqc(i);
132                 return e ? e.alpha : 1;
133         }
134
135     /**
136      * @param i zero indexed player
137      */
138         vector entcs_GetColor(int i)
139         {
140                 entity e = CSQCModel_server2csqc(i);
141                 return (!e || e.colormap <= 0)
142                        ? '1 1 1'
143                            : colormapPaletteColor(((e.colormap >= 1024)
144                         ? e.colormap
145                         : entcs_GetClientColors(e.colormap - 1)) & 15, true)
146                 ;
147         }
148
149     /**
150      * @param i zero indexed player
151      */
152         bool entcs_IsDead(int i)
153         {
154                 entity e = CSQCModel_server2csqc(i);
155                 return e ? e.csqcmodel_isdead : false;
156         }
157
158 #endif