]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/ent_cs.qh
e44ccdabbe897511371c8d5b4cbacf22491f120f
[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
13 /** True when origin is available */
14 // FIXME: it seems sometimes this is false when observing even though observers should be able to know about all players
15 // easily reproducible on heart_v2 or The_Yard with bots - might be because they lack waypoints and bots stand still
16 // it has happened in matches with players and no bots but much more rarely
17 .bool has_origin;
18
19 /** True when a recent server sent origin has been received */
20 .bool has_sv_origin;
21
22 #ifdef SVQC
23 /*
24  * The point of these entities is to avoid the problems
25  * with clientprediction.
26  * If you add SendEntity to players, the engine will not
27  * do any prediction anymore, and you'd have to write the whole
28  * prediction code in CSQC, you want that? :P
29  * Data can depend on gamemode. For now, it serves as GPS entities
30  * in onslaught... YAY ;)
31  */
32
33         .entity entcs;
34
35         bool entcs_send(entity this, entity to, int sf);
36
37         void entcs_think(entity this);
38
39         void entcs_attach(entity player);
40
41         void entcs_detach(entity player);
42
43         .int m_forceupdate;
44
45         void entcs_force_origin(entity player);
46
47 #endif
48
49 #ifdef CSQC
50
51         ArrayList _entcs;
52         STATIC_INIT(_entcs)
53         {
54                 AL_NEW(_entcs, 255, NULL, e);  // 255 is the engine limit on maxclients
55         }
56         SHUTDOWN(_entcs)
57         {
58                 AL_DELETE(_entcs);
59         }
60         #define entcs_receiver(...) EVAL_entcs_receiver(OVERLOAD(entcs_receiver, __VA_ARGS__))
61         #define EVAL_entcs_receiver(...) __VA_ARGS__
62         #define entcs_receiver_1(i) AL_gete(_entcs, i)
63         #define entcs_receiver_2(i, v) AL_sete(_entcs, i, v)
64         #define entcs_is_self(e) ((e).sv_entnum == player_localentnum - 1)
65
66         /**
67      * @param i zero indexed player
68      */
69     .int frags;
70         const int ENTCS_SPEC_PURE = 1; // real spectator
71         const int ENTCS_SPEC_IN_SCOREBOARD = 2; // spectator but still in game (can be in a team)
72         #define entcs_IsSpectating(i) boolean(entcs_GetSpecState(i))
73
74         int entcs_GetSpecState(int i)
75         {
76                 bool unconnected = !playerslots[i].gotscores;
77                 entity e = entcs_receiver(i);
78                 int fr = ((e) ? e.frags : stof(getplayerkeyvalue(i, "frags")));
79                 if (unconnected || fr == FRAGS_SPECTATOR)
80                         return ENTCS_SPEC_PURE;
81                 int sol = ((e) ? e.solid : SOLID_NOT);
82                 if (fr == FRAGS_PLAYER_OUT_OF_GAME && sol == SOLID_NOT)
83                         return ENTCS_SPEC_IN_SCOREBOARD;
84                 return 0;
85         }
86
87         /**
88      * @param i zero indexed player
89      */
90         int entcs_GetClientColors(int i)
91         {
92                 entity e = entcs_receiver(i);
93                 return e ? e.colormap : stof(getplayerkeyvalue(i, "colors"));
94         }
95
96         /**
97         * @param i zero indexed player
98         * @returns 0 if not teamplay
99         */
100         int entcs_GetTeamColor(int i)
101         {
102                 return (!teamplay) ? 0 : entcs_GetClientColors(i) & 15;
103         }
104
105         /**
106         * @param i zero indexed player
107         */
108         int entcs_GetTeam(int i)
109         {
110                 return (entcs_GetSpecState(i) == ENTCS_SPEC_PURE) ? NUM_SPECTATOR : entcs_GetTeamColor(i);
111         }
112
113         /**
114          * Same as `entcs_GetTeam`, but returns -1 for no team in teamplay
115          */
116         int entcs_GetScoreTeam(int i)
117         {
118                 int t = entcs_GetTeam(i);
119                 if (teamplay && !t) t = -1;
120                 return t;
121         }
122
123         /**
124         * @param i zero indexed player
125         */
126         string entcs_GetName(int i)
127         {
128                 entity e = entcs_receiver(i);
129                 return ColorTranslateRGB(e ? e.netname : getplayerkeyvalue(i, "name"));
130         }
131
132     /**
133      * @param i zero indexed player
134      */
135         entity CSQCModel_server2csqc(int i);
136
137     .float alpha;
138
139     /**
140      * @param i zero indexed player
141      */
142         float entcs_GetAlpha(int i)
143         {
144                 entity e = CSQCModel_server2csqc(i);
145                 return e ? e.alpha : 1;
146         }
147
148     /**
149      * @param i zero indexed player
150      */
151         vector entcs_GetColor(int i)
152         {
153                 entity e = CSQCModel_server2csqc(i);
154                 return (!e || e.colormap <= 0)
155                        ? '1 1 1'
156                            : colormapPaletteColor(((e.colormap >= 1024)
157                         ? e.colormap
158                         : entcs_GetClientColors(e.colormap - 1)) & 15, true)
159                 ;
160         }
161
162     /**
163      * @param i zero indexed player
164      */
165         bool entcs_IsDead(int i)
166         {
167                 entity e = CSQCModel_server2csqc(i);
168                 return e ? e.csqcmodel_isdead : false;
169         }
170
171 #endif