]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/mode_onslaught.qc
new generator model, with damage models and small code changes for it
[divverent/nexuiz.git] / data / qcsrc / server / mode_onslaught.qc
1 void onslaught_generator_updatesprite(entity e);
2 void onslaught_controlpoint_updatesprite(entity e);
3 void onslaught_link_checkupdate();
4
5 .entity sprite;
6 .string target2;
7 .float iscaptured;
8 .float islinked;
9 .float isgenneighbor_red;
10 .float isgenneighbor_blue;
11 .float iscpneighbor_red;
12 .float iscpneighbor_blue;
13 .float isshielded;
14 .float lasthealth;
15 .float lastteam;
16 .float lastshielded;
17
18 .string model1, model2, model3;
19
20 void ons_gib_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce)
21 {
22     self.velocity += vforce;
23 }
24
25 void ons_trowgib(
26     vector v_from, vector v_to, vector v_colormod,
27     string smodel,
28     float f_lifetime, float f_fadetime, float b_burn)
29 {
30     local entity gib;
31     local entity burn;
32
33     gib = spawn();
34
35     gib.classname = "turret_gib";
36     setmodel(gib,smodel);
37     setorigin(gib,v_from);
38     SUB_SetFade(gib,time + f_lifetime,2);
39
40     gib.solid              = SOLID_BBOX;
41
42     gib.movetype           = MOVETYPE_BOUNCE;
43     gib.takedamage         = DAMAGE_YES;
44     gib.event_damage       = ons_gib_damage;
45     gib.health             = -1;
46     gib.effects            = EF_LOWPRECISION;
47     gib.flags              = FL_NOTARGET;
48     gib.colormod           = v_colormod;
49     gib.velocity           = v_to;
50
51     if (b_burn)
52     {
53         burn = spawn();
54         burn.effects        = EF_LOWPRECISION;//|EF_FLAME;
55         setattachment(burn,gib,"");
56         setorigin(burn,(gib.mins + gib.maxs) * 0.5);
57         SUB_SetFade(burn,time + (f_lifetime * 0.5) ,2);
58     }
59 }
60
61 void onslaught_updatelinks()
62 {
63         local entity l, links;
64         local float stop, t1, t2, t3, t4;
65         // first check if the game has ended
66         dprint("--- updatelinks ---\n");
67         links = findchain(classname, "onslaught_link");
68         // mark generators as being shielded and networked
69         l = findchain(classname, "onslaught_generator");
70         while (l)
71         {
72                 if (l.iscaptured)
73                         dprint(etos(l), " (generator) belongs to team ", ftos(l.team), "\n");
74                 else
75                         dprint(etos(l), " (generator) is destroyed\n");
76                 l.islinked = l.iscaptured;
77                 l.isshielded = l.iscaptured;
78                 l = l.chain;
79         }
80         // mark points as shielded and not networked
81         l = findchain(classname, "onslaught_controlpoint");
82         while (l)
83         {
84                 l.islinked = FALSE;
85                 l.isshielded = TRUE;
86                 l.isgenneighbor_red = FALSE;
87                 l.isgenneighbor_blue = FALSE;
88                 l.iscpneighbor_red = FALSE;
89                 l.iscpneighbor_blue = FALSE;
90                 dprint(etos(l), " (point) belongs to team ", ftos(l.team), "\n");
91                 l = l.chain;
92         }
93         // flow power outward from the generators through the network
94         l = links;
95         while (l)
96         {
97                 dprint(etos(l), " (link) connects ", etos(l.goalentity), " with ", etos(l.enemy), "\n");
98                 l = l.chain;
99         }
100         stop = FALSE;
101         while (!stop)
102         {
103                 stop = TRUE;
104                 l = links;
105                 while (l)
106                 {
107                         // if both points are captured by the same team, and only one of
108                         // them is powered, mark the other one as powered as well
109                         if (l.enemy.iscaptured && l.goalentity.iscaptured)
110                         if (l.enemy.islinked != l.goalentity.islinked)
111                         if (l.enemy.team == l.goalentity.team)
112                         {
113                                 if (!l.goalentity.islinked)
114                                 {
115                                         stop = FALSE;
116                                         l.goalentity.islinked = TRUE;
117                                         dprint(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)\n");
118                                 }
119                                 else if (!l.enemy.islinked)
120                                 {
121                                         stop = FALSE;
122                                         l.enemy.islinked = TRUE;
123                                         dprint(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)\n");
124                                 }
125                         }
126                         l = l.chain;
127                 }
128         }
129         // now that we know which points are powered we can mark their neighbors
130         // as unshielded if team differs
131         l = links;
132         while (l)
133         {
134                 if (l.goalentity.team != l.enemy.team)
135                 {
136                         if (l.goalentity.islinked)
137                         {
138                                 dprint(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)\n");
139                                 l.enemy.isshielded = FALSE;
140                                 if(l.goalentity.classname == "onslaught_generator")
141                                 {
142                                         if(l.goalentity.team == COLOR_TEAM1)
143                                                 l.enemy.isgenneighbor_red = TRUE;
144                                         else if(l.goalentity.team == COLOR_TEAM2)
145                                                 l.enemy.isgenneighbor_blue = TRUE;
146                                 }
147                                 else
148                                 {
149                                         if(l.goalentity.team == COLOR_TEAM1)
150                                                 l.enemy.iscpneighbor_red = TRUE;
151                                         else if(l.goalentity.team == COLOR_TEAM2)
152                                                 l.enemy.iscpneighbor_blue = TRUE;
153                                 }
154                         }
155                         if (l.enemy.islinked)
156                         {
157                                 dprint(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)\n");
158                                 l.goalentity.isshielded = FALSE;
159                                 if(l.enemy.classname == "onslaught_generator")
160                                 {
161                                         if(l.enemy.team == COLOR_TEAM1)
162                                                 l.goalentity.isgenneighbor_red = TRUE;
163                                         else if(l.enemy.team == COLOR_TEAM2)
164                                                 l.goalentity.isgenneighbor_blue = TRUE;
165                                 }
166                                 else
167                                 {
168                                         if(l.enemy.team == COLOR_TEAM1)
169                                                 l.goalentity.iscpneighbor_red = TRUE;
170                                         else if(l.enemy.team == COLOR_TEAM2)
171                                                 l.goalentity.iscpneighbor_blue = TRUE;
172                                 }
173                         }
174                 }
175                 l = l.chain;
176         }
177         // now update the takedamage and alpha variables on generator shields
178         l = findchain(classname, "onslaught_generator");
179         while (l)
180         {
181                 if (l.isshielded)
182                 {
183                         dprint(etos(l), " (generator) is shielded\n");
184                         l.enemy.alpha = 1;
185                         l.takedamage = DAMAGE_NO;
186                         l.bot_attack = FALSE;
187                 }
188                 else
189                 {
190                         dprint(etos(l), " (generator) is not shielded\n");
191                         l.enemy.alpha = -1;
192                         l.takedamage = DAMAGE_AIM;
193                         l.bot_attack = TRUE;
194                 }
195                 l = l.chain;
196         }
197         // now update the takedamage and alpha variables on control point icons
198         l = findchain(classname, "onslaught_controlpoint");
199         while (l)
200         {
201                 if (l.isshielded)
202                 {
203                         dprint(etos(l), " (point) is shielded\n");
204                         l.enemy.alpha = 1;
205                         if (l.goalentity)
206                         {
207                                 l.goalentity.takedamage = DAMAGE_NO;
208                                 l.goalentity.bot_attack = FALSE;
209                         }
210                 }
211                 else
212                 {
213                         dprint(etos(l), " (point) is not shielded\n");
214                         l.enemy.alpha = -1;
215                         if (l.goalentity)
216                         {
217                                 l.goalentity.takedamage = DAMAGE_AIM;
218                                 l.goalentity.bot_attack = TRUE;
219                         }
220                 }
221                 onslaught_controlpoint_updatesprite(l);
222                 l = l.chain;
223         }
224         // count generators owned by each team
225         t1 = t2 = t3 = t4 = 0;
226         l = findchain(classname, "onslaught_generator");
227         while (l)
228         {
229                 if (l.iscaptured)
230                 {
231                         if (l.team == COLOR_TEAM1) t1 = 1;
232                         if (l.team == COLOR_TEAM2) t2 = 1;
233                         if (l.team == COLOR_TEAM3) t3 = 1;
234                         if (l.team == COLOR_TEAM4) t4 = 1;
235                 }
236                 onslaught_generator_updatesprite(l);
237                 l = l.chain;
238         }
239         // see if multiple teams remain (if not, it's game over)
240         if (t1 + t2 + t3 + t4 < 2)
241                 dprint("--- game over ---\n");
242         else
243                 dprint("--- done updating links ---\n");
244 };
245
246 float onslaught_controlpoint_can_be_linked(entity cp, float t)
247 {
248         if(t == COLOR_TEAM1)
249         {
250                 if(cp.isgenneighbor_red)
251                         return 2;
252                 if(cp.iscpneighbor_red)
253                         return 1;
254         }
255         else if(t == COLOR_TEAM2)
256         {
257                 if(cp.isgenneighbor_blue)
258                         return 2;
259                 if(cp.iscpneighbor_blue)
260                         return 1;
261         }
262         return 0;
263 /*
264         entity e;
265         // check to see if this player has a legitimate claim to capture this
266         // control point - more specifically that there is a captured path of
267         // points leading back to the team generator
268         e = findchain(classname, "onslaught_link");
269         while (e)
270         {
271                 if (e.goalentity == cp)
272                 {
273                         dprint(etos(e), " (link) connects to ", etos(e.enemy), " (point)");
274                         if (e.enemy.islinked)
275                         {
276                                 dprint(" which is linked");
277                                 if (e.enemy.team == t)
278                                 {
279                                         dprint(" and has the correct team!\n");
280                                         return 1;
281                                 }
282                                 else
283                                         dprint(" but has the wrong team\n");
284                         }
285                         else
286                                 dprint("\n");
287                 }
288                 else if (e.enemy == cp)
289                 {
290                         dprint(etos(e), " (link) connects to ", etos(e.goalentity), " (point)");
291                         if (e.goalentity.islinked)
292                         {
293                                 dprint(" which is linked");
294                                 if (e.goalentity.team == t)
295                                 {
296                                         dprint(" and has a team!\n");
297                                         return 1;
298                                 }
299                                 else
300                                         dprint(" but has the wrong team\n");
301                         }
302                         else
303                                 dprint("\n");
304                 }
305                 e = e.chain;
306         }
307         return 0;
308 */
309 }
310
311 float onslaught_controlpoint_attackable(entity cp, float t)
312 // -2: SAME TEAM, attackable by enemy!
313 // -1: SAME TEAM!
314 // 0:  off limits
315 // 1:  attack it
316 // 2:  touch it
317 // 3:  attack it (HIGH PRIO)
318 // 4:  touch it (HIGH PRIO)
319 {
320         float a;
321
322         if(cp.isshielded)
323         {
324                 return 0;
325         }
326         else if(cp.goalentity)
327         {
328                 // if there's already an icon built, nothing happens
329                 if(cp.team == t)
330                 {
331                         a = onslaught_controlpoint_can_be_linked(cp, COLOR_TEAM1 + COLOR_TEAM2 - t);
332                         if(a) // attackable by enemy?
333                                 return -2; // EMERGENCY!
334                         return -1;
335                 }
336                 // we know it can be linked, so no need to check
337                 // but...
338                 a = onslaught_controlpoint_can_be_linked(cp, t);
339                 if(a == 2) // near our generator?
340                         return 3; // EMERGENCY!
341                 return 1;
342         }
343         else
344         {
345                 // free point
346                 if(onslaught_controlpoint_can_be_linked(cp, t))
347                 {
348                         a = onslaught_controlpoint_can_be_linked(cp, COLOR_TEAM1 + COLOR_TEAM2 - t);
349                         if(a == 2)
350                                 return 4; // GET THIS ONE NOW!
351                         else
352                                 return 2; // TOUCH ME
353                 }
354         }
355         return 0;
356 }
357
358 void onslaught_generator_think()
359 {
360         local float d;
361         local entity e;
362         self.nextthink = ceil(time + 1);
363         if (cvar("timelimit"))
364         if (time > cvar("timelimit") * 60 - 60)
365         {
366                 // self.max_health / 300 gives 5 minutes of overtime.
367                 // control points reduce the overtime duration.
368                 sound(self, CHAN_TRIGGER, "onslaught/generator_decay.wav", VOL_BASE, ATTN_NORM);
369                 d = 1;
370                 e = findchain(classname, "onslaught_controlpoint");
371                 while (e)
372                 {
373                         if (e.team != self.team)
374                         if (e.islinked)
375                                 d = d + 1;
376                         e = e.chain;
377                 }
378                 d = d * self.max_health / 300;
379                 Damage(self, self, self, d, DEATH_HURTTRIGGER, self.origin, '0 0 0');
380         }
381 };
382
383 void onslaught_generator_deaththink()
384 {
385         local vector org;
386         if (self.count > 0)
387         {
388                 self.nextthink = time + 0.1;
389                 self.count = self.count - 1;
390                 org = randompos(self.origin + self.mins + '8 8 8', self.origin + self.maxs + '-8 -8 -8');
391                 pointparticles(particleeffectnum("onslaught_generator_smallexplosion"), org, '0 0 0', 1);
392                 sound(self, CHAN_TRIGGER, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
393         }
394         else
395         {
396                 org = self.origin;
397                 pointparticles(particleeffectnum("onslaught_generator_finalexplosion"), org, '0 0 0', 1);
398                 sound(self, CHAN_TRIGGER, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
399         }
400 };
401
402 void onslaught_generator_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
403 {
404         if (damage <= 0)
405                 return;
406         if (attacker != self)
407         {
408                 if (self.isshielded)
409                 {
410                         // this is protected by a shield, so ignore the damage
411                         if (time > self.pain_finished)
412                         if (attacker.classname == "player")
413                         {
414                                 play2(attacker, "onslaught/damageblockedbyshield.wav");
415                                 self.pain_finished = time + 1;
416                         }
417                         return;
418                 }
419                 if (time > self.pain_finished)
420                 {
421                         self.pain_finished = time + 5;
422                         bprint(ColoredTeamName(self.team), " generator under attack!\n");
423                         play2team(self.team, "onslaught/generator_underattack.wav");
424                 }
425         }
426         self.health = self.health - damage;
427         // choose an animation frame based on health
428         self.frame = 10 * bound(0, (1 - self.health / self.max_health), 1);
429         // see if the generator is still functional, or dying
430         if (self.health > 0)
431         {
432                 float h, lh;
433                 lh = ceil(self.lasthealth / 100) * 100;
434                 h = ceil(self.health / 100) * 100;
435                 if(lh != h)
436                         bprint(ColoredTeamName(self.team), " generator has less than ", ftos(h), " health remaining\n");
437                 self.lasthealth = self.health;
438         }
439         else
440         {
441                 if (attacker == self)
442                         bprint(ColoredTeamName(self.team), " generator spontaneously exploded due to overtime!\n");
443                 else
444                 {
445                         string t;
446                         t = ColoredTeamName(attacker.team);
447                         bprint(ColoredTeamName(self.team), " generator destroyed by ", t, "!\n");
448                 }
449                 self.iscaptured = FALSE;
450                 self.islinked = FALSE;
451                 self.isshielded = FALSE;
452                 self.takedamage = DAMAGE_NO; // can't be hurt anymore
453                 self.event_damage = SUB_Null; // won't do anything if hurt
454                 self.count = 30; // 30 explosions
455                 self.think = onslaught_generator_deaththink; // explosion sequence
456                 self.nextthink = time; // start exploding immediately
457                 self.think(); // do the first explosion now
458                 onslaught_updatelinks();
459         }
460         if(self.health < cvar("g_onslaught_gen_health") * 0.90)
461                 setmodel(self, "models/onslaught/generator_dmg1.md3");
462         if(self.health < cvar("g_onslaught_gen_health") * 0.80)
463                 setmodel(self, "models/onslaught/generator_dmg2.md3");
464         if(self.health < cvar("g_onslaught_gen_health") * 0.70)
465                 setmodel(self, "models/onslaught/generator_dmg3.md3");
466         if(self.health < cvar("g_onslaught_gen_health") * 0.60)
467                 setmodel(self, "models/onslaught/generator_dmg4.md3");
468         if(self.health < cvar("g_onslaught_gen_health") * 0.50)
469                 setmodel(self, "models/onslaught/generator_dmg5.md3");
470         if(self.health < cvar("g_onslaught_gen_health") * 0.40)
471                 setmodel(self, "models/onslaught/generator_dmg6.md3");
472         if(self.health < cvar("g_onslaught_gen_health") * 0.30)
473                 setmodel(self, "models/onslaught/generator_dmg7.md3");
474         if(self.health < cvar("g_onslaught_gen_health") * 0.20)
475                 setmodel(self, "models/onslaught/generator_dmg8.md3");
476         if(self.health < cvar("g_onslaught_gen_health") * 0.10)
477                 setmodel(self, "models/onslaught/generator_dmg9.md3");
478         if(self.health <= 0)
479                 setmodel(self, "models/onslaught/generator_dead.md3");
480 };
481
482 // update links after a delay
483 void onslaught_generator_delayed()
484 {
485         onslaught_updatelinks();
486         // now begin normal thinking
487         self.think = onslaught_generator_think;
488         self.nextthink = time;
489 };
490
491 string onslaught_generator_waypointsprite_for_team(entity e, float t)
492 {
493         if(t == e.team)
494         {
495                 if(e.team == COLOR_TEAM1)
496                         return "ons-gen-red";
497                 else if(e.team == COLOR_TEAM2)
498                         return "ons-gen-blue";
499         }
500         if(e.isshielded)
501                 return "ons-gen-shielded";
502         if(e.team == COLOR_TEAM1)
503                 return "ons-gen-red";
504         else if(e.team == COLOR_TEAM2)
505                 return "ons-gen-blue";
506         return "";
507 }
508
509 void onslaught_generator_updatesprite(entity e)
510 {
511         string s1, s2, s3;
512         s1 = onslaught_generator_waypointsprite_for_team(e, COLOR_TEAM1);
513         s2 = onslaught_generator_waypointsprite_for_team(e, COLOR_TEAM2);
514         s3 = onslaught_generator_waypointsprite_for_team(e, -1);
515         WaypointSprite_UpdateSprites(e.sprite, s1, s2, s3);
516
517         if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
518         {
519                 e.lastteam = e.team + 2;
520                 e.lastshielded = e.isshielded;
521                 if(e.lastshielded)
522                 {
523                         if(e.team == COLOR_TEAM1)
524                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0 0');
525                         else if(e.team == COLOR_TEAM2)
526                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0 0 0.5');
527                         else
528                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
529                 }
530                 else
531                 {
532                         if(e.team == COLOR_TEAM1)
533                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '1 0 0');
534                         else if(e.team == COLOR_TEAM2)
535                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0 0 1');
536                         else
537                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
538                 }
539                 WaypointSprite_Ping(e.sprite);
540         }
541 }
542
543 string onslaught_controlpoint_waypointsprite_for_team(entity e, float t)
544 {
545         float a;
546         if(t != -1)
547         {
548                 a = onslaught_controlpoint_attackable(e, t);
549                 if(a == 3 || a == 4) // ATTACK/TOUCH THIS ONE NOW
550                 {
551                         if(e.team == COLOR_TEAM1)
552                                 return "ons-cp-atck-red";
553                         else if(e.team == COLOR_TEAM2)
554                                 return "ons-cp-atck-blue";
555                         else
556                                 return "ons-cp-atck-neut";
557                 }
558                 else if(a == -2) // DEFEND THIS ONE NOW
559                 {
560                         if(e.team == COLOR_TEAM1)
561                                 return "ons-cp-dfnd-red";
562                         else if(e.team == COLOR_TEAM2)
563                                 return "ons-cp-dfnd-blue";
564                 }
565                 else if(e.team == t || a == -1 || a == 1) // own point, or fire at it
566                 {
567                         if(e.team == COLOR_TEAM1)
568                                 return "ons-cp-red";
569                         else if(e.team == COLOR_TEAM2)
570                                 return "ons-cp-blue";
571                 }
572                 else if(a == 2) // touch it
573                         return "ons-cp-neut";
574         }
575         else
576         {
577                 if(e.team == COLOR_TEAM1)
578                         return "ons-cp-red";
579                 else if(e.team == COLOR_TEAM2)
580                         return "ons-cp-blue";
581                 else
582                         return "ons-cp-neut";
583         }
584         return "";
585 }
586
587 void onslaught_controlpoint_updatesprite(entity e)
588 {
589         string s1, s2, s3;
590         s1 = onslaught_controlpoint_waypointsprite_for_team(e, COLOR_TEAM1);
591         s2 = onslaught_controlpoint_waypointsprite_for_team(e, COLOR_TEAM2);
592         s3 = onslaught_controlpoint_waypointsprite_for_team(e, -1);
593         WaypointSprite_UpdateSprites(e.sprite, s1, s2, s3);
594
595         float sh;
596         sh = !(onslaught_controlpoint_can_be_linked(e, COLOR_TEAM1) || onslaught_controlpoint_can_be_linked(e, COLOR_TEAM2));
597
598         if(e.lastteam != e.team + 2 || e.lastshielded != sh)
599         {
600                 e.lastteam = e.team + 2;
601                 e.lastshielded = sh;
602                 if(e.lastshielded)
603                 {
604                         if(e.team == COLOR_TEAM1)
605                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0 0');
606                         else if(e.team == COLOR_TEAM2)
607                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0 0 0.5');
608                         else
609                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
610                 }
611                 else
612                 {
613                         if(e.team == COLOR_TEAM1)
614                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '1 0 0');
615                         else if(e.team == COLOR_TEAM2)
616                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0 0 1');
617                         else
618                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
619                 }
620                 WaypointSprite_Ping(e.sprite);
621         }
622 }
623
624 void onslaught_generator_reset()
625 {
626         self.team = self.team_saved;
627         self.lasthealth = self.max_health = self.health = cvar("g_onslaught_gen_health");
628         self.takedamage = DAMAGE_AIM;
629         self.bot_attack = TRUE;
630         self.iscaptured = TRUE;
631         self.islinked = TRUE;
632         self.isshielded = TRUE;
633         self.enemy.solid = SOLID_NOT;
634         self.think = onslaught_generator_delayed;
635         self.nextthink = time + 0.2;
636 }
637
638 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
639 Base generator.
640
641 spawnfunc_onslaught_link entities can target this.
642
643 keys:
644 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
645 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
646 */
647 void spawnfunc_onslaught_generator()
648 {
649         if (!g_onslaught)
650         {
651                 remove(self);
652                 return;
653         }
654
655         local entity e;
656         precache_model("models/onslaught/generator.md3");
657         precache_model("models/onslaught/generator_shield.md3");
658         precache_model("models/onslaught/generator_dmg1.md3");
659         precache_model("models/onslaught/generator_dmg2.md3");
660         precache_model("models/onslaught/generator_dmg3.md3");
661         precache_model("models/onslaught/generator_dmg4.md3");
662         precache_model("models/onslaught/generator_dmg5.md3");
663         precache_model("models/onslaught/generator_dmg6.md3");
664         precache_model("models/onslaught/generator_dmg7.md3");
665         precache_model("models/onslaught/generator_dmg8.md3");
666         precache_model("models/onslaught/generator_dmg9.md3");
667         precache_model("models/onslaught/generator_dead.md3");
668         precache_sound("onslaught/generator_decay.wav");
669         precache_sound("weapons/grenade_impact.wav");
670         precache_sound("weapons/rocket_impact.wav");
671         precache_sound("onslaught/generator_underattack.wav");
672         if (!self.team)
673                 objerror("team must be set");
674         self.team_saved = self.team;
675         self.colormap = 1024 + (self.team - 1) * 17;
676         self.solid = SOLID_BSP;
677         self.movetype = MOVETYPE_NONE;
678         self.lasthealth = self.max_health = self.health = cvar("g_onslaught_gen_health");
679         setmodel(self, "models/onslaught/generator.md3");
680         //setsize(self, '-32 -32 -24', '32 32 64');
681         setorigin(self, self.origin);
682         self.takedamage = DAMAGE_AIM;
683         self.bot_attack = TRUE;
684         self.event_damage = onslaught_generator_damage;
685         self.iscaptured = TRUE;
686         self.islinked = TRUE;
687         self.isshielded = TRUE;
688         // spawn shield model which indicates whether this can be damaged
689         self.enemy = e = spawn();
690         e.classname = "onslaught_generator_shield";
691         e.solid = SOLID_NOT;
692         e.movetype = MOVETYPE_NONE;
693         e.effects = EF_ADDITIVE;
694         setmodel(e, "models/onslaught/generator_shield.md3");
695         //setsize(e, '-32 -32 0', '32 32 128');
696         setorigin(e, self.origin);
697         e.colormap = self.colormap;
698         e.team = self.team;
699         self.think = onslaught_generator_delayed;
700         self.nextthink = time + 0.2;
701         InitializeEntity(self, onslaught_generator_delayed, INITPRIO_LAST);
702
703         WaypointSprite_SpawnFixed(string_null, e.origin + '0 0 1' * e.maxs_z, self, sprite);
704         WaypointSprite_UpdateRule(self.sprite, COLOR_TEAM2, SPRITERULE_TEAMPLAY);
705
706         onslaught_updatelinks();
707
708         self.reset = onslaught_generator_reset;
709 };
710
711 .float waslinked;
712 .float cp_bob_spd;
713 .vector cp_origin, cp_bob_origin, cp_bob_dmg;
714 void onslaught_controlpoint_icon_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
715 {
716         entity oself;
717         if (damage <= 0)
718                 return;
719         if (self.owner.isshielded)
720         {
721                 // this is protected by a shield, so ignore the damage
722                 if (time > self.pain_finished)
723                 if (attacker.classname == "player")
724                 {
725                         play2(attacker, "onslaught/damageblockedbyshield.wav");
726                         self.pain_finished = time + 1;
727                 }
728                 return;
729         }
730         if (time > self.pain_finished)
731         if (attacker.classname == "player")
732         {
733                 play2team(self.team, "onslaught/controlpoint_underattack.wav");
734                 self.pain_finished = time + 5;
735         }
736         self.health = self.health - damage;
737         self.pain_finished = time + 1;
738         self.punchangle = (2 * randomvec() - '1 1 1') * 45;
739         self.cp_bob_dmg_z = (2 * random() - 1) * 15;
740         // colormod flash when shot
741         self.colormod = '2 2 2';
742         if (self.health < 0)
743         {
744                 sound(self, CHAN_TRIGGER, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
745                 pointparticles(particleeffectnum("onslaught_controlpoint_explosion"), self.origin, '0 0 0', 1);
746                 {
747                         string t;
748                         t = ColoredTeamName(attacker.team);
749                         bprint(ColoredTeamName(self.team), " ", self.message, " control point destroyed by ", t, "\n");
750                         ons_trowgib(self.origin, (2 * randomvec() - '1 1 1') * 25,'1 1 1',"models/onslaught/controlpoint_icon_gib1.md3",5,1,1);
751                         ons_trowgib(self.origin, (2 * randomvec() - '1 1 1') * 45,'1 1 1',"models/onslaught/controlpoint_icon_gib2.md3",5,1,1);
752                         ons_trowgib(self.origin, (2 * randomvec() - '1 1 1') * 45,'1 1 1',"models/onslaught/controlpoint_icon_gib2.md3",5,1,1);
753                         ons_trowgib(self.origin, (2 * randomvec() - '1 1 1') * 75,'1 1 1',"models/onslaught/controlpoint_icon_gib4.md3",5,1,1);
754                         ons_trowgib(self.origin, (2 * randomvec() - '1 1 1') * 75,'1 1 1',"models/onslaught/controlpoint_icon_gib4.md3",5,1,1);
755                         ons_trowgib(self.origin, (2 * randomvec() - '1 1 1') * 75,'1 1 1',"models/onslaught/controlpoint_icon_gib4.md3",5,1,1);
756                         ons_trowgib(self.origin, (2 * randomvec() - '1 1 1') * 75,'1 1 1',"models/onslaught/controlpoint_icon_gib4.md3",5,1,1);
757                 }
758                 self.owner.goalentity = world;
759                 self.owner.islinked = FALSE;
760                 self.owner.iscaptured = FALSE;
761                 self.owner.team = 0;
762                 self.owner.colormap = 1024;
763                 onslaught_updatelinks();
764
765                 // Use targets now (somebody make sure this is in the right place..)
766                 oself = self;
767                 self = self.owner;
768                 activator = self;
769                 SUB_UseTargets ();
770                 self = oself;
771
772                 self.owner.waslinked = self.owner.islinked;
773                 if(self.owner.model != "models/onslaught/controlpoint_pad.md3")
774                         setmodel(self.owner, "models/onslaught/controlpoint_pad.md3");
775
776                 remove(self);
777         }
778 };
779
780 void onslaught_controlpoint_icon_think()
781 {
782         entity oself;
783         self.nextthink = time + 0.05;
784         if (time > self.pain_finished + 5)
785         {
786                 self.health = self.health + self.count;
787                 if (self.health >= self.max_health)
788                         self.health = self.max_health;
789         }
790         if (self.health < self.max_health * 0.90)
791                 setmodel(self, "models/onslaught/controlpoint_icon.md3");
792         if (self.health < self.max_health * 0.75)
793                 setmodel(self, "models/onslaught/controlpoint_icon_dmg1.md3");
794         if (self.health < self.max_health * 0.50)
795                 setmodel(self, "models/onslaught/controlpoint_icon_dmg2.md3");
796         if (self.health < self.max_health * 0.25)
797                 setmodel(self, "models/onslaught/controlpoint_icon_dmg3.md3");
798         // colormod flash when shot
799         self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));
800
801         if(self.owner.islinked != self.owner.waslinked)
802         {
803                 // unteam the spawnpoint if needed
804                 float t;
805                 t = self.owner.team;
806                 if(!self.owner.islinked)
807                         self.owner.team = 0;
808
809                 oself = self;
810                 self = self.owner;
811                 activator = self;
812                 SUB_UseTargets ();
813                 self = oself;
814
815                 self.owner.team = t;
816
817                 self.owner.waslinked = self.owner.islinked;
818         }
819         if (self.punchangle_x > 2)
820                 self.punchangle_x = self.punchangle_x - 2;
821         else if (self.punchangle_x < -2)
822                 self.punchangle_x = self.punchangle_x + 2;
823         else
824                 self.punchangle_x = 0;
825         if (self.punchangle_y > 2)
826                 self.punchangle_y = self.punchangle_y - 2;
827         else if (self.punchangle_y < -2)
828                 self.punchangle_y = self.punchangle_y + 2;
829         else
830                 self.punchangle_y = 0;
831         if (self.punchangle_z > 2)
832                 self.punchangle_z = self.punchangle_z - 2;
833         else if (self.punchangle_z < -2)
834                 self.punchangle_z = self.punchangle_z + 2;
835         else
836                 self.punchangle_z = 0;
837         self.angles_x = self.punchangle_x;
838         self.angles_y = self.angles_y + self.punchangle_y + 2;
839         self.angles_z = self.punchangle_z;
840
841         self.cp_bob_origin_z = 4 * PI * (1 - cos(self.cp_bob_spd / 8));
842         self.cp_bob_spd = self.cp_bob_spd + 0.5;
843         if(self.cp_bob_dmg_z > 0)
844                 self.cp_bob_dmg_z = self.cp_bob_dmg_z - 0.1;
845         else
846                 self.cp_bob_dmg_z = 0;
847         self.origin = self.cp_origin + self.cp_bob_origin + self.cp_bob_dmg;
848 };
849
850 void onslaught_controlpoint_icon_buildthink()
851 {
852         local entity oself;
853         float a;
854
855         self.nextthink = time + 0.05;
856
857         // only do this if there is power
858         a = onslaught_controlpoint_can_be_linked(self.owner, self.owner.team);
859         if(!a)
860                 return;
861
862         self.health = self.health + (self.count / 2);
863
864         if (self.health >= self.max_health)
865         {
866                 self.health = self.max_health;
867                 self.count = self.count * 0.1; // slow repair rate from now on
868                 self.think = onslaught_controlpoint_icon_think;
869                 sound(self, CHAN_TRIGGER, "onslaught/controlpoint_built.wav", VOL_BASE, ATTN_NORM);
870                 bprint(ColoredTeamName(self.team), " captured ", self.owner.message, " control point\n");
871                 self.owner.iscaptured = TRUE;
872                 onslaught_updatelinks();
873
874                 // Use targets now (somebody make sure this is in the right place..)
875                 oself = self;
876                 self = self.owner;
877                 activator = self;
878                 SUB_UseTargets ();
879                 self = oself;
880                 self.cp_origin = self.origin;
881                 self.cp_bob_origin = '0 0 0.1';
882                 self.cp_bob_spd = 0;
883         }
884         self.alpha = self.health / self.max_health;
885         // colormod flash when shot
886         self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));
887         if(self.owner.model != "models/onslaught/controlpoint_pad2.md3")
888                 setmodel(self.owner, "models/onslaught/controlpoint_pad2.md3");
889 };
890
891 void onslaught_controlpoint_touch()
892 {
893         local entity e;
894         float a;
895         if (other.classname != "player")
896                 return;
897         a = onslaught_controlpoint_attackable(self, other.team);
898         if(a != 2 && a != 4)
899                 return;
900         // we've verified that this player has a legitimate claim to this point,
901         // so start building the captured point icon (which only captures this
902         // point if it successfully builds without being destroyed first)
903         self.goalentity = e = spawn();
904         e.classname = "onslaught_controlpoint_icon";
905         e.owner = self;
906         e.max_health = cvar("g_onslaught_cp_health");
907         e.health = e.max_health * 0.1;
908         e.solid = SOLID_BBOX;
909         e.movetype = MOVETYPE_NONE;
910         setmodel(e, "models/onslaught/controlpoint_icon.md3");
911         setsize(e, '-32 -32 -32', '32 32 32');
912         setorigin(e, self.origin + '0 0 96');
913         e.takedamage = DAMAGE_AIM;
914         e.bot_attack = TRUE;
915         e.event_damage = onslaught_controlpoint_icon_damage;
916         e.team = other.team;
917         e.colormap = 1024 + (e.team - 1) * 17;
918         e.think = onslaught_controlpoint_icon_buildthink;
919         e.nextthink = time + 0.1;
920         e.count = e.max_health / 50; // how long it takes to build
921         sound(e, CHAN_TRIGGER, "onslaught/controlpoint_build.wav", VOL_BASE, ATTN_NORM);
922         self.team = e.team;
923         self.colormap = e.colormap;
924 };
925
926 void onslaught_controlpoint_reset()
927 {
928         if(self.goalentity && self.goalentity != world)
929                 remove(self.goalentity);
930         self.goalentity = world;
931         self.team = 0;
932         self.colormap = 1024;
933         self.iscaptured = FALSE;
934         self.islinked = FALSE;
935         self.isshielded = TRUE;
936         self.enemy.solid = SOLID_NOT;
937         self.enemy.colormap = self.colormap;
938         self.think = self.enemy.think = SUB_Null;
939         self.nextthink = 0; // don't like SUB_Null :P
940         
941         onslaught_updatelinks();
942
943         activator = self;
944         SUB_UseTargets(); // to reset the structures, playerspawns etc.
945 }
946
947 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
948 Control point.  Be sure to give this enough clearance so that the shootable part has room to exist
949
950 This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
951
952 keys:
953 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
954 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
955 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
956 */
957 void spawnfunc_onslaught_controlpoint()
958 {
959         local entity e;
960         if (!g_onslaught)
961         {
962                 remove(self);
963                 return;
964         }
965         precache_model("models/onslaught/controlpoint_pad.md3");
966         precache_model("models/onslaught/controlpoint_pad2.md3");
967         precache_model("models/onslaught/controlpoint_shield.md3");
968         precache_model("models/onslaught/controlpoint_icon.md3");
969         precache_model("models/onslaught/controlpoint_icon_dmg1.md3");
970         precache_model("models/onslaught/controlpoint_icon_dmg2.md3");
971         precache_model("models/onslaught/controlpoint_icon_dmg3.md3");
972         precache_model("models/onslaught/controlpoint_icon_gib1.md3");
973         precache_model("models/onslaught/controlpoint_icon_gib2.md3");
974         precache_model("models/onslaught/controlpoint_icon_gib4.md3");
975         precache_sound("onslaught/controlpoint_build.wav");
976         precache_sound("onslaught/controlpoint_built.wav");
977         precache_sound("weapons/grenade_impact.wav");
978         precache_sound("onslaught/damageblockedbyshield.wav");
979         precache_sound("onslaught/controlpoint_underattack.wav");
980         self.solid = SOLID_BSP;
981         self.movetype = MOVETYPE_NONE;
982         setmodel(self, "models/onslaught/controlpoint_pad.md3");
983         //setsize(self, '-32 -32 0', '32 32 8');
984         setorigin(self, self.origin);
985         self.touch = onslaught_controlpoint_touch;
986         self.team = 0;
987         self.colormap = 1024;
988         self.iscaptured = FALSE;
989         self.islinked = FALSE;
990         self.isshielded = TRUE;
991         // spawn shield model which indicates whether this can be damaged
992         self.enemy = e = spawn();
993         e.classname = "onslaught_controlpoint_shield";
994         e.solid = SOLID_NOT;
995         e.movetype = MOVETYPE_NONE;
996         e.effects = EF_ADDITIVE;
997         setmodel(e, "models/onslaught/controlpoint_shield.md3");
998         //setsize(e, '-32 -32 0', '32 32 128');
999         setorigin(e, self.origin);
1000         e.colormap = self.colormap;
1001
1002         waypoint_spawnforitem(self);
1003
1004         WaypointSprite_SpawnFixed(string_null, e.origin + '0 0 1' * e.maxs_z, self, sprite);
1005         WaypointSprite_UpdateRule(self.sprite, COLOR_TEAM2, SPRITERULE_TEAMPLAY);
1006
1007         onslaught_updatelinks();
1008
1009         self.reset = onslaught_controlpoint_reset;
1010 };
1011
1012 float onslaught_link_send(entity to, float sendflags)
1013 {
1014         WriteByte(MSG_ENTITY, ENT_CLIENT_RADARLINK);
1015         WriteByte(MSG_ENTITY, sendflags);
1016         if(sendflags & 1)
1017         {
1018                 WriteCoord(MSG_ENTITY, self.goalentity.origin_x);
1019                 WriteCoord(MSG_ENTITY, self.goalentity.origin_y);
1020                 WriteCoord(MSG_ENTITY, self.goalentity.origin_z);
1021         }
1022         if(sendflags & 2)
1023         {
1024                 WriteCoord(MSG_ENTITY, self.enemy.origin_x);
1025                 WriteCoord(MSG_ENTITY, self.enemy.origin_y);
1026                 WriteCoord(MSG_ENTITY, self.enemy.origin_z);
1027         }
1028         if(sendflags & 4)
1029         {
1030                 WriteByte(MSG_ENTITY, self.clientcolors); // which is goalentity's color + enemy's color * 16
1031         }
1032         return TRUE;
1033 }
1034
1035 void onslaught_link_checkupdate()
1036 {
1037         // TODO check if the two sides have moved (currently they won't move anyway)
1038         float redpower, bluepower;
1039
1040         redpower = bluepower = 0;
1041         if(self.goalentity.islinked)
1042         {
1043                 if(self.goalentity.team == COLOR_TEAM1)
1044                         redpower = 1;
1045                 else if(self.goalentity.team == COLOR_TEAM2)
1046                         bluepower = 1;
1047         }
1048         if(self.enemy.islinked)
1049         {
1050                 if(self.enemy.team == COLOR_TEAM1)
1051                         redpower = 2;
1052                 else if(self.enemy.team == COLOR_TEAM2)
1053                         bluepower = 2;
1054         }
1055
1056         float cc;
1057         if(redpower == 1 && bluepower == 2)
1058                 cc = (COLOR_TEAM1 - 1) * 0x01 + (COLOR_TEAM2 - 1) * 0x10;
1059         else if(redpower == 2 && bluepower == 1)
1060                 cc = (COLOR_TEAM1 - 1) * 0x10 + (COLOR_TEAM2 - 1) * 0x01;
1061         else if(redpower)
1062                 cc = (COLOR_TEAM1 - 1) * 0x11;
1063         else if(bluepower)
1064                 cc = (COLOR_TEAM2 - 1) * 0x11;
1065         else
1066                 cc = 0;
1067
1068         if(cc != self.clientcolors)
1069         {
1070                 self.clientcolors = cc;
1071                 self.SendFlags |= 4;
1072         }
1073
1074         self.nextthink = time;
1075 }
1076
1077 void onslaught_link_delayed()
1078 {
1079         self.goalentity = find(world, targetname, self.target);
1080         self.enemy = find(world, targetname, self.target2);
1081         if (!self.goalentity)
1082                 objerror("can not find target\n");
1083         if (!self.enemy)
1084                 objerror("can not find target2\n");
1085         dprint(etos(self.goalentity), " linked with ", etos(self.enemy), "\n");
1086
1087         self.SendFlags |= 3;
1088         self.think = onslaught_link_checkupdate;
1089         self.nextthink = time;
1090 }
1091
1092 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
1093 Link between control points.
1094
1095 This entity targets two different spawnfunc_onslaught_controlpoint or spawnfunc_onslaught_generator entities, and suppresses shielding on both if they are owned by different teams.
1096
1097 keys:
1098 "target" - first control point.
1099 "target2" - second control point.
1100 */
1101 void spawnfunc_onslaught_link()
1102 {
1103         if (!g_onslaught)
1104         {
1105                 remove(self);
1106                 return;
1107         }
1108         if (self.target == "" || self.target2 == "")
1109                 objerror("target and target2 must be set\n");
1110         InitializeEntity(self, onslaught_link_delayed, INITPRIO_FINDTARGET);
1111         Net_LinkEntity(self, FALSE, 0, onslaught_link_send);
1112 };