1 void onslaught_generator_updatesprite(entity e);
2 void onslaught_controlpoint_updatesprite(entity e);
3 void onslaught_link_checkupdate();
9 .float isgenneighbor_red;
10 .float isgenneighbor_blue;
11 .float iscpneighbor_red;
12 .float iscpneighbor_blue;
18 .string model1, model2, model3;
21 void onslaught_generator_boom_think()
23 self.nextthink = time + 0.05;
26 self.think = SUB_Remove;
32 void onslaught_generator_boom_spawn(vector org, float fscale)
36 setmodel(e, "models/onslaught/boom.md3");
40 setsize(e, e.mins * e.scale, e.maxs * e.scale);
41 e.angles = randomvec() * 360;
43 e.effects = EF_NOSHADOW;
45 e.think = onslaught_generator_boom_think;
46 e.nextthink = time + 0.05;
49 void ons_gib_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce)
51 self.velocity = self.velocity + vforce;
55 void ons_throwgib_think()
59 self.nextthink = time + 0.05;
60 if(self.count > self.giblifetime)
62 self.think = SUB_Remove;
65 if(self.count > self.giblifetime-10)
67 org = self.origin + 20 * randomvec();
68 onslaught_generator_boom_spawn(org, random()*0.5+0.3);
72 void ons_throwgib(vector v_from, vector v_to, string smodel, float f_lifetime, float f_fadetime, float b_burn)
78 setmodel(gib, smodel);
79 setorigin(gib, v_from);
80 gib.solid = SOLID_BBOX;
81 gib.movetype = MOVETYPE_BOUNCE;
82 gib.takedamage = DAMAGE_YES;
83 gib.event_damage = ons_gib_damage;
85 gib.effects = EF_LOWPRECISION;
86 gib.flags = FL_NOTARGET;
88 gib.giblifetime = f_lifetime;
92 gib.think = ons_throwgib_think;
93 gib.nextthink = time + 0.05;
96 SUB_SetFade(gib, time + f_lifetime, 2);
99 void onslaught_updatelinks()
101 local entity l, links;
102 local float stop, t1, t2, t3, t4;
103 // first check if the game has ended
104 dprint("--- updatelinks ---\n");
105 links = findchain(classname, "onslaught_link");
106 // mark generators as being shielded and networked
107 l = findchain(classname, "onslaught_generator");
111 dprint(etos(l), " (generator) belongs to team ", ftos(l.team), "\n");
113 dprint(etos(l), " (generator) is destroyed\n");
114 l.islinked = l.iscaptured;
115 l.isshielded = l.iscaptured;
118 // mark points as shielded and not networked
119 l = findchain(classname, "onslaught_controlpoint");
124 l.isgenneighbor_red = FALSE;
125 l.isgenneighbor_blue = FALSE;
126 l.iscpneighbor_red = FALSE;
127 l.iscpneighbor_blue = FALSE;
128 dprint(etos(l), " (point) belongs to team ", ftos(l.team), "\n");
131 // flow power outward from the generators through the network
135 dprint(etos(l), " (link) connects ", etos(l.goalentity), " with ", etos(l.enemy), "\n");
145 // if both points are captured by the same team, and only one of
146 // them is powered, mark the other one as powered as well
147 if (l.enemy.iscaptured && l.goalentity.iscaptured)
148 if (l.enemy.islinked != l.goalentity.islinked)
149 if (l.enemy.team == l.goalentity.team)
151 if (!l.goalentity.islinked)
154 l.goalentity.islinked = TRUE;
155 dprint(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)\n");
157 else if (!l.enemy.islinked)
160 l.enemy.islinked = TRUE;
161 dprint(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)\n");
167 // now that we know which points are powered we can mark their neighbors
168 // as unshielded if team differs
172 if (l.goalentity.team != l.enemy.team)
174 if (l.goalentity.islinked)
176 dprint(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)\n");
177 l.enemy.isshielded = FALSE;
178 if(l.goalentity.classname == "onslaught_generator")
180 if(l.goalentity.team == COLOR_TEAM1)
181 l.enemy.isgenneighbor_red = TRUE;
182 else if(l.goalentity.team == COLOR_TEAM2)
183 l.enemy.isgenneighbor_blue = TRUE;
187 if(l.goalentity.team == COLOR_TEAM1)
188 l.enemy.iscpneighbor_red = TRUE;
189 else if(l.goalentity.team == COLOR_TEAM2)
190 l.enemy.iscpneighbor_blue = TRUE;
193 if (l.enemy.islinked)
195 dprint(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)\n");
196 l.goalentity.isshielded = FALSE;
197 if(l.enemy.classname == "onslaught_generator")
199 if(l.enemy.team == COLOR_TEAM1)
200 l.goalentity.isgenneighbor_red = TRUE;
201 else if(l.enemy.team == COLOR_TEAM2)
202 l.goalentity.isgenneighbor_blue = TRUE;
206 if(l.enemy.team == COLOR_TEAM1)
207 l.goalentity.iscpneighbor_red = TRUE;
208 else if(l.enemy.team == COLOR_TEAM2)
209 l.goalentity.iscpneighbor_blue = TRUE;
215 // now update the takedamage and alpha variables on generator shields
216 l = findchain(classname, "onslaught_generator");
221 dprint(etos(l), " (generator) is shielded\n");
223 l.takedamage = DAMAGE_NO;
224 l.bot_attack = FALSE;
228 dprint(etos(l), " (generator) is not shielded\n");
230 l.takedamage = DAMAGE_AIM;
235 // now update the takedamage and alpha variables on control point icons
236 l = findchain(classname, "onslaught_controlpoint");
241 dprint(etos(l), " (point) is shielded\n");
245 l.goalentity.takedamage = DAMAGE_NO;
246 l.goalentity.bot_attack = FALSE;
251 dprint(etos(l), " (point) is not shielded\n");
255 l.goalentity.takedamage = DAMAGE_AIM;
256 l.goalentity.bot_attack = TRUE;
259 onslaught_controlpoint_updatesprite(l);
262 // count generators owned by each team
263 t1 = t2 = t3 = t4 = 0;
264 l = findchain(classname, "onslaught_generator");
269 if (l.team == COLOR_TEAM1) t1 = 1;
270 if (l.team == COLOR_TEAM2) t2 = 1;
271 if (l.team == COLOR_TEAM3) t3 = 1;
272 if (l.team == COLOR_TEAM4) t4 = 1;
274 onslaught_generator_updatesprite(l);
277 // see if multiple teams remain (if not, it's game over)
278 if (t1 + t2 + t3 + t4 < 2)
279 dprint("--- game over ---\n");
281 dprint("--- done updating links ---\n");
284 float onslaught_controlpoint_can_be_linked(entity cp, float t)
288 if(cp.isgenneighbor_red)
290 if(cp.iscpneighbor_red)
293 else if(t == COLOR_TEAM2)
295 if(cp.isgenneighbor_blue)
297 if(cp.iscpneighbor_blue)
303 // check to see if this player has a legitimate claim to capture this
304 // control point - more specifically that there is a captured path of
305 // points leading back to the team generator
306 e = findchain(classname, "onslaught_link");
309 if (e.goalentity == cp)
311 dprint(etos(e), " (link) connects to ", etos(e.enemy), " (point)");
312 if (e.enemy.islinked)
314 dprint(" which is linked");
315 if (e.enemy.team == t)
317 dprint(" and has the correct team!\n");
321 dprint(" but has the wrong team\n");
326 else if (e.enemy == cp)
328 dprint(etos(e), " (link) connects to ", etos(e.goalentity), " (point)");
329 if (e.goalentity.islinked)
331 dprint(" which is linked");
332 if (e.goalentity.team == t)
334 dprint(" and has a team!\n");
338 dprint(" but has the wrong team\n");
349 float onslaught_controlpoint_attackable(entity cp, float t)
350 // -2: SAME TEAM, attackable by enemy!
355 // 3: attack it (HIGH PRIO)
356 // 4: touch it (HIGH PRIO)
364 else if(cp.goalentity)
366 // if there's already an icon built, nothing happens
369 a = onslaught_controlpoint_can_be_linked(cp, COLOR_TEAM1 + COLOR_TEAM2 - t);
370 if(a) // attackable by enemy?
371 return -2; // EMERGENCY!
374 // we know it can be linked, so no need to check
376 a = onslaught_controlpoint_can_be_linked(cp, t);
377 if(a == 2) // near our generator?
378 return 3; // EMERGENCY!
384 if(onslaught_controlpoint_can_be_linked(cp, t))
386 a = onslaught_controlpoint_can_be_linked(cp, COLOR_TEAM1 + COLOR_TEAM2 - t);
388 return 4; // GET THIS ONE NOW!
390 return 2; // TOUCH ME
396 void onslaught_generator_think()
400 self.nextthink = ceil(time + 1);
401 if (cvar("timelimit"))
402 if (time > cvar("timelimit") * 60 - 60)
404 // self.max_health / 300 gives 5 minutes of overtime.
405 // control points reduce the overtime duration.
406 sound(self, CHAN_TRIGGER, "onslaught/generator_decay.wav", VOL_BASE, ATTN_NORM);
408 e = findchain(classname, "onslaught_controlpoint");
411 if (e.team != self.team)
416 d = d * self.max_health / 300;
417 Damage(self, self, self, d, DEATH_HURTTRIGGER, self.origin, '0 0 0');
422 void onslaught_generator_ring_think()
424 self.nextthink = time + 0.05;
427 self.think = SUB_Remove;
431 self.scale = self.count * 4;
433 self.frame = self.count;
439 void onslaught_generator_ring_spawn(vector org)
443 setmodel(e, "models/onslaught/shockwavetransring.md3");
449 e.think = onslaught_generator_ring_think;
450 e.nextthink = time + 0.05;
452 void onslaught_generator_ray_think()
454 self.nextthink = time + 0.05;
457 self.think = SUB_Remove;
470 void onslaught_generator_ray_spawn(vector org)
474 setmodel(e, "models/onslaught/ons_ray.md3");
476 e.angles = randomvec() * 360;
478 e.scale = random() * 5 + 8;
479 e.think = onslaught_generator_ray_think;
480 e.nextthink = time + 0.05;
483 void onslaught_generator_shockwave_think()
485 self.nextthink = time + 0.05;
488 self.think = SUB_Remove;
497 self.scale = self.count * 4;
498 setsize(self, self.mins * self.scale, self.maxs * self.scale);
499 self.frame = self.count;
504 void onslaught_generator_shockwave_spawn(vector org)
508 setmodel(e, "models/onslaught/shockwave.md3");
516 e.think = onslaught_generator_shockwave_think;
517 e.nextthink = time + 0.05;
520 void onslaught_generator_damage_think()
522 if(self.owner.health < 0)
524 self.think = SUB_Remove;
527 self.nextthink = time+0.1;
529 // damaged fx (less probable the more damaged is the generator)
530 if(random() < 0.9 - self.owner.health / self.owner.max_health)
533 pointparticles(particleeffectnum("electro_ballexplode"), self.origin + randompos('-50 -50 -20', '50 50 50'), '0 0 0', 1);
534 sound(self, CHAN_TRIGGER, "onslaught/electricity_explode.ogg", VOL_BASE, ATTN_NORM);
537 pointparticles(particleeffectnum("torch_small"), self.origin + randompos('-60 -60 -20', '60 60 60'), '0 0 0', 1);
540 void onslaught_generator_damage_spawn(entity gd_owner)
545 e.health = self.owner.health;
546 setorigin(e, gd_owner.origin);
547 e.think = onslaught_generator_damage_think;
548 e.nextthink = time+1;
551 void onslaught_generator_deaththink()
560 if(self.count==40||self.count==20)
562 onslaught_generator_ring_spawn(self.origin);
563 sound(self, CHAN_TRIGGER, "onslaught/shockwave.wav", VOL_BASE, ATTN_NORM);
571 ons_throwgib(self.origin + '0 0 40', (100 * randomvec() - '1 1 1') * 11 + '0 0 20', "models/onslaught/gen_gib1.md3", 25, 1, 1);
573 ons_throwgib(self.origin + '0 0 40', (100 * randomvec() - '1 1 1') * 12 + '0 0 20', "models/onslaught/gen_gib2.md3", 20, 1, 1);
575 ons_throwgib(self.origin + '0 0 40', (100 * randomvec() - '1 1 1') * 13 + '0 0 20', "models/onslaught/gen_gib3.md3", 15, 1, 1);
581 org = self.origin + randompos('-30 -30 -30' * i + '0 0 -20', '30 30 30' * i + '0 0 20');
582 onslaught_generator_boom_spawn(org, (6-i)/5+0.3);
585 // Short explosion sound + small explosion
588 te_explosion(self.origin);
589 sound(self, CHAN_TRIGGER, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
593 org = self.origin + randompos(self.mins + '8 8 8', self.maxs + '-8 -8 -8');
594 pointparticles(particleeffectnum("onslaught_generator_smallexplosion"), org, '0 0 0', 1);
599 onslaught_generator_ray_spawn(self.origin);
607 onslaught_generator_shockwave_spawn(org);
608 pointparticles(particleeffectnum("onslaught_generator_finalexplosion"), org, '0 0 0', 1);
609 sound(self, CHAN_TRIGGER, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
612 self.nextthink = time + 0.05;
614 self.count = self.count - 1;
617 void onslaught_generator_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
622 if (attacker != self)
626 // this is protected by a shield, so ignore the damage
627 if (time > self.pain_finished)
628 if (attacker.classname == "player")
630 play2(attacker, "onslaught/damageblockedbyshield.wav");
631 self.pain_finished = time + 1;
635 if (time > self.pain_finished)
637 self.pain_finished = time + 10;
638 bprint(ColoredTeamName(self.team), " generator under attack!\n");
639 play2team(self.team, "onslaught/generator_underattack.wav");
642 self.health = self.health - damage;
643 // choose an animation frame based on health
644 self.frame = 10 * bound(0, (1 - self.health / self.max_health), 1);
645 // see if the generator is still functional, or dying
649 lh = ceil(self.lasthealth / 100) * 100;
650 h = ceil(self.health / 100) * 100;
652 bprint(ColoredTeamName(self.team), " generator has less than ", ftos(h), " health remaining\n");
653 self.lasthealth = self.health;
657 if (attacker == self)
658 bprint(ColoredTeamName(self.team), " generator spontaneously exploded due to overtime!\n");
662 t = ColoredTeamName(attacker.team);
663 bprint(ColoredTeamName(self.team), " generator destroyed by ", t, "!\n");
665 self.iscaptured = FALSE;
666 self.islinked = FALSE;
667 self.isshielded = FALSE;
668 self.takedamage = DAMAGE_NO; // can't be hurt anymore
669 self.event_damage = SUB_Null; // won't do anything if hurt
670 self.count = 0; // reset counter
671 self.think = onslaught_generator_deaththink; // explosion sequence
672 self.nextthink = time; // start exploding immediately
673 self.think(); // do the first explosion now
674 onslaught_updatelinks();
677 setmodel(self, "models/onslaught/generator_dead.md3");
678 else if(self.health < self.max_health * 0.10)
679 setmodel(self, "models/onslaught/generator_dmg9.md3");
680 else if(self.health < self.max_health * 0.20)
681 setmodel(self, "models/onslaught/generator_dmg8.md3");
682 else if(self.health < self.max_health * 0.30)
683 setmodel(self, "models/onslaught/generator_dmg7.md3");
684 else if(self.health < self.max_health * 0.40)
685 setmodel(self, "models/onslaught/generator_dmg6.md3");
686 else if(self.health < self.max_health * 0.50)
687 setmodel(self, "models/onslaught/generator_dmg5.md3");
688 else if(self.health < self.max_health * 0.60)
689 setmodel(self, "models/onslaught/generator_dmg4.md3");
690 else if(self.health < self.max_health * 0.70)
691 setmodel(self, "models/onslaught/generator_dmg3.md3");
692 else if(self.health < self.max_health * 0.80)
693 setmodel(self, "models/onslaught/generator_dmg2.md3");
694 else if(self.health < self.max_health * 0.90)
695 setmodel(self, "models/onslaught/generator_dmg1.md3");
696 setsize(self, '-52 -52 -14', '52 52 75');
698 // Throw some flaming gibs on damage, more damage = more chance for gib
699 if(random() < damage/220)
701 sound(self, CHAN_TRIGGER, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
704 ons_throwgib(hitloc, (force * -1) + '0 0 40', "models/onslaught/gen_gib1.md3", 7, 1, 1);
706 ons_throwgib(hitloc, (force * -1)+ '0 0 40', "models/onslaught/gen_gib2.md3", 6, 1, 1);
708 ons_throwgib(hitloc, (force * -1)+ '0 0 40', "models/onslaught/gen_gib3.md3", 5, 1, 1);
712 // particles on every hit
713 pointparticles(particleeffectnum("sparks"), hitloc, force * -1, 1);
717 sound(self, CHAN_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE, ATTN_NORM);
719 sound(self, CHAN_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE, ATTN_NORM);
722 //throw some gibs on damage
723 if(random() < damage/200+0.2)
725 ons_throwgib(hitloc, randomvec()*360, "models/onslaught/gen_gib1.md3", 1, 1, 0);
728 // update links after a delay
729 void onslaught_generator_delayed()
731 onslaught_updatelinks();
732 // now begin normal thinking
733 self.think = onslaught_generator_think;
734 self.nextthink = time;
737 string onslaught_generator_waypointsprite_for_team(entity e, float t)
741 if(e.team == COLOR_TEAM1)
742 return "ons-gen-red";
743 else if(e.team == COLOR_TEAM2)
744 return "ons-gen-blue";
747 return "ons-gen-shielded";
748 if(e.team == COLOR_TEAM1)
749 return "ons-gen-red";
750 else if(e.team == COLOR_TEAM2)
751 return "ons-gen-blue";
755 void onslaught_generator_updatesprite(entity e)
758 s1 = onslaught_generator_waypointsprite_for_team(e, COLOR_TEAM1);
759 s2 = onslaught_generator_waypointsprite_for_team(e, COLOR_TEAM2);
760 s3 = onslaught_generator_waypointsprite_for_team(e, -1);
761 WaypointSprite_UpdateSprites(e.sprite, s1, s2, s3);
763 if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
765 e.lastteam = e.team + 2;
766 e.lastshielded = e.isshielded;
769 if(e.team == COLOR_TEAM1)
770 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0 0');
771 else if(e.team == COLOR_TEAM2)
772 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0 0 0.5');
774 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
778 if(e.team == COLOR_TEAM1)
779 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '1 0 0');
780 else if(e.team == COLOR_TEAM2)
781 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0 0 1');
783 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
785 WaypointSprite_Ping(e.sprite);
789 string onslaught_controlpoint_waypointsprite_for_team(entity e, float t)
794 a = onslaught_controlpoint_attackable(e, t);
795 if(a == 3 || a == 4) // ATTACK/TOUCH THIS ONE NOW
797 if(e.team == COLOR_TEAM1)
798 return "ons-cp-atck-red";
799 else if(e.team == COLOR_TEAM2)
800 return "ons-cp-atck-blue";
802 return "ons-cp-atck-neut";
804 else if(a == -2) // DEFEND THIS ONE NOW
806 if(e.team == COLOR_TEAM1)
807 return "ons-cp-dfnd-red";
808 else if(e.team == COLOR_TEAM2)
809 return "ons-cp-dfnd-blue";
811 else if(e.team == t || a == -1 || a == 1) // own point, or fire at it
813 if(e.team == COLOR_TEAM1)
815 else if(e.team == COLOR_TEAM2)
816 return "ons-cp-blue";
818 else if(a == 2) // touch it
819 return "ons-cp-neut";
823 if(e.team == COLOR_TEAM1)
825 else if(e.team == COLOR_TEAM2)
826 return "ons-cp-blue";
828 return "ons-cp-neut";
833 void onslaught_controlpoint_updatesprite(entity e)
836 s1 = onslaught_controlpoint_waypointsprite_for_team(e, COLOR_TEAM1);
837 s2 = onslaught_controlpoint_waypointsprite_for_team(e, COLOR_TEAM2);
838 s3 = onslaught_controlpoint_waypointsprite_for_team(e, -1);
839 WaypointSprite_UpdateSprites(e.sprite, s1, s2, s3);
842 sh = !(onslaught_controlpoint_can_be_linked(e, COLOR_TEAM1) || onslaught_controlpoint_can_be_linked(e, COLOR_TEAM2));
844 if(e.lastteam != e.team + 2 || e.lastshielded != sh)
846 e.lastteam = e.team + 2;
850 if(e.team == COLOR_TEAM1)
851 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0 0');
852 else if(e.team == COLOR_TEAM2)
853 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0 0 0.5');
855 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
859 if(e.team == COLOR_TEAM1)
860 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '1 0 0');
861 else if(e.team == COLOR_TEAM2)
862 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0 0 1');
864 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
866 WaypointSprite_Ping(e.sprite);
870 void onslaught_generator_reset()
872 self.team = self.team_saved;
873 self.lasthealth = self.max_health = self.health = cvar("g_onslaught_gen_health");
874 self.takedamage = DAMAGE_AIM;
875 self.bot_attack = TRUE;
876 self.iscaptured = TRUE;
877 self.islinked = TRUE;
878 self.isshielded = TRUE;
879 self.enemy.solid = SOLID_NOT;
880 self.think = onslaught_generator_delayed;
881 self.nextthink = time + 0.2;
882 setmodel(self, "models/onslaught/generator.md3");
885 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
888 spawnfunc_onslaught_link entities can target this.
891 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
892 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
894 void spawnfunc_onslaught_generator()
903 precache_model("models/onslaught/generator.md3");
904 precache_model("models/onslaught/generator_shield.md3");
905 precache_model("models/onslaught/generator_dmg1.md3");
906 precache_model("models/onslaught/generator_dmg2.md3");
907 precache_model("models/onslaught/generator_dmg3.md3");
908 precache_model("models/onslaught/generator_dmg4.md3");
909 precache_model("models/onslaught/generator_dmg5.md3");
910 precache_model("models/onslaught/generator_dmg6.md3");
911 precache_model("models/onslaught/generator_dmg7.md3");
912 precache_model("models/onslaught/generator_dmg8.md3");
913 precache_model("models/onslaught/generator_dmg9.md3");
914 precache_model("models/onslaught/generator_dead.md3");
915 precache_model("models/onslaught/boom.md3");
916 precache_model("models/onslaught/shockwave.md3");
917 precache_model("models/onslaught/shockwavetransring.md3");
918 precache_model("models/onslaught/gen_gib1.md3");
919 precache_model("models/onslaught/gen_gib2.md3");
920 precache_model("models/onslaught/gen_gib3.md3");
921 precache_model("models/onslaught/ons_ray.md3");
922 precache_sound("onslaught/generator_decay.wav");
923 precache_sound("weapons/grenade_impact.wav");
924 precache_sound("weapons/rocket_impact.wav");
925 precache_sound("onslaught/generator_underattack.wav");
926 precache_sound("onslaught/shockwave.wav");
927 precache_sound("onslaught/ons_hit1.wav");
928 precache_sound("onslaught/ons_hit2.wav");
929 precache_sound("onslaught/electricity_explode.wav");
931 objerror("team must be set");
932 self.team_saved = self.team;
933 self.colormap = 1024 + (self.team - 1) * 17;
934 self.solid = SOLID_BBOX;
935 self.movetype = MOVETYPE_NONE;
936 self.lasthealth = self.max_health = self.health = cvar("g_onslaught_gen_health");
937 setmodel(self, "models/onslaught/generator.md3");
938 setsize(self, '-52 -52 -14', '52 52 75');
939 setorigin(self, self.origin);
940 self.takedamage = DAMAGE_AIM;
941 self.bot_attack = TRUE;
942 self.event_damage = onslaught_generator_damage;
943 self.iscaptured = TRUE;
944 self.islinked = TRUE;
945 self.isshielded = TRUE;
946 // helper entity that create fx when generator is damaged
947 onslaught_generator_damage_spawn(self);
948 // spawn shield model which indicates whether this can be damaged
949 self.enemy = e = spawn();
950 e.classname = "onslaught_generator_shield";
952 e.movetype = MOVETYPE_NONE;
953 e.effects = EF_ADDITIVE;
954 setmodel(e, "models/onslaught/generator_shield.md3");
955 setorigin(e, self.origin);
956 e.colormap = self.colormap;
958 self.think = onslaught_generator_delayed;
959 self.nextthink = time + 0.2;
960 InitializeEntity(self, onslaught_generator_delayed, INITPRIO_LAST);
962 WaypointSprite_SpawnFixed(string_null, e.origin + '0 0 1' * e.maxs_z, self, sprite);
963 WaypointSprite_UpdateRule(self.sprite, COLOR_TEAM2, SPRITERULE_TEAMPLAY);
965 onslaught_updatelinks();
967 self.reset = onslaught_generator_reset;
972 .vector cp_origin, cp_bob_origin, cp_bob_dmg;
973 void onslaught_controlpoint_icon_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
978 if (self.owner.isshielded)
980 // this is protected by a shield, so ignore the damage
981 if (time > self.pain_finished)
982 if (attacker.classname == "player")
984 play2(attacker, "onslaught/damageblockedbyshield.wav");
985 self.pain_finished = time + 1;
989 if (time > self.pain_finished)
990 if (attacker.classname == "player")
992 play2team(self.team, "onslaught/controlpoint_underattack.wav");
993 self.pain_finished = time + 10;
995 self.health = self.health - damage;
996 self.pain_finished = time + 1;
997 self.punchangle = (2 * randomvec() - '1 1 1') * 45;
998 self.cp_bob_dmg_z = (2 * random() - 1) * 15;
999 // colormod flash when shot
1000 self.colormod = '2 2 2';
1001 // particles on every hit
1002 pointparticles(particleeffectnum("sparks"), hitloc, force*-1, 1);
1003 //sound on every hit
1005 sound(self, CHAN_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE+0.3, ATTN_NORM);
1007 sound(self, CHAN_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE+0.3, ATTN_NORM);
1009 if (self.health < 0)
1011 sound(self, CHAN_TRIGGER, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
1012 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
1015 t = ColoredTeamName(attacker.team);
1016 bprint(ColoredTeamName(self.team), " ", self.message, " control point destroyed by ", t, "\n");
1017 ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 25, "models/onslaught/controlpoint_icon_gib1.md3", 5, 1, 0);
1018 ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 45, "models/onslaught/controlpoint_icon_gib2.md3", 5, 1, 0);
1019 ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 45, "models/onslaught/controlpoint_icon_gib2.md3", 5, 1, 0);
1020 ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 5, 1, 0);
1021 ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 5, 1, 0);
1022 ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 5, 1, 0);
1023 ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 5, 1, 0);
1025 self.owner.goalentity = world;
1026 self.owner.islinked = FALSE;
1027 self.owner.iscaptured = FALSE;
1028 self.owner.team = 0;
1029 self.owner.colormap = 1024;
1030 onslaught_updatelinks();
1032 // Use targets now (somebody make sure this is in the right place..)
1040 self.owner.waslinked = self.owner.islinked;
1041 if(self.owner.model != "models/onslaught/controlpoint_pad.md3")
1042 setmodel(self.owner, "models/onslaught/controlpoint_pad.md3");
1043 //setsize(self, '-32 -32 0', '32 32 8');
1049 void onslaught_controlpoint_icon_think()
1052 self.nextthink = time + 0.05;
1053 if (time > self.pain_finished + 5)
1055 self.health = self.health + self.count;
1056 if (self.health >= self.max_health)
1057 self.health = self.max_health;
1059 if (self.health < self.max_health * 0.25)
1060 setmodel(self, "models/onslaught/controlpoint_icon_dmg3.md3");
1061 else if (self.health < self.max_health * 0.50)
1062 setmodel(self, "models/onslaught/controlpoint_icon_dmg2.md3");
1063 else if (self.health < self.max_health * 0.75)
1064 setmodel(self, "models/onslaught/controlpoint_icon_dmg1.md3");
1065 else if (self.health < self.max_health * 0.90)
1066 setmodel(self, "models/onslaught/controlpoint_icon.md3");
1067 // colormod flash when shot
1068 self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));
1070 if(self.owner.islinked != self.owner.waslinked)
1072 // unteam the spawnpoint if needed
1074 t = self.owner.team;
1075 if(!self.owner.islinked)
1076 self.owner.team = 0;
1084 self.owner.team = t;
1086 self.owner.waslinked = self.owner.islinked;
1088 if (self.punchangle_x > 2)
1089 self.punchangle_x = self.punchangle_x - 2;
1090 else if (self.punchangle_x < -2)
1091 self.punchangle_x = self.punchangle_x + 2;
1093 self.punchangle_x = 0;
1094 if (self.punchangle_y > 2)
1095 self.punchangle_y = self.punchangle_y - 2;
1096 else if (self.punchangle_y < -2)
1097 self.punchangle_y = self.punchangle_y + 2;
1099 self.punchangle_y = 0;
1100 if (self.punchangle_z > 2)
1101 self.punchangle_z = self.punchangle_z - 2;
1102 else if (self.punchangle_z < -2)
1103 self.punchangle_z = self.punchangle_z + 2;
1105 self.punchangle_z = 0;
1106 self.angles_x = self.punchangle_x;
1107 self.angles_y = self.punchangle_y;
1108 self.angles_z = self.punchangle_z;
1110 self.cp_bob_origin_z = 4 * PI * (1 - cos(self.cp_bob_spd / 8));
1111 self.cp_bob_spd = self.cp_bob_spd + 0.5;
1112 if(self.cp_bob_dmg_z > 0)
1113 self.cp_bob_dmg_z = self.cp_bob_dmg_z - 0.1;
1115 self.cp_bob_dmg_z = 0;
1116 self.origin = self.cp_origin + self.cp_bob_origin + self.cp_bob_dmg;
1119 if(random() < 0.6 - self.health / self.max_health)
1121 pointparticles(particleeffectnum("electricity_sparks"), self.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
1124 sound(self, CHAN_PAIN, "onslaught/ons_spark1.wav", VOL_BASE, ATTN_NORM);
1125 else if (random() > 0.5)
1126 sound(self, CHAN_PAIN, "onslaught/ons_spark2.wav", VOL_BASE, ATTN_NORM);
1130 void onslaught_controlpoint_icon_buildthink()
1135 self.nextthink = time + 0.05;
1137 // only do this if there is power
1138 a = onslaught_controlpoint_can_be_linked(self.owner, self.owner.team);
1142 self.health = self.health + self.count;
1144 if (self.health >= self.max_health)
1146 self.health = self.max_health;
1147 self.count = self.count * 0.1; // slow repair rate from now on
1148 self.think = onslaught_controlpoint_icon_think;
1149 sound(self, CHAN_TRIGGER, "onslaught/controlpoint_built.wav", VOL_BASE, ATTN_NORM);
1150 bprint(ColoredTeamName(self.team), " captured ", self.owner.message, " control point\n");
1151 self.owner.iscaptured = TRUE;
1152 onslaught_updatelinks();
1154 // Use targets now (somebody make sure this is in the right place..)
1160 self.cp_origin = self.origin;
1161 self.cp_bob_origin = '0 0 0.1';
1162 self.cp_bob_spd = 0;
1164 self.alpha = self.health / self.max_health;
1165 // colormod flash when shot
1166 self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));
1167 if(self.owner.model != "models/onslaught/controlpoint_pad2.md3")
1168 setmodel(self.owner, "models/onslaught/controlpoint_pad2.md3");
1169 //setsize(self, '-32 -32 0', '32 32 8');
1171 if(random() < 0.9 - self.health / self.max_health)
1172 pointparticles(particleeffectnum("rage"), self.origin + 10 * randomvec(), '0 0 -1', 1);
1178 void onslaught_controlpoint_touch()
1182 if (other.classname != "player")
1184 a = onslaught_controlpoint_attackable(self, other.team);
1185 if(a != 2 && a != 4)
1187 // we've verified that this player has a legitimate claim to this point,
1188 // so start building the captured point icon (which only captures this
1189 // point if it successfully builds without being destroyed first)
1190 self.goalentity = e = spawn();
1191 e.classname = "onslaught_controlpoint_icon";
1193 e.max_health = cvar("g_onslaught_cp_health");
1194 e.health = e.max_health * 0.1;
1195 e.solid = SOLID_BBOX;
1196 e.movetype = MOVETYPE_NONE;
1197 setmodel(e, "models/onslaught/controlpoint_icon.md3");
1198 setsize(e, '-32 -32 -32', '32 32 32');
1199 setorigin(e, self.origin + '0 0 96');
1200 e.takedamage = DAMAGE_AIM;
1201 e.bot_attack = TRUE;
1202 e.event_damage = onslaught_controlpoint_icon_damage;
1203 e.team = other.team;
1204 e.colormap = 1024 + (e.team - 1) * 17;
1205 e.think = onslaught_controlpoint_icon_buildthink;
1206 e.nextthink = time + 0.1;
1207 e.count = e.max_health / 100; // how long it takes to build
1208 sound(e, CHAN_TRIGGER, "onslaught/controlpoint_build.wav", VOL_BASE, ATTN_NORM);
1210 self.colormap = e.colormap;
1213 void onslaught_controlpoint_reset()
1215 if(self.goalentity && self.goalentity != world)
1216 remove(self.goalentity);
1217 self.goalentity = world;
1219 self.colormap = 1024;
1220 self.iscaptured = FALSE;
1221 self.islinked = FALSE;
1222 self.isshielded = TRUE;
1223 self.enemy.solid = SOLID_NOT;
1224 self.enemy.colormap = self.colormap;
1225 self.think = self.enemy.think = SUB_Null;
1226 self.nextthink = 0; // don't like SUB_Null :P
1227 setmodel(self, "models/onslaught/controlpoint_pad.md3");
1228 //setsize(self, '-32 -32 0', '32 32 8');
1230 onslaught_updatelinks();
1233 SUB_UseTargets(); // to reset the structures, playerspawns etc.
1236 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
1237 Control point. Be sure to give this enough clearance so that the shootable part has room to exist
1239 This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
1242 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
1243 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
1244 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
1246 void spawnfunc_onslaught_controlpoint()
1254 precache_model("models/onslaught/controlpoint_pad.md3");
1255 precache_model("models/onslaught/controlpoint_pad2.md3");
1256 precache_model("models/onslaught/controlpoint_shield.md3");
1257 precache_model("models/onslaught/controlpoint_icon.md3");
1258 precache_model("models/onslaught/controlpoint_icon_dmg1.md3");
1259 precache_model("models/onslaught/controlpoint_icon_dmg2.md3");
1260 precache_model("models/onslaught/controlpoint_icon_dmg3.md3");
1261 precache_model("models/onslaught/controlpoint_icon_gib1.md3");
1262 precache_model("models/onslaught/controlpoint_icon_gib2.md3");
1263 precache_model("models/onslaught/controlpoint_icon_gib4.md3");
1264 precache_sound("onslaught/controlpoint_build.wav");
1265 precache_sound("onslaught/controlpoint_built.wav");
1266 precache_sound("weapons/grenade_impact.wav");
1267 precache_sound("onslaught/damageblockedbyshield.wav");
1268 precache_sound("onslaught/controlpoint_underattack.wav");
1269 precache_sound("onslaught/ons_spark1.wav");
1270 precache_sound("onslaught/ons_spark2.wav");
1271 self.solid = SOLID_BBOX;
1272 self.movetype = MOVETYPE_NONE;
1273 setmodel(self, "models/onslaught/controlpoint_pad.md3");
1274 //setsize(self, '-32 -32 0', '32 32 8');
1275 setorigin(self, self.origin);
1276 self.touch = onslaught_controlpoint_touch;
1278 self.colormap = 1024;
1279 self.iscaptured = FALSE;
1280 self.islinked = FALSE;
1281 self.isshielded = TRUE;
1282 // spawn shield model which indicates whether this can be damaged
1283 self.enemy = e = spawn();
1284 e.classname = "onslaught_controlpoint_shield";
1285 e.solid = SOLID_NOT;
1286 e.movetype = MOVETYPE_NONE;
1287 e.effects = EF_ADDITIVE;
1288 setmodel(e, "models/onslaught/controlpoint_shield.md3");
1289 //setsize(e, '-32 -32 0', '32 32 128');
1290 setorigin(e, self.origin);
1291 e.colormap = self.colormap;
1293 waypoint_spawnforitem(self);
1295 WaypointSprite_SpawnFixed(string_null, e.origin + '0 0 1' * e.maxs_z, self, sprite);
1296 WaypointSprite_UpdateRule(self.sprite, COLOR_TEAM2, SPRITERULE_TEAMPLAY);
1298 onslaught_updatelinks();
1300 self.reset = onslaught_controlpoint_reset;
1303 float onslaught_link_send(entity to, float sendflags)
1305 WriteByte(MSG_ENTITY, ENT_CLIENT_RADARLINK);
1306 WriteByte(MSG_ENTITY, sendflags);
1309 WriteCoord(MSG_ENTITY, self.goalentity.origin_x);
1310 WriteCoord(MSG_ENTITY, self.goalentity.origin_y);
1311 WriteCoord(MSG_ENTITY, self.goalentity.origin_z);
1315 WriteCoord(MSG_ENTITY, self.enemy.origin_x);
1316 WriteCoord(MSG_ENTITY, self.enemy.origin_y);
1317 WriteCoord(MSG_ENTITY, self.enemy.origin_z);
1321 WriteByte(MSG_ENTITY, self.clientcolors); // which is goalentity's color + enemy's color * 16
1326 void onslaught_link_checkupdate()
1328 // TODO check if the two sides have moved (currently they won't move anyway)
1329 float redpower, bluepower;
1331 redpower = bluepower = 0;
1332 if(self.goalentity.islinked)
1334 if(self.goalentity.team == COLOR_TEAM1)
1336 else if(self.goalentity.team == COLOR_TEAM2)
1339 if(self.enemy.islinked)
1341 if(self.enemy.team == COLOR_TEAM1)
1343 else if(self.enemy.team == COLOR_TEAM2)
1348 if(redpower == 1 && bluepower == 2)
1349 cc = (COLOR_TEAM1 - 1) * 0x01 + (COLOR_TEAM2 - 1) * 0x10;
1350 else if(redpower == 2 && bluepower == 1)
1351 cc = (COLOR_TEAM1 - 1) * 0x10 + (COLOR_TEAM2 - 1) * 0x01;
1353 cc = (COLOR_TEAM1 - 1) * 0x11;
1355 cc = (COLOR_TEAM2 - 1) * 0x11;
1359 if(cc != self.clientcolors)
1361 self.clientcolors = cc;
1362 self.SendFlags |= 4;
1365 self.nextthink = time;
1368 void onslaught_link_delayed()
1370 self.goalentity = find(world, targetname, self.target);
1371 self.enemy = find(world, targetname, self.target2);
1372 if (!self.goalentity)
1373 objerror("can not find target\n");
1375 objerror("can not find target2\n");
1376 dprint(etos(self.goalentity), " linked with ", etos(self.enemy), "\n");
1377 self.SendFlags |= 3;
1378 self.think = onslaught_link_checkupdate;
1379 self.nextthink = time;
1382 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
1383 Link between control points.
1385 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.
1388 "target" - first control point.
1389 "target2" - second control point.
1391 void spawnfunc_onslaught_link()
1398 if (self.target == "" || self.target2 == "")
1399 objerror("target and target2 must be set\n");
1400 InitializeEntity(self, onslaught_link_delayed, INITPRIO_FINDTARGET);
1401 Net_LinkEntity(self, FALSE, 0, onslaught_link_send);