]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/ent_cs.qc
Committed my CSQC stuff, let's see:
[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 .float(entity to) SendEntity;
17 .float Version;
18
19 entity entcs_start;
20
21 void() entcs_init =
22 {
23         print("Initializing ClientSide information entities\n");
24         entcs_start = spawn();
25         entcs_start.solid = SOLID_NOT;
26         entcs_start.chain = world;
27 };
28
29 entity(float num) get_entcs_ent =
30 {
31         entity entcs;
32         entcs = spawn();
33         entcs.chain = entcs_start.chain;
34         entcs_start.chain = entcs;
35         return entcs;
36 };
37
38
39 float(entity to) entcs_send =
40 {
41         if(to == self.owner || self.team != to.team)
42                 return FALSE;
43         if(self.owner.classname == "observer" || to.classname == "observer")
44                 return FALSE;
45         
46         WriteByte(MSG_ENTITY, ENT_CLIENT_ENTCS);
47         WriteByte(MSG_ENTITY, self.health); // serves as entitynumber
48         WriteCoord(MSG_ENTITY, self.owner.origin_x);
49         WriteCoord(MSG_ENTITY, self.owner.origin_y);
50         WriteCoord(MSG_ENTITY, self.owner.angles_y);
51         // write health maybe?
52         return TRUE;
53 };
54
55 void() entcs_think =
56 {
57         self.team = self.owner.team;
58         self.Version++;
59         setorigin(self, self.owner.origin);
60         self.nextthink = time + 0.1;
61 };
62
63 void() attach_entcs =
64 {
65         local float num;
66         local entity ent;
67
68         print("Attaching ENTCS entity\n");
69
70         num = num_for_edict(self);
71         ent = get_entcs_ent(num);
72
73         ent.classname = "entcs_sender";
74         ent.health = num;
75         setorigin(ent, self.origin);
76         ent.owner = self;
77         ent.think = entcs_think;
78         ent.nextthink = time;
79         ent.effects = EF_NODEPTHTEST | EF_LOWPRECISION;
80         ent.model = "entcs_sender";
81         ent.modelindex = 1;
82         setsize(ent, '0 0 0', '0 0 0');
83                 
84         ent.SendEntity = entcs_send;
85 };
86
87 void() detach_entcs =
88 {
89         local float num;
90         local entity ent;
91         num = num_for_edict(self);
92         for(ent = entcs_start; ent.chain.owner != self && ent.chain != world; ent = ent.chain);
93         if(ent.chain != world && ent.chain.owner == self)
94         {
95                 remove(ent.chain);
96                 ent.chain = ent.chain.chain;
97         }
98 };