]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/ent_cs.qc
Merge branch 'master' into fruitiex/gamemode_freezetag
[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")
34                 if(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         entity o;
43         o = self.owner;
44         WriteByte(MSG_ENTITY, ENT_CLIENT_ENTCS);
45         WriteByte(MSG_ENTITY, num_for_edict(o));
46         WriteShort(MSG_ENTITY, o.origin_x);
47         WriteShort(MSG_ENTITY, o.origin_y);
48         WriteShort(MSG_ENTITY, o.origin_z);
49         WriteByte(MSG_ENTITY, o.angles_y * 256.0 / 360);
50         return TRUE;
51 };
52
53 void entcs_think()
54 {
55         self.nextthink = time;
56
57         entity o;
58         o = self.owner;
59
60         if(o.origin != self.origin || o.angles != self.angles)
61         {
62                 setorigin(self, o.origin);
63                 self.angles = o.angles;
64                 self.SendFlags |= 1;
65         }
66 };
67
68 entity attach_entcs()
69 {
70         local entity ent;
71
72         ent = spawn();
73         ent.classname = "entcs_sender_v2";
74         ent.owner = self;
75         ent.think = entcs_think;
76         ent.nextthink = time;
77
78         Net_LinkEntity(ent, FALSE, 0, entcs_send);
79         ent.customizeentityforclient = entcs_customize;
80
81         self.entcs = ent;
82
83         return ent;
84 };
85
86 void detach_entcs()
87 {
88         remove(self.entcs);
89         self.entcs = world;
90 };