]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/common/ent_cs.qh
Merge branch 'terencehill/strzone_fixes' 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
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();
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         AL_declare(_entcs);
44         STATIC_INIT(_entcs)
45         {
46                 AL_init(_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(OVERLOAD(entcs_receiver, __VA_ARGS__))
53         #define entcs_receiver_1(i) AL_gete(_entcs, i)
54         #define entcs_receiver_2(i, v) AL_sete(_entcs, i, v)
55         #define entcs_is_self(e) ((e).sv_entnum == player_localentnum - 1)
56
57         /**
58      * @param i zero indexed player
59      */
60         bool entcs_IsSpectating(int i)
61         {
62                 bool unconnected = !playerslots[i].gotscores;
63                 return unconnected || stof(getplayerkeyvalue(i, "frags")) == FRAGS_SPECTATOR;
64         }
65
66         /**
67         * @param i zero indexed player
68         * @returns 0 if not teamplay
69         */
70         int entcs_GetTeamColor(int i)
71         {
72                 return (!teamplay) ? 0 : stof(getplayerkeyvalue(i, "colors")) & 15;
73         }
74
75         /**
76         * @param i zero indexed player
77         * @returns 0 if not teamplay | NUM_TEAM_##N | NUM_SPECTATOR
78         */
79         int entcs_GetTeam(int i)
80         {
81                 return entcs_IsSpectating(i) ? NUM_SPECTATOR : entcs_GetTeamColor(i);
82         }
83
84         /**
85         * @param i zero indexed player
86         */
87         string entcs_GetName(int i)
88         {
89                 return ColorTranslateRGB(getplayerkeyvalue(i, "name"));
90         }
91
92     /**
93      * @param i zero indexed player
94      */
95         entity CSQCModel_server2csqc(int i);
96
97     .float alpha;
98
99     /**
100      * @param i zero indexed player
101      */
102         float entcs_GetAlpha(int i)
103         {
104                 entity e = CSQCModel_server2csqc(i);
105                 return e ? e.alpha : 1;
106         }
107
108     /**
109      * @param i zero indexed player
110      */
111         vector entcs_GetColor(int i)
112         {
113                 entity e = CSQCModel_server2csqc(i);
114                 return (!e || e.colormap <= 0)
115                        ? '1 1 1'
116                            : colormapPaletteColor(((e.colormap >= 1024)
117                         ? e.colormap
118                         : stof(getplayerkeyvalue(e.colormap - 1, "colors"))) & 15, true)
119                 ;
120         }
121
122     /**
123      * @param i zero indexed player
124      */
125         bool entcs_IsDead(int i)
126         {
127                 entity e = CSQCModel_server2csqc(i);
128                 return e ? e.csqcmodel_isdead : false;
129         }
130
131 #endif
132
133 #endif