- Spawn points can now be activated (turns to player's .team - doesn't do anything...
[divverent/nexuiz.git] / data / qcsrc / server / mode_onslaught.qc
1 \r
2 .string target2;\r
3 .float iscaptured;\r
4 .float islinked;\r
5 .float isshielded;\r
6 void() onslaught_updatelinks =\r
7 {\r
8         local entity l, links;\r
9         local float stop, t1, t2, t3, t4;\r
10         // first check if the game has ended\r
11         dprint("--- updatelinks ---\n");\r
12         links = findchain(classname, "onslaught_link");\r
13         // mark generators as being shielded and networked\r
14         l = findchain(classname, "onslaught_generator");\r
15         while (l)\r
16         {\r
17                 if (l.iscaptured)\r
18                         dprint(etos(l), " (generator) belongs to team ", ftos(l.team), "\n");\r
19                 else\r
20                         dprint(etos(l), " (generator) is destroyed\n");\r
21                 l.islinked = l.iscaptured;\r
22                 l.isshielded = l.iscaptured;\r
23                 l = l.chain;\r
24         }\r
25         // mark points as shielded and not networked\r
26         l = findchain(classname, "onslaught_controlpoint");\r
27         while (l)\r
28         {\r
29                 l.islinked = FALSE;\r
30                 l.isshielded = TRUE;\r
31                 dprint(etos(l), " (point) belongs to team ", ftos(l.team), "\n");\r
32                 l = l.chain;\r
33         }\r
34         // flow power outward from the generators through the network\r
35         l = links;\r
36         while (l)\r
37         {\r
38                 dprint(etos(l), " (link) connects ", etos(l.goalentity), " with ", etos(l.enemy), "\n");\r
39                 l = l.chain;\r
40         }\r
41         stop = FALSE;\r
42         while (!stop)\r
43         {\r
44                 stop = TRUE;\r
45                 l = links;\r
46                 while (l)\r
47                 {\r
48                         // if both points are captured by the same team, and only one of\r
49                         // them is powered, mark the other one as powered as well\r
50                         if (l.enemy.iscaptured && l.goalentity.iscaptured)\r
51                         if (l.enemy.islinked != l.goalentity.islinked)\r
52                         if (l.enemy.team == l.goalentity.team)\r
53                         {\r
54                                 if (!l.goalentity.islinked)\r
55                                 {\r
56                                         stop = FALSE;\r
57                                         l.goalentity.islinked = TRUE;\r
58                                         dprint(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)\n");\r
59                                 }\r
60                                 else if (!l.enemy.islinked)\r
61                                 {\r
62                                         stop = FALSE;\r
63                                         l.enemy.islinked = TRUE;\r
64                                         dprint(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)\n");\r
65                                 }\r
66                         }\r
67                         l = l.chain;\r
68                 }\r
69         }\r
70         // now that we know which points are powered we can mark their neighbors\r
71         // as unshielded if team differs\r
72         l = links;\r
73         while (l)\r
74         {\r
75                 if (l.goalentity.team != l.enemy.team)\r
76                 {\r
77                         if (l.goalentity.islinked)\r
78                         {\r
79                                 dprint(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)\n");\r
80                                 l.enemy.isshielded = FALSE;\r
81                         }\r
82                         if (l.enemy.islinked)\r
83                         {\r
84                                 dprint(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)\n");\r
85                                 l.goalentity.isshielded = FALSE;\r
86                         }\r
87                 }\r
88                 l = l.chain;\r
89         }\r
90         // now update the takedamage and alpha variables on generator shields\r
91         l = findchain(classname, "onslaught_generator");\r
92         while (l)\r
93         {\r
94                 if (l.isshielded)\r
95                 {\r
96                         dprint(etos(l), " (generator) is shielded\n");\r
97                         l.enemy.alpha = 1;\r
98                         l.takedamage = DAMAGE_NO;\r
99                         l.bot_attack = FALSE;\r
100                 }\r
101                 else\r
102                 {\r
103                         dprint(etos(l), " (generator) is not shielded\n");\r
104                         l.enemy.alpha = -1;\r
105                         l.takedamage = DAMAGE_AIM;\r
106                         l.bot_attack = TRUE;\r
107                 }\r
108                 l = l.chain;\r
109         }\r
110         // now update the takedamage and alpha variables on control point icons\r
111         l = findchain(classname, "onslaught_controlpoint");\r
112         while (l)\r
113         {\r
114                 if (l.isshielded)\r
115                 {\r
116                         dprint(etos(l), " (point) is shielded\n");\r
117                         l.enemy.alpha = 1;\r
118                         if (l.goalentity)\r
119                         {\r
120                                 l.goalentity.takedamage = DAMAGE_NO;\r
121                                 l.goalentity.bot_attack = FALSE;\r
122                         }\r
123                 }\r
124                 else\r
125                 {\r
126                         dprint(etos(l), " (point) is not shielded\n");\r
127                         l.enemy.alpha = -1;\r
128                         if (l.goalentity)\r
129                         {\r
130                                 l.goalentity.takedamage = DAMAGE_AIM;\r
131                                 l.goalentity.bot_attack = TRUE;\r
132                         }\r
133                 }\r
134                 l = l.chain;\r
135         }\r
136         // count generators owned by each team\r
137         t1 = t2 = t3 = t4 = 0;\r
138         l = findchain(classname, "onslaught_generator");\r
139         while (l)\r
140         {\r
141                 if (l.iscaptured)\r
142                 {\r
143                         if (l.team == COLOR_TEAM1) t1 = 1;\r
144                         if (l.team == COLOR_TEAM2) t2 = 1;\r
145                         if (l.team == COLOR_TEAM3) t3 = 1;\r
146                         if (l.team == COLOR_TEAM4) t4 = 1;\r
147                 }\r
148                 l = l.chain;\r
149         }\r
150         // see if multiple teams remain (if not, it's game over)\r
151         if (t1 + t2 + t3 + t4 < 2)\r
152                 dprint("--- game over ---\n");\r
153         else\r
154                 dprint("--- done updating links ---\n");\r
155 };\r
156 \r
157 void() onslaught_generator_think =\r
158 {\r
159         local float d;\r
160         local entity e;\r
161         self.nextthink = ceil(time + 1);\r
162         if (cvar("timelimit"))\r
163         if (time > cvar("timelimit") * 60 - 60)\r
164         {\r
165                 // self.max_health / 300 gives 5 minutes of overtime.\r
166                 // control points reduce the overtime duration.\r
167                 sound(self, CHAN_AUTO, "sound/onslaught/generator_decay.wav", 1, ATTN_NORM);\r
168                 d = 1;\r
169                 e = findchain(classname, "onslaught_controlpoint");\r
170                 while (e)\r
171                 {\r
172                         if (e.team != self.team)\r
173                         if (e.islinked)\r
174                                 d = d + 1;\r
175                         e = e.chain;\r
176                 }\r
177                 d = d * self.max_health / 300;\r
178                 Damage(self, self, self, d, DEATH_HURTTRIGGER, self.origin, '0 0 0');\r
179         }\r
180 };\r
181 \r
182 void() onslaught_generator_deaththink =\r
183 {\r
184         local vector org;\r
185         if (self.count > 0)\r
186         {\r
187                 self.nextthink = time + 0.1;\r
188                 self.count = self.count - 1;\r
189                 org = randompos(self.origin + self.mins + '8 8 8', self.origin + self.maxs + '-8 -8 -8');\r
190                 pointparticles(particleeffectnum("onslaught_generator_smallexplosion"), org, '0 0 0', 1);\r
191                 sound(self, CHAN_AUTO, "sound/weapons/grenade_impact.wav", 1, ATTN_NORM);\r
192         }\r
193         else\r
194         {\r
195                 org = self.origin;\r
196                 pointparticles(particleeffectnum("onslaught_generator_finalexplosion"), org, '0 0 0', 1);\r
197                 sound(self, CHAN_AUTO, "sound/weapons/rocket_impact.wav", 1, ATTN_NORM);\r
198         }\r
199 };\r
200 \r
201 void(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force) onslaught_generator_damage =\r
202 {\r
203         if (damage <= 0)\r
204                 return;\r
205         if (attacker != self)\r
206         {\r
207                 if (self.isshielded)\r
208                 {\r
209                         // this is protected by a shield, so ignore the damage\r
210                         if (time > self.pain_finished)\r
211                         if (attacker.classname == "player")\r
212                         {\r
213                                 play2(attacker, "sound/onslaught/damageblockedbyshield.wav");\r
214                                 self.pain_finished = time + 1;\r
215                         }\r
216                         return;\r
217                 }\r
218                 if (time > self.pain_finished)\r
219                 {\r
220                         self.pain_finished = time + 5;\r
221                         bprint(ColoredTeamName(self.team), " generator under attack!\n");\r
222                         play2team(self.team, "sound/onslaught/generator_underattack.wav");\r
223                 }\r
224         }\r
225         self.health = self.health - damage;\r
226         // choose an animation frame based on health\r
227         self.frame = 10 * bound(0, (1 - self.health / self.max_health), 1);\r
228         // see if the generator is still functional, or dying\r
229         if (self.health > 0)\r
230                 bprint(ColoredTeamName(self.team), " generator has ", ftos(floor(self.health)), " health remaining\n");\r
231         else\r
232         {\r
233                 if (attacker == self)\r
234                         bprint(ColoredTeamName(self.team), " generator spontaneously exploded due to overtime!\n");\r
235                 else\r
236                         bprint(ColoredTeamName(self.team), " generator destroyed by ", ColoredTeamName(attacker.team), "!\n");\r
237                 self.iscaptured = FALSE;\r
238                 self.islinked = FALSE;\r
239                 self.isshielded = FALSE;\r
240                 self.takedamage = DAMAGE_NO; // can't be hurt anymore\r
241                 self.event_damage = SUB_Null; // won't do anything if hurt\r
242                 self.count = 30; // 30 explosions\r
243                 self.think = onslaught_generator_deaththink; // explosion sequence\r
244                 self.nextthink = time; // start exploding immediately\r
245                 self.think(); // do the first explosion now\r
246                 onslaught_updatelinks();\r
247         }\r
248 };\r
249 \r
250 // update links after a delay\r
251 void() onslaught_generator_delayed =\r
252 {\r
253         onslaught_updatelinks();\r
254         // now begin normal thinking\r
255         self.think = onslaught_generator_think;\r
256         self.nextthink = time;\r
257 };\r
258 \r
259 /*QUAKED onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)\r
260 Base generator.\r
261 \r
262 onslaught_link entities can target this.\r
263 \r
264 keys:\r
265 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.\r
266 "targetname" - name that onslaught_link entities will use to target this.\r
267 */\r
268 void() onslaught_generator =\r
269 {\r
270         if (!g_onslaught)\r
271         {\r
272                 remove(self);\r
273                 return;\r
274         }\r
275         local entity e;\r
276         precache_model("models/onslaught/generator.md3");\r
277         precache_model("models/onslaught/generator_shield.md3");\r
278         precache_sound("sound/onslaught/generator_decay.wav");\r
279         precache_sound("sound/weapons/grenade_impact.wav");\r
280         precache_sound("sound/weapons/rocket_impact.wav");\r
281         precache_sound("sound/onslaught/generator_underattack.wav");\r
282         if (!self.team)\r
283                 objerror("team must be set");\r
284         self.colormap = 1024 + (self.team - 1) * 17;\r
285         self.solid = SOLID_BSP;\r
286         self.movetype = MOVETYPE_NONE;\r
287         self.max_health = self.health = 3000;\r
288         setmodel(self, "models/onslaught/generator.md3");\r
289         //setsize(self, '-32 -32 -24', '32 32 64');\r
290         setorigin(self, self.origin);\r
291         self.takedamage = DAMAGE_AIM;\r
292         self.bot_attack = TRUE;\r
293         self.event_damage = onslaught_generator_damage;\r
294         self.iscaptured = TRUE;\r
295         self.islinked = TRUE;\r
296         self.isshielded = TRUE;\r
297         // spawn shield model which indicates whether this can be damaged\r
298         self.enemy = e = spawn();\r
299         e.solid = SOLID_NOT;\r
300         e.movetype = MOVETYPE_NONE;\r
301         e.effects = EF_ADDITIVE;\r
302         setmodel(e, "models/onslaught/generator_shield.md3");\r
303         //setsize(e, '-32 -32 0', '32 32 128');\r
304         setorigin(e, self.origin);\r
305         e.colormap = self.colormap;\r
306         e.team = self.team;\r
307         self.think = onslaught_generator_delayed;\r
308         self.nextthink = time + 0.2;\r
309 };\r
310 \r
311 void(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force) onslaught_controlpoint_icon_damage =\r
312 {\r
313         if (damage <= 0)\r
314                 return;\r
315         if (self.owner.isshielded)\r
316         {\r
317                 // this is protected by a shield, so ignore the damage\r
318                 if (time > self.pain_finished)\r
319                 if (attacker.classname == "player")\r
320                 {\r
321                         play2(attacker, "sound/onslaught/damageblockedbyshield.wav");\r
322                         self.pain_finished = time + 1;\r
323                 }\r
324                 return;\r
325         }\r
326         if (time > self.pain_finished)\r
327         if (attacker.classname == "player")\r
328         {\r
329                 play2team(self.team, "sound/onslaught/controlpoint_underattack.wav");\r
330                 self.pain_finished = time + 5;\r
331         }\r
332         self.health = self.health - damage;\r
333         self.alpha = self.health / self.max_health;\r
334         self.pain_finished = time + 1;\r
335         // colormod flash when shot\r
336         self.colormod = '2 2 2';\r
337         if (self.health < 0)\r
338         {\r
339                 sound(self, CHAN_AUTO, "sound/weapons/grenade_impact.wav", 1, ATTN_NORM);\r
340                 pointparticles(particleeffectnum("onslaught_controlpoint_explosion"), self.origin, '0 0 0', 1);\r
341                 bprint(ColoredTeamName(self.team), " ", self.message, " control point destroyed by ", ColoredTeamName(attacker.team), "\n");\r
342                 self.owner.goalentity = world;\r
343                 self.owner.islinked = FALSE;\r
344                 self.owner.iscaptured = FALSE;\r
345                 self.owner.team = 0;\r
346                 self.owner.colormap = 1024;\r
347                 onslaught_updatelinks();\r
348                 remove(self);\r
349         }\r
350 };\r
351 \r
352 void() onslaught_controlpoint_icon_think =\r
353 {\r
354         self.nextthink = time + 0.1;\r
355         if (time > self.pain_finished + 1)\r
356         {\r
357                 self.health = self.health + self.count;\r
358                 if (self.health >= self.max_health)\r
359                         self.health = self.max_health;\r
360         }\r
361         self.alpha = self.health / self.max_health;\r
362         // colormod flash when shot\r
363         self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));\r
364 };\r
365 \r
366 void() onslaught_controlpoint_icon_buildthink =\r
367 {\r
368         self.nextthink = time + 0.1;\r
369         self.health = self.health + self.count;\r
370         if (self.health >= self.max_health)\r
371         {\r
372                 self.health = self.max_health;\r
373                 self.count = self.count * 0.2; // slow repair rate from now on\r
374                 self.think = onslaught_controlpoint_icon_think;\r
375                 sound(self, CHAN_BODY, "sound/onslaught/controlpoint_built.wav", 1, ATTN_NORM);\r
376                 bprint(ColoredTeamName(self.team), " captured ", self.owner.message, " control point\n");\r
377                 self.owner.iscaptured = TRUE;\r
378                 onslaught_updatelinks();\r
379         }\r
380         self.alpha = self.health / self.max_health;\r
381         // colormod flash when shot\r
382         self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));\r
383 };\r
384 \r
385 void() onslaught_controlpoint_touch =\r
386 {\r
387         local entity e;\r
388         if (other.classname != "player")\r
389                 return;\r
390         // if there's already an icon built, nothing happens\r
391         if (self.goalentity)\r
392         {\r
393                 dprint("a\n");\r
394                 return;\r
395         }\r
396         // shielded points are definitely off-limits\r
397         if (self.isshielded)\r
398         {\r
399                 dprint("b\n");\r
400                 return;\r
401         }\r
402         // check to see if this player has a legitimate claim to capture this\r
403         // control point - more specifically that there is a captured path of\r
404         // points leading back to the team generator\r
405         e = findchain(classname, "onslaught_link");\r
406         while (e)\r
407         {\r
408                 if (e.goalentity == self)\r
409                 {\r
410                         dprint(etos(e), " (link) connects to ", etos(e.enemy), " (point)");\r
411                         if (e.enemy.islinked)\r
412                         {\r
413                                 dprint(" which is linked");\r
414                                 if (e.enemy.team == other.team)\r
415                                 {\r
416                                         dprint(" and has the correct team!\n");\r
417                                         break;\r
418                                 }\r
419                                 else\r
420                                         dprint(" but has the wrong team\n");\r
421                         }\r
422                         else\r
423                                 dprint("\n");\r
424                 }\r
425                 else if (e.enemy == self)\r
426                 {\r
427                         dprint(etos(e), " (link) connects to ", etos(e.goalentity), " (point)");\r
428                         if (e.goalentity.islinked)\r
429                         {\r
430                                 dprint(" which is linked");\r
431                                 if (e.goalentity.team == other.team)\r
432                                 {\r
433                                         dprint(" and has a team!\n");\r
434                                         break;\r
435                                 }\r
436                                 else\r
437                                         dprint(" but has the wrong team\n");\r
438                         }\r
439                         else\r
440                                 dprint("\n");\r
441                 }\r
442                 e = e.chain;\r
443         }\r
444         if (!e)\r
445         {\r
446                 dprint("c\n");\r
447                 return;\r
448         }\r
449         // we've verified that this player has a legitimate claim to this point,\r
450         // so start building the captured point icon (which only captures this\r
451         // point if it successfully builds without being destroyed first)\r
452         self.goalentity = e = spawn();\r
453         e.owner = self;\r
454         e.max_health = 1000;\r
455         e.health = e.max_health * 0.1;\r
456         e.alpha = e.health / e.max_health;\r
457         e.solid = SOLID_BBOX;\r
458         e.movetype = MOVETYPE_NONE;\r
459         setmodel(e, "models/onslaught/controlpoint_icon.md3");\r
460         setsize(e, '-32 -32 -32', '32 32 32');\r
461         setorigin(e, self.origin + '0 0 96');\r
462         e.takedamage = DAMAGE_AIM;\r
463         e.bot_attack = TRUE;\r
464         e.event_damage = onslaught_controlpoint_icon_damage;\r
465         e.team = other.team;\r
466         e.colormap = 1024 + (e.team - 1) * 17;\r
467         e.think = onslaught_controlpoint_icon_buildthink;\r
468         e.nextthink = time + 0.1;\r
469         e.count = e.max_health / 50; // how long it takes to build\r
470         sound(e, CHAN_BODY, "sound/onslaught/controlpoint_build.wav", 1, ATTN_NORM);\r
471         self.team = e.team;\r
472         self.colormap = e.colormap;\r
473 };\r
474 \r
475 /*QUAKED onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)\r
476 Control point.  Be sure to give this enough clearance so that the shootable part has room to exist\r
477 \r
478 This should link to an onslaught_controlpoint entity or onslaught_generator entity.\r
479 \r
480 keys:\r
481 "targetname" - name that onslaught_link entities will use to target this.\r
482 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.\r
483 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)\r
484 */\r
485 void() onslaught_controlpoint =\r
486 {\r
487         local entity e;\r
488         if (!g_onslaught)\r
489         {\r
490                 remove(self);\r
491                 return;\r
492         }\r
493         precache_model("models/onslaught/controlpoint_pad.md3");\r
494         precache_model("models/onslaught/controlpoint_shield.md3");\r
495         precache_model("models/onslaught/controlpoint_icon.md3");\r
496         precache_sound("sound/onslaught/controlpoint_build.wav");\r
497         precache_sound("sound/onslaught/controlpoint_built.wav");\r
498         precache_sound("sound/weapons/grenade_impact.wav");\r
499         precache_sound("sound/onslaught/damageblockedbyshield.wav");\r
500         precache_sound("sound/onslaught/controlpoint_underattack.wav");\r
501         self.solid = SOLID_BSP;\r
502         self.movetype = MOVETYPE_NONE;\r
503         setmodel(self, "models/onslaught/controlpoint_pad.md3");\r
504         //setsize(self, '-32 -32 0', '32 32 8');\r
505         setorigin(self, self.origin);\r
506         self.touch = onslaught_controlpoint_touch;\r
507         self.team = 0;\r
508         self.colormap = 1024;\r
509         self.iscaptured = FALSE;\r
510         self.islinked = FALSE;\r
511         self.isshielded = TRUE;\r
512         // spawn shield model which indicates whether this can be damaged\r
513         self.enemy = e = spawn();\r
514         e.solid = SOLID_NOT;\r
515         e.movetype = MOVETYPE_NONE;\r
516         e.effects = EF_ADDITIVE;\r
517         setmodel(e, "models/onslaught/controlpoint_shield.md3");\r
518         //setsize(e, '-32 -32 0', '32 32 128');\r
519         setorigin(e, self.origin);\r
520         e.colormap = self.colormap;\r
521         onslaught_updatelinks();\r
522 };\r
523 \r
524 void() onslaught_link_delayed =\r
525 {\r
526         self.goalentity = find(world, targetname, self.target);\r
527         self.enemy = find(world, targetname, self.target2);\r
528         if (!self.goalentity)\r
529                 objerror("can not find target\n");\r
530         if (!self.enemy)\r
531                 objerror("can not find target2\n");\r
532         dprint(etos(self.goalentity), " linked with ", etos(self.enemy), "\n");\r
533 }\r
534 \r
535 /*QUAKED onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)\r
536 Link between control points.\r
537 \r
538 This entity targets two different onslaught_controlpoint or onslaught_generator entities, and suppresses shielding on both if they are owned by different teams.\r
539 \r
540 keys:\r
541 "target" - first control point.\r
542 "target2" - second control point.\r
543 */\r
544 void() onslaught_link =\r
545 {\r
546         if (!g_onslaught)\r
547         {\r
548                 remove(self);\r
549                 return;\r
550         }\r
551         if (self.target == "" || self.target2 == "")\r
552                 objerror("target and target2 must be set\n");\r
553         self.think = onslaught_link_delayed;\r
554         self.nextthink = time + 0.1;\r
555 };\r
556 \r
557 void() onslaught_spawnpoint_use =\r
558 {\r
559         self.team = activator.team;\r
560 };