]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/assault.qc
turret_stdproc_use team changes the turret to its *activator* now.
[divverent/nexuiz.git] / data / qcsrc / server / assault.qc
1 void spawnfunc_func_breakable();
2
3 //=============================================================================
4
5 /*QUAKED spawnfunc_info_player_attacker (1 0 0) (-16 -16 -24) (16 16 45) INITIAL
6 Normal attacker spawning location for Nexuiz Asssault
7 -------- KEYS --------
8 angle : direction in which player will look when spawning in the game. Does not apply to bots.
9 target : this should point to a spawnfunc_target_objective to decide when this spawning point is active.
10 nobots : when set to 1, bots will never use this spawn point to respawn in the game.
11 nohumans : when set to 1, human players will never use this spawn point to respawn in the game.
12 notfree : when set to 1, entity will not spawn in "Free for all" and "Tournament" modes.
13 notteam : when set to 1, entity will not spawn in "Teamplay" and "CTF" modes.
14 notsingle : when set to 1, entity will not spawn in Single Player mode (bot play mode).
15 -------- SPAWNFLAGS --------
16 INITIAL : makes the spawnpoint the initial place for the player to spawn at the beginning of the game.*/
17 void spawnfunc_info_player_attacker() {
18         self.team = COLOR_TEAM1; // red, gets swapped every round
19         spawnfunc_info_player_deathmatch();
20 }
21
22 //=============================================================================
23
24 /*QUAKED spawnfunc_info_player_defender (0 1 0) (-16 -16 -24) (16 16 45) INITIAL
25 Normal defender spawning location for Nexuiz Asssault
26 -------- KEYS --------
27 angle : direction in which player will look when spawning in the game. Does not apply to bots.
28 target : this should point to a spawnfunc_target_objective to decide when this spawning point is active.
29 nobots : when set to 1, bots will never use this spawn point to respawn in the game.
30 nohumans : when set to 1, human players will never use this spawn point to respawn in the game.
31 notfree : when set to 1, entity will not spawn in "Free for all" and "Tournament" modes.
32 notteam : when set to 1, entity will not spawn in "Teamplay" and "CTF" modes.
33 notsingle : when set to 1, entity will not spawn in Single Player mode (bot play mode).
34 -------- SPAWNFLAGS --------
35 INITIAL : makes the spawnpoint the initial place for the player to spawn at the beginning of the game.*/
36 void spawnfunc_info_player_defender() {
37         self.team = COLOR_TEAM2; // blue, gets swapped every round
38         spawnfunc_info_player_deathmatch();
39 }
40
41 // reset this objective. Used when spawning an objective
42 // and when a new round starts
43 void assault_objective_reset() {
44         self.health = ASSAULT_VALUE_INACTIVE;
45 }
46
47 void assault_objective_use() {
48         // activate objective
49         self.health = 100;
50         self.nextthink = time + 0.1;
51 }
52
53 void assault_objective_think() {
54         if(self.health < 0) {
55                 //self.effects = 0;
56                 activator = self;
57                 SUB_UseTargets();
58         } else {
59                 //self.effects = EF_STARDUST;
60                 self.nextthink = time + 0.1;
61         }
62
63 }
64 //=============================================================================
65
66 /*QUAKED spawnfunc_target_objective (0 .5 0) (-8 -8 -8) (8 8 8)
67 Objective controller for Nexuiz Assault. When active it has 100 health. If it falls below 0 then
68 it'll trigger the next targeted entity (usually the next objective or spawnfunc_target_assault_roundend etc.)
69 -------- KEYS --------
70 targetname : point to e.g. next objective*/
71 void spawnfunc_target_objective() {
72         self.classname = "target_objective";
73         self.think = assault_objective_think;
74         self.use = assault_objective_use;
75         assault_objective_reset();
76 }
77
78 float assault_objective_decrease_customizeforclient() {
79         if(!self.spawnflags)
80                 return FALSE;
81
82         if(self.cnt == 0) {
83                 if(other.team == assault_attacker_team)
84                         if(self.spawnflags == 1)
85                                 setmodel(self, "models/sprites/push.sp2");
86                         else
87                                 setmodel(self, "models/sprites/destroy.sp2");
88                 else
89                         setmodel(self, "models/sprites/defend.sp2");
90         } else {
91                 return FALSE;
92         }
93         return TRUE;
94 }
95
96
97 void assault_objective_decrease_think() {
98
99         local entity objective;
100         local float found;
101         found = 0;
102         objective = find(world, targetname, self.target);
103         while(objective && found == 0) {
104                 if(objective.classname == "target_objective") {
105                         found = 1;
106                         if(objective.health < ASSAULT_VALUE_INACTIVE) { // targeted objective is active
107                                 if(self.cnt == 1 && self.max_health >= ASSAULT_VALUE_INACTIVE) {
108                                         // decrease was fired already, but objective did recover (round reset)
109                                         self.cnt = 0;
110                                 }
111                         } else { // objective isn't active
112                                 self.cnt = 1;
113                         }
114                         self.max_health = objective.health; // save current objective status for next think
115                 }
116         }
117
118         if(!self.spawnflags) {
119                 local entity ent;
120                 ent = find(world, target, self.targetname);
121                 if(ent) {
122                         if(ent.classname == "func_assault_destructible")
123                                 self.spawnflags = 2;
124                         else
125                                 self.spawnflags = 1;
126                 }
127         }
128
129         self.nextthink = time + 0.2;
130 }
131
132
133 // decrease the health of targeted objectives
134 void assault_objective_decrease_use() {
135
136         if(self.cnt > 0) {
137                 // did already fire
138                 return;
139         }
140
141         if(activator.team != assault_attacker_team) {
142                 // wrong team triggered decrease
143                 return;
144         }
145
146         local entity ent;
147         ent = find(world, targetname, self.target);
148         while(ent) {
149                 if(ent.health > 0 && ent.health < ASSAULT_VALUE_INACTIVE)
150                         ent.health = ent.health - self.dmg;
151                 ent = find(ent, targetname, self.target);
152         }
153
154         self.cnt = 1;
155 }
156
157 //=============================================================================
158
159 /*QUAKED target_objective_decrease (0 .5 0) (-8 -8 -8) (8 8 8)
160 When triggered decreases health of the targeted spawnfunc_target_objective.
161 -------- KEYS --------
162 targetname : point to a spawnfunc_target_objective entity*/
163 void spawnfunc_target_objective_decrease() {
164
165         self.classname = "target_objective_decrease";
166
167         precache_model("models/sprites/defend.sp2");
168         precache_model("models/sprites/destroy.sp2");
169         precache_model("models/sprites/push.sp2");
170
171         if(!self.dmg) {
172                 self.dmg = 101;
173         }
174         self.cnt = 0; // not used yet
175         self.use = assault_objective_decrease_use;
176         self.mdl = "models/sprites/here.sp2";
177         self.effects = EF_NODEPTHTEST;
178         self.health = ASSAULT_VALUE_INACTIVE;
179         self.max_health = ASSAULT_VALUE_INACTIVE;
180         self.think = assault_objective_decrease_think;
181         self.customizeentityforclient = assault_objective_decrease_customizeforclient;
182         self.nextthink = time;
183 }
184
185
186 void assault_destructible_reset() {
187         self.health = self.max_health;
188         self.model = self.mdl;
189         self.solid = SOLID_BSP;
190         self.colormod = '1 1 1';
191         self.cnt = 0; // not active
192         if(self.spawnflags)
193         {
194                 activator = self;
195                 self.use();
196         }
197 }
198
199 // destructible walls that can be used to trigger target_objective_decrease
200 void spawnfunc_func_assault_destructible() {
201         self.spawnflags = 3;
202         spawnfunc_func_breakable();
203 }
204
205 void assault_wall_think() {
206         local entity ent;
207         local float notvisible;
208         notvisible = 0;
209         ent = find(world, targetname, self.target);
210         while(ent) {
211                 if(ent.classname == "target_objective" && ent.health < 0)
212                         notvisible = 1;
213                 ent = find(ent, targetname, self.target);
214         }
215
216         if(notvisible) {
217                 self.model = "";
218                 self.solid = SOLID_NOT;
219         } else {
220                 self.model = self.mdl;
221                 self.solid = SOLID_BSP;
222         }
223
224         self.nextthink = time + 0.2;
225 }
226
227 void spawnfunc_func_assault_wall() {
228         self.classname = "func_assault_wall";
229         self.mdl = self.model;
230         setmodel(self, self.mdl);
231         self.solid = SOLID_BSP;
232         self.think = assault_wall_think;
233         self.nextthink = time;
234 }
235
236
237 void target_assault_roundend_reset() {
238         self.cnt = self.cnt + 1; // up round counter
239         self.winning = 0; // up round
240 }
241
242 void target_assault_roundend_use() {
243         self.winning = 1; // round has been won by attackers
244 }
245
246 void spawnfunc_target_assault_roundend() {
247         if(!self.health)
248                 self.health = 300; // 5 minutes
249
250         cvar_set("timelimit", ftos(self.health/60));
251         self.winning = 0; // round not yet won by attackers
252         self.classname = "target_assault_roundend";
253         self.use = target_assault_roundend_use;
254         self.cnt = 0; // first round
255 }
256
257 void assault_roundstart_use() {
258
259         activator = self;
260         SUB_UseTargets();
261
262 /*
263 #ifdef TTURRETS_ENABLED
264     entity ent,oldself;
265
266         //(Re)spawn all turrets
267         oldself = self;
268         ent = find(world, classname, "turret_main");
269         while(ent) {
270             // Swap turret teams
271         if(ent.team == COLOR_TEAM1)
272             ent.team = COLOR_TEAM2;
273         else
274             ent.team = COLOR_TEAM1;
275
276         self = ent;
277
278         // Dubbles as teamchange
279         turret_stdproc_respawn();
280         //ent.turret_spawnfunc();
281
282                 ent = find(ent, classname, "turret_main");
283         }
284         self = oldself;
285 #endif
286 */
287
288 }
289
290 void spawnfunc_target_assault_roundstart() {
291         assault_attacker_team = COLOR_TEAM1;
292         self.classname = "target_assault_roundstart";
293         self.use = assault_roundstart_use;
294         self.think = assault_roundstart_use;
295         self.nextthink = time + 0.1;
296 }
297
298 // trigger new round
299 // reset objectives, toggle spawnpoints, reset triggers, ...
300 void assault_new_round() {
301
302         // up round counter
303         self.winning = self.winning + 1;
304         // set end time for next round
305         self.cnt = time + self.health;
306
307         // swap spawn point teams
308         local entity ent;
309         local entity oldself;
310
311         // reward attackers for winning the round
312         ent = find(world, classname, "player");
313         while(ent) {
314                 if(ent.team == assault_attacker_team) {
315                         UpdateFrags(ent, 10);
316                 }
317                 ent = find(ent, classname, "player");
318         }
319
320         // swap attacker/defender roles
321         if(assault_attacker_team == COLOR_TEAM1) {
322                 assault_attacker_team = COLOR_TEAM2;
323         } else {
324                 assault_attacker_team = COLOR_TEAM1;
325         }
326
327         ent = find(world, classname, "info_player_deathmatch");
328         while (ent)
329         {
330                 oldself = self;
331                 self = ent;
332                 if(self.team == COLOR_TEAM1) {
333                         self.team = COLOR_TEAM2;
334                 } else {
335                         self.team = COLOR_TEAM1;
336                 }
337                 self = oldself;
338
339                 ent = find(ent, classname, "info_player_deathmatch");
340         }
341
342         // reset all objectives
343         ent = find(world, classname, "target_objective");
344         while (ent)
345         {
346                 oldself = self;
347                 self = ent;
348                 assault_objective_reset();
349                 self = oldself;
350
351                 ent = find(ent, classname, "target_objective");
352         }
353
354         // reset round end triggers
355         ent = find(world, classname, "target_assault_roundend");
356         while (ent)
357         {
358                 oldself = self;
359                 self = ent;
360                 target_assault_roundend_reset();
361                 self = oldself;
362
363                 ent = find(ent, classname, "target_assault_roundend");
364         }
365
366         // reset all target_object_decrease
367         ent = find(world, classname, "target_objective_decrease");
368         while (ent)
369         {
370                 ent.cnt = 0;
371                 ent = find(ent, classname, "target_objective_decrease");
372         }
373
374         // reset all spawnfunc_func_assault_destructible
375         ent = find(world, classname, "func_assault_destructible");
376         while (ent)
377         {
378                 oldself = self;
379                 self = ent;
380
381         if(ent.team == COLOR_TEAM1)
382             ent.team = COLOR_TEAM2;
383         else
384             ent.team = COLOR_TEAM1;
385
386                 assault_destructible_reset();
387                 self = oldself;
388                 ent = find(ent, classname, "func_assault_destructible");
389         }
390
391         ent = find(world, classname, "target_assault_roundstart");
392         while (ent)
393         {
394                 oldself = self;
395                 self = ent;
396                 self.use();
397                 self = oldself;
398                 ent = find(ent, classname, "target_assault_roundstart");
399         }
400
401         // actually restart round... how to do that?
402         ent = find(world, classname, "player");
403         while(ent) {
404                 oldself = self;
405                 self = ent;
406                 PutClientInServer();
407                 self = oldself;
408                 ent = find(ent, classname, "player");
409
410         }
411
412
413 }
414
415