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