1 #ifndef GAMEMODE_ONSLAUGHT_H
2 #define GAMEMODE_ONSLAUGHT_H
4 float autocvar_g_onslaught_point_limit;
7 REGISTER_MUTATOR(ons, false)
11 if (time > 1) // game loads at time 1
12 error("This is a game type and it cannot be added at runtime.");
16 SetLimits(autocvar_g_onslaught_point_limit, -1, -1, -1);
17 have_team_spawns = -1; // request team spawns
20 MUTATOR_ONROLLBACK_OR_REMOVE
22 // we actually cannot roll back ons_Initialize here
23 // BUT: we don't need to! If this gets called, adding always
29 LOG_INFO("This is a game type and it cannot be removed at runtime.");
38 .entity ons_toucher; // player who touched the control point
40 // control point / generator constants
41 const float ONS_CP_THINKRATE = 0.2;
42 const float GEN_THINKRATE = 1;
43 #define CPGEN_SPAWN_OFFSET ('0 0 1' * (PL_MAX_CONST.z - 13))
44 const vector CPGEN_WAYPOINT_OFFSET = ('0 0 128');
45 const vector CPICON_OFFSET = ('0 0 96');
47 // list of generators on the map
48 entity ons_worldgeneratorlist;
49 .entity ons_worldgeneratornext;
50 .entity ons_stalegeneratornext;
52 // list of control points on the map
53 entity ons_worldcplist;
54 .entity ons_worldcpnext;
55 .entity ons_stalecpnext;
57 // list of links on the map
58 entity ons_worldlinklist;
59 .entity ons_worldlinknext;
60 .entity ons_stalelinknext;
77 .float teleport_antispam;
79 .bool ons_roundlost = _STAT(ROUNDLOST);
82 .entity bot_basewaypoint; // generator waypointsprite
84 .bool isgenneighbor[17];
85 .bool iscpneighbor[17];
86 float ons_notification_time[17];
88 .float ons_overtime_damagedelay;
94 // declarations for functions used outside gamemode_onslaught.qc
95 void ons_Generator_UpdateSprite(entity e);
96 void ons_ControlPoint_UpdateSprite(entity e);
97 bool ons_ControlPoint_Attackable(entity cp, int teamnumber);
99 // CaptureShield: Prevent capturing or destroying control point/generator if it is not available yet
100 float ons_captureshield_force; // push force of the shield
103 const int HAVOCBOT_ONS_ROLE_NONE = 0;
104 const int HAVOCBOT_ONS_ROLE_DEFENSE = 2;
105 const int HAVOCBOT_ONS_ROLE_ASSISTANT = 4;
106 const int HAVOCBOT_ONS_ROLE_OFFENSE = 8;
108 .entity havocbot_ons_target;
110 .int havocbot_role_flags;
111 .float havocbot_attack_time;
113 void havocbot_role_ons_defense(entity this);
114 void havocbot_role_ons_offense(entity this);
115 void havocbot_role_ons_assistant(entity this);
117 void havocbot_ons_reset_role(entity this);
118 void havocbot_goalrating_items(entity this, float ratingscale, vector org, float sradius);
119 void havocbot_goalrating_enemyplayers(entity this, float ratingscale, vector org, float sradius);
121 // score rule declarations
122 const int ST_ONS_CAPS = 1;
123 const int SP_ONS_CAPS = 4;
124 const int SP_ONS_TAKES = 6;
129 #ifdef IMPLEMENTATION
131 #include "sv_controlpoint.qh"
132 #include "sv_generator.qh"
136 float autocvar_g_onslaught_teleport_wait;
137 bool autocvar_g_onslaught_spawn_at_controlpoints;
138 bool autocvar_g_onslaught_spawn_at_generator;
139 float autocvar_g_onslaught_cp_proxydecap;
140 float autocvar_g_onslaught_cp_proxydecap_distance = 512;
141 float autocvar_g_onslaught_cp_proxydecap_dps = 100;
142 float autocvar_g_onslaught_spawn_at_controlpoints_chance = 0.5;
143 float autocvar_g_onslaught_spawn_at_controlpoints_random;
144 float autocvar_g_onslaught_spawn_at_generator_chance;
145 float autocvar_g_onslaught_spawn_at_generator_random;
146 float autocvar_g_onslaught_cp_buildhealth;
147 float autocvar_g_onslaught_cp_buildtime;
148 float autocvar_g_onslaught_cp_health;
149 float autocvar_g_onslaught_cp_regen;
150 float autocvar_g_onslaught_gen_health;
151 float autocvar_g_onslaught_shield_force = 100;
152 float autocvar_g_onslaught_allow_vehicle_touch;
153 float autocvar_g_onslaught_round_timelimit;
154 float autocvar_g_onslaught_warmup;
155 float autocvar_g_onslaught_teleport_radius;
156 float autocvar_g_onslaught_spawn_choose;
157 float autocvar_g_onslaught_click_radius;
159 void FixSize(entity e);
161 // =======================
162 // CaptureShield Functions
163 // =======================
165 bool ons_CaptureShield_Customize()
167 entity e = WaypointSprite_getviewentity(other);
169 if(!self.enemy.isshielded && (ons_ControlPoint_Attackable(self.enemy, e.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return false; }
170 if(SAME_TEAM(self, e)) { return false; }
175 void ons_CaptureShield_Touch()
177 if(!self.enemy.isshielded && (ons_ControlPoint_Attackable(self.enemy, other.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return; }
178 if(!IS_PLAYER(other)) { return; }
179 if(SAME_TEAM(other, self)) { return; }
181 vector mymid = (self.absmin + self.absmax) * 0.5;
182 vector othermid = (other.absmin + other.absmax) * 0.5;
184 Damage(other, self, self, 0, DEATH_HURTTRIGGER.m_id, mymid, normalize(othermid - mymid) * ons_captureshield_force);
186 if(IS_REAL_CLIENT(other))
188 play2(other, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
190 if(self.enemy.classname == "onslaught_generator")
191 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_GENERATOR_SHIELDED);
193 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_CONTROLPOINT_SHIELDED);
197 void ons_CaptureShield_Reset(entity this)
199 this.colormap = this.enemy.colormap;
200 this.team = this.enemy.team;
203 void ons_CaptureShield_Spawn(entity generator, bool is_generator)
205 entity shield = new(ons_captureshield);
207 shield.enemy = generator;
208 shield.team = generator.team;
209 shield.colormap = generator.colormap;
210 shield.reset = ons_CaptureShield_Reset;
211 shield.touch = ons_CaptureShield_Touch;
212 shield.customizeentityforclient = ons_CaptureShield_Customize;
213 shield.effects = EF_ADDITIVE;
214 shield.movetype = MOVETYPE_NOCLIP;
215 shield.solid = SOLID_TRIGGER;
216 shield.avelocity = '7 0 11';
218 shield.model = ((is_generator) ? "models/onslaught/generator_shield.md3" : "models/onslaught/controlpoint_shield.md3");
220 precache_model(shield.model);
221 setorigin(shield, generator.origin);
222 _setmodel(shield, shield.model);
223 setsize(shield, shield.scale * shield.mins, shield.scale * shield.maxs);
231 void setmodel_fixsize(entity e, Model m)
237 void onslaught_updatelinks()
240 // first check if the game has ended
241 LOG_DEBUG("--- updatelinks ---\n");
242 // mark generators as being shielded and networked
243 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
246 LOG_DEBUG(strcat(etos(l), " (generator) belongs to team ", ftos(l.team), "\n"));
248 LOG_DEBUG(strcat(etos(l), " (generator) is destroyed\n"));
249 l.islinked = l.iscaptured;
250 l.isshielded = l.iscaptured;
251 l.sprite.SendFlags |= 16;
253 // mark points as shielded and not networked
254 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
259 for(i = 0; i < 17; ++i) { l.isgenneighbor[i] = false; l.iscpneighbor[i] = false; }
260 LOG_DEBUG(strcat(etos(l), " (point) belongs to team ", ftos(l.team), "\n"));
261 l.sprite.SendFlags |= 16;
263 // flow power outward from the generators through the network
268 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
270 // if both points are captured by the same team, and only one of
271 // them is powered, mark the other one as powered as well
272 if (l.enemy.iscaptured && l.goalentity.iscaptured)
273 if (l.enemy.islinked != l.goalentity.islinked)
274 if(SAME_TEAM(l.enemy, l.goalentity))
276 if (!l.goalentity.islinked)
279 l.goalentity.islinked = true;
280 LOG_DEBUG(strcat(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)\n"));
282 else if (!l.enemy.islinked)
285 l.enemy.islinked = true;
286 LOG_DEBUG(strcat(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)\n"));
291 // now that we know which points are powered we can mark their neighbors
292 // as unshielded if team differs
293 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
295 if (l.goalentity.islinked)
297 if(DIFF_TEAM(l.goalentity, l.enemy))
299 LOG_DEBUG(strcat(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)\n"));
300 l.enemy.isshielded = false;
302 if(l.goalentity.classname == "onslaught_generator")
303 l.enemy.isgenneighbor[l.goalentity.team] = true;
305 l.enemy.iscpneighbor[l.goalentity.team] = true;
307 if (l.enemy.islinked)
309 if(DIFF_TEAM(l.goalentity, l.enemy))
311 LOG_DEBUG(strcat(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)\n"));
312 l.goalentity.isshielded = false;
314 if(l.enemy.classname == "onslaught_generator")
315 l.goalentity.isgenneighbor[l.enemy.team] = true;
317 l.goalentity.iscpneighbor[l.enemy.team] = true;
320 // now update the generators
321 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
325 LOG_DEBUG(strcat(etos(l), " (generator) is shielded\n"));
326 l.takedamage = DAMAGE_NO;
327 l.bot_attack = false;
331 LOG_DEBUG(strcat(etos(l), " (generator) is not shielded\n"));
332 l.takedamage = DAMAGE_AIM;
336 ons_Generator_UpdateSprite(l);
338 // now update the takedamage and alpha variables on control point icons
339 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
343 LOG_DEBUG(strcat(etos(l), " (point) is shielded\n"));
346 l.goalentity.takedamage = DAMAGE_NO;
347 l.goalentity.bot_attack = false;
352 LOG_DEBUG(strcat(etos(l), " (point) is not shielded\n"));
355 l.goalentity.takedamage = DAMAGE_AIM;
356 l.goalentity.bot_attack = true;
359 ons_ControlPoint_UpdateSprite(l);
361 l = findchain(classname, "ons_captureshield");
364 l.team = l.enemy.team;
365 l.colormap = l.enemy.colormap;
371 // ===================
372 // Main Link Functions
373 // ===================
375 bool ons_Link_Send(entity this, entity to, int sendflags)
377 WriteHeader(MSG_ENTITY, ENT_CLIENT_RADARLINK);
378 WriteByte(MSG_ENTITY, sendflags);
381 WriteCoord(MSG_ENTITY, self.goalentity.origin_x);
382 WriteCoord(MSG_ENTITY, self.goalentity.origin_y);
383 WriteCoord(MSG_ENTITY, self.goalentity.origin_z);
387 WriteCoord(MSG_ENTITY, self.enemy.origin_x);
388 WriteCoord(MSG_ENTITY, self.enemy.origin_y);
389 WriteCoord(MSG_ENTITY, self.enemy.origin_z);
393 WriteByte(MSG_ENTITY, self.clientcolors); // which is goalentity's color + enemy's color * 16
398 void ons_Link_CheckUpdate()
400 // TODO check if the two sides have moved (currently they won't move anyway)
401 float cc = 0, cc1 = 0, cc2 = 0;
403 if(self.goalentity.islinked || self.goalentity.iscaptured) { cc1 = (self.goalentity.team - 1) * 0x01; }
404 if(self.enemy.islinked || self.enemy.iscaptured) { cc2 = (self.enemy.team - 1) * 0x10; }
408 if(cc != self.clientcolors)
410 self.clientcolors = cc;
414 self.nextthink = time;
417 void ons_DelayedLinkSetup()
419 self.goalentity = find(world, targetname, self.target);
420 self.enemy = find(world, targetname, self.target2);
421 if(!self.goalentity) { objerror("can not find target\n"); }
422 if(!self.enemy) { objerror("can not find target2\n"); }
424 LOG_DEBUG(strcat(etos(self.goalentity), " linked with ", etos(self.enemy), "\n"));
426 self.think = ons_Link_CheckUpdate;
427 self.nextthink = time;
431 // =============================
432 // Main Control Point Functions
433 // =============================
435 int ons_ControlPoint_CanBeLinked(entity cp, int teamnumber)
437 if(cp.isgenneighbor[teamnumber]) { return 2; }
438 if(cp.iscpneighbor[teamnumber]) { return 1; }
443 int ons_ControlPoint_Attackable(entity cp, int teamnumber)
444 // -2: SAME TEAM, attackable by enemy!
449 // 3: attack it (HIGH PRIO)
450 // 4: touch it (HIGH PRIO)
458 else if(cp.goalentity)
460 // if there's already an icon built, nothing happens
461 if(cp.team == teamnumber)
463 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
464 if(a) // attackable by enemy?
465 return -2; // EMERGENCY!
468 // we know it can be linked, so no need to check
470 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
471 if(a == 2) // near our generator?
472 return 3; // EMERGENCY!
478 if(ons_ControlPoint_CanBeLinked(cp, teamnumber))
480 a = ons_ControlPoint_CanBeLinked(cp, teamnumber); // why was this here NUM_TEAM_1 + NUM_TEAM_2 - t
482 return 4; // GET THIS ONE NOW!
484 return 2; // TOUCH ME
490 void ons_ControlPoint_Icon_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
492 if(damage <= 0) { return; }
494 if (this.owner.isshielded)
496 // this is protected by a shield, so ignore the damage
497 if (time > this.pain_finished)
498 if (IS_PLAYER(attacker))
500 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
501 this.pain_finished = time + 1;
502 attacker.typehitsound += 1; // play both sounds (shield is way too quiet)
508 if(IS_PLAYER(attacker))
509 if(time - ons_notification_time[this.team] > 10)
511 play2team(this.team, SND(ONS_CONTROLPOINT_UNDERATTACK));
512 ons_notification_time[this.team] = time;
515 this.health = this.health - damage;
516 if(this.owner.iscaptured)
517 WaypointSprite_UpdateHealth(this.owner.sprite, this.health);
519 WaypointSprite_UpdateBuildFinished(this.owner.sprite, time + (this.max_health - this.health) / (this.count / ONS_CP_THINKRATE));
520 this.pain_finished = time + 1;
521 // particles on every hit
522 pointparticles(EFFECT_SPARKS, hitloc, force*-1, 1);
525 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE+0.3, ATTEN_NORM);
527 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE+0.3, ATTEN_NORM);
531 sound(this, CH_TRIGGER, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
532 pointparticles(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
533 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_CPDESTROYED), this.owner.message, attacker.netname);
535 PlayerScore_Add(attacker, SP_ONS_TAKES, 1);
536 PlayerScore_Add(attacker, SP_SCORE, 10);
538 this.owner.goalentity = world;
539 this.owner.islinked = false;
540 this.owner.iscaptured = false;
542 this.owner.colormap = 1024;
544 WaypointSprite_UpdateMaxHealth(this.owner.sprite, 0);
546 onslaught_updatelinks();
548 // Use targets now (somebody make sure this is in the right place..)
551 WITH(entity, self, this, SUB_UseTargets());
554 this.owner.waslinked = this.owner.islinked;
555 if(this.owner.model != "models/onslaught/controlpoint_pad.md3")
556 setmodel_fixsize(this.owner, MDL_ONS_CP_PAD1);
557 //setsize(this, '-32 -32 0', '32 32 8');
562 this.SendFlags |= CPSF_STATUS;
565 void ons_ControlPoint_Icon_Think()
567 self.nextthink = time + ONS_CP_THINKRATE;
569 if(autocvar_g_onslaught_cp_proxydecap)
571 int _enemy_count = 0;
572 int _friendly_count = 0;
574 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it), {
575 if(vdist(it.origin - self.origin, <, autocvar_g_onslaught_cp_proxydecap_distance))
577 if(SAME_TEAM(it, self))
584 _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
585 _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
587 self.health = bound(0, self.health + (_friendly_count - _enemy_count), self.max_health);
588 self.SendFlags |= CPSF_STATUS;
591 ons_ControlPoint_Icon_Damage(self, self, self, 1, 0, self.origin, '0 0 0');
596 if (time > self.pain_finished + 5)
598 if(self.health < self.max_health)
600 self.health = self.health + self.count;
601 if (self.health >= self.max_health)
602 self.health = self.max_health;
603 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
607 if(self.owner.islinked != self.owner.waslinked)
609 // unteam the spawnpoint if needed
610 int t = self.owner.team;
611 if(!self.owner.islinked)
621 self.owner.waslinked = self.owner.islinked;
625 if(random() < 0.6 - self.health / self.max_health)
627 Send_Effect(EFFECT_ELECTRIC_SPARKS, self.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
630 sound(self, CH_PAIN, SND_ONS_SPARK1, VOL_BASE, ATTEN_NORM);
631 else if (random() > 0.5)
632 sound(self, CH_PAIN, SND_ONS_SPARK2, VOL_BASE, ATTEN_NORM);
636 void ons_ControlPoint_Icon_BuildThink()
640 self.nextthink = time + ONS_CP_THINKRATE;
642 // only do this if there is power
643 a = ons_ControlPoint_CanBeLinked(self.owner, self.owner.team);
647 self.health = self.health + self.count;
649 self.SendFlags |= CPSF_STATUS;
651 if (self.health >= self.max_health)
653 self.health = self.max_health;
654 self.count = autocvar_g_onslaught_cp_regen * ONS_CP_THINKRATE; // slow repair rate from now on
655 self.think = ons_ControlPoint_Icon_Think;
656 sound(self, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILT, VOL_BASE, ATTEN_NORM);
657 self.owner.iscaptured = true;
658 self.solid = SOLID_BBOX;
660 Send_Effect(EFFECT_CAP(self.owner.team), self.owner.origin, '0 0 0', 1);
662 WaypointSprite_UpdateMaxHealth(self.owner.sprite, self.max_health);
663 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
665 if(IS_PLAYER(self.owner.ons_toucher))
667 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ONSLAUGHT_CAPTURE, self.owner.ons_toucher.netname, self.owner.message);
668 Send_Notification(NOTIF_ALL_EXCEPT, self.owner.ons_toucher, MSG_CENTER, APP_TEAM_NUM(self.owner.ons_toucher.team, CENTER_ONS_CAPTURE), self.owner.message);
669 Send_Notification(NOTIF_ONE, self.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE, self.owner.message);
670 PlayerScore_Add(self.owner.ons_toucher, SP_ONS_CAPS, 1);
671 PlayerTeamScore_AddScore(self.owner.ons_toucher, 10);
674 self.owner.ons_toucher = world;
676 onslaught_updatelinks();
678 // Use targets now (somebody make sure this is in the right place..)
684 self.SendFlags |= CPSF_SETUP;
686 if(self.owner.model != MDL_ONS_CP_PAD2.model_str())
687 setmodel_fixsize(self.owner, MDL_ONS_CP_PAD2);
689 if(random() < 0.9 - self.health / self.max_health)
690 Send_Effect(EFFECT_RAGE, self.origin + 10 * randomvec(), '0 0 -1', 1);
693 void onslaught_controlpoint_icon_link(entity e, void() spawnproc);
695 void ons_ControlPoint_Icon_Spawn(entity cp, entity player)
697 entity e = new(onslaught_controlpoint_icon);
699 setsize(e, CPICON_MIN, CPICON_MAX);
700 setorigin(e, cp.origin + CPICON_OFFSET);
703 e.max_health = autocvar_g_onslaught_cp_health;
704 e.health = autocvar_g_onslaught_cp_buildhealth;
706 e.takedamage = DAMAGE_AIM;
708 e.event_damage = ons_ControlPoint_Icon_Damage;
709 e.team = player.team;
710 e.colormap = 1024 + (e.team - 1) * 17;
711 e.count = (e.max_health - e.health) * ONS_CP_THINKRATE / autocvar_g_onslaught_cp_buildtime; // how long it takes to build
713 sound(e, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILD, VOL_BASE, ATTEN_NORM);
717 cp.colormap = e.colormap;
719 Send_Effect(EFFECT_FLAG_TOUCH(player.team), e.origin, '0 0 0', 1);
721 WaypointSprite_UpdateBuildFinished(cp.sprite, time + (e.max_health - e.health) / (e.count / ONS_CP_THINKRATE));
722 WaypointSprite_UpdateRule(cp.sprite,cp.team,SPRITERULE_TEAMPLAY);
723 cp.sprite.SendFlags |= 16;
725 onslaught_controlpoint_icon_link(e, ons_ControlPoint_Icon_BuildThink);
728 entity ons_ControlPoint_Waypoint(entity e)
732 int a = ons_ControlPoint_Attackable(e, e.team);
734 if(a == -2) { return WP_OnsCPDefend; } // defend now
735 if(a == -1 || a == 1 || a == 2) { return WP_OnsCP; } // touch
736 if(a == 3 || a == 4) { return WP_OnsCPAttack; } // attack
744 void ons_ControlPoint_UpdateSprite(entity e)
746 entity s1 = ons_ControlPoint_Waypoint(e);
747 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
750 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));
752 if(e.lastteam != e.team + 2 || e.lastshielded != sh || e.iscaptured != e.lastcaptured)
754 if(e.iscaptured) // don't mess up build bars!
758 WaypointSprite_UpdateMaxHealth(e.sprite, 0);
762 WaypointSprite_UpdateMaxHealth(e.sprite, e.goalentity.max_health);
763 WaypointSprite_UpdateHealth(e.sprite, e.goalentity.health);
769 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, false));
771 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
776 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, false));
778 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
780 WaypointSprite_Ping(e.sprite);
782 e.lastteam = e.team + 2;
784 e.lastcaptured = e.iscaptured;
788 void ons_ControlPoint_Touch()
790 entity toucher = other;
793 if(IS_VEHICLE(toucher) && toucher.owner)
794 if(autocvar_g_onslaught_allow_vehicle_touch)
795 toucher = toucher.owner;
799 if(!IS_PLAYER(toucher)) { return; }
800 if(STAT(FROZEN, toucher)) { return; }
801 if(IS_DEAD(toucher)) { return; }
803 if ( SAME_TEAM(self,toucher) )
804 if ( self.iscaptured )
806 if(time <= toucher.teleport_antispam)
807 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT_ANTISPAM, rint(toucher.teleport_antispam - time));
809 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
812 attackable = ons_ControlPoint_Attackable(self, toucher.team);
813 if(attackable != 2 && attackable != 4)
815 // we've verified that this player has a legitimate claim to this point,
816 // so start building the captured point icon (which only captures this
817 // point if it successfully builds without being destroyed first)
818 ons_ControlPoint_Icon_Spawn(self, toucher);
820 self.ons_toucher = toucher;
822 onslaught_updatelinks();
825 void ons_ControlPoint_Think()
827 self.nextthink = time + ONS_CP_THINKRATE;
828 CSQCMODEL_AUTOUPDATE(self);
831 void ons_ControlPoint_Reset(entity this)
834 remove(this.goalentity);
836 this.goalentity = world;
838 this.colormap = 1024;
839 this.iscaptured = false;
840 this.islinked = false;
841 this.isshielded = true;
842 this.think = ons_ControlPoint_Think;
843 this.ons_toucher = world;
844 this.nextthink = time + ONS_CP_THINKRATE;
845 setmodel_fixsize(this, MDL_ONS_CP_PAD1);
847 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
848 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
850 onslaught_updatelinks();
853 SUB_UseTargets(); // to reset the structures, playerspawns etc.
855 CSQCMODEL_AUTOUPDATE(this);
858 void ons_DelayedControlPoint_Setup()
860 onslaught_updatelinks();
862 // captureshield setup
863 ons_CaptureShield_Spawn(self, false);
865 CSQCMODEL_AUTOINIT(self);
868 void ons_ControlPoint_Setup(entity cp)
871 setself(cp); // for later usage with droptofloor()
874 cp.ons_worldcpnext = ons_worldcplist; // link control point into ons_worldcplist
875 ons_worldcplist = cp;
877 cp.netname = "Control point";
879 cp.solid = SOLID_BBOX;
880 cp.movetype = MOVETYPE_NONE;
881 cp.touch = ons_ControlPoint_Touch;
882 cp.think = ons_ControlPoint_Think;
883 cp.nextthink = time + ONS_CP_THINKRATE;
884 cp.reset = ons_ControlPoint_Reset;
886 cp.iscaptured = false;
888 cp.isshielded = true;
890 if(cp.message == "") { cp.message = "a"; }
893 setmodel_fixsize(cp, MDL_ONS_CP_PAD1);
895 // control point placement
896 if((cp.spawnflags & 1) || cp.noalign) // don't drop to floor, just stay at fixed location
899 cp.movetype = MOVETYPE_NONE;
901 else // drop to floor, automatically find a platform and set that as spawn origin
903 setorigin(cp, cp.origin + '0 0 20');
907 cp.movetype = MOVETYPE_TOSS;
911 WaypointSprite_SpawnFixed(WP_Null, self.origin + CPGEN_WAYPOINT_OFFSET, self, sprite, RADARICON_NONE);
912 WaypointSprite_UpdateRule(self.sprite, self.team, SPRITERULE_TEAMPLAY);
914 InitializeEntity(cp, ons_DelayedControlPoint_Setup, INITPRIO_SETLOCATION);
918 // =========================
919 // Main Generator Functions
920 // =========================
922 entity ons_Generator_Waypoint(entity e)
925 return WP_OnsGenShielded;
929 void ons_Generator_UpdateSprite(entity e)
931 entity s1 = ons_Generator_Waypoint(e);
932 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
934 if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
936 e.lastteam = e.team + 2;
937 e.lastshielded = e.isshielded;
941 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, false));
943 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
948 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, false));
950 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
952 WaypointSprite_Ping(e.sprite);
956 void ons_GeneratorDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
958 if(damage <= 0) { return; }
959 if(warmup_stage || gameover) { return; }
960 if(!round_handler_IsRoundStarted()) { return; }
962 if (attacker != this)
966 // this is protected by a shield, so ignore the damage
967 if (time > this.pain_finished)
968 if (IS_PLAYER(attacker))
970 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
971 attacker.typehitsound += 1;
972 this.pain_finished = time + 1;
976 if (time > this.pain_finished)
978 this.pain_finished = time + 10;
979 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && SAME_TEAM(it, this), Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK));
980 play2team(this.team, SND(ONS_GENERATOR_UNDERATTACK));
983 this.health = this.health - damage;
984 WaypointSprite_UpdateHealth(this.sprite, this.health);
985 // choose an animation frame based on health
986 this.frame = 10 * bound(0, (1 - this.health / this.max_health), 1);
987 // see if the generator is still functional, or dying
990 this.lasthealth = this.health;
994 if (attacker == this)
995 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME));
998 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED));
999 PlayerScore_Add(attacker, SP_SCORE, 100);
1001 this.iscaptured = false;
1002 this.islinked = false;
1003 this.isshielded = false;
1004 this.takedamage = DAMAGE_NO; // can't be hurt anymore
1005 this.event_damage = func_null; // won't do anything if hurt
1006 this.count = 0; // reset counter
1007 this.think = func_null;
1009 //this.think(); // do the first explosion now
1011 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
1012 WaypointSprite_Ping(this.sprite);
1013 //WaypointSprite_Kill(this.sprite); // can't do this yet, code too poor
1015 onslaught_updatelinks();
1018 // Throw some flaming gibs on damage, more damage = more chance for gib
1019 if(random() < damage/220)
1021 sound(this, CH_TRIGGER, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
1025 // particles on every hit
1026 Send_Effect(EFFECT_SPARKS, hitloc, force * -1, 1);
1028 //sound on every hit
1030 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE, ATTEN_NORM);
1032 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE, ATTEN_NORM);
1035 this.SendFlags |= GSF_STATUS;
1038 void ons_GeneratorThink()
1040 self.nextthink = time + GEN_THINKRATE;
1043 if(!self.isshielded && self.wait < time)
1045 self.wait = time + 5;
1046 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
1047 if(SAME_TEAM(it, self))
1049 Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM);
1050 soundto(MSG_ONE, it, CHAN_AUTO, SND(KH_ALARM), VOL_BASE, ATTEN_NONE); // FIXME: unique sound?
1053 Send_Notification(NOTIF_ONE, it, MSG_CENTER, APP_TEAM_NUM(self.team, CENTER_ONS_NOTSHIELDED));
1059 void ons_GeneratorReset(entity this)
1061 this.team = this.team_saved;
1062 this.lasthealth = this.max_health = this.health = autocvar_g_onslaught_gen_health;
1063 this.takedamage = DAMAGE_AIM;
1064 this.bot_attack = true;
1065 this.iscaptured = true;
1066 this.islinked = true;
1067 this.isshielded = true;
1068 this.event_damage = ons_GeneratorDamage;
1069 this.think = ons_GeneratorThink;
1070 this.nextthink = time + GEN_THINKRATE;
1072 Net_LinkEntity(this, false, 0, generator_send);
1074 this.SendFlags = GSF_SETUP; // just incase
1075 this.SendFlags |= GSF_STATUS;
1077 WaypointSprite_UpdateMaxHealth(this.sprite, this.max_health);
1078 WaypointSprite_UpdateHealth(this.sprite, this.health);
1079 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
1081 onslaught_updatelinks();
1084 void ons_DelayedGeneratorSetup()
1087 waypoint_spawnforitem_force(self, self.origin);
1088 self.nearestwaypointtimeout = 0; // activate waypointing again
1089 self.bot_basewaypoint = self.nearestwaypoint;
1091 // captureshield setup
1092 ons_CaptureShield_Spawn(self, true);
1094 onslaught_updatelinks();
1096 Net_LinkEntity(self, false, 0, generator_send);
1100 void onslaught_generator_touch()
1102 if ( IS_PLAYER(other) )
1103 if ( SAME_TEAM(self,other) )
1104 if ( self.iscaptured )
1106 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_TELEPORT);
1110 void ons_GeneratorSetup(entity gen) // called when spawning a generator entity on the map as a spawnfunc
1113 int teamnumber = gen.team;
1114 setself(gen); // for later usage with droptofloor()
1117 gen.ons_worldgeneratornext = ons_worldgeneratorlist; // link generator into ons_worldgeneratorlist
1118 ons_worldgeneratorlist = gen;
1120 gen.netname = sprintf("%s generator", Team_ColoredFullName(teamnumber));
1121 gen.classname = "onslaught_generator";
1122 gen.solid = SOLID_BBOX;
1123 gen.team_saved = teamnumber;
1124 gen.movetype = MOVETYPE_NONE;
1125 gen.lasthealth = gen.max_health = gen.health = autocvar_g_onslaught_gen_health;
1126 gen.takedamage = DAMAGE_AIM;
1127 gen.bot_attack = true;
1128 gen.event_damage = ons_GeneratorDamage;
1129 gen.reset = ons_GeneratorReset;
1130 gen.think = ons_GeneratorThink;
1131 gen.nextthink = time + GEN_THINKRATE;
1132 gen.iscaptured = true;
1133 gen.islinked = true;
1134 gen.isshielded = true;
1135 gen.touch = onslaught_generator_touch;
1138 // model handled by CSQC
1139 setsize(gen, GENERATOR_MIN, GENERATOR_MAX);
1140 setorigin(gen, (gen.origin + CPGEN_SPAWN_OFFSET));
1141 gen.colormap = 1024 + (teamnumber - 1) * 17;
1143 // generator placement
1148 WaypointSprite_SpawnFixed(WP_Null, self.origin + CPGEN_WAYPOINT_OFFSET, self, sprite, RADARICON_NONE);
1149 WaypointSprite_UpdateRule(self.sprite, self.team, SPRITERULE_TEAMPLAY);
1150 WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
1151 WaypointSprite_UpdateHealth(self.sprite, self.health);
1153 InitializeEntity(gen, ons_DelayedGeneratorSetup, INITPRIO_SETLOCATION);
1161 int total_generators;
1162 void Onslaught_count_generators()
1165 total_generators = redowned = blueowned = yellowowned = pinkowned = 0;
1166 for(e = ons_worldgeneratorlist; e; e = e.ons_worldgeneratornext)
1169 redowned += (e.team == NUM_TEAM_1 && e.health > 0);
1170 blueowned += (e.team == NUM_TEAM_2 && e.health > 0);
1171 yellowowned += (e.team == NUM_TEAM_3 && e.health > 0);
1172 pinkowned += (e.team == NUM_TEAM_4 && e.health > 0);
1176 int Onslaught_GetWinnerTeam()
1178 int winner_team = 0;
1180 winner_team = NUM_TEAM_1;
1183 if(winner_team) return 0;
1184 winner_team = NUM_TEAM_2;
1188 if(winner_team) return 0;
1189 winner_team = NUM_TEAM_3;
1193 if(winner_team) return 0;
1194 winner_team = NUM_TEAM_4;
1198 return -1; // no generators left?
1201 void nades_Clear(entity e);
1203 #define ONS_OWNED_GENERATORS() ((redowned > 0) + (blueowned > 0) + (yellowowned > 0) + (pinkowned > 0))
1204 #define ONS_OWNED_GENERATORS_OK() (ONS_OWNED_GENERATORS() > 1)
1205 bool Onslaught_CheckWinner()
1207 if ((autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60) || (round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0))
1209 ons_stalemate = true;
1211 if (!wpforenemy_announced)
1213 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT);
1214 sound(world, CH_INFO, SND_ONS_GENERATOR_DECAY, VOL_BASE, ATTEN_NONE);
1216 wpforenemy_announced = true;
1219 entity tmp_entity; // temporary entity
1221 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext) if(time >= tmp_entity.ons_overtime_damagedelay)
1223 // tmp_entity.max_health / 300 gives 5 minutes of overtime.
1224 // control points reduce the overtime duration.
1227 for(e = ons_worldcplist; e; e = e.ons_worldcpnext)
1229 if(DIFF_TEAM(e, tmp_entity))
1234 if(autocvar_g_campaign && autocvar__campaign_testrun)
1235 d = d * tmp_entity.max_health;
1237 d = d * tmp_entity.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
1239 Damage(tmp_entity, tmp_entity, tmp_entity, d, DEATH_HURTTRIGGER.m_id, tmp_entity.origin, '0 0 0');
1241 tmp_entity.sprite.SendFlags |= 16;
1243 tmp_entity.ons_overtime_damagedelay = time + 1;
1246 else { wpforenemy_announced = false; ons_stalemate = false; }
1248 Onslaught_count_generators();
1250 if(ONS_OWNED_GENERATORS_OK())
1253 int winner_team = Onslaught_GetWinnerTeam();
1257 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
1258 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
1259 TeamScore_AddToTeam(winner_team, ST_ONS_CAPS, +1);
1261 else if(winner_team == -1)
1263 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
1264 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
1267 ons_stalemate = false;
1269 play2all(SND(CTF_CAPTURE(winner_team)));
1271 round_handler_Init(7, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
1273 FOREACH_CLIENT(IS_PLAYER(it), {
1274 it.ons_roundlost = true;
1275 it.player_blocked = true;
1283 bool Onslaught_CheckPlayers()
1288 void Onslaught_RoundStart()
1291 FOREACH_CLIENT(IS_PLAYER(it), it.player_blocked = false);
1293 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1294 tmp_entity.sprite.SendFlags |= 16;
1296 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1297 tmp_entity.sprite.SendFlags |= 16;
1305 // NOTE: LEGACY CODE, needs to be re-written!
1307 void havocbot_goalrating_ons_offenseitems(entity this, float ratingscale, vector org, float sradius)
1311 bool needarmor = false, needweapons = false;
1313 // Needs armor/health?
1319 FOREACH(Weapons, it != WEP_Null, {
1320 if(this.weapons & (it.m_wepset))
1328 if(!needweapons && !needarmor)
1331 LOG_DEBUG(strcat(this.netname, " needs weapons ", ftos(needweapons) , "\n"));
1332 LOG_DEBUG(strcat(this.netname, " needs armor ", ftos(needarmor) , "\n"));
1334 // See what is around
1335 head = findchainfloat(bot_pickup, true);
1338 // gather health and armor only
1340 if ( ((head.health || head.armorvalue) && needarmor) || (head.weapons && needweapons ) )
1341 if (vlen(head.origin - org) < sradius)
1343 t = head.bot_pickupevalfunc(this, head);
1345 navigation_routerating(this, head, t * ratingscale, 500);
1351 void havocbot_role_ons_setrole(entity this, int role)
1353 LOG_DEBUG(strcat(this.netname," switched to "));
1356 case HAVOCBOT_ONS_ROLE_DEFENSE:
1357 LOG_DEBUG("defense");
1358 this.havocbot_role = havocbot_role_ons_defense;
1359 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE;
1360 this.havocbot_role_timeout = 0;
1362 case HAVOCBOT_ONS_ROLE_ASSISTANT:
1363 LOG_DEBUG("assistant");
1364 this.havocbot_role = havocbot_role_ons_assistant;
1365 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT;
1366 this.havocbot_role_timeout = 0;
1368 case HAVOCBOT_ONS_ROLE_OFFENSE:
1369 LOG_DEBUG("offense");
1370 this.havocbot_role = havocbot_role_ons_offense;
1371 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE;
1372 this.havocbot_role_timeout = 0;
1378 void havocbot_goalrating_ons_controlpoints_attack(entity this, float ratingscale)
1380 entity cp, cp1, cp2, best, wp;
1381 float radius, bestvalue;
1385 // Filter control points
1386 for(cp2 = ons_worldcplist; cp2; cp2 = cp2.ons_worldcpnext)
1389 cp2.wpconsidered = false;
1394 // Ignore owned controlpoints
1395 if(!(cp2.isgenneighbor[this.team] || cp2.iscpneighbor[this.team]))
1398 // Count team mates interested in this control point
1399 // (easier and cleaner than keeping counters per cp and teams)
1400 FOREACH_CLIENT(IS_PLAYER(it), {
1401 if(SAME_TEAM(it, this))
1402 if(it.havocbot_role_flags & HAVOCBOT_ONS_ROLE_OFFENSE)
1403 if(it.havocbot_ons_target == cp2)
1407 // NOTE: probably decrease the cost of attackable control points
1409 cp2.wpconsidered = true;
1412 // We'll consider only the best case
1413 bestvalue = 99999999999;
1415 for(cp1 = ons_worldcplist; cp1; cp1 = cp1.ons_worldcpnext)
1417 if (!cp1.wpconsidered)
1420 if(cp1.wpcost<bestvalue)
1422 bestvalue = cp1.wpcost;
1424 this.havocbot_ons_target = cp1;
1431 LOG_DEBUG(strcat(this.netname, " chose cp ranked ", ftos(bestvalue), "\n"));
1435 // Should be attacked
1436 // Rate waypoints near it
1439 bestvalue = 99999999999;
1440 for(radius=0; radius<1000 && !found; radius+=500)
1442 for(wp=findradius(cp.origin,radius); wp; wp=wp.chain)
1444 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
1445 if(wp.classname=="waypoint")
1446 if(checkpvs(wp.origin,cp))
1449 if(wp.cnt<bestvalue)
1460 navigation_routerating(this, best, ratingscale, 10000);
1463 this.havocbot_attack_time = 0;
1464 if(checkpvs(this.view_ofs,cp))
1465 if(checkpvs(this.view_ofs,best))
1466 this.havocbot_attack_time = time + 2;
1470 navigation_routerating(this, cp, ratingscale, 10000);
1472 LOG_DEBUG(strcat(this.netname, " found an attackable controlpoint at ", vtos(cp.origin) ,"\n"));
1476 // Should be touched
1477 LOG_DEBUG(strcat(this.netname, " found a touchable controlpoint at ", vtos(cp.origin) ,"\n"));
1480 // Look for auto generated waypoint
1481 if (!bot_waypoints_for_items)
1482 for (wp = findradius(cp.origin,100); wp; wp = wp.chain)
1484 if(wp.classname=="waypoint")
1486 navigation_routerating(this, wp, ratingscale, 10000);
1491 // Nothing found, rate the controlpoint itself
1493 navigation_routerating(this, cp, ratingscale, 10000);
1497 bool havocbot_goalrating_ons_generator_attack(entity this, float ratingscale)
1499 entity g, wp, bestwp;
1503 for(g = ons_worldgeneratorlist; g; g = g.ons_worldgeneratornext)
1505 if(SAME_TEAM(g, this) || g.isshielded)
1508 // Should be attacked
1509 // Rate waypoints near it
1514 for(wp=findradius(g.origin,400); wp; wp=wp.chain)
1516 if(wp.classname=="waypoint")
1517 if(checkpvs(wp.origin,g))
1530 LOG_DEBUG("waypoints found around generator\n");
1531 navigation_routerating(this, bestwp, ratingscale, 10000);
1534 this.havocbot_attack_time = 0;
1535 if(checkpvs(this.view_ofs,g))
1536 if(checkpvs(this.view_ofs,bestwp))
1537 this.havocbot_attack_time = time + 5;
1543 LOG_DEBUG("generator found without waypoints around\n");
1544 // if there aren't waypoints near the generator go straight to it
1545 navigation_routerating(this, g, ratingscale, 10000);
1546 this.havocbot_attack_time = 0;
1553 void havocbot_role_ons_offense(entity this)
1557 this.havocbot_attack_time = 0;
1558 havocbot_ons_reset_role(this);
1562 // Set the role timeout if necessary
1563 if (!this.havocbot_role_timeout)
1564 this.havocbot_role_timeout = time + 120;
1566 if (time > this.havocbot_role_timeout)
1568 havocbot_ons_reset_role(this);
1572 if(this.havocbot_attack_time>time)
1575 if (this.bot_strategytime < time)
1577 navigation_goalrating_start(this);
1578 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
1579 if(!havocbot_goalrating_ons_generator_attack(this, 20000))
1580 havocbot_goalrating_ons_controlpoints_attack(this, 20000);
1581 havocbot_goalrating_ons_offenseitems(this, 10000, this.origin, 10000);
1582 navigation_goalrating_end(this);
1584 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
1588 void havocbot_role_ons_assistant(entity this)
1590 havocbot_ons_reset_role(this);
1593 void havocbot_role_ons_defense(entity this)
1595 havocbot_ons_reset_role(this);
1598 void havocbot_ons_reset_role(entity this)
1603 this.havocbot_ons_target = world;
1605 // TODO: Defend control points or generator if necessary
1607 havocbot_role_ons_setrole(this, HAVOCBOT_ONS_ROLE_OFFENSE);
1612 * Find control point or generator owned by the same team self which is nearest to pos
1613 * if max_dist is positive, only control points within this range will be considered
1615 entity ons_Nearest_ControlPoint(vector pos, float max_dist)
1617 entity tmp_entity, closest_target = world;
1618 tmp_entity = findchain(classname, "onslaught_controlpoint");
1621 if(SAME_TEAM(tmp_entity, self))
1622 if(tmp_entity.iscaptured)
1623 if(max_dist <= 0 || vdist(tmp_entity.origin - pos, <=, max_dist))
1624 if(vlen2(tmp_entity.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == world)
1625 closest_target = tmp_entity;
1626 tmp_entity = tmp_entity.chain;
1628 tmp_entity = findchain(classname, "onslaught_generator");
1631 if(SAME_TEAM(tmp_entity, self))
1632 if(max_dist <= 0 || vdist(tmp_entity.origin - pos, <, max_dist))
1633 if(vlen2(tmp_entity.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == world)
1634 closest_target = tmp_entity;
1635 tmp_entity = tmp_entity.chain;
1638 return closest_target;
1642 * Find control point or generator owned by the same team self which is nearest to pos
1643 * if max_dist is positive, only control points within this range will be considered
1644 * This function only check distances on the XY plane, disregarding Z
1646 entity ons_Nearest_ControlPoint_2D(vector pos, float max_dist)
1648 entity tmp_entity, closest_target = world;
1650 float smallest_distance = 0, distance;
1652 tmp_entity = findchain(classname, "onslaught_controlpoint");
1655 delta = tmp_entity.origin - pos;
1657 distance = vlen(delta);
1659 if(SAME_TEAM(tmp_entity, self))
1660 if(tmp_entity.iscaptured)
1661 if(max_dist <= 0 || distance <= max_dist)
1662 if(closest_target == world || distance <= smallest_distance )
1664 closest_target = tmp_entity;
1665 smallest_distance = distance;
1668 tmp_entity = tmp_entity.chain;
1670 tmp_entity = findchain(classname, "onslaught_generator");
1673 delta = tmp_entity.origin - pos;
1675 distance = vlen(delta);
1677 if(SAME_TEAM(tmp_entity, self))
1678 if(max_dist <= 0 || distance <= max_dist)
1679 if(closest_target == world || distance <= smallest_distance )
1681 closest_target = tmp_entity;
1682 smallest_distance = distance;
1685 tmp_entity = tmp_entity.chain;
1688 return closest_target;
1691 * find the number of control points and generators in the same team as this
1693 int ons_Count_SelfControlPoints(entity this)
1696 tmp_entity = findchain(classname, "onslaught_controlpoint");
1700 if(SAME_TEAM(tmp_entity, this))
1701 if(tmp_entity.iscaptured)
1703 tmp_entity = tmp_entity.chain;
1705 tmp_entity = findchain(classname, "onslaught_generator");
1708 if(SAME_TEAM(tmp_entity, this))
1710 tmp_entity = tmp_entity.chain;
1716 * Teleport player to a random position near tele_target
1717 * if tele_effects is true, teleport sound+particles are created
1718 * return false on failure
1720 bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effects)
1728 // narrow the range for each iteration to increase chances that a spawnpoint
1729 // can be found even if there's little room around the control point
1730 float iteration_scale = 1;
1731 for(i = 0; i < 16; ++i)
1733 iteration_scale -= i / 16;
1734 theta = random() * 2 * M_PI;
1738 loc *= random() * range * iteration_scale;
1740 loc += tele_target.origin + '0 0 128' * iteration_scale;
1742 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
1743 if(trace_fraction == 1.0 && !trace_startsolid)
1745 traceline(tele_target.origin, loc, MOVE_NOMONSTERS, tele_target); // double check to make sure we're not spawning outside the world
1746 if(trace_fraction == 1.0 && !trace_startsolid)
1750 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
1751 sound (player, CH_TRIGGER, SND_TELEPORT, VOL_BASE, ATTEN_NORM);
1753 setorigin(player, loc);
1754 player.angles = '0 1 0' * ( theta * RAD2DEG + 180 );
1755 makevectors(player.angles);
1756 player.fixangle = true;
1757 player.teleport_antispam = time + autocvar_g_onslaught_teleport_wait;
1760 Send_Effect(EFFECT_TELEPORT, player.origin + v_forward * 32, '0 0 0', 1);
1773 MUTATOR_HOOKFUNCTION(ons, reset_map_global)
1775 FOREACH_CLIENT(IS_PLAYER(it), {
1776 it.ons_roundlost = false;
1777 it.ons_deathloc = '0 0 0';
1778 WITH(entity, self, it, PutClientInServer());
1783 MUTATOR_HOOKFUNCTION(ons, ClientDisconnect)
1785 self.ons_deathloc = '0 0 0';
1789 MUTATOR_HOOKFUNCTION(ons, MakePlayerObserver)
1791 self.ons_deathloc = '0 0 0';
1795 MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
1797 if(!round_handler_IsRoundStarted())
1799 self.player_blocked = true;
1804 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1806 l.sprite.SendFlags |= 16;
1808 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1810 l.sprite.SendFlags |= 16;
1813 if(ons_stalemate) { Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); }
1815 if ( autocvar_g_onslaught_spawn_choose )
1816 if ( self.ons_spawn_by )
1817 if ( ons_Teleport(self,self.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) )
1819 self.ons_spawn_by = world;
1823 if(autocvar_g_onslaught_spawn_at_controlpoints)
1824 if(random() <= autocvar_g_onslaught_spawn_at_controlpoints_chance)
1826 float random_target = autocvar_g_onslaught_spawn_at_controlpoints_random;
1827 entity tmp_entity, closest_target = world;
1828 vector spawn_loc = self.ons_deathloc;
1830 // new joining player or round reset, don't bother checking
1831 if(spawn_loc == '0 0 0') { return false; }
1833 if(random_target) { RandomSelection_Init(); }
1835 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1837 if(SAME_TEAM(tmp_entity, self))
1839 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1840 else if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world)
1841 closest_target = tmp_entity;
1844 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1850 float iteration_scale = 1;
1851 for(i = 0; i < 10; ++i)
1853 iteration_scale -= i / 10;
1854 loc = closest_target.origin + '0 0 96' * iteration_scale;
1855 loc += ('0 1 0' * random()) * 128 * iteration_scale;
1856 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, self);
1857 if(trace_fraction == 1.0 && !trace_startsolid)
1859 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
1860 if(trace_fraction == 1.0 && !trace_startsolid)
1862 setorigin(self, loc);
1863 self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1871 if(autocvar_g_onslaught_spawn_at_generator)
1872 if(random() <= autocvar_g_onslaught_spawn_at_generator_chance)
1874 float random_target = autocvar_g_onslaught_spawn_at_generator_random;
1875 entity tmp_entity, closest_target = world;
1876 vector spawn_loc = self.ons_deathloc;
1878 // new joining player or round reset, don't bother checking
1879 if(spawn_loc == '0 0 0') { return false; }
1881 if(random_target) { RandomSelection_Init(); }
1883 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1886 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1889 if(SAME_TEAM(tmp_entity, self))
1890 if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world)
1891 closest_target = tmp_entity;
1895 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1901 float iteration_scale = 1;
1902 for(i = 0; i < 10; ++i)
1904 iteration_scale -= i / 10;
1905 loc = closest_target.origin + '0 0 128' * iteration_scale;
1906 loc += ('0 1 0' * random()) * 256 * iteration_scale;
1907 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, self);
1908 if(trace_fraction == 1.0 && !trace_startsolid)
1910 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
1911 if(trace_fraction == 1.0 && !trace_startsolid)
1913 setorigin(self, loc);
1914 self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1925 MUTATOR_HOOKFUNCTION(ons, PlayerDies)
1927 frag_target.ons_deathloc = frag_target.origin;
1929 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1931 l.sprite.SendFlags |= 16;
1933 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1935 l.sprite.SendFlags |= 16;
1938 if ( autocvar_g_onslaught_spawn_choose )
1939 if ( ons_Count_SelfControlPoints(frag_target) > 1 )
1940 stuffcmd(frag_target, "qc_cmd_cl hud clickradar\n");
1945 MUTATOR_HOOKFUNCTION(ons, MonsterMove)
1947 entity e = find(world, targetname, self.target);
1954 void ons_MonsterSpawn_Delayed()
1956 entity e, own = self.owner;
1958 if(!own) { remove(self); return; }
1962 e = find(world, target, own.targetname);
1975 MUTATOR_HOOKFUNCTION(ons, MonsterSpawn)
1979 InitializeEntity(e, ons_MonsterSpawn_Delayed, INITPRIO_FINDTARGET);
1984 void ons_TurretSpawn_Delayed()
1986 entity e, own = self.owner;
1988 if(!own) { remove(self); return; }
1992 e = find(world, target, own.targetname);
1996 own.active = ACTIVE_NOT;
2006 MUTATOR_HOOKFUNCTION(ons, TurretSpawn)
2010 InitializeEntity(e, ons_TurretSpawn_Delayed, INITPRIO_FINDTARGET);
2015 MUTATOR_HOOKFUNCTION(ons, HavocBot_ChooseRole)
2017 havocbot_ons_reset_role(self);
2021 MUTATOR_HOOKFUNCTION(ons, GetTeamCount)
2023 // onslaught is special
2024 for(entity tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
2026 switch(tmp_entity.team)
2028 case NUM_TEAM_1: c1 = 0; break;
2029 case NUM_TEAM_2: c2 = 0; break;
2030 case NUM_TEAM_3: c3 = 0; break;
2031 case NUM_TEAM_4: c4 = 0; break;
2038 MUTATOR_HOOKFUNCTION(ons, SpectateCopy)
2040 self.ons_roundlost = other.ons_roundlost; // make spectators see it too
2044 MUTATOR_HOOKFUNCTION(ons, SV_ParseClientCommand)
2046 if(MUTATOR_RETURNVALUE) // command was already handled?
2049 if ( cmd_name == "ons_spawn" )
2051 vector pos = self.origin;
2053 pos_x = stof(argv(1));
2055 pos_y = stof(argv(2));
2057 pos_z = stof(argv(3));
2059 if ( IS_PLAYER(self) )
2061 if ( !STAT(FROZEN, self) )
2063 entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
2065 if ( !source_point && self.health > 0 )
2067 sprint(self, "\nYou need to be next to a control point\n");
2072 entity closest_target = ons_Nearest_ControlPoint_2D(pos, autocvar_g_onslaught_click_radius);
2074 if ( closest_target == world )
2076 sprint(self, "\nNo control point found\n");
2080 if ( self.health <= 0 )
2082 self.ons_spawn_by = closest_target;
2083 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
2087 if ( source_point == closest_target )
2089 sprint(self, "\nTeleporting to the same point\n");
2093 if ( !ons_Teleport(self,closest_target,autocvar_g_onslaught_teleport_radius,true) )
2094 sprint(self, "\nUnable to teleport there\n");
2100 sprint(self, "\nNo teleportation for you\n");
2108 MUTATOR_HOOKFUNCTION(ons, PlayerUseKey)
2110 if(MUTATOR_RETURNVALUE || gameover) { return false; }
2112 if((time > self.teleport_antispam) && (!IS_DEAD(self)) && !self.vehicle)
2114 entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
2117 stuffcmd(self, "qc_cmd_cl hud clickradar\n");
2125 MUTATOR_HOOKFUNCTION(ons, PlayHitsound)
2127 return (frag_victim.classname == "onslaught_generator" && !frag_victim.isshielded)
2128 || (frag_victim.classname == "onslaught_controlpoint_icon" && !frag_victim.owner.isshielded);
2131 MUTATOR_HOOKFUNCTION(ons, SendWaypoint)
2134 if(wp_sendflags & 16)
2136 if(self.owner.classname == "onslaught_controlpoint")
2138 entity wp_owner = self.owner;
2139 entity e = WaypointSprite_getviewentity(wp_sendto);
2140 if(SAME_TEAM(e, wp_owner) && wp_owner.goalentity.health >= wp_owner.goalentity.max_health) { wp_flag |= 2; }
2141 if(!ons_ControlPoint_Attackable(wp_owner, e.team)) { wp_flag |= 2; }
2143 if(self.owner.classname == "onslaught_generator")
2145 entity wp_owner = self.owner;
2146 if(wp_owner.isshielded && wp_owner.health >= wp_owner.max_health) { wp_flag |= 2; }
2147 if(wp_owner.health <= 0) { wp_flag |= 2; }
2154 MUTATOR_HOOKFUNCTION(ons, TurretValidateTarget)
2156 if(substring(turret_target.classname, 0, 10) == "onslaught_") // don't attack onslaught targets, that's the player's job!
2165 MUTATOR_HOOKFUNCTION(ons, TurretThink)
2168 // ONS uses somewhat backwards linking.
2171 entity e = find(world, targetname, self.target);
2176 if(self.team != self.tur_head.team)
2187 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
2188 Link between control points.
2190 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.
2193 "target" - first control point.
2194 "target2" - second control point.
2196 spawnfunc(onslaught_link)
2198 if(!g_onslaught) { remove(self); return; }
2200 if (self.target == "" || self.target2 == "")
2201 objerror("target and target2 must be set\n");
2203 self.ons_worldlinknext = ons_worldlinklist; // link into ons_worldlinklist
2204 ons_worldlinklist = self;
2206 InitializeEntity(self, ons_DelayedLinkSetup, INITPRIO_FINDTARGET);
2207 Net_LinkEntity(self, false, 0, ons_Link_Send);
2210 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
2211 Control point. Be sure to give this enough clearance so that the shootable part has room to exist
2213 This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
2216 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2217 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
2218 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
2221 spawnfunc(onslaught_controlpoint)
2223 if(!g_onslaught) { remove(self); return; }
2225 ons_ControlPoint_Setup(self);
2228 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
2231 spawnfunc_onslaught_link entities can target this.
2234 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
2235 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2237 spawnfunc(onslaught_generator)
2239 if(!g_onslaught) { remove(self); return; }
2240 if(!self.team) { objerror("team must be set"); }
2242 ons_GeneratorSetup(self);
2246 void ons_ScoreRules()
2248 CheckAllowedTeams(world);
2249 ScoreRules_basics(((c4>=0) ? 4 : (c3>=0) ? 3 : 2), SFL_SORT_PRIO_PRIMARY, 0, true);
2250 ScoreInfo_SetLabel_TeamScore (ST_ONS_CAPS, "destroyed", SFL_SORT_PRIO_PRIMARY);
2251 ScoreInfo_SetLabel_PlayerScore(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
2252 ScoreInfo_SetLabel_PlayerScore(SP_ONS_TAKES, "takes", 0);
2253 ScoreRules_basics_end();
2256 void ons_DelayedInit() // Do this check with a delay so we can wait for teams to be set up
2260 round_handler_Spawn(Onslaught_CheckPlayers, Onslaught_CheckWinner, Onslaught_RoundStart);
2261 round_handler_Init(5, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
2264 void ons_Initialize()
2267 ons_captureshield_force = autocvar_g_onslaught_shield_force;
2269 InitializeEntity(world, ons_DelayedInit, INITPRIO_GAMETYPE);