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