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