]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/ent_cs.qh
Merge branch 'master' 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     .int wants_join;
76         const int ENTCS_SPEC_PURE = 1; // real spectator
77         const int ENTCS_SPEC_IN_SCOREBOARD = 2; // spectator but still in game (can be in a team)
78         #define entcs_IsSpectating(i) boolean(entcs_GetSpecState(i))
79
80         int entcs_GetSpecState(int i)
81         {
82                 bool unconnected = !playerslots[i].gotscores;
83                 entity e = entcs_receiver(i);
84                 int fr = ((e) ? e.frags : 0);
85                 if (unconnected || fr == FRAGS_SPECTATOR)
86                         return ENTCS_SPEC_PURE;
87                 int sol = ((e) ? e.sv_solid : SOLID_NOT);
88                 if (fr == FRAGS_PLAYER_OUT_OF_GAME && sol == SOLID_NOT)
89                         return ENTCS_SPEC_IN_SCOREBOARD;
90                 return 0;
91         }
92
93         /**
94      * @param i zero indexed player
95      */
96         int entcs_GetWantsJoin(int i)
97         {
98                 entity e = entcs_receiver(i);
99                 return e.wants_join;
100         }
101
102         /**
103      * @param i zero indexed player
104      */
105         int entcs_GetClientColors(int i)
106         {
107                 entity e = entcs_receiver(i);
108                 return e ? e.colormap : 0;
109         }
110
111         /**
112         * @param i zero indexed player
113         * @returns 0 if not teamplay
114         */
115         int entcs_GetTeamColor(int i)
116         {
117                 return (!teamplay) ? 0 : entcs_GetClientColors(i) & 15;
118         }
119
120         /**
121         * @param i zero indexed player
122         */
123         int entcs_GetTeam(int i)
124         {
125                 return (entcs_GetSpecState(i) == ENTCS_SPEC_PURE) ? NUM_SPECTATOR : entcs_GetTeamColor(i);
126         }
127
128         /**
129          * Same as `entcs_GetTeam`, but returns -1 for no team in teamplay
130          */
131         int entcs_GetScoreTeam(int i)
132         {
133                 int t = entcs_GetTeam(i);
134                 if (teamplay && !t) t = -1;
135                 return t;
136         }
137
138         /**
139         * @param i zero indexed player
140         */
141         string entcs_GetName(int i)
142         {
143                 entity e = entcs_receiver(i);
144                 return e ? ColorTranslateRGB(e.netname) : "";
145         }
146         
147         int entcs_GetCountryCode(int i)
148         {
149                 entity e = entcs_receiver(i);
150                 return e.countrycode;
151         }
152         
153         string entcs_GetRank(int i)
154         {
155                 entity e = entcs_receiver(i);
156                 return e.rank;
157         }
158
159     /**
160      * @param i zero indexed player
161      */
162         entity CSQCModel_server2csqc(int i);
163
164     .float alpha;
165
166     /**
167      * @param i zero indexed player
168      */
169         float entcs_GetAlpha(int i)
170         {
171                 entity e = CSQCModel_server2csqc(i);
172                 return e ? e.alpha : 1;
173         }
174
175     /**
176      * @param i zero indexed player
177      */
178         vector entcs_GetColor(int i)
179         {
180                 entity e = CSQCModel_server2csqc(i);
181                 return (!e || e.colormap <= 0)
182                        ? '1 1 1'
183                            : colormapPaletteColor(((e.colormap >= 1024)
184                         ? e.colormap
185                         : entcs_GetClientColors(e.colormap - 1)) & 15, true)
186                 ;
187         }
188
189     /**
190      * @param i zero indexed player
191      */
192         bool entcs_IsDead(int i)
193         {
194                 entity e = CSQCModel_server2csqc(i);
195                 return e ? e.csqcmodel_isdead : false;
196         }
197
198 #endif