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