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