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