]> de.git.xonotic.org Git - voretournament/voretournament.git/blob - data/qcsrc/server/ent_cs.qc
6635689ebc8c304a552e31cb7a201d2724359e3a
[voretournament/voretournament.git] / data / qcsrc / server / ent_cs.qc
1 /**\r
2  * The point of these entities is to avoid the problems\r
3  * with clientprediction.\r
4  * If you add SendEntity to players, the engine will not\r
5  * do any prediction anymore, and you'd have to write the whole\r
6  * prediction code in CSQC, you want that? :P\r
7  * Data can depend on gamemode. For now, it serves as GPS entities\r
8  * in onslaught... YAY ;)\r
9  */\r
10 \r
11 // Beware: do not redefine those in other files\r
12 // and NO, you cannot use ".version", which already exists (at least\r
13 // it did when I added this) But you have to use .Version\r
14 // Capital V\r
15 \r
16 .entity entcs;\r
17 \r
18 void entcs_init()\r
19 {\r
20         print("Initializing ClientSide information entities\n");\r
21 };\r
22 \r
23 float entcs_customize()\r
24 {\r
25         entity o;\r
26         o = self.owner;\r
27         if(o.deadflag != DEAD_NO)\r
28                 return FALSE;\r
29         if(o.classname != "player")\r
30                 return FALSE;\r
31         if(other == o)\r
32                 return FALSE;\r
33         if(other.classname == "player")\r
34                 if(o.team != other.team)\r
35                         if not (radar_showennemies)\r
36                                 return FALSE;\r
37         return TRUE;\r
38 }\r
39 \r
40 float entcs_send(entity to, float sf)\r
41 {\r
42         entity o;\r
43         o = self.owner;\r
44         WriteByte(MSG_ENTITY, ENT_CLIENT_ENTCS);\r
45         WriteByte(MSG_ENTITY, num_for_edict(o));\r
46         WriteShort(MSG_ENTITY, o.origin_x);\r
47         WriteShort(MSG_ENTITY, o.origin_y);\r
48         WriteShort(MSG_ENTITY, o.origin_z);\r
49         WriteByte(MSG_ENTITY, o.angles_y * 256.0 / 360);\r
50         return TRUE;\r
51 };\r
52 \r
53 void entcs_think()\r
54 {\r
55         self.nextthink = time;\r
56 \r
57         entity o;\r
58         o = self.owner;\r
59 \r
60         if(o.origin != self.origin || o.angles != self.angles)\r
61         {\r
62                 setorigin(self, o.origin);\r
63                 self.angles = o.angles;\r
64                 self.SendFlags |= 1;\r
65         }\r
66 };\r
67 \r
68 entity attach_entcs()\r
69 {\r
70         local entity ent;\r
71 \r
72         ent = spawn();\r
73         ent.classname = "entcs_sender_v2";\r
74         ent.owner = self;\r
75         ent.think = entcs_think;\r
76         ent.nextthink = time;\r
77 \r
78         Net_LinkEntity(ent, FALSE, 0, entcs_send);\r
79         ent.customizeentityforclient = entcs_customize;\r
80 \r
81         self.entcs = ent;\r
82 \r
83         return ent;\r
84 };\r
85 \r
86 void detach_entcs()\r
87 {\r
88         remove(self.entcs);\r
89         self.entcs = world;\r
90 };\r