]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/ent_cs.qc
CSQC part for the new score system (not really finished yet, needs cleaning)
[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 ||
38            self.owner.classname == "observer" || to.classname == "observer")
39         {
40                 WriteByte(MSG_ENTITY, ENTCS_MSG_ONS_REMOVE);
41                 return;
42         }
43         WriteByte(MSG_ENTITY, ENTCS_MSG_ONS_GPS);
44         WriteCoord(MSG_ENTITY, self.owner.origin_x);
45         WriteCoord(MSG_ENTITY, self.owner.origin_y);
46         WriteCoord(MSG_ENTITY, self.owner.angles_y);
47 }
48
49 void entcs_common_self()
50 {
51         /*
52         entity pl;
53         if(self.pingtime < time)
54         {
55                 self.pingtime = time + 9; // keep it 1 below the non-ons update intervall
56                 // just to be safe... (blah)
57                 WriteByte(MSG_ENTITY, ENTCS_MSG_PING);
58                 FOR_EACH_REALCLIENT(pl)
59                 {
60                         WriteByte(MSG_ENTITY, num_for_edict(pl));
61                         WriteShort(MSG_ENTITY, pl.ping);
62                 }
63                 WriteByte(MSG_ENTITY, 0);
64         }
65         */
66 }
67
68 float entcs_send(entity to)
69 {
70         WriteByte(MSG_ENTITY, ENT_CLIENT_ENTCS);
71         WriteByte(MSG_ENTITY, self.health); // serves as entitynumber
72         
73         if(to == self.owner)
74         {
75                 entcs_common_self();
76         }
77         
78         if(g_onslaught)
79                 entcs_ons(to);
80         
81         WriteByte(MSG_ENTITY, ENTCS_MSG_END);
82         return TRUE;
83 };
84
85 void entcs_think()
86 {
87         self.team = self.owner.team;
88         self.Version++;
89         setorigin(self, self.owner.origin);
90         if(game == GAME_ONSLAUGHT)
91                 self.nextthink = time + 0.1;
92         else
93                 self.nextthink = time + 10; // update pings every 10 seconds
94 };
95
96 entity attach_entcs()
97 {
98         local float num;
99         local entity ent;
100
101         print("Attaching ENTCS entity\n");
102
103         num = num_for_edict(self);
104         ent = get_entcs_ent();
105
106         ent.classname = "entcs_sender";
107         ent.health = num;
108         setorigin(ent, self.origin);
109         ent.owner = self;
110         ent.think = entcs_think;
111         ent.nextthink = time;
112         ent.effects = EF_NODEPTHTEST | EF_LOWPRECISION;
113         ent.model = "entcs_sender";
114         ent.modelindex = 1;
115         setsize(ent, '0 0 0', '0 0 0');
116                 
117         ent.SendEntity = entcs_send;
118         return ent;
119 };
120
121 void detach_entcs()
122 {
123         local float num;
124         local entity ent;
125         num = num_for_edict(self);
126         for(ent = entcs_start; ent.chain.owner != self && ent.chain != world; ent = ent.chain);
127         if(ent.chain != world && ent.chain.owner == self)
128         {
129                 remove(ent.chain);
130                 ent.chain = ent.chain.chain;
131         }
132 };