]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/ent_cs.qh
Merge branch 'master' into Mario/qc_camstuff
[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 /** True when private information such as origin is available */
11 .bool m_entcs_private;
12
13 /** True when origin is available */
14 // FIXME: it seems sometimes this is false when observing even though observers should be able to know about all players
15 // easily reproducible on heart_v2 or The_Yard with bots - might be because they lack waypoints and bots stand still
16 // it has happened in matches with players and no bots but much more rarely
17 .bool has_origin;
18
19 /** True when a recent server sent origin has been received */
20 .bool has_sv_origin;
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 #endif
48
49 #ifdef CSQC
50
51         ArrayList _entcs;
52         STATIC_INIT(_entcs)
53         {
54                 AL_NEW(_entcs, 255, NULL, e);  // 255 is the engine limit on maxclients
55         }
56         SHUTDOWN(_entcs)
57         {
58                 AL_DELETE(_entcs);
59         }
60         #define entcs_receiver(...) EVAL_entcs_receiver(OVERLOAD(entcs_receiver, __VA_ARGS__))
61         #define EVAL_entcs_receiver(...) __VA_ARGS__
62         #define entcs_receiver_1(i) AL_gete(_entcs, i)
63         #define entcs_receiver_2(i, v) AL_sete(_entcs, i, v)
64         #define entcs_is_self(e) ((e).sv_entnum == player_localentnum - 1)
65
66         /**
67      * @param i zero indexed player
68      */
69     .int frags;
70         bool entcs_IsSpectating(int i)
71         {
72                 bool unconnected = !playerslots[i].gotscores;
73                 entity e = entcs_receiver(i);
74                 return unconnected || ((e) ? e.frags : stof(getplayerkeyvalue(i, "frags"))) == FRAGS_SPECTATOR;
75         }
76
77         /**
78      * @param i zero indexed player
79      */
80         int entcs_GetClientColors(int i)
81         {
82                 entity e = entcs_receiver(i);
83                 return e ? e.colormap : stof(getplayerkeyvalue(i, "colors"));
84         }
85
86         /**
87         * @param i zero indexed player
88         * @returns 0 if not teamplay
89         */
90         int entcs_GetTeamColor(int i)
91         {
92                 return (!teamplay) ? 0 : entcs_GetClientColors(i) & 15;
93         }
94
95         /**
96         * @param i zero indexed player
97         * @returns 0 if not teamplay | NUM_TEAM_##N | NUM_SPECTATOR
98         */
99         int entcs_GetTeam(int i)
100         {
101                 return entcs_IsSpectating(i) ? NUM_SPECTATOR : entcs_GetTeamColor(i);
102         }
103
104         /**
105          * Same as `entcs_GetTeam`, but returns -1 for no team in teamplay
106          */
107         int entcs_GetScoreTeam(int i)
108         {
109                 int t = entcs_GetTeam(i);
110                 if (teamplay && !t) t = -1;
111                 return t;
112         }
113
114         /**
115         * @param i zero indexed player
116         */
117         string entcs_GetName(int i)
118         {
119                 entity e = entcs_receiver(i);
120                 return ColorTranslateRGB(e ? e.netname : getplayerkeyvalue(i, "name"));
121         }
122
123     /**
124      * @param i zero indexed player
125      */
126         entity CSQCModel_server2csqc(int i);
127
128     .float alpha;
129
130     /**
131      * @param i zero indexed player
132      */
133         float entcs_GetAlpha(int i)
134         {
135                 entity e = CSQCModel_server2csqc(i);
136                 return e ? e.alpha : 1;
137         }
138
139     /**
140      * @param i zero indexed player
141      */
142         vector entcs_GetColor(int i)
143         {
144                 entity e = CSQCModel_server2csqc(i);
145                 return (!e || e.colormap <= 0)
146                        ? '1 1 1'
147                            : colormapPaletteColor(((e.colormap >= 1024)
148                         ? e.colormap
149                         : entcs_GetClientColors(e.colormap - 1)) & 15, true)
150                 ;
151         }
152
153     /**
154      * @param i zero indexed player
155      */
156         bool entcs_IsDead(int i)
157         {
158                 entity e = CSQCModel_server2csqc(i);
159                 return e ? e.csqcmodel_isdead : false;
160         }
161
162 #endif