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