]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/assault.qc
after assault round end: Respawn all clients, centerprint what role they
[divverent/nexuiz.git] / data / qcsrc / server / assault.qc
1
2 // attacker spawn point
3 void info_player_attacker() {
4         info_player_deathmatch();
5         self.team = COLOR_TEAM1; // red, gets swapped every round
6 }
7
8 // defender spawn point
9 void info_player_defender() {
10         info_player_deathmatch();
11         self.team = COLOR_TEAM2; // blue, gets swapped every round
12 }
13
14 // reset this objective. Used when spawning an objective
15 // and when a new round starts
16 void assault_objective_reset() {
17         self.health = ASSAULT_VALUE_INACTIVE;
18 }
19
20 void assault_objective_use() {
21         // activate objective
22         self.health = 100; 
23         self.nextthink = time + 0.1;
24 }
25
26 void assault_objective_think() {
27         local entity oldself;   
28         if(self.health < 0) {
29                 //self.effects = 0;
30                 local entity ent;
31                 ent = find(world, targetname, self.target);
32                 while(ent) {
33                         oldself = self;
34                         self = ent;
35                         self.use();
36                         self = oldself;
37                         ent = find(ent, targetname, self.target);
38                         
39                 }
40         } else {
41                 //self.effects = EF_STARDUST;
42                 self.nextthink = time + 0.1;
43         }
44         
45 }
46
47 void target_objective() {
48         self.classname = "target_objective";
49         self.think = assault_objective_think;
50         self.use = assault_objective_use;
51         assault_objective_reset();
52 }
53
54 float assault_objective_decrease_customizeforclient() {
55         if(self.cnt == 0) {
56                 if(other.team == assault_attacker_team)
57                         setmodel(self, "models/sprites/here.sp2");
58                 else
59                         setmodel(self, "models/sprites/helpme.sp2");
60         } else {
61                 return FALSE;
62         }
63         return TRUE;
64 }
65
66
67 void assault_objective_decrease_think() {
68
69         local entity objective;
70         local float found;
71         found = 0;
72         objective = find(world, targetname, self.target);
73         while(objective && found == 0) {
74                 if(objective.classname == "target_objective") {
75                         found = 1;
76                         if(objective.health < ASSAULT_VALUE_INACTIVE) { // targeted objective is active
77                                 if(self.cnt == 1 && self.max_health >= ASSAULT_VALUE_INACTIVE) { 
78                                         // decrease was fired already, but objective did recover (round reset)
79                                         self.cnt = 0;
80                                 }
81                         } else { // objective isn't active
82                                 self.cnt = 1;
83                         }
84                         self.max_health = objective.health; // save current objective status for next think
85                 }
86         }
87
88
89         self.nextthink = time + 0.2;
90 }
91
92
93 // decrease the health of targeted objectives
94 void assault_objective_decrease_use() {
95
96         if(activator.team != assault_attacker_team)
97                 return;
98
99         local entity ent;
100         ent = find(world, targetname, self.target);
101         while(ent) {
102                 if(ent.health > 0 && ent.health < ASSAULT_VALUE_INACTIVE)
103                         ent.health = ent.health - self.dmg;
104                 ent = find(ent, targetname, self.target);
105         }
106
107         self.cnt = 1;
108 }
109
110 // this entity should target an objective and be targeted by triggers
111 void target_objective_decrease() {
112
113         self.classname = "target_objective_decrease";
114
115         if(!self.dmg) {
116                 self.dmg = 101;
117         }
118         self.cnt = 0; // not used yet
119         self.use = assault_objective_decrease_use;
120         self.mdl = "models/sprites/here.sp2";
121         self.effects = EF_NODEPTHTEST;
122         self.health = ASSAULT_VALUE_INACTIVE;
123         self.max_health = ASSAULT_VALUE_INACTIVE;
124         self.think = assault_objective_decrease_think;
125         self.customizeentityforclient = assault_objective_decrease_customizeforclient;
126         self.nextthink = time;
127 }
128
129
130 void assault_destructible_reset() {
131         self.health = self.max_health;
132         self.model = self.mdl;
133         self.solid = SOLID_BSP;
134         self.cnt = 0; // not active
135         if(self.spawnflags)
136                 self.use();
137 }
138
139 void assault_destructible_use() {
140         self.cnt = 1; // mark active
141         self.takedamage = DAMAGE_YES;
142 }
143
144 void assault_destructible_destroy() {
145         local entity oldself;
146         
147         self.model = "";
148         self.takedamage = DAMAGE_NO;
149         self.solid = SOLID_NOT;
150         local entity ent;
151         ent = find(world, targetname, self.target);
152         while(ent) {
153                 oldself = self;
154                 self = ent;
155                 self.use();
156                 self = oldself;
157                 ent = find(ent, targetname, self.target);
158         }
159 }
160
161 void assault_destructible_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force) {
162
163         if(self.cnt > 0 && assault_attacker_team == attacker.team) {
164                 self.health = self.health - damage;
165         }
166
167         if(self.health < 0) {
168                 activator = attacker;
169                 assault_destructible_destroy();
170         }
171 }
172
173 // destructible walls that can be used to trigger target_objective_decrease
174 void func_assault_destructible() {
175         if(!self.health)
176                 self.health = 100;
177
178         self.max_health = self.health;
179         
180         self.cnt = 0; // not yet activated
181
182         self.classname = "func_assault_destructible";
183         self.mdl = self.model;
184         setmodel(self, self.mdl);
185
186         self.solid = SOLID_BSP;
187         self.use = assault_destructible_use;
188         self.event_damage = assault_destructible_damage;
189
190 }
191
192
193 // trigger new round
194 // reset objectives, toggle spawnpoints, reset triggers, ...
195 void assault_new_round() {
196         
197         // this assumes self.classname == "func_assault_roundend"!
198         self.cnt = self.cnt + 1;
199
200         // swap spawn point teams
201         local entity ent;
202         local entity oldself;
203
204         if(assault_attacker_team == COLOR_TEAM1) {
205                 assault_attacker_team = COLOR_TEAM2;
206         } else {
207                 assault_attacker_team = COLOR_TEAM1;
208         }
209
210         ent = find(world, classname, "info_player_deathmatch");
211         while (ent)
212         {
213                 oldself = self;
214                 self = ent;
215                 if(self.team == COLOR_TEAM1) {
216                         self.team = COLOR_TEAM2;
217                 } else {
218                         self.team = COLOR_TEAM1;
219                 }
220                 self = oldself;
221
222                 ent = find(ent, classname, "info_player_deathmatch");
223         } 
224
225         // reset all objectives
226         ent = find(world, classname, "target_objective");
227         while (ent)
228         {
229                 oldself = self;
230                 self = ent;
231                 assault_objective_reset();
232                 self = oldself;
233
234                 ent = find(ent, classname, "target_objective");
235         } 
236
237         // reset all target_object_decrease
238         ent = find(world, classname, "target_objective_decrease");
239         while (ent)
240         {
241                 ent.cnt = 0;
242                 ent = find(ent, classname, "target_objective_decrease");
243         } 
244
245         // reset all func_assault_destructible
246         ent = find(world, classname, "func_assault_destructible");
247         while (ent)
248         {
249                 oldself = self;
250                 self = ent;
251                 assault_destructible_reset();
252                 self = oldself;
253                 ent = find(ent, classname, "func_assault_destructible");
254         }
255
256         ent = find(world, classname, "target_assault_roundstart");
257         while (ent)
258         {
259                 oldself = self;
260                 self = ent;
261                 self.use();
262                 self = oldself;
263                 ent = find(ent, classname, "target_assault_roundstart");
264         }
265
266         // actually restart round... how to do that?
267         ent = find(world, classname, "player");
268         while(ent) {
269                 oldself = self;
270                 self = ent;
271                 PutClientInServer();
272                 self = oldself;
273                 ent = find(ent, classname, "player");
274         }
275 }
276
277 void target_assault_roundend() {
278         self.cnt = 0; // round counter
279         self.classname = "target_assault_roundend";
280         self.use = assault_new_round;
281 }
282
283 void assault_roundstart_use() {
284         local entity ent;
285         local entity oldself;
286         ent = find(world, targetname, self.target);
287         while(ent) {
288                 oldself = self;
289                 self = ent;
290                 self.use();
291                 self = oldself;
292                 ent = find(ent, targetname, self.target);
293         }
294 }
295
296 void target_assault_roundstart() {
297         assault_attacker_team = COLOR_TEAM1;
298         self.classname = "target_assault_roundstart";
299         self.use = assault_roundstart_use;
300         self.think = assault_roundstart_use;
301         self.nextthink = time + 0.1;
302 }
303
304