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