]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/ent_cs.qh
Merge branch 'martin-t/dmgtextconfig' 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 /** 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 e);
40
41         void entcs_detach(entity e);
42
43         .int m_forceupdate;
44
45 /** Force an origin update, for player sounds */
46         #define entcs_force_origin(e) ((e).entcs.m_forceupdate = BIT(2))
47
48 #endif
49
50 #ifdef CSQC
51
52         ArrayList _entcs;
53         STATIC_INIT(_entcs)
54         {
55                 AL_NEW(_entcs, 255, NULL, e);  // 255 is the engine limit on maxclients
56         }
57         SHUTDOWN(_entcs)
58         {
59                 AL_DELETE(_entcs);
60         }
61         #define entcs_receiver(...) EVAL_entcs_receiver(OVERLOAD(entcs_receiver, __VA_ARGS__))
62         #define EVAL_entcs_receiver(...) __VA_ARGS__
63         #define entcs_receiver_1(i) AL_gete(_entcs, i)
64         #define entcs_receiver_2(i, v) AL_sete(_entcs, i, v)
65         #define entcs_is_self(e) ((e).sv_entnum == player_localentnum - 1)
66
67         /**
68      * @param i zero indexed player
69      */
70     .int frags;
71         bool entcs_IsSpectating(int i)
72         {
73                 bool unconnected = !playerslots[i].gotscores;
74                 entity e = entcs_receiver(i);
75                 return unconnected || ((e) ? e.frags : stof(getplayerkeyvalue(i, "frags"))) == FRAGS_SPECTATOR;
76         }
77
78         /**
79      * @param i zero indexed player
80      */
81         int entcs_GetClientColors(int i)
82         {
83                 entity e = entcs_receiver(i);
84                 return e ? e.colormap : stof(getplayerkeyvalue(i, "colors"));
85         }
86
87         /**
88         * @param i zero indexed player
89         * @returns 0 if not teamplay
90         */
91         int entcs_GetTeamColor(int i)
92         {
93                 return (!teamplay) ? 0 : entcs_GetClientColors(i) & 15;
94         }
95
96         /**
97         * @param i zero indexed player
98         * @returns 0 if not teamplay | NUM_TEAM_##N | NUM_SPECTATOR
99         */
100         int entcs_GetTeam(int i)
101         {
102                 return entcs_IsSpectating(i) ? NUM_SPECTATOR : entcs_GetTeamColor(i);
103         }
104
105         /**
106          * Same as `entcs_GetTeam`, but returns -1 for no team in teamplay
107          */
108         int entcs_GetScoreTeam(int i)
109         {
110                 int t = entcs_GetTeam(i);
111                 if (teamplay && !t) t = -1;
112                 return t;
113         }
114
115         /**
116         * @param i zero indexed player
117         */
118         string entcs_GetName(int i)
119         {
120                 entity e = entcs_receiver(i);
121                 return ColorTranslateRGB(e ? e.netname : getplayerkeyvalue(i, "name"));
122         }
123
124     /**
125      * @param i zero indexed player
126      */
127         entity CSQCModel_server2csqc(int i);
128
129     .float alpha;
130
131     /**
132      * @param i zero indexed player
133      */
134         float entcs_GetAlpha(int i)
135         {
136                 entity e = CSQCModel_server2csqc(i);
137                 return e ? e.alpha : 1;
138         }
139
140     /**
141      * @param i zero indexed player
142      */
143         vector entcs_GetColor(int i)
144         {
145                 entity e = CSQCModel_server2csqc(i);
146                 return (!e || e.colormap <= 0)
147                        ? '1 1 1'
148                            : colormapPaletteColor(((e.colormap >= 1024)
149                         ? e.colormap
150                         : entcs_GetClientColors(e.colormap - 1)) & 15, true)
151                 ;
152         }
153
154     /**
155      * @param i zero indexed player
156      */
157         bool entcs_IsDead(int i)
158         {
159                 entity e = CSQCModel_server2csqc(i);
160                 return e ? e.csqcmodel_isdead : false;
161         }
162
163 #endif