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