]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/ent_cs.qc
Merge remote branch 'origin/master' into samual/add_eventlog_reporting
[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") || other.caplayer)
34                 if(!teamplay || 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         WriteByte(MSG_ENTITY, ENT_CLIENT_ENTCS);
43         WriteByte(MSG_ENTITY, sf);
44         if(sf & 1)
45                 WriteByte(MSG_ENTITY, num_for_edict(self.owner)-1);
46         if(sf & 2)
47         {
48                 WriteShort(MSG_ENTITY, self.origin_x);
49                 WriteShort(MSG_ENTITY, self.origin_y);
50                 WriteShort(MSG_ENTITY, self.origin_z);
51         }
52         if(sf & 4)
53                 WriteByte(MSG_ENTITY, self.angles_y * 256.0 / 360);
54         if(sf & 8)
55                 WriteByte(MSG_ENTITY, self.health / 10); // FIXME use a better scale?
56         if(sf & 16)
57                 WriteByte(MSG_ENTITY, self.armorvalue / 10); // FIXME use a better scale?
58         return TRUE;
59 }
60
61 void entcs_think()
62 {
63         self.nextthink = time + 0.033333333333; // increase this to like 0.15 once the client can do smoothing
64
65         entity o;
66         o = self.owner;
67
68         if(o.origin != self.origin)
69         {
70                 setorigin(self, o.origin);
71                 self.SendFlags |= 2;
72         }
73         if(o.angles_y != self.angles_y)
74         {
75                 self.angles = o.angles;
76                 self.SendFlags |= 4;
77         }
78         if(o.health != self.health)
79         {
80                 self.health = o.health;
81                 self.SendFlags |= 8;
82         }
83         if(o.armorvalue != self.armorvalue)
84         {
85                 self.armorvalue = o.armorvalue;
86                 self.SendFlags |= 16;
87         }
88 }
89
90 entity attach_entcs()
91 {
92         entity ent;
93
94         ent = spawn();
95         ent.classname = "entcs_sender_v2";
96         ent.owner = self;
97         ent.think = entcs_think;
98         ent.nextthink = time;
99
100         Net_LinkEntity(ent, FALSE, 0, entcs_send);
101         ent.customizeentityforclient = entcs_customize;
102
103         self.entcs = ent;
104
105         return ent;
106 }
107
108 void detach_entcs()
109 {
110         remove(self.entcs);
111         self.entcs = world;
112 }