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