1 #include "../controlpoint.qh"
2 #include "../generator.qh"
4 // =======================
5 // CaptureShield Functions
6 // =======================
8 bool ons_CaptureShield_Customize()
10 entity e = WaypointSprite_getviewentity(other);
12 if(!self.enemy.isshielded && (ons_ControlPoint_Attackable(self.enemy, e.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return false; }
13 if(SAME_TEAM(self, e)) { return false; }
18 void ons_CaptureShield_Touch()
20 if(!self.enemy.isshielded && (ons_ControlPoint_Attackable(self.enemy, other.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return; }
21 if(!IS_PLAYER(other)) { return; }
22 if(SAME_TEAM(other, self)) { return; }
24 vector mymid = (self.absmin + self.absmax) * 0.5;
25 vector othermid = (other.absmin + other.absmax) * 0.5;
27 Damage(other, self, self, 0, DEATH_HURTTRIGGER, mymid, normalize(othermid - mymid) * ons_captureshield_force);
29 if(IS_REAL_CLIENT(other))
31 play2(other, "onslaught/damageblockedbyshield.wav");
33 if(self.enemy.classname == "onslaught_generator")
34 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_GENERATOR_SHIELDED);
36 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_CONTROLPOINT_SHIELDED);
40 void ons_CaptureShield_Reset()
42 self.colormap = self.enemy.colormap;
43 self.team = self.enemy.team;
46 void ons_CaptureShield_Spawn(entity generator, bool is_generator)
48 entity shield = spawn();
50 shield.enemy = generator;
51 shield.team = generator.team;
52 shield.colormap = generator.colormap;
53 shield.reset = ons_CaptureShield_Reset;
54 shield.touch = ons_CaptureShield_Touch;
55 shield.customizeentityforclient = ons_CaptureShield_Customize;
56 shield.classname = "ons_captureshield";
57 shield.effects = EF_ADDITIVE;
58 shield.movetype = MOVETYPE_NOCLIP;
59 shield.solid = SOLID_TRIGGER;
60 shield.avelocity = '7 0 11';
62 shield.model = ((is_generator) ? "models/onslaught/generator_shield.md3" : "models/onslaught/controlpoint_shield.md3");
64 precache_model(shield.model);
65 setorigin(shield, generator.origin);
66 setmodel(shield, shield.model);
67 setsize(shield, shield.scale * shield.mins, shield.scale * shield.maxs);
75 void ons_debug(string input)
77 switch(autocvar_g_onslaught_debug)
79 case 1: dprint(input); break;
80 case 2: print(input); break;
84 void FixSize(entity e)
86 e.mins_x = rint(e.mins_x);
87 e.mins_y = rint(e.mins_y);
88 e.mins_z = rint(e.mins_z);
90 e.maxs_x = rint(e.maxs_x);
91 e.maxs_y = rint(e.maxs_y);
92 e.maxs_z = rint(e.maxs_z);
95 vector randompos(vector m1, vector m2)
99 v_x = m2_x * random() + m1_x;
100 v_y = m2_y * random() + m1_y;
101 v_z = m2_z * random() + m1_z;
105 void setmodel_fixsize(entity e, string m)
111 void onslaught_updatelinks()
114 // first check if the game has ended
115 ons_debug("--- updatelinks ---\n");
116 // mark generators as being shielded and networked
117 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
120 ons_debug(strcat(etos(l), " (generator) belongs to team ", ftos(l.team), "\n"));
122 ons_debug(strcat(etos(l), " (generator) is destroyed\n"));
123 l.islinked = l.iscaptured;
124 l.isshielded = l.iscaptured;
125 l.sprite.SendFlags |= 16;
127 // mark points as shielded and not networked
128 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
133 for(i = 0; i < 17; ++i) { l.isgenneighbor[i] = false; l.iscpneighbor[i] = false; }
134 ons_debug(strcat(etos(l), " (point) belongs to team ", ftos(l.team), "\n"));
135 l.sprite.SendFlags |= 16;
137 // flow power outward from the generators through the network
142 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
144 // if both points are captured by the same team, and only one of
145 // them is powered, mark the other one as powered as well
146 if (l.enemy.iscaptured && l.goalentity.iscaptured)
147 if (l.enemy.islinked != l.goalentity.islinked)
148 if(SAME_TEAM(l.enemy, l.goalentity))
150 if (!l.goalentity.islinked)
153 l.goalentity.islinked = true;
154 ons_debug(strcat(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)\n"));
156 else if (!l.enemy.islinked)
159 l.enemy.islinked = true;
160 ons_debug(strcat(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)\n"));
165 // now that we know which points are powered we can mark their neighbors
166 // as unshielded if team differs
167 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
169 if (l.goalentity.islinked)
171 if(DIFF_TEAM(l.goalentity, l.enemy))
173 ons_debug(strcat(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)\n"));
174 l.enemy.isshielded = false;
176 if(l.goalentity.classname == "onslaught_generator")
177 l.enemy.isgenneighbor[l.goalentity.team] = true;
179 l.enemy.iscpneighbor[l.goalentity.team] = true;
181 if (l.enemy.islinked)
183 if(DIFF_TEAM(l.goalentity, l.enemy))
185 ons_debug(strcat(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)\n"));
186 l.goalentity.isshielded = false;
188 if(l.enemy.classname == "onslaught_generator")
189 l.goalentity.isgenneighbor[l.enemy.team] = true;
191 l.goalentity.iscpneighbor[l.enemy.team] = true;
194 // now update the generators
195 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
199 ons_debug(strcat(etos(l), " (generator) is shielded\n"));
200 l.takedamage = DAMAGE_NO;
201 l.bot_attack = false;
205 ons_debug(strcat(etos(l), " (generator) is not shielded\n"));
206 l.takedamage = DAMAGE_AIM;
210 ons_Generator_UpdateSprite(l);
212 // now update the takedamage and alpha variables on control point icons
213 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
217 ons_debug(strcat(etos(l), " (point) is shielded\n"));
220 l.goalentity.takedamage = DAMAGE_NO;
221 l.goalentity.bot_attack = false;
226 ons_debug(strcat(etos(l), " (point) is not shielded\n"));
229 l.goalentity.takedamage = DAMAGE_AIM;
230 l.goalentity.bot_attack = true;
233 ons_ControlPoint_UpdateSprite(l);
235 l = findchain(classname, "ons_captureshield");
238 l.team = l.enemy.team;
239 l.colormap = l.enemy.colormap;
245 // ===================
246 // Main Link Functions
247 // ===================
249 bool ons_Link_Send(entity to, int sendflags)
251 WriteByte(MSG_ENTITY, ENT_CLIENT_RADARLINK);
252 WriteByte(MSG_ENTITY, sendflags);
255 WriteCoord(MSG_ENTITY, self.goalentity.origin_x);
256 WriteCoord(MSG_ENTITY, self.goalentity.origin_y);
257 WriteCoord(MSG_ENTITY, self.goalentity.origin_z);
261 WriteCoord(MSG_ENTITY, self.enemy.origin_x);
262 WriteCoord(MSG_ENTITY, self.enemy.origin_y);
263 WriteCoord(MSG_ENTITY, self.enemy.origin_z);
267 WriteByte(MSG_ENTITY, self.clientcolors); // which is goalentity's color + enemy's color * 16
272 void ons_Link_CheckUpdate()
274 // TODO check if the two sides have moved (currently they won't move anyway)
275 float cc = 0, cc1 = 0, cc2 = 0;
277 if(self.goalentity.islinked || self.goalentity.iscaptured) { cc1 = (self.goalentity.team - 1) * 0x01; }
278 if(self.enemy.islinked || self.enemy.iscaptured) { cc2 = (self.enemy.team - 1) * 0x10; }
282 if(cc != self.clientcolors)
284 self.clientcolors = cc;
288 self.nextthink = time;
291 void ons_DelayedLinkSetup()
293 self.goalentity = find(world, targetname, self.target);
294 self.enemy = find(world, targetname, self.target2);
295 if(!self.goalentity) { objerror("can not find target\n"); }
296 if(!self.enemy) { objerror("can not find target2\n"); }
298 ons_debug(strcat(etos(self.goalentity), " linked with ", etos(self.enemy), "\n"));
300 self.think = ons_Link_CheckUpdate;
301 self.nextthink = time;
305 // =============================
306 // Main Control Point Functions
307 // =============================
309 int ons_ControlPoint_CanBeLinked(entity cp, int teamnumber)
311 if(cp.isgenneighbor[teamnumber]) { return 2; }
312 if(cp.iscpneighbor[teamnumber]) { return 1; }
317 int ons_ControlPoint_Attackable(entity cp, int teamnumber)
318 // -2: SAME TEAM, attackable by enemy!
323 // 3: attack it (HIGH PRIO)
324 // 4: touch it (HIGH PRIO)
332 else if(cp.goalentity)
334 // if there's already an icon built, nothing happens
335 if(cp.team == teamnumber)
337 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
338 if(a) // attackable by enemy?
339 return -2; // EMERGENCY!
342 // we know it can be linked, so no need to check
344 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
345 if(a == 2) // near our generator?
346 return 3; // EMERGENCY!
352 if(ons_ControlPoint_CanBeLinked(cp, teamnumber))
354 a = ons_ControlPoint_CanBeLinked(cp, teamnumber); // why was this here NUM_TEAM_1 + NUM_TEAM_2 - t
356 return 4; // GET THIS ONE NOW!
358 return 2; // TOUCH ME
364 void ons_ControlPoint_Icon_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
368 if(damage <= 0) { return; }
370 if (self.owner.isshielded)
372 // this is protected by a shield, so ignore the damage
373 if (time > self.pain_finished)
374 if (IS_PLAYER(attacker))
376 play2(attacker, "onslaught/damageblockedbyshield.wav");
377 self.pain_finished = time + 1;
378 attacker.typehitsound += 1; // play both sounds (shield is way too quiet)
384 if(IS_PLAYER(attacker))
385 if(time - ons_notification_time[self.team] > 10)
387 play2team(self.team, "onslaught/controlpoint_underattack.wav");
388 ons_notification_time[self.team] = time;
391 self.health = self.health - damage;
392 if(self.owner.iscaptured)
393 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
395 WaypointSprite_UpdateBuildFinished(self.owner.sprite, time + (self.max_health - self.health) / (self.count / ONS_CP_THINKRATE));
396 self.pain_finished = time + 1;
397 // particles on every hit
398 pointparticles(particleeffectnum("sparks"), hitloc, force*-1, 1);
401 sound(self, CH_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE+0.3, ATTEN_NORM);
403 sound(self, CH_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE+0.3, ATTEN_NORM);
407 sound(self, CH_TRIGGER, "weapons/grenade_impact.wav", VOL_BASE, ATTEN_NORM);
408 pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
409 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_CPDESTROYED_), self.owner.message, attacker.netname);
411 PlayerScore_Add(attacker, SP_ONS_TAKES, 1);
412 PlayerScore_Add(attacker, SP_SCORE, 10);
414 self.owner.goalentity = world;
415 self.owner.islinked = false;
416 self.owner.iscaptured = false;
418 self.owner.colormap = 1024;
420 WaypointSprite_UpdateMaxHealth(self.owner.sprite, 0);
422 onslaught_updatelinks();
424 // Use targets now (somebody make sure this is in the right place..)
431 self.owner.waslinked = self.owner.islinked;
432 if(self.owner.model != "models/onslaught/controlpoint_pad.md3")
433 setmodel_fixsize(self.owner, "models/onslaught/controlpoint_pad.md3");
434 //setsize(self, '-32 -32 0', '32 32 8');
439 self.SendFlags |= CPSF_STATUS;
442 void ons_ControlPoint_Icon_Think()
445 self.nextthink = time + ONS_CP_THINKRATE;
447 if(autocvar_g_onslaught_cp_proxydecap)
449 int _enemy_count = 0;
450 int _friendly_count = 0;
454 FOR_EACH_PLAYER(_player)
456 if(!_player.deadflag)
458 _dist = vlen(_player.origin - self.origin);
459 if(_dist < autocvar_g_onslaught_cp_proxydecap_distance)
461 if(SAME_TEAM(_player, self))
469 _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
470 _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
472 self.health = bound(0, self.health + (_friendly_count - _enemy_count), self.max_health);
473 self.SendFlags |= CPSF_STATUS;
476 ons_ControlPoint_Icon_Damage(self, self, 1, 0, self.origin, '0 0 0');
481 if (time > self.pain_finished + 5)
483 if(self.health < self.max_health)
485 self.health = self.health + self.count;
486 if (self.health >= self.max_health)
487 self.health = self.max_health;
488 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
492 if(self.owner.islinked != self.owner.waslinked)
494 // unteam the spawnpoint if needed
495 int t = self.owner.team;
496 if(!self.owner.islinked)
507 self.owner.waslinked = self.owner.islinked;
511 if(random() < 0.6 - self.health / self.max_health)
513 pointparticles(particleeffectnum("electricity_sparks"), self.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
516 sound(self, CH_PAIN, "onslaught/ons_spark1.wav", VOL_BASE, ATTEN_NORM);
517 else if (random() > 0.5)
518 sound(self, CH_PAIN, "onslaught/ons_spark2.wav", VOL_BASE, ATTEN_NORM);
522 void ons_ControlPoint_Icon_BuildThink()
527 self.nextthink = time + ONS_CP_THINKRATE;
529 // only do this if there is power
530 a = ons_ControlPoint_CanBeLinked(self.owner, self.owner.team);
534 self.health = self.health + self.count;
536 self.SendFlags |= CPSF_STATUS;
538 if (self.health >= self.max_health)
540 self.health = self.max_health;
541 self.count = autocvar_g_onslaught_cp_regen * ONS_CP_THINKRATE; // slow repair rate from now on
542 self.think = ons_ControlPoint_Icon_Think;
543 sound(self, CH_TRIGGER, "onslaught/controlpoint_built.wav", VOL_BASE, ATTEN_NORM);
544 self.owner.iscaptured = true;
545 self.solid = SOLID_BBOX;
547 pointparticles(particleeffectnum(sprintf("%s_cap", Static_Team_ColorName_Lower(self.owner.team))), self.owner.origin, '0 0 0', 1);
549 WaypointSprite_UpdateMaxHealth(self.owner.sprite, self.max_health);
550 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
552 if(IS_PLAYER(self.owner.ons_toucher))
554 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ONSLAUGHT_CAPTURE, self.owner.ons_toucher.netname, self.owner.message);
555 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);
556 Send_Notification(NOTIF_ONE, self.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE, self.owner.message);
557 PlayerScore_Add(self.owner.ons_toucher, SP_ONS_CAPS, 1);
558 PlayerTeamScore_AddScore(self.owner.ons_toucher, 10);
561 self.owner.ons_toucher = world;
563 onslaught_updatelinks();
565 // Use targets now (somebody make sure this is in the right place..)
572 self.SendFlags |= CPSF_SETUP;
574 if(self.owner.model != "models/onslaught/controlpoint_pad2.md3")
575 setmodel_fixsize(self.owner, "models/onslaught/controlpoint_pad2.md3");
577 if(random() < 0.9 - self.health / self.max_health)
578 pointparticles(particleeffectnum("rage"), self.origin + 10 * randomvec(), '0 0 -1', 1);
581 void ons_ControlPoint_Icon_Spawn(entity cp, entity player)
585 setsize(e, CPICON_MIN, CPICON_MAX);
586 setorigin(e, cp.origin + CPICON_OFFSET);
588 e.classname = "onslaught_controlpoint_icon";
590 e.max_health = autocvar_g_onslaught_cp_health;
591 e.health = autocvar_g_onslaught_cp_buildhealth;
593 e.takedamage = DAMAGE_AIM;
595 e.event_damage = ons_ControlPoint_Icon_Damage;
596 e.team = player.team;
597 e.colormap = 1024 + (e.team - 1) * 17;
598 e.count = (e.max_health - e.health) * ONS_CP_THINKRATE / autocvar_g_onslaught_cp_buildtime; // how long it takes to build
600 sound(e, CH_TRIGGER, "onslaught/controlpoint_build.wav", VOL_BASE, ATTEN_NORM);
604 cp.colormap = e.colormap;
606 pointparticles(particleeffectnum(sprintf("%sflag_touch", Static_Team_ColorName_Lower(player.team))), e.origin, '0 0 0', 1);
608 WaypointSprite_UpdateBuildFinished(cp.sprite, time + (e.max_health - e.health) / (e.count / ONS_CP_THINKRATE));
609 WaypointSprite_UpdateRule(cp.sprite,cp.team,SPRITERULE_TEAMPLAY);
610 cp.sprite.SendFlags |= 16;
612 onslaught_controlpoint_icon_link(e, ons_ControlPoint_Icon_BuildThink);
615 string ons_ControlPoint_Waypoint(entity e)
619 int a = ons_ControlPoint_Attackable(e, e.team);
621 if(a == -2) { return "ons-cp-dfnd"; } // defend now
622 if(a == -1 || a == 1 || a == 2) { return "ons-cp"; } // touch
623 if(a == 3 || a == 4) { return "ons-cp-atck"; } // attack
631 void ons_ControlPoint_UpdateSprite(entity e)
634 s1 = ons_ControlPoint_Waypoint(e);
635 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
638 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));
640 if(e.lastteam != e.team + 2 || e.lastshielded != sh || e.iscaptured != e.lastcaptured)
642 if(e.iscaptured) // don't mess up build bars!
646 WaypointSprite_UpdateMaxHealth(e.sprite, 0);
650 WaypointSprite_UpdateMaxHealth(e.sprite, e.goalentity.max_health);
651 WaypointSprite_UpdateHealth(e.sprite, e.goalentity.health);
657 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, false));
659 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
664 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, false));
666 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
668 WaypointSprite_Ping(e.sprite);
670 e.lastteam = e.team + 2;
672 e.lastcaptured = e.iscaptured;
676 void ons_ControlPoint_Touch()
678 entity toucher = other;
681 if((toucher.vehicle_flags & VHF_ISVEHICLE) && toucher.owner)
682 if(autocvar_g_onslaught_allow_vehicle_touch)
683 toucher = toucher.owner;
687 if(!IS_PLAYER(toucher)) { return; }
688 if(toucher.frozen) { return; }
689 if(toucher.deadflag != DEAD_NO) { return; }
691 if ( SAME_TEAM(self,toucher) )
692 if ( self.iscaptured )
694 if(time <= toucher.teleport_antispam)
695 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT_ANTISPAM, rint(toucher.teleport_antispam - time));
697 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
700 attackable = ons_ControlPoint_Attackable(self, toucher.team);
701 if(attackable != 2 && attackable != 4)
703 // we've verified that this player has a legitimate claim to this point,
704 // so start building the captured point icon (which only captures this
705 // point if it successfully builds without being destroyed first)
706 ons_ControlPoint_Icon_Spawn(self, toucher);
708 self.ons_toucher = toucher;
710 onslaught_updatelinks();
713 void ons_ControlPoint_Think()
715 self.nextthink = time + ONS_CP_THINKRATE;
716 CSQCMODEL_AUTOUPDATE();
719 void ons_ControlPoint_Reset()
722 remove(self.goalentity);
724 self.goalentity = world;
726 self.colormap = 1024;
727 self.iscaptured = false;
728 self.islinked = false;
729 self.isshielded = true;
730 self.think = ons_ControlPoint_Think;
731 self.ons_toucher = world;
732 self.nextthink = time + ONS_CP_THINKRATE;
733 setmodel_fixsize(self, "models/onslaught/controlpoint_pad.md3");
735 WaypointSprite_UpdateMaxHealth(self.sprite, 0);
736 WaypointSprite_UpdateRule(self.sprite,self.team,SPRITERULE_TEAMPLAY);
738 onslaught_updatelinks();
741 SUB_UseTargets(); // to reset the structures, playerspawns etc.
743 CSQCMODEL_AUTOUPDATE();
746 void ons_DelayedControlPoint_Setup(void)
748 onslaught_updatelinks();
750 // captureshield setup
751 ons_CaptureShield_Spawn(self, false);
753 CSQCMODEL_AUTOINIT();
756 void ons_ControlPoint_Setup(entity cp)
759 self = cp; // for later usage with droptofloor()
762 cp.ons_worldcpnext = ons_worldcplist; // link control point into ons_worldcplist
763 ons_worldcplist = cp;
765 cp.netname = "Control point";
767 cp.solid = SOLID_BBOX;
768 cp.movetype = MOVETYPE_NONE;
769 cp.touch = ons_ControlPoint_Touch;
770 cp.think = ons_ControlPoint_Think;
771 cp.nextthink = time + ONS_CP_THINKRATE;
772 cp.reset = ons_ControlPoint_Reset;
774 cp.iscaptured = false;
776 cp.isshielded = true;
778 if(cp.message == "") { cp.message = "a"; }
780 // precache - TODO: clean up!
781 precache_model("models/onslaught/controlpoint_pad.md3");
782 precache_model("models/onslaught/controlpoint_pad2.md3");
783 precache_model("models/onslaught/controlpoint_shield.md3");
784 precache_model("models/onslaught/controlpoint_icon.md3");
785 precache_model("models/onslaught/controlpoint_icon_dmg1.md3");
786 precache_model("models/onslaught/controlpoint_icon_dmg2.md3");
787 precache_model("models/onslaught/controlpoint_icon_dmg3.md3");
788 precache_model("models/onslaught/controlpoint_icon_gib1.md3");
789 precache_model("models/onslaught/controlpoint_icon_gib2.md3");
790 precache_model("models/onslaught/controlpoint_icon_gib4.md3");
791 precache_sound("onslaught/controlpoint_build.wav");
792 precache_sound("onslaught/controlpoint_built.wav");
793 precache_sound("weapons/grenade_impact.wav");
794 precache_sound("onslaught/damageblockedbyshield.wav");
795 precache_sound("onslaught/controlpoint_underattack.wav");
796 precache_sound("onslaught/ons_spark1.wav");
797 precache_sound("onslaught/ons_spark2.wav");
800 setmodel_fixsize(cp, "models/onslaught/controlpoint_pad.md3");
802 // control point placement
803 if((cp.spawnflags & 1) || cp.noalign) // don't drop to floor, just stay at fixed location
806 cp.movetype = MOVETYPE_NONE;
808 else // drop to floor, automatically find a platform and set that as spawn origin
810 setorigin(cp, cp.origin + '0 0 20');
814 cp.movetype = MOVETYPE_TOSS;
818 WaypointSprite_SpawnFixed(string_null, self.origin + CPGEN_WAYPOINT_OFFSET, self, sprite, RADARICON_NONE, '0 0 0');
819 WaypointSprite_UpdateRule(self.sprite, self.team, SPRITERULE_TEAMPLAY);
821 InitializeEntity(cp, ons_DelayedControlPoint_Setup, INITPRIO_SETLOCATION);
825 // =========================
826 // Main Generator Functions
827 // =========================
829 string ons_Generator_Waypoint(entity e)
832 return "ons-gen-shielded";
836 void ons_Generator_UpdateSprite(entity e)
838 string s1 = ons_Generator_Waypoint(e);
839 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
841 if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
843 e.lastteam = e.team + 2;
844 e.lastshielded = e.isshielded;
848 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, false));
850 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
855 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, false));
857 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
859 WaypointSprite_Ping(e.sprite);
863 void ons_GeneratorDamage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
865 if(damage <= 0) { return; }
866 if(warmup_stage || gameover) { return; }
867 if(!round_handler_IsRoundStarted()) { return; }
869 if (attacker != self)
873 // this is protected by a shield, so ignore the damage
874 if (time > self.pain_finished)
875 if (IS_PLAYER(attacker))
877 play2(attacker, "onslaught/damageblockedbyshield.wav");
878 attacker.typehitsound += 1;
879 self.pain_finished = time + 1;
883 if (time > self.pain_finished)
885 self.pain_finished = time + 10;
887 FOR_EACH_REALPLAYER(head) if(SAME_TEAM(head, self)) { Send_Notification(NOTIF_ONE, head, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK); }
888 play2team(self.team, "onslaught/generator_underattack.wav");
891 self.health = self.health - damage;
892 WaypointSprite_UpdateHealth(self.sprite, self.health);
893 // choose an animation frame based on health
894 self.frame = 10 * bound(0, (1 - self.health / self.max_health), 1);
895 // see if the generator is still functional, or dying
898 self.lasthealth = self.health;
902 if (attacker == self)
903 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME_));
906 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_GENDESTROYED_));
907 PlayerScore_Add(attacker, SP_SCORE, 100);
909 self.iscaptured = false;
910 self.islinked = false;
911 self.isshielded = false;
912 self.takedamage = DAMAGE_NO; // can't be hurt anymore
913 self.event_damage = func_null; // won't do anything if hurt
914 self.count = 0; // reset counter
915 self.think = func_null;
917 //self.think(); // do the first explosion now
919 WaypointSprite_UpdateMaxHealth(self.sprite, 0);
920 WaypointSprite_Ping(self.sprite);
921 //WaypointSprite_Kill(self.sprite); // can't do this yet, code too poor
923 onslaught_updatelinks();
926 // Throw some flaming gibs on damage, more damage = more chance for gib
927 if(random() < damage/220)
929 sound(self, CH_TRIGGER, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
933 // particles on every hit
934 pointparticles(particleeffectnum("sparks"), hitloc, force * -1, 1);
938 sound(self, CH_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE, ATTEN_NORM);
940 sound(self, CH_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM);
943 self.SendFlags |= GSF_STATUS;
946 void ons_GeneratorThink()
949 self.nextthink = time + GEN_THINKRATE;
952 if(!self.isshielded && self.wait < time)
954 self.wait = time + 5;
955 FOR_EACH_REALPLAYER(e)
957 if(SAME_TEAM(e, self))
959 Send_Notification(NOTIF_ONE, e, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM);
960 soundto(MSG_ONE, e, CHAN_AUTO, "kh/alarm.wav", VOL_BASE, ATTEN_NONE); // FIXME: unique sound?
963 Send_Notification(NOTIF_ONE, e, MSG_CENTER, APP_TEAM_NUM_4(self.team, CENTER_ONS_NOTSHIELDED_));
969 void ons_GeneratorReset()
971 self.team = self.team_saved;
972 self.lasthealth = self.max_health = self.health = autocvar_g_onslaught_gen_health;
973 self.takedamage = DAMAGE_AIM;
974 self.bot_attack = true;
975 self.iscaptured = true;
976 self.islinked = true;
977 self.isshielded = true;
978 self.event_damage = ons_GeneratorDamage;
979 self.think = ons_GeneratorThink;
980 self.nextthink = time + GEN_THINKRATE;
982 Net_LinkEntity(self, false, 0, generator_send);
984 self.SendFlags = GSF_SETUP; // just incase
985 self.SendFlags |= GSF_STATUS;
987 WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
988 WaypointSprite_UpdateHealth(self.sprite, self.health);
989 WaypointSprite_UpdateRule(self.sprite,self.team,SPRITERULE_TEAMPLAY);
991 onslaught_updatelinks();
994 void ons_DelayedGeneratorSetup()
997 waypoint_spawnforitem_force(self, self.origin);
998 self.nearestwaypointtimeout = 0; // activate waypointing again
999 self.bot_basewaypoint = self.nearestwaypoint;
1001 // captureshield setup
1002 ons_CaptureShield_Spawn(self, true);
1004 onslaught_updatelinks();
1006 Net_LinkEntity(self, false, 0, generator_send);
1010 void onslaught_generator_touch()
1012 if ( IS_PLAYER(other) )
1013 if ( SAME_TEAM(self,other) )
1014 if ( self.iscaptured )
1016 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_TELEPORT);
1020 void ons_GeneratorSetup(entity gen) // called when spawning a generator entity on the map as a spawnfunc
1023 int teamnumber = gen.team;
1024 self = gen; // for later usage with droptofloor()
1027 gen.ons_worldgeneratornext = ons_worldgeneratorlist; // link generator into ons_worldgeneratorlist
1028 ons_worldgeneratorlist = gen;
1030 gen.netname = sprintf("%s generator", Team_ColoredFullName(teamnumber));
1031 gen.classname = "onslaught_generator";
1032 gen.solid = SOLID_BBOX;
1033 gen.team_saved = teamnumber;
1034 gen.movetype = MOVETYPE_NONE;
1035 gen.lasthealth = gen.max_health = gen.health = autocvar_g_onslaught_gen_health;
1036 gen.takedamage = DAMAGE_AIM;
1037 gen.bot_attack = true;
1038 gen.event_damage = ons_GeneratorDamage;
1039 gen.reset = ons_GeneratorReset;
1040 gen.think = ons_GeneratorThink;
1041 gen.nextthink = time + GEN_THINKRATE;
1042 gen.iscaptured = true;
1043 gen.islinked = true;
1044 gen.isshielded = true;
1045 gen.touch = onslaught_generator_touch;
1047 // precache - TODO: clean up!
1048 precache_model("models/onslaught/generator_shield.md3");
1049 precache_model("models/onslaught/gen_gib1.md3");
1050 precache_model("models/onslaught/gen_gib2.md3");
1051 precache_model("models/onslaught/gen_gib3.md3");
1052 precache_sound("onslaught/generator_decay.wav");
1053 precache_sound("weapons/grenade_impact.wav");
1054 precache_sound("weapons/rocket_impact.wav");
1055 precache_sound("onslaught/generator_underattack.wav");
1056 precache_sound("onslaught/shockwave.wav");
1057 precache_sound("onslaught/ons_hit1.wav");
1058 precache_sound("onslaught/ons_hit2.wav");
1059 precache_sound("onslaught/generator_underattack.wav");
1062 // model handled by CSQC
1063 setsize(gen, GENERATOR_MIN, GENERATOR_MAX);
1064 setorigin(gen, (gen.origin + CPGEN_SPAWN_OFFSET));
1065 gen.colormap = 1024 + (teamnumber - 1) * 17;
1067 // generator placement
1072 WaypointSprite_SpawnFixed(string_null, self.origin + CPGEN_WAYPOINT_OFFSET, self, sprite, RADARICON_NONE, '0 0 0');
1073 WaypointSprite_UpdateRule(self.sprite, self.team, SPRITERULE_TEAMPLAY);
1074 WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
1075 WaypointSprite_UpdateHealth(self.sprite, self.health);
1077 InitializeEntity(gen, ons_DelayedGeneratorSetup, INITPRIO_SETLOCATION);
1085 int total_generators;
1086 void Onslaught_count_generators()
1089 total_generators = redowned = blueowned = yellowowned = pinkowned = 0;
1090 for(e = ons_worldgeneratorlist; e; e = e.ons_worldgeneratornext)
1093 redowned += (e.team == NUM_TEAM_1 && e.health > 0);
1094 blueowned += (e.team == NUM_TEAM_2 && e.health > 0);
1095 yellowowned += (e.team == NUM_TEAM_3 && e.health > 0);
1096 pinkowned += (e.team == NUM_TEAM_4 && e.health > 0);
1100 int Onslaught_GetWinnerTeam()
1102 int winner_team = 0;
1104 winner_team = NUM_TEAM_1;
1107 if(winner_team) return 0;
1108 winner_team = NUM_TEAM_2;
1112 if(winner_team) return 0;
1113 winner_team = NUM_TEAM_3;
1117 if(winner_team) return 0;
1118 winner_team = NUM_TEAM_4;
1122 return -1; // no generators left?
1125 #define ONS_OWNED_GENERATORS() ((redowned > 0) + (blueowned > 0) + (yellowowned > 0) + (pinkowned > 0))
1126 #define ONS_OWNED_GENERATORS_OK() (ONS_OWNED_GENERATORS() > 1)
1127 bool Onslaught_CheckWinner()
1131 if ((autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60) || (round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0))
1133 ons_stalemate = true;
1135 if (!wpforenemy_announced)
1137 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT);
1138 sound(world, CH_INFO, "onslaught/generator_decay.wav", VOL_BASE, ATTEN_NONE);
1140 wpforenemy_announced = true;
1143 entity tmp_entity; // temporary entity
1145 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext) if(time >= tmp_entity.ons_overtime_damagedelay)
1147 // tmp_entity.max_health / 300 gives 5 minutes of overtime.
1148 // control points reduce the overtime duration.
1150 for(e = ons_worldcplist; e; e = e.ons_worldcpnext)
1152 if(DIFF_TEAM(e, tmp_entity))
1157 if(autocvar_g_campaign && autocvar__campaign_testrun)
1158 d = d * tmp_entity.max_health;
1160 d = d * tmp_entity.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
1162 Damage(tmp_entity, tmp_entity, tmp_entity, d, DEATH_HURTTRIGGER, tmp_entity.origin, '0 0 0');
1164 tmp_entity.sprite.SendFlags |= 16;
1166 tmp_entity.ons_overtime_damagedelay = time + 1;
1169 else { wpforenemy_announced = false; ons_stalemate = false; }
1171 Onslaught_count_generators();
1173 if(ONS_OWNED_GENERATORS_OK())
1176 int winner_team = Onslaught_GetWinnerTeam();
1180 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
1181 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
1182 TeamScore_AddToTeam(winner_team, ST_ONS_CAPS, +1);
1184 else if(winner_team == -1)
1186 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
1187 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
1190 ons_stalemate = false;
1192 play2all(sprintf("ctf/%s_capture.wav", Static_Team_ColorName_Lower(winner_team)));
1194 round_handler_Init(7, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
1198 e.ons_roundlost = true;
1199 e.player_blocked = true;
1207 bool Onslaught_CheckPlayers()
1212 void Onslaught_RoundStart()
1215 FOR_EACH_PLAYER(tmp_entity) { tmp_entity.player_blocked = false; }
1217 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1218 tmp_entity.sprite.SendFlags |= 16;
1220 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1221 tmp_entity.sprite.SendFlags |= 16;
1229 // NOTE: LEGACY CODE, needs to be re-written!
1231 void havocbot_goalrating_ons_offenseitems(float ratingscale, vector org, float sradius)
1236 bool needarmor = false, needweapons = false;
1238 // Needs armor/health?
1244 for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
1247 if(self.weapons & WepSet_FromWeapon(i))
1255 if(!needweapons && !needarmor)
1258 ons_debug(strcat(self.netname, " needs weapons ", ftos(needweapons) , "\n"));
1259 ons_debug(strcat(self.netname, " needs armor ", ftos(needarmor) , "\n"));
1261 // See what is around
1262 head = findchainfloat(bot_pickup, true);
1265 // gather health and armor only
1267 if ( ((head.health || head.armorvalue) && needarmor) || (head.weapons && needweapons ) )
1268 if (vlen(head.origin - org) < sradius)
1270 t = head.bot_pickupevalfunc(self, head);
1272 navigation_routerating(head, t * ratingscale, 500);
1278 void havocbot_role_ons_setrole(entity bot, int role)
1280 ons_debug(strcat(bot.netname," switched to "));
1283 case HAVOCBOT_ONS_ROLE_DEFENSE:
1284 ons_debug("defense");
1285 bot.havocbot_role = havocbot_role_ons_defense;
1286 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE;
1287 bot.havocbot_role_timeout = 0;
1289 case HAVOCBOT_ONS_ROLE_ASSISTANT:
1290 ons_debug("assistant");
1291 bot.havocbot_role = havocbot_role_ons_assistant;
1292 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT;
1293 bot.havocbot_role_timeout = 0;
1295 case HAVOCBOT_ONS_ROLE_OFFENSE:
1296 ons_debug("offense");
1297 bot.havocbot_role = havocbot_role_ons_offense;
1298 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE;
1299 bot.havocbot_role_timeout = 0;
1305 int havocbot_ons_teamcount(entity bot, int role)
1310 FOR_EACH_PLAYER(head)
1311 if(SAME_TEAM(head, self))
1312 if(head.havocbot_role_flags & role)
1318 void havocbot_goalrating_ons_controlpoints_attack(float ratingscale)
1320 entity cp, cp1, cp2, best, pl, wp;
1321 float radius, bestvalue;
1325 // Filter control points
1326 for(cp2 = ons_worldcplist; cp2; cp2 = cp2.ons_worldcpnext)
1329 cp2.wpconsidered = false;
1334 // Ignore owned controlpoints
1335 if(!(cp2.isgenneighbor[self.team] || cp2.iscpneighbor[self.team]))
1338 // Count team mates interested in this control point
1339 // (easier and cleaner than keeping counters per cp and teams)
1341 if(SAME_TEAM(pl, self))
1342 if(pl.havocbot_role_flags & HAVOCBOT_ONS_ROLE_OFFENSE)
1343 if(pl.havocbot_ons_target==cp2)
1346 // NOTE: probably decrease the cost of attackable control points
1348 cp2.wpconsidered = true;
1351 // We'll consider only the best case
1352 bestvalue = 99999999999;
1354 for(cp1 = ons_worldcplist; cp1; cp1 = cp1.ons_worldcpnext)
1356 if (!cp1.wpconsidered)
1359 if(cp1.wpcost<bestvalue)
1361 bestvalue = cp1.wpcost;
1363 self.havocbot_ons_target = cp1;
1370 ons_debug(strcat(self.netname, " chose cp ranked ", ftos(bestvalue), "\n"));
1374 // Should be attacked
1375 // Rate waypoints near it
1378 bestvalue = 99999999999;
1379 for(radius=0; radius<1000 && !found; radius+=500)
1381 for(wp=findradius(cp.origin,radius); wp; wp=wp.chain)
1383 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
1384 if(wp.classname=="waypoint")
1385 if(checkpvs(wp.origin,cp))
1388 if(wp.cnt<bestvalue)
1399 navigation_routerating(best, ratingscale, 10000);
1402 self.havocbot_attack_time = 0;
1403 if(checkpvs(self.view_ofs,cp))
1404 if(checkpvs(self.view_ofs,best))
1405 self.havocbot_attack_time = time + 2;
1409 navigation_routerating(cp, ratingscale, 10000);
1411 ons_debug(strcat(self.netname, " found an attackable controlpoint at ", vtos(cp.origin) ,"\n"));
1415 // Should be touched
1416 ons_debug(strcat(self.netname, " found a touchable controlpoint at ", vtos(cp.origin) ,"\n"));
1419 // Look for auto generated waypoint
1420 if (!bot_waypoints_for_items)
1421 for (wp = findradius(cp.origin,100); wp; wp = wp.chain)
1423 if(wp.classname=="waypoint")
1425 navigation_routerating(wp, ratingscale, 10000);
1430 // Nothing found, rate the controlpoint itself
1432 navigation_routerating(cp, ratingscale, 10000);
1436 bool havocbot_goalrating_ons_generator_attack(float ratingscale)
1438 entity g, wp, bestwp;
1442 for(g = ons_worldgeneratorlist; g; g = g.ons_worldgeneratornext)
1444 if(SAME_TEAM(g, self) || g.isshielded)
1447 // Should be attacked
1448 // Rate waypoints near it
1453 for(wp=findradius(g.origin,400); wp; wp=wp.chain)
1455 if(wp.classname=="waypoint")
1456 if(checkpvs(wp.origin,g))
1469 ons_debug("waypoints found around generator\n");
1470 navigation_routerating(bestwp, ratingscale, 10000);
1473 self.havocbot_attack_time = 0;
1474 if(checkpvs(self.view_ofs,g))
1475 if(checkpvs(self.view_ofs,bestwp))
1476 self.havocbot_attack_time = time + 5;
1482 ons_debug("generator found without waypoints around\n");
1483 // if there aren't waypoints near the generator go straight to it
1484 navigation_routerating(g, ratingscale, 10000);
1485 self.havocbot_attack_time = 0;
1492 void havocbot_role_ons_offense()
1494 if(self.deadflag != DEAD_NO)
1496 self.havocbot_attack_time = 0;
1497 havocbot_ons_reset_role(self);
1501 // Set the role timeout if necessary
1502 if (!self.havocbot_role_timeout)
1503 self.havocbot_role_timeout = time + 120;
1505 if (time > self.havocbot_role_timeout)
1507 havocbot_ons_reset_role(self);
1511 if(self.havocbot_attack_time>time)
1514 if (self.bot_strategytime < time)
1516 navigation_goalrating_start();
1517 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
1518 if(!havocbot_goalrating_ons_generator_attack(20000))
1519 havocbot_goalrating_ons_controlpoints_attack(20000);
1520 havocbot_goalrating_ons_offenseitems(10000, self.origin, 10000);
1521 navigation_goalrating_end();
1523 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
1527 void havocbot_role_ons_assistant()
1529 havocbot_ons_reset_role(self);
1532 void havocbot_role_ons_defense()
1534 havocbot_ons_reset_role(self);
1537 void havocbot_ons_reset_role(entity bot)
1542 if(self.deadflag != DEAD_NO)
1545 bot.havocbot_ons_target = world;
1547 // TODO: Defend control points or generator if necessary
1549 // if there is only me on the team switch to offense
1551 FOR_EACH_PLAYER(head)
1552 if(SAME_TEAM(head, self))
1557 havocbot_role_ons_setrole(bot, HAVOCBOT_ONS_ROLE_OFFENSE);
1561 havocbot_role_ons_setrole(bot, HAVOCBOT_ONS_ROLE_OFFENSE);
1566 * Find control point or generator owned by the same team self which is nearest to pos
1567 * if max_dist is positive, only control points within this range will be considered
1569 entity ons_Nearest_ControlPoint(vector pos, float max_dist)
1571 entity tmp_entity, closest_target = world;
1572 tmp_entity = findchain(classname, "onslaught_controlpoint");
1575 if(SAME_TEAM(tmp_entity, self))
1576 if(tmp_entity.iscaptured)
1577 if(max_dist <= 0 || vlen(tmp_entity.origin - pos) <= max_dist)
1578 if(vlen(tmp_entity.origin - pos) <= vlen(closest_target.origin - pos) || closest_target == world)
1579 closest_target = tmp_entity;
1580 tmp_entity = tmp_entity.chain;
1582 tmp_entity = findchain(classname, "onslaught_generator");
1585 if(SAME_TEAM(tmp_entity, self))
1586 if(max_dist <= 0 || vlen(tmp_entity.origin - pos) < max_dist)
1587 if(vlen(tmp_entity.origin - pos) <= vlen(closest_target.origin - pos) || closest_target == world)
1588 closest_target = tmp_entity;
1589 tmp_entity = tmp_entity.chain;
1592 return closest_target;
1596 * Find control point or generator owned by the same team self which is nearest to pos
1597 * if max_dist is positive, only control points within this range will be considered
1598 * This function only check distances on the XY plane, disregarding Z
1600 entity ons_Nearest_ControlPoint_2D(vector pos, float max_dist)
1602 entity tmp_entity, closest_target = world;
1604 float smallest_distance = 0, distance;
1606 tmp_entity = findchain(classname, "onslaught_controlpoint");
1609 delta = tmp_entity.origin - pos;
1611 distance = vlen(delta);
1613 if(SAME_TEAM(tmp_entity, self))
1614 if(tmp_entity.iscaptured)
1615 if(max_dist <= 0 || distance <= max_dist)
1616 if(closest_target == world || distance <= smallest_distance )
1618 closest_target = tmp_entity;
1619 smallest_distance = distance;
1622 tmp_entity = tmp_entity.chain;
1624 tmp_entity = findchain(classname, "onslaught_generator");
1627 delta = tmp_entity.origin - pos;
1629 distance = vlen(delta);
1631 if(SAME_TEAM(tmp_entity, self))
1632 if(max_dist <= 0 || distance <= max_dist)
1633 if(closest_target == world || distance <= smallest_distance )
1635 closest_target = tmp_entity;
1636 smallest_distance = distance;
1639 tmp_entity = tmp_entity.chain;
1642 return closest_target;
1645 * find the number of control points and generators in the same team as self
1647 int ons_Count_SelfControlPoints()
1650 tmp_entity = findchain(classname, "onslaught_controlpoint");
1654 if(SAME_TEAM(tmp_entity, self))
1655 if(tmp_entity.iscaptured)
1657 tmp_entity = tmp_entity.chain;
1659 tmp_entity = findchain(classname, "onslaught_generator");
1662 if(SAME_TEAM(tmp_entity, self))
1664 tmp_entity = tmp_entity.chain;
1670 * Teleport player to a random position near tele_target
1671 * if tele_effects is true, teleport sound+particles are created
1672 * return false on failure
1674 bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effects)
1682 for(i = 0; i < 16; ++i)
1684 theta = random() * 2 * M_PI;
1688 loc *= random() * range;
1690 loc += tele_target.origin + '0 0 128';
1692 tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, player);
1693 if(trace_fraction == 1.0 && !trace_startsolid)
1695 traceline(tele_target.origin, loc, MOVE_NOMONSTERS, tele_target); // double check to make sure we're not spawning outside the world
1696 if(trace_fraction == 1.0 && !trace_startsolid)
1700 pointparticles(particleeffectnum("teleport"), player.origin, '0 0 0', 1);
1701 sound (player, CH_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTEN_NORM);
1703 setorigin(player, loc);
1704 player.angles = '0 1 0' * ( theta * RAD2DEG + 180 );
1705 makevectors(player.angles);
1706 player.fixangle = true;
1707 player.teleport_antispam = time + autocvar_g_onslaught_teleport_wait;
1710 pointparticles(particleeffectnum("teleport"), player.origin + v_forward * 32, '0 0 0', 1);
1723 MUTATOR_HOOKFUNCTION(ons_ResetMap)
1725 FOR_EACH_PLAYER(self)
1727 self.ons_roundlost = false;
1728 self.ons_deathloc = '0 0 0';
1729 PutClientInServer();
1734 MUTATOR_HOOKFUNCTION(ons_RemovePlayer)
1736 self.ons_deathloc = '0 0 0';
1740 MUTATOR_HOOKFUNCTION(ons_PlayerSpawn)
1742 if(!round_handler_IsRoundStarted())
1744 self.player_blocked = true;
1749 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1751 l.sprite.SendFlags |= 16;
1753 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1755 l.sprite.SendFlags |= 16;
1758 if(ons_stalemate) { Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); }
1760 if ( autocvar_g_onslaught_spawn_choose )
1761 if ( self.ons_spawn_by )
1762 if ( ons_Teleport(self,self.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) )
1764 self.ons_spawn_by = world;
1768 if(autocvar_g_onslaught_spawn_at_controlpoints)
1769 if(random() <= autocvar_g_onslaught_spawn_at_controlpoints_chance)
1771 float random_target = autocvar_g_onslaught_spawn_at_controlpoints_random;
1772 entity tmp_entity, closest_target = world;
1773 vector spawn_loc = self.ons_deathloc;
1775 // new joining player or round reset, don't bother checking
1776 if(spawn_loc == '0 0 0') { return false; }
1778 if(random_target) { RandomSelection_Init(); }
1780 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1782 if(SAME_TEAM(tmp_entity, self))
1784 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1785 else if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world)
1786 closest_target = tmp_entity;
1789 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1795 for(i = 0; i < 10; ++i)
1797 loc = closest_target.origin + '0 0 96';
1798 loc += ('0 1 0' * random()) * 128;
1799 tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, self);
1800 if(trace_fraction == 1.0 && !trace_startsolid)
1802 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
1803 if(trace_fraction == 1.0 && !trace_startsolid)
1805 setorigin(self, loc);
1806 self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1814 if(autocvar_g_onslaught_spawn_at_generator)
1815 if(random() <= autocvar_g_onslaught_spawn_at_generator_chance)
1817 float random_target = autocvar_g_onslaught_spawn_at_generator_random;
1818 entity tmp_entity, closest_target = world;
1819 vector spawn_loc = self.ons_deathloc;
1821 // new joining player or round reset, don't bother checking
1822 if(spawn_loc == '0 0 0') { return false; }
1824 if(random_target) { RandomSelection_Init(); }
1826 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1829 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1832 if(SAME_TEAM(tmp_entity, self))
1833 if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world)
1834 closest_target = tmp_entity;
1838 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1844 for(i = 0; i < 10; ++i)
1846 loc = closest_target.origin + '0 0 128';
1847 loc += ('0 1 0' * random()) * 256;
1848 tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, self);
1849 if(trace_fraction == 1.0 && !trace_startsolid)
1851 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
1852 if(trace_fraction == 1.0 && !trace_startsolid)
1854 setorigin(self, loc);
1855 self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1866 MUTATOR_HOOKFUNCTION(ons_PlayerDies)
1868 frag_target.ons_deathloc = frag_target.origin;
1870 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1872 l.sprite.SendFlags |= 16;
1874 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1876 l.sprite.SendFlags |= 16;
1879 if ( autocvar_g_onslaught_spawn_choose )
1880 if ( ons_Count_SelfControlPoints() > 1 )
1881 stuffcmd(self, "qc_cmd_cl hud clickradar\n");
1886 MUTATOR_HOOKFUNCTION(ons_MonsterThink)
1888 entity e = find(world, targetname, self.target);
1895 void ons_MonsterSpawn_Delayed()
1897 entity e, own = self.owner;
1899 if(!own) { remove(self); return; }
1903 e = find(world, target, own.targetname);
1916 MUTATOR_HOOKFUNCTION(ons_MonsterSpawn)
1920 InitializeEntity(e, ons_MonsterSpawn_Delayed, INITPRIO_FINDTARGET);
1925 void ons_TurretSpawn_Delayed()
1927 entity e, own = self.owner;
1929 if(!own) { remove(self); return; }
1933 e = find(world, target, own.targetname);
1937 own.active = ACTIVE_NOT;
1947 MUTATOR_HOOKFUNCTION(ons_TurretSpawn)
1951 InitializeEntity(e, ons_TurretSpawn_Delayed, INITPRIO_FINDTARGET);
1956 MUTATOR_HOOKFUNCTION(ons_BotRoles)
1958 havocbot_ons_reset_role(self);
1962 MUTATOR_HOOKFUNCTION(ons_GetTeamCount)
1964 // onslaught is special
1966 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1968 switch(tmp_entity.team)
1970 case NUM_TEAM_1: c1 = 0; break;
1971 case NUM_TEAM_2: c2 = 0; break;
1972 case NUM_TEAM_3: c3 = 0; break;
1973 case NUM_TEAM_4: c4 = 0; break;
1980 MUTATOR_HOOKFUNCTION(ons_SpectateCopy)
1982 self.ons_roundlost = other.ons_roundlost; // make spectators see it too
1986 MUTATOR_HOOKFUNCTION(ons_SV_ParseClientCommand)
1988 if(MUTATOR_RETURNVALUE) // command was already handled?
1991 if ( cmd_name == "ons_spawn" )
1993 vector pos = self.origin;
1995 pos_x = stof(argv(1));
1997 pos_y = stof(argv(2));
1999 pos_z = stof(argv(3));
2001 if ( IS_PLAYER(self) )
2005 entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
2007 if ( !source_point && self.health > 0 )
2009 sprint(self, "\nYou need to be next to a control point\n");
2014 entity closest_target = ons_Nearest_ControlPoint_2D(pos, autocvar_g_onslaught_click_radius);
2016 if ( closest_target == world )
2018 sprint(self, "\nNo control point found\n");
2022 if ( self.health <= 0 )
2024 self.ons_spawn_by = closest_target;
2025 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
2029 if ( source_point == closest_target )
2031 sprint(self, "\nTeleporting to the same point\n");
2035 if ( !ons_Teleport(self,closest_target,autocvar_g_onslaught_teleport_radius,true) )
2036 sprint(self, "\nUnable to teleport there\n");
2042 sprint(self, "\nNo teleportation for you\n");
2050 MUTATOR_HOOKFUNCTION(ons_PlayerUseKey)
2052 if(MUTATOR_RETURNVALUE || gameover) { return false; }
2054 if((time > self.teleport_antispam) && (self.deadflag == DEAD_NO) && !self.vehicle)
2056 entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
2059 stuffcmd(self, "qc_cmd_cl hud clickradar\n");
2071 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
2072 Link between control points.
2074 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.
2077 "target" - first control point.
2078 "target2" - second control point.
2080 void spawnfunc_onslaught_link()
2082 if(!g_onslaught) { remove(self); return; }
2084 if (self.target == "" || self.target2 == "")
2085 objerror("target and target2 must be set\n");
2087 self.ons_worldlinknext = ons_worldlinklist; // link into ons_worldlinklist
2088 ons_worldlinklist = self;
2090 InitializeEntity(self, ons_DelayedLinkSetup, INITPRIO_FINDTARGET);
2091 Net_LinkEntity(self, false, 0, ons_Link_Send);
2094 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
2095 Control point. Be sure to give this enough clearance so that the shootable part has room to exist
2097 This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
2100 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2101 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
2102 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
2105 void spawnfunc_onslaught_controlpoint()
2107 if(!g_onslaught) { remove(self); return; }
2109 ons_ControlPoint_Setup(self);
2112 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
2115 spawnfunc_onslaught_link entities can target this.
2118 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
2119 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2121 void spawnfunc_onslaught_generator()
2123 if(!g_onslaught) { remove(self); return; }
2124 if(!self.team) { objerror("team must be set"); }
2126 ons_GeneratorSetup(self);
2131 void ons_ScoreRules()
2133 CheckAllowedTeams(world);
2134 ScoreRules_basics(((c4>=0) ? 4 : (c3>=0) ? 3 : 2), SFL_SORT_PRIO_PRIMARY, 0, true);
2135 ScoreInfo_SetLabel_TeamScore (ST_ONS_CAPS, "destroyed", SFL_SORT_PRIO_PRIMARY);
2136 ScoreInfo_SetLabel_PlayerScore(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
2137 ScoreInfo_SetLabel_PlayerScore(SP_ONS_TAKES, "takes", 0);
2138 ScoreRules_basics_end();
2141 void ons_DelayedInit() // Do this check with a delay so we can wait for teams to be set up
2145 round_handler_Spawn(Onslaught_CheckPlayers, Onslaught_CheckWinner, Onslaught_RoundStart);
2146 round_handler_Init(5, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
2149 void ons_Initialize()
2151 precache_sound("ctf/red_capture.wav");
2152 precache_sound("ctf/blue_capture.wav");
2153 precache_sound("ctf/yellow_capture.wav");
2154 precache_sound("ctf/pink_capture.wav");
2156 ons_captureshield_force = autocvar_g_onslaught_shield_force;
2158 addstat(STAT_ROUNDLOST, AS_INT, ons_roundlost);
2160 InitializeEntity(world, ons_DelayedInit, INITPRIO_GAMETYPE);
2163 MUTATOR_DEFINITION(gamemode_onslaught)
2165 MUTATOR_HOOK(reset_map_global, ons_ResetMap, CBC_ORDER_ANY);
2166 MUTATOR_HOOK(MakePlayerObserver, ons_RemovePlayer, CBC_ORDER_ANY);
2167 MUTATOR_HOOK(ClientDisconnect, ons_RemovePlayer, CBC_ORDER_ANY);
2168 MUTATOR_HOOK(PlayerSpawn, ons_PlayerSpawn, CBC_ORDER_ANY);
2169 MUTATOR_HOOK(PlayerDies, ons_PlayerDies, CBC_ORDER_ANY);
2170 MUTATOR_HOOK(MonsterMove, ons_MonsterThink, CBC_ORDER_ANY);
2171 MUTATOR_HOOK(MonsterSpawn, ons_MonsterSpawn, CBC_ORDER_ANY);
2172 MUTATOR_HOOK(TurretSpawn, ons_TurretSpawn, CBC_ORDER_ANY);
2173 MUTATOR_HOOK(HavocBot_ChooseRole, ons_BotRoles, CBC_ORDER_ANY);
2174 MUTATOR_HOOK(GetTeamCount, ons_GetTeamCount, CBC_ORDER_ANY);
2175 MUTATOR_HOOK(SpectateCopy, ons_SpectateCopy, CBC_ORDER_ANY);
2176 MUTATOR_HOOK(SV_ParseClientCommand, ons_SV_ParseClientCommand, CBC_ORDER_ANY);
2177 MUTATOR_HOOK(PlayerUseKey, ons_PlayerUseKey, CBC_ORDER_ANY);
2181 if(time > 1) // game loads at time 1
2182 error("This is a game type and it cannot be added at runtime.");
2186 MUTATOR_ONROLLBACK_OR_REMOVE
2188 // we actually cannot roll back ons_Initialize here
2189 // BUT: we don't need to! If this gets called, adding always
2195 print("This is a game type and it cannot be removed at runtime.");