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