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