4 #include "../controlpoint.qh"
5 #include "../generator.qh"
7 // =======================
8 // CaptureShield Functions
9 // =======================
11 bool ons_CaptureShield_Customize()
13 entity e = WaypointSprite_getviewentity(other);
15 if(!self.enemy.isshielded && (ons_ControlPoint_Attackable(self.enemy, e.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return false; }
16 if(SAME_TEAM(self, e)) { return false; }
21 void ons_CaptureShield_Touch()
23 if(!self.enemy.isshielded && (ons_ControlPoint_Attackable(self.enemy, other.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return; }
24 if(!IS_PLAYER(other)) { return; }
25 if(SAME_TEAM(other, self)) { return; }
27 vector mymid = (self.absmin + self.absmax) * 0.5;
28 vector othermid = (other.absmin + other.absmax) * 0.5;
30 Damage(other, self, self, 0, DEATH_HURTTRIGGER, mymid, normalize(othermid - mymid) * ons_captureshield_force);
32 if(IS_REAL_CLIENT(other))
34 play2(other, "onslaught/damageblockedbyshield.wav");
36 if(self.enemy.classname == "onslaught_generator")
37 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_GENERATOR_SHIELDED);
39 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_CONTROLPOINT_SHIELDED);
43 void ons_CaptureShield_Reset()
45 self.colormap = self.enemy.colormap;
46 self.team = self.enemy.team;
49 void ons_CaptureShield_Spawn(entity generator, bool is_generator)
51 entity shield = spawn();
53 shield.enemy = generator;
54 shield.team = generator.team;
55 shield.colormap = generator.colormap;
56 shield.reset = ons_CaptureShield_Reset;
57 shield.touch = ons_CaptureShield_Touch;
58 shield.customizeentityforclient = ons_CaptureShield_Customize;
59 shield.classname = "ons_captureshield";
60 shield.effects = EF_ADDITIVE;
61 shield.movetype = MOVETYPE_NOCLIP;
62 shield.solid = SOLID_TRIGGER;
63 shield.avelocity = '7 0 11';
65 shield.model = ((is_generator) ? "models/onslaught/generator_shield.md3" : "models/onslaught/controlpoint_shield.md3");
67 precache_model(shield.model);
68 setorigin(shield, generator.origin);
69 setmodel(shield, shield.model);
70 setsize(shield, shield.scale * shield.mins, shield.scale * shield.maxs);
78 void ons_debug(string input)
80 switch(autocvar_g_onslaught_debug)
82 case 1: LOG_TRACE(input); break;
83 case 2: LOG_INFO(input); break;
87 void setmodel_fixsize(entity e, string m)
93 void onslaught_updatelinks()
96 // first check if the game has ended
97 ons_debug("--- updatelinks ---\n");
98 // mark generators as being shielded and networked
99 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
102 ons_debug(strcat(etos(l), " (generator) belongs to team ", ftos(l.team), "\n"));
104 ons_debug(strcat(etos(l), " (generator) is destroyed\n"));
105 l.islinked = l.iscaptured;
106 l.isshielded = l.iscaptured;
107 l.sprite.SendFlags |= 16;
109 // mark points as shielded and not networked
110 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
115 for(i = 0; i < 17; ++i) { l.isgenneighbor[i] = false; l.iscpneighbor[i] = false; }
116 ons_debug(strcat(etos(l), " (point) belongs to team ", ftos(l.team), "\n"));
117 l.sprite.SendFlags |= 16;
119 // flow power outward from the generators through the network
124 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
126 // if both points are captured by the same team, and only one of
127 // them is powered, mark the other one as powered as well
128 if (l.enemy.iscaptured && l.goalentity.iscaptured)
129 if (l.enemy.islinked != l.goalentity.islinked)
130 if(SAME_TEAM(l.enemy, l.goalentity))
132 if (!l.goalentity.islinked)
135 l.goalentity.islinked = true;
136 ons_debug(strcat(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)\n"));
138 else if (!l.enemy.islinked)
141 l.enemy.islinked = true;
142 ons_debug(strcat(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)\n"));
147 // now that we know which points are powered we can mark their neighbors
148 // as unshielded if team differs
149 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
151 if (l.goalentity.islinked)
153 if(DIFF_TEAM(l.goalentity, l.enemy))
155 ons_debug(strcat(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)\n"));
156 l.enemy.isshielded = false;
158 if(l.goalentity.classname == "onslaught_generator")
159 l.enemy.isgenneighbor[l.goalentity.team] = true;
161 l.enemy.iscpneighbor[l.goalentity.team] = true;
163 if (l.enemy.islinked)
165 if(DIFF_TEAM(l.goalentity, l.enemy))
167 ons_debug(strcat(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)\n"));
168 l.goalentity.isshielded = false;
170 if(l.enemy.classname == "onslaught_generator")
171 l.goalentity.isgenneighbor[l.enemy.team] = true;
173 l.goalentity.iscpneighbor[l.enemy.team] = true;
176 // now update the generators
177 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
181 ons_debug(strcat(etos(l), " (generator) is shielded\n"));
182 l.takedamage = DAMAGE_NO;
183 l.bot_attack = false;
187 ons_debug(strcat(etos(l), " (generator) is not shielded\n"));
188 l.takedamage = DAMAGE_AIM;
192 ons_Generator_UpdateSprite(l);
194 // now update the takedamage and alpha variables on control point icons
195 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
199 ons_debug(strcat(etos(l), " (point) is shielded\n"));
202 l.goalentity.takedamage = DAMAGE_NO;
203 l.goalentity.bot_attack = false;
208 ons_debug(strcat(etos(l), " (point) is not shielded\n"));
211 l.goalentity.takedamage = DAMAGE_AIM;
212 l.goalentity.bot_attack = true;
215 ons_ControlPoint_UpdateSprite(l);
217 l = findchain(classname, "ons_captureshield");
220 l.team = l.enemy.team;
221 l.colormap = l.enemy.colormap;
227 // ===================
228 // Main Link Functions
229 // ===================
231 bool ons_Link_Send(entity to, int sendflags)
233 WriteByte(MSG_ENTITY, ENT_CLIENT_RADARLINK);
234 WriteByte(MSG_ENTITY, sendflags);
237 WriteCoord(MSG_ENTITY, self.goalentity.origin_x);
238 WriteCoord(MSG_ENTITY, self.goalentity.origin_y);
239 WriteCoord(MSG_ENTITY, self.goalentity.origin_z);
243 WriteCoord(MSG_ENTITY, self.enemy.origin_x);
244 WriteCoord(MSG_ENTITY, self.enemy.origin_y);
245 WriteCoord(MSG_ENTITY, self.enemy.origin_z);
249 WriteByte(MSG_ENTITY, self.clientcolors); // which is goalentity's color + enemy's color * 16
254 void ons_Link_CheckUpdate()
256 // TODO check if the two sides have moved (currently they won't move anyway)
257 float cc = 0, cc1 = 0, cc2 = 0;
259 if(self.goalentity.islinked || self.goalentity.iscaptured) { cc1 = (self.goalentity.team - 1) * 0x01; }
260 if(self.enemy.islinked || self.enemy.iscaptured) { cc2 = (self.enemy.team - 1) * 0x10; }
264 if(cc != self.clientcolors)
266 self.clientcolors = cc;
270 self.nextthink = time;
273 void ons_DelayedLinkSetup()
275 self.goalentity = find(world, targetname, self.target);
276 self.enemy = find(world, targetname, self.target2);
277 if(!self.goalentity) { objerror("can not find target\n"); }
278 if(!self.enemy) { objerror("can not find target2\n"); }
280 ons_debug(strcat(etos(self.goalentity), " linked with ", etos(self.enemy), "\n"));
282 self.think = ons_Link_CheckUpdate;
283 self.nextthink = time;
287 // =============================
288 // Main Control Point Functions
289 // =============================
291 int ons_ControlPoint_CanBeLinked(entity cp, int teamnumber)
293 if(cp.isgenneighbor[teamnumber]) { return 2; }
294 if(cp.iscpneighbor[teamnumber]) { return 1; }
299 int ons_ControlPoint_Attackable(entity cp, int teamnumber)
300 // -2: SAME TEAM, attackable by enemy!
305 // 3: attack it (HIGH PRIO)
306 // 4: touch it (HIGH PRIO)
314 else if(cp.goalentity)
316 // if there's already an icon built, nothing happens
317 if(cp.team == teamnumber)
319 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
320 if(a) // attackable by enemy?
321 return -2; // EMERGENCY!
324 // we know it can be linked, so no need to check
326 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
327 if(a == 2) // near our generator?
328 return 3; // EMERGENCY!
334 if(ons_ControlPoint_CanBeLinked(cp, teamnumber))
336 a = ons_ControlPoint_CanBeLinked(cp, teamnumber); // why was this here NUM_TEAM_1 + NUM_TEAM_2 - t
338 return 4; // GET THIS ONE NOW!
340 return 2; // TOUCH ME
346 void ons_ControlPoint_Icon_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
350 if(damage <= 0) { return; }
352 if (self.owner.isshielded)
354 // this is protected by a shield, so ignore the damage
355 if (time > self.pain_finished)
356 if (IS_PLAYER(attacker))
358 play2(attacker, "onslaught/damageblockedbyshield.wav");
359 self.pain_finished = time + 1;
360 attacker.typehitsound += 1; // play both sounds (shield is way too quiet)
366 if(IS_PLAYER(attacker))
367 if(time - ons_notification_time[self.team] > 10)
369 play2team(self.team, "onslaught/controlpoint_underattack.wav");
370 ons_notification_time[self.team] = time;
373 self.health = self.health - damage;
374 if(self.owner.iscaptured)
375 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
377 WaypointSprite_UpdateBuildFinished(self.owner.sprite, time + (self.max_health - self.health) / (self.count / ONS_CP_THINKRATE));
378 self.pain_finished = time + 1;
379 // particles on every hit
380 pointparticles(particleeffectnum(EFFECT_SPARKS), hitloc, force*-1, 1);
383 sound(self, CH_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE+0.3, ATTEN_NORM);
385 sound(self, CH_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE+0.3, ATTEN_NORM);
389 sound(self, CH_TRIGGER, W_Sound("grenade_impact"), VOL_BASE, ATTEN_NORM);
390 pointparticles(particleeffectnum(EFFECT_ROCKET_EXPLODE), self.origin, '0 0 0', 1);
391 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_CPDESTROYED_), self.owner.message, attacker.netname);
393 PlayerScore_Add(attacker, SP_ONS_TAKES, 1);
394 PlayerScore_Add(attacker, SP_SCORE, 10);
396 self.owner.goalentity = world;
397 self.owner.islinked = false;
398 self.owner.iscaptured = false;
400 self.owner.colormap = 1024;
402 WaypointSprite_UpdateMaxHealth(self.owner.sprite, 0);
404 onslaught_updatelinks();
406 // Use targets now (somebody make sure this is in the right place..)
413 self.owner.waslinked = self.owner.islinked;
414 if(self.owner.model != "models/onslaught/controlpoint_pad.md3")
415 setmodel_fixsize(self.owner, "models/onslaught/controlpoint_pad.md3");
416 //setsize(self, '-32 -32 0', '32 32 8');
421 self.SendFlags |= CPSF_STATUS;
424 void ons_ControlPoint_Icon_Think()
427 self.nextthink = time + ONS_CP_THINKRATE;
429 if(autocvar_g_onslaught_cp_proxydecap)
431 int _enemy_count = 0;
432 int _friendly_count = 0;
436 FOR_EACH_PLAYER(_player)
438 if(!_player.deadflag)
440 _dist = vlen(_player.origin - self.origin);
441 if(_dist < autocvar_g_onslaught_cp_proxydecap_distance)
443 if(SAME_TEAM(_player, self))
451 _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
452 _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
454 self.health = bound(0, self.health + (_friendly_count - _enemy_count), self.max_health);
455 self.SendFlags |= CPSF_STATUS;
458 ons_ControlPoint_Icon_Damage(self, self, 1, 0, self.origin, '0 0 0');
463 if (time > self.pain_finished + 5)
465 if(self.health < self.max_health)
467 self.health = self.health + self.count;
468 if (self.health >= self.max_health)
469 self.health = self.max_health;
470 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
474 if(self.owner.islinked != self.owner.waslinked)
476 // unteam the spawnpoint if needed
477 int t = self.owner.team;
478 if(!self.owner.islinked)
489 self.owner.waslinked = self.owner.islinked;
493 if(random() < 0.6 - self.health / self.max_health)
495 Send_Effect(EFFECT_ELECTRIC_SPARKS, self.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
498 sound(self, CH_PAIN, "onslaught/ons_spark1.wav", VOL_BASE, ATTEN_NORM);
499 else if (random() > 0.5)
500 sound(self, CH_PAIN, "onslaught/ons_spark2.wav", VOL_BASE, ATTEN_NORM);
504 void ons_ControlPoint_Icon_BuildThink()
509 self.nextthink = time + ONS_CP_THINKRATE;
511 // only do this if there is power
512 a = ons_ControlPoint_CanBeLinked(self.owner, self.owner.team);
516 self.health = self.health + self.count;
518 self.SendFlags |= CPSF_STATUS;
520 if (self.health >= self.max_health)
522 self.health = self.max_health;
523 self.count = autocvar_g_onslaught_cp_regen * ONS_CP_THINKRATE; // slow repair rate from now on
524 self.think = ons_ControlPoint_Icon_Think;
525 sound(self, CH_TRIGGER, "onslaught/controlpoint_built.wav", VOL_BASE, ATTEN_NORM);
526 self.owner.iscaptured = true;
527 self.solid = SOLID_BBOX;
529 Send_Effect_(sprintf("%s_cap", Static_Team_ColorName_Lower(self.owner.team)), self.owner.origin, '0 0 0', 1);
531 WaypointSprite_UpdateMaxHealth(self.owner.sprite, self.max_health);
532 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
534 if(IS_PLAYER(self.owner.ons_toucher))
536 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ONSLAUGHT_CAPTURE, self.owner.ons_toucher.netname, self.owner.message);
537 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);
538 Send_Notification(NOTIF_ONE, self.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE, self.owner.message);
539 PlayerScore_Add(self.owner.ons_toucher, SP_ONS_CAPS, 1);
540 PlayerTeamScore_AddScore(self.owner.ons_toucher, 10);
543 self.owner.ons_toucher = world;
545 onslaught_updatelinks();
547 // Use targets now (somebody make sure this is in the right place..)
554 self.SendFlags |= CPSF_SETUP;
556 if(self.owner.model != "models/onslaught/controlpoint_pad2.md3")
557 setmodel_fixsize(self.owner, "models/onslaught/controlpoint_pad2.md3");
559 if(random() < 0.9 - self.health / self.max_health)
560 Send_Effect(EFFECT_RAGE, self.origin + 10 * randomvec(), '0 0 -1', 1);
563 void ons_ControlPoint_Icon_Spawn(entity cp, entity player)
567 setsize(e, CPICON_MIN, CPICON_MAX);
568 setorigin(e, cp.origin + CPICON_OFFSET);
570 e.classname = "onslaught_controlpoint_icon";
572 e.max_health = autocvar_g_onslaught_cp_health;
573 e.health = autocvar_g_onslaught_cp_buildhealth;
575 e.takedamage = DAMAGE_AIM;
577 e.event_damage = ons_ControlPoint_Icon_Damage;
578 e.team = player.team;
579 e.colormap = 1024 + (e.team - 1) * 17;
580 e.count = (e.max_health - e.health) * ONS_CP_THINKRATE / autocvar_g_onslaught_cp_buildtime; // how long it takes to build
582 sound(e, CH_TRIGGER, "onslaught/controlpoint_build.wav", VOL_BASE, ATTEN_NORM);
586 cp.colormap = e.colormap;
588 Send_Effect_(sprintf("%sflag_touch", Static_Team_ColorName_Lower(player.team)), e.origin, '0 0 0', 1);
590 WaypointSprite_UpdateBuildFinished(cp.sprite, time + (e.max_health - e.health) / (e.count / ONS_CP_THINKRATE));
591 WaypointSprite_UpdateRule(cp.sprite,cp.team,SPRITERULE_TEAMPLAY);
592 cp.sprite.SendFlags |= 16;
594 onslaught_controlpoint_icon_link(e, ons_ControlPoint_Icon_BuildThink);
597 entity ons_ControlPoint_Waypoint(entity e)
601 int a = ons_ControlPoint_Attackable(e, e.team);
603 if(a == -2) { return WP_OnsCPDefend; } // defend now
604 if(a == -1 || a == 1 || a == 2) { return WP_OnsCP; } // touch
605 if(a == 3 || a == 4) { return WP_OnsCPAttack; } // attack
613 void ons_ControlPoint_UpdateSprite(entity e)
615 entity s1 = ons_ControlPoint_Waypoint(e);
616 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
619 sh = !(ons_ControlPoint_CanBeLinked(e, NUM_TEAM_1) || ons_ControlPoint_CanBeLinked(e, NUM_TEAM_2) || ons_ControlPoint_CanBeLinked(e, NUM_TEAM_3) || ons_ControlPoint_CanBeLinked(e, NUM_TEAM_4));
621 if(e.lastteam != e.team + 2 || e.lastshielded != sh || e.iscaptured != e.lastcaptured)
623 if(e.iscaptured) // don't mess up build bars!
627 WaypointSprite_UpdateMaxHealth(e.sprite, 0);
631 WaypointSprite_UpdateMaxHealth(e.sprite, e.goalentity.max_health);
632 WaypointSprite_UpdateHealth(e.sprite, e.goalentity.health);
638 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, false));
640 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
645 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, false));
647 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
649 WaypointSprite_Ping(e.sprite);
651 e.lastteam = e.team + 2;
653 e.lastcaptured = e.iscaptured;
657 void ons_ControlPoint_Touch()
659 entity toucher = other;
662 if(IS_VEHICLE(toucher) && toucher.owner)
663 if(autocvar_g_onslaught_allow_vehicle_touch)
664 toucher = toucher.owner;
668 if(!IS_PLAYER(toucher)) { return; }
669 if(toucher.frozen) { return; }
670 if(toucher.deadflag != DEAD_NO) { return; }
672 if ( SAME_TEAM(self,toucher) )
673 if ( self.iscaptured )
675 if(time <= toucher.teleport_antispam)
676 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT_ANTISPAM, rint(toucher.teleport_antispam - time));
678 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
681 attackable = ons_ControlPoint_Attackable(self, toucher.team);
682 if(attackable != 2 && attackable != 4)
684 // we've verified that this player has a legitimate claim to this point,
685 // so start building the captured point icon (which only captures this
686 // point if it successfully builds without being destroyed first)
687 ons_ControlPoint_Icon_Spawn(self, toucher);
689 self.ons_toucher = toucher;
691 onslaught_updatelinks();
694 void ons_ControlPoint_Think()
696 self.nextthink = time + ONS_CP_THINKRATE;
697 CSQCMODEL_AUTOUPDATE();
700 void ons_ControlPoint_Reset()
703 remove(self.goalentity);
705 self.goalentity = world;
707 self.colormap = 1024;
708 self.iscaptured = false;
709 self.islinked = false;
710 self.isshielded = true;
711 self.think = ons_ControlPoint_Think;
712 self.ons_toucher = world;
713 self.nextthink = time + ONS_CP_THINKRATE;
714 setmodel_fixsize(self, "models/onslaught/controlpoint_pad.md3");
716 WaypointSprite_UpdateMaxHealth(self.sprite, 0);
717 WaypointSprite_UpdateRule(self.sprite,self.team,SPRITERULE_TEAMPLAY);
719 onslaught_updatelinks();
722 SUB_UseTargets(); // to reset the structures, playerspawns etc.
724 CSQCMODEL_AUTOUPDATE();
727 void ons_DelayedControlPoint_Setup(void)
729 onslaught_updatelinks();
731 // captureshield setup
732 ons_CaptureShield_Spawn(self, false);
734 CSQCMODEL_AUTOINIT();
737 void ons_ControlPoint_Setup(entity cp)
740 self = cp; // for later usage with droptofloor()
743 cp.ons_worldcpnext = ons_worldcplist; // link control point into ons_worldcplist
744 ons_worldcplist = cp;
746 cp.netname = "Control point";
748 cp.solid = SOLID_BBOX;
749 cp.movetype = MOVETYPE_NONE;
750 cp.touch = ons_ControlPoint_Touch;
751 cp.think = ons_ControlPoint_Think;
752 cp.nextthink = time + ONS_CP_THINKRATE;
753 cp.reset = ons_ControlPoint_Reset;
755 cp.iscaptured = false;
757 cp.isshielded = true;
759 if(cp.message == "") { cp.message = "a"; }
761 // precache - TODO: clean up!
762 precache_model("models/onslaught/controlpoint_pad.md3");
763 precache_model("models/onslaught/controlpoint_pad2.md3");
764 precache_model("models/onslaught/controlpoint_shield.md3");
765 precache_model("models/onslaught/controlpoint_icon.md3");
766 precache_model("models/onslaught/controlpoint_icon_dmg1.md3");
767 precache_model("models/onslaught/controlpoint_icon_dmg2.md3");
768 precache_model("models/onslaught/controlpoint_icon_dmg3.md3");
769 precache_model("models/onslaught/controlpoint_icon_gib1.md3");
770 precache_model("models/onslaught/controlpoint_icon_gib2.md3");
771 precache_model("models/onslaught/controlpoint_icon_gib4.md3");
772 precache_sound("onslaught/controlpoint_build.wav");
773 precache_sound("onslaught/controlpoint_built.wav");
774 precache_sound(W_Sound("grenade_impact"));
775 precache_sound("onslaught/damageblockedbyshield.wav");
776 precache_sound("onslaught/controlpoint_underattack.wav");
777 precache_sound("onslaught/ons_spark1.wav");
778 precache_sound("onslaught/ons_spark2.wav");
781 setmodel_fixsize(cp, "models/onslaught/controlpoint_pad.md3");
783 // control point placement
784 if((cp.spawnflags & 1) || cp.noalign) // don't drop to floor, just stay at fixed location
787 cp.movetype = MOVETYPE_NONE;
789 else // drop to floor, automatically find a platform and set that as spawn origin
791 setorigin(cp, cp.origin + '0 0 20');
795 cp.movetype = MOVETYPE_TOSS;
799 WaypointSprite_SpawnFixed(WP_Null, self.origin + CPGEN_WAYPOINT_OFFSET, self, sprite, RADARICON_NONE);
800 WaypointSprite_UpdateRule(self.sprite, self.team, SPRITERULE_TEAMPLAY);
802 InitializeEntity(cp, ons_DelayedControlPoint_Setup, INITPRIO_SETLOCATION);
806 // =========================
807 // Main Generator Functions
808 // =========================
810 entity ons_Generator_Waypoint(entity e)
813 return WP_OnsGenShielded;
817 void ons_Generator_UpdateSprite(entity e)
819 entity s1 = ons_Generator_Waypoint(e);
820 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
822 if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
824 e.lastteam = e.team + 2;
825 e.lastshielded = e.isshielded;
829 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, false));
831 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
836 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, false));
838 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
840 WaypointSprite_Ping(e.sprite);
844 void ons_GeneratorDamage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
846 if(damage <= 0) { return; }
847 if(warmup_stage || gameover) { return; }
848 if(!round_handler_IsRoundStarted()) { return; }
850 if (attacker != self)
854 // this is protected by a shield, so ignore the damage
855 if (time > self.pain_finished)
856 if (IS_PLAYER(attacker))
858 play2(attacker, "onslaught/damageblockedbyshield.wav");
859 attacker.typehitsound += 1;
860 self.pain_finished = time + 1;
864 if (time > self.pain_finished)
866 self.pain_finished = time + 10;
868 FOR_EACH_REALPLAYER(head) if(SAME_TEAM(head, self)) { Send_Notification(NOTIF_ONE, head, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK); }
869 play2team(self.team, "onslaught/generator_underattack.wav");
872 self.health = self.health - damage;
873 WaypointSprite_UpdateHealth(self.sprite, self.health);
874 // choose an animation frame based on health
875 self.frame = 10 * bound(0, (1 - self.health / self.max_health), 1);
876 // see if the generator is still functional, or dying
879 self.lasthealth = self.health;
883 if (attacker == self)
884 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME_));
887 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_GENDESTROYED_));
888 PlayerScore_Add(attacker, SP_SCORE, 100);
890 self.iscaptured = false;
891 self.islinked = false;
892 self.isshielded = false;
893 self.takedamage = DAMAGE_NO; // can't be hurt anymore
894 self.event_damage = func_null; // won't do anything if hurt
895 self.count = 0; // reset counter
896 self.think = func_null;
898 //self.think(); // do the first explosion now
900 WaypointSprite_UpdateMaxHealth(self.sprite, 0);
901 WaypointSprite_Ping(self.sprite);
902 //WaypointSprite_Kill(self.sprite); // can't do this yet, code too poor
904 onslaught_updatelinks();
907 // Throw some flaming gibs on damage, more damage = more chance for gib
908 if(random() < damage/220)
910 sound(self, CH_TRIGGER, W_Sound("rocket_impact"), VOL_BASE, ATTEN_NORM);
914 // particles on every hit
915 Send_Effect(EFFECT_SPARKS, hitloc, force * -1, 1);
919 sound(self, CH_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE, ATTEN_NORM);
921 sound(self, CH_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM);
924 self.SendFlags |= GSF_STATUS;
927 void ons_GeneratorThink()
930 self.nextthink = time + GEN_THINKRATE;
933 if(!self.isshielded && self.wait < time)
935 self.wait = time + 5;
936 FOR_EACH_REALPLAYER(e)
938 if(SAME_TEAM(e, self))
940 Send_Notification(NOTIF_ONE, e, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM);
941 soundto(MSG_ONE, e, CHAN_AUTO, "kh/alarm.wav", VOL_BASE, ATTEN_NONE); // FIXME: unique sound?
944 Send_Notification(NOTIF_ONE, e, MSG_CENTER, APP_TEAM_NUM_4(self.team, CENTER_ONS_NOTSHIELDED_));
950 void ons_GeneratorReset()
952 self.team = self.team_saved;
953 self.lasthealth = self.max_health = self.health = autocvar_g_onslaught_gen_health;
954 self.takedamage = DAMAGE_AIM;
955 self.bot_attack = true;
956 self.iscaptured = true;
957 self.islinked = true;
958 self.isshielded = true;
959 self.event_damage = ons_GeneratorDamage;
960 self.think = ons_GeneratorThink;
961 self.nextthink = time + GEN_THINKRATE;
963 Net_LinkEntity(self, false, 0, generator_send);
965 self.SendFlags = GSF_SETUP; // just incase
966 self.SendFlags |= GSF_STATUS;
968 WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
969 WaypointSprite_UpdateHealth(self.sprite, self.health);
970 WaypointSprite_UpdateRule(self.sprite,self.team,SPRITERULE_TEAMPLAY);
972 onslaught_updatelinks();
975 void ons_DelayedGeneratorSetup()
978 waypoint_spawnforitem_force(self, self.origin);
979 self.nearestwaypointtimeout = 0; // activate waypointing again
980 self.bot_basewaypoint = self.nearestwaypoint;
982 // captureshield setup
983 ons_CaptureShield_Spawn(self, true);
985 onslaught_updatelinks();
987 Net_LinkEntity(self, false, 0, generator_send);
991 void onslaught_generator_touch()
993 if ( IS_PLAYER(other) )
994 if ( SAME_TEAM(self,other) )
995 if ( self.iscaptured )
997 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_TELEPORT);
1001 void ons_GeneratorSetup(entity gen) // called when spawning a generator entity on the map as a spawnfunc
1004 int teamnumber = gen.team;
1005 self = gen; // for later usage with droptofloor()
1008 gen.ons_worldgeneratornext = ons_worldgeneratorlist; // link generator into ons_worldgeneratorlist
1009 ons_worldgeneratorlist = gen;
1011 gen.netname = sprintf("%s generator", Team_ColoredFullName(teamnumber));
1012 gen.classname = "onslaught_generator";
1013 gen.solid = SOLID_BBOX;
1014 gen.team_saved = teamnumber;
1015 gen.movetype = MOVETYPE_NONE;
1016 gen.lasthealth = gen.max_health = gen.health = autocvar_g_onslaught_gen_health;
1017 gen.takedamage = DAMAGE_AIM;
1018 gen.bot_attack = true;
1019 gen.event_damage = ons_GeneratorDamage;
1020 gen.reset = ons_GeneratorReset;
1021 gen.think = ons_GeneratorThink;
1022 gen.nextthink = time + GEN_THINKRATE;
1023 gen.iscaptured = true;
1024 gen.islinked = true;
1025 gen.isshielded = true;
1026 gen.touch = onslaught_generator_touch;
1028 // precache - TODO: clean up!
1029 precache_model("models/onslaught/generator_shield.md3");
1030 precache_model("models/onslaught/gen_gib1.md3");
1031 precache_model("models/onslaught/gen_gib2.md3");
1032 precache_model("models/onslaught/gen_gib3.md3");
1033 precache_sound("onslaught/generator_decay.wav");
1034 precache_sound(W_Sound("grenade_impact"));
1035 precache_sound(W_Sound("rocket_impact"));
1036 precache_sound("onslaught/generator_underattack.wav");
1037 precache_sound("onslaught/shockwave.wav");
1038 precache_sound("onslaught/ons_hit1.wav");
1039 precache_sound("onslaught/ons_hit2.wav");
1040 precache_sound("onslaught/generator_underattack.wav");
1043 // model handled by CSQC
1044 setsize(gen, GENERATOR_MIN, GENERATOR_MAX);
1045 setorigin(gen, (gen.origin + CPGEN_SPAWN_OFFSET));
1046 gen.colormap = 1024 + (teamnumber - 1) * 17;
1048 // generator placement
1053 WaypointSprite_SpawnFixed(WP_Null, self.origin + CPGEN_WAYPOINT_OFFSET, self, sprite, RADARICON_NONE);
1054 WaypointSprite_UpdateRule(self.sprite, self.team, SPRITERULE_TEAMPLAY);
1055 WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
1056 WaypointSprite_UpdateHealth(self.sprite, self.health);
1058 InitializeEntity(gen, ons_DelayedGeneratorSetup, INITPRIO_SETLOCATION);
1066 int total_generators;
1067 void Onslaught_count_generators()
1070 total_generators = redowned = blueowned = yellowowned = pinkowned = 0;
1071 for(e = ons_worldgeneratorlist; e; e = e.ons_worldgeneratornext)
1074 redowned += (e.team == NUM_TEAM_1 && e.health > 0);
1075 blueowned += (e.team == NUM_TEAM_2 && e.health > 0);
1076 yellowowned += (e.team == NUM_TEAM_3 && e.health > 0);
1077 pinkowned += (e.team == NUM_TEAM_4 && e.health > 0);
1081 int Onslaught_GetWinnerTeam()
1083 int winner_team = 0;
1085 winner_team = NUM_TEAM_1;
1088 if(winner_team) return 0;
1089 winner_team = NUM_TEAM_2;
1093 if(winner_team) return 0;
1094 winner_team = NUM_TEAM_3;
1098 if(winner_team) return 0;
1099 winner_team = NUM_TEAM_4;
1103 return -1; // no generators left?
1106 #define ONS_OWNED_GENERATORS() ((redowned > 0) + (blueowned > 0) + (yellowowned > 0) + (pinkowned > 0))
1107 #define ONS_OWNED_GENERATORS_OK() (ONS_OWNED_GENERATORS() > 1)
1108 bool Onslaught_CheckWinner()
1112 if ((autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60) || (round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0))
1114 ons_stalemate = true;
1116 if (!wpforenemy_announced)
1118 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT);
1119 sound(world, CH_INFO, "onslaught/generator_decay.wav", VOL_BASE, ATTEN_NONE);
1121 wpforenemy_announced = true;
1124 entity tmp_entity; // temporary entity
1126 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext) if(time >= tmp_entity.ons_overtime_damagedelay)
1128 // tmp_entity.max_health / 300 gives 5 minutes of overtime.
1129 // control points reduce the overtime duration.
1131 for(e = ons_worldcplist; e; e = e.ons_worldcpnext)
1133 if(DIFF_TEAM(e, tmp_entity))
1138 if(autocvar_g_campaign && autocvar__campaign_testrun)
1139 d = d * tmp_entity.max_health;
1141 d = d * tmp_entity.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
1143 Damage(tmp_entity, tmp_entity, tmp_entity, d, DEATH_HURTTRIGGER, tmp_entity.origin, '0 0 0');
1145 tmp_entity.sprite.SendFlags |= 16;
1147 tmp_entity.ons_overtime_damagedelay = time + 1;
1150 else { wpforenemy_announced = false; ons_stalemate = false; }
1152 Onslaught_count_generators();
1154 if(ONS_OWNED_GENERATORS_OK())
1157 int winner_team = Onslaught_GetWinnerTeam();
1161 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
1162 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
1163 TeamScore_AddToTeam(winner_team, ST_ONS_CAPS, +1);
1165 else if(winner_team == -1)
1167 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
1168 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
1171 ons_stalemate = false;
1173 play2all(sprintf("ctf/%s_capture.wav", Static_Team_ColorName_Lower(winner_team)));
1175 round_handler_Init(7, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
1179 e.ons_roundlost = true;
1180 e.player_blocked = true;
1188 bool Onslaught_CheckPlayers()
1193 void Onslaught_RoundStart()
1196 FOR_EACH_PLAYER(tmp_entity) { tmp_entity.player_blocked = false; }
1198 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1199 tmp_entity.sprite.SendFlags |= 16;
1201 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1202 tmp_entity.sprite.SendFlags |= 16;
1210 // NOTE: LEGACY CODE, needs to be re-written!
1212 void havocbot_goalrating_ons_offenseitems(float ratingscale, vector org, float sradius)
1217 bool needarmor = false, needweapons = false;
1219 // Needs armor/health?
1225 for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
1228 if(self.weapons & WepSet_FromWeapon(i))
1236 if(!needweapons && !needarmor)
1239 ons_debug(strcat(self.netname, " needs weapons ", ftos(needweapons) , "\n"));
1240 ons_debug(strcat(self.netname, " needs armor ", ftos(needarmor) , "\n"));
1242 // See what is around
1243 head = findchainfloat(bot_pickup, true);
1246 // gather health and armor only
1248 if ( ((head.health || head.armorvalue) && needarmor) || (head.weapons && needweapons ) )
1249 if (vlen(head.origin - org) < sradius)
1251 t = head.bot_pickupevalfunc(self, head);
1253 navigation_routerating(head, t * ratingscale, 500);
1259 void havocbot_role_ons_setrole(entity bot, int role)
1261 ons_debug(strcat(bot.netname," switched to "));
1264 case HAVOCBOT_ONS_ROLE_DEFENSE:
1265 ons_debug("defense");
1266 bot.havocbot_role = havocbot_role_ons_defense;
1267 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE;
1268 bot.havocbot_role_timeout = 0;
1270 case HAVOCBOT_ONS_ROLE_ASSISTANT:
1271 ons_debug("assistant");
1272 bot.havocbot_role = havocbot_role_ons_assistant;
1273 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT;
1274 bot.havocbot_role_timeout = 0;
1276 case HAVOCBOT_ONS_ROLE_OFFENSE:
1277 ons_debug("offense");
1278 bot.havocbot_role = havocbot_role_ons_offense;
1279 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE;
1280 bot.havocbot_role_timeout = 0;
1286 int havocbot_ons_teamcount(entity bot, int role)
1291 FOR_EACH_PLAYER(head)
1292 if(SAME_TEAM(head, self))
1293 if(head.havocbot_role_flags & role)
1299 void havocbot_goalrating_ons_controlpoints_attack(float ratingscale)
1301 entity cp, cp1, cp2, best, pl, wp;
1302 float radius, bestvalue;
1306 // Filter control points
1307 for(cp2 = ons_worldcplist; cp2; cp2 = cp2.ons_worldcpnext)
1310 cp2.wpconsidered = false;
1315 // Ignore owned controlpoints
1316 if(!(cp2.isgenneighbor[self.team] || cp2.iscpneighbor[self.team]))
1319 // Count team mates interested in this control point
1320 // (easier and cleaner than keeping counters per cp and teams)
1322 if(SAME_TEAM(pl, self))
1323 if(pl.havocbot_role_flags & HAVOCBOT_ONS_ROLE_OFFENSE)
1324 if(pl.havocbot_ons_target==cp2)
1327 // NOTE: probably decrease the cost of attackable control points
1329 cp2.wpconsidered = true;
1332 // We'll consider only the best case
1333 bestvalue = 99999999999;
1335 for(cp1 = ons_worldcplist; cp1; cp1 = cp1.ons_worldcpnext)
1337 if (!cp1.wpconsidered)
1340 if(cp1.wpcost<bestvalue)
1342 bestvalue = cp1.wpcost;
1344 self.havocbot_ons_target = cp1;
1351 ons_debug(strcat(self.netname, " chose cp ranked ", ftos(bestvalue), "\n"));
1355 // Should be attacked
1356 // Rate waypoints near it
1359 bestvalue = 99999999999;
1360 for(radius=0; radius<1000 && !found; radius+=500)
1362 for(wp=findradius(cp.origin,radius); wp; wp=wp.chain)
1364 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
1365 if(wp.classname=="waypoint")
1366 if(checkpvs(wp.origin,cp))
1369 if(wp.cnt<bestvalue)
1380 navigation_routerating(best, ratingscale, 10000);
1383 self.havocbot_attack_time = 0;
1384 if(checkpvs(self.view_ofs,cp))
1385 if(checkpvs(self.view_ofs,best))
1386 self.havocbot_attack_time = time + 2;
1390 navigation_routerating(cp, ratingscale, 10000);
1392 ons_debug(strcat(self.netname, " found an attackable controlpoint at ", vtos(cp.origin) ,"\n"));
1396 // Should be touched
1397 ons_debug(strcat(self.netname, " found a touchable controlpoint at ", vtos(cp.origin) ,"\n"));
1400 // Look for auto generated waypoint
1401 if (!bot_waypoints_for_items)
1402 for (wp = findradius(cp.origin,100); wp; wp = wp.chain)
1404 if(wp.classname=="waypoint")
1406 navigation_routerating(wp, ratingscale, 10000);
1411 // Nothing found, rate the controlpoint itself
1413 navigation_routerating(cp, ratingscale, 10000);
1417 bool havocbot_goalrating_ons_generator_attack(float ratingscale)
1419 entity g, wp, bestwp;
1423 for(g = ons_worldgeneratorlist; g; g = g.ons_worldgeneratornext)
1425 if(SAME_TEAM(g, self) || g.isshielded)
1428 // Should be attacked
1429 // Rate waypoints near it
1434 for(wp=findradius(g.origin,400); wp; wp=wp.chain)
1436 if(wp.classname=="waypoint")
1437 if(checkpvs(wp.origin,g))
1450 ons_debug("waypoints found around generator\n");
1451 navigation_routerating(bestwp, ratingscale, 10000);
1454 self.havocbot_attack_time = 0;
1455 if(checkpvs(self.view_ofs,g))
1456 if(checkpvs(self.view_ofs,bestwp))
1457 self.havocbot_attack_time = time + 5;
1463 ons_debug("generator found without waypoints around\n");
1464 // if there aren't waypoints near the generator go straight to it
1465 navigation_routerating(g, ratingscale, 10000);
1466 self.havocbot_attack_time = 0;
1473 void havocbot_role_ons_offense()
1475 if(self.deadflag != DEAD_NO)
1477 self.havocbot_attack_time = 0;
1478 havocbot_ons_reset_role(self);
1482 // Set the role timeout if necessary
1483 if (!self.havocbot_role_timeout)
1484 self.havocbot_role_timeout = time + 120;
1486 if (time > self.havocbot_role_timeout)
1488 havocbot_ons_reset_role(self);
1492 if(self.havocbot_attack_time>time)
1495 if (self.bot_strategytime < time)
1497 navigation_goalrating_start();
1498 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
1499 if(!havocbot_goalrating_ons_generator_attack(20000))
1500 havocbot_goalrating_ons_controlpoints_attack(20000);
1501 havocbot_goalrating_ons_offenseitems(10000, self.origin, 10000);
1502 navigation_goalrating_end();
1504 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
1508 void havocbot_role_ons_assistant()
1510 havocbot_ons_reset_role(self);
1513 void havocbot_role_ons_defense()
1515 havocbot_ons_reset_role(self);
1518 void havocbot_ons_reset_role(entity bot)
1523 if(self.deadflag != DEAD_NO)
1526 bot.havocbot_ons_target = world;
1528 // TODO: Defend control points or generator if necessary
1530 // if there is only me on the team switch to offense
1532 FOR_EACH_PLAYER(head)
1533 if(SAME_TEAM(head, self))
1538 havocbot_role_ons_setrole(bot, HAVOCBOT_ONS_ROLE_OFFENSE);
1542 havocbot_role_ons_setrole(bot, HAVOCBOT_ONS_ROLE_OFFENSE);
1547 * Find control point or generator owned by the same team self which is nearest to pos
1548 * if max_dist is positive, only control points within this range will be considered
1550 entity ons_Nearest_ControlPoint(vector pos, float max_dist)
1552 entity tmp_entity, closest_target = world;
1553 tmp_entity = findchain(classname, "onslaught_controlpoint");
1556 if(SAME_TEAM(tmp_entity, self))
1557 if(tmp_entity.iscaptured)
1558 if(max_dist <= 0 || vlen(tmp_entity.origin - pos) <= max_dist)
1559 if(vlen(tmp_entity.origin - pos) <= vlen(closest_target.origin - pos) || closest_target == world)
1560 closest_target = tmp_entity;
1561 tmp_entity = tmp_entity.chain;
1563 tmp_entity = findchain(classname, "onslaught_generator");
1566 if(SAME_TEAM(tmp_entity, self))
1567 if(max_dist <= 0 || vlen(tmp_entity.origin - pos) < max_dist)
1568 if(vlen(tmp_entity.origin - pos) <= vlen(closest_target.origin - pos) || closest_target == world)
1569 closest_target = tmp_entity;
1570 tmp_entity = tmp_entity.chain;
1573 return closest_target;
1577 * Find control point or generator owned by the same team self which is nearest to pos
1578 * if max_dist is positive, only control points within this range will be considered
1579 * This function only check distances on the XY plane, disregarding Z
1581 entity ons_Nearest_ControlPoint_2D(vector pos, float max_dist)
1583 entity tmp_entity, closest_target = world;
1585 float smallest_distance = 0, distance;
1587 tmp_entity = findchain(classname, "onslaught_controlpoint");
1590 delta = tmp_entity.origin - pos;
1592 distance = vlen(delta);
1594 if(SAME_TEAM(tmp_entity, self))
1595 if(tmp_entity.iscaptured)
1596 if(max_dist <= 0 || distance <= max_dist)
1597 if(closest_target == world || distance <= smallest_distance )
1599 closest_target = tmp_entity;
1600 smallest_distance = distance;
1603 tmp_entity = tmp_entity.chain;
1605 tmp_entity = findchain(classname, "onslaught_generator");
1608 delta = tmp_entity.origin - pos;
1610 distance = vlen(delta);
1612 if(SAME_TEAM(tmp_entity, self))
1613 if(max_dist <= 0 || distance <= max_dist)
1614 if(closest_target == world || distance <= smallest_distance )
1616 closest_target = tmp_entity;
1617 smallest_distance = distance;
1620 tmp_entity = tmp_entity.chain;
1623 return closest_target;
1626 * find the number of control points and generators in the same team as self
1628 int ons_Count_SelfControlPoints()
1631 tmp_entity = findchain(classname, "onslaught_controlpoint");
1635 if(SAME_TEAM(tmp_entity, self))
1636 if(tmp_entity.iscaptured)
1638 tmp_entity = tmp_entity.chain;
1640 tmp_entity = findchain(classname, "onslaught_generator");
1643 if(SAME_TEAM(tmp_entity, self))
1645 tmp_entity = tmp_entity.chain;
1651 * Teleport player to a random position near tele_target
1652 * if tele_effects is true, teleport sound+particles are created
1653 * return false on failure
1655 bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effects)
1663 for(i = 0; i < 16; ++i)
1665 theta = random() * 2 * M_PI;
1669 loc *= random() * range;
1671 loc += tele_target.origin + '0 0 128';
1673 tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, player);
1674 if(trace_fraction == 1.0 && !trace_startsolid)
1676 traceline(tele_target.origin, loc, MOVE_NOMONSTERS, tele_target); // double check to make sure we're not spawning outside the world
1677 if(trace_fraction == 1.0 && !trace_startsolid)
1681 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
1682 sound (player, CH_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTEN_NORM);
1684 setorigin(player, loc);
1685 player.angles = '0 1 0' * ( theta * RAD2DEG + 180 );
1686 makevectors(player.angles);
1687 player.fixangle = true;
1688 player.teleport_antispam = time + autocvar_g_onslaught_teleport_wait;
1691 Send_Effect(EFFECT_TELEPORT, player.origin + v_forward * 32, '0 0 0', 1);
1704 MUTATOR_HOOKFUNCTION(ons_ResetMap)
1706 FOR_EACH_PLAYER(self)
1708 self.ons_roundlost = false;
1709 self.ons_deathloc = '0 0 0';
1710 PutClientInServer();
1715 MUTATOR_HOOKFUNCTION(ons_RemovePlayer)
1717 self.ons_deathloc = '0 0 0';
1721 MUTATOR_HOOKFUNCTION(ons_PlayerSpawn)
1723 if(!round_handler_IsRoundStarted())
1725 self.player_blocked = true;
1730 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1732 l.sprite.SendFlags |= 16;
1734 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1736 l.sprite.SendFlags |= 16;
1739 if(ons_stalemate) { Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); }
1741 if ( autocvar_g_onslaught_spawn_choose )
1742 if ( self.ons_spawn_by )
1743 if ( ons_Teleport(self,self.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) )
1745 self.ons_spawn_by = world;
1749 if(autocvar_g_onslaught_spawn_at_controlpoints)
1750 if(random() <= autocvar_g_onslaught_spawn_at_controlpoints_chance)
1752 float random_target = autocvar_g_onslaught_spawn_at_controlpoints_random;
1753 entity tmp_entity, closest_target = world;
1754 vector spawn_loc = self.ons_deathloc;
1756 // new joining player or round reset, don't bother checking
1757 if(spawn_loc == '0 0 0') { return false; }
1759 if(random_target) { RandomSelection_Init(); }
1761 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1763 if(SAME_TEAM(tmp_entity, self))
1765 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1766 else if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world)
1767 closest_target = tmp_entity;
1770 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1776 for(i = 0; i < 10; ++i)
1778 loc = closest_target.origin + '0 0 96';
1779 loc += ('0 1 0' * random()) * 128;
1780 tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, self);
1781 if(trace_fraction == 1.0 && !trace_startsolid)
1783 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
1784 if(trace_fraction == 1.0 && !trace_startsolid)
1786 setorigin(self, loc);
1787 self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1795 if(autocvar_g_onslaught_spawn_at_generator)
1796 if(random() <= autocvar_g_onslaught_spawn_at_generator_chance)
1798 float random_target = autocvar_g_onslaught_spawn_at_generator_random;
1799 entity tmp_entity, closest_target = world;
1800 vector spawn_loc = self.ons_deathloc;
1802 // new joining player or round reset, don't bother checking
1803 if(spawn_loc == '0 0 0') { return false; }
1805 if(random_target) { RandomSelection_Init(); }
1807 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
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;
1819 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1825 for(i = 0; i < 10; ++i)
1827 loc = closest_target.origin + '0 0 128';
1828 loc += ('0 1 0' * random()) * 256;
1829 tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, self);
1830 if(trace_fraction == 1.0 && !trace_startsolid)
1832 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
1833 if(trace_fraction == 1.0 && !trace_startsolid)
1835 setorigin(self, loc);
1836 self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1847 MUTATOR_HOOKFUNCTION(ons_PlayerDies)
1849 frag_target.ons_deathloc = frag_target.origin;
1851 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1853 l.sprite.SendFlags |= 16;
1855 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1857 l.sprite.SendFlags |= 16;
1860 if ( autocvar_g_onslaught_spawn_choose )
1861 if ( ons_Count_SelfControlPoints() > 1 )
1862 stuffcmd(self, "qc_cmd_cl hud clickradar\n");
1867 MUTATOR_HOOKFUNCTION(ons_MonsterThink)
1869 entity e = find(world, targetname, self.target);
1876 void ons_MonsterSpawn_Delayed()
1878 entity e, own = self.owner;
1880 if(!own) { remove(self); return; }
1884 e = find(world, target, own.targetname);
1897 MUTATOR_HOOKFUNCTION(ons_MonsterSpawn)
1901 InitializeEntity(e, ons_MonsterSpawn_Delayed, INITPRIO_FINDTARGET);
1906 void ons_TurretSpawn_Delayed()
1908 entity e, own = self.owner;
1910 if(!own) { remove(self); return; }
1914 e = find(world, target, own.targetname);
1918 own.active = ACTIVE_NOT;
1928 MUTATOR_HOOKFUNCTION(ons_TurretSpawn)
1932 InitializeEntity(e, ons_TurretSpawn_Delayed, INITPRIO_FINDTARGET);
1937 MUTATOR_HOOKFUNCTION(ons_BotRoles)
1939 havocbot_ons_reset_role(self);
1943 MUTATOR_HOOKFUNCTION(ons_GetTeamCount)
1945 // onslaught is special
1947 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1949 switch(tmp_entity.team)
1951 case NUM_TEAM_1: c1 = 0; break;
1952 case NUM_TEAM_2: c2 = 0; break;
1953 case NUM_TEAM_3: c3 = 0; break;
1954 case NUM_TEAM_4: c4 = 0; break;
1961 MUTATOR_HOOKFUNCTION(ons_SpectateCopy)
1963 self.ons_roundlost = other.ons_roundlost; // make spectators see it too
1967 MUTATOR_HOOKFUNCTION(ons_SV_ParseClientCommand)
1969 if(MUTATOR_RETURNVALUE) // command was already handled?
1972 if ( cmd_name == "ons_spawn" )
1974 vector pos = self.origin;
1976 pos_x = stof(argv(1));
1978 pos_y = stof(argv(2));
1980 pos_z = stof(argv(3));
1982 if ( IS_PLAYER(self) )
1986 entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
1988 if ( !source_point && self.health > 0 )
1990 sprint(self, "\nYou need to be next to a control point\n");
1995 entity closest_target = ons_Nearest_ControlPoint_2D(pos, autocvar_g_onslaught_click_radius);
1997 if ( closest_target == world )
1999 sprint(self, "\nNo control point found\n");
2003 if ( self.health <= 0 )
2005 self.ons_spawn_by = closest_target;
2006 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
2010 if ( source_point == closest_target )
2012 sprint(self, "\nTeleporting to the same point\n");
2016 if ( !ons_Teleport(self,closest_target,autocvar_g_onslaught_teleport_radius,true) )
2017 sprint(self, "\nUnable to teleport there\n");
2023 sprint(self, "\nNo teleportation for you\n");
2031 MUTATOR_HOOKFUNCTION(ons_PlayerUseKey)
2033 if(MUTATOR_RETURNVALUE || gameover) { return false; }
2035 if((time > self.teleport_antispam) && (self.deadflag == DEAD_NO) && !self.vehicle)
2037 entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
2040 stuffcmd(self, "qc_cmd_cl hud clickradar\n");
2048 MUTATOR_HOOKFUNCTION(ons_PlayHitsound)
2050 return (frag_victim.classname == "onslaught_generator" && !frag_victim.isshielded)
2051 || (frag_victim.classname == "onslaught_controlpoint_icon" && !frag_victim.owner.isshielded);
2058 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
2059 Link between control points.
2061 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.
2064 "target" - first control point.
2065 "target2" - second control point.
2067 void spawnfunc_onslaught_link()
2069 if(!g_onslaught) { remove(self); return; }
2071 if (self.target == "" || self.target2 == "")
2072 objerror("target and target2 must be set\n");
2074 self.ons_worldlinknext = ons_worldlinklist; // link into ons_worldlinklist
2075 ons_worldlinklist = self;
2077 InitializeEntity(self, ons_DelayedLinkSetup, INITPRIO_FINDTARGET);
2078 Net_LinkEntity(self, false, 0, ons_Link_Send);
2081 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
2082 Control point. Be sure to give this enough clearance so that the shootable part has room to exist
2084 This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
2087 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2088 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
2089 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
2092 void spawnfunc_onslaught_controlpoint()
2094 if(!g_onslaught) { remove(self); return; }
2096 ons_ControlPoint_Setup(self);
2099 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
2102 spawnfunc_onslaught_link entities can target this.
2105 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
2106 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2108 void spawnfunc_onslaught_generator()
2110 if(!g_onslaught) { remove(self); return; }
2111 if(!self.team) { objerror("team must be set"); }
2113 ons_GeneratorSetup(self);
2117 void ons_ScoreRules()
2119 CheckAllowedTeams(world);
2120 ScoreRules_basics(((c4>=0) ? 4 : (c3>=0) ? 3 : 2), SFL_SORT_PRIO_PRIMARY, 0, true);
2121 ScoreInfo_SetLabel_TeamScore (ST_ONS_CAPS, "destroyed", SFL_SORT_PRIO_PRIMARY);
2122 ScoreInfo_SetLabel_PlayerScore(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
2123 ScoreInfo_SetLabel_PlayerScore(SP_ONS_TAKES, "takes", 0);
2124 ScoreRules_basics_end();
2127 void ons_DelayedInit() // Do this check with a delay so we can wait for teams to be set up
2131 round_handler_Spawn(Onslaught_CheckPlayers, Onslaught_CheckWinner, Onslaught_RoundStart);
2132 round_handler_Init(5, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
2135 void ons_Initialize()
2137 precache_sound("ctf/red_capture.wav");
2138 precache_sound("ctf/blue_capture.wav");
2139 precache_sound("ctf/yellow_capture.wav");
2140 precache_sound("ctf/pink_capture.wav");
2142 ons_captureshield_force = autocvar_g_onslaught_shield_force;
2144 addstat(STAT_ROUNDLOST, AS_INT, ons_roundlost);
2146 InitializeEntity(world, ons_DelayedInit, INITPRIO_GAMETYPE);
2149 MUTATOR_DEFINITION(gamemode_onslaught)
2151 MUTATOR_HOOK(reset_map_global, ons_ResetMap, CBC_ORDER_ANY);
2152 MUTATOR_HOOK(MakePlayerObserver, ons_RemovePlayer, CBC_ORDER_ANY);
2153 MUTATOR_HOOK(ClientDisconnect, ons_RemovePlayer, CBC_ORDER_ANY);
2154 MUTATOR_HOOK(PlayerSpawn, ons_PlayerSpawn, CBC_ORDER_ANY);
2155 MUTATOR_HOOK(PlayerDies, ons_PlayerDies, CBC_ORDER_ANY);
2156 MUTATOR_HOOK(MonsterMove, ons_MonsterThink, CBC_ORDER_ANY);
2157 MUTATOR_HOOK(MonsterSpawn, ons_MonsterSpawn, CBC_ORDER_ANY);
2158 MUTATOR_HOOK(TurretSpawn, ons_TurretSpawn, CBC_ORDER_ANY);
2159 MUTATOR_HOOK(HavocBot_ChooseRole, ons_BotRoles, CBC_ORDER_ANY);
2160 MUTATOR_HOOK(GetTeamCount, ons_GetTeamCount, CBC_ORDER_ANY);
2161 MUTATOR_HOOK(SpectateCopy, ons_SpectateCopy, CBC_ORDER_ANY);
2162 MUTATOR_HOOK(SV_ParseClientCommand, ons_SV_ParseClientCommand, CBC_ORDER_ANY);
2163 MUTATOR_HOOK(PlayerUseKey, ons_PlayerUseKey, CBC_ORDER_ANY);
2164 MUTATOR_HOOK(PlayHitsound, ons_PlayHitsound, CBC_ORDER_ANY);
2168 if(time > 1) // game loads at time 1
2169 error("This is a game type and it cannot be added at runtime.");
2173 MUTATOR_ONROLLBACK_OR_REMOVE
2175 // we actually cannot roll back ons_Initialize here
2176 // BUT: we don't need to! If this gets called, adding always
2182 LOG_INFO("This is a game type and it cannot be removed at runtime.");