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_gen_red, ons_sprite_gen_blue, ons_sprite_gen_shielded;
16 void() onslaught_updatelinks =
18 local entity l, links;
19 local float stop, t1, t2, t3, t4;
20 // first check if the game has ended
21 dprint("--- updatelinks ---\n");
22 links = findchain(classname, "onslaught_link");
23 // mark generators as being shielded and networked
24 l = findchain(classname, "onslaught_generator");
28 dprint(etos(l), " (generator) belongs to team ", ftos(l.team), "\n");
30 dprint(etos(l), " (generator) is destroyed\n");
31 l.islinked = l.iscaptured;
32 l.isshielded = l.iscaptured;
35 // mark points as shielded and not networked
36 l = findchain(classname, "onslaught_controlpoint");
41 l.isgenneighbor_red = FALSE;
42 l.isgenneighbor_blue = FALSE;
43 l.iscpneighbor_red = FALSE;
44 l.iscpneighbor_blue = FALSE;
45 dprint(etos(l), " (point) belongs to team ", ftos(l.team), "\n");
48 // flow power outward from the generators through the network
52 dprint(etos(l), " (link) connects ", etos(l.goalentity), " with ", etos(l.enemy), "\n");
62 // if both points are captured by the same team, and only one of
63 // them is powered, mark the other one as powered as well
64 if (l.enemy.iscaptured && l.goalentity.iscaptured)
65 if (l.enemy.islinked != l.goalentity.islinked)
66 if (l.enemy.team == l.goalentity.team)
68 if (!l.goalentity.islinked)
71 l.goalentity.islinked = TRUE;
72 dprint(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)\n");
74 else if (!l.enemy.islinked)
77 l.enemy.islinked = TRUE;
78 dprint(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)\n");
84 // now that we know which points are powered we can mark their neighbors
85 // as unshielded if team differs
89 if (l.goalentity.team != l.enemy.team)
91 if (l.goalentity.islinked)
93 dprint(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)\n");
94 l.enemy.isshielded = FALSE;
95 if(l.goalentity.classname == "onslaught_generator")
97 if(l.goalentity.team == COLOR_TEAM1)
98 l.enemy.isgenneighbor_red = TRUE;
99 else if(l.goalentity.team == COLOR_TEAM2)
100 l.enemy.isgenneighbor_blue = TRUE;
104 if(l.goalentity.team == COLOR_TEAM1)
105 l.enemy.iscpneighbor_red = TRUE;
106 else if(l.goalentity.team == COLOR_TEAM2)
107 l.enemy.iscpneighbor_blue = TRUE;
110 if (l.enemy.islinked)
112 dprint(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)\n");
113 l.goalentity.isshielded = FALSE;
114 if(l.enemy.classname == "onslaught_generator")
116 if(l.enemy.team == COLOR_TEAM1)
117 l.goalentity.isgenneighbor_red = TRUE;
118 else if(l.enemy.team == COLOR_TEAM2)
119 l.goalentity.isgenneighbor_blue = TRUE;
123 if(l.enemy.team == COLOR_TEAM1)
124 l.goalentity.iscpneighbor_red = TRUE;
125 else if(l.enemy.team == COLOR_TEAM2)
126 l.goalentity.iscpneighbor_blue = TRUE;
132 // now update the takedamage and alpha variables on generator shields
133 l = findchain(classname, "onslaught_generator");
138 dprint(etos(l), " (generator) is shielded\n");
140 l.takedamage = DAMAGE_NO;
141 l.bot_attack = FALSE;
145 dprint(etos(l), " (generator) is not shielded\n");
147 l.takedamage = DAMAGE_AIM;
152 // now update the takedamage and alpha variables on control point icons
153 l = findchain(classname, "onslaught_controlpoint");
158 dprint(etos(l), " (point) is shielded\n");
162 l.goalentity.takedamage = DAMAGE_NO;
163 l.goalentity.bot_attack = FALSE;
168 dprint(etos(l), " (point) is not shielded\n");
172 l.goalentity.takedamage = DAMAGE_AIM;
173 l.goalentity.bot_attack = TRUE;
178 // count generators owned by each team
179 t1 = t2 = t3 = t4 = 0;
180 l = findchain(classname, "onslaught_generator");
185 if (l.team == COLOR_TEAM1) t1 = 1;
186 if (l.team == COLOR_TEAM2) t2 = 1;
187 if (l.team == COLOR_TEAM3) t3 = 1;
188 if (l.team == COLOR_TEAM4) t4 = 1;
192 // see if multiple teams remain (if not, it's game over)
193 if (t1 + t2 + t3 + t4 < 2)
194 dprint("--- game over ---\n");
196 dprint("--- done updating links ---\n");
199 float onslaught_controlpoint_can_be_linked(entity cp, float t)
203 if(cp.isgenneighbor_red)
205 if(cp.iscpneighbor_red)
208 else if(t == COLOR_TEAM2)
210 if(cp.isgenneighbor_blue)
212 if(cp.iscpneighbor_blue)
218 // check to see if this player has a legitimate claim to capture this
219 // control point - more specifically that there is a captured path of
220 // points leading back to the team generator
221 e = findchain(classname, "onslaught_link");
224 if (e.goalentity == cp)
226 dprint(etos(e), " (link) connects to ", etos(e.enemy), " (point)");
227 if (e.enemy.islinked)
229 dprint(" which is linked");
230 if (e.enemy.team == t)
232 dprint(" and has the correct team!\n");
236 dprint(" but has the wrong team\n");
241 else if (e.enemy == cp)
243 dprint(etos(e), " (link) connects to ", etos(e.goalentity), " (point)");
244 if (e.goalentity.islinked)
246 dprint(" which is linked");
247 if (e.goalentity.team == t)
249 dprint(" and has a team!\n");
253 dprint(" but has the wrong team\n");
264 float onslaught_controlpoint_attackable(entity cp, float t)
269 // 3: attack it (HIGH PRIO)
270 // 4: touch it (HIGH PRIO)
278 else if(cp.goalentity)
280 // if there's already an icon built, nothing happens
283 // we know it can be linked, so no need to check
285 a = onslaught_controlpoint_can_be_linked(cp, t);
286 if(a == 2) // near our generator?
287 return 3; // EMERGENCY!
293 if(onslaught_controlpoint_can_be_linked(cp, t))
295 a = onslaught_controlpoint_can_be_linked(cp, COLOR_TEAM1 + COLOR_TEAM2 - t);
297 return 4; // GET THIS ONE NOW!
299 return 2; // TOUCH ME
305 void() onslaught_generator_think =
309 self.nextthink = ceil(time + 1);
310 if (cvar("timelimit"))
311 if (time > cvar("timelimit") * 60 - 60)
313 // self.max_health / 300 gives 5 minutes of overtime.
314 // control points reduce the overtime duration.
315 sound(self, CHAN_AUTO, "sound/onslaught/generator_decay.wav", 1, ATTN_NORM);
317 e = findchain(classname, "onslaught_controlpoint");
320 if (e.team != self.team)
325 d = d * self.max_health / 300;
326 Damage(self, self, self, d, DEATH_HURTTRIGGER, self.origin, '0 0 0');
330 void() onslaught_generator_deaththink =
335 self.nextthink = time + 0.1;
336 self.count = self.count - 1;
337 org = randompos(self.origin + self.mins + '8 8 8', self.origin + self.maxs + '-8 -8 -8');
338 pointparticles(particleeffectnum("onslaught_generator_smallexplosion"), org, '0 0 0', 1);
339 sound(self, CHAN_AUTO, "sound/weapons/grenade_impact.wav", 1, ATTN_NORM);
344 pointparticles(particleeffectnum("onslaught_generator_finalexplosion"), org, '0 0 0', 1);
345 sound(self, CHAN_AUTO, "sound/weapons/rocket_impact.wav", 1, ATTN_NORM);
349 void(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force) onslaught_generator_damage =
353 if (attacker != self)
357 // this is protected by a shield, so ignore the damage
358 if (time > self.pain_finished)
359 if (attacker.classname == "player")
361 play2(attacker, "sound/onslaught/damageblockedbyshield.wav");
362 self.pain_finished = time + 1;
366 if (time > self.pain_finished)
368 self.pain_finished = time + 5;
369 bprint(ColoredTeamName(self.team), " generator under attack!\n");
370 play2team(self.team, "sound/onslaught/generator_underattack.wav");
373 self.health = self.health - damage;
374 // choose an animation frame based on health
375 self.frame = 10 * bound(0, (1 - self.health / self.max_health), 1);
376 // see if the generator is still functional, or dying
380 lh = ceil(self.lasthealth / 100) * 100;
381 h = ceil(self.health / 100) * 100;
383 bprint(ColoredTeamName(self.team), " generator has less than ", ftos(h), " health remaining\n");
384 self.lasthealth = self.health;
388 if (attacker == self)
389 bprint(ColoredTeamName(self.team), " generator spontaneously exploded due to overtime!\n");
393 t = ColoredTeamName(attacker.team);
394 bprint(ColoredTeamName(self.team), " generator destroyed by ", t, "!\n");
396 self.iscaptured = FALSE;
397 self.islinked = FALSE;
398 self.isshielded = FALSE;
399 self.takedamage = DAMAGE_NO; // can't be hurt anymore
400 self.event_damage = SUB_Null; // won't do anything if hurt
401 self.count = 30; // 30 explosions
402 self.think = onslaught_generator_deaththink; // explosion sequence
403 self.nextthink = time; // start exploding immediately
404 self.think(); // do the first explosion now
405 onslaught_updatelinks();
409 // update links after a delay
410 void() onslaught_generator_delayed =
412 onslaught_updatelinks();
413 // now begin normal thinking
414 self.think = onslaught_generator_think;
415 self.nextthink = time;
418 float onslaught_generator_waypointsprite_for_player(entity e)
420 if(e.classname == "player")
421 if(e.team == self.owner.team)
423 if(self.owner.team == COLOR_TEAM1)
424 return ons_sprite_gen_red;
425 else if(self.owner.team == COLOR_TEAM2)
426 return ons_sprite_gen_blue;
428 if(self.owner.isshielded)
429 return ons_sprite_gen_shielded;
430 if(self.owner.team == COLOR_TEAM1)
431 return ons_sprite_gen_red;
432 else if(self.owner.team == COLOR_TEAM2)
433 return ons_sprite_gen_blue;
437 float onslaught_controlpoint_waypointsprite_for_player(entity e)
440 if(e.classname == "player")
442 a = onslaught_controlpoint_attackable(self.owner, e.team);
443 if(a == 3 || a == 4) // ATTACK/TOUCH THIS ONE NOW
445 if(self.owner.team == COLOR_TEAM1)
446 return ons_sprite_cp_atck_red;
447 else if(self.owner.team == COLOR_TEAM2)
448 return ons_sprite_cp_atck_blue;
450 return ons_sprite_cp_atck_neut;
452 else if(self.owner.team == e.team || a == -1 || a == 1) // own point, or fire at it
454 if(self.owner.team == COLOR_TEAM1)
455 return ons_sprite_cp_red;
456 else if(self.owner.team == COLOR_TEAM2)
457 return ons_sprite_cp_blue;
459 else if(a == 2) // touch it
460 return ons_sprite_cp_neut;
464 if(self.owner.team == COLOR_TEAM1)
465 return ons_sprite_cp_red;
466 else if(self.owner.team == COLOR_TEAM2)
467 return ons_sprite_cp_blue;
469 return ons_sprite_cp_neut;
474 /*QUAKED onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
477 onslaught_link entities can target this.
480 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
481 "targetname" - name that onslaught_link entities will use to target this.
483 void() onslaught_generator =
491 if(!ons_sprite_cp_blue)
493 precache_model("models/sprites/ons-cp-blue.sp2");
494 setmodel(self, "models/sprites/ons-cp-blue.sp2");
495 ons_sprite_cp_blue = self.modelindex;
496 precache_model("models/sprites/ons-cp-red.sp2");
497 setmodel(self, "models/sprites/ons-cp-red.sp2");
498 ons_sprite_cp_red = self.modelindex;
499 precache_model("models/sprites/ons-cp-neut.sp2");
500 setmodel(self, "models/sprites/ons-cp-neut.sp2");
501 ons_sprite_cp_neut = self.modelindex;
502 precache_model("models/sprites/ons-cp-atck-blue.sp2");
503 setmodel(self, "models/sprites/ons-cp-atck-blue.sp2");
504 ons_sprite_cp_atck_blue = self.modelindex;
505 precache_model("models/sprites/ons-cp-atck-red.sp2");
506 setmodel(self, "models/sprites/ons-cp-atck-red.sp2");
507 ons_sprite_cp_atck_red = self.modelindex;
508 precache_model("models/sprites/ons-cp-atck-neut.sp2");
509 setmodel(self, "models/sprites/ons-cp-atck-neut.sp2");
510 ons_sprite_cp_atck_neut = self.modelindex;
511 precache_model("models/sprites/ons-gen-blue.sp2");
512 setmodel(self, "models/sprites/ons-gen-blue.sp2");
513 ons_sprite_gen_blue = self.modelindex;
514 precache_model("models/sprites/ons-gen-red.sp2");
515 setmodel(self, "models/sprites/ons-gen-red.sp2");
516 ons_sprite_gen_red = self.modelindex;
517 precache_model("models/sprites/ons-gen-shielded.sp2");
518 setmodel(self, "models/sprites/ons-gen-shielded.sp2");
519 ons_sprite_gen_shielded = self.modelindex;
523 precache_model("models/onslaught/generator.md3");
524 precache_model("models/onslaught/generator_shield.md3");
525 precache_sound("sound/onslaught/generator_decay.wav");
526 precache_sound("sound/weapons/grenade_impact.wav");
527 precache_sound("sound/weapons/rocket_impact.wav");
528 precache_sound("sound/onslaught/generator_underattack.wav");
530 objerror("team must be set");
531 self.colormap = 1024 + (self.team - 1) * 17;
532 self.solid = SOLID_BSP;
533 self.movetype = MOVETYPE_NONE;
534 self.lasthealth = self.max_health = self.health = 3000;
535 setmodel(self, "models/onslaught/generator.md3");
536 //setsize(self, '-32 -32 -24', '32 32 64');
537 setorigin(self, self.origin);
538 self.takedamage = DAMAGE_AIM;
539 self.bot_attack = TRUE;
540 self.event_damage = onslaught_generator_damage;
541 self.iscaptured = TRUE;
542 self.islinked = TRUE;
543 self.isshielded = TRUE;
544 // spawn shield model which indicates whether this can be damaged
545 self.enemy = e = spawn();
547 e.movetype = MOVETYPE_NONE;
548 e.effects = EF_ADDITIVE;
549 setmodel(e, "models/onslaught/generator_shield.md3");
550 //setsize(e, '-32 -32 0', '32 32 128');
551 setorigin(e, self.origin);
552 e.colormap = self.colormap;
554 self.think = onslaught_generator_delayed;
555 self.nextthink = time + 0.2;
557 WaypointSprite_SpawnFixed(string_null, e.origin + '0 0 1' * e.maxs_z, self, sprite);
558 self.sprite.waypointsprite_for_player = onslaught_generator_waypointsprite_for_player;
561 void(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force) onslaught_controlpoint_icon_damage =
566 if (self.owner.isshielded)
568 // this is protected by a shield, so ignore the damage
569 if (time > self.pain_finished)
570 if (attacker.classname == "player")
572 play2(attacker, "sound/onslaught/damageblockedbyshield.wav");
573 self.pain_finished = time + 1;
577 if (time > self.pain_finished)
578 if (attacker.classname == "player")
580 play2team(self.team, "sound/onslaught/controlpoint_underattack.wav");
581 self.pain_finished = time + 5;
583 self.health = self.health - damage;
584 self.alpha = self.health / self.max_health;
585 self.pain_finished = time + 1;
586 // colormod flash when shot
587 self.colormod = '2 2 2';
590 sound(self, CHAN_AUTO, "sound/weapons/grenade_impact.wav", 1, ATTN_NORM);
591 pointparticles(particleeffectnum("onslaught_controlpoint_explosion"), self.origin, '0 0 0', 1);
594 t = ColoredTeamName(attacker.team);
595 bprint(ColoredTeamName(self.team), " ", self.message, " control point destroyed by ", t, "\n");
597 self.owner.goalentity = world;
598 self.owner.islinked = FALSE;
599 self.owner.iscaptured = FALSE;
601 self.owner.colormap = 1024;
602 onslaught_updatelinks();
604 // Use targets now (somebody make sure this is in the right place..)
607 activator = self.owner;
615 void() onslaught_controlpoint_icon_think =
617 self.nextthink = time + 0.1;
618 if (time > self.pain_finished + 1)
620 self.health = self.health + self.count;
621 if (self.health >= self.max_health)
622 self.health = self.max_health;
624 self.alpha = self.health / self.max_health;
625 // colormod flash when shot
626 self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));
629 void() onslaught_controlpoint_icon_buildthink =
633 self.nextthink = time + 0.1;
634 self.health = self.health + self.count;
635 if (self.health >= self.max_health)
637 self.health = self.max_health;
638 self.count = self.count * 0.2; // slow repair rate from now on
639 self.think = onslaught_controlpoint_icon_think;
640 sound(self, CHAN_BODY, "sound/onslaught/controlpoint_built.wav", 1, ATTN_NORM);
641 bprint(ColoredTeamName(self.team), " captured ", self.owner.message, " control point\n");
642 self.owner.iscaptured = TRUE;
643 onslaught_updatelinks();
645 // Use targets now (somebody make sure this is in the right place..)
652 self.alpha = self.health / self.max_health;
653 // colormod flash when shot
654 self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));
657 void() onslaught_controlpoint_touch =
661 if (other.classname != "player")
663 a = onslaught_controlpoint_attackable(self, other.team);
666 // we've verified that this player has a legitimate claim to this point,
667 // so start building the captured point icon (which only captures this
668 // point if it successfully builds without being destroyed first)
669 self.goalentity = e = spawn();
672 e.health = e.max_health * 0.1;
673 e.alpha = e.health / e.max_health;
674 e.solid = SOLID_BBOX;
675 e.movetype = MOVETYPE_NONE;
676 setmodel(e, "models/onslaught/controlpoint_icon.md3");
677 setsize(e, '-32 -32 -32', '32 32 32');
678 setorigin(e, self.origin + '0 0 96');
679 e.takedamage = DAMAGE_AIM;
681 e.event_damage = onslaught_controlpoint_icon_damage;
683 e.colormap = 1024 + (e.team - 1) * 17;
684 e.think = onslaught_controlpoint_icon_buildthink;
685 e.nextthink = time + 0.1;
686 e.count = e.max_health / 50; // how long it takes to build
687 sound(e, CHAN_BODY, "sound/onslaught/controlpoint_build.wav", 1, ATTN_NORM);
689 self.colormap = e.colormap;
692 /*QUAKED onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
693 Control point. Be sure to give this enough clearance so that the shootable part has room to exist
695 This should link to an onslaught_controlpoint entity or onslaught_generator entity.
698 "targetname" - name that onslaught_link entities will use to target this.
699 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
700 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
702 void() onslaught_controlpoint =
710 precache_model("models/onslaught/controlpoint_pad.md3");
711 precache_model("models/onslaught/controlpoint_shield.md3");
712 precache_model("models/onslaught/controlpoint_icon.md3");
713 precache_sound("sound/onslaught/controlpoint_build.wav");
714 precache_sound("sound/onslaught/controlpoint_built.wav");
715 precache_sound("sound/weapons/grenade_impact.wav");
716 precache_sound("sound/onslaught/damageblockedbyshield.wav");
717 precache_sound("sound/onslaught/controlpoint_underattack.wav");
718 self.solid = SOLID_BSP;
719 self.movetype = MOVETYPE_NONE;
720 setmodel(self, "models/onslaught/controlpoint_pad.md3");
721 //setsize(self, '-32 -32 0', '32 32 8');
722 setorigin(self, self.origin);
723 self.touch = onslaught_controlpoint_touch;
725 self.colormap = 1024;
726 self.iscaptured = FALSE;
727 self.islinked = FALSE;
728 self.isshielded = TRUE;
729 // spawn shield model which indicates whether this can be damaged
730 self.enemy = e = spawn();
732 e.movetype = MOVETYPE_NONE;
733 e.effects = EF_ADDITIVE;
734 setmodel(e, "models/onslaught/controlpoint_shield.md3");
735 //setsize(e, '-32 -32 0', '32 32 128');
736 setorigin(e, self.origin);
737 e.colormap = self.colormap;
738 onslaught_updatelinks();
740 WaypointSprite_SpawnFixed(string_null, e.origin + '0 0 1' * e.maxs_z, self, sprite);
741 self.sprite.waypointsprite_for_player = onslaught_controlpoint_waypointsprite_for_player;
744 void() onslaught_link_delayed =
746 self.goalentity = find(world, targetname, self.target);
747 self.enemy = find(world, targetname, self.target2);
748 if (!self.goalentity)
749 objerror("can not find target\n");
751 objerror("can not find target2\n");
752 dprint(etos(self.goalentity), " linked with ", etos(self.enemy), "\n");
755 /*QUAKED onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
756 Link between control points.
758 This entity targets two different onslaught_controlpoint or onslaught_generator entities, and suppresses shielding on both if they are owned by different teams.
761 "target" - first control point.
762 "target2" - second control point.
764 void() onslaught_link =
771 if (self.target == "" || self.target2 == "")
772 objerror("target and target2 must be set\n");
773 self.think = onslaught_link_delayed;
774 self.nextthink = time + 0.1;