]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/mode_onslaught.qc
onslaught: new toys, new toys
[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
21 void onslaught_generator_boom_think()
22 {
23         self.nextthink = time + 0.05;
24         if(self.frame > 14)
25         {
26                 self.think = SUB_Remove;
27                 return;
28         }
29         self.frame +=1;
30 };
31
32 void onslaught_generator_boom_spawn(vector org, float fscale)
33 {
34         entity e;
35         e = spawn();
36         setmodel(e, "models/onslaught/boom.md3");
37         setorigin(e, org);
38
39         e.scale = fscale;
40         setsize(e, e.mins * e.scale, e.maxs * e.scale);
41         e.angles = randomvec() * 360;
42
43         e.effects = EF_NOSHADOW;
44
45         e.think = onslaught_generator_boom_think;
46         e.nextthink = time + 0.05;
47 };
48
49 void ons_gib_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce)
50 {
51         self.velocity = self.velocity + vforce;
52 }
53
54 .float giblifetime;
55 void ons_throwgib_think()
56 {
57         local vector org;
58
59         self.nextthink = time + 0.05;
60         if(self.count > self.giblifetime)
61         {
62                 self.think = SUB_Remove;
63                 return;
64         }
65         if(self.count > self.giblifetime-10)
66                 self.alpha -= 0.1;
67         org = self.origin + 20 * randomvec();
68         onslaught_generator_boom_spawn(org, random()*0.5+0.3);
69         self.count +=1;
70 };
71
72 void ons_throwgib(vector v_from, vector v_to, string smodel, float f_lifetime, float f_fadetime, float b_burn)
73 {
74         local entity gib;
75
76         gib = spawn();
77
78         setmodel(gib, smodel);
79         setorigin(gib, v_from);
80         gib.solid = SOLID_BBOX;
81         gib.movetype = MOVETYPE_BOUNCE;
82         gib.takedamage = DAMAGE_YES;
83         gib.event_damage = ons_gib_damage;
84         gib.health = -1;
85         gib.effects = EF_LOWPRECISION;
86         gib.flags = FL_NOTARGET;
87         gib.velocity = v_to;
88         gib.giblifetime = f_lifetime;
89
90         if (b_burn)
91         {
92                 gib.think = ons_throwgib_think;
93                 gib.nextthink = time + 0.05;
94         }
95         else
96                 SUB_SetFade(gib, time + f_lifetime, 2);
97 };
98
99 void onslaught_updatelinks()
100 {
101         local entity l, links;
102         local float stop, t1, t2, t3, t4;
103         // first check if the game has ended
104         dprint("--- updatelinks ---\n");
105         links = findchain(classname, "onslaught_link");
106         // mark generators as being shielded and networked
107         l = findchain(classname, "onslaught_generator");
108         while (l)
109         {
110                 if (l.iscaptured)
111                         dprint(etos(l), " (generator) belongs to team ", ftos(l.team), "\n");
112                 else
113                         dprint(etos(l), " (generator) is destroyed\n");
114                 l.islinked = l.iscaptured;
115                 l.isshielded = l.iscaptured;
116                 l = l.chain;
117         }
118         // mark points as shielded and not networked
119         l = findchain(classname, "onslaught_controlpoint");
120         while (l)
121         {
122                 l.islinked = FALSE;
123                 l.isshielded = TRUE;
124                 l.isgenneighbor_red = FALSE;
125                 l.isgenneighbor_blue = FALSE;
126                 l.iscpneighbor_red = FALSE;
127                 l.iscpneighbor_blue = FALSE;
128                 dprint(etos(l), " (point) belongs to team ", ftos(l.team), "\n");
129                 l = l.chain;
130         }
131         // flow power outward from the generators through the network
132         l = links;
133         while (l)
134         {
135                 dprint(etos(l), " (link) connects ", etos(l.goalentity), " with ", etos(l.enemy), "\n");
136                 l = l.chain;
137         }
138         stop = FALSE;
139         while (!stop)
140         {
141                 stop = TRUE;
142                 l = links;
143                 while (l)
144                 {
145                         // if both points are captured by the same team, and only one of
146                         // them is powered, mark the other one as powered as well
147                         if (l.enemy.iscaptured && l.goalentity.iscaptured)
148                                 if (l.enemy.islinked != l.goalentity.islinked)
149                                         if (l.enemy.team == l.goalentity.team)
150                                         {
151                                                 if (!l.goalentity.islinked)
152                                                 {
153                                                         stop = FALSE;
154                                                         l.goalentity.islinked = TRUE;
155                                                         dprint(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)\n");
156                                                 }
157                                                 else if (!l.enemy.islinked)
158                                                 {
159                                                         stop = FALSE;
160                                                         l.enemy.islinked = TRUE;
161                                                         dprint(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)\n");
162                                                 }
163                                         }
164                         l = l.chain;
165                 }
166         }
167         // now that we know which points are powered we can mark their neighbors
168         // as unshielded if team differs
169         l = links;
170         while (l)
171         {
172                 if (l.goalentity.team != l.enemy.team)
173                 {
174                         if (l.goalentity.islinked)
175                         {
176                                 dprint(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)\n");
177                                 l.enemy.isshielded = FALSE;
178                                 if(l.goalentity.classname == "onslaught_generator")
179                                 {
180                                         if(l.goalentity.team == COLOR_TEAM1)
181                                                 l.enemy.isgenneighbor_red = TRUE;
182                                         else if(l.goalentity.team == COLOR_TEAM2)
183                                                 l.enemy.isgenneighbor_blue = TRUE;
184                                 }
185                                 else
186                                 {
187                                         if(l.goalentity.team == COLOR_TEAM1)
188                                                 l.enemy.iscpneighbor_red = TRUE;
189                                         else if(l.goalentity.team == COLOR_TEAM2)
190                                                 l.enemy.iscpneighbor_blue = TRUE;
191                                 }
192                         }
193                         if (l.enemy.islinked)
194                         {
195                                 dprint(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)\n");
196                                 l.goalentity.isshielded = FALSE;
197                                 if(l.enemy.classname == "onslaught_generator")
198                                 {
199                                         if(l.enemy.team == COLOR_TEAM1)
200                                                 l.goalentity.isgenneighbor_red = TRUE;
201                                         else if(l.enemy.team == COLOR_TEAM2)
202                                                 l.goalentity.isgenneighbor_blue = TRUE;
203                                 }
204                                 else
205                                 {
206                                         if(l.enemy.team == COLOR_TEAM1)
207                                                 l.goalentity.iscpneighbor_red = TRUE;
208                                         else if(l.enemy.team == COLOR_TEAM2)
209                                                 l.goalentity.iscpneighbor_blue = TRUE;
210                                 }
211                         }
212                 }
213                 l = l.chain;
214         }
215         // now update the takedamage and alpha variables on generator shields
216         l = findchain(classname, "onslaught_generator");
217         while (l)
218         {
219                 if (l.isshielded)
220                 {
221                         dprint(etos(l), " (generator) is shielded\n");
222                         l.enemy.alpha = 1;
223                         l.takedamage = DAMAGE_NO;
224                         l.bot_attack = FALSE;
225                 }
226                 else
227                 {
228                         dprint(etos(l), " (generator) is not shielded\n");
229                         l.enemy.alpha = -1;
230                         l.takedamage = DAMAGE_AIM;
231                         l.bot_attack = TRUE;
232                 }
233                 l = l.chain;
234         }
235         // now update the takedamage and alpha variables on control point icons
236         l = findchain(classname, "onslaught_controlpoint");
237         while (l)
238         {
239                 if (l.isshielded)
240                 {
241                         dprint(etos(l), " (point) is shielded\n");
242                         l.enemy.alpha = 1;
243                         if (l.goalentity)
244                         {
245                                 l.goalentity.takedamage = DAMAGE_NO;
246                                 l.goalentity.bot_attack = FALSE;
247                         }
248                 }
249                 else
250                 {
251                         dprint(etos(l), " (point) is not shielded\n");
252                         l.enemy.alpha = -1;
253                         if (l.goalentity)
254                         {
255                                 l.goalentity.takedamage = DAMAGE_AIM;
256                                 l.goalentity.bot_attack = TRUE;
257                         }
258                 }
259                 onslaught_controlpoint_updatesprite(l);
260                 l = l.chain;
261         }
262         // count generators owned by each team
263         t1 = t2 = t3 = t4 = 0;
264         l = findchain(classname, "onslaught_generator");
265         while (l)
266         {
267                 if (l.iscaptured)
268                 {
269                         if (l.team == COLOR_TEAM1) t1 = 1;
270                         if (l.team == COLOR_TEAM2) t2 = 1;
271                         if (l.team == COLOR_TEAM3) t3 = 1;
272                         if (l.team == COLOR_TEAM4) t4 = 1;
273                 }
274                 onslaught_generator_updatesprite(l);
275                 l = l.chain;
276         }
277         // see if multiple teams remain (if not, it's game over)
278         if (t1 + t2 + t3 + t4 < 2)
279                 dprint("--- game over ---\n");
280         else
281                 dprint("--- done updating links ---\n");
282 };
283
284 float onslaught_controlpoint_can_be_linked(entity cp, float t)
285 {
286         if(t == COLOR_TEAM1)
287         {
288                 if(cp.isgenneighbor_red)
289                         return 2;
290                 if(cp.iscpneighbor_red)
291                         return 1;
292         }
293         else if(t == COLOR_TEAM2)
294         {
295                 if(cp.isgenneighbor_blue)
296                         return 2;
297                 if(cp.iscpneighbor_blue)
298                         return 1;
299         }
300         return 0;
301         /*
302            entity e;
303         // check to see if this player has a legitimate claim to capture this
304         // control point - more specifically that there is a captured path of
305         // points leading back to the team generator
306         e = findchain(classname, "onslaught_link");
307         while (e)
308         {
309         if (e.goalentity == cp)
310         {
311         dprint(etos(e), " (link) connects to ", etos(e.enemy), " (point)");
312         if (e.enemy.islinked)
313         {
314         dprint(" which is linked");
315         if (e.enemy.team == t)
316         {
317         dprint(" and has the correct team!\n");
318         return 1;
319         }
320         else
321         dprint(" but has the wrong team\n");
322         }
323         else
324         dprint("\n");
325         }
326         else if (e.enemy == cp)
327         {
328         dprint(etos(e), " (link) connects to ", etos(e.goalentity), " (point)");
329         if (e.goalentity.islinked)
330         {
331         dprint(" which is linked");
332         if (e.goalentity.team == t)
333         {
334         dprint(" and has a team!\n");
335         return 1;
336         }
337         else
338         dprint(" but has the wrong team\n");
339         }
340         else
341         dprint("\n");
342         }
343         e = e.chain;
344         }
345         return 0;
346          */
347 }
348
349 float onslaught_controlpoint_attackable(entity cp, float t)
350         // -2: SAME TEAM, attackable by enemy!
351         // -1: SAME TEAM!
352         // 0: off limits
353         // 1: attack it
354         // 2: touch it
355         // 3: attack it (HIGH PRIO)
356         // 4: touch it (HIGH PRIO)
357 {
358         float a;
359
360         if(cp.isshielded)
361         {
362                 return 0;
363         }
364         else if(cp.goalentity)
365         {
366                 // if there's already an icon built, nothing happens
367                 if(cp.team == t)
368                 {
369                         a = onslaught_controlpoint_can_be_linked(cp, COLOR_TEAM1 + COLOR_TEAM2 - t);
370                         if(a) // attackable by enemy?
371                                 return -2; // EMERGENCY!
372                         return -1;
373                 }
374                 // we know it can be linked, so no need to check
375                 // but...
376                 a = onslaught_controlpoint_can_be_linked(cp, t);
377                 if(a == 2) // near our generator?
378                         return 3; // EMERGENCY!
379                 return 1;
380         }
381         else
382         {
383                 // free point
384                 if(onslaught_controlpoint_can_be_linked(cp, t))
385                 {
386                         a = onslaught_controlpoint_can_be_linked(cp, COLOR_TEAM1 + COLOR_TEAM2 - t);
387                         if(a == 2)
388                                 return 4; // GET THIS ONE NOW!
389                         else
390                                 return 2; // TOUCH ME
391                 }
392         }
393         return 0;
394 }
395
396 void onslaught_generator_think()
397 {
398         local float d;
399         local entity e;
400         self.nextthink = ceil(time + 1);
401         if (cvar("timelimit"))
402                 if (time > cvar("timelimit") * 60 - 60)
403                 {
404                         // self.max_health / 300 gives 5 minutes of overtime.
405                         // control points reduce the overtime duration.
406                         sound(self, CHAN_TRIGGER, "onslaught/generator_decay.wav", VOL_BASE, ATTN_NORM);
407                         d = 1;
408                         e = findchain(classname, "onslaught_controlpoint");
409                         while (e)
410                         {
411                                 if (e.team != self.team)
412                                         if (e.islinked)
413                                                 d = d + 1;
414                                 e = e.chain;
415                         }
416                         d = d * self.max_health / 300;
417                         Damage(self, self, self, d, DEATH_HURTTRIGGER, self.origin, '0 0 0');
418                 }
419
420 };
421
422 void onslaught_generator_ring_think()
423 {
424         self.nextthink = time + 0.05;
425         if(self.count > 24)
426         {
427                 self.think = SUB_Remove;
428                 return;
429         }
430
431         self.scale = self.count * 4;
432
433         self.frame = self.count;
434
435         self.count += 1;
436         self.alpha = 0.1;
437 };
438
439 void onslaught_generator_ring_spawn(vector org)
440 {
441         entity e;
442         e = spawn();
443         setmodel(e, "models/onslaught/shockwavetransring.md3");
444         setorigin(e, org);
445
446         e.count = 1;
447         e.alpha = 0;
448
449         e.think = onslaught_generator_ring_think;
450         e.nextthink = time + 0.05;
451 };
452 void onslaught_generator_ray_think()
453 {
454         self.nextthink = time + 0.05;
455         if(self.count > 10)
456         {
457                 self.think = SUB_Remove;
458                 return;
459         }
460
461         if(self.count > 5)
462                 self.alpha -= 0.1;
463         else
464                 self.alpha += 0.1;
465
466         self.scale += 0.2;
467         self.count +=1;
468 };
469
470 void onslaught_generator_ray_spawn(vector org)
471 {
472         entity e;
473         e = spawn();
474         setmodel(e, "models/onslaught/ons_ray.md3");
475         setorigin(e, org);
476         e.angles = randomvec() * 360;
477         e.alpha = 0;
478         e.scale = random() * 5 + 8;
479         e.think = onslaught_generator_ray_think;
480         e.nextthink = time + 0.05;
481 };
482
483 void onslaught_generator_shockwave_think()
484 {
485         self.nextthink = time + 0.05;
486         if(self.count > 25)
487         {
488                 self.think = SUB_Remove;
489                 return;
490         }
491
492         if(self.count > 15)
493                 self.alpha -= 0.1;
494         else
495                 self.alpha = 1;
496
497         self.scale = self.count * 4;
498         setsize(self, self.mins * self.scale, self.maxs * self.scale);
499         self.frame = self.count;
500
501         self.count +=1;
502 };
503
504 void onslaught_generator_shockwave_spawn(vector org)
505 {
506         entity e;
507         e = spawn();
508         setmodel(e, "models/onslaught/shockwave.md3");
509         setorigin(e, org);
510
511         e.alpha = 0;
512         e.frame = 0;
513         e.count = 0;
514
515
516         e.think = onslaught_generator_shockwave_think;
517         e.nextthink = time + 0.05;
518 };
519
520 void onslaught_generator_damage_think()
521 {
522         if(self.owner.health < 0)
523         {
524                 self.think = SUB_Remove;
525                 return;
526         }
527         self.nextthink = time+0.1;
528
529         // damaged fx (less probable the more damaged is the generator)
530         if(random() < 0.9 - self.owner.health / self.owner.max_health)
531                 if(random() < 0.01)
532                 {
533                         pointparticles(particleeffectnum("electro_ballexplode"), self.origin + randompos('-50 -50 -20', '50 50 50'), '0 0 0', 1);
534                         sound(self, CHAN_TRIGGER, "onslaught/electricity_explode.wav", VOL_BASE, ATTN_NORM);
535                 }
536                 else
537                         pointparticles(particleeffectnum("torch_small"), self.origin + randompos('-60 -60 -20', '60 60 60'), '0 0 0', 1);
538 };
539
540 void onslaught_generator_damage_spawn(entity gd_owner)
541 {
542         entity e;
543         e = spawn();
544         e.owner = gd_owner;
545         e.health = self.owner.health;
546         setorigin(e, gd_owner.origin);
547         e.think = onslaught_generator_damage_think;
548         e.nextthink = time+1;
549 };
550
551 void onslaught_generator_deaththink()
552 {
553         local vector org;
554         local float i;
555
556         if not (self.count)
557                 self.count = 40;
558
559         // White shockwave
560         if(self.count==40||self.count==20)
561         {
562                 onslaught_generator_ring_spawn(self.origin);
563                 sound(self, CHAN_TRIGGER, "onslaught/shockwave.wav", VOL_BASE, ATTN_NORM);
564         }
565
566         // Throw some gibs
567         if(random() < 0.3)
568         {
569                 i = random();
570                 if(i < 0.3)
571                         ons_throwgib(self.origin + '0 0 40', (100 * randomvec() - '1 1 1') * 11 + '0 0 20', "models/onslaught/gen_gib1.md3", 25, 1, 1);
572                 else if(i > 0.7)
573                         ons_throwgib(self.origin + '0 0 40', (100 * randomvec() - '1 1 1') * 12 + '0 0 20', "models/onslaught/gen_gib2.md3", 20, 1, 1);
574                 else
575                         ons_throwgib(self.origin + '0 0 40', (100 * randomvec() - '1 1 1') * 13 + '0 0 20', "models/onslaught/gen_gib3.md3", 15, 1, 1);
576         }
577
578         // Spawn fire balls
579         for(i=0;i < 6;++i)
580         {
581                 org = self.origin + randompos('-30 -30 -30' * i + '0 0 -20', '30 30 30' * i + '0 0 20');
582                 onslaught_generator_boom_spawn(org, (6-i)/5+0.3);
583         }
584
585         // Short explosion sound + small explosion
586         if(random() < 0.25)
587         {
588                 te_explosion(self.origin);
589                 sound(self, CHAN_TRIGGER, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
590         }
591
592         // Particles
593         org = self.origin + randompos(self.mins + '8 8 8', self.maxs + '-8 -8 -8');
594         pointparticles(particleeffectnum("onslaught_generator_smallexplosion"), org, '0 0 0', 1);
595
596         // rays
597         if(random() > 0.25 )
598         {
599                 onslaught_generator_ray_spawn(self.origin);
600         }
601
602         // Final explosion
603         if(self.count==1)
604         {
605                 org = self.origin;
606                 te_explosion(org);
607                 onslaught_generator_shockwave_spawn(org);
608                 pointparticles(particleeffectnum("onslaught_generator_finalexplosion"), org, '0 0 0', 1);
609                 sound(self, CHAN_TRIGGER, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
610         }
611         else
612                 self.nextthink = time + 0.05;
613
614         self.count = self.count - 1;
615 };
616
617 void onslaught_generator_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
618 {
619         local float i;
620         if (damage <= 0)
621                 return;
622         if (attacker != self)
623         {
624                 if (self.isshielded)
625                 {
626                         // this is protected by a shield, so ignore the damage
627                         if (time > self.pain_finished)
628                                 if (attacker.classname == "player")
629                                 {
630                                         play2(attacker, "onslaught/damageblockedbyshield.wav");
631                                         self.pain_finished = time + 1;
632                                 }
633                         return;
634                 }
635                 if (time > self.pain_finished)
636                 {
637                         self.pain_finished = time + 10;
638                         bprint(ColoredTeamName(self.team), " generator under attack!\n");
639                         play2team(self.team, "onslaught/generator_underattack.wav");
640                 }
641         }
642         self.health = self.health - damage;
643         WaypointSprite_UpdateHealth(self.sprite, self.health);
644         // choose an animation frame based on health
645         self.frame = 10 * bound(0, (1 - self.health / self.max_health), 1);
646         // see if the generator is still functional, or dying
647         if (self.health > 0)
648         {
649 #ifdef ONSLAUGHT_SPAM
650                 float h, lh;
651                 lh = ceil(self.lasthealth / 100) * 100;
652                 h = ceil(self.health / 100) * 100;
653                 if(lh != h)
654                         bprint(ColoredTeamName(self.team), " generator has less than ", ftos(h), " health remaining\n");
655 #endif
656                 self.lasthealth = self.health;
657         }
658         else
659         {
660                 if (attacker == self)
661                         bprint(ColoredTeamName(self.team), " generator spontaneously exploded due to overtime!\n");
662                 else
663                 {
664                         string t;
665                         t = ColoredTeamName(attacker.team);
666                         bprint(ColoredTeamName(self.team), " generator destroyed by ", t, "!\n");
667                 }
668                 self.iscaptured = FALSE;
669                 self.islinked = FALSE;
670                 self.isshielded = FALSE;
671                 self.takedamage = DAMAGE_NO; // can't be hurt anymore
672                 self.event_damage = SUB_Null; // won't do anything if hurt
673                 self.count = 0; // reset counter
674                 self.think = onslaught_generator_deaththink; // explosion sequence
675                 self.nextthink = time; // start exploding immediately
676                 self.think(); // do the first explosion now
677
678                 WaypointSprite_UpdateMaxHealth(self.sprite, 0);
679
680                 onslaught_updatelinks();
681         }
682         if(self.health <= 0)
683                 setmodel(self, "models/onslaught/generator_dead.md3");
684         else if(self.health < self.max_health * 0.10)
685                 setmodel(self, "models/onslaught/generator_dmg9.md3");
686         else if(self.health < self.max_health * 0.20)
687                 setmodel(self, "models/onslaught/generator_dmg8.md3");
688         else if(self.health < self.max_health * 0.30)
689                 setmodel(self, "models/onslaught/generator_dmg7.md3");
690         else if(self.health < self.max_health * 0.40)
691                 setmodel(self, "models/onslaught/generator_dmg6.md3");
692         else if(self.health < self.max_health * 0.50)
693                 setmodel(self, "models/onslaught/generator_dmg5.md3");
694         else if(self.health < self.max_health * 0.60)
695                 setmodel(self, "models/onslaught/generator_dmg4.md3");
696         else if(self.health < self.max_health * 0.70)
697                 setmodel(self, "models/onslaught/generator_dmg3.md3");
698         else if(self.health < self.max_health * 0.80)
699                 setmodel(self, "models/onslaught/generator_dmg2.md3");
700         else if(self.health < self.max_health * 0.90)
701                 setmodel(self, "models/onslaught/generator_dmg1.md3");
702         setsize(self, '-52 -52 -14', '52 52 75');
703
704         // Throw some flaming gibs on damage, more damage = more chance for gib
705         if(random() < damage/220)
706         {
707                 sound(self, CHAN_TRIGGER, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
708                 i = random();
709                 if(i < 0.3)
710                         ons_throwgib(hitloc, (force * -1) + '0 0 40', "models/onslaught/gen_gib1.md3", 7, 1, 1);
711                 else if(i > 0.7)
712                         ons_throwgib(hitloc, (force * -1)+ '0 0 40', "models/onslaught/gen_gib2.md3", 6, 1, 1);
713                 else
714                         ons_throwgib(hitloc, (force * -1)+ '0 0 40', "models/onslaught/gen_gib3.md3", 5, 1, 1);
715         }
716         else
717         {
718                 // particles on every hit
719                 pointparticles(particleeffectnum("sparks"), hitloc, force * -1, 1);
720
721                 //sound on every hit
722                 if (random() < 0.5)
723                         sound(self, CHAN_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE, ATTN_NORM);
724                 else
725                         sound(self, CHAN_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE, ATTN_NORM);
726         }
727
728         //throw some gibs on damage
729         if(random() < damage/200+0.2)
730                 if(random() < 0.5)
731                         ons_throwgib(hitloc, randomvec()*360, "models/onslaught/gen_gib1.md3", 1, 1, 0);
732 };
733
734 // update links after a delay
735 void onslaught_generator_delayed()
736 {
737         onslaught_updatelinks();
738         // now begin normal thinking
739         self.think = onslaught_generator_think;
740         self.nextthink = time;
741 };
742
743 string onslaught_generator_waypointsprite_for_team(entity e, float t)
744 {
745         if(t == e.team)
746         {
747                 if(e.team == COLOR_TEAM1)
748                         return "ons-gen-red";
749                 else if(e.team == COLOR_TEAM2)
750                         return "ons-gen-blue";
751         }
752         if(e.isshielded)
753                 return "ons-gen-shielded";
754         if(e.team == COLOR_TEAM1)
755                 return "ons-gen-red";
756         else if(e.team == COLOR_TEAM2)
757                 return "ons-gen-blue";
758         return "";
759 }
760
761 void onslaught_generator_updatesprite(entity e)
762 {
763         string s1, s2, s3;
764         s1 = onslaught_generator_waypointsprite_for_team(e, COLOR_TEAM1);
765         s2 = onslaught_generator_waypointsprite_for_team(e, COLOR_TEAM2);
766         s3 = onslaught_generator_waypointsprite_for_team(e, -1);
767         WaypointSprite_UpdateSprites(e.sprite, s1, s2, s3);
768
769         if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
770         {
771                 e.lastteam = e.team + 2;
772                 e.lastshielded = e.isshielded;
773                 if(e.lastshielded)
774                 {
775                         if(e.team == COLOR_TEAM1 || e.team == COLOR_TEAM2)
776                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, FALSE));
777                         else
778                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
779                 }
780                 else
781                 {
782                         if(e.team == COLOR_TEAM1 || e.team == COLOR_TEAM2)
783                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, FALSE));
784                         else
785                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
786                 }
787                 WaypointSprite_Ping(e.sprite);
788         }
789 }
790
791 string onslaught_controlpoint_waypointsprite_for_team(entity e, float t)
792 {
793         float a;
794         if(t != -1)
795         {
796                 a = onslaught_controlpoint_attackable(e, t);
797                 if(a == 3 || a == 4) // ATTACK/TOUCH THIS ONE NOW
798                 {
799                         if(e.team == COLOR_TEAM1)
800                                 return "ons-cp-atck-red";
801                         else if(e.team == COLOR_TEAM2)
802                                 return "ons-cp-atck-blue";
803                         else
804                                 return "ons-cp-atck-neut";
805                 }
806                 else if(a == -2) // DEFEND THIS ONE NOW
807                 {
808                         if(e.team == COLOR_TEAM1)
809                                 return "ons-cp-dfnd-red";
810                         else if(e.team == COLOR_TEAM2)
811                                 return "ons-cp-dfnd-blue";
812                 }
813                 else if(e.team == t || a == -1 || a == 1) // own point, or fire at it
814                 {
815                         if(e.team == COLOR_TEAM1)
816                                 return "ons-cp-red";
817                         else if(e.team == COLOR_TEAM2)
818                                 return "ons-cp-blue";
819                 }
820                 else if(a == 2) // touch it
821                         return "ons-cp-neut";
822         }
823         else
824         {
825                 if(e.team == COLOR_TEAM1)
826                         return "ons-cp-red";
827                 else if(e.team == COLOR_TEAM2)
828                         return "ons-cp-blue";
829                 else
830                         return "ons-cp-neut";
831         }
832         return "";
833 }
834
835 void onslaught_controlpoint_updatesprite(entity e)
836 {
837         string s1, s2, s3;
838         s1 = onslaught_controlpoint_waypointsprite_for_team(e, COLOR_TEAM1);
839         s2 = onslaught_controlpoint_waypointsprite_for_team(e, COLOR_TEAM2);
840         s3 = onslaught_controlpoint_waypointsprite_for_team(e, -1);
841         WaypointSprite_UpdateSprites(e.sprite, s1, s2, s3);
842
843         float sh;
844         sh = !(onslaught_controlpoint_can_be_linked(e, COLOR_TEAM1) || onslaught_controlpoint_can_be_linked(e, COLOR_TEAM2));
845
846         if(e.lastteam != e.team + 2 || e.lastshielded != sh)
847         {
848                 e.lastteam = e.team + 2;
849                 e.lastshielded = sh;
850                 if(e.lastshielded)
851                 {
852                         if(e.team == COLOR_TEAM1 || e.team == COLOR_TEAM2)
853                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, FALSE));
854                         else
855                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
856                 }
857                 else
858                 {
859                         if(e.team == COLOR_TEAM1 || e.team == COLOR_TEAM2)
860                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, FALSE));
861                         else
862                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
863                 }
864                 WaypointSprite_Ping(e.sprite);
865
866                 if(e.goalentity) // don't mess up build bars!
867                 {
868                         if(sh)
869                         {
870                                 WaypointSprite_UpdateMaxHealth(e.sprite, 0);
871                         }
872                         else
873                         {
874                                 WaypointSprite_UpdateMaxHealth(e.sprite, e.goalentity.max_health);
875                                 WaypointSprite_UpdateHealth(e.sprite, e.goalentity.health);
876                         }
877                 }
878         }
879 }
880
881 void onslaught_generator_reset()
882 {
883         self.team = self.team_saved;
884         self.lasthealth = self.max_health = self.health = cvar("g_onslaught_gen_health");
885         self.takedamage = DAMAGE_AIM;
886         self.bot_attack = TRUE;
887         self.iscaptured = TRUE;
888         self.islinked = TRUE;
889         self.isshielded = TRUE;
890         self.enemy.solid = SOLID_NOT;
891         self.think = onslaught_generator_delayed;
892         self.nextthink = time + 0.2;
893         setmodel(self, "models/onslaught/generator.md3");
894
895         WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
896         WaypointSprite_UpdateHealth(self.sprite, self.health);
897 }
898
899 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
900   Base generator.
901
902   spawnfunc_onslaught_link entities can target this.
903
904 keys:
905 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
906 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
907  */
908 void spawnfunc_onslaught_generator()
909 {
910         if (!g_onslaught)
911         {
912                 remove(self);
913                 return;
914         }
915
916         local entity e;
917         precache_model("models/onslaught/generator.md3");
918         precache_model("models/onslaught/generator_shield.md3");
919         precache_model("models/onslaught/generator_dmg1.md3");
920         precache_model("models/onslaught/generator_dmg2.md3");
921         precache_model("models/onslaught/generator_dmg3.md3");
922         precache_model("models/onslaught/generator_dmg4.md3");
923         precache_model("models/onslaught/generator_dmg5.md3");
924         precache_model("models/onslaught/generator_dmg6.md3");
925         precache_model("models/onslaught/generator_dmg7.md3");
926         precache_model("models/onslaught/generator_dmg8.md3");
927         precache_model("models/onslaught/generator_dmg9.md3");
928         precache_model("models/onslaught/generator_dead.md3");
929         precache_model("models/onslaught/boom.md3");
930         precache_model("models/onslaught/shockwave.md3");
931         precache_model("models/onslaught/shockwavetransring.md3");
932         precache_model("models/onslaught/gen_gib1.md3");
933         precache_model("models/onslaught/gen_gib2.md3");
934         precache_model("models/onslaught/gen_gib3.md3");
935         precache_model("models/onslaught/ons_ray.md3");
936         precache_sound("onslaught/generator_decay.wav");
937         precache_sound("weapons/grenade_impact.wav");
938         precache_sound("weapons/rocket_impact.wav");
939         precache_sound("onslaught/generator_underattack.wav");
940         precache_sound("onslaught/shockwave.wav");
941         precache_sound("onslaught/ons_hit1.wav");
942         precache_sound("onslaught/ons_hit2.wav");
943         precache_sound("onslaught/electricity_explode.wav");
944         if (!self.team)
945                 objerror("team must be set");
946         self.team_saved = self.team;
947         self.colormap = 1024 + (self.team - 1) * 17;
948         self.solid = SOLID_BBOX;
949         self.movetype = MOVETYPE_NONE;
950         self.lasthealth = self.max_health = self.health = cvar("g_onslaught_gen_health");
951         setmodel(self, "models/onslaught/generator.md3");
952         setsize(self, '-52 -52 -14', '52 52 75');
953         setorigin(self, self.origin);
954         self.takedamage = DAMAGE_AIM;
955         self.bot_attack = TRUE;
956         self.event_damage = onslaught_generator_damage;
957         self.iscaptured = TRUE;
958         self.islinked = TRUE;
959         self.isshielded = TRUE;
960         // helper entity that create fx when generator is damaged
961         onslaught_generator_damage_spawn(self);
962         // spawn shield model which indicates whether this can be damaged
963         self.enemy = e = spawn();
964         e.classname = "onslaught_generator_shield";
965         e.solid = SOLID_NOT;
966         e.movetype = MOVETYPE_NONE;
967         e.effects = EF_ADDITIVE;
968         setmodel(e, "models/onslaught/generator_shield.md3");
969         setorigin(e, self.origin);
970         e.colormap = self.colormap;
971         e.team = self.team;
972         self.think = onslaught_generator_delayed;
973         self.nextthink = time + 0.2;
974         InitializeEntity(self, onslaught_generator_delayed, INITPRIO_LAST);
975
976         WaypointSprite_SpawnFixed(string_null, e.origin + '0 0 1' * e.maxs_z, self, sprite);
977         WaypointSprite_UpdateRule(self.sprite, COLOR_TEAM2, SPRITERULE_TEAMPLAY);
978         WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
979         WaypointSprite_UpdateHealth(self.sprite, self.health);
980
981         waypoint_spawnforitem(self);
982
983         onslaught_updatelinks();
984
985         self.reset = onslaught_generator_reset;
986 };
987
988 .float waslinked;
989 .float cp_bob_spd;
990 .vector cp_origin, cp_bob_origin, cp_bob_dmg;
991 void onslaught_controlpoint_icon_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
992 {
993         entity oself;
994         if (damage <= 0)
995                 return;
996         if (self.owner.isshielded)
997         {
998                 // this is protected by a shield, so ignore the damage
999                 if (time > self.pain_finished)
1000                         if (attacker.classname == "player")
1001                         {
1002                                 play2(attacker, "onslaught/damageblockedbyshield.wav");
1003                                 self.pain_finished = time + 1;
1004                         }
1005                 return;
1006         }
1007         if (time > self.pain_finished)
1008                 if (attacker.classname == "player")
1009                 {
1010                         play2team(self.team, "onslaught/controlpoint_underattack.wav");
1011                         self.pain_finished = time + 10;
1012                 }
1013         self.health = self.health - damage;
1014         if(self.owner.iscaptured)
1015                 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
1016         else
1017                 WaypointSprite_UpdateBuildFinished(self.owner.sprite, time + (self.max_health - self.health) / (self.count / sys_ticrate));
1018         self.pain_finished = time + 1;
1019         self.punchangle = (2 * randomvec() - '1 1 1') * 45;
1020         self.cp_bob_dmg_z = (2 * random() - 1) * 15;
1021         // colormod flash when shot
1022         self.colormod = '2 2 2';
1023         // particles on every hit
1024         pointparticles(particleeffectnum("sparks"), hitloc, force*-1, 1);
1025         //sound on every hit
1026         if (random() < 0.5)
1027                 sound(self, CHAN_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE+0.3, ATTN_NORM);
1028         else
1029                 sound(self, CHAN_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE+0.3, ATTN_NORM);
1030
1031         if (self.health < 0)
1032         {
1033                 sound(self, CHAN_TRIGGER, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
1034                 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
1035                 {
1036                         string t;
1037                         t = ColoredTeamName(attacker.team);
1038                         bprint(ColoredTeamName(self.team), " ", self.message, " control point destroyed by ", t, "\n");
1039                         ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 25, "models/onslaught/controlpoint_icon_gib1.md3", 5, 1, 0);
1040                         ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 45, "models/onslaught/controlpoint_icon_gib2.md3", 5, 1, 0);
1041                         ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 45, "models/onslaught/controlpoint_icon_gib2.md3", 5, 1, 0);
1042                         ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 5, 1, 0);
1043                         ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 5, 1, 0);
1044                         ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 5, 1, 0);
1045                         ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 5, 1, 0);
1046                 }
1047                 self.owner.goalentity = world;
1048                 self.owner.islinked = FALSE;
1049                 self.owner.iscaptured = FALSE;
1050                 self.owner.team = 0;
1051                 self.owner.colormap = 1024;
1052
1053                 WaypointSprite_UpdateMaxHealth(self.owner.sprite, 0);
1054
1055                 onslaught_updatelinks();
1056
1057                 // Use targets now (somebody make sure this is in the right place..)
1058                 oself = self;
1059                 self = self.owner;
1060                 activator = self;
1061                 SUB_UseTargets ();
1062                 self = oself;
1063
1064
1065                 self.owner.waslinked = self.owner.islinked;
1066                 if(self.owner.model != "models/onslaught/controlpoint_pad.md3")
1067                         setmodel(self.owner, "models/onslaught/controlpoint_pad.md3");
1068                 //setsize(self, '-32 -32 0', '32 32 8');
1069
1070                 remove(self);
1071         }
1072 };
1073
1074 void onslaught_controlpoint_icon_think()
1075 {
1076         entity oself;
1077         self.nextthink = time + sys_ticrate;
1078         if (time > self.pain_finished + 5)
1079         {
1080                 if(self.health < self.max_health)
1081                 {
1082                         self.health = self.health + self.count;
1083                         if (self.health >= self.max_health)
1084                                 self.health = self.max_health;
1085                         WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
1086                 }
1087         }
1088         if (self.health < self.max_health * 0.25)
1089                 setmodel(self, "models/onslaught/controlpoint_icon_dmg3.md3");
1090         else if (self.health < self.max_health * 0.50)
1091                 setmodel(self, "models/onslaught/controlpoint_icon_dmg2.md3");
1092         else if (self.health < self.max_health * 0.75)
1093                 setmodel(self, "models/onslaught/controlpoint_icon_dmg1.md3");
1094         else if (self.health < self.max_health * 0.90)
1095                 setmodel(self, "models/onslaught/controlpoint_icon.md3");
1096         // colormod flash when shot
1097         self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));
1098
1099         if(self.owner.islinked != self.owner.waslinked)
1100         {
1101                 // unteam the spawnpoint if needed
1102                 float t;
1103                 t = self.owner.team;
1104                 if(!self.owner.islinked)
1105                         self.owner.team = 0;
1106
1107                 oself = self;
1108                 self = self.owner;
1109                 activator = self;
1110                 SUB_UseTargets ();
1111                 self = oself;
1112
1113                 self.owner.team = t;
1114
1115                 self.owner.waslinked = self.owner.islinked;
1116         }
1117         if (self.punchangle_x > 2)
1118                 self.punchangle_x = self.punchangle_x - 2;
1119         else if (self.punchangle_x < -2)
1120                 self.punchangle_x = self.punchangle_x + 2;
1121         else
1122                 self.punchangle_x = 0;
1123         if (self.punchangle_y > 2)
1124                 self.punchangle_y = self.punchangle_y - 2;
1125         else if (self.punchangle_y < -2)
1126                 self.punchangle_y = self.punchangle_y + 2;
1127         else
1128                 self.punchangle_y = 0;
1129         if (self.punchangle_z > 2)
1130                 self.punchangle_z = self.punchangle_z - 2;
1131         else if (self.punchangle_z < -2)
1132                 self.punchangle_z = self.punchangle_z + 2;
1133         else
1134                 self.punchangle_z = 0;
1135         self.angles_x = self.punchangle_x;
1136         self.angles_y = self.punchangle_y + self.mangle_y;
1137         self.angles_z = self.punchangle_z;
1138         self.mangle_y = self.mangle_y + 1.5;
1139
1140         self.cp_bob_origin_z = 4 * PI * (1 - cos(self.cp_bob_spd / 8));
1141         self.cp_bob_spd = self.cp_bob_spd + 0.5;
1142         if(self.cp_bob_dmg_z > 0)
1143                 self.cp_bob_dmg_z = self.cp_bob_dmg_z - 0.1;
1144         else
1145                 self.cp_bob_dmg_z = 0;
1146         self.origin = self.cp_origin + self.cp_bob_origin + self.cp_bob_dmg;
1147
1148         // damaged fx
1149         if(random() < 0.6 - self.health / self.max_health)
1150         {
1151                 pointparticles(particleeffectnum("electricity_sparks"), self.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
1152
1153                 if(random() > 0.8)
1154                         sound(self, CHAN_PAIN, "onslaught/ons_spark1.wav", VOL_BASE, ATTN_NORM);
1155                 else if (random() > 0.5)
1156                         sound(self, CHAN_PAIN, "onslaught/ons_spark2.wav", VOL_BASE, ATTN_NORM);
1157         }
1158 };
1159
1160 void onslaught_controlpoint_icon_buildthink()
1161 {
1162         local entity oself;
1163         float a;
1164
1165         self.nextthink = time + sys_ticrate;
1166
1167         // only do this if there is power
1168         a = onslaught_controlpoint_can_be_linked(self.owner, self.owner.team);
1169         if(!a)
1170                 return;
1171
1172         self.health = self.health + self.count;
1173
1174         if (self.health >= self.max_health)
1175         {
1176                 self.health = self.max_health;
1177                 self.count = cvar("g_onslaught_cp_regen") * sys_ticrate; // slow repair rate from now on
1178                 self.think = onslaught_controlpoint_icon_think;
1179                 sound(self, CHAN_TRIGGER, "onslaught/controlpoint_built.wav", VOL_BASE, ATTN_NORM);
1180                 bprint(ColoredTeamName(self.team), " captured ", self.owner.message, " control point\n");
1181                 self.owner.iscaptured = TRUE;
1182
1183                 WaypointSprite_UpdateMaxHealth(self.owner.sprite, self.max_health);
1184                 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
1185
1186                 onslaught_updatelinks();
1187
1188                 // Use targets now (somebody make sure this is in the right place..)
1189                 oself = self;
1190                 self = self.owner;
1191                 activator = self;
1192                 SUB_UseTargets ();
1193                 self = oself;
1194                 self.cp_origin = self.origin;
1195                 self.cp_bob_origin = '0 0 0.1';
1196                 self.cp_bob_spd = 0;
1197         }
1198         self.alpha = self.health / self.max_health;
1199         // colormod flash when shot
1200         self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));
1201         if(self.owner.model != "models/onslaught/controlpoint_pad2.md3")
1202                 setmodel(self.owner, "models/onslaught/controlpoint_pad2.md3");
1203         //setsize(self, '-32 -32 0', '32 32 8');
1204
1205         if(random() < 0.9 - self.health / self.max_health)
1206                 pointparticles(particleeffectnum("rage"), self.origin + 10 * randomvec(), '0 0 -1', 1);
1207 };
1208
1209
1210
1211
1212 void onslaught_controlpoint_touch()
1213 {
1214         local entity e;
1215         float a;
1216         if (other.classname != "player")
1217                 return;
1218         a = onslaught_controlpoint_attackable(self, other.team);
1219         if(a != 2 && a != 4)
1220                 return;
1221         // we've verified that this player has a legitimate claim to this point,
1222         // so start building the captured point icon (which only captures this
1223         // point if it successfully builds without being destroyed first)
1224         self.goalentity = e = spawn();
1225         e.classname = "onslaught_controlpoint_icon";
1226         e.owner = self;
1227         e.max_health = cvar("g_onslaught_cp_health");
1228         e.health = cvar("g_onslaught_cp_buildhealth");
1229         e.solid = SOLID_BBOX;
1230         e.movetype = MOVETYPE_NONE;
1231         setmodel(e, "models/onslaught/controlpoint_icon.md3");
1232         setsize(e, '-32 -32 -32', '32 32 32');
1233         setorigin(e, self.origin + '0 0 96');
1234         e.takedamage = DAMAGE_AIM;
1235         e.bot_attack = TRUE;
1236         e.event_damage = onslaught_controlpoint_icon_damage;
1237         e.team = other.team;
1238         e.colormap = 1024 + (e.team - 1) * 17;
1239         e.think = onslaught_controlpoint_icon_buildthink;
1240         e.nextthink = time + sys_ticrate;
1241         e.count = (e.max_health - e.health) * sys_ticrate / cvar("g_onslaught_cp_buildtime"); // how long it takes to build
1242         sound(e, CHAN_TRIGGER, "onslaught/controlpoint_build.wav", VOL_BASE, ATTN_NORM);
1243         self.team = e.team;
1244         self.colormap = e.colormap;
1245         WaypointSprite_UpdateBuildFinished(self.sprite, time + (e.max_health - e.health) / (e.count / sys_ticrate));
1246 };
1247
1248 void onslaught_controlpoint_reset()
1249 {
1250         if(self.goalentity && self.goalentity != world)
1251                 remove(self.goalentity);
1252         self.goalentity = world;
1253         self.team = 0;
1254         self.colormap = 1024;
1255         self.iscaptured = FALSE;
1256         self.islinked = FALSE;
1257         self.isshielded = TRUE;
1258         self.enemy.solid = SOLID_NOT;
1259         self.enemy.colormap = self.colormap;
1260         self.think = self.enemy.think = SUB_Null;
1261         self.nextthink = 0; // don't like SUB_Null :P
1262         setmodel(self, "models/onslaught/controlpoint_pad.md3");
1263         //setsize(self, '-32 -32 0', '32 32 8');
1264
1265         WaypointSprite_UpdateMaxHealth(self.sprite, 0);
1266
1267         onslaught_updatelinks();
1268
1269         activator = self;
1270         SUB_UseTargets(); // to reset the structures, playerspawns etc.
1271 }
1272
1273 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
1274   Control point. Be sure to give this enough clearance so that the shootable part has room to exist
1275
1276   This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
1277
1278 keys:
1279 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
1280 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
1281 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
1282  */
1283 void spawnfunc_onslaught_controlpoint()
1284 {
1285         local entity e;
1286         if (!g_onslaught)
1287         {
1288                 remove(self);
1289                 return;
1290         }
1291         precache_model("models/onslaught/controlpoint_pad.md3");
1292         precache_model("models/onslaught/controlpoint_pad2.md3");
1293         precache_model("models/onslaught/controlpoint_shield.md3");
1294         precache_model("models/onslaught/controlpoint_icon.md3");
1295         precache_model("models/onslaught/controlpoint_icon_dmg1.md3");
1296         precache_model("models/onslaught/controlpoint_icon_dmg2.md3");
1297         precache_model("models/onslaught/controlpoint_icon_dmg3.md3");
1298         precache_model("models/onslaught/controlpoint_icon_gib1.md3");
1299         precache_model("models/onslaught/controlpoint_icon_gib2.md3");
1300         precache_model("models/onslaught/controlpoint_icon_gib4.md3");
1301         precache_sound("onslaught/controlpoint_build.wav");
1302         precache_sound("onslaught/controlpoint_built.wav");
1303         precache_sound("weapons/grenade_impact.wav");
1304         precache_sound("onslaught/damageblockedbyshield.wav");
1305         precache_sound("onslaught/controlpoint_underattack.wav");
1306         precache_sound("onslaught/ons_spark1.wav");
1307         precache_sound("onslaught/ons_spark2.wav");
1308         self.solid = SOLID_BBOX;
1309         self.movetype = MOVETYPE_NONE;
1310         setmodel(self, "models/onslaught/controlpoint_pad.md3");
1311         //setsize(self, '-32 -32 0', '32 32 8');
1312         setorigin(self, self.origin);
1313         self.touch = onslaught_controlpoint_touch;
1314         self.team = 0;
1315         self.colormap = 1024;
1316         self.iscaptured = FALSE;
1317         self.islinked = FALSE;
1318         self.isshielded = TRUE;
1319         // spawn shield model which indicates whether this can be damaged
1320         self.enemy = e = spawn();
1321         e.classname = "onslaught_controlpoint_shield";
1322         e.solid = SOLID_NOT;
1323         e.movetype = MOVETYPE_NONE;
1324         e.effects = EF_ADDITIVE;
1325         setmodel(e, "models/onslaught/controlpoint_shield.md3");
1326         //setsize(e, '-32 -32 0', '32 32 128');
1327         setorigin(e, self.origin);
1328         e.colormap = self.colormap;
1329
1330         waypoint_spawnforitem(self);
1331
1332         WaypointSprite_SpawnFixed(string_null, e.origin + '0 0 1' * e.maxs_z, self, sprite);
1333         WaypointSprite_UpdateRule(self.sprite, COLOR_TEAM2, SPRITERULE_TEAMPLAY);
1334
1335         onslaught_updatelinks();
1336
1337         self.reset = onslaught_controlpoint_reset;
1338 };
1339
1340 float onslaught_link_send(entity to, float sendflags)
1341 {
1342         WriteByte(MSG_ENTITY, ENT_CLIENT_RADARLINK);
1343         WriteByte(MSG_ENTITY, sendflags);
1344         if(sendflags & 1)
1345         {
1346                 WriteCoord(MSG_ENTITY, self.goalentity.origin_x);
1347                 WriteCoord(MSG_ENTITY, self.goalentity.origin_y);
1348                 WriteCoord(MSG_ENTITY, self.goalentity.origin_z);
1349         }
1350         if(sendflags & 2)
1351         {
1352                 WriteCoord(MSG_ENTITY, self.enemy.origin_x);
1353                 WriteCoord(MSG_ENTITY, self.enemy.origin_y);
1354                 WriteCoord(MSG_ENTITY, self.enemy.origin_z);
1355         }
1356         if(sendflags & 4)
1357         {
1358                 WriteByte(MSG_ENTITY, self.clientcolors); // which is goalentity's color + enemy's color * 16
1359         }
1360         return TRUE;
1361 }
1362
1363 void onslaught_link_checkupdate()
1364 {
1365         // TODO check if the two sides have moved (currently they won't move anyway)
1366         float redpower, bluepower;
1367
1368         redpower = bluepower = 0;
1369         if(self.goalentity.islinked)
1370         {
1371                 if(self.goalentity.team == COLOR_TEAM1)
1372                         redpower = 1;
1373                 else if(self.goalentity.team == COLOR_TEAM2)
1374                         bluepower = 1;
1375         }
1376         if(self.enemy.islinked)
1377         {
1378                 if(self.enemy.team == COLOR_TEAM1)
1379                         redpower = 2;
1380                 else if(self.enemy.team == COLOR_TEAM2)
1381                         bluepower = 2;
1382         }
1383
1384         float cc;
1385         if(redpower == 1 && bluepower == 2)
1386                 cc = (COLOR_TEAM1 - 1) * 0x01 + (COLOR_TEAM2 - 1) * 0x10;
1387         else if(redpower == 2 && bluepower == 1)
1388                 cc = (COLOR_TEAM1 - 1) * 0x10 + (COLOR_TEAM2 - 1) * 0x01;
1389         else if(redpower)
1390                 cc = (COLOR_TEAM1 - 1) * 0x11;
1391         else if(bluepower)
1392                 cc = (COLOR_TEAM2 - 1) * 0x11;
1393         else
1394                 cc = 0;
1395
1396         if(cc != self.clientcolors)
1397         {
1398                 self.clientcolors = cc;
1399                 self.SendFlags |= 4;
1400         }
1401
1402         self.nextthink = time;
1403 }
1404
1405 void onslaught_link_delayed()
1406 {
1407         self.goalentity = find(world, targetname, self.target);
1408         self.enemy = find(world, targetname, self.target2);
1409         if (!self.goalentity)
1410                 objerror("can not find target\n");
1411         if (!self.enemy)
1412                 objerror("can not find target2\n");
1413         dprint(etos(self.goalentity), " linked with ", etos(self.enemy), "\n");
1414         self.SendFlags |= 3;
1415         self.think = onslaught_link_checkupdate;
1416         self.nextthink = time;
1417 }
1418
1419 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
1420   Link between control points.
1421
1422   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.
1423
1424 keys:
1425 "target" - first control point.
1426 "target2" - second control point.
1427  */
1428 void spawnfunc_onslaught_link()
1429 {
1430         if (!g_onslaught)
1431         {
1432                 remove(self);
1433                 return;
1434         }
1435         if (self.target == "" || self.target2 == "")
1436                 objerror("target and target2 must be set\n");
1437         InitializeEntity(self, onslaught_link_delayed, INITPRIO_FINDTARGET);
1438         Net_LinkEntity(self, FALSE, 0, onslaught_link_send);
1439 };