]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/ent_cs.qc
forgot this one
[divverent/nexuiz.git] / data / 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                         return FALSE;
36         return TRUE;
37 }
38
39 float entcs_send(entity to)
40 {
41         entity o;
42         o = self.owner;
43         WriteByte(MSG_ENTITY, ENT_CLIENT_ENTCS);
44         WriteByte(MSG_ENTITY, num_for_edict(o));
45         WriteShort(MSG_ENTITY, o.origin_x);
46         WriteShort(MSG_ENTITY, o.origin_y);
47         WriteShort(MSG_ENTITY, o.origin_z);
48         WriteByte(MSG_ENTITY, o.angles_y * 256.0 / 360);
49         return TRUE;
50 };
51
52 void entcs_think()
53 {
54         self.nextthink = time;
55
56         entity o;
57         o = self.owner;
58
59         if(o.origin != self.origin || o.angles != self.angles)
60         {
61                 self.origin = o.origin;
62                 self.angles = o.angles;
63                 self.SendFlags |= 1;
64         }
65 };
66
67 entity attach_entcs()
68 {
69         local entity ent;
70
71         ent = spawn();
72         ent.classname = "entcs_sender_v2";
73         ent.owner = self;
74         ent.think = entcs_think;
75         ent.nextthink = time;
76         ent.effects = EF_NODEPTHTEST | EF_LOWPRECISION;
77         ent.model = "entcs_sender";
78         ent.modelindex = 1;
79
80         ent.SendEntity = entcs_send;
81         ent.customizeentityforclient = entcs_customize;
82
83         self.entcs = ent;
84
85         return ent;
86 };
87
88 void detach_entcs()
89 {
90         remove(self.entcs);
91         self.entcs = world;
92 };