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