]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/ent_cs.qc
Temporarily tweak entcs so it's sent for both self and enemy players in the view...
[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) // allow sending entcs for self, for damage effects to work. To be decided!
32         //      return FALSE;
33         if(other.classname == "player")
34                 if(!teamplay || o.team != other.team)
35                         //if not (radar_showennemies)
36                         if not (checkpvs(other.origin + other.view_ofs, o))  // allow sending entcs for enemies in view, for damage effects to work. To be decided!
37                                 return FALSE;
38         return TRUE;
39 }
40
41 float entcs_send(entity to, float sf)
42 {
43         WriteByte(MSG_ENTITY, ENT_CLIENT_ENTCS);
44         WriteByte(MSG_ENTITY, sf);
45         if(sf & 1)
46                 WriteByte(MSG_ENTITY, num_for_edict(self.owner)-1);
47         if(sf & 2)
48         {
49                 WriteShort(MSG_ENTITY, self.origin_x);
50                 WriteShort(MSG_ENTITY, self.origin_y);
51                 WriteShort(MSG_ENTITY, self.origin_z);
52         }
53         if(sf & 4)
54                 WriteByte(MSG_ENTITY, self.angles_y * 256.0 / 360);
55         if(sf & 8)
56                 WriteByte(MSG_ENTITY, self.health / 10); // FIXME use a better scale?
57         if(sf & 16)
58                 WriteByte(MSG_ENTITY, self.armorvalue / 10); // FIXME use a better scale?
59         return TRUE;
60 };
61
62 void entcs_think()
63 {
64         self.nextthink = time + 0.033333333333; // increase this to like 0.15 once the client can do smoothing
65
66         entity o;
67         o = self.owner;
68
69         if(o.origin != self.origin)
70         {
71                 setorigin(self, o.origin);
72                 self.SendFlags |= 2;
73         }
74         if(o.angles_y != self.angles_y)
75         {
76                 self.angles = o.angles;
77                 self.SendFlags |= 4;
78         }
79         if(o.health != self.health)
80         {
81                 self.health = o.health;
82                 self.SendFlags |= 8;
83         }
84         if(o.armorvalue != self.armorvalue)
85         {
86                 self.armorvalue = o.armorvalue;
87                 self.SendFlags |= 16;
88         }
89 };
90
91 entity attach_entcs()
92 {
93         local entity ent;
94
95         ent = spawn();
96         ent.classname = "entcs_sender_v2";
97         ent.owner = self;
98         ent.think = entcs_think;
99         ent.nextthink = time;
100
101         Net_LinkEntity(ent, FALSE, 0, entcs_send);
102         ent.customizeentityforclient = entcs_customize;
103
104         self.entcs = ent;
105
106         return ent;
107 };
108
109 void detach_entcs()
110 {
111         remove(self.entcs);
112         self.entcs = world;
113 };