]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/mode_onslaught.qc
fix CP rotation
[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.ogg", 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         // choose an animation frame based on health
644         self.frame = 10 * bound(0, (1 - self.health / self.max_health), 1);
645         // see if the generator is still functional, or dying
646         if (self.health > 0)
647         {
648                 float h, lh;
649                 lh = ceil(self.lasthealth / 100) * 100;
650                 h = ceil(self.health / 100) * 100;
651                 if(lh != h)
652                         bprint(ColoredTeamName(self.team), " generator has less than ", ftos(h), " health remaining\n");
653                 self.lasthealth = self.health;
654         }
655         else
656         {
657                 if (attacker == self)
658                         bprint(ColoredTeamName(self.team), " generator spontaneously exploded due to overtime!\n");
659                 else
660                 {
661                         string t;
662                         t = ColoredTeamName(attacker.team);
663                         bprint(ColoredTeamName(self.team), " generator destroyed by ", t, "!\n");
664                 }
665                 self.iscaptured = FALSE;
666                 self.islinked = FALSE;
667                 self.isshielded = FALSE;
668                 self.takedamage = DAMAGE_NO; // can't be hurt anymore
669                 self.event_damage = SUB_Null; // won't do anything if hurt
670                 self.count = 0; // reset counter
671                 self.think = onslaught_generator_deaththink; // explosion sequence
672                 self.nextthink = time; // start exploding immediately
673                 self.think(); // do the first explosion now
674                 onslaught_updatelinks();
675         }
676         if(self.health <= 0)
677                 setmodel(self, "models/onslaught/generator_dead.md3");
678         else if(self.health < self.max_health * 0.10)
679                 setmodel(self, "models/onslaught/generator_dmg9.md3");
680         else if(self.health < self.max_health * 0.20)
681                 setmodel(self, "models/onslaught/generator_dmg8.md3");
682         else if(self.health < self.max_health * 0.30)
683                 setmodel(self, "models/onslaught/generator_dmg7.md3");
684         else if(self.health < self.max_health * 0.40)
685                 setmodel(self, "models/onslaught/generator_dmg6.md3");
686         else if(self.health < self.max_health * 0.50)
687                 setmodel(self, "models/onslaught/generator_dmg5.md3");
688         else if(self.health < self.max_health * 0.60)
689                 setmodel(self, "models/onslaught/generator_dmg4.md3");
690         else if(self.health < self.max_health * 0.70)
691                 setmodel(self, "models/onslaught/generator_dmg3.md3");
692         else if(self.health < self.max_health * 0.80)
693                 setmodel(self, "models/onslaught/generator_dmg2.md3");
694         else if(self.health < self.max_health * 0.90)
695                 setmodel(self, "models/onslaught/generator_dmg1.md3");
696         setsize(self, '-52 -52 -14', '52 52 75');
697
698         // Throw some flaming gibs on damage, more damage = more chance for gib
699         if(random() < damage/220)
700         {
701                 sound(self, CHAN_TRIGGER, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
702                 i = random();
703                 if(i < 0.3)
704                         ons_throwgib(hitloc, (force * -1) + '0 0 40', "models/onslaught/gen_gib1.md3", 7, 1, 1);
705                 else if(i > 0.7)
706                         ons_throwgib(hitloc, (force * -1)+ '0 0 40', "models/onslaught/gen_gib2.md3", 6, 1, 1);
707                 else
708                         ons_throwgib(hitloc, (force * -1)+ '0 0 40', "models/onslaught/gen_gib3.md3", 5, 1, 1);
709         }
710         else
711         {
712                 // particles on every hit
713                 pointparticles(particleeffectnum("sparks"), hitloc, force * -1, 1);
714
715                 //sound on every hit
716                 if (random() < 0.5)
717                         sound(self, CHAN_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE, ATTN_NORM);
718                 else
719                         sound(self, CHAN_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE, ATTN_NORM);
720         }
721
722         //throw some gibs on damage
723         if(random() < damage/200+0.2)
724                 if(random() < 0.5)
725                         ons_throwgib(hitloc, randomvec()*360, "models/onslaught/gen_gib1.md3", 1, 1, 0);
726 };
727
728 // update links after a delay
729 void onslaught_generator_delayed()
730 {
731         onslaught_updatelinks();
732         // now begin normal thinking
733         self.think = onslaught_generator_think;
734         self.nextthink = time;
735 };
736
737 string onslaught_generator_waypointsprite_for_team(entity e, float t)
738 {
739         if(t == e.team)
740         {
741                 if(e.team == COLOR_TEAM1)
742                         return "ons-gen-red";
743                 else if(e.team == COLOR_TEAM2)
744                         return "ons-gen-blue";
745         }
746         if(e.isshielded)
747                 return "ons-gen-shielded";
748         if(e.team == COLOR_TEAM1)
749                 return "ons-gen-red";
750         else if(e.team == COLOR_TEAM2)
751                 return "ons-gen-blue";
752         return "";
753 }
754
755 void onslaught_generator_updatesprite(entity e)
756 {
757         string s1, s2, s3;
758         s1 = onslaught_generator_waypointsprite_for_team(e, COLOR_TEAM1);
759         s2 = onslaught_generator_waypointsprite_for_team(e, COLOR_TEAM2);
760         s3 = onslaught_generator_waypointsprite_for_team(e, -1);
761         WaypointSprite_UpdateSprites(e.sprite, s1, s2, s3);
762
763         if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
764         {
765                 e.lastteam = e.team + 2;
766                 e.lastshielded = e.isshielded;
767                 if(e.lastshielded)
768                 {
769                         if(e.team == COLOR_TEAM1)
770                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0 0');
771                         else if(e.team == COLOR_TEAM2)
772                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0 0 0.5');
773                         else
774                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
775                 }
776                 else
777                 {
778                         if(e.team == COLOR_TEAM1)
779                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '1 0 0');
780                         else if(e.team == COLOR_TEAM2)
781                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0 0 1');
782                         else
783                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
784                 }
785                 WaypointSprite_Ping(e.sprite);
786         }
787 }
788
789 string onslaught_controlpoint_waypointsprite_for_team(entity e, float t)
790 {
791         float a;
792         if(t != -1)
793         {
794                 a = onslaught_controlpoint_attackable(e, t);
795                 if(a == 3 || a == 4) // ATTACK/TOUCH THIS ONE NOW
796                 {
797                         if(e.team == COLOR_TEAM1)
798                                 return "ons-cp-atck-red";
799                         else if(e.team == COLOR_TEAM2)
800                                 return "ons-cp-atck-blue";
801                         else
802                                 return "ons-cp-atck-neut";
803                 }
804                 else if(a == -2) // DEFEND THIS ONE NOW
805                 {
806                         if(e.team == COLOR_TEAM1)
807                                 return "ons-cp-dfnd-red";
808                         else if(e.team == COLOR_TEAM2)
809                                 return "ons-cp-dfnd-blue";
810                 }
811                 else if(e.team == t || a == -1 || a == 1) // own point, or fire at it
812                 {
813                         if(e.team == COLOR_TEAM1)
814                                 return "ons-cp-red";
815                         else if(e.team == COLOR_TEAM2)
816                                 return "ons-cp-blue";
817                 }
818                 else if(a == 2) // touch it
819                         return "ons-cp-neut";
820         }
821         else
822         {
823                 if(e.team == COLOR_TEAM1)
824                         return "ons-cp-red";
825                 else if(e.team == COLOR_TEAM2)
826                         return "ons-cp-blue";
827                 else
828                         return "ons-cp-neut";
829         }
830         return "";
831 }
832
833 void onslaught_controlpoint_updatesprite(entity e)
834 {
835         string s1, s2, s3;
836         s1 = onslaught_controlpoint_waypointsprite_for_team(e, COLOR_TEAM1);
837         s2 = onslaught_controlpoint_waypointsprite_for_team(e, COLOR_TEAM2);
838         s3 = onslaught_controlpoint_waypointsprite_for_team(e, -1);
839         WaypointSprite_UpdateSprites(e.sprite, s1, s2, s3);
840
841         float sh;
842         sh = !(onslaught_controlpoint_can_be_linked(e, COLOR_TEAM1) || onslaught_controlpoint_can_be_linked(e, COLOR_TEAM2));
843
844         if(e.lastteam != e.team + 2 || e.lastshielded != sh)
845         {
846                 e.lastteam = e.team + 2;
847                 e.lastshielded = sh;
848                 if(e.lastshielded)
849                 {
850                         if(e.team == COLOR_TEAM1)
851                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0 0');
852                         else if(e.team == COLOR_TEAM2)
853                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0 0 0.5');
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)
860                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '1 0 0');
861                         else if(e.team == COLOR_TEAM2)
862                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0 0 1');
863                         else
864                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
865                 }
866                 WaypointSprite_Ping(e.sprite);
867         }
868 }
869
870 void onslaught_generator_reset()
871 {
872         self.team = self.team_saved;
873         self.lasthealth = self.max_health = self.health = cvar("g_onslaught_gen_health");
874         self.takedamage = DAMAGE_AIM;
875         self.bot_attack = TRUE;
876         self.iscaptured = TRUE;
877         self.islinked = TRUE;
878         self.isshielded = TRUE;
879         self.enemy.solid = SOLID_NOT;
880         self.think = onslaught_generator_delayed;
881         self.nextthink = time + 0.2;
882         setmodel(self, "models/onslaught/generator.md3");
883 }
884
885 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
886   Base generator.
887
888   spawnfunc_onslaught_link entities can target this.
889
890 keys:
891 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
892 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
893  */
894 void spawnfunc_onslaught_generator()
895 {
896         if (!g_onslaught)
897         {
898                 remove(self);
899                 return;
900         }
901
902         local entity e;
903         precache_model("models/onslaught/generator.md3");
904         precache_model("models/onslaught/generator_shield.md3");
905         precache_model("models/onslaught/generator_dmg1.md3");
906         precache_model("models/onslaught/generator_dmg2.md3");
907         precache_model("models/onslaught/generator_dmg3.md3");
908         precache_model("models/onslaught/generator_dmg4.md3");
909         precache_model("models/onslaught/generator_dmg5.md3");
910         precache_model("models/onslaught/generator_dmg6.md3");
911         precache_model("models/onslaught/generator_dmg7.md3");
912         precache_model("models/onslaught/generator_dmg8.md3");
913         precache_model("models/onslaught/generator_dmg9.md3");
914         precache_model("models/onslaught/generator_dead.md3");
915         precache_model("models/onslaught/boom.md3");
916         precache_model("models/onslaught/shockwave.md3");
917         precache_model("models/onslaught/shockwavetransring.md3");
918         precache_model("models/onslaught/gen_gib1.md3");
919         precache_model("models/onslaught/gen_gib2.md3");
920         precache_model("models/onslaught/gen_gib3.md3");
921         precache_model("models/onslaught/ons_ray.md3");
922         precache_sound("onslaught/generator_decay.wav");
923         precache_sound("weapons/grenade_impact.wav");
924         precache_sound("weapons/rocket_impact.wav");
925         precache_sound("onslaught/generator_underattack.wav");
926         precache_sound("onslaught/shockwave.wav");
927         precache_sound("onslaught/ons_hit1.wav");
928         precache_sound("onslaught/ons_hit2.wav");
929         precache_sound("onslaught/electricity_explode.wav");
930         if (!self.team)
931                 objerror("team must be set");
932         self.team_saved = self.team;
933         self.colormap = 1024 + (self.team - 1) * 17;
934         self.solid = SOLID_BBOX;
935         self.movetype = MOVETYPE_NONE;
936         self.lasthealth = self.max_health = self.health = cvar("g_onslaught_gen_health");
937         setmodel(self, "models/onslaught/generator.md3");
938         setsize(self, '-52 -52 -14', '52 52 75');
939         setorigin(self, self.origin);
940         self.takedamage = DAMAGE_AIM;
941         self.bot_attack = TRUE;
942         self.event_damage = onslaught_generator_damage;
943         self.iscaptured = TRUE;
944         self.islinked = TRUE;
945         self.isshielded = TRUE;
946         // helper entity that create fx when generator is damaged
947         onslaught_generator_damage_spawn(self);
948         // spawn shield model which indicates whether this can be damaged
949         self.enemy = e = spawn();
950         e.classname = "onslaught_generator_shield";
951         e.solid = SOLID_NOT;
952         e.movetype = MOVETYPE_NONE;
953         e.effects = EF_ADDITIVE;
954         setmodel(e, "models/onslaught/generator_shield.md3");
955         setorigin(e, self.origin);
956         e.colormap = self.colormap;
957         e.team = self.team;
958         self.think = onslaught_generator_delayed;
959         self.nextthink = time + 0.2;
960         InitializeEntity(self, onslaught_generator_delayed, INITPRIO_LAST);
961
962         WaypointSprite_SpawnFixed(string_null, e.origin + '0 0 1' * e.maxs_z, self, sprite);
963         WaypointSprite_UpdateRule(self.sprite, COLOR_TEAM2, SPRITERULE_TEAMPLAY);
964
965         onslaught_updatelinks();
966
967         self.reset = onslaught_generator_reset;
968 };
969
970 .float waslinked;
971 .float cp_bob_spd;
972 .vector cp_origin, cp_bob_origin, cp_bob_dmg;
973 void onslaught_controlpoint_icon_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
974 {
975         entity oself;
976         if (damage <= 0)
977                 return;
978         if (self.owner.isshielded)
979         {
980                 // this is protected by a shield, so ignore the damage
981                 if (time > self.pain_finished)
982                         if (attacker.classname == "player")
983                         {
984                                 play2(attacker, "onslaught/damageblockedbyshield.wav");
985                                 self.pain_finished = time + 1;
986                         }
987                 return;
988         }
989         if (time > self.pain_finished)
990                 if (attacker.classname == "player")
991                 {
992                         play2team(self.team, "onslaught/controlpoint_underattack.wav");
993                         self.pain_finished = time + 10;
994                 }
995         self.health = self.health - damage;
996         self.pain_finished = time + 1;
997         self.punchangle = (2 * randomvec() - '1 1 1') * 45;
998         self.cp_bob_dmg_z = (2 * random() - 1) * 15;
999         // colormod flash when shot
1000         self.colormod = '2 2 2';
1001         // particles on every hit
1002         pointparticles(particleeffectnum("sparks"), hitloc, force*-1, 1);
1003         //sound on every hit
1004         if (random() < 0.5)
1005                 sound(self, CHAN_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE+0.3, ATTN_NORM);
1006         else
1007                 sound(self, CHAN_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE+0.3, ATTN_NORM);
1008
1009         if (self.health < 0)
1010         {
1011                 sound(self, CHAN_TRIGGER, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
1012                 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
1013                 {
1014                         string t;
1015                         t = ColoredTeamName(attacker.team);
1016                         bprint(ColoredTeamName(self.team), " ", self.message, " control point destroyed by ", t, "\n");
1017                         ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 25, "models/onslaught/controlpoint_icon_gib1.md3", 5, 1, 0);
1018                         ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 45, "models/onslaught/controlpoint_icon_gib2.md3", 5, 1, 0);
1019                         ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 45, "models/onslaught/controlpoint_icon_gib2.md3", 5, 1, 0);
1020                         ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 5, 1, 0);
1021                         ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 5, 1, 0);
1022                         ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 5, 1, 0);
1023                         ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 5, 1, 0);
1024                 }
1025                 self.owner.goalentity = world;
1026                 self.owner.islinked = FALSE;
1027                 self.owner.iscaptured = FALSE;
1028                 self.owner.team = 0;
1029                 self.owner.colormap = 1024;
1030                 onslaught_updatelinks();
1031
1032                 // Use targets now (somebody make sure this is in the right place..)
1033                 oself = self;
1034                 self = self.owner;
1035                 activator = self;
1036                 SUB_UseTargets ();
1037                 self = oself;
1038
1039
1040                 self.owner.waslinked = self.owner.islinked;
1041                 if(self.owner.model != "models/onslaught/controlpoint_pad.md3")
1042                         setmodel(self.owner, "models/onslaught/controlpoint_pad.md3");
1043                 //setsize(self, '-32 -32 0', '32 32 8');
1044
1045                 remove(self);
1046         }
1047 };
1048
1049 void onslaught_controlpoint_icon_think()
1050 {
1051         entity oself;
1052         self.nextthink = time + 0.05;
1053         if (time > self.pain_finished + 5)
1054         {
1055                 self.health = self.health + self.count;
1056                 if (self.health >= self.max_health)
1057                         self.health = self.max_health;
1058         }
1059         if (self.health < self.max_health * 0.25)
1060                 setmodel(self, "models/onslaught/controlpoint_icon_dmg3.md3");
1061         else if (self.health < self.max_health * 0.50)
1062                 setmodel(self, "models/onslaught/controlpoint_icon_dmg2.md3");
1063         else if (self.health < self.max_health * 0.75)
1064                 setmodel(self, "models/onslaught/controlpoint_icon_dmg1.md3");
1065         else if (self.health < self.max_health * 0.90)
1066                 setmodel(self, "models/onslaught/controlpoint_icon.md3");
1067         // colormod flash when shot
1068         self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));
1069
1070         if(self.owner.islinked != self.owner.waslinked)
1071         {
1072                 // unteam the spawnpoint if needed
1073                 float t;
1074                 t = self.owner.team;
1075                 if(!self.owner.islinked)
1076                         self.owner.team = 0;
1077
1078                 oself = self;
1079                 self = self.owner;
1080                 activator = self;
1081                 SUB_UseTargets ();
1082                 self = oself;
1083
1084                 self.owner.team = t;
1085
1086                 self.owner.waslinked = self.owner.islinked;
1087         }
1088         if (self.punchangle_x > 2)
1089                 self.punchangle_x = self.punchangle_x - 2;
1090         else if (self.punchangle_x < -2)
1091                 self.punchangle_x = self.punchangle_x + 2;
1092         else
1093                 self.punchangle_x = 0;
1094         if (self.punchangle_y > 2)
1095                 self.punchangle_y = self.punchangle_y - 2;
1096         else if (self.punchangle_y < -2)
1097                 self.punchangle_y = self.punchangle_y + 2;
1098         else
1099                 self.punchangle_y = 0;
1100         if (self.punchangle_z > 2)
1101                 self.punchangle_z = self.punchangle_z - 2;
1102         else if (self.punchangle_z < -2)
1103                 self.punchangle_z = self.punchangle_z + 2;
1104         else
1105                 self.punchangle_z = 0;
1106         self.angles_x = self.punchangle_x;
1107         self.angles_y = self.punchangle_y + self.mangle_y;
1108         self.angles_z = self.punchangle_z;
1109         self.mangle_y = self.mangle_y + 1.5;
1110
1111         self.cp_bob_origin_z = 4 * PI * (1 - cos(self.cp_bob_spd / 8));
1112         self.cp_bob_spd = self.cp_bob_spd + 0.5;
1113         if(self.cp_bob_dmg_z > 0)
1114                 self.cp_bob_dmg_z = self.cp_bob_dmg_z - 0.1;
1115         else
1116                 self.cp_bob_dmg_z = 0;
1117         self.origin = self.cp_origin + self.cp_bob_origin + self.cp_bob_dmg;
1118
1119         // damaged fx
1120         if(random() < 0.6 - self.health / self.max_health)
1121         {
1122                 pointparticles(particleeffectnum("electricity_sparks"), self.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
1123
1124                 if(random() > 0.8)
1125                         sound(self, CHAN_PAIN, "onslaught/ons_spark1.wav", VOL_BASE, ATTN_NORM);
1126                 else if (random() > 0.5)
1127                         sound(self, CHAN_PAIN, "onslaught/ons_spark2.wav", VOL_BASE, ATTN_NORM);
1128         }
1129 };
1130
1131 void onslaught_controlpoint_icon_buildthink()
1132 {
1133         local entity oself;
1134         float a;
1135
1136         self.nextthink = time + 0.05;
1137
1138         // only do this if there is power
1139         a = onslaught_controlpoint_can_be_linked(self.owner, self.owner.team);
1140         if(!a)
1141                 return;
1142
1143         self.health = self.health + self.count;
1144
1145         if (self.health >= self.max_health)
1146         {
1147                 self.health = self.max_health;
1148                 self.count = self.count * 0.1; // slow repair rate from now on
1149                 self.think = onslaught_controlpoint_icon_think;
1150                 sound(self, CHAN_TRIGGER, "onslaught/controlpoint_built.wav", VOL_BASE, ATTN_NORM);
1151                 bprint(ColoredTeamName(self.team), " captured ", self.owner.message, " control point\n");
1152                 self.owner.iscaptured = TRUE;
1153                 onslaught_updatelinks();
1154
1155                 // Use targets now (somebody make sure this is in the right place..)
1156                 oself = self;
1157                 self = self.owner;
1158                 activator = self;
1159                 SUB_UseTargets ();
1160                 self = oself;
1161                 self.cp_origin = self.origin;
1162                 self.cp_bob_origin = '0 0 0.1';
1163                 self.cp_bob_spd = 0;
1164         }
1165         self.alpha = self.health / self.max_health;
1166         // colormod flash when shot
1167         self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));
1168         if(self.owner.model != "models/onslaught/controlpoint_pad2.md3")
1169                 setmodel(self.owner, "models/onslaught/controlpoint_pad2.md3");
1170         //setsize(self, '-32 -32 0', '32 32 8');
1171
1172         if(random() < 0.9 - self.health / self.max_health)
1173                 pointparticles(particleeffectnum("rage"), self.origin + 10 * randomvec(), '0 0 -1', 1);
1174 };
1175
1176
1177
1178
1179 void onslaught_controlpoint_touch()
1180 {
1181         local entity e;
1182         float a;
1183         if (other.classname != "player")
1184                 return;
1185         a = onslaught_controlpoint_attackable(self, other.team);
1186         if(a != 2 && a != 4)
1187                 return;
1188         // we've verified that this player has a legitimate claim to this point,
1189         // so start building the captured point icon (which only captures this
1190         // point if it successfully builds without being destroyed first)
1191         self.goalentity = e = spawn();
1192         e.classname = "onslaught_controlpoint_icon";
1193         e.owner = self;
1194         e.max_health = cvar("g_onslaught_cp_health");
1195         e.health = e.max_health * 0.1;
1196         e.solid = SOLID_BBOX;
1197         e.movetype = MOVETYPE_NONE;
1198         setmodel(e, "models/onslaught/controlpoint_icon.md3");
1199         setsize(e, '-32 -32 -32', '32 32 32');
1200         setorigin(e, self.origin + '0 0 96');
1201         e.takedamage = DAMAGE_AIM;
1202         e.bot_attack = TRUE;
1203         e.event_damage = onslaught_controlpoint_icon_damage;
1204         e.team = other.team;
1205         e.colormap = 1024 + (e.team - 1) * 17;
1206         e.think = onslaught_controlpoint_icon_buildthink;
1207         e.nextthink = time + 0.1;
1208         e.count = e.max_health / 100; // how long it takes to build
1209         sound(e, CHAN_TRIGGER, "onslaught/controlpoint_build.wav", VOL_BASE, ATTN_NORM);
1210         self.team = e.team;
1211         self.colormap = e.colormap;
1212 };
1213
1214 void onslaught_controlpoint_reset()
1215 {
1216         if(self.goalentity && self.goalentity != world)
1217                 remove(self.goalentity);
1218         self.goalentity = world;
1219         self.team = 0;
1220         self.colormap = 1024;
1221         self.iscaptured = FALSE;
1222         self.islinked = FALSE;
1223         self.isshielded = TRUE;
1224         self.enemy.solid = SOLID_NOT;
1225         self.enemy.colormap = self.colormap;
1226         self.think = self.enemy.think = SUB_Null;
1227         self.nextthink = 0; // don't like SUB_Null :P
1228         setmodel(self, "models/onslaught/controlpoint_pad.md3");
1229         //setsize(self, '-32 -32 0', '32 32 8');
1230
1231         onslaught_updatelinks();
1232
1233         activator = self;
1234         SUB_UseTargets(); // to reset the structures, playerspawns etc.
1235 }
1236
1237 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
1238   Control point. Be sure to give this enough clearance so that the shootable part has room to exist
1239
1240   This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
1241
1242 keys:
1243 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
1244 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
1245 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
1246  */
1247 void spawnfunc_onslaught_controlpoint()
1248 {
1249         local entity e;
1250         if (!g_onslaught)
1251         {
1252                 remove(self);
1253                 return;
1254         }
1255         precache_model("models/onslaught/controlpoint_pad.md3");
1256         precache_model("models/onslaught/controlpoint_pad2.md3");
1257         precache_model("models/onslaught/controlpoint_shield.md3");
1258         precache_model("models/onslaught/controlpoint_icon.md3");
1259         precache_model("models/onslaught/controlpoint_icon_dmg1.md3");
1260         precache_model("models/onslaught/controlpoint_icon_dmg2.md3");
1261         precache_model("models/onslaught/controlpoint_icon_dmg3.md3");
1262         precache_model("models/onslaught/controlpoint_icon_gib1.md3");
1263         precache_model("models/onslaught/controlpoint_icon_gib2.md3");
1264         precache_model("models/onslaught/controlpoint_icon_gib4.md3");
1265         precache_sound("onslaught/controlpoint_build.wav");
1266         precache_sound("onslaught/controlpoint_built.wav");
1267         precache_sound("weapons/grenade_impact.wav");
1268         precache_sound("onslaught/damageblockedbyshield.wav");
1269         precache_sound("onslaught/controlpoint_underattack.wav");
1270         precache_sound("onslaught/ons_spark1.wav");
1271         precache_sound("onslaught/ons_spark2.wav");
1272         self.solid = SOLID_BBOX;
1273         self.movetype = MOVETYPE_NONE;
1274         setmodel(self, "models/onslaught/controlpoint_pad.md3");
1275         //setsize(self, '-32 -32 0', '32 32 8');
1276         setorigin(self, self.origin);
1277         self.touch = onslaught_controlpoint_touch;
1278         self.team = 0;
1279         self.colormap = 1024;
1280         self.iscaptured = FALSE;
1281         self.islinked = FALSE;
1282         self.isshielded = TRUE;
1283         // spawn shield model which indicates whether this can be damaged
1284         self.enemy = e = spawn();
1285         e.classname = "onslaught_controlpoint_shield";
1286         e.solid = SOLID_NOT;
1287         e.movetype = MOVETYPE_NONE;
1288         e.effects = EF_ADDITIVE;
1289         setmodel(e, "models/onslaught/controlpoint_shield.md3");
1290         //setsize(e, '-32 -32 0', '32 32 128');
1291         setorigin(e, self.origin);
1292         e.colormap = self.colormap;
1293
1294         waypoint_spawnforitem(self);
1295
1296         WaypointSprite_SpawnFixed(string_null, e.origin + '0 0 1' * e.maxs_z, self, sprite);
1297         WaypointSprite_UpdateRule(self.sprite, COLOR_TEAM2, SPRITERULE_TEAMPLAY);
1298
1299         onslaught_updatelinks();
1300
1301         self.reset = onslaught_controlpoint_reset;
1302 };
1303
1304 float onslaught_link_send(entity to, float sendflags)
1305 {
1306         WriteByte(MSG_ENTITY, ENT_CLIENT_RADARLINK);
1307         WriteByte(MSG_ENTITY, sendflags);
1308         if(sendflags & 1)
1309         {
1310                 WriteCoord(MSG_ENTITY, self.goalentity.origin_x);
1311                 WriteCoord(MSG_ENTITY, self.goalentity.origin_y);
1312                 WriteCoord(MSG_ENTITY, self.goalentity.origin_z);
1313         }
1314         if(sendflags & 2)
1315         {
1316                 WriteCoord(MSG_ENTITY, self.enemy.origin_x);
1317                 WriteCoord(MSG_ENTITY, self.enemy.origin_y);
1318                 WriteCoord(MSG_ENTITY, self.enemy.origin_z);
1319         }
1320         if(sendflags & 4)
1321         {
1322                 WriteByte(MSG_ENTITY, self.clientcolors); // which is goalentity's color + enemy's color * 16
1323         }
1324         return TRUE;
1325 }
1326
1327 void onslaught_link_checkupdate()
1328 {
1329         // TODO check if the two sides have moved (currently they won't move anyway)
1330         float redpower, bluepower;
1331
1332         redpower = bluepower = 0;
1333         if(self.goalentity.islinked)
1334         {
1335                 if(self.goalentity.team == COLOR_TEAM1)
1336                         redpower = 1;
1337                 else if(self.goalentity.team == COLOR_TEAM2)
1338                         bluepower = 1;
1339         }
1340         if(self.enemy.islinked)
1341         {
1342                 if(self.enemy.team == COLOR_TEAM1)
1343                         redpower = 2;
1344                 else if(self.enemy.team == COLOR_TEAM2)
1345                         bluepower = 2;
1346         }
1347
1348         float cc;
1349         if(redpower == 1 && bluepower == 2)
1350                 cc = (COLOR_TEAM1 - 1) * 0x01 + (COLOR_TEAM2 - 1) * 0x10;
1351         else if(redpower == 2 && bluepower == 1)
1352                 cc = (COLOR_TEAM1 - 1) * 0x10 + (COLOR_TEAM2 - 1) * 0x01;
1353         else if(redpower)
1354                 cc = (COLOR_TEAM1 - 1) * 0x11;
1355         else if(bluepower)
1356                 cc = (COLOR_TEAM2 - 1) * 0x11;
1357         else
1358                 cc = 0;
1359
1360         if(cc != self.clientcolors)
1361         {
1362                 self.clientcolors = cc;
1363                 self.SendFlags |= 4;
1364         }
1365
1366         self.nextthink = time;
1367 }
1368
1369 void onslaught_link_delayed()
1370 {
1371         self.goalentity = find(world, targetname, self.target);
1372         self.enemy = find(world, targetname, self.target2);
1373         if (!self.goalentity)
1374                 objerror("can not find target\n");
1375         if (!self.enemy)
1376                 objerror("can not find target2\n");
1377         dprint(etos(self.goalentity), " linked with ", etos(self.enemy), "\n");
1378         self.SendFlags |= 3;
1379         self.think = onslaught_link_checkupdate;
1380         self.nextthink = time;
1381 }
1382
1383 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
1384   Link between control points.
1385
1386   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.
1387
1388 keys:
1389 "target" - first control point.
1390 "target2" - second control point.
1391  */
1392 void spawnfunc_onslaught_link()
1393 {
1394         if (!g_onslaught)
1395         {
1396                 remove(self);
1397                 return;
1398         }
1399         if (self.target == "" || self.target2 == "")
1400                 objerror("target and target2 must be set\n");
1401         InitializeEntity(self, onslaught_link_delayed, INITPRIO_FINDTARGET);
1402         Net_LinkEntity(self, FALSE, 0, onslaught_link_send);
1403 };