Onslaught: use the new waypoint sprites! But I don't like them yet... need to get...
[divverent/nexuiz.git] / data / qcsrc / server / mode_onslaught.qc
1 .entity sprite;
2 .string target2;
3 .float iscaptured;
4 .float islinked;
5 .float isgenneighbor_red;
6 .float isgenneighbor_blue;
7 .float iscpneighbor_red;
8 .float iscpneighbor_blue;
9 .float isshielded;
10 .float lasthealth;
11
12 float ons_sprite_cp_red, ons_sprite_cp_blue, ons_sprite_cp_neut;
13 float ons_sprite_cp_atck_red, ons_sprite_cp_atck_blue, ons_sprite_cp_atck_neut;
14 float ons_sprite_gen_red, ons_sprite_gen_blue, ons_sprite_gen_shielded;
15
16 void() onslaught_updatelinks =
17 {
18         local entity l, links;
19         local float stop, t1, t2, t3, t4;
20         // first check if the game has ended
21         dprint("--- updatelinks ---\n");
22         links = findchain(classname, "onslaught_link");
23         // mark generators as being shielded and networked
24         l = findchain(classname, "onslaught_generator");
25         while (l)
26         {
27                 if (l.iscaptured)
28                         dprint(etos(l), " (generator) belongs to team ", ftos(l.team), "\n");
29                 else
30                         dprint(etos(l), " (generator) is destroyed\n");
31                 l.islinked = l.iscaptured;
32                 l.isshielded = l.iscaptured;
33                 l = l.chain;
34         }
35         // mark points as shielded and not networked
36         l = findchain(classname, "onslaught_controlpoint");
37         while (l)
38         {
39                 l.islinked = FALSE;
40                 l.isshielded = TRUE;
41                 l.isgenneighbor_red = FALSE;
42                 l.isgenneighbor_blue = FALSE;
43                 l.iscpneighbor_red = FALSE;
44                 l.iscpneighbor_blue = FALSE;
45                 dprint(etos(l), " (point) belongs to team ", ftos(l.team), "\n");
46                 l = l.chain;
47         }
48         // flow power outward from the generators through the network
49         l = links;
50         while (l)
51         {
52                 dprint(etos(l), " (link) connects ", etos(l.goalentity), " with ", etos(l.enemy), "\n");
53                 l = l.chain;
54         }
55         stop = FALSE;
56         while (!stop)
57         {
58                 stop = TRUE;
59                 l = links;
60                 while (l)
61                 {
62                         // if both points are captured by the same team, and only one of
63                         // them is powered, mark the other one as powered as well
64                         if (l.enemy.iscaptured && l.goalentity.iscaptured)
65                         if (l.enemy.islinked != l.goalentity.islinked)
66                         if (l.enemy.team == l.goalentity.team)
67                         {
68                                 if (!l.goalentity.islinked)
69                                 {
70                                         stop = FALSE;
71                                         l.goalentity.islinked = TRUE;
72                                         dprint(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)\n");
73                                 }
74                                 else if (!l.enemy.islinked)
75                                 {
76                                         stop = FALSE;
77                                         l.enemy.islinked = TRUE;
78                                         dprint(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)\n");
79                                 }
80                         }
81                         l = l.chain;
82                 }
83         }
84         // now that we know which points are powered we can mark their neighbors
85         // as unshielded if team differs
86         l = links;
87         while (l)
88         {
89                 if (l.goalentity.team != l.enemy.team)
90                 {
91                         if (l.goalentity.islinked)
92                         {
93                                 dprint(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)\n");
94                                 l.enemy.isshielded = FALSE;
95                                 if(l.goalentity.classname == "onslaught_generator")
96                                 {
97                                         if(l.goalentity.team == COLOR_TEAM1)
98                                                 l.enemy.isgenneighbor_red = TRUE;
99                                         else if(l.goalentity.team == COLOR_TEAM2)
100                                                 l.enemy.isgenneighbor_blue = TRUE;
101                                 }
102                                 else
103                                 {
104                                         if(l.goalentity.team == COLOR_TEAM1)
105                                                 l.enemy.iscpneighbor_red = TRUE;
106                                         else if(l.goalentity.team == COLOR_TEAM2)
107                                                 l.enemy.iscpneighbor_blue = TRUE;
108                                 }
109                         }
110                         if (l.enemy.islinked)
111                         {
112                                 dprint(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)\n");
113                                 l.goalentity.isshielded = FALSE;
114                                 if(l.enemy.classname == "onslaught_generator")
115                                 {
116                                         if(l.enemy.team == COLOR_TEAM1)
117                                                 l.goalentity.isgenneighbor_red = TRUE;
118                                         else if(l.enemy.team == COLOR_TEAM2)
119                                                 l.goalentity.isgenneighbor_blue = TRUE;
120                                 }
121                                 else
122                                 {
123                                         if(l.enemy.team == COLOR_TEAM1)
124                                                 l.goalentity.iscpneighbor_red = TRUE;
125                                         else if(l.enemy.team == COLOR_TEAM2)
126                                                 l.goalentity.iscpneighbor_blue = TRUE;
127                                 }
128                         }
129                 }
130                 l = l.chain;
131         }
132         // now update the takedamage and alpha variables on generator shields
133         l = findchain(classname, "onslaught_generator");
134         while (l)
135         {
136                 if (l.isshielded)
137                 {
138                         dprint(etos(l), " (generator) is shielded\n");
139                         l.enemy.alpha = 1;
140                         l.takedamage = DAMAGE_NO;
141                         l.bot_attack = FALSE;
142                 }
143                 else
144                 {
145                         dprint(etos(l), " (generator) is not shielded\n");
146                         l.enemy.alpha = -1;
147                         l.takedamage = DAMAGE_AIM;
148                         l.bot_attack = TRUE;
149                 }
150                 l = l.chain;
151         }
152         // now update the takedamage and alpha variables on control point icons
153         l = findchain(classname, "onslaught_controlpoint");
154         while (l)
155         {
156                 if (l.isshielded)
157                 {
158                         dprint(etos(l), " (point) is shielded\n");
159                         l.enemy.alpha = 1;
160                         if (l.goalentity)
161                         {
162                                 l.goalentity.takedamage = DAMAGE_NO;
163                                 l.goalentity.bot_attack = FALSE;
164                         }
165                 }
166                 else
167                 {
168                         dprint(etos(l), " (point) is not shielded\n");
169                         l.enemy.alpha = -1;
170                         if (l.goalentity)
171                         {
172                                 l.goalentity.takedamage = DAMAGE_AIM;
173                                 l.goalentity.bot_attack = TRUE;
174                         }
175                 }
176                 l = l.chain;
177         }
178         // count generators owned by each team
179         t1 = t2 = t3 = t4 = 0;
180         l = findchain(classname, "onslaught_generator");
181         while (l)
182         {
183                 if (l.iscaptured)
184                 {
185                         if (l.team == COLOR_TEAM1) t1 = 1;
186                         if (l.team == COLOR_TEAM2) t2 = 1;
187                         if (l.team == COLOR_TEAM3) t3 = 1;
188                         if (l.team == COLOR_TEAM4) t4 = 1;
189                 }
190                 l = l.chain;
191         }
192         // see if multiple teams remain (if not, it's game over)
193         if (t1 + t2 + t3 + t4 < 2)
194                 dprint("--- game over ---\n");
195         else
196                 dprint("--- done updating links ---\n");
197 };
198
199 float onslaught_controlpoint_can_be_linked(entity cp, float t)
200 {
201         if(t == COLOR_TEAM1)
202         {
203                 if(cp.isgenneighbor_red)
204                         return 2;
205                 if(cp.iscpneighbor_red)
206                         return 1;
207         }
208         else if(t == COLOR_TEAM2)
209         {
210                 if(cp.isgenneighbor_blue)
211                         return 2;
212                 if(cp.iscpneighbor_blue)
213                         return 1;
214         }
215         return 0;
216 /*
217         entity e;
218         // check to see if this player has a legitimate claim to capture this
219         // control point - more specifically that there is a captured path of
220         // points leading back to the team generator
221         e = findchain(classname, "onslaught_link");
222         while (e)
223         {
224                 if (e.goalentity == cp)
225                 {
226                         dprint(etos(e), " (link) connects to ", etos(e.enemy), " (point)");
227                         if (e.enemy.islinked)
228                         {
229                                 dprint(" which is linked");
230                                 if (e.enemy.team == t)
231                                 {
232                                         dprint(" and has the correct team!\n");
233                                         return 1;
234                                 }
235                                 else
236                                         dprint(" but has the wrong team\n");
237                         }
238                         else
239                                 dprint("\n");
240                 }
241                 else if (e.enemy == cp)
242                 {
243                         dprint(etos(e), " (link) connects to ", etos(e.goalentity), " (point)");
244                         if (e.goalentity.islinked)
245                         {
246                                 dprint(" which is linked");
247                                 if (e.goalentity.team == t)
248                                 {
249                                         dprint(" and has a team!\n");
250                                         return 1;
251                                 }
252                                 else
253                                         dprint(" but has the wrong team\n");
254                         }
255                         else
256                                 dprint("\n");
257                 }
258                 e = e.chain;
259         }
260         return 0;
261 */
262 }
263
264 float onslaught_controlpoint_attackable(entity cp, float t)
265 // -1: SAME TEAM!
266 // 0:  off limits
267 // 1:  attack it
268 // 2:  touch it
269 // 3:  attack it (HIGH PRIO)
270 // 4:  touch it (HIGH PRIO)
271 {
272         float a;
273
274         if(cp.isshielded)
275         {
276                 return 0;
277         }
278         else if(cp.goalentity)
279         {
280                 // if there's already an icon built, nothing happens
281                 if(cp.team == t)
282                         return -1;
283                 // we know it can be linked, so no need to check
284                 // but...
285                 a = onslaught_controlpoint_can_be_linked(cp, t);
286                 if(a == 2) // near our generator?
287                         return 3; // EMERGENCY!
288                 return 1;
289         }
290         else
291         {
292                 // free point
293                 if(onslaught_controlpoint_can_be_linked(cp, t))
294                 {
295                         a = onslaught_controlpoint_can_be_linked(cp, COLOR_TEAM1 + COLOR_TEAM2 - t);
296                         if(a == 2)
297                                 return 4; // GET THIS ONE NOW!
298                         else
299                                 return 2; // TOUCH ME
300                 }
301         }
302         return 0;
303 }
304
305 void() onslaught_generator_think =
306 {
307         local float d;
308         local entity e;
309         self.nextthink = ceil(time + 1);
310         if (cvar("timelimit"))
311         if (time > cvar("timelimit") * 60 - 60)
312         {
313                 // self.max_health / 300 gives 5 minutes of overtime.
314                 // control points reduce the overtime duration.
315                 sound(self, CHAN_AUTO, "sound/onslaught/generator_decay.wav", 1, ATTN_NORM);
316                 d = 1;
317                 e = findchain(classname, "onslaught_controlpoint");
318                 while (e)
319                 {
320                         if (e.team != self.team)
321                         if (e.islinked)
322                                 d = d + 1;
323                         e = e.chain;
324                 }
325                 d = d * self.max_health / 300;
326                 Damage(self, self, self, d, DEATH_HURTTRIGGER, self.origin, '0 0 0');
327         }
328 };
329
330 void() onslaught_generator_deaththink =
331 {
332         local vector org;
333         if (self.count > 0)
334         {
335                 self.nextthink = time + 0.1;
336                 self.count = self.count - 1;
337                 org = randompos(self.origin + self.mins + '8 8 8', self.origin + self.maxs + '-8 -8 -8');
338                 pointparticles(particleeffectnum("onslaught_generator_smallexplosion"), org, '0 0 0', 1);
339                 sound(self, CHAN_AUTO, "sound/weapons/grenade_impact.wav", 1, ATTN_NORM);
340         }
341         else
342         {
343                 org = self.origin;
344                 pointparticles(particleeffectnum("onslaught_generator_finalexplosion"), org, '0 0 0', 1);
345                 sound(self, CHAN_AUTO, "sound/weapons/rocket_impact.wav", 1, ATTN_NORM);
346         }
347 };
348
349 void(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force) onslaught_generator_damage =
350 {
351         if (damage <= 0)
352                 return;
353         if (attacker != self)
354         {
355                 if (self.isshielded)
356                 {
357                         // this is protected by a shield, so ignore the damage
358                         if (time > self.pain_finished)
359                         if (attacker.classname == "player")
360                         {
361                                 play2(attacker, "sound/onslaught/damageblockedbyshield.wav");
362                                 self.pain_finished = time + 1;
363                         }
364                         return;
365                 }
366                 if (time > self.pain_finished)
367                 {
368                         self.pain_finished = time + 5;
369                         bprint(ColoredTeamName(self.team), " generator under attack!\n");
370                         play2team(self.team, "sound/onslaught/generator_underattack.wav");
371                 }
372         }
373         self.health = self.health - damage;
374         // choose an animation frame based on health
375         self.frame = 10 * bound(0, (1 - self.health / self.max_health), 1);
376         // see if the generator is still functional, or dying
377         if (self.health > 0)
378         {
379                 float h, lh;
380                 lh = ceil(self.lasthealth / 100) * 100;
381                 h = ceil(self.health / 100) * 100;
382                 if(lh != h)
383                         bprint(ColoredTeamName(self.team), " generator has less than ", ftos(h), " health remaining\n");
384                 self.lasthealth = self.health;
385         }
386         else
387         {
388                 if (attacker == self)
389                         bprint(ColoredTeamName(self.team), " generator spontaneously exploded due to overtime!\n");
390                 else
391                 {
392                         string t;
393                         t = ColoredTeamName(attacker.team);
394                         bprint(ColoredTeamName(self.team), " generator destroyed by ", t, "!\n");
395                 }
396                 self.iscaptured = FALSE;
397                 self.islinked = FALSE;
398                 self.isshielded = FALSE;
399                 self.takedamage = DAMAGE_NO; // can't be hurt anymore
400                 self.event_damage = SUB_Null; // won't do anything if hurt
401                 self.count = 30; // 30 explosions
402                 self.think = onslaught_generator_deaththink; // explosion sequence
403                 self.nextthink = time; // start exploding immediately
404                 self.think(); // do the first explosion now
405                 onslaught_updatelinks();
406         }
407 };
408
409 // update links after a delay
410 void() onslaught_generator_delayed =
411 {
412         onslaught_updatelinks();
413         // now begin normal thinking
414         self.think = onslaught_generator_think;
415         self.nextthink = time;
416 };
417
418 float onslaught_generator_waypointsprite_for_player(entity e)
419 {
420         if(e.classname == "player")
421                 if(e.team == self.owner.team)
422                 {
423                         if(self.owner.team == COLOR_TEAM1)
424                                 return ons_sprite_gen_red;
425                         else if(self.owner.team == COLOR_TEAM2)
426                                 return ons_sprite_gen_blue;
427                 }
428         if(self.owner.isshielded)
429                 return ons_sprite_gen_shielded;
430         if(self.owner.team == COLOR_TEAM1)
431                 return ons_sprite_gen_red;
432         else if(self.owner.team == COLOR_TEAM2)
433                 return ons_sprite_gen_blue;
434         return 0;
435 }
436
437 float onslaught_controlpoint_waypointsprite_for_player(entity e)
438 {
439         float a;
440         if(e.classname == "player")
441         {
442                 a = onslaught_controlpoint_attackable(self.owner, e.team);
443                 if(a == 3 || a == 4) // ATTACK/TOUCH THIS ONE NOW
444                 {
445                         if(self.owner.team == COLOR_TEAM1)
446                                 return ons_sprite_cp_atck_red;
447                         else if(self.owner.team == COLOR_TEAM2)
448                                 return ons_sprite_cp_atck_blue;
449                         else
450                                 return ons_sprite_cp_atck_neut;
451                 }
452                 else if(self.owner.team == e.team || a == -1 || a == 1) // own point, or fire at it
453                 {
454                         if(self.owner.team == COLOR_TEAM1)
455                                 return ons_sprite_cp_red;
456                         else if(self.owner.team == COLOR_TEAM2)
457                                 return ons_sprite_cp_blue;
458                 }
459                 else if(a == 2) // touch it
460                         return ons_sprite_cp_neut;
461         }
462         else
463         {
464                 if(self.owner.team == COLOR_TEAM1)
465                         return ons_sprite_cp_red;
466                 else if(self.owner.team == COLOR_TEAM2)
467                         return ons_sprite_cp_blue;
468                 else
469                         return ons_sprite_cp_neut;
470         }
471         return 0;
472 }
473
474 /*QUAKED onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
475 Base generator.
476
477 onslaught_link entities can target this.
478
479 keys:
480 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
481 "targetname" - name that onslaught_link entities will use to target this.
482 */
483 void() onslaught_generator =
484 {
485         if (!g_onslaught)
486         {
487                 remove(self);
488                 return;
489         }
490
491         if(!ons_sprite_cp_blue)
492         {
493                 precache_model("models/sprites/ons-cp-blue.sp2");
494                 setmodel(self, "models/sprites/ons-cp-blue.sp2");
495                 ons_sprite_cp_blue = self.modelindex;
496                 precache_model("models/sprites/ons-cp-red.sp2");
497                 setmodel(self, "models/sprites/ons-cp-red.sp2");
498                 ons_sprite_cp_red = self.modelindex;
499                 precache_model("models/sprites/ons-cp-neut.sp2");
500                 setmodel(self, "models/sprites/ons-cp-neut.sp2");
501                 ons_sprite_cp_neut = self.modelindex;
502                 precache_model("models/sprites/ons-cp-atck-blue.sp2");
503                 setmodel(self, "models/sprites/ons-cp-atck-blue.sp2");
504                 ons_sprite_cp_atck_blue = self.modelindex;
505                 precache_model("models/sprites/ons-cp-atck-red.sp2");
506                 setmodel(self, "models/sprites/ons-cp-atck-red.sp2");
507                 ons_sprite_cp_atck_red = self.modelindex;
508                 precache_model("models/sprites/ons-cp-atck-neut.sp2");
509                 setmodel(self, "models/sprites/ons-cp-atck-neut.sp2");
510                 ons_sprite_cp_atck_neut = self.modelindex;
511                 precache_model("models/sprites/ons-gen-blue.sp2");
512                 setmodel(self, "models/sprites/ons-gen-blue.sp2");
513                 ons_sprite_gen_blue = self.modelindex;
514                 precache_model("models/sprites/ons-gen-red.sp2");
515                 setmodel(self, "models/sprites/ons-gen-red.sp2");
516                 ons_sprite_gen_red = self.modelindex;
517                 precache_model("models/sprites/ons-gen-shielded.sp2");
518                 setmodel(self, "models/sprites/ons-gen-shielded.sp2");
519                 ons_sprite_gen_shielded = self.modelindex;
520         }
521
522         local entity e;
523         precache_model("models/onslaught/generator.md3");
524         precache_model("models/onslaught/generator_shield.md3");
525         precache_sound("sound/onslaught/generator_decay.wav");
526         precache_sound("sound/weapons/grenade_impact.wav");
527         precache_sound("sound/weapons/rocket_impact.wav");
528         precache_sound("sound/onslaught/generator_underattack.wav");
529         if (!self.team)
530                 objerror("team must be set");
531         self.colormap = 1024 + (self.team - 1) * 17;
532         self.solid = SOLID_BSP;
533         self.movetype = MOVETYPE_NONE;
534         self.lasthealth = self.max_health = self.health = 3000;
535         setmodel(self, "models/onslaught/generator.md3");
536         //setsize(self, '-32 -32 -24', '32 32 64');
537         setorigin(self, self.origin);
538         self.takedamage = DAMAGE_AIM;
539         self.bot_attack = TRUE;
540         self.event_damage = onslaught_generator_damage;
541         self.iscaptured = TRUE;
542         self.islinked = TRUE;
543         self.isshielded = TRUE;
544         // spawn shield model which indicates whether this can be damaged
545         self.enemy = e = spawn();
546         e.solid = SOLID_NOT;
547         e.movetype = MOVETYPE_NONE;
548         e.effects = EF_ADDITIVE;
549         setmodel(e, "models/onslaught/generator_shield.md3");
550         //setsize(e, '-32 -32 0', '32 32 128');
551         setorigin(e, self.origin);
552         e.colormap = self.colormap;
553         e.team = self.team;
554         self.think = onslaught_generator_delayed;
555         self.nextthink = time + 0.2;
556
557         WaypointSprite_SpawnFixed(string_null, e.origin + '0 0 1' * e.maxs_z, self, sprite);
558         self.sprite.waypointsprite_for_player = onslaught_generator_waypointsprite_for_player;
559 };
560
561 void(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force) onslaught_controlpoint_icon_damage =
562 {
563         entity oself;
564         if (damage <= 0)
565                 return;
566         if (self.owner.isshielded)
567         {
568                 // this is protected by a shield, so ignore the damage
569                 if (time > self.pain_finished)
570                 if (attacker.classname == "player")
571                 {
572                         play2(attacker, "sound/onslaught/damageblockedbyshield.wav");
573                         self.pain_finished = time + 1;
574                 }
575                 return;
576         }
577         if (time > self.pain_finished)
578         if (attacker.classname == "player")
579         {
580                 play2team(self.team, "sound/onslaught/controlpoint_underattack.wav");
581                 self.pain_finished = time + 5;
582         }
583         self.health = self.health - damage;
584         self.alpha = self.health / self.max_health;
585         self.pain_finished = time + 1;
586         // colormod flash when shot
587         self.colormod = '2 2 2';
588         if (self.health < 0)
589         {
590                 sound(self, CHAN_AUTO, "sound/weapons/grenade_impact.wav", 1, ATTN_NORM);
591                 pointparticles(particleeffectnum("onslaught_controlpoint_explosion"), self.origin, '0 0 0', 1);
592                 {
593                         string t;
594                         t = ColoredTeamName(attacker.team);
595                         bprint(ColoredTeamName(self.team), " ", self.message, " control point destroyed by ", t, "\n");
596                 }
597                 self.owner.goalentity = world;
598                 self.owner.islinked = FALSE;
599                 self.owner.iscaptured = FALSE;
600                 self.owner.team = 0;
601                 self.owner.colormap = 1024;
602                 onslaught_updatelinks();
603
604                 // Use targets now (somebody make sure this is in the right place..)
605                 oself = self;
606                 self = self.owner;
607                 activator = self.owner;
608                 SUB_UseTargets ();
609                 self = oself;
610
611                 remove(self);
612         }
613 };
614
615 void() onslaught_controlpoint_icon_think =
616 {
617         self.nextthink = time + 0.1;
618         if (time > self.pain_finished + 1)
619         {
620                 self.health = self.health + self.count;
621                 if (self.health >= self.max_health)
622                         self.health = self.max_health;
623         }
624         self.alpha = self.health / self.max_health;
625         // colormod flash when shot
626         self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));
627 };
628
629 void() onslaught_controlpoint_icon_buildthink =
630 {
631         local entity oself;
632
633         self.nextthink = time + 0.1;
634         self.health = self.health + self.count;
635         if (self.health >= self.max_health)
636         {
637                 self.health = self.max_health;
638                 self.count = self.count * 0.2; // slow repair rate from now on
639                 self.think = onslaught_controlpoint_icon_think;
640                 sound(self, CHAN_BODY, "sound/onslaught/controlpoint_built.wav", 1, ATTN_NORM);
641                 bprint(ColoredTeamName(self.team), " captured ", self.owner.message, " control point\n");
642                 self.owner.iscaptured = TRUE;
643                 onslaught_updatelinks();
644
645                 // Use targets now (somebody make sure this is in the right place..)
646                 oself = self;
647                 self = self.owner;
648                 activator = self;
649                 SUB_UseTargets ();
650                 self = oself;
651         }
652         self.alpha = self.health / self.max_health;
653         // colormod flash when shot
654         self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));
655 };
656
657 void() onslaught_controlpoint_touch =
658 {
659         local entity e;
660         float a;
661         if (other.classname != "player")
662                 return;
663         a = onslaught_controlpoint_attackable(self, other.team);
664         if(a != 2 && a != 4)
665                 return;
666         // we've verified that this player has a legitimate claim to this point,
667         // so start building the captured point icon (which only captures this
668         // point if it successfully builds without being destroyed first)
669         self.goalentity = e = spawn();
670         e.owner = self;
671         e.max_health = 1000;
672         e.health = e.max_health * 0.1;
673         e.alpha = e.health / e.max_health;
674         e.solid = SOLID_BBOX;
675         e.movetype = MOVETYPE_NONE;
676         setmodel(e, "models/onslaught/controlpoint_icon.md3");
677         setsize(e, '-32 -32 -32', '32 32 32');
678         setorigin(e, self.origin + '0 0 96');
679         e.takedamage = DAMAGE_AIM;
680         e.bot_attack = TRUE;
681         e.event_damage = onslaught_controlpoint_icon_damage;
682         e.team = other.team;
683         e.colormap = 1024 + (e.team - 1) * 17;
684         e.think = onslaught_controlpoint_icon_buildthink;
685         e.nextthink = time + 0.1;
686         e.count = e.max_health / 50; // how long it takes to build
687         sound(e, CHAN_BODY, "sound/onslaught/controlpoint_build.wav", 1, ATTN_NORM);
688         self.team = e.team;
689         self.colormap = e.colormap;
690 };
691
692 /*QUAKED onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
693 Control point.  Be sure to give this enough clearance so that the shootable part has room to exist
694
695 This should link to an onslaught_controlpoint entity or onslaught_generator entity.
696
697 keys:
698 "targetname" - name that onslaught_link entities will use to target this.
699 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
700 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
701 */
702 void() onslaught_controlpoint =
703 {
704         local entity e;
705         if (!g_onslaught)
706         {
707                 remove(self);
708                 return;
709         }
710         precache_model("models/onslaught/controlpoint_pad.md3");
711         precache_model("models/onslaught/controlpoint_shield.md3");
712         precache_model("models/onslaught/controlpoint_icon.md3");
713         precache_sound("sound/onslaught/controlpoint_build.wav");
714         precache_sound("sound/onslaught/controlpoint_built.wav");
715         precache_sound("sound/weapons/grenade_impact.wav");
716         precache_sound("sound/onslaught/damageblockedbyshield.wav");
717         precache_sound("sound/onslaught/controlpoint_underattack.wav");
718         self.solid = SOLID_BSP;
719         self.movetype = MOVETYPE_NONE;
720         setmodel(self, "models/onslaught/controlpoint_pad.md3");
721         //setsize(self, '-32 -32 0', '32 32 8');
722         setorigin(self, self.origin);
723         self.touch = onslaught_controlpoint_touch;
724         self.team = 0;
725         self.colormap = 1024;
726         self.iscaptured = FALSE;
727         self.islinked = FALSE;
728         self.isshielded = TRUE;
729         // spawn shield model which indicates whether this can be damaged
730         self.enemy = e = spawn();
731         e.solid = SOLID_NOT;
732         e.movetype = MOVETYPE_NONE;
733         e.effects = EF_ADDITIVE;
734         setmodel(e, "models/onslaught/controlpoint_shield.md3");
735         //setsize(e, '-32 -32 0', '32 32 128');
736         setorigin(e, self.origin);
737         e.colormap = self.colormap;
738         onslaught_updatelinks();
739
740         WaypointSprite_SpawnFixed(string_null, e.origin + '0 0 1' * e.maxs_z, self, sprite);
741         self.sprite.waypointsprite_for_player = onslaught_controlpoint_waypointsprite_for_player;
742 };
743
744 void() onslaught_link_delayed =
745 {
746         self.goalentity = find(world, targetname, self.target);
747         self.enemy = find(world, targetname, self.target2);
748         if (!self.goalentity)
749                 objerror("can not find target\n");
750         if (!self.enemy)
751                 objerror("can not find target2\n");
752         dprint(etos(self.goalentity), " linked with ", etos(self.enemy), "\n");
753 }
754
755 /*QUAKED onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
756 Link between control points.
757
758 This entity targets two different onslaught_controlpoint or onslaught_generator entities, and suppresses shielding on both if they are owned by different teams.
759
760 keys:
761 "target" - first control point.
762 "target2" - second control point.
763 */
764 void() onslaught_link =
765 {
766         if (!g_onslaught)
767         {
768                 remove(self);
769                 return;
770         }
771         if (self.target == "" || self.target2 == "")
772                 objerror("target and target2 must be set\n");
773         self.think = onslaught_link_delayed;
774         self.nextthink = time + 0.1;
775 };