]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/ent_cs.qc
now REALLY remove dead players
[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_start;
17
18 void entcs_init()
19 {
20         print("Initializing ClientSide information entities\n");
21         entcs_start = spawn();
22         entcs_start.solid = SOLID_NOT;
23         entcs_start.chain = world;
24 };
25
26 entity get_entcs_ent()
27 {
28         entity entcs;
29         entcs = spawn();
30         entcs.chain = entcs_start.chain;
31         entcs_start.chain = entcs;
32         return entcs;
33 };
34
35 void entcs_ons(entity to)
36 {
37         if(to == self.owner || self.team != to.team || self.owner.classname == "observer" || to.classname == "observer" || self.owner.deadflag != DEAD_NO)
38         {
39                 WriteByte(MSG_ENTITY, ENTCS_MSG_ONS_REMOVE); // looks like a waste to me
40                 return;
41         }
42         WriteByte(MSG_ENTITY, ENTCS_MSG_ONS_GPS);
43         WriteShort(MSG_ENTITY, self.owner.origin_x);
44         WriteShort(MSG_ENTITY, self.owner.origin_y);
45         WriteShort(MSG_ENTITY, self.owner.origin_z);
46         WriteByte(MSG_ENTITY, self.owner.angles_y * 256.0 / 360);
47 }
48
49 void entcs_common_self()
50 {
51 }
52
53 float entcs_send(entity to)
54 {
55         WriteByte(MSG_ENTITY, ENT_CLIENT_ENTCS);
56         WriteByte(MSG_ENTITY, self.health); // serves as entitynumber
57
58         if(to == self.owner)
59         {
60                 entcs_common_self();
61         }
62
63         if(teams_matter)
64                 entcs_ons(to);
65
66         WriteByte(MSG_ENTITY, ENTCS_MSG_END);
67         return TRUE;
68 };
69
70 void entcs_think()
71 {
72         self.team = self.owner.team;
73         self.Version++;
74         setorigin(self, self.owner.origin);
75         self.nextthink = time;
76 };
77
78 entity attach_entcs()
79 {
80         local float num;
81         local entity ent;
82
83         num = num_for_edict(self);
84         ent = get_entcs_ent();
85
86         ent.classname = "entcs_sender";
87         ent.health = num;
88         setorigin(ent, self.origin);
89         ent.owner = self;
90         ent.think = entcs_think;
91         ent.nextthink = time;
92         ent.effects = EF_NODEPTHTEST | EF_LOWPRECISION;
93         ent.model = "entcs_sender";
94         ent.modelindex = 1;
95         setsize(ent, '0 0 0', '0 0 0');
96
97         ent.SendEntity = entcs_send;
98         return ent;
99 };
100
101 void detach_entcs()
102 {
103         local float num;
104         local entity ent;
105         num = num_for_edict(self);
106         for(ent = entcs_start; ent.chain.owner != self && ent.chain != world; ent = ent.chain);
107         if(ent.chain != world && ent.chain.owner == self)
108         {
109                 remove(ent.chain);
110                 ent.chain = ent.chain.chain;
111         }
112 };