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