]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/ent_cs.qh
Merge branch 'master' into terencehill/ft_autorevive_progress
[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
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         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     /**
138      * @param i zero indexed player
139      */
140         entity CSQCModel_server2csqc(int i);
141
142     .float alpha;
143
144     /**
145      * @param i zero indexed player
146      */
147         float entcs_GetAlpha(int i)
148         {
149                 entity e = CSQCModel_server2csqc(i);
150                 return e ? e.alpha : 1;
151         }
152
153     /**
154      * @param i zero indexed player
155      */
156         vector entcs_GetColor(int i)
157         {
158                 entity e = CSQCModel_server2csqc(i);
159                 return (!e || e.colormap <= 0)
160                        ? '1 1 1'
161                            : colormapPaletteColor(((e.colormap >= 1024)
162                         ? e.colormap
163                         : entcs_GetClientColors(e.colormap - 1)) & 15, true)
164                 ;
165         }
166
167     /**
168      * @param i zero indexed player
169      */
170         bool entcs_IsDead(int i)
171         {
172                 entity e = CSQCModel_server2csqc(i);
173                 return e ? e.csqcmodel_isdead : false;
174         }
175
176 #endif