]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/ent_cs.qh
Merge branch 'terencehill/ca_bots_fix' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / ent_cs.qh
1 #pragma once
2
3 REGISTER_NET_LINKED(ENT_CLIENT_ENTCS)
4 REGISTER_NET_TEMP(CLIENT_ENTCS)
5
6 /** True when private information such as origin is available */
7 .bool m_entcs_private;
8 /** True when origin is available */
9 .bool has_origin;
10 /** True when a recent server sent origin has been received */
11 .bool has_sv_origin;
12
13 #ifdef SVQC
14 /*
15  * The point of these entities is to avoid the problems
16  * with clientprediction.
17  * If you add SendEntity to players, the engine will not
18  * do any prediction anymore, and you'd have to write the whole
19  * prediction code in CSQC, you want that? :P
20  * Data can depend on gamemode. For now, it serves as GPS entities
21  * in onslaught... YAY ;)
22  */
23
24         .entity entcs;
25
26         bool entcs_send(entity this, entity to, int sf);
27
28         void entcs_think(entity this);
29
30         void entcs_attach(entity e);
31
32         void entcs_detach(entity e);
33
34         .int m_forceupdate;
35
36 /** Force an origin update, for player sounds */
37         #define entcs_force_origin(e) ((e).entcs.m_forceupdate = BIT(2))
38
39 #endif
40
41 #ifdef CSQC
42
43         ArrayList _entcs;
44         STATIC_INIT(_entcs)
45         {
46                 AL_NEW(_entcs, 255, NULL, e);  // 255 is the engine limit on maxclients
47         }
48         SHUTDOWN(_entcs)
49         {
50                 AL_DELETE(_entcs);
51         }
52         #define entcs_receiver(...) EVAL_entcs_receiver(OVERLOAD(entcs_receiver, __VA_ARGS__))
53         #define EVAL_entcs_receiver(...) __VA_ARGS__
54         #define entcs_receiver_1(i) AL_gete(_entcs, i)
55         #define entcs_receiver_2(i, v) AL_sete(_entcs, i, v)
56         #define entcs_is_self(e) ((e).sv_entnum == player_localentnum - 1)
57
58         /**
59      * @param i zero indexed player
60      */
61     .int frags;
62         bool entcs_IsSpectating(int i)
63         {
64                 bool unconnected = !playerslots[i].gotscores;
65                 entity e = entcs_receiver(i);
66                 return unconnected || ((e) ? e.frags : stof(getplayerkeyvalue(i, "frags"))) == FRAGS_SPECTATOR;
67         }
68
69         /**
70      * @param i zero indexed player
71      */
72         int entcs_GetClientColors(int i)
73         {
74                 entity e = entcs_receiver(i);
75                 return e ? e.colormap : stof(getplayerkeyvalue(i, "colors"));
76         }
77
78         /**
79         * @param i zero indexed player
80         * @returns 0 if not teamplay
81         */
82         int entcs_GetTeamColor(int i)
83         {
84                 return (!teamplay) ? 0 : entcs_GetClientColors(i) & 15;
85         }
86
87         /**
88         * @param i zero indexed player
89         * @returns 0 if not teamplay | NUM_TEAM_##N | NUM_SPECTATOR
90         */
91         int entcs_GetTeam(int i)
92         {
93                 return entcs_IsSpectating(i) ? NUM_SPECTATOR : entcs_GetTeamColor(i);
94         }
95
96         /**
97          * Same as `entcs_GetTeam`, but returns -1 for no team in teamplay
98          */
99         int entcs_GetScoreTeam(int i)
100         {
101                 int t = entcs_GetTeam(i);
102                 if (teamplay && !t) t = -1;
103                 return t;
104         }
105
106         /**
107         * @param i zero indexed player
108         */
109         string entcs_GetName(int i)
110         {
111                 entity e = entcs_receiver(i);
112                 return ColorTranslateRGB(e ? e.netname : getplayerkeyvalue(i, "name"));
113         }
114
115     /**
116      * @param i zero indexed player
117      */
118         entity CSQCModel_server2csqc(int i);
119
120     .float alpha;
121
122     /**
123      * @param i zero indexed player
124      */
125         float entcs_GetAlpha(int i)
126         {
127                 entity e = CSQCModel_server2csqc(i);
128                 return e ? e.alpha : 1;
129         }
130
131     /**
132      * @param i zero indexed player
133      */
134         vector entcs_GetColor(int i)
135         {
136                 entity e = CSQCModel_server2csqc(i);
137                 return (!e || e.colormap <= 0)
138                        ? '1 1 1'
139                            : colormapPaletteColor(((e.colormap >= 1024)
140                         ? e.colormap
141                         : entcs_GetClientColors(e.colormap - 1)) & 15, true)
142                 ;
143         }
144
145     /**
146      * @param i zero indexed player
147      */
148         bool entcs_IsDead(int i)
149         {
150                 entity e = CSQCModel_server2csqc(i);
151                 return e ? e.csqcmodel_isdead : false;
152         }
153
154 #endif