]> de.git.xonotic.org Git - voretournament/voretournament.git/blob - data/qcsrc/server/ent_cs.qc
Attempt to port the shownames feature from Xonotic (floating names above players...
[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(!teamplay || 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         WriteByte(MSG_ENTITY, ENT_CLIENT_ENTCS);\r
43         WriteByte(MSG_ENTITY, sf);\r
44         if(sf & 1)\r
45                 WriteByte(MSG_ENTITY, num_for_edict(self.owner)-1);\r
46         if(sf & 2)\r
47         {\r
48                 WriteShort(MSG_ENTITY, self.origin_x);\r
49                 WriteShort(MSG_ENTITY, self.origin_y);\r
50                 WriteShort(MSG_ENTITY, self.origin_z);\r
51         }\r
52         if(sf & 4)\r
53                 WriteByte(MSG_ENTITY, self.angles_y * 256.0 / 360);\r
54         if(sf & 8)\r
55                 WriteByte(MSG_ENTITY, self.health / 10); // FIXME use a better scale?\r
56         if(sf & 16)\r
57                 WriteByte(MSG_ENTITY, self.armorvalue / 10); // FIXME use a better scale?\r
58         return TRUE;\r
59 };\r
60 \r
61 void entcs_think()\r
62 {\r
63         self.nextthink = time + 0.033333333333; // increase this to like 0.15 once the client can do smoothing\r
64 \r
65         entity o;\r
66         o = self.owner;\r
67 \r
68         if(o.origin != self.origin)\r
69         {\r
70                 setorigin(self, o.origin);\r
71                 self.SendFlags |= 2;\r
72         }\r
73         if(o.angles_y != self.angles_y)\r
74         {\r
75                 self.angles = o.angles;\r
76                 self.SendFlags |= 4;\r
77         }\r
78         if(o.health != self.health)\r
79         {\r
80                 self.health = o.health;\r
81                 self.SendFlags |= 8;\r
82         }\r
83         if(o.armorvalue != self.armorvalue)\r
84         {\r
85                 self.armorvalue = o.armorvalue;\r
86                 self.SendFlags |= 16;\r
87         }\r
88 };\r
89 \r
90 entity attach_entcs()\r
91 {\r
92         local entity ent;\r
93 \r
94         ent = spawn();\r
95         ent.classname = "entcs_sender_v2";\r
96         ent.owner = self;\r
97         ent.think = entcs_think;\r
98         ent.nextthink = time;\r
99 \r
100         Net_LinkEntity(ent, FALSE, 0, entcs_send);\r
101         ent.customizeentityforclient = entcs_customize;\r
102 \r
103         self.entcs = ent;\r
104 \r
105         return ent;\r
106 };\r
107 \r
108 void detach_entcs()\r
109 {\r
110         remove(self.entcs);\r
111         self.entcs = world;\r
112 };\r