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