1 // =======================
2 // CaptureShield Functions
3 // =======================
5 float ons_CaptureShield_Customize()
7 if(!self.enemy.isshielded && (onslaught_controlpoint_attackable(self.enemy, other.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return FALSE; }
8 if(SAME_TEAM(self, other)) { return FALSE; }
13 void ons_CaptureShield_Touch()
15 if(!self.enemy.isshielded && (onslaught_controlpoint_attackable(self.enemy, other.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return; }
16 if(!IS_PLAYER(other)) { return; }
17 if(SAME_TEAM(other, self)) { return; }
19 vector mymid = (self.absmin + self.absmax) * 0.5;
20 vector othermid = (other.absmin + other.absmax) * 0.5;
22 Damage(other, self, self, 0, DEATH_HURTTRIGGER, mymid, normalize(othermid - mymid) * ons_captureshield_force);
24 play2(other, "onslaught/damageblockedbyshield.wav");
26 if(self.enemy.classname == "onslaught_generator")
27 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_GENERATOR_SHIELDED);
29 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_CONTROLPOINT_SHIELDED);
32 void ons_CaptureShield_Reset()
34 self.colormap = self.enemy.colormap;
35 self.team = self.enemy.team;
38 void ons_CaptureShield_Spawn(entity generator, string themodel)
40 entity shield = spawn();
42 shield.enemy = generator;
43 shield.team = generator.team;
44 shield.colormap = generator.colormap;
45 shield.reset = ons_CaptureShield_Reset;
46 shield.touch = ons_CaptureShield_Touch;
47 shield.customizeentityforclient = ons_CaptureShield_Customize;
48 shield.classname = "ons_captureshield";
49 shield.effects = EF_ADDITIVE;
50 shield.movetype = MOVETYPE_NOCLIP;
51 shield.solid = SOLID_TRIGGER;
52 shield.avelocity = '7 0 11';
55 setorigin(shield, generator.origin);
56 setmodel(shield, themodel);
57 setsize(shield, shield.scale * shield.mins, shield.scale * shield.maxs);
60 void ons_gib_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce)
62 self.velocity = self.velocity + vforce;
66 void ons_throwgib_think()
70 self.nextthink = time + 0.05;
72 d = self.giblifetime - time;
76 self.think = SUB_Remove;
84 pointparticles(particleeffectnum("onslaught_generator_gib_flame"), self.origin, '0 0 0', 1);
87 void ons_throwgib(vector v_from, vector v_to, string smodel, float f_lifetime, float b_burn)
93 setmodel(gib, smodel);
94 setorigin(gib, v_from);
95 gib.solid = SOLID_CORPSE;
96 gib.movetype = MOVETYPE_BOUNCE;
97 gib.takedamage = DAMAGE_YES;
98 gib.event_damage = ons_gib_damage;
100 gib.effects = EF_LOWPRECISION;
101 gib.flags = FL_NOTARGET;
103 gib.giblifetime = time + f_lifetime;
107 gib.think = ons_throwgib_think;
108 gib.nextthink = time + 0.05;
111 SUB_SetFade(gib, gib.giblifetime, 2);
114 void FixSize(entity e)
116 e.mins_x = rint(e.mins_x);
117 e.mins_y = rint(e.mins_y);
118 e.mins_z = rint(e.mins_z);
120 e.maxs_x = rint(e.maxs_x);
121 e.maxs_y = rint(e.maxs_y);
122 e.maxs_z = rint(e.maxs_z);
125 void setmodel_fixsize(entity e, string m)
131 void onslaught_updatelinks()
134 // first check if the game has ended
135 dprint("--- updatelinks ---\n");
136 links = findchain(classname, "onslaught_link");
137 // mark generators as being shielded and networked
138 l = findchain(classname, "onslaught_generator");
142 dprint(etos(l), " (generator) belongs to team ", ftos(l.team), "\n");
144 dprint(etos(l), " (generator) is destroyed\n");
145 l.islinked = l.iscaptured;
146 l.isshielded = l.iscaptured;
149 // mark points as shielded and not networked
150 l = findchain(classname, "onslaught_controlpoint");
156 for(i = 0; i < 17; ++i) { l.isgenneighbor[i] = FALSE; l.iscpneighbor[i] = FALSE; }
157 dprint(etos(l), " (point) belongs to team ", ftos(l.team), "\n");
160 // flow power outward from the generators through the network
164 dprint(etos(l), " (link) connects ", etos(l.goalentity), " with ", etos(l.enemy), "\n");
174 // if both points are captured by the same team, and only one of
175 // them is powered, mark the other one as powered as well
176 if (l.enemy.iscaptured && l.goalentity.iscaptured)
177 if (l.enemy.islinked != l.goalentity.islinked)
178 if (l.enemy.team == l.goalentity.team)
180 if (!l.goalentity.islinked)
183 l.goalentity.islinked = TRUE;
184 dprint(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)\n");
186 else if (!l.enemy.islinked)
189 l.enemy.islinked = TRUE;
190 dprint(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)\n");
196 // now that we know which points are powered we can mark their neighbors
197 // as unshielded if team differs
201 if (l.goalentity.islinked)
203 if(DIFF_TEAM(l.goalentity, l.enemy))
205 dprint(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)\n");
206 l.enemy.isshielded = FALSE;
208 if(l.goalentity.classname == "onslaught_generator")
209 l.enemy.isgenneighbor[l.goalentity.team] = TRUE;
211 l.enemy.iscpneighbor[l.goalentity.team] = TRUE;
213 if (l.enemy.islinked)
215 if(DIFF_TEAM(l.goalentity, l.enemy))
217 dprint(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)\n");
218 l.goalentity.isshielded = FALSE;
220 if(l.enemy.classname == "onslaught_generator")
221 l.goalentity.isgenneighbor[l.enemy.team] = TRUE;
223 l.goalentity.iscpneighbor[l.enemy.team] = TRUE;
227 // now update the takedamage and alpha variables on generator shields
228 l = findchain(classname, "onslaught_generator");
233 dprint(etos(l), " (generator) is shielded\n");
234 l.takedamage = DAMAGE_NO;
235 l.bot_attack = FALSE;
239 dprint(etos(l), " (generator) is not shielded\n");
240 l.takedamage = DAMAGE_AIM;
245 // now update the takedamage and alpha variables on control point icons
246 l = findchain(classname, "onslaught_controlpoint");
251 dprint(etos(l), " (point) is shielded\n");
254 l.goalentity.takedamage = DAMAGE_NO;
255 l.goalentity.bot_attack = FALSE;
260 dprint(etos(l), " (point) is not shielded\n");
263 l.goalentity.takedamage = DAMAGE_AIM;
264 l.goalentity.bot_attack = TRUE;
267 onslaught_controlpoint_updatesprite(l);
270 // count generators owned by each team
271 float t1 = 0, t2 = 0, t3 = 0, t4 = 0;
272 l = findchain(classname, "onslaught_generator");
279 case NUM_TEAM_1: t1 = 1; break;
280 case NUM_TEAM_2: t2 = 1; break;
281 case NUM_TEAM_3: t3 = 1; break;
282 case NUM_TEAM_4: t4 = 1; break;
285 onslaught_generator_updatesprite(l);
288 l = findchain(classname, "ons_captureshield");
291 l.team = l.enemy.team;
292 l.colormap = l.enemy.colormap;
295 // see if multiple teams remain (if not, it's game over)
296 if (t1 + t2 + t3 + t4 < 2)
297 dprint("--- game over ---\n");
299 dprint("--- done updating links ---\n");
302 float onslaught_controlpoint_can_be_linked(entity cp, float t)
304 if(cp.isgenneighbor[t]) { return 2; }
305 if(cp.iscpneighbor[t]) { return 1; }
310 float onslaught_controlpoint_attackable(entity cp, float t)
311 // -2: SAME TEAM, attackable by enemy!
316 // 3: attack it (HIGH PRIO)
317 // 4: touch it (HIGH PRIO)
325 else if(cp.goalentity)
327 // if there's already an icon built, nothing happens
330 a = onslaught_controlpoint_can_be_linked(cp, t);
331 if(a) // attackable by enemy?
332 return -2; // EMERGENCY!
335 // we know it can be linked, so no need to check
337 a = onslaught_controlpoint_can_be_linked(cp, t);
338 if(a == 2) // near our generator?
339 return 3; // EMERGENCY!
345 if(onslaught_controlpoint_can_be_linked(cp, t))
347 a = onslaught_controlpoint_can_be_linked(cp, t); // why was this here NUM_TEAM_1 + NUM_TEAM_2 - t
349 return 4; // GET THIS ONE NOW!
351 return 2; // TOUCH ME
357 float overtime_msg_time;
358 void onslaught_generator_think()
362 self.nextthink = ceil(time + 1);
365 if (autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60)
367 if (!overtime_msg_time)
369 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT);
370 overtime_msg_time = time;
372 // self.max_health / 300 gives 5 minutes of overtime.
373 // control points reduce the overtime duration.
374 sound(self, CH_TRIGGER, "onslaught/generator_decay.wav", VOL_BASE, ATTEN_NORM);
376 e = findchain(classname, "onslaught_controlpoint");
379 if (e.team != self.team)
385 if(autocvar_g_campaign && autocvar__campaign_testrun)
386 d = d * self.max_health;
388 d = d * self.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
390 Damage(self, self, self, d, DEATH_HURTTRIGGER, self.origin, '0 0 0');
392 else if (overtime_msg_time)
393 overtime_msg_time = 0;
395 if(!self.isshielded && self.wait < time)
397 self.wait = time + 5;
398 FOR_EACH_REALPLAYER(e)
400 if(SAME_TEAM(e, self))
402 Send_Notification(NOTIF_ONE, e, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM);
403 soundto(MSG_ONE, e, CHAN_AUTO, "kh/alarm.wav", VOL_BASE, ATTEN_NONE); // FIXME: unique sound?
406 Send_Notification(NOTIF_ONE, e, MSG_CENTER, APP_TEAM_NUM_4(self.team, CENTER_ONS_NOTSHIELDED_));
412 void onslaught_generator_ring_spawn(vector org)
414 modeleffect_spawn("models/onslaught/shockwavetransring.md3", 0, 0, org, '0 0 0', '0 0 0', '0 0 0', 0, -16, 0.1, 1.25, 0.25);
417 void onslaught_generator_ray_think()
419 self.nextthink = time + 0.05;
422 self.think = SUB_Remove;
435 void onslaught_generator_ray_spawn(vector org)
439 setmodel(e, "models/onslaught/ons_ray.md3");
441 e.angles = randomvec() * 360;
443 e.scale = random() * 5 + 8;
444 e.think = onslaught_generator_ray_think;
445 e.nextthink = time + 0.05;
448 void onslaught_generator_shockwave_spawn(vector org)
450 shockwave_spawn("models/onslaught/shockwave.md3", org, -64, 0.75, 0.5);
453 void onslaught_generator_damage_think()
455 if(self.owner.health < 0)
457 self.think = SUB_Remove;
460 self.nextthink = time+0.1;
462 // damaged fx (less probable the more damaged is the generator)
463 if(random() < 0.9 - self.owner.health / self.owner.max_health)
466 pointparticles(particleeffectnum("electro_ballexplode"), self.origin + randompos('-50 -50 -20', '50 50 50'), '0 0 0', 1);
467 sound(self, CH_TRIGGER, "onslaught/electricity_explode.wav", VOL_BASE, ATTEN_NORM);
470 pointparticles(particleeffectnum("torch_small"), self.origin + randompos('-60 -60 -20', '60 60 60'), '0 0 0', 1);
473 void onslaught_generator_damage_spawn(entity gd_owner)
478 e.health = self.owner.health;
479 setorigin(e, gd_owner.origin);
480 e.think = onslaught_generator_damage_think;
481 e.nextthink = time+1;
484 void onslaught_generator_deaththink()
493 if(self.count==40||self.count==20)
495 onslaught_generator_ring_spawn(self.origin);
496 sound(self, CH_TRIGGER, "onslaught/shockwave.wav", VOL_BASE, ATTEN_NORM);
504 ons_throwgib(self.origin + '0 0 40', (100 * randomvec() - '1 1 1') * 11 + '0 0 20', "models/onslaught/gen_gib1.md3", 6, TRUE);
506 ons_throwgib(self.origin + '0 0 40', (100 * randomvec() - '1 1 1') * 12 + '0 0 20', "models/onslaught/gen_gib2.md3", 6, TRUE);
508 ons_throwgib(self.origin + '0 0 40', (100 * randomvec() - '1 1 1') * 13 + '0 0 20', "models/onslaught/gen_gib3.md3", 6, TRUE);
514 org = self.origin + randompos('-30 -30 -30' * i + '0 0 -20', '30 30 30' * i + '0 0 20');
515 pointparticles(particleeffectnum("onslaught_generator_gib_explode"), org, '0 0 0', 1);
518 // Short explosion sound + small explosion
521 te_explosion(self.origin);
522 sound(self, CH_TRIGGER, "weapons/grenade_impact.wav", VOL_BASE, ATTEN_NORM);
526 org = self.origin + randompos(self.mins + '8 8 8', self.maxs + '-8 -8 -8');
527 pointparticles(particleeffectnum("onslaught_generator_smallexplosion"), org, '0 0 0', 1);
532 onslaught_generator_ray_spawn(self.origin);
540 onslaught_generator_shockwave_spawn(org);
541 pointparticles(particleeffectnum("onslaught_generator_finalexplosion"), org, '0 0 0', 1);
542 sound(self, CH_TRIGGER, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
545 self.nextthink = time + 0.05;
547 self.count = self.count - 1;
550 void onslaught_generator_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
557 if (attacker != self)
561 // this is protected by a shield, so ignore the damage
562 if (time > self.pain_finished)
563 if (IS_PLAYER(attacker))
565 play2(attacker, "onslaught/damageblockedbyshield.wav");
566 self.pain_finished = time + 1;
570 if (time > self.pain_finished)
572 self.pain_finished = time + 10;
574 FOR_EACH_REALPLAYER(head) if(SAME_TEAM(head, self)) { Send_Notification(NOTIF_ONE, head, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK); }
575 play2team(self.team, "onslaught/generator_underattack.wav");
578 self.health = self.health - damage;
579 WaypointSprite_UpdateHealth(self.sprite, self.health);
580 // choose an animation frame based on health
581 self.frame = 10 * bound(0, (1 - self.health / self.max_health), 1);
582 // see if the generator is still functional, or dying
585 self.lasthealth = self.health;
587 else if (!warmup_stage)
589 if (attacker == self)
590 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME_));
593 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_GENDESTROYED_));
594 PlayerScore_Add(attacker, SP_SCORE, 100);
596 self.iscaptured = FALSE;
597 self.islinked = FALSE;
598 self.isshielded = FALSE;
599 self.takedamage = DAMAGE_NO; // can't be hurt anymore
600 self.event_damage = func_null; // won't do anything if hurt
601 self.count = 0; // reset counter
602 self.think = onslaught_generator_deaththink; // explosion sequence
603 self.nextthink = time; // start exploding immediately
604 self.think(); // do the first explosion now
606 WaypointSprite_UpdateMaxHealth(self.sprite, 0);
608 onslaught_updatelinks();
611 // Throw some flaming gibs on damage, more damage = more chance for gib
612 if(random() < damage/220)
614 sound(self, CH_TRIGGER, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
617 ons_throwgib(hitloc + '0 0 20', force * -1, "models/onslaught/gen_gib1.md3", 5, TRUE);
619 ons_throwgib(hitloc + '0 0 20', force * -1, "models/onslaught/gen_gib2.md3", 5, TRUE);
621 ons_throwgib(hitloc + '0 0 20', force * -1, "models/onslaught/gen_gib3.md3", 5, TRUE);
625 // particles on every hit
626 pointparticles(particleeffectnum("sparks"), hitloc, force * -1, 1);
630 sound(self, CH_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE, ATTEN_NORM);
632 sound(self, CH_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM);
635 //throw some gibs on damage
636 if(random() < damage/200+0.2)
638 ons_throwgib(hitloc + '0 0 20', randomvec()*360, "models/onslaught/gen_gib1.md3", 5, FALSE);
640 self.SendFlags |= GSF_STATUS;
643 // update links after a delay
644 void onslaught_generator_delayed()
646 onslaught_updatelinks();
647 // now begin normal thinking
648 generator_link(onslaught_generator_think);
650 self.SendFlags = GSF_SETUP;
653 string onslaught_generator_waypointsprite_for_team(entity e, float t)
657 return "ons-gen-shielded";
660 case NUM_TEAM_1: return "ons-gen-red";
661 case NUM_TEAM_2: return "ons-gen-blue";
662 case NUM_TEAM_3: return "ons-gen-yellow";
663 case NUM_TEAM_4: return "ons-gen-pink";
668 void onslaught_generator_updatesprite(entity e)
671 s1 = onslaught_generator_waypointsprite_for_team(e, NUM_TEAM_1);
672 s2 = onslaught_generator_waypointsprite_for_team(e, NUM_TEAM_2);
673 s3 = onslaught_generator_waypointsprite_for_team(e, -1);
674 WaypointSprite_UpdateSprites(e.sprite, s1, s2, s3);
676 if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
678 e.lastteam = e.team + 2;
679 e.lastshielded = e.isshielded;
682 if(e.team == NUM_TEAM_1 || e.team == NUM_TEAM_2 || e.team == NUM_TEAM_3 || e.team == NUM_TEAM_4)
683 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, FALSE));
685 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
689 if(e.team == NUM_TEAM_1 || e.team == NUM_TEAM_2 || e.team == NUM_TEAM_3 || e.team == NUM_TEAM_4)
690 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, FALSE));
692 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
694 WaypointSprite_Ping(e.sprite);
698 string onslaught_controlpoint_waypointsprite_for_team(entity e, float t)
703 a = onslaught_controlpoint_attackable(e, t);
704 if(a == 3 || a == 4) // ATTACK/TOUCH THIS ONE NOW
708 case NUM_TEAM_1: return "ons-cp-atck-red";
709 case NUM_TEAM_2: return "ons-cp-atck-blue";
710 case NUM_TEAM_3: return "ons-cp-atck-yellow";
711 case NUM_TEAM_4: return "ons-cp-atck-pink";
712 default: return "ons-cp-atck-neut";
715 else if(a == -2) // DEFEND THIS ONE NOW
719 case NUM_TEAM_1: return "ons-cp-dfnd-red";
720 case NUM_TEAM_2: return "ons-cp-dfnd-blue";
721 case NUM_TEAM_3: return "ons-cp-dfnd-yellow";
722 case NUM_TEAM_4: return "ons-cp-dfnd-pink";
725 else if(e.team == t || a == -1 || a == 1) // own point, or fire at it
729 case NUM_TEAM_1: return "ons-cp-red";
730 case NUM_TEAM_2: return "ons-cp-blue";
731 case NUM_TEAM_3: return "ons-cp-yellow";
732 case NUM_TEAM_4: return "ons-cp-pink";
735 else if(a == 2) // touch it
736 return "ons-cp-neut";
742 case NUM_TEAM_1: return "ons-cp-red";
743 case NUM_TEAM_2: return "ons-cp-blue";
744 case NUM_TEAM_3: return "ons-cp-yellow";
745 case NUM_TEAM_4: return "ons-cp-pink";
746 default: return "ons-cp-neut";
752 void onslaught_controlpoint_updatesprite(entity e)
755 s1 = onslaught_controlpoint_waypointsprite_for_team(e, NUM_TEAM_1);
756 s2 = onslaught_controlpoint_waypointsprite_for_team(e, NUM_TEAM_2);
757 s3 = onslaught_controlpoint_waypointsprite_for_team(e, -1);
758 WaypointSprite_UpdateSprites(e.sprite, s1, s2, s3);
761 sh = !(onslaught_controlpoint_can_be_linked(e, NUM_TEAM_1) || onslaught_controlpoint_can_be_linked(e, NUM_TEAM_2));
763 if(e.lastteam != e.team + 2 || e.lastshielded != sh || e.iscaptured != e.lastcaptured)
765 if(e.iscaptured) // don't mess up build bars!
769 WaypointSprite_UpdateMaxHealth(e.sprite, 0);
773 WaypointSprite_UpdateMaxHealth(e.sprite, e.goalentity.max_health);
774 WaypointSprite_UpdateHealth(e.sprite, e.goalentity.health);
779 if(e.team == NUM_TEAM_1 || e.team == NUM_TEAM_2 || e.team == NUM_TEAM_3 || e.team == NUM_TEAM_4)
780 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, FALSE));
782 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
786 if(e.team == NUM_TEAM_1 || e.team == NUM_TEAM_2 || e.team == NUM_TEAM_3 || e.team == NUM_TEAM_4)
787 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, FALSE));
789 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
791 WaypointSprite_Ping(e.sprite);
793 e.lastteam = e.team + 2;
795 e.lastcaptured = e.iscaptured;
799 void onslaught_generator_reset()
801 self.team = self.team_saved;
802 self.lasthealth = self.max_health = self.health = autocvar_g_onslaught_gen_health;
803 self.takedamage = DAMAGE_AIM;
804 self.bot_attack = TRUE;
805 self.iscaptured = TRUE;
806 self.islinked = TRUE;
807 self.isshielded = TRUE;
808 self.think = onslaught_generator_delayed;
809 self.nextthink = time + 0.2;
810 setmodel(self, "models/onslaught/generator.md3");
811 setsize(self, GENERATOR_MIN, GENERATOR_MAX);
813 self.SendFlags |= GSF_STATUS;
817 setorigin(self, self.origin + '0 0 20');
821 WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
822 WaypointSprite_UpdateHealth(self.sprite, self.health);
825 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
828 spawnfunc_onslaught_link entities can target this.
831 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
832 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
834 void spawnfunc_onslaught_generator()
836 if(!g_onslaught) { remove(self); return; }
839 precache_model("models/onslaught/generator.md3");
840 precache_model("models/onslaught/generator_shield.md3");
841 precache_model("models/onslaught/shockwave.md3");
842 precache_model("models/onslaught/shockwavetransring.md3");
843 precache_model("models/onslaught/gen_gib1.md3");
844 precache_model("models/onslaught/gen_gib2.md3");
845 precache_model("models/onslaught/gen_gib3.md3");
846 precache_model("models/onslaught/ons_ray.md3");
847 precache_sound("onslaught/generator_decay.wav");
848 precache_sound("weapons/grenade_impact.wav");
849 precache_sound("weapons/rocket_impact.wav");
850 precache_sound("onslaught/generator_underattack.wav");
851 precache_sound("onslaught/shockwave.wav");
852 precache_sound("onslaught/ons_hit1.wav");
853 precache_sound("onslaught/ons_hit2.wav");
854 precache_sound("onslaught/electricity_explode.wav");
855 precache_sound("onslaught/generator_underattack.wav");
857 objerror("team must be set");
859 ons_generator[self.team] = self;
860 self.team_saved = self.team;
861 self.colormap = 1024 + (self.team - 1) * 17;
862 self.solid = SOLID_BBOX;
863 self.movetype = MOVETYPE_NONE;
864 self.lasthealth = self.max_health = self.health = autocvar_g_onslaught_gen_health;
865 setmodel(self, "models/onslaught/generator.md3");
866 setsize(self, GENERATOR_MIN, GENERATOR_MAX);
867 setorigin(self, self.origin);
868 self.takedamage = DAMAGE_AIM;
869 self.bot_attack = TRUE;
870 self.event_damage = onslaught_generator_damage;
871 self.iscaptured = TRUE;
872 self.islinked = TRUE;
873 self.isshielded = TRUE;
874 // helper entity that create fx when generator is damaged
875 onslaught_generator_damage_spawn(self);
877 ons_CaptureShield_Spawn(self, "models/onslaught/generator_shield.md3");
879 InitializeEntity(self, onslaught_generator_delayed, INITPRIO_LAST);
881 WaypointSprite_SpawnFixed(string_null, self.origin + '0 0 128', self, sprite, RADARICON_NONE, '0 0 0');
882 WaypointSprite_UpdateRule(self.sprite, NUM_TEAM_2, SPRITERULE_TEAMPLAY);
883 WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
884 WaypointSprite_UpdateHealth(self.sprite, self.health);
886 waypoint_spawnforitem(self);
888 onslaught_updatelinks();
890 self.reset = onslaught_generator_reset;
895 void onslaught_controlpoint_icon_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
901 if (self.owner.isshielded)
903 // this is protected by a shield, so ignore the damage
904 if (time > self.pain_finished)
905 if (IS_PLAYER(attacker))
907 play2(attacker, "onslaught/damageblockedbyshield.wav");
908 self.pain_finished = time + 1;
913 if(IS_PLAYER(attacker))
914 if(time - ons_notification_time[self.team] > 10)
916 play2team(self.team, "onslaught/controlpoint_underattack.wav");
917 ons_notification_time[self.team] = time;
920 self.health = self.health - damage;
921 if(self.owner.iscaptured)
922 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
924 WaypointSprite_UpdateBuildFinished(self.owner.sprite, time + (self.max_health - self.health) / (self.count / CP_THINKRATE));
925 self.pain_finished = time + 1;
926 // particles on every hit
927 pointparticles(particleeffectnum("sparks"), hitloc, force*-1, 1);
930 sound(self, CH_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE+0.3, ATTEN_NORM);
932 sound(self, CH_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE+0.3, ATTEN_NORM);
936 sound(self, CH_TRIGGER, "weapons/grenade_impact.wav", VOL_BASE, ATTEN_NORM);
937 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
939 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_CPDESTROYED_), self.owner.message, attacker.netname);
940 ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 25, "models/onslaught/controlpoint_icon_gib1.md3", 3, FALSE);
941 ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 45, "models/onslaught/controlpoint_icon_gib2.md3", 3, FALSE);
942 ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 45, "models/onslaught/controlpoint_icon_gib2.md3", 3, FALSE);
943 ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 3, FALSE);
944 ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 3, FALSE);
945 ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 3, FALSE);
946 ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 3, FALSE);
949 PlayerScore_Add(attacker, SP_ONS_TAKES, 1);
950 PlayerScore_Add(attacker, SP_SCORE, 10);
952 self.owner.goalentity = world;
953 self.owner.islinked = FALSE;
954 self.owner.iscaptured = FALSE;
956 self.owner.colormap = 1024;
958 WaypointSprite_UpdateMaxHealth(self.owner.sprite, 0);
960 onslaught_updatelinks();
962 // Use targets now (somebody make sure this is in the right place..)
969 self.owner.waslinked = self.owner.islinked;
970 if(self.owner.model != "models/onslaught/controlpoint_pad.md3")
971 setmodel_fixsize(self.owner, "models/onslaught/controlpoint_pad.md3");
976 self.SendFlags |= CPSF_STATUS;
979 void onslaught_controlpoint_icon_think()
982 self.nextthink = time + CP_THINKRATE;
984 if(autocvar_g_onslaught_cp_proxydecap)
986 float _enemy_count = 0;
987 float _friendly_count = 0;
991 FOR_EACH_PLAYER(_player)
993 if(!_player.deadflag)
995 _dist = vlen(_player.origin - self.origin);
996 if(_dist < autocvar_g_onslaught_cp_proxydecap_distance)
998 if(SAME_TEAM(_player, self))
1006 _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * CP_THINKRATE);
1007 _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * CP_THINKRATE);
1009 self.health = bound(0, self.health + (_friendly_count - _enemy_count), self.max_health);
1010 self.SendFlags |= CPSF_STATUS;
1011 if(self.health <= 0)
1013 onslaught_controlpoint_icon_damage(self, self, 1, 0, self.origin, '0 0 0');
1018 if (time > self.pain_finished + 5)
1020 if(self.health < self.max_health)
1022 self.health = self.health + self.count;
1023 if (self.health >= self.max_health)
1024 self.health = self.max_health;
1025 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
1029 if(self.owner.islinked != self.owner.waslinked)
1031 // unteam the spawnpoint if needed
1033 t = self.owner.team;
1034 if(!self.owner.islinked)
1035 self.owner.team = 0;
1043 self.owner.team = t;
1045 self.owner.waslinked = self.owner.islinked;
1049 if(random() < 0.6 - self.health / self.max_health)
1051 pointparticles(particleeffectnum("electricity_sparks"), self.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
1054 sound(self, CH_PAIN, "onslaught/ons_spark1.wav", VOL_BASE, ATTEN_NORM);
1055 else if (random() > 0.5)
1056 sound(self, CH_PAIN, "onslaught/ons_spark2.wav", VOL_BASE, ATTEN_NORM);
1060 void onslaught_controlpoint_icon_buildthink()
1065 self.nextthink = time + CP_THINKRATE;
1067 // only do this if there is power
1068 a = onslaught_controlpoint_can_be_linked(self.owner, self.owner.team);
1072 self.health = self.health + self.count;
1074 self.SendFlags |= CPSF_STATUS;
1076 if (self.health >= self.max_health)
1078 self.health = self.max_health;
1079 self.count = autocvar_g_onslaught_cp_regen * CP_THINKRATE; // slow repair rate from now on
1080 self.think = onslaught_controlpoint_icon_think;
1081 sound(self, CH_TRIGGER, "onslaught/controlpoint_built.wav", VOL_BASE, ATTEN_NORM);
1082 self.owner.iscaptured = TRUE;
1083 self.solid = SOLID_BBOX;
1085 WaypointSprite_UpdateMaxHealth(self.owner.sprite, self.max_health);
1086 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
1088 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ONSLAUGHT_CAPTURE, self.owner.ons_toucher.netname, self.owner.message);
1089 Send_Notification(NOTIF_ALL_EXCEPT, self.owner.ons_toucher, MSG_CENTER, APP_TEAM_ENT_4(self.owner.ons_toucher, CENTER_ONS_CAPTURE_), self.owner.message);
1090 Send_Notification(NOTIF_ONE, self.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE, self.owner.message);
1091 PlayerTeamScore_Add(self.owner.ons_toucher, SP_ONS_CAPS, ST_ONS_CAPS, 1);
1092 PlayerTeamScore_AddScore(self.owner.ons_toucher, 10);
1094 self.owner.ons_toucher = world;
1096 onslaught_updatelinks();
1098 // Use targets now (somebody make sure this is in the right place..)
1105 self.SendFlags |= CPSF_SETUP;
1107 if(self.owner.model != "models/onslaught/controlpoint_pad2.md3")
1108 setmodel_fixsize(self.owner, "models/onslaught/controlpoint_pad2.md3");
1110 if(random() < 0.9 - self.health / self.max_health)
1111 pointparticles(particleeffectnum("rage"), self.origin + 10 * randomvec(), '0 0 -1', 1);
1114 void onslaught_controlpoint_touch()
1116 entity e, toucher = other;
1119 if((toucher.vehicle_flags & VHF_ISVEHICLE) && toucher.owner)
1120 if(autocvar_g_onslaught_allow_vehicle_touch)
1121 toucher = toucher.owner;
1125 if(!IS_PLAYER(toucher)) { return; }
1127 a = onslaught_controlpoint_attackable(self, other.team);
1128 if(a != 2 && a != 4)
1130 // we've verified that this player has a legitimate claim to this point,
1131 // so start building the captured point icon (which only captures this
1132 // point if it successfully builds without being destroyed first)
1133 self.goalentity = e = spawn();
1134 e.classname = "onslaught_controlpoint_icon";
1136 e.max_health = autocvar_g_onslaught_cp_health;
1137 e.health = autocvar_g_onslaught_cp_buildhealth;
1138 e.solid = SOLID_NOT;
1139 e.movetype = MOVETYPE_NONE;
1140 //setmodel(e, "models/onslaught/controlpoint_icon.md3");
1141 setsize(e, CPICON_MIN, CPICON_MAX);
1142 setorigin(e, self.origin + '0 0 96');
1143 e.takedamage = DAMAGE_AIM;
1144 e.bot_attack = TRUE;
1145 e.event_damage = onslaught_controlpoint_icon_damage;
1146 e.team = other.team;
1147 e.colormap = 1024 + (e.team - 1) * 17;
1148 e.count = (e.max_health - e.health) * CP_THINKRATE / autocvar_g_onslaught_cp_buildtime; // how long it takes to build
1149 sound(e, CH_TRIGGER, "onslaught/controlpoint_build.wav", VOL_BASE, ATTEN_NORM);
1151 self.colormap = e.colormap;
1152 WaypointSprite_UpdateBuildFinished(self.sprite, time + (e.max_health - e.health) / (e.count / CP_THINKRATE));
1153 self.ons_toucher = other;
1154 onslaught_updatelinks();
1156 onslaught_controlpoint_icon_link(e, onslaught_controlpoint_icon_buildthink);
1159 void onslaught_controlpoint_think()
1161 self.nextthink = time + CP_THINKRATE;
1162 CSQCMODEL_AUTOUPDATE();
1165 void onslaught_controlpoint_reset()
1167 if(self.goalentity && self.goalentity != world)
1168 remove(self.goalentity);
1169 self.goalentity = world;
1171 self.colormap = 1024;
1172 self.iscaptured = FALSE;
1173 self.islinked = FALSE;
1174 self.isshielded = TRUE;
1175 self.think = onslaught_controlpoint_think;
1176 self.ons_toucher = world;
1177 self.nextthink = time + CP_THINKRATE; // don't like func_null :P
1178 setmodel_fixsize(self, "models/onslaught/controlpoint_pad.md3");
1179 //setsize(self, '-32 -32 0', '32 32 8');
1181 WaypointSprite_UpdateMaxHealth(self.sprite, 0);
1183 onslaught_updatelinks();
1186 SUB_UseTargets(); // to reset the structures, playerspawns etc.
1188 CSQCMODEL_AUTOUPDATE();
1191 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
1192 Control point. Be sure to give this enough clearance so that the shootable part has room to exist
1194 This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
1197 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
1198 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
1199 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
1202 void spawnfunc_onslaught_controlpoint()
1204 if(!g_onslaught) { remove(self); return; }
1206 precache_model("models/onslaught/controlpoint_pad.md3");
1207 precache_model("models/onslaught/controlpoint_pad2.md3");
1208 precache_model("models/onslaught/controlpoint_shield.md3");
1209 precache_model("models/onslaught/controlpoint_icon.md3");
1210 precache_model("models/onslaught/controlpoint_icon_dmg1.md3");
1211 precache_model("models/onslaught/controlpoint_icon_dmg2.md3");
1212 precache_model("models/onslaught/controlpoint_icon_dmg3.md3");
1213 precache_model("models/onslaught/controlpoint_icon_gib1.md3");
1214 precache_model("models/onslaught/controlpoint_icon_gib2.md3");
1215 precache_model("models/onslaught/controlpoint_icon_gib4.md3");
1216 precache_sound("onslaught/controlpoint_build.wav");
1217 precache_sound("onslaught/controlpoint_built.wav");
1218 precache_sound("weapons/grenade_impact.wav");
1219 precache_sound("onslaught/damageblockedbyshield.wav");
1220 precache_sound("onslaught/controlpoint_underattack.wav");
1221 precache_sound("onslaught/ons_spark1.wav");
1222 precache_sound("onslaught/ons_spark2.wav");
1224 self.solid = SOLID_BBOX;
1225 self.movetype = MOVETYPE_NONE;
1226 setmodel_fixsize(self, "models/onslaught/controlpoint_pad.md3");
1229 setorigin(self, self.origin + '0 0 20');
1232 self.touch = onslaught_controlpoint_touch;
1234 self.colormap = 1024;
1235 self.iscaptured = FALSE;
1236 self.islinked = FALSE;
1237 self.isshielded = TRUE;
1239 if(self.message == "") { self.message = "a"; }
1241 waypoint_spawnforitem(self);
1243 self.think = onslaught_controlpoint_think;
1244 self.nextthink = time + CP_THINKRATE;
1246 self.reset = onslaught_controlpoint_reset;
1248 WaypointSprite_SpawnFixed(string_null, self.origin + '0 0 128', self, sprite, RADARICON_NONE, '0 0 0');
1249 WaypointSprite_UpdateRule(self.sprite, NUM_TEAM_2, SPRITERULE_TEAMPLAY);
1251 onslaught_updatelinks();
1253 ons_CaptureShield_Spawn(self, "models/onslaught/controlpoint_shield.md3");
1255 CSQCMODEL_AUTOINIT();
1258 float onslaught_link_send(entity to, float sendflags)
1260 WriteByte(MSG_ENTITY, ENT_CLIENT_RADARLINK);
1261 WriteByte(MSG_ENTITY, sendflags);
1264 WriteCoord(MSG_ENTITY, self.goalentity.origin_x);
1265 WriteCoord(MSG_ENTITY, self.goalentity.origin_y);
1266 WriteCoord(MSG_ENTITY, self.goalentity.origin_z);
1270 WriteCoord(MSG_ENTITY, self.enemy.origin_x);
1271 WriteCoord(MSG_ENTITY, self.enemy.origin_y);
1272 WriteCoord(MSG_ENTITY, self.enemy.origin_z);
1276 WriteByte(MSG_ENTITY, self.clientcolors); // which is goalentity's color + enemy's color * 16
1281 void onslaught_link_checkupdate()
1283 // TODO check if the two sides have moved (currently they won't move anyway)
1284 float redpower, bluepower;
1286 redpower = bluepower = 0;
1287 if(self.goalentity.islinked)
1289 switch(self.goalentity.team)
1291 case NUM_TEAM_1: redpower = 1; break;
1292 case NUM_TEAM_2: bluepower = 1; break;
1295 if(self.enemy.islinked)
1297 switch(self.enemy.team)
1299 case NUM_TEAM_1: redpower = 2; break;
1300 case NUM_TEAM_2: bluepower = 2; break;
1305 if(redpower == 1 && bluepower == 2)
1306 cc = (NUM_TEAM_1 - 1) * 0x01 + (NUM_TEAM_2 - 1) * 0x10;
1307 else if(redpower == 2 && bluepower == 1)
1308 cc = (NUM_TEAM_1 - 1) * 0x10 + (NUM_TEAM_2 - 1) * 0x01;
1310 cc = (NUM_TEAM_1 - 1) * 0x11;
1312 cc = (NUM_TEAM_2 - 1) * 0x11;
1316 //print(etos(self), " rp=", ftos(redpower), " bp=", ftos(bluepower), " ");
1317 //print("cc=", ftos(cc), "\n");
1319 if(cc != self.clientcolors)
1321 self.clientcolors = cc;
1322 self.SendFlags |= 4;
1325 self.nextthink = time;
1328 void onslaught_link_delayed()
1330 self.goalentity = find(world, targetname, self.target);
1331 self.enemy = find(world, targetname, self.target2);
1332 if (!self.goalentity)
1333 objerror("can not find target\n");
1335 objerror("can not find target2\n");
1336 dprint(etos(self.goalentity), " linked with ", etos(self.enemy), "\n");
1337 self.SendFlags |= 3;
1338 self.think = onslaught_link_checkupdate;
1339 self.nextthink = time;
1342 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
1343 Link between control points.
1345 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.
1348 "target" - first control point.
1349 "target2" - second control point.
1351 void spawnfunc_onslaught_link()
1358 if (self.target == "" || self.target2 == "")
1359 objerror("target and target2 must be set\n");
1360 InitializeEntity(self, onslaught_link_delayed, INITPRIO_FINDTARGET);
1361 Net_LinkEntity(self, FALSE, 0, onslaught_link_send);
1365 #define HAVOCBOT_ONS_ROLE_NONE 0
1366 #define HAVOCBOT_ONS_ROLE_DEFENSE 2
1367 #define HAVOCBOT_ONS_ROLE_ASSISTANT 4
1368 #define HAVOCBOT_ONS_ROLE_OFFENSE 8
1370 .float havocbot_role_flags;
1371 .float havocbot_attack_time;
1373 .void() havocbot_role;
1374 .void() havocbot_previous_role;
1376 void() havocbot_role_ons_defense;
1377 void() havocbot_role_ons_offense;
1378 void() havocbot_role_ons_assistant;
1380 void(entity bot) havocbot_ons_reset_role;
1381 void(float ratingscale, vector org, float sradius) havocbot_goalrating_items;
1382 void(float ratingscale, vector org, float sradius) havocbot_goalrating_enemyplayers;
1384 .entity havocbot_ons_target;
1386 void havocbot_goalrating_ons_offenseitems(float ratingscale, vector org, float sradius)
1389 float t, i, c, needarmor = FALSE, needweapons = FALSE;
1391 // Needs armor/health?
1397 for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
1400 if(self.weapons & WepSet_FromWeapon(i))
1408 if(!needweapons && !needarmor)
1411 // dprint(self.netname, " needs weapons ", ftos(needweapons) , "\n");
1412 // dprint(self.netname, " needs armor ", ftos(needarmor) , "\n");
1414 // See what is around
1415 head = findchainfloat(bot_pickup, TRUE);
1418 // gather health and armor only
1420 if ( ((head.health || head.armorvalue) && needarmor) || (head.weapons && needweapons ) )
1421 if (vlen(head.origin - org) < sradius)
1423 t = head.bot_pickupevalfunc(self, head);
1425 navigation_routerating(head, t * ratingscale, 500);
1431 void havocbot_role_ons_setrole(entity bot, float role)
1433 dprint(strcat(bot.netname," switched to "));
1436 case HAVOCBOT_ONS_ROLE_DEFENSE:
1438 bot.havocbot_role = havocbot_role_ons_defense;
1439 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE;
1440 bot.havocbot_role_timeout = 0;
1442 case HAVOCBOT_ONS_ROLE_ASSISTANT:
1443 dprint("assistant");
1444 bot.havocbot_role = havocbot_role_ons_assistant;
1445 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT;
1446 bot.havocbot_role_timeout = 0;
1448 case HAVOCBOT_ONS_ROLE_OFFENSE:
1450 bot.havocbot_role = havocbot_role_ons_offense;
1451 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE;
1452 bot.havocbot_role_timeout = 0;
1458 float havocbot_ons_teamcount(entity bot, float role)
1463 FOR_EACH_PLAYER(head)
1464 if(head.team==self.team)
1465 if(head.havocbot_role_flags & role)
1471 void havocbot_goalrating_ons_controlpoints_attack(float ratingscale)
1473 entity cp, cp1, cp2, best, pl, wp;
1474 float radius, found, bestvalue, c;
1476 cp1 = cp2 = findchain(classname, "onslaught_controlpoint");
1478 // Filter control points
1479 for (; cp2; cp2 = cp2.chain)
1482 cp2.wpconsidered = FALSE;
1487 // Ignore owned controlpoints
1488 if(self.team == NUM_TEAM_1)
1490 if( (cp2.isgenneighbor[NUM_TEAM_2] || cp2.iscpneighbor[NUM_TEAM_2]) && !(cp2.isgenneighbor[NUM_TEAM_1] || cp2.iscpneighbor[NUM_TEAM_1]) )
1493 else if(self.team == NUM_TEAM_2)
1495 if( (cp2.isgenneighbor[NUM_TEAM_1] || cp2.iscpneighbor[NUM_TEAM_1]) && !(cp2.isgenneighbor[NUM_TEAM_2] || cp2.iscpneighbor[NUM_TEAM_2]) )
1499 // Count team mates interested in this control point
1500 // (easier and cleaner than keeping counters per cp and teams)
1502 if(pl.team==self.team)
1503 if(pl.havocbot_role_flags & HAVOCBOT_ONS_ROLE_OFFENSE)
1504 if(pl.havocbot_ons_target==cp2)
1507 // NOTE: probably decrease the cost of attackable control points
1509 cp2.wpconsidered = TRUE;
1512 // We'll consider only the best case
1513 bestvalue = 99999999999;
1515 for (; cp1; cp1 = cp1.chain)
1517 if (!cp1.wpconsidered)
1520 if(cp1.wpcost<bestvalue)
1522 bestvalue = cp1.wpcost;
1524 self.havocbot_ons_target = cp1;
1531 // dprint(self.netname, " chose cp ranked ", ftos(bestvalue), "\n");
1535 // Should be attacked
1536 // Rate waypoints near it
1539 bestvalue = 99999999999;
1540 for(radius=0; radius<1000 && !found; radius+=500)
1542 for(wp=findradius(cp.origin,radius); wp; wp=wp.chain)
1544 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
1545 if(wp.classname=="waypoint")
1546 if(checkpvs(wp.origin,cp))
1549 if(wp.cnt<bestvalue)
1560 navigation_routerating(best, ratingscale, 10000);
1563 self.havocbot_attack_time = 0;
1564 if(checkpvs(self.view_ofs,cp))
1565 if(checkpvs(self.view_ofs,best))
1566 self.havocbot_attack_time = time + 2;
1570 navigation_routerating(cp, ratingscale, 10000);
1572 // dprint(self.netname, " found an attackable controlpoint at ", vtos(cp.origin) ,"\n");
1576 // Should be touched
1577 // dprint(self.netname, " found a touchable controlpoint at ", vtos(cp.origin) ,"\n");
1580 // Look for auto generated waypoint
1581 if (!bot_waypoints_for_items)
1582 for (wp = findradius(cp.origin,100); wp; wp = wp.chain)
1584 if(wp.classname=="waypoint")
1586 navigation_routerating(wp, ratingscale, 10000);
1591 // Nothing found, rate the controlpoint itself
1593 navigation_routerating(cp, ratingscale, 10000);
1597 float havocbot_goalrating_ons_generator_attack(float ratingscale)
1599 entity g, wp, bestwp;
1602 for (g = findchain(classname, "onslaught_generator"); g; g = g.chain)
1604 if(g.team == self.team || g.isshielded)
1607 // Should be attacked
1608 // Rate waypoints near it
1613 for(wp=findradius(g.origin,400); wp; wp=wp.chain)
1615 if(wp.classname=="waypoint")
1616 if(checkpvs(wp.origin,g))
1629 // dprint("waypoints found around generator\n");
1630 navigation_routerating(bestwp, ratingscale, 10000);
1633 self.havocbot_attack_time = 0;
1634 if(checkpvs(self.view_ofs,g))
1635 if(checkpvs(self.view_ofs,bestwp))
1636 self.havocbot_attack_time = time + 5;
1642 // dprint("generator found without waypoints around\n");
1643 // if there aren't waypoints near the generator go straight to it
1644 navigation_routerating(g, ratingscale, 10000);
1645 self.havocbot_attack_time = 0;
1652 void havocbot_role_ons_offense()
1654 if(self.deadflag != DEAD_NO)
1656 self.havocbot_attack_time = 0;
1657 havocbot_ons_reset_role(self);
1661 // Set the role timeout if necessary
1662 if (!self.havocbot_role_timeout)
1663 self.havocbot_role_timeout = time + 120;
1665 if (time > self.havocbot_role_timeout)
1667 havocbot_ons_reset_role(self);
1671 if(self.havocbot_attack_time>time)
1674 if (self.bot_strategytime < time)
1676 navigation_goalrating_start();
1677 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
1678 if(!havocbot_goalrating_ons_generator_attack(20000))
1679 havocbot_goalrating_ons_controlpoints_attack(20000);
1680 havocbot_goalrating_ons_offenseitems(10000, self.origin, 10000);
1681 navigation_goalrating_end();
1683 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
1687 void havocbot_role_ons_assistant()
1689 havocbot_ons_reset_role(self);
1692 void havocbot_role_ons_defense()
1694 havocbot_ons_reset_role(self);
1697 void havocbot_ons_reset_role(entity bot)
1702 if(self.deadflag != DEAD_NO)
1705 bot.havocbot_ons_target = world;
1707 // TODO: Defend control points or generator if necessary
1709 // if there is only me on the team switch to offense
1711 FOR_EACH_PLAYER(head)
1712 if(head.team==self.team)
1717 havocbot_role_ons_setrole(bot, HAVOCBOT_ONS_ROLE_OFFENSE);
1721 havocbot_role_ons_setrole(bot, HAVOCBOT_ONS_ROLE_OFFENSE);
1729 MUTATOR_HOOKFUNCTION(ons_ResetMap)
1731 FOR_EACH_PLAYER(self) { self.ons_deathloc = '0 0 0'; }
1735 MUTATOR_HOOKFUNCTION(ons_RemovePlayer)
1737 self.ons_deathloc = '0 0 0';
1741 MUTATOR_HOOKFUNCTION(ons_PlayerSpawn)
1743 if(autocvar_g_onslaught_spawn_at_controlpoints)
1744 if(random() <= autocvar_g_onslaught_spawn_at_controlpoints_chance)
1746 float random_target = autocvar_g_onslaught_spawn_at_controlpoints_random;
1747 entity tmp_entity, closest_target = world;
1748 vector spawn_loc = self.ons_deathloc;
1750 // new joining player or round reset, don't bother checking
1751 if(spawn_loc == '0 0 0') { return FALSE; }
1753 tmp_entity = findchain(classname, "onslaught_controlpoint");
1755 if(random_target) { RandomSelection_Init(); }
1759 if(SAME_TEAM(tmp_entity, self))
1761 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1762 else if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world)
1763 closest_target = tmp_entity;
1765 tmp_entity = tmp_entity.chain;
1768 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1774 for(i = 0; i < 10; ++i)
1776 loc = closest_target.origin + '0 0 96';
1777 loc += ('0 1 0' * random()) * 128;
1778 tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, self);
1779 if(trace_fraction == 1.0 && !trace_startsolid)
1781 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
1782 if(trace_fraction == 1.0 && !trace_startsolid)
1784 setorigin(self, loc);
1785 self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1793 if(autocvar_g_onslaught_spawn_at_generator)
1794 if(random() <= autocvar_g_onslaught_spawn_at_generator_chance)
1796 float random_target = autocvar_g_onslaught_spawn_at_generator_random;
1797 entity tmp_entity, closest_target = world;
1798 vector spawn_loc = self.ons_deathloc;
1800 // new joining player or round reset, don't bother checking
1801 if(spawn_loc == '0 0 0') { return FALSE; }
1803 tmp_entity = findchain(classname, "onslaught_generator");
1805 if(random_target) { RandomSelection_Init(); }
1810 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1813 if(SAME_TEAM(tmp_entity, self))
1814 if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world)
1815 closest_target = tmp_entity;
1818 tmp_entity = tmp_entity.chain;
1821 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1827 for(i = 0; i < 10; ++i)
1829 loc = closest_target.origin + '0 0 128';
1830 loc += ('0 1 0' * random()) * 256;
1831 tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, self);
1832 if(trace_fraction == 1.0 && !trace_startsolid)
1834 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
1835 if(trace_fraction == 1.0 && !trace_startsolid)
1837 setorigin(self, loc);
1838 self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1849 MUTATOR_HOOKFUNCTION(ons_PlayerDies)
1851 frag_target.ons_deathloc = frag_target.origin;
1855 MUTATOR_HOOKFUNCTION(ons_MonsterThink)
1857 entity e = find(world, targetname, self.target);
1864 MUTATOR_HOOKFUNCTION(ons_MonsterSpawn)
1866 entity e, ee = world;
1870 e = find(world,target,self.targetname);
1887 MUTATOR_HOOKFUNCTION(ons_TurretSpawn)
1889 entity e, ee = world;
1892 e = find(world, target, self.targetname);
1910 MUTATOR_HOOKFUNCTION(ons_BotRoles)
1912 havocbot_ons_reset_role(self);
1916 MUTATOR_HOOKFUNCTION(ons_GetTeamCount)
1918 // onslaught is special
1919 entity head = findchain(classname, "onslaught_generator");
1924 case NUM_TEAM_1: c1 = 0; break;
1925 case NUM_TEAM_2: c2 = 0; break;
1926 case NUM_TEAM_3: c3 = 0; break;
1927 case NUM_TEAM_4: c4 = 0; break;
1936 void ons_ScoreRules()
1938 CheckAllowedTeams(world);
1939 ScoreRules_basics(((c4>=0) ? 4 : (c3>=0) ? 3 : 2), SFL_SORT_PRIO_PRIMARY, 0, TRUE);
1940 ScoreInfo_SetLabel_TeamScore (ST_ONS_CAPS, "caps", SFL_SORT_PRIO_PRIMARY);
1941 ScoreInfo_SetLabel_PlayerScore(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
1942 ScoreInfo_SetLabel_PlayerScore(SP_ONS_TAKES, "takes", 0);
1943 ScoreRules_basics_end();
1946 void ons_DelayedInit() // Do this check with a delay so we can wait for teams to be set up
1951 void ons_Initialize()
1953 ons_captureshield_force = autocvar_g_onslaught_shield_force;
1954 InitializeEntity(world, ons_DelayedInit, INITPRIO_GAMETYPE);
1957 MUTATOR_DEFINITION(gamemode_onslaught)
1959 MUTATOR_HOOK(reset_map_global, ons_ResetMap, CBC_ORDER_ANY);
1960 MUTATOR_HOOK(MakePlayerObserver, ons_RemovePlayer, CBC_ORDER_ANY);
1961 MUTATOR_HOOK(ClientDisconnect, ons_RemovePlayer, CBC_ORDER_ANY);
1962 MUTATOR_HOOK(PlayerSpawn, ons_PlayerSpawn, CBC_ORDER_ANY);
1963 MUTATOR_HOOK(PlayerDies, ons_PlayerDies, CBC_ORDER_ANY);
1964 MUTATOR_HOOK(MonsterMove, ons_MonsterThink, CBC_ORDER_ANY);
1965 MUTATOR_HOOK(MonsterSpawn, ons_MonsterSpawn, CBC_ORDER_ANY);
1966 MUTATOR_HOOK(TurretSpawn, ons_TurretSpawn, CBC_ORDER_ANY);
1967 MUTATOR_HOOK(HavocBot_ChooseRule, ons_BotRoles, CBC_ORDER_ANY);
1971 if(time > 1) // game loads at time 1
1972 error("This is a game type and it cannot be added at runtime.");
1976 MUTATOR_ONROLLBACK_OR_REMOVE
1978 // we actually cannot roll back ons_Initialize here
1979 // BUT: we don't need to! If this gets called, adding always
1985 print("This is a game type and it cannot be removed at runtime.");