]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/ent_cs.qc
Mutators: combine headers
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / ent_cs.qc
1 #include "ent_cs.qh"
2
3 float entcs_customize()
4 {
5         SELFPARAM();
6         entity o = self.owner;
7         if(o.deadflag != DEAD_NO)
8                 return false;
9         if (!IS_PLAYER(o))
10                 return false;
11         if(other == o)
12                 return false;
13         if((IS_PLAYER(other)) || other.caplayer)
14                 if(!teamplay || o.team != other.team)
15                         if (!radar_showennemies)
16                                 return false;
17         return true;
18 }
19
20 bool entcs_send(entity this, entity to, int sf)
21 {
22         WriteByte(MSG_ENTITY, ENT_CLIENT_ENTCS);
23         WriteByte(MSG_ENTITY, sf);
24         if(sf & BIT(0))
25                 WriteByte(MSG_ENTITY, num_for_edict(self.owner) - 1);
26         if(sf & BIT(1))
27         {
28                 WriteShort(MSG_ENTITY, self.origin.x);
29                 WriteShort(MSG_ENTITY, self.origin.y);
30                 WriteShort(MSG_ENTITY, self.origin.z);
31         }
32         if(sf & BIT(2))
33                 WriteByte(MSG_ENTITY, self.angles.y * 256.0 / 360);
34         if(sf & BIT(3))
35                 WriteByte(MSG_ENTITY, self.health / 10); // FIXME use a better scale?
36         if(sf & BIT(4))
37                 WriteByte(MSG_ENTITY, self.armorvalue / 10); // FIXME use a better scale?
38         return true;
39 }
40
41 void entcs_think()
42 {
43         SELFPARAM();
44         self.nextthink = time + 0.033333333333; // increase this to like 0.15 once the client can do smoothing
45         entity o = self.owner;
46         if (o.origin != self.origin)
47         {
48                 setorigin(self, o.origin);
49                 self.SendFlags |= BIT(1);
50         }
51         if (o.angles.y != self.angles.y)
52         {
53                 self.angles = o.angles;
54                 self.SendFlags |= BIT(2);
55         }
56         if (o.health != self.health)
57         {
58                 self.health = o.health;
59                 self.SendFlags |= BIT(3);
60         }
61         if (o.armorvalue != self.armorvalue)
62         {
63                 self.armorvalue = o.armorvalue;
64                 self.SendFlags |= BIT(4);
65         }
66 }
67
68 entity attach_entcs(entity e)
69 {
70         entity ent = e.entcs = new(entcs_sender);
71         ent.owner = e;
72         ent.think = entcs_think;
73         ent.nextthink = time;
74
75         Net_LinkEntity(ent, false, 0, entcs_send);
76         ent.customizeentityforclient = entcs_customize;
77
78         return ent;
79 }
80
81 void detach_entcs(entity e)
82 {
83         if (!e.entcs) return;
84         remove(e.entcs);
85         e.entcs = NULL;
86 }