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