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