5 .float isgenneighbor_red;
6 .float isgenneighbor_blue;
7 .float iscpneighbor_red;
8 .float iscpneighbor_blue;
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;
17 void() onslaught_updatelinks =
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");
29 dprint(etos(l), " (generator) belongs to team ", ftos(l.team), "\n");
31 dprint(etos(l), " (generator) is destroyed\n");
32 l.islinked = l.iscaptured;
33 l.isshielded = l.iscaptured;
36 // mark points as shielded and not networked
37 l = findchain(classname, "onslaught_controlpoint");
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");
49 // flow power outward from the generators through the network
53 dprint(etos(l), " (link) connects ", etos(l.goalentity), " with ", etos(l.enemy), "\n");
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)
69 if (!l.goalentity.islinked)
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");
75 else if (!l.enemy.islinked)
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");
85 // now that we know which points are powered we can mark their neighbors
86 // as unshielded if team differs
90 if (l.goalentity.team != l.enemy.team)
92 if (l.goalentity.islinked)
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")
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;
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;
111 if (l.enemy.islinked)
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")
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;
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;
133 // now update the takedamage and alpha variables on generator shields
134 l = findchain(classname, "onslaught_generator");
139 dprint(etos(l), " (generator) is shielded\n");
141 l.takedamage = DAMAGE_NO;
142 l.bot_attack = FALSE;
146 dprint(etos(l), " (generator) is not shielded\n");
148 l.takedamage = DAMAGE_AIM;
153 // now update the takedamage and alpha variables on control point icons
154 l = findchain(classname, "onslaught_controlpoint");
159 dprint(etos(l), " (point) is shielded\n");
163 l.goalentity.takedamage = DAMAGE_NO;
164 l.goalentity.bot_attack = FALSE;
169 dprint(etos(l), " (point) is not shielded\n");
173 l.goalentity.takedamage = DAMAGE_AIM;
174 l.goalentity.bot_attack = TRUE;
179 // count generators owned by each team
180 t1 = t2 = t3 = t4 = 0;
181 l = findchain(classname, "onslaught_generator");
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;
193 // see if multiple teams remain (if not, it's game over)
194 if (t1 + t2 + t3 + t4 < 2)
195 dprint("--- game over ---\n");
197 dprint("--- done updating links ---\n");
200 float onslaught_controlpoint_can_be_linked(entity cp, float t)
204 if(cp.isgenneighbor_red)
206 if(cp.iscpneighbor_red)
209 else if(t == COLOR_TEAM2)
211 if(cp.isgenneighbor_blue)
213 if(cp.iscpneighbor_blue)
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");
225 if (e.goalentity == cp)
227 dprint(etos(e), " (link) connects to ", etos(e.enemy), " (point)");
228 if (e.enemy.islinked)
230 dprint(" which is linked");
231 if (e.enemy.team == t)
233 dprint(" and has the correct team!\n");
237 dprint(" but has the wrong team\n");
242 else if (e.enemy == cp)
244 dprint(etos(e), " (link) connects to ", etos(e.goalentity), " (point)");
245 if (e.goalentity.islinked)
247 dprint(" which is linked");
248 if (e.goalentity.team == t)
250 dprint(" and has a team!\n");
254 dprint(" but has the wrong team\n");
265 float onslaught_controlpoint_attackable(entity cp, float t)
266 // -2: SAME TEAM, attackable by enemy!
271 // 3: attack it (HIGH PRIO)
272 // 4: touch it (HIGH PRIO)
280 else if(cp.goalentity)
282 // if there's already an icon built, nothing happens
285 a = onslaught_controlpoint_can_be_linked(cp, COLOR_TEAM1 + COLOR_TEAM2 - t);
286 if(a) // attackable by enemy?
287 return -2; // EMERGENCY!
290 // we know it can be linked, so no need to check
292 a = onslaught_controlpoint_can_be_linked(cp, t);
293 if(a == 2) // near our generator?
294 return 3; // EMERGENCY!
300 if(onslaught_controlpoint_can_be_linked(cp, t))
302 a = onslaught_controlpoint_can_be_linked(cp, COLOR_TEAM1 + COLOR_TEAM2 - t);
304 return 4; // GET THIS ONE NOW!
306 return 2; // TOUCH ME
312 void() onslaught_generator_think =
316 self.nextthink = ceil(time + 1);
317 if (cvar("timelimit"))
318 if (time > cvar("timelimit") * 60 - 60)
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);
324 e = findchain(classname, "onslaught_controlpoint");
327 if (e.team != self.team)
332 d = d * self.max_health / 300;
333 Damage(self, self, self, d, DEATH_HURTTRIGGER, self.origin, '0 0 0');
337 void() onslaught_generator_deaththink =
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);
351 pointparticles(particleeffectnum("onslaught_generator_finalexplosion"), org, '0 0 0', 1);
352 sound(self, CHAN_AUTO, "sound/weapons/rocket_impact.wav", 1, ATTN_NORM);
356 void(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force) onslaught_generator_damage =
360 if (attacker != self)
364 // this is protected by a shield, so ignore the damage
365 if (time > self.pain_finished)
366 if (attacker.classname == "player")
368 play2(attacker, "sound/onslaught/damageblockedbyshield.wav");
369 self.pain_finished = time + 1;
373 if (time > self.pain_finished)
375 self.pain_finished = time + 5;
376 bprint(ColoredTeamName(self.team), " generator under attack!\n");
377 play2team(self.team, "sound/onslaught/generator_underattack.wav");
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
387 lh = ceil(self.lasthealth / 100) * 100;
388 h = ceil(self.health / 100) * 100;
390 bprint(ColoredTeamName(self.team), " generator has less than ", ftos(h), " health remaining\n");
391 self.lasthealth = self.health;
395 if (attacker == self)
396 bprint(ColoredTeamName(self.team), " generator spontaneously exploded due to overtime!\n");
400 t = ColoredTeamName(attacker.team);
401 bprint(ColoredTeamName(self.team), " generator destroyed by ", t, "!\n");
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();
416 // update links after a delay
417 void() onslaught_generator_delayed =
419 onslaught_updatelinks();
420 // now begin normal thinking
421 self.think = onslaught_generator_think;
422 self.nextthink = time;
425 float onslaught_generator_waypointsprite_for_player(entity e)
427 if(e.classname == "player")
428 if(e.team == self.owner.team)
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;
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;
444 float onslaught_controlpoint_waypointsprite_for_player(entity e)
447 if(e.classname == "player")
449 a = onslaught_controlpoint_attackable(self.owner, e.team);
450 if(a == 3 || a == 4) // ATTACK/TOUCH THIS ONE NOW
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;
457 return ons_sprite_cp_atck_neut;
459 else if(a == -2) // DEFEND THIS ONE NOW
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;
466 else if(self.owner.team == e.team || a == -1 || a == 1) // own point, or fire at it
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;
473 else if(a == 2) // touch it
474 return ons_sprite_cp_neut;
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;
483 return ons_sprite_cp_neut;
488 /*QUAKED onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
491 onslaught_link entities can target this.
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.
497 void() onslaught_generator =
505 if(!ons_sprite_cp_blue)
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;
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");
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 = 3000;
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();
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;
574 self.think = onslaught_generator_delayed;
575 self.nextthink = time + 0.2;
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;
581 void(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force) onslaught_controlpoint_icon_damage =
586 if (self.owner.isshielded)
588 // this is protected by a shield, so ignore the damage
589 if (time > self.pain_finished)
590 if (attacker.classname == "player")
592 play2(attacker, "sound/onslaught/damageblockedbyshield.wav");
593 self.pain_finished = time + 1;
597 if (time > self.pain_finished)
598 if (attacker.classname == "player")
600 play2team(self.team, "sound/onslaught/controlpoint_underattack.wav");
601 self.pain_finished = time + 5;
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';
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);
614 t = ColoredTeamName(attacker.team);
615 bprint(ColoredTeamName(self.team), " ", self.message, " control point destroyed by ", t, "\n");
617 self.owner.goalentity = world;
618 self.owner.islinked = FALSE;
619 self.owner.iscaptured = FALSE;
621 self.owner.colormap = 1024;
622 onslaught_updatelinks();
624 // Use targets now (somebody make sure this is in the right place..)
627 activator = self.owner;
635 void() onslaught_controlpoint_icon_think =
637 self.nextthink = time + 0.1;
638 if (time > self.pain_finished + 1)
640 self.health = self.health + self.count;
641 if (self.health >= self.max_health)
642 self.health = self.max_health;
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));
649 void() onslaught_controlpoint_icon_buildthink =
653 self.nextthink = time + 0.1;
654 self.health = self.health + self.count;
655 if (self.health >= self.max_health)
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();
665 // Use targets now (somebody make sure this is in the right place..)
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));
677 void() onslaught_controlpoint_touch =
681 if (other.classname != "player")
683 a = onslaught_controlpoint_attackable(self, other.team);
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();
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;
701 e.event_damage = onslaught_controlpoint_icon_damage;
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);
709 self.colormap = e.colormap;
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
715 This should link to an onslaught_controlpoint entity or onslaught_generator entity.
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)
722 void() onslaught_controlpoint =
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;
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();
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();
760 WaypointSprite_SpawnFixed(string_null, e.origin + '0 0 1' * e.maxs_z, self, sprite);
761 self.sprite.waypointsprite_for_player = onslaught_controlpoint_waypointsprite_for_player;
764 void() onslaught_link_delayed =
766 self.goalentity = find(world, targetname, self.target);
767 self.enemy = find(world, targetname, self.target2);
768 if (!self.goalentity)
769 objerror("can not find target\n");
771 objerror("can not find target2\n");
772 dprint(etos(self.goalentity), " linked with ", etos(self.enemy), "\n");
775 /*QUAKED onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
776 Link between control points.
778 This entity targets two different onslaught_controlpoint or onslaught_generator entities, and suppresses shielding on both if they are owned by different teams.
781 "target" - first control point.
782 "target2" - second control point.
784 void() onslaught_link =
791 if (self.target == "" || self.target2 == "")
792 objerror("target and target2 must be set\n");
793 self.think = onslaught_link_delayed;
794 self.nextthink = time + 0.1;