]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/mode_onslaught.qc
Clean up/optimize racer code a bit. Make it use a simpler phys path when idle. Tweak...
[xonotic/xonotic-data.pk3dir.git] / 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         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         entity l, links;
78         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 float overtime_msg_time;
376 void onslaught_generator_think()
377 {
378         float d;
379         entity e;
380         self.nextthink = ceil(time + 1);
381         if (!gameover)
382         {
383                 if (autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60)
384                 {
385                         if (!overtime_msg_time)
386                         {
387                                 FOR_EACH_PLAYER(e)
388                                         centerprint(e, "^3Now playing ^1OVERTIME^3!\n^3Generators start now to self-damaging.\n^3The more control points your team holds,\n^3the more damage the enemy generator gets.");
389                                 overtime_msg_time = time;
390                         }
391                         // self.max_health / 300 gives 5 minutes of overtime.
392                         // control points reduce the overtime duration.
393                         sound(self, CH_TRIGGER, "onslaught/generator_decay.wav", VOL_BASE, ATTN_NORM);
394                         d = 1;
395                         e = findchain(classname, "onslaught_controlpoint");
396                         while (e)
397                         {
398                                 if (e.team != self.team)
399                                         if (e.islinked)
400                                                 d = d + 1;
401                                 e = e.chain;
402                         }
403                         if(autocvar_g_campaign && autocvar__campaign_testrun)
404                                 d = d * self.max_health;
405                         else
406                                 d = d * self.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
407                         Damage(self, self, self, d, DEATH_HURTTRIGGER, self.origin, '0 0 0');
408                 }
409                 else if (overtime_msg_time)
410                         overtime_msg_time = 0;
411         }
412 }
413
414 void onslaught_generator_ring_spawn(vector org)
415 {
416         modeleffect_spawn("models/onslaught/shockwavetransring.md3", 0, 0, org, '0 0 0', '0 0 0', '0 0 0', 0, -16, 0.1, 1.25, 0.25);
417 }
418
419 void onslaught_generator_ray_think()
420 {
421         self.nextthink = time + 0.05;
422         if(self.count > 10)
423         {
424                 self.think = SUB_Remove;
425                 return;
426         }
427
428         if(self.count > 5)
429                 self.alpha -= 0.1;
430         else
431                 self.alpha += 0.1;
432
433         self.scale += 0.2;
434         self.count +=1;
435 }
436
437 void onslaught_generator_ray_spawn(vector org)
438 {
439         entity e;
440         e = spawn();
441         setmodel(e, "models/onslaught/ons_ray.md3");
442         setorigin(e, org);
443         e.angles = randomvec() * 360;
444         e.alpha = 0;
445         e.scale = random() * 5 + 8;
446         e.think = onslaught_generator_ray_think;
447         e.nextthink = time + 0.05;
448 }
449
450 void onslaught_generator_shockwave_spawn(vector org)
451 {
452         shockwave_spawn("models/onslaught/shockwave.md3", org, -64, 0.75, 0.5);
453 }
454
455 void onslaught_generator_damage_think()
456 {
457         if(self.owner.health < 0)
458         {
459                 self.think = SUB_Remove;
460                 return;
461         }
462         self.nextthink = time+0.1;
463
464         // damaged fx (less probable the more damaged is the generator)
465         if(random() < 0.9 - self.owner.health / self.owner.max_health)
466                 if(random() < 0.01)
467                 {
468                         pointparticles(particleeffectnum("electro_ballexplode"), self.origin + randompos('-50 -50 -20', '50 50 50'), '0 0 0', 1);
469                         sound(self, CH_TRIGGER, "onslaught/electricity_explode.wav", VOL_BASE, ATTN_NORM);
470                 }
471                 else
472                         pointparticles(particleeffectnum("torch_small"), self.origin + randompos('-60 -60 -20', '60 60 60'), '0 0 0', 1);
473 }
474
475 void onslaught_generator_damage_spawn(entity gd_owner)
476 {
477         entity e;
478         e = spawn();
479         e.owner = gd_owner;
480         e.health = self.owner.health;
481         setorigin(e, gd_owner.origin);
482         e.think = onslaught_generator_damage_think;
483         e.nextthink = time+1;
484 }
485
486 void onslaught_generator_deaththink()
487 {
488         vector org;
489         float i;
490
491         if not (self.count)
492                 self.count = 40;
493
494         // White shockwave
495         if(self.count==40||self.count==20)
496         {
497                 onslaught_generator_ring_spawn(self.origin);
498                 sound(self, CH_TRIGGER, "onslaught/shockwave.wav", VOL_BASE, ATTN_NORM);
499         }
500
501         // Throw some gibs
502         if(random() < 0.3)
503         {
504                 i = random();
505                 if(i < 0.3)
506                         ons_throwgib(self.origin + '0 0 40', (100 * randomvec() - '1 1 1') * 11 + '0 0 20', "models/onslaught/gen_gib1.md3", 6, TRUE);
507                 else if(i > 0.7)
508                         ons_throwgib(self.origin + '0 0 40', (100 * randomvec() - '1 1 1') * 12 + '0 0 20', "models/onslaught/gen_gib2.md3", 6, TRUE);
509                 else
510                         ons_throwgib(self.origin + '0 0 40', (100 * randomvec() - '1 1 1') * 13 + '0 0 20', "models/onslaught/gen_gib3.md3", 6, TRUE);
511         }
512
513         // Spawn fire balls
514         for(i=0;i < 10;++i)
515         {
516                 org = self.origin + randompos('-30 -30 -30' * i + '0 0 -20', '30 30 30' * i + '0 0 20');
517                 pointparticles(particleeffectnum("onslaught_generator_gib_explode"), org, '0 0 0', 1);
518         }
519
520         // Short explosion sound + small explosion
521         if(random() < 0.25)
522         {
523                 te_explosion(self.origin);
524                 sound(self, CH_TRIGGER, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
525         }
526
527         // Particles
528         org = self.origin + randompos(self.mins + '8 8 8', self.maxs + '-8 -8 -8');
529         pointparticles(particleeffectnum("onslaught_generator_smallexplosion"), org, '0 0 0', 1);
530
531         // rays
532         if(random() > 0.25 )
533         {
534                 onslaught_generator_ray_spawn(self.origin);
535         }
536
537         // Final explosion
538         if(self.count==1)
539         {
540                 org = self.origin;
541                 te_explosion(org);
542                 onslaught_generator_shockwave_spawn(org);
543                 pointparticles(particleeffectnum("onslaught_generator_finalexplosion"), org, '0 0 0', 1);
544                 sound(self, CH_TRIGGER, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
545         }
546         else
547                 self.nextthink = time + 0.05;
548
549         self.count = self.count - 1;
550 }
551
552 void onslaught_generator_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
553 {
554         float i;
555         if (damage <= 0)
556                 return;
557         if(inWarmupStage)
558                 return;
559         if (attacker != self)
560         {
561                 if (self.isshielded)
562                 {
563                         // this is protected by a shield, so ignore the damage
564                         if (time > self.pain_finished)
565                                 if (attacker.classname == "player")
566                                 {
567                                         play2(attacker, "onslaught/damageblockedbyshield.wav");
568                                         self.pain_finished = time + 1;
569                                 }
570                         return;
571                 }
572                 if (time > self.pain_finished)
573                 {
574                         self.pain_finished = time + 10;
575                         bprint(ColoredTeamName(self.team), " generator under attack!\n");
576                         play2team(self.team, "onslaught/generator_underattack.wav");
577                 }
578         }
579         self.health = self.health - damage;
580         WaypointSprite_UpdateHealth(self.sprite, self.health);
581         // choose an animation frame based on health
582         self.frame = 10 * bound(0, (1 - self.health / self.max_health), 1);
583         // see if the generator is still functional, or dying
584         if (self.health > 0)
585         {
586 #ifdef ONSLAUGHT_SPAM
587                 float h, lh;
588                 lh = ceil(self.lasthealth / 100) * 100;
589                 h = ceil(self.health / 100) * 100;
590                 if(lh != h)
591                         bprint(ColoredTeamName(self.team), " generator has less than ", ftos(h), " health remaining\n");
592 #endif
593                 self.lasthealth = self.health;
594         }
595         else if not(inWarmupStage)
596         {
597                 if (attacker == self)
598                         bprint(ColoredTeamName(self.team), " generator spontaneously exploded due to overtime!\n");
599                 else
600                 {
601                         string t;
602                         t = ColoredTeamName(attacker.team);
603                         bprint(ColoredTeamName(self.team), " generator destroyed by ", t, "!\n");
604                 }
605                 self.iscaptured = FALSE;
606                 self.islinked = FALSE;
607                 self.isshielded = FALSE;
608                 self.takedamage = DAMAGE_NO; // can't be hurt anymore
609                 self.event_damage = SUB_Null; // won't do anything if hurt
610                 self.count = 0; // reset counter
611                 self.think = onslaught_generator_deaththink; // explosion sequence
612                 self.nextthink = time; // start exploding immediately
613                 self.think(); // do the first explosion now
614
615                 WaypointSprite_UpdateMaxHealth(self.sprite, 0);
616
617                 onslaught_updatelinks();
618         }
619
620         if(self.health <= 0)
621                 setmodel(self, "models/onslaught/generator_dead.md3");
622         else if(self.health < self.max_health * 0.10)
623                 setmodel(self, "models/onslaught/generator_dmg9.md3");
624         else if(self.health < self.max_health * 0.20)
625                 setmodel(self, "models/onslaught/generator_dmg8.md3");
626         else if(self.health < self.max_health * 0.30)
627                 setmodel(self, "models/onslaught/generator_dmg7.md3");
628         else if(self.health < self.max_health * 0.40)
629                 setmodel(self, "models/onslaught/generator_dmg6.md3");
630         else if(self.health < self.max_health * 0.50)
631                 setmodel(self, "models/onslaught/generator_dmg5.md3");
632         else if(self.health < self.max_health * 0.60)
633                 setmodel(self, "models/onslaught/generator_dmg4.md3");
634         else if(self.health < self.max_health * 0.70)
635                 setmodel(self, "models/onslaught/generator_dmg3.md3");
636         else if(self.health < self.max_health * 0.80)
637                 setmodel(self, "models/onslaught/generator_dmg2.md3");
638         else if(self.health < self.max_health * 0.90)
639                 setmodel(self, "models/onslaught/generator_dmg1.md3");
640         setsize(self, '-52 -52 -14', '52 52 75');
641
642         // Throw some flaming gibs on damage, more damage = more chance for gib
643         if(random() < damage/220)
644         {
645                 sound(self, CH_TRIGGER, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
646                 i = random();
647                 if(i < 0.3)
648                         ons_throwgib(hitloc + '0 0 20', force * -1, "models/onslaught/gen_gib1.md3", 5, TRUE);
649                 else if(i > 0.7)
650                         ons_throwgib(hitloc + '0 0 20', force * -1, "models/onslaught/gen_gib2.md3", 5, TRUE);
651                 else
652                         ons_throwgib(hitloc + '0 0 20', force * -1, "models/onslaught/gen_gib3.md3", 5, TRUE);
653         }
654         else
655         {
656                 // particles on every hit
657                 pointparticles(particleeffectnum("sparks"), hitloc, force * -1, 1);
658
659                 //sound on every hit
660                 if (random() < 0.5)
661                         sound(self, CH_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE, ATTN_NORM);
662                 else
663                         sound(self, CH_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE, ATTN_NORM);
664         }
665
666         //throw some gibs on damage
667         if(random() < damage/200+0.2)
668                 if(random() < 0.5)
669                         ons_throwgib(hitloc + '0 0 20', randomvec()*360, "models/onslaught/gen_gib1.md3", 5, FALSE);
670 }
671
672 // update links after a delay
673 void onslaught_generator_delayed()
674 {
675         onslaught_updatelinks();
676         // now begin normal thinking
677         self.think = onslaught_generator_think;
678         self.nextthink = time;
679 }
680
681 string onslaught_generator_waypointsprite_for_team(entity e, float t)
682 {
683         if(t == e.team)
684         {
685                 if(e.team == COLOR_TEAM1)
686                         return "ons-gen-red";
687                 else if(e.team == COLOR_TEAM2)
688                         return "ons-gen-blue";
689         }
690         if(e.isshielded)
691                 return "ons-gen-shielded";
692         if(e.team == COLOR_TEAM1)
693                 return "ons-gen-red";
694         else if(e.team == COLOR_TEAM2)
695                 return "ons-gen-blue";
696         return "";
697 }
698
699 void onslaught_generator_updatesprite(entity e)
700 {
701         string s1, s2, s3;
702         s1 = onslaught_generator_waypointsprite_for_team(e, COLOR_TEAM1);
703         s2 = onslaught_generator_waypointsprite_for_team(e, COLOR_TEAM2);
704         s3 = onslaught_generator_waypointsprite_for_team(e, -1);
705         WaypointSprite_UpdateSprites(e.sprite, s1, s2, s3);
706
707         if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
708         {
709                 e.lastteam = e.team + 2;
710                 e.lastshielded = e.isshielded;
711                 if(e.lastshielded)
712                 {
713                         if(e.team == COLOR_TEAM1 || e.team == COLOR_TEAM2)
714                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, FALSE));
715                         else
716                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
717                 }
718                 else
719                 {
720                         if(e.team == COLOR_TEAM1 || e.team == COLOR_TEAM2)
721                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, FALSE));
722                         else
723                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
724                 }
725                 WaypointSprite_Ping(e.sprite);
726         }
727 }
728
729 string onslaught_controlpoint_waypointsprite_for_team(entity e, float t)
730 {
731         float a;
732         if(t != -1)
733         {
734                 a = onslaught_controlpoint_attackable(e, t);
735                 if(a == 3 || a == 4) // ATTACK/TOUCH THIS ONE NOW
736                 {
737                         if(e.team == COLOR_TEAM1)
738                                 return "ons-cp-atck-red";
739                         else if(e.team == COLOR_TEAM2)
740                                 return "ons-cp-atck-blue";
741                         else
742                                 return "ons-cp-atck-neut";
743                 }
744                 else if(a == -2) // DEFEND THIS ONE NOW
745                 {
746                         if(e.team == COLOR_TEAM1)
747                                 return "ons-cp-dfnd-red";
748                         else if(e.team == COLOR_TEAM2)
749                                 return "ons-cp-dfnd-blue";
750                 }
751                 else if(e.team == t || a == -1 || a == 1) // own point, or fire at it
752                 {
753                         if(e.team == COLOR_TEAM1)
754                                 return "ons-cp-red";
755                         else if(e.team == COLOR_TEAM2)
756                                 return "ons-cp-blue";
757                 }
758                 else if(a == 2) // touch it
759                         return "ons-cp-neut";
760         }
761         else
762         {
763                 if(e.team == COLOR_TEAM1)
764                         return "ons-cp-red";
765                 else if(e.team == COLOR_TEAM2)
766                         return "ons-cp-blue";
767                 else
768                         return "ons-cp-neut";
769         }
770         return "";
771 }
772
773 void onslaught_controlpoint_updatesprite(entity e)
774 {
775         string s1, s2, s3;
776         s1 = onslaught_controlpoint_waypointsprite_for_team(e, COLOR_TEAM1);
777         s2 = onslaught_controlpoint_waypointsprite_for_team(e, COLOR_TEAM2);
778         s3 = onslaught_controlpoint_waypointsprite_for_team(e, -1);
779         WaypointSprite_UpdateSprites(e.sprite, s1, s2, s3);
780
781         float sh;
782         sh = !(onslaught_controlpoint_can_be_linked(e, COLOR_TEAM1) || onslaught_controlpoint_can_be_linked(e, COLOR_TEAM2));
783
784         if(e.lastteam != e.team + 2 || e.lastshielded != sh || e.iscaptured != e.lastcaptured)
785         {
786                 if(e.iscaptured) // don't mess up build bars!
787                 {
788                         if(sh)
789                         {
790                                 WaypointSprite_UpdateMaxHealth(e.sprite, 0);
791                         }
792                         else
793                         {
794                                 WaypointSprite_UpdateMaxHealth(e.sprite, e.goalentity.max_health);
795                                 WaypointSprite_UpdateHealth(e.sprite, e.goalentity.health);
796                         }
797                 }
798                 if(e.lastshielded)
799                 {
800                         if(e.team == COLOR_TEAM1 || e.team == COLOR_TEAM2)
801                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, FALSE));
802                         else
803                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
804                 }
805                 else
806                 {
807                         if(e.team == COLOR_TEAM1 || e.team == COLOR_TEAM2)
808                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, FALSE));
809                         else
810                                 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
811                 }
812                 WaypointSprite_Ping(e.sprite);
813
814                 e.lastteam = e.team + 2;
815                 e.lastshielded = sh;
816                 e.lastcaptured = e.iscaptured;
817         }
818 }
819
820 void onslaught_generator_reset()
821 {
822         self.team = self.team_saved;
823         self.lasthealth = self.max_health = self.health = autocvar_g_onslaught_gen_health;
824         self.takedamage = DAMAGE_AIM;
825         self.bot_attack = TRUE;
826         self.iscaptured = TRUE;
827         self.islinked = TRUE;
828         self.isshielded = TRUE;
829         self.enemy.solid = SOLID_NOT;
830         self.think = onslaught_generator_delayed;
831         self.nextthink = time + 0.2;
832         setmodel(self, "models/onslaught/generator.md3");
833         setsize(self, '-52 -52 -14', '52 52 75');
834
835         WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
836         WaypointSprite_UpdateHealth(self.sprite, self.health);
837 }
838
839 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
840   Base generator.
841
842   spawnfunc_onslaught_link entities can target this.
843
844 keys:
845 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
846 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
847  */
848 void spawnfunc_onslaught_generator()
849 {
850         if (!g_onslaught)
851         {
852                 remove(self);
853                 return;
854         }
855
856         entity e;
857         precache_model("models/onslaught/generator.md3");
858         precache_model("models/onslaught/generator_shield.md3");
859         precache_model("models/onslaught/generator_dmg1.md3");
860         precache_model("models/onslaught/generator_dmg2.md3");
861         precache_model("models/onslaught/generator_dmg3.md3");
862         precache_model("models/onslaught/generator_dmg4.md3");
863         precache_model("models/onslaught/generator_dmg5.md3");
864         precache_model("models/onslaught/generator_dmg6.md3");
865         precache_model("models/onslaught/generator_dmg7.md3");
866         precache_model("models/onslaught/generator_dmg8.md3");
867         precache_model("models/onslaught/generator_dmg9.md3");
868         precache_model("models/onslaught/generator_dead.md3");
869         precache_model("models/onslaught/shockwave.md3");
870         precache_model("models/onslaught/shockwavetransring.md3");
871         precache_model("models/onslaught/gen_gib1.md3");
872         precache_model("models/onslaught/gen_gib2.md3");
873         precache_model("models/onslaught/gen_gib3.md3");
874         precache_model("models/onslaught/ons_ray.md3");
875         precache_sound("onslaught/generator_decay.wav");
876         precache_sound("weapons/grenade_impact.wav");
877         precache_sound("weapons/rocket_impact.wav");
878         precache_sound("onslaught/generator_underattack.wav");
879         precache_sound("onslaught/shockwave.wav");
880         precache_sound("onslaught/ons_hit1.wav");
881         precache_sound("onslaught/ons_hit2.wav");
882         precache_sound("onslaught/electricity_explode.wav");
883         if (!self.team)
884                 objerror("team must be set");
885         self.team_saved = self.team;
886         self.colormap = 1024 + (self.team - 1) * 17;
887         self.solid = SOLID_BBOX;
888         self.movetype = MOVETYPE_NONE;
889         self.lasthealth = self.max_health = self.health = autocvar_g_onslaught_gen_health;
890         setmodel(self, "models/onslaught/generator.md3");
891         setsize(self, '-52 -52 -14', '52 52 75');
892         setorigin(self, self.origin);
893         self.takedamage = DAMAGE_AIM;
894         self.bot_attack = TRUE;
895         self.event_damage = onslaught_generator_damage;
896         self.iscaptured = TRUE;
897         self.islinked = TRUE;
898         self.isshielded = TRUE;
899         // helper entity that create fx when generator is damaged
900         onslaught_generator_damage_spawn(self);
901         // spawn shield model which indicates whether this can be damaged
902         self.enemy = e = spawn();
903         e.classname = "onslaught_generator_shield";
904         e.solid = SOLID_NOT;
905         e.movetype = MOVETYPE_NONE;
906         e.effects = EF_ADDITIVE;
907         setmodel(e, "models/onslaught/generator_shield.md3");
908         setorigin(e, self.origin);
909         e.colormap = self.colormap;
910         e.team = self.team;
911         self.think = onslaught_generator_delayed;
912         self.nextthink = time + 0.2;
913         InitializeEntity(self, onslaught_generator_delayed, INITPRIO_LAST);
914
915         WaypointSprite_SpawnFixed(string_null, e.origin + '0 0 1' * e.maxs_z, self, sprite, RADARICON_NONE, '0 0 0');
916         WaypointSprite_UpdateRule(self.sprite, COLOR_TEAM2, SPRITERULE_TEAMPLAY);
917         WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
918         WaypointSprite_UpdateHealth(self.sprite, self.health);
919
920         waypoint_spawnforitem(self);
921
922         onslaught_updatelinks();
923
924         self.reset = onslaught_generator_reset;
925 }
926
927 .float waslinked;
928 .float cp_bob_spd;
929 .vector cp_origin, cp_bob_origin, cp_bob_dmg;
930
931 float ons_notification_time_team1;
932 float ons_notification_time_team2;
933
934 void onslaught_controlpoint_icon_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
935 {
936         entity oself;
937         float nag;
938
939         if (damage <= 0)
940                 return;
941         if (self.owner.isshielded)
942         {
943                 // this is protected by a shield, so ignore the damage
944                 if (time > self.pain_finished)
945                         if (attacker.classname == "player")
946                         {
947                                 play2(attacker, "onslaught/damageblockedbyshield.wav");
948                                 self.pain_finished = time + 1;
949                         }
950                 return;
951         }
952
953         if (attacker.classname == "player")
954         {
955                 nag = FALSE;
956                 if(self.team == COLOR_TEAM1)
957                 {
958                         if(time - ons_notification_time_team1 > 10)
959                         {
960                                 nag = TRUE;
961                                 ons_notification_time_team1 = time;
962                         }
963                 }
964                 else if(self.team == COLOR_TEAM2)
965                 {
966                         if(time - ons_notification_time_team2 > 10)
967                         {
968                                 nag = TRUE;
969                                 ons_notification_time_team2 = time;
970                         }
971                 }
972                 else
973                         nag = TRUE;
974
975                 if(nag)
976                         play2team(self.team, "onslaught/controlpoint_underattack.wav");
977         }
978
979         self.health = self.health - damage;
980         if(self.owner.iscaptured)
981                 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
982         else
983                 WaypointSprite_UpdateBuildFinished(self.owner.sprite, time + (self.max_health - self.health) / (self.count / sys_frametime));
984         self.pain_finished = time + 1;
985         self.punchangle = (2 * randomvec() - '1 1 1') * 45;
986         self.cp_bob_dmg_z = (2 * random() - 1) * 15;
987         // colormod flash when shot
988         self.colormod = '2 2 2';
989         // particles on every hit
990         pointparticles(particleeffectnum("sparks"), hitloc, force*-1, 1);
991         //sound on every hit
992         if (random() < 0.5)
993                 sound(self, CH_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE+0.3, ATTN_NORM);
994         else
995                 sound(self, CH_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE+0.3, ATTN_NORM);
996
997         if (self.health < 0)
998         {
999                 sound(self, CH_TRIGGER, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
1000                 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
1001                 {
1002                         string t;
1003                         t = ColoredTeamName(attacker.team);
1004                         bprint(ColoredTeamName(self.team), " ", self.message, " control point destroyed by ", t, "\n");
1005                         ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 25, "models/onslaught/controlpoint_icon_gib1.md3", 3, FALSE);
1006                         ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 45, "models/onslaught/controlpoint_icon_gib2.md3", 3, FALSE);
1007                         ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 45, "models/onslaught/controlpoint_icon_gib2.md3", 3, FALSE);
1008                         ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 3, FALSE);
1009                         ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 3, FALSE);
1010                         ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 3, FALSE);
1011                         ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 3, FALSE);
1012                 }
1013                 self.owner.goalentity = world;
1014                 self.owner.islinked = FALSE;
1015                 self.owner.iscaptured = FALSE;
1016                 self.owner.team = 0;
1017                 self.owner.colormap = 1024;
1018
1019                 WaypointSprite_UpdateMaxHealth(self.owner.sprite, 0);
1020
1021                 onslaught_updatelinks();
1022
1023                 // Use targets now (somebody make sure this is in the right place..)
1024                 oself = self;
1025                 self = self.owner;
1026                 activator = self;
1027                 SUB_UseTargets ();
1028                 self = oself;
1029
1030
1031                 self.owner.waslinked = self.owner.islinked;
1032                 if(self.owner.model != "models/onslaught/controlpoint_pad.md3")
1033                         setmodel(self.owner, "models/onslaught/controlpoint_pad.md3");
1034                 //setsize(self, '-32 -32 0', '32 32 8');
1035
1036                 remove(self);
1037         }
1038 }
1039
1040 void onslaught_controlpoint_icon_think()
1041 {
1042         entity oself;
1043         self.nextthink = time + sys_frametime;
1044         if (time > self.pain_finished + 5)
1045         {
1046                 if(self.health < self.max_health)
1047                 {
1048                         self.health = self.health + self.count;
1049                         if (self.health >= self.max_health)
1050                                 self.health = self.max_health;
1051                         WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
1052                 }
1053         }
1054         if (self.health < self.max_health * 0.25)
1055                 setmodel(self, "models/onslaught/controlpoint_icon_dmg3.md3");
1056         else if (self.health < self.max_health * 0.50)
1057                 setmodel(self, "models/onslaught/controlpoint_icon_dmg2.md3");
1058         else if (self.health < self.max_health * 0.75)
1059                 setmodel(self, "models/onslaught/controlpoint_icon_dmg1.md3");
1060         else if (self.health < self.max_health * 0.90)
1061                 setmodel(self, "models/onslaught/controlpoint_icon.md3");
1062         // colormod flash when shot
1063         self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));
1064
1065         if(self.owner.islinked != self.owner.waslinked)
1066         {
1067                 // unteam the spawnpoint if needed
1068                 float t;
1069                 t = self.owner.team;
1070                 if(!self.owner.islinked)
1071                         self.owner.team = 0;
1072
1073                 oself = self;
1074                 self = self.owner;
1075                 activator = self;
1076                 SUB_UseTargets ();
1077                 self = oself;
1078
1079                 self.owner.team = t;
1080
1081                 self.owner.waslinked = self.owner.islinked;
1082         }
1083
1084         if (self.punchangle_x > 0)
1085         {
1086                 self.punchangle_x = self.punchangle_x - 60 * sys_frametime;
1087                 if (self.punchangle_x < 0)
1088                         self.punchangle_x = 0;
1089         }
1090         else if (self.punchangle_x < 0)
1091         {
1092                 self.punchangle_x = self.punchangle_x + 60 * sys_frametime;
1093                 if (self.punchangle_x > 0)
1094                         self.punchangle_x = 0;
1095         }
1096
1097         if (self.punchangle_y > 0)
1098         {
1099                 self.punchangle_y = self.punchangle_y - 60 * sys_frametime;
1100                 if (self.punchangle_y < 0)
1101                         self.punchangle_y = 0;
1102         }
1103         else if (self.punchangle_y < 0)
1104         {
1105                 self.punchangle_y = self.punchangle_y + 60 * sys_frametime;
1106                 if (self.punchangle_y > 0)
1107                         self.punchangle_y = 0;
1108         }
1109
1110         if (self.punchangle_z > 0)
1111         {
1112                 self.punchangle_z = self.punchangle_z - 60 * sys_frametime;
1113                 if (self.punchangle_z < 0)
1114                         self.punchangle_z = 0;
1115         }
1116         else if (self.punchangle_z < 0)
1117         {
1118                 self.punchangle_z = self.punchangle_z + 60 * sys_frametime;
1119                 if (self.punchangle_z > 0)
1120                         self.punchangle_z = 0;
1121         }
1122
1123         self.angles_x = self.punchangle_x;
1124         self.angles_y = self.punchangle_y + self.mangle_y;
1125         self.angles_z = self.punchangle_z;
1126         self.mangle_y = self.mangle_y + 45 * sys_frametime;
1127
1128         self.cp_bob_origin_z = 4 * PI * (1 - cos(self.cp_bob_spd));
1129         self.cp_bob_spd = self.cp_bob_spd + 1.875 * sys_frametime;
1130         if(self.cp_bob_dmg_z > 0)
1131                 self.cp_bob_dmg_z = self.cp_bob_dmg_z - 3 * sys_frametime;
1132         else
1133                 self.cp_bob_dmg_z = 0;
1134         setorigin(self,self.cp_origin + self.cp_bob_origin + self.cp_bob_dmg);
1135
1136         // damaged fx
1137         if(random() < 0.6 - self.health / self.max_health)
1138         {
1139                 pointparticles(particleeffectnum("electricity_sparks"), self.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
1140
1141                 if(random() > 0.8)
1142                         sound(self, CH_PAIN, "onslaught/ons_spark1.wav", VOL_BASE, ATTN_NORM);
1143                 else if (random() > 0.5)
1144                         sound(self, CH_PAIN, "onslaught/ons_spark2.wav", VOL_BASE, ATTN_NORM);
1145         }
1146 }
1147
1148 void onslaught_controlpoint_icon_buildthink()
1149 {
1150         entity oself;
1151         float a;
1152
1153         self.nextthink = time + sys_frametime;
1154
1155         // only do this if there is power
1156         a = onslaught_controlpoint_can_be_linked(self.owner, self.owner.team);
1157         if(!a)
1158                 return;
1159
1160         self.health = self.health + self.count;
1161
1162         if (self.health >= self.max_health)
1163         {
1164                 self.health = self.max_health;
1165                 self.count = autocvar_g_onslaught_cp_regen * sys_frametime; // slow repair rate from now on
1166                 self.think = onslaught_controlpoint_icon_think;
1167                 sound(self, CH_TRIGGER, "onslaught/controlpoint_built.wav", VOL_BASE, ATTN_NORM);
1168                 bprint(ColoredTeamName(self.team), " captured ", self.owner.message, " control point\n");
1169                 self.owner.iscaptured = TRUE;
1170
1171                 WaypointSprite_UpdateMaxHealth(self.owner.sprite, self.max_health);
1172                 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
1173
1174                 onslaught_updatelinks();
1175
1176                 // Use targets now (somebody make sure this is in the right place..)
1177                 oself = self;
1178                 self = self.owner;
1179                 activator = self;
1180                 SUB_UseTargets ();
1181                 self = oself;
1182                 self.cp_origin = self.origin;
1183                 self.cp_bob_origin = '0 0 0.1';
1184                 self.cp_bob_spd = 0;
1185         }
1186         self.alpha = self.health / self.max_health;
1187         // colormod flash when shot
1188         self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));
1189         if(self.owner.model != "models/onslaught/controlpoint_pad2.md3")
1190                 setmodel(self.owner, "models/onslaught/controlpoint_pad2.md3");
1191         //setsize(self, '-32 -32 0', '32 32 8');
1192
1193         if(random() < 0.9 - self.health / self.max_health)
1194                 pointparticles(particleeffectnum("rage"), self.origin + 10 * randomvec(), '0 0 -1', 1);
1195 }
1196
1197
1198
1199
1200 void onslaught_controlpoint_touch()
1201 {
1202         entity e;
1203         float a;
1204         if (other.classname != "player")
1205                 return;
1206         a = onslaught_controlpoint_attackable(self, other.team);
1207         if(a != 2 && a != 4)
1208                 return;
1209         // we've verified that this player has a legitimate claim to this point,
1210         // so start building the captured point icon (which only captures this
1211         // point if it successfully builds without being destroyed first)
1212         self.goalentity = e = spawn();
1213         e.classname = "onslaught_controlpoint_icon";
1214         e.owner = self;
1215         e.max_health = autocvar_g_onslaught_cp_health;
1216         e.health = autocvar_g_onslaught_cp_buildhealth;
1217         e.solid = SOLID_BBOX;
1218         e.movetype = MOVETYPE_NONE;
1219         setmodel(e, "models/onslaught/controlpoint_icon.md3");
1220         setsize(e, '-32 -32 -32', '32 32 32');
1221         setorigin(e, self.origin + '0 0 96');
1222         e.takedamage = DAMAGE_AIM;
1223         e.bot_attack = TRUE;
1224         e.event_damage = onslaught_controlpoint_icon_damage;
1225         e.team = other.team;
1226         e.colormap = 1024 + (e.team - 1) * 17;
1227         e.think = onslaught_controlpoint_icon_buildthink;
1228         e.nextthink = time + sys_frametime;
1229         e.count = (e.max_health - e.health) * sys_frametime / autocvar_g_onslaught_cp_buildtime; // how long it takes to build
1230         sound(e, CH_TRIGGER, "onslaught/controlpoint_build.wav", VOL_BASE, ATTN_NORM);
1231         self.team = e.team;
1232         self.colormap = e.colormap;
1233         WaypointSprite_UpdateBuildFinished(self.sprite, time + (e.max_health - e.health) / (e.count / sys_frametime));
1234         onslaught_updatelinks();
1235 }
1236
1237 void onslaught_controlpoint_reset()
1238 {
1239         if(self.goalentity && self.goalentity != world)
1240                 remove(self.goalentity);
1241         self.goalentity = world;
1242         self.team = 0;
1243         self.colormap = 1024;
1244         self.iscaptured = FALSE;
1245         self.islinked = FALSE;
1246         self.isshielded = TRUE;
1247         self.enemy.solid = SOLID_NOT;
1248         self.enemy.colormap = self.colormap;
1249         self.think = self.enemy.think = SUB_Null;
1250         self.nextthink = 0; // don't like SUB_Null :P
1251         setmodel(self, "models/onslaught/controlpoint_pad.md3");
1252         //setsize(self, '-32 -32 0', '32 32 8');
1253
1254         WaypointSprite_UpdateMaxHealth(self.sprite, 0);
1255
1256         onslaught_updatelinks();
1257
1258         activator = self;
1259         SUB_UseTargets(); // to reset the structures, playerspawns etc.
1260 }
1261
1262 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
1263   Control point. Be sure to give this enough clearance so that the shootable part has room to exist
1264
1265   This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
1266
1267 keys:
1268 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
1269 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
1270 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
1271  */
1272 void spawnfunc_onslaught_controlpoint()
1273 {
1274         entity e;
1275         if (!g_onslaught)
1276         {
1277                 remove(self);
1278                 return;
1279         }
1280         precache_model("models/onslaught/controlpoint_pad.md3");
1281         precache_model("models/onslaught/controlpoint_pad2.md3");
1282         precache_model("models/onslaught/controlpoint_shield.md3");
1283         precache_model("models/onslaught/controlpoint_icon.md3");
1284         precache_model("models/onslaught/controlpoint_icon_dmg1.md3");
1285         precache_model("models/onslaught/controlpoint_icon_dmg2.md3");
1286         precache_model("models/onslaught/controlpoint_icon_dmg3.md3");
1287         precache_model("models/onslaught/controlpoint_icon_gib1.md3");
1288         precache_model("models/onslaught/controlpoint_icon_gib2.md3");
1289         precache_model("models/onslaught/controlpoint_icon_gib4.md3");
1290         precache_sound("onslaught/controlpoint_build.wav");
1291         precache_sound("onslaught/controlpoint_built.wav");
1292         precache_sound("weapons/grenade_impact.wav");
1293         precache_sound("onslaught/damageblockedbyshield.wav");
1294         precache_sound("onslaught/controlpoint_underattack.wav");
1295         precache_sound("onslaught/ons_spark1.wav");
1296         precache_sound("onslaught/ons_spark2.wav");
1297         self.solid = SOLID_BBOX;
1298         self.movetype = MOVETYPE_NONE;
1299         setmodel(self, "models/onslaught/controlpoint_pad.md3");
1300         //setsize(self, '-32 -32 0', '32 32 8');
1301         setorigin(self, self.origin);
1302         self.touch = onslaught_controlpoint_touch;
1303         self.team = 0;
1304         self.colormap = 1024;
1305         self.iscaptured = FALSE;
1306         self.islinked = FALSE;
1307         self.isshielded = TRUE;
1308         // spawn shield model which indicates whether this can be damaged
1309         self.enemy = e = spawn();
1310         e.classname = "onslaught_controlpoint_shield";
1311         e.solid = SOLID_NOT;
1312         e.movetype = MOVETYPE_NONE;
1313         e.effects = EF_ADDITIVE;
1314         setmodel(e, "models/onslaught/controlpoint_shield.md3");
1315         //setsize(e, '-32 -32 0', '32 32 128');
1316         setorigin(e, self.origin);
1317         e.colormap = self.colormap;
1318
1319         waypoint_spawnforitem(self);
1320
1321         WaypointSprite_SpawnFixed(string_null, e.origin + '0 0 1' * e.maxs_z, self, sprite, RADARICON_NONE, '0 0 0');
1322         WaypointSprite_UpdateRule(self.sprite, COLOR_TEAM2, SPRITERULE_TEAMPLAY);
1323
1324         onslaught_updatelinks();
1325
1326         self.reset = onslaught_controlpoint_reset;
1327 }
1328
1329 float onslaught_link_send(entity to, float sendflags)
1330 {
1331         WriteByte(MSG_ENTITY, ENT_CLIENT_RADARLINK);
1332         WriteByte(MSG_ENTITY, sendflags);
1333         if(sendflags & 1)
1334         {
1335                 WriteCoord(MSG_ENTITY, self.goalentity.origin_x);
1336                 WriteCoord(MSG_ENTITY, self.goalentity.origin_y);
1337                 WriteCoord(MSG_ENTITY, self.goalentity.origin_z);
1338         }
1339         if(sendflags & 2)
1340         {
1341                 WriteCoord(MSG_ENTITY, self.enemy.origin_x);
1342                 WriteCoord(MSG_ENTITY, self.enemy.origin_y);
1343                 WriteCoord(MSG_ENTITY, self.enemy.origin_z);
1344         }
1345         if(sendflags & 4)
1346         {
1347                 WriteByte(MSG_ENTITY, self.clientcolors); // which is goalentity's color + enemy's color * 16
1348         }
1349         return TRUE;
1350 }
1351
1352 void onslaught_link_checkupdate()
1353 {
1354         // TODO check if the two sides have moved (currently they won't move anyway)
1355         float redpower, bluepower;
1356
1357         redpower = bluepower = 0;
1358         if(self.goalentity.islinked)
1359         {
1360                 if(self.goalentity.team == COLOR_TEAM1)
1361                         redpower = 1;
1362                 else if(self.goalentity.team == COLOR_TEAM2)
1363                         bluepower = 1;
1364         }
1365         if(self.enemy.islinked)
1366         {
1367                 if(self.enemy.team == COLOR_TEAM1)
1368                         redpower = 2;
1369                 else if(self.enemy.team == COLOR_TEAM2)
1370                         bluepower = 2;
1371         }
1372
1373         float cc;
1374         if(redpower == 1 && bluepower == 2)
1375                 cc = (COLOR_TEAM1 - 1) * 0x01 + (COLOR_TEAM2 - 1) * 0x10;
1376         else if(redpower == 2 && bluepower == 1)
1377                 cc = (COLOR_TEAM1 - 1) * 0x10 + (COLOR_TEAM2 - 1) * 0x01;
1378         else if(redpower)
1379                 cc = (COLOR_TEAM1 - 1) * 0x11;
1380         else if(bluepower)
1381                 cc = (COLOR_TEAM2 - 1) * 0x11;
1382         else
1383                 cc = 0;
1384
1385         //print(etos(self), " rp=", ftos(redpower), " bp=", ftos(bluepower), " ");
1386         //print("cc=", ftos(cc), "\n");
1387
1388         if(cc != self.clientcolors)
1389         {
1390                 self.clientcolors = cc;
1391                 self.SendFlags |= 4;
1392         }
1393
1394         self.nextthink = time;
1395 }
1396
1397 void onslaught_link_delayed()
1398 {
1399         self.goalentity = find(world, targetname, self.target);
1400         self.enemy = find(world, targetname, self.target2);
1401         if (!self.goalentity)
1402                 objerror("can not find target\n");
1403         if (!self.enemy)
1404                 objerror("can not find target2\n");
1405         dprint(etos(self.goalentity), " linked with ", etos(self.enemy), "\n");
1406         self.SendFlags |= 3;
1407         self.think = onslaught_link_checkupdate;
1408         self.nextthink = time;
1409 }
1410
1411 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
1412   Link between control points.
1413
1414   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.
1415
1416 keys:
1417 "target" - first control point.
1418 "target2" - second control point.
1419  */
1420 void spawnfunc_onslaught_link()
1421 {
1422         if (!g_onslaught)
1423         {
1424                 remove(self);
1425                 return;
1426         }
1427         if (self.target == "" || self.target2 == "")
1428                 objerror("target and target2 must be set\n");
1429         InitializeEntity(self, onslaught_link_delayed, INITPRIO_FINDTARGET);
1430         Net_LinkEntity(self, FALSE, 0, onslaught_link_send);
1431 }