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;
19 .string model1, model2, model3;
22 void onslaught_generator_boom_think()
24 self.nextthink = time + 0.05;
27 self.think = SUB_Remove;
33 void onslaught_generator_boom_spawn(vector org, float fscale)
37 setmodel(e, "models/onslaught/boom.md3");
41 setsize(e, e.mins * e.scale, e.maxs * e.scale);
42 e.angles = randomvec() * 360;
44 e.effects = EF_NOSHADOW;
46 e.think = onslaught_generator_boom_think;
47 e.nextthink = time + 0.05;
50 void ons_gib_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce)
52 self.velocity = self.velocity + vforce;
56 void ons_throwgib_think()
60 self.nextthink = time + 0.05;
61 if(self.count > self.giblifetime)
63 self.think = SUB_Remove;
66 if(self.count > self.giblifetime-10)
68 org = self.origin + 20 * randomvec();
69 onslaught_generator_boom_spawn(org, random()*0.5+0.3);
73 void ons_throwgib(vector v_from, vector v_to, string smodel, float f_lifetime, float f_fadetime, float b_burn)
79 setmodel(gib, smodel);
80 setorigin(gib, v_from);
81 gib.solid = SOLID_BBOX;
82 gib.movetype = MOVETYPE_BOUNCE;
83 gib.takedamage = DAMAGE_YES;
84 gib.event_damage = ons_gib_damage;
86 gib.effects = EF_LOWPRECISION;
87 gib.flags = FL_NOTARGET;
89 gib.giblifetime = f_lifetime;
93 gib.think = ons_throwgib_think;
94 gib.nextthink = time + 0.05;
97 SUB_SetFade(gib, time + f_lifetime, 2);
100 void onslaught_updatelinks()
102 local entity l, links;
103 local float stop, t1, t2, t3, t4;
104 // first check if the game has ended
105 dprint("--- updatelinks ---\n");
106 links = findchain(classname, "onslaught_link");
107 // mark generators as being shielded and networked
108 l = findchain(classname, "onslaught_generator");
112 dprint(etos(l), " (generator) belongs to team ", ftos(l.team), "\n");
114 dprint(etos(l), " (generator) is destroyed\n");
115 l.islinked = l.iscaptured;
116 l.isshielded = l.iscaptured;
119 // mark points as shielded and not networked
120 l = findchain(classname, "onslaught_controlpoint");
125 l.isgenneighbor_red = FALSE;
126 l.isgenneighbor_blue = FALSE;
127 l.iscpneighbor_red = FALSE;
128 l.iscpneighbor_blue = FALSE;
129 dprint(etos(l), " (point) belongs to team ", ftos(l.team), "\n");
132 // flow power outward from the generators through the network
136 dprint(etos(l), " (link) connects ", etos(l.goalentity), " with ", etos(l.enemy), "\n");
146 // if both points are captured by the same team, and only one of
147 // them is powered, mark the other one as powered as well
148 if (l.enemy.iscaptured && l.goalentity.iscaptured)
149 if (l.enemy.islinked != l.goalentity.islinked)
150 if (l.enemy.team == l.goalentity.team)
152 if (!l.goalentity.islinked)
155 l.goalentity.islinked = TRUE;
156 dprint(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)\n");
158 else if (!l.enemy.islinked)
161 l.enemy.islinked = TRUE;
162 dprint(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)\n");
168 // now that we know which points are powered we can mark their neighbors
169 // as unshielded if team differs
173 if (l.goalentity.islinked)
175 if (l.goalentity.team != l.enemy.team)
177 dprint(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)\n");
178 l.enemy.isshielded = FALSE;
180 if(l.goalentity.classname == "onslaught_generator")
182 if(l.goalentity.team == COLOR_TEAM1)
183 l.enemy.isgenneighbor_red = TRUE;
184 else if(l.goalentity.team == COLOR_TEAM2)
185 l.enemy.isgenneighbor_blue = TRUE;
189 if(l.goalentity.team == COLOR_TEAM1)
190 l.enemy.iscpneighbor_red = TRUE;
191 else if(l.goalentity.team == COLOR_TEAM2)
192 l.enemy.iscpneighbor_blue = TRUE;
195 if (l.enemy.islinked)
197 if (l.goalentity.team != l.enemy.team)
199 dprint(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)\n");
200 l.goalentity.isshielded = FALSE;
202 if(l.enemy.classname == "onslaught_generator")
204 if(l.enemy.team == COLOR_TEAM1)
205 l.goalentity.isgenneighbor_red = TRUE;
206 else if(l.enemy.team == COLOR_TEAM2)
207 l.goalentity.isgenneighbor_blue = TRUE;
211 if(l.enemy.team == COLOR_TEAM1)
212 l.goalentity.iscpneighbor_red = TRUE;
213 else if(l.enemy.team == COLOR_TEAM2)
214 l.goalentity.iscpneighbor_blue = TRUE;
219 // now update the takedamage and alpha variables on generator shields
220 l = findchain(classname, "onslaught_generator");
225 dprint(etos(l), " (generator) is shielded\n");
227 l.takedamage = DAMAGE_NO;
228 l.bot_attack = FALSE;
232 dprint(etos(l), " (generator) is not shielded\n");
234 l.takedamage = DAMAGE_AIM;
239 // now update the takedamage and alpha variables on control point icons
240 l = findchain(classname, "onslaught_controlpoint");
245 dprint(etos(l), " (point) is shielded\n");
249 l.goalentity.takedamage = DAMAGE_NO;
250 l.goalentity.bot_attack = FALSE;
255 dprint(etos(l), " (point) is not shielded\n");
259 l.goalentity.takedamage = DAMAGE_AIM;
260 l.goalentity.bot_attack = TRUE;
263 onslaught_controlpoint_updatesprite(l);
266 // count generators owned by each team
267 t1 = t2 = t3 = t4 = 0;
268 l = findchain(classname, "onslaught_generator");
273 if (l.team == COLOR_TEAM1) t1 = 1;
274 if (l.team == COLOR_TEAM2) t2 = 1;
275 if (l.team == COLOR_TEAM3) t3 = 1;
276 if (l.team == COLOR_TEAM4) t4 = 1;
278 onslaught_generator_updatesprite(l);
281 // see if multiple teams remain (if not, it's game over)
282 if (t1 + t2 + t3 + t4 < 2)
283 dprint("--- game over ---\n");
285 dprint("--- done updating links ---\n");
288 float onslaught_controlpoint_can_be_linked(entity cp, float t)
292 if(cp.isgenneighbor_red)
294 if(cp.iscpneighbor_red)
297 else if(t == COLOR_TEAM2)
299 if(cp.isgenneighbor_blue)
301 if(cp.iscpneighbor_blue)
307 // check to see if this player has a legitimate claim to capture this
308 // control point - more specifically that there is a captured path of
309 // points leading back to the team generator
310 e = findchain(classname, "onslaught_link");
313 if (e.goalentity == cp)
315 dprint(etos(e), " (link) connects to ", etos(e.enemy), " (point)");
316 if (e.enemy.islinked)
318 dprint(" which is linked");
319 if (e.enemy.team == t)
321 dprint(" and has the correct team!\n");
325 dprint(" but has the wrong team\n");
330 else if (e.enemy == cp)
332 dprint(etos(e), " (link) connects to ", etos(e.goalentity), " (point)");
333 if (e.goalentity.islinked)
335 dprint(" which is linked");
336 if (e.goalentity.team == t)
338 dprint(" and has a team!\n");
342 dprint(" but has the wrong team\n");
353 float onslaught_controlpoint_attackable(entity cp, float t)
354 // -2: SAME TEAM, attackable by enemy!
359 // 3: attack it (HIGH PRIO)
360 // 4: touch it (HIGH PRIO)
368 else if(cp.goalentity)
370 // if there's already an icon built, nothing happens
373 a = onslaught_controlpoint_can_be_linked(cp, COLOR_TEAM1 + COLOR_TEAM2 - t);
374 if(a) // attackable by enemy?
375 return -2; // EMERGENCY!
378 // we know it can be linked, so no need to check
380 a = onslaught_controlpoint_can_be_linked(cp, t);
381 if(a == 2) // near our generator?
382 return 3; // EMERGENCY!
388 if(onslaught_controlpoint_can_be_linked(cp, t))
390 a = onslaught_controlpoint_can_be_linked(cp, COLOR_TEAM1 + COLOR_TEAM2 - t);
392 return 4; // GET THIS ONE NOW!
394 return 2; // TOUCH ME
400 void onslaught_generator_think()
404 self.nextthink = ceil(time + 1);
405 if (cvar("timelimit"))
406 if (time > cvar("timelimit") * 60 - 60)
408 // self.max_health / 300 gives 5 minutes of overtime.
409 // control points reduce the overtime duration.
410 sound(self, CHAN_TRIGGER, "onslaught/generator_decay.wav", VOL_BASE, ATTN_NORM);
412 e = findchain(classname, "onslaught_controlpoint");
415 if (e.team != self.team)
420 d = d * self.max_health / 300;
421 Damage(self, self, self, d, DEATH_HURTTRIGGER, self.origin, '0 0 0');
426 void onslaught_generator_ring_think()
428 self.nextthink = time + 0.05;
431 self.think = SUB_Remove;
435 self.scale = self.count * 4;
437 self.frame = self.count;
443 void onslaught_generator_ring_spawn(vector org)
447 setmodel(e, "models/onslaught/shockwavetransring.md3");
453 e.think = onslaught_generator_ring_think;
454 e.nextthink = time + 0.05;
456 void onslaught_generator_ray_think()
458 self.nextthink = time + 0.05;
461 self.think = SUB_Remove;
474 void onslaught_generator_ray_spawn(vector org)
478 setmodel(e, "models/onslaught/ons_ray.md3");
480 e.angles = randomvec() * 360;
482 e.scale = random() * 5 + 8;
483 e.think = onslaught_generator_ray_think;
484 e.nextthink = time + 0.05;
487 void onslaught_generator_shockwave_think()
489 self.nextthink = time + 0.05;
492 self.think = SUB_Remove;
501 self.scale = self.count * 4;
502 setsize(self, self.mins * self.scale, self.maxs * self.scale);
503 self.frame = self.count;
508 void onslaught_generator_shockwave_spawn(vector org)
512 setmodel(e, "models/onslaught/shockwave.md3");
520 e.think = onslaught_generator_shockwave_think;
521 e.nextthink = time + 0.05;
524 void onslaught_generator_damage_think()
526 if(self.owner.health < 0)
528 self.think = SUB_Remove;
531 self.nextthink = time+0.1;
533 // damaged fx (less probable the more damaged is the generator)
534 if(random() < 0.9 - self.owner.health / self.owner.max_health)
537 pointparticles(particleeffectnum("electro_ballexplode"), self.origin + randompos('-50 -50 -20', '50 50 50'), '0 0 0', 1);
538 sound(self, CHAN_TRIGGER, "onslaught/electricity_explode.wav", VOL_BASE, ATTN_NORM);
541 pointparticles(particleeffectnum("torch_small"), self.origin + randompos('-60 -60 -20', '60 60 60'), '0 0 0', 1);
544 void onslaught_generator_damage_spawn(entity gd_owner)
549 e.health = self.owner.health;
550 setorigin(e, gd_owner.origin);
551 e.think = onslaught_generator_damage_think;
552 e.nextthink = time+1;
555 void onslaught_generator_deaththink()
564 if(self.count==40||self.count==20)
566 onslaught_generator_ring_spawn(self.origin);
567 sound(self, CHAN_TRIGGER, "onslaught/shockwave.wav", VOL_BASE, ATTN_NORM);
575 ons_throwgib(self.origin + '0 0 40', (100 * randomvec() - '1 1 1') * 11 + '0 0 20', "models/onslaught/gen_gib1.md3", 25, 1, 1);
577 ons_throwgib(self.origin + '0 0 40', (100 * randomvec() - '1 1 1') * 12 + '0 0 20', "models/onslaught/gen_gib2.md3", 20, 1, 1);
579 ons_throwgib(self.origin + '0 0 40', (100 * randomvec() - '1 1 1') * 13 + '0 0 20', "models/onslaught/gen_gib3.md3", 15, 1, 1);
585 org = self.origin + randompos('-30 -30 -30' * i + '0 0 -20', '30 30 30' * i + '0 0 20');
586 onslaught_generator_boom_spawn(org, (6-i)/5+0.3);
589 // Short explosion sound + small explosion
592 te_explosion(self.origin);
593 sound(self, CHAN_TRIGGER, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
597 org = self.origin + randompos(self.mins + '8 8 8', self.maxs + '-8 -8 -8');
598 pointparticles(particleeffectnum("onslaught_generator_smallexplosion"), org, '0 0 0', 1);
603 onslaught_generator_ray_spawn(self.origin);
611 onslaught_generator_shockwave_spawn(org);
612 pointparticles(particleeffectnum("onslaught_generator_finalexplosion"), org, '0 0 0', 1);
613 sound(self, CHAN_TRIGGER, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
616 self.nextthink = time + 0.05;
618 self.count = self.count - 1;
621 void onslaught_generator_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
626 if (attacker != self)
630 // this is protected by a shield, so ignore the damage
631 if (time > self.pain_finished)
632 if (attacker.classname == "player")
634 play2(attacker, "onslaught/damageblockedbyshield.wav");
635 self.pain_finished = time + 1;
639 if (time > self.pain_finished)
641 self.pain_finished = time + 10;
642 bprint(ColoredTeamName(self.team), " generator under attack!\n");
643 play2team(self.team, "onslaught/generator_underattack.wav");
646 self.health = self.health - damage;
647 WaypointSprite_UpdateHealth(self.sprite, self.health);
648 // choose an animation frame based on health
649 self.frame = 10 * bound(0, (1 - self.health / self.max_health), 1);
650 // see if the generator is still functional, or dying
653 #ifdef ONSLAUGHT_SPAM
655 lh = ceil(self.lasthealth / 100) * 100;
656 h = ceil(self.health / 100) * 100;
658 bprint(ColoredTeamName(self.team), " generator has less than ", ftos(h), " health remaining\n");
660 self.lasthealth = self.health;
664 if (attacker == self)
665 bprint(ColoredTeamName(self.team), " generator spontaneously exploded due to overtime!\n");
669 t = ColoredTeamName(attacker.team);
670 bprint(ColoredTeamName(self.team), " generator destroyed by ", t, "!\n");
672 self.iscaptured = FALSE;
673 self.islinked = FALSE;
674 self.isshielded = FALSE;
675 self.takedamage = DAMAGE_NO; // can't be hurt anymore
676 self.event_damage = SUB_Null; // won't do anything if hurt
677 self.count = 0; // reset counter
678 self.think = onslaught_generator_deaththink; // explosion sequence
679 self.nextthink = time; // start exploding immediately
680 self.think(); // do the first explosion now
682 WaypointSprite_UpdateMaxHealth(self.sprite, 0);
684 onslaught_updatelinks();
687 setmodel(self, "models/onslaught/generator_dead.md3");
688 else if(self.health < self.max_health * 0.10)
689 setmodel(self, "models/onslaught/generator_dmg9.md3");
690 else if(self.health < self.max_health * 0.20)
691 setmodel(self, "models/onslaught/generator_dmg8.md3");
692 else if(self.health < self.max_health * 0.30)
693 setmodel(self, "models/onslaught/generator_dmg7.md3");
694 else if(self.health < self.max_health * 0.40)
695 setmodel(self, "models/onslaught/generator_dmg6.md3");
696 else if(self.health < self.max_health * 0.50)
697 setmodel(self, "models/onslaught/generator_dmg5.md3");
698 else if(self.health < self.max_health * 0.60)
699 setmodel(self, "models/onslaught/generator_dmg4.md3");
700 else if(self.health < self.max_health * 0.70)
701 setmodel(self, "models/onslaught/generator_dmg3.md3");
702 else if(self.health < self.max_health * 0.80)
703 setmodel(self, "models/onslaught/generator_dmg2.md3");
704 else if(self.health < self.max_health * 0.90)
705 setmodel(self, "models/onslaught/generator_dmg1.md3");
706 setsize(self, '-52 -52 -14', '52 52 75');
708 // Throw some flaming gibs on damage, more damage = more chance for gib
709 if(random() < damage/220)
711 sound(self, CHAN_TRIGGER, "weapons/rocket_impact.wav", VOL_BASE, ATTN_NORM);
714 ons_throwgib(hitloc, (force * -1) + '0 0 40', "models/onslaught/gen_gib1.md3", 7, 1, 1);
716 ons_throwgib(hitloc, (force * -1)+ '0 0 40', "models/onslaught/gen_gib2.md3", 6, 1, 1);
718 ons_throwgib(hitloc, (force * -1)+ '0 0 40', "models/onslaught/gen_gib3.md3", 5, 1, 1);
722 // particles on every hit
723 pointparticles(particleeffectnum("sparks"), hitloc, force * -1, 1);
727 sound(self, CHAN_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE, ATTN_NORM);
729 sound(self, CHAN_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE, ATTN_NORM);
732 //throw some gibs on damage
733 if(random() < damage/200+0.2)
735 ons_throwgib(hitloc, randomvec()*360, "models/onslaught/gen_gib1.md3", 1, 1, 0);
738 // update links after a delay
739 void onslaught_generator_delayed()
741 onslaught_updatelinks();
742 // now begin normal thinking
743 self.think = onslaught_generator_think;
744 self.nextthink = time;
747 string onslaught_generator_waypointsprite_for_team(entity e, float t)
751 if(e.team == COLOR_TEAM1)
752 return "ons-gen-red";
753 else if(e.team == COLOR_TEAM2)
754 return "ons-gen-blue";
757 return "ons-gen-shielded";
758 if(e.team == COLOR_TEAM1)
759 return "ons-gen-red";
760 else if(e.team == COLOR_TEAM2)
761 return "ons-gen-blue";
765 void onslaught_generator_updatesprite(entity e)
768 s1 = onslaught_generator_waypointsprite_for_team(e, COLOR_TEAM1);
769 s2 = onslaught_generator_waypointsprite_for_team(e, COLOR_TEAM2);
770 s3 = onslaught_generator_waypointsprite_for_team(e, -1);
771 WaypointSprite_UpdateSprites(e.sprite, s1, s2, s3);
773 if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
775 e.lastteam = e.team + 2;
776 e.lastshielded = e.isshielded;
779 if(e.team == COLOR_TEAM1 || e.team == COLOR_TEAM2)
780 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, FALSE));
782 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
786 if(e.team == COLOR_TEAM1 || e.team == COLOR_TEAM2)
787 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, FALSE));
789 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
791 WaypointSprite_Ping(e.sprite);
795 string onslaught_controlpoint_waypointsprite_for_team(entity e, float t)
800 a = onslaught_controlpoint_attackable(e, t);
801 if(a == 3 || a == 4) // ATTACK/TOUCH THIS ONE NOW
803 if(e.team == COLOR_TEAM1)
804 return "ons-cp-atck-red";
805 else if(e.team == COLOR_TEAM2)
806 return "ons-cp-atck-blue";
808 return "ons-cp-atck-neut";
810 else if(a == -2) // DEFEND THIS ONE NOW
812 if(e.team == COLOR_TEAM1)
813 return "ons-cp-dfnd-red";
814 else if(e.team == COLOR_TEAM2)
815 return "ons-cp-dfnd-blue";
817 else if(e.team == t || a == -1 || a == 1) // own point, or fire at it
819 if(e.team == COLOR_TEAM1)
821 else if(e.team == COLOR_TEAM2)
822 return "ons-cp-blue";
824 else if(a == 2) // touch it
825 return "ons-cp-neut";
829 if(e.team == COLOR_TEAM1)
831 else if(e.team == COLOR_TEAM2)
832 return "ons-cp-blue";
834 return "ons-cp-neut";
839 void onslaught_controlpoint_updatesprite(entity e)
842 s1 = onslaught_controlpoint_waypointsprite_for_team(e, COLOR_TEAM1);
843 s2 = onslaught_controlpoint_waypointsprite_for_team(e, COLOR_TEAM2);
844 s3 = onslaught_controlpoint_waypointsprite_for_team(e, -1);
845 WaypointSprite_UpdateSprites(e.sprite, s1, s2, s3);
848 sh = !(onslaught_controlpoint_can_be_linked(e, COLOR_TEAM1) || onslaught_controlpoint_can_be_linked(e, COLOR_TEAM2));
850 if(e.lastteam != e.team + 2 || e.lastshielded != sh || e.iscaptured != e.lastcaptured)
852 if(e.iscaptured) // don't mess up build bars!
856 WaypointSprite_UpdateMaxHealth(e.sprite, 0);
860 WaypointSprite_UpdateMaxHealth(e.sprite, e.goalentity.max_health);
861 WaypointSprite_UpdateHealth(e.sprite, e.goalentity.health);
866 if(e.team == COLOR_TEAM1 || e.team == COLOR_TEAM2)
867 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, FALSE));
869 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
873 if(e.team == COLOR_TEAM1 || e.team == COLOR_TEAM2)
874 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, FALSE));
876 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
878 WaypointSprite_Ping(e.sprite);
880 e.lastteam = e.team + 2;
882 e.lastcaptured = e.iscaptured;
886 void onslaught_generator_reset()
888 self.team = self.team_saved;
889 self.lasthealth = self.max_health = self.health = cvar("g_onslaught_gen_health");
890 self.takedamage = DAMAGE_AIM;
891 self.bot_attack = TRUE;
892 self.iscaptured = TRUE;
893 self.islinked = TRUE;
894 self.isshielded = TRUE;
895 self.enemy.solid = SOLID_NOT;
896 self.think = onslaught_generator_delayed;
897 self.nextthink = time + 0.2;
898 setmodel(self, "models/onslaught/generator.md3");
900 WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
901 WaypointSprite_UpdateHealth(self.sprite, self.health);
904 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
907 spawnfunc_onslaught_link entities can target this.
910 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
911 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
913 void spawnfunc_onslaught_generator()
922 precache_model("models/onslaught/generator.md3");
923 precache_model("models/onslaught/generator_shield.md3");
924 precache_model("models/onslaught/generator_dmg1.md3");
925 precache_model("models/onslaught/generator_dmg2.md3");
926 precache_model("models/onslaught/generator_dmg3.md3");
927 precache_model("models/onslaught/generator_dmg4.md3");
928 precache_model("models/onslaught/generator_dmg5.md3");
929 precache_model("models/onslaught/generator_dmg6.md3");
930 precache_model("models/onslaught/generator_dmg7.md3");
931 precache_model("models/onslaught/generator_dmg8.md3");
932 precache_model("models/onslaught/generator_dmg9.md3");
933 precache_model("models/onslaught/generator_dead.md3");
934 precache_model("models/onslaught/boom.md3");
935 precache_model("models/onslaught/shockwave.md3");
936 precache_model("models/onslaught/shockwavetransring.md3");
937 precache_model("models/onslaught/gen_gib1.md3");
938 precache_model("models/onslaught/gen_gib2.md3");
939 precache_model("models/onslaught/gen_gib3.md3");
940 precache_model("models/onslaught/ons_ray.md3");
941 precache_sound("onslaught/generator_decay.wav");
942 precache_sound("weapons/grenade_impact.wav");
943 precache_sound("weapons/rocket_impact.wav");
944 precache_sound("onslaught/generator_underattack.wav");
945 precache_sound("onslaught/shockwave.wav");
946 precache_sound("onslaught/ons_hit1.wav");
947 precache_sound("onslaught/ons_hit2.wav");
948 precache_sound("onslaught/electricity_explode.wav");
950 objerror("team must be set");
951 self.team_saved = self.team;
952 self.colormap = 1024 + (self.team - 1) * 17;
953 self.solid = SOLID_BBOX;
954 self.movetype = MOVETYPE_NONE;
955 self.lasthealth = self.max_health = self.health = cvar("g_onslaught_gen_health");
956 setmodel(self, "models/onslaught/generator.md3");
957 setsize(self, '-52 -52 -14', '52 52 75');
958 setorigin(self, self.origin);
959 self.takedamage = DAMAGE_AIM;
960 self.bot_attack = TRUE;
961 self.event_damage = onslaught_generator_damage;
962 self.iscaptured = TRUE;
963 self.islinked = TRUE;
964 self.isshielded = TRUE;
965 // helper entity that create fx when generator is damaged
966 onslaught_generator_damage_spawn(self);
967 // spawn shield model which indicates whether this can be damaged
968 self.enemy = e = spawn();
969 e.classname = "onslaught_generator_shield";
971 e.movetype = MOVETYPE_NONE;
972 e.effects = EF_ADDITIVE;
973 setmodel(e, "models/onslaught/generator_shield.md3");
974 setorigin(e, self.origin);
975 e.colormap = self.colormap;
977 self.think = onslaught_generator_delayed;
978 self.nextthink = time + 0.2;
979 InitializeEntity(self, onslaught_generator_delayed, INITPRIO_LAST);
981 WaypointSprite_SpawnFixed(string_null, e.origin + '0 0 1' * e.maxs_z, self, sprite);
982 WaypointSprite_UpdateRule(self.sprite, COLOR_TEAM2, SPRITERULE_TEAMPLAY);
983 WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
984 WaypointSprite_UpdateHealth(self.sprite, self.health);
986 waypoint_spawnforitem(self);
988 onslaught_updatelinks();
990 self.reset = onslaught_generator_reset;
995 .vector cp_origin, cp_bob_origin, cp_bob_dmg;
997 float ons_notification_time_team1;
998 float ons_notification_time_team2;
1000 void onslaught_controlpoint_icon_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
1007 if (self.owner.isshielded)
1009 // this is protected by a shield, so ignore the damage
1010 if (time > self.pain_finished)
1011 if (attacker.classname == "player")
1013 play2(attacker, "onslaught/damageblockedbyshield.wav");
1014 self.pain_finished = time + 1;
1019 if (attacker.classname == "player")
1021 if(self.team == COLOR_TEAM1)
1023 if(time - ons_notification_time_team1 > 10)
1026 ons_notification_time_team1 = time;
1029 else if(self.team == COLOR_TEAM2)
1031 if(time - ons_notification_time_team2 > 10)
1034 ons_notification_time_team2 = time;
1041 play2team(self.team, "onslaught/controlpoint_underattack.wav");
1044 self.health = self.health - damage;
1045 if(self.owner.iscaptured)
1046 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
1048 WaypointSprite_UpdateBuildFinished(self.owner.sprite, time + (self.max_health - self.health) / (self.count / sys_ticrate));
1049 self.pain_finished = time + 1;
1050 self.punchangle = (2 * randomvec() - '1 1 1') * 45;
1051 self.cp_bob_dmg_z = (2 * random() - 1) * 15;
1052 // colormod flash when shot
1053 self.colormod = '2 2 2';
1054 // particles on every hit
1055 pointparticles(particleeffectnum("sparks"), hitloc, force*-1, 1);
1056 //sound on every hit
1058 sound(self, CHAN_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE+0.3, ATTN_NORM);
1060 sound(self, CHAN_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE+0.3, ATTN_NORM);
1062 if (self.health < 0)
1064 sound(self, CHAN_TRIGGER, "weapons/grenade_impact.wav", VOL_BASE, ATTN_NORM);
1065 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
1068 t = ColoredTeamName(attacker.team);
1069 bprint(ColoredTeamName(self.team), " ", self.message, " control point destroyed by ", t, "\n");
1070 ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 25, "models/onslaught/controlpoint_icon_gib1.md3", 5, 1, 0);
1071 ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 45, "models/onslaught/controlpoint_icon_gib2.md3", 5, 1, 0);
1072 ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 45, "models/onslaught/controlpoint_icon_gib2.md3", 5, 1, 0);
1073 ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 5, 1, 0);
1074 ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 5, 1, 0);
1075 ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 5, 1, 0);
1076 ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 5, 1, 0);
1078 self.owner.goalentity = world;
1079 self.owner.islinked = FALSE;
1080 self.owner.iscaptured = FALSE;
1081 self.owner.team = 0;
1082 self.owner.colormap = 1024;
1084 WaypointSprite_UpdateMaxHealth(self.owner.sprite, 0);
1086 onslaught_updatelinks();
1088 // Use targets now (somebody make sure this is in the right place..)
1096 self.owner.waslinked = self.owner.islinked;
1097 if(self.owner.model != "models/onslaught/controlpoint_pad.md3")
1098 setmodel(self.owner, "models/onslaught/controlpoint_pad.md3");
1099 //setsize(self, '-32 -32 0', '32 32 8');
1105 void onslaught_controlpoint_icon_think()
1108 self.nextthink = time + sys_ticrate;
1109 if (time > self.pain_finished + 5)
1111 if(self.health < self.max_health)
1113 self.health = self.health + self.count;
1114 if (self.health >= self.max_health)
1115 self.health = self.max_health;
1116 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
1119 if (self.health < self.max_health * 0.25)
1120 setmodel(self, "models/onslaught/controlpoint_icon_dmg3.md3");
1121 else if (self.health < self.max_health * 0.50)
1122 setmodel(self, "models/onslaught/controlpoint_icon_dmg2.md3");
1123 else if (self.health < self.max_health * 0.75)
1124 setmodel(self, "models/onslaught/controlpoint_icon_dmg1.md3");
1125 else if (self.health < self.max_health * 0.90)
1126 setmodel(self, "models/onslaught/controlpoint_icon.md3");
1127 // colormod flash when shot
1128 self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));
1130 if(self.owner.islinked != self.owner.waslinked)
1132 // unteam the spawnpoint if needed
1134 t = self.owner.team;
1135 if(!self.owner.islinked)
1136 self.owner.team = 0;
1144 self.owner.team = t;
1146 self.owner.waslinked = self.owner.islinked;
1148 if (self.punchangle_x > 2)
1149 self.punchangle_x = self.punchangle_x - 2;
1150 else if (self.punchangle_x < -2)
1151 self.punchangle_x = self.punchangle_x + 2;
1153 self.punchangle_x = 0;
1154 if (self.punchangle_y > 2)
1155 self.punchangle_y = self.punchangle_y - 2;
1156 else if (self.punchangle_y < -2)
1157 self.punchangle_y = self.punchangle_y + 2;
1159 self.punchangle_y = 0;
1160 if (self.punchangle_z > 2)
1161 self.punchangle_z = self.punchangle_z - 2;
1162 else if (self.punchangle_z < -2)
1163 self.punchangle_z = self.punchangle_z + 2;
1165 self.punchangle_z = 0;
1166 self.angles_x = self.punchangle_x;
1167 self.angles_y = self.punchangle_y + self.mangle_y;
1168 self.angles_z = self.punchangle_z;
1169 self.mangle_y = self.mangle_y + 1.5;
1171 self.cp_bob_origin_z = 4 * PI * (1 - cos(self.cp_bob_spd / 8));
1172 self.cp_bob_spd = self.cp_bob_spd + 0.5;
1173 if(self.cp_bob_dmg_z > 0)
1174 self.cp_bob_dmg_z = self.cp_bob_dmg_z - 0.1;
1176 self.cp_bob_dmg_z = 0;
1177 self.origin = self.cp_origin + self.cp_bob_origin + self.cp_bob_dmg;
1180 if(random() < 0.6 - self.health / self.max_health)
1182 pointparticles(particleeffectnum("electricity_sparks"), self.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
1185 sound(self, CHAN_PAIN, "onslaught/ons_spark1.wav", VOL_BASE, ATTN_NORM);
1186 else if (random() > 0.5)
1187 sound(self, CHAN_PAIN, "onslaught/ons_spark2.wav", VOL_BASE, ATTN_NORM);
1191 void onslaught_controlpoint_icon_buildthink()
1196 self.nextthink = time + sys_ticrate;
1198 // only do this if there is power
1199 a = onslaught_controlpoint_can_be_linked(self.owner, self.owner.team);
1203 self.health = self.health + self.count;
1205 if (self.health >= self.max_health)
1207 self.health = self.max_health;
1208 self.count = cvar("g_onslaught_cp_regen") * sys_ticrate; // slow repair rate from now on
1209 self.think = onslaught_controlpoint_icon_think;
1210 sound(self, CHAN_TRIGGER, "onslaught/controlpoint_built.wav", VOL_BASE, ATTN_NORM);
1211 bprint(ColoredTeamName(self.team), " captured ", self.owner.message, " control point\n");
1212 self.owner.iscaptured = TRUE;
1214 WaypointSprite_UpdateMaxHealth(self.owner.sprite, self.max_health);
1215 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
1217 onslaught_updatelinks();
1219 // Use targets now (somebody make sure this is in the right place..)
1225 self.cp_origin = self.origin;
1226 self.cp_bob_origin = '0 0 0.1';
1227 self.cp_bob_spd = 0;
1229 self.alpha = self.health / self.max_health;
1230 // colormod flash when shot
1231 self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));
1232 if(self.owner.model != "models/onslaught/controlpoint_pad2.md3")
1233 setmodel(self.owner, "models/onslaught/controlpoint_pad2.md3");
1234 //setsize(self, '-32 -32 0', '32 32 8');
1236 if(random() < 0.9 - self.health / self.max_health)
1237 pointparticles(particleeffectnum("rage"), self.origin + 10 * randomvec(), '0 0 -1', 1);
1243 void onslaught_controlpoint_touch()
1247 if (other.classname != "player")
1249 a = onslaught_controlpoint_attackable(self, other.team);
1250 if(a != 2 && a != 4)
1252 // we've verified that this player has a legitimate claim to this point,
1253 // so start building the captured point icon (which only captures this
1254 // point if it successfully builds without being destroyed first)
1255 self.goalentity = e = spawn();
1256 e.classname = "onslaught_controlpoint_icon";
1258 e.max_health = cvar("g_onslaught_cp_health");
1259 e.health = cvar("g_onslaught_cp_buildhealth");
1260 e.solid = SOLID_BBOX;
1261 e.movetype = MOVETYPE_NONE;
1262 setmodel(e, "models/onslaught/controlpoint_icon.md3");
1263 setsize(e, '-32 -32 -32', '32 32 32');
1264 setorigin(e, self.origin + '0 0 96');
1265 e.takedamage = DAMAGE_AIM;
1266 e.bot_attack = TRUE;
1267 e.event_damage = onslaught_controlpoint_icon_damage;
1268 e.team = other.team;
1269 e.colormap = 1024 + (e.team - 1) * 17;
1270 e.think = onslaught_controlpoint_icon_buildthink;
1271 e.nextthink = time + sys_ticrate;
1272 e.count = (e.max_health - e.health) * sys_ticrate / cvar("g_onslaught_cp_buildtime"); // how long it takes to build
1273 sound(e, CHAN_TRIGGER, "onslaught/controlpoint_build.wav", VOL_BASE, ATTN_NORM);
1275 self.colormap = e.colormap;
1276 WaypointSprite_UpdateBuildFinished(self.sprite, time + (e.max_health - e.health) / (e.count / sys_ticrate));
1277 onslaught_updatelinks();
1280 void onslaught_controlpoint_reset()
1282 if(self.goalentity && self.goalentity != world)
1283 remove(self.goalentity);
1284 self.goalentity = world;
1286 self.colormap = 1024;
1287 self.iscaptured = FALSE;
1288 self.islinked = FALSE;
1289 self.isshielded = TRUE;
1290 self.enemy.solid = SOLID_NOT;
1291 self.enemy.colormap = self.colormap;
1292 self.think = self.enemy.think = SUB_Null;
1293 self.nextthink = 0; // don't like SUB_Null :P
1294 setmodel(self, "models/onslaught/controlpoint_pad.md3");
1295 //setsize(self, '-32 -32 0', '32 32 8');
1297 WaypointSprite_UpdateMaxHealth(self.sprite, 0);
1299 onslaught_updatelinks();
1302 SUB_UseTargets(); // to reset the structures, playerspawns etc.
1305 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
1306 Control point. Be sure to give this enough clearance so that the shootable part has room to exist
1308 This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
1311 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
1312 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
1313 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
1315 void spawnfunc_onslaught_controlpoint()
1323 precache_model("models/onslaught/controlpoint_pad.md3");
1324 precache_model("models/onslaught/controlpoint_pad2.md3");
1325 precache_model("models/onslaught/controlpoint_shield.md3");
1326 precache_model("models/onslaught/controlpoint_icon.md3");
1327 precache_model("models/onslaught/controlpoint_icon_dmg1.md3");
1328 precache_model("models/onslaught/controlpoint_icon_dmg2.md3");
1329 precache_model("models/onslaught/controlpoint_icon_dmg3.md3");
1330 precache_model("models/onslaught/controlpoint_icon_gib1.md3");
1331 precache_model("models/onslaught/controlpoint_icon_gib2.md3");
1332 precache_model("models/onslaught/controlpoint_icon_gib4.md3");
1333 precache_sound("onslaught/controlpoint_build.wav");
1334 precache_sound("onslaught/controlpoint_built.wav");
1335 precache_sound("weapons/grenade_impact.wav");
1336 precache_sound("onslaught/damageblockedbyshield.wav");
1337 precache_sound("onslaught/controlpoint_underattack.wav");
1338 precache_sound("onslaught/ons_spark1.wav");
1339 precache_sound("onslaught/ons_spark2.wav");
1340 self.solid = SOLID_BBOX;
1341 self.movetype = MOVETYPE_NONE;
1342 setmodel(self, "models/onslaught/controlpoint_pad.md3");
1343 //setsize(self, '-32 -32 0', '32 32 8');
1344 setorigin(self, self.origin);
1345 self.touch = onslaught_controlpoint_touch;
1347 self.colormap = 1024;
1348 self.iscaptured = FALSE;
1349 self.islinked = FALSE;
1350 self.isshielded = TRUE;
1351 // spawn shield model which indicates whether this can be damaged
1352 self.enemy = e = spawn();
1353 e.classname = "onslaught_controlpoint_shield";
1354 e.solid = SOLID_NOT;
1355 e.movetype = MOVETYPE_NONE;
1356 e.effects = EF_ADDITIVE;
1357 setmodel(e, "models/onslaught/controlpoint_shield.md3");
1358 //setsize(e, '-32 -32 0', '32 32 128');
1359 setorigin(e, self.origin);
1360 e.colormap = self.colormap;
1362 waypoint_spawnforitem(self);
1364 WaypointSprite_SpawnFixed(string_null, e.origin + '0 0 1' * e.maxs_z, self, sprite);
1365 WaypointSprite_UpdateRule(self.sprite, COLOR_TEAM2, SPRITERULE_TEAMPLAY);
1367 onslaught_updatelinks();
1369 self.reset = onslaught_controlpoint_reset;
1372 float onslaught_link_send(entity to, float sendflags)
1374 WriteByte(MSG_ENTITY, ENT_CLIENT_RADARLINK);
1375 WriteByte(MSG_ENTITY, sendflags);
1378 WriteCoord(MSG_ENTITY, self.goalentity.origin_x);
1379 WriteCoord(MSG_ENTITY, self.goalentity.origin_y);
1380 WriteCoord(MSG_ENTITY, self.goalentity.origin_z);
1384 WriteCoord(MSG_ENTITY, self.enemy.origin_x);
1385 WriteCoord(MSG_ENTITY, self.enemy.origin_y);
1386 WriteCoord(MSG_ENTITY, self.enemy.origin_z);
1390 WriteByte(MSG_ENTITY, self.clientcolors); // which is goalentity's color + enemy's color * 16
1395 void onslaught_link_checkupdate()
1397 // TODO check if the two sides have moved (currently they won't move anyway)
1398 float redpower, bluepower;
1400 redpower = bluepower = 0;
1401 if(self.goalentity.islinked)
1403 if(self.goalentity.team == COLOR_TEAM1)
1405 else if(self.goalentity.team == COLOR_TEAM2)
1408 if(self.enemy.islinked)
1410 if(self.enemy.team == COLOR_TEAM1)
1412 else if(self.enemy.team == COLOR_TEAM2)
1417 if(redpower == 1 && bluepower == 2)
1418 cc = (COLOR_TEAM1 - 1) * 0x01 + (COLOR_TEAM2 - 1) * 0x10;
1419 else if(redpower == 2 && bluepower == 1)
1420 cc = (COLOR_TEAM1 - 1) * 0x10 + (COLOR_TEAM2 - 1) * 0x01;
1422 cc = (COLOR_TEAM1 - 1) * 0x11;
1424 cc = (COLOR_TEAM2 - 1) * 0x11;
1428 //print(etos(self), " rp=", ftos(redpower), " bp=", ftos(bluepower), " ");
1429 //print("cc=", ftos(cc), "\n");
1431 if(cc != self.clientcolors)
1433 self.clientcolors = cc;
1434 self.SendFlags |= 4;
1437 self.nextthink = time;
1440 void onslaught_link_delayed()
1442 self.goalentity = find(world, targetname, self.target);
1443 self.enemy = find(world, targetname, self.target2);
1444 if (!self.goalentity)
1445 objerror("can not find target\n");
1447 objerror("can not find target2\n");
1448 dprint(etos(self.goalentity), " linked with ", etos(self.enemy), "\n");
1449 self.SendFlags |= 3;
1450 self.think = onslaught_link_checkupdate;
1451 self.nextthink = time;
1454 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
1455 Link between control points.
1457 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.
1460 "target" - first control point.
1461 "target2" - second control point.
1463 void spawnfunc_onslaught_link()
1470 if (self.target == "" || self.target2 == "")
1471 objerror("target and target2 must be set\n");
1472 InitializeEntity(self, onslaught_link_delayed, INITPRIO_FINDTARGET);
1473 Net_LinkEntity(self, FALSE, 0, onslaught_link_send);