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();
114 void havocbot_role_ons_offense();
115 void havocbot_role_ons_assistant();
117 void havocbot_ons_reset_role(entity bot);
118 void havocbot_goalrating_items(float ratingscale, vector org, float sradius);
119 void havocbot_goalrating_enemyplayers(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_4(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;
575 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it), LAMBDA(
576 _dist = vlen(it.origin - self.origin);
577 if(_dist < autocvar_g_onslaught_cp_proxydecap_distance)
579 if(SAME_TEAM(it, self))
586 _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
587 _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
589 self.health = bound(0, self.health + (_friendly_count - _enemy_count), self.max_health);
590 self.SendFlags |= CPSF_STATUS;
593 ons_ControlPoint_Icon_Damage(self, self, self, 1, 0, self.origin, '0 0 0');
598 if (time > self.pain_finished + 5)
600 if(self.health < self.max_health)
602 self.health = self.health + self.count;
603 if (self.health >= self.max_health)
604 self.health = self.max_health;
605 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
609 if(self.owner.islinked != self.owner.waslinked)
611 // unteam the spawnpoint if needed
612 int t = self.owner.team;
613 if(!self.owner.islinked)
623 self.owner.waslinked = self.owner.islinked;
627 if(random() < 0.6 - self.health / self.max_health)
629 Send_Effect(EFFECT_ELECTRIC_SPARKS, self.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
632 sound(self, CH_PAIN, SND_ONS_SPARK1, VOL_BASE, ATTEN_NORM);
633 else if (random() > 0.5)
634 sound(self, CH_PAIN, SND_ONS_SPARK2, VOL_BASE, ATTEN_NORM);
638 void ons_ControlPoint_Icon_BuildThink()
642 self.nextthink = time + ONS_CP_THINKRATE;
644 // only do this if there is power
645 a = ons_ControlPoint_CanBeLinked(self.owner, self.owner.team);
649 self.health = self.health + self.count;
651 self.SendFlags |= CPSF_STATUS;
653 if (self.health >= self.max_health)
655 self.health = self.max_health;
656 self.count = autocvar_g_onslaught_cp_regen * ONS_CP_THINKRATE; // slow repair rate from now on
657 self.think = ons_ControlPoint_Icon_Think;
658 sound(self, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILT, VOL_BASE, ATTEN_NORM);
659 self.owner.iscaptured = true;
660 self.solid = SOLID_BBOX;
662 Send_Effect(EFFECT_CAP(self.owner.team), self.owner.origin, '0 0 0', 1);
664 WaypointSprite_UpdateMaxHealth(self.owner.sprite, self.max_health);
665 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
667 if(IS_PLAYER(self.owner.ons_toucher))
669 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ONSLAUGHT_CAPTURE, self.owner.ons_toucher.netname, self.owner.message);
670 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);
671 Send_Notification(NOTIF_ONE, self.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE, self.owner.message);
672 PlayerScore_Add(self.owner.ons_toucher, SP_ONS_CAPS, 1);
673 PlayerTeamScore_AddScore(self.owner.ons_toucher, 10);
676 self.owner.ons_toucher = world;
678 onslaught_updatelinks();
680 // Use targets now (somebody make sure this is in the right place..)
686 self.SendFlags |= CPSF_SETUP;
688 if(self.owner.model != MDL_ONS_CP_PAD2.model_str())
689 setmodel_fixsize(self.owner, MDL_ONS_CP_PAD2);
691 if(random() < 0.9 - self.health / self.max_health)
692 Send_Effect(EFFECT_RAGE, self.origin + 10 * randomvec(), '0 0 -1', 1);
695 void onslaught_controlpoint_icon_link(entity e, void() spawnproc);
697 void ons_ControlPoint_Icon_Spawn(entity cp, entity player)
699 entity e = new(onslaught_controlpoint_icon);
701 setsize(e, CPICON_MIN, CPICON_MAX);
702 setorigin(e, cp.origin + CPICON_OFFSET);
705 e.max_health = autocvar_g_onslaught_cp_health;
706 e.health = autocvar_g_onslaught_cp_buildhealth;
708 e.takedamage = DAMAGE_AIM;
710 e.event_damage = ons_ControlPoint_Icon_Damage;
711 e.team = player.team;
712 e.colormap = 1024 + (e.team - 1) * 17;
713 e.count = (e.max_health - e.health) * ONS_CP_THINKRATE / autocvar_g_onslaught_cp_buildtime; // how long it takes to build
715 sound(e, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILD, VOL_BASE, ATTEN_NORM);
719 cp.colormap = e.colormap;
721 Send_Effect(EFFECT_FLAG_TOUCH(player.team), e.origin, '0 0 0', 1);
723 WaypointSprite_UpdateBuildFinished(cp.sprite, time + (e.max_health - e.health) / (e.count / ONS_CP_THINKRATE));
724 WaypointSprite_UpdateRule(cp.sprite,cp.team,SPRITERULE_TEAMPLAY);
725 cp.sprite.SendFlags |= 16;
727 onslaught_controlpoint_icon_link(e, ons_ControlPoint_Icon_BuildThink);
730 entity ons_ControlPoint_Waypoint(entity e)
734 int a = ons_ControlPoint_Attackable(e, e.team);
736 if(a == -2) { return WP_OnsCPDefend; } // defend now
737 if(a == -1 || a == 1 || a == 2) { return WP_OnsCP; } // touch
738 if(a == 3 || a == 4) { return WP_OnsCPAttack; } // attack
746 void ons_ControlPoint_UpdateSprite(entity e)
748 entity s1 = ons_ControlPoint_Waypoint(e);
749 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
752 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));
754 if(e.lastteam != e.team + 2 || e.lastshielded != sh || e.iscaptured != e.lastcaptured)
756 if(e.iscaptured) // don't mess up build bars!
760 WaypointSprite_UpdateMaxHealth(e.sprite, 0);
764 WaypointSprite_UpdateMaxHealth(e.sprite, e.goalentity.max_health);
765 WaypointSprite_UpdateHealth(e.sprite, e.goalentity.health);
771 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, false));
773 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
778 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, false));
780 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
782 WaypointSprite_Ping(e.sprite);
784 e.lastteam = e.team + 2;
786 e.lastcaptured = e.iscaptured;
790 void ons_ControlPoint_Touch()
792 entity toucher = other;
795 if(IS_VEHICLE(toucher) && toucher.owner)
796 if(autocvar_g_onslaught_allow_vehicle_touch)
797 toucher = toucher.owner;
801 if(!IS_PLAYER(toucher)) { return; }
802 if(STAT(FROZEN, toucher)) { return; }
803 if(IS_DEAD(toucher)) { return; }
805 if ( SAME_TEAM(self,toucher) )
806 if ( self.iscaptured )
808 if(time <= toucher.teleport_antispam)
809 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT_ANTISPAM, rint(toucher.teleport_antispam - time));
811 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
814 attackable = ons_ControlPoint_Attackable(self, toucher.team);
815 if(attackable != 2 && attackable != 4)
817 // we've verified that this player has a legitimate claim to this point,
818 // so start building the captured point icon (which only captures this
819 // point if it successfully builds without being destroyed first)
820 ons_ControlPoint_Icon_Spawn(self, toucher);
822 self.ons_toucher = toucher;
824 onslaught_updatelinks();
827 void ons_ControlPoint_Think()
829 self.nextthink = time + ONS_CP_THINKRATE;
830 CSQCMODEL_AUTOUPDATE(self);
833 void ons_ControlPoint_Reset(entity this)
836 remove(this.goalentity);
838 this.goalentity = world;
840 this.colormap = 1024;
841 this.iscaptured = false;
842 this.islinked = false;
843 this.isshielded = true;
844 this.think = ons_ControlPoint_Think;
845 this.ons_toucher = world;
846 this.nextthink = time + ONS_CP_THINKRATE;
847 setmodel_fixsize(this, MDL_ONS_CP_PAD1);
849 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
850 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
852 onslaught_updatelinks();
855 SUB_UseTargets(); // to reset the structures, playerspawns etc.
857 CSQCMODEL_AUTOUPDATE(this);
860 void ons_DelayedControlPoint_Setup()
862 onslaught_updatelinks();
864 // captureshield setup
865 ons_CaptureShield_Spawn(self, false);
867 CSQCMODEL_AUTOINIT(self);
870 void ons_ControlPoint_Setup(entity cp)
873 setself(cp); // for later usage with droptofloor()
876 cp.ons_worldcpnext = ons_worldcplist; // link control point into ons_worldcplist
877 ons_worldcplist = cp;
879 cp.netname = "Control point";
881 cp.solid = SOLID_BBOX;
882 cp.movetype = MOVETYPE_NONE;
883 cp.touch = ons_ControlPoint_Touch;
884 cp.think = ons_ControlPoint_Think;
885 cp.nextthink = time + ONS_CP_THINKRATE;
886 cp.reset = ons_ControlPoint_Reset;
888 cp.iscaptured = false;
890 cp.isshielded = true;
892 if(cp.message == "") { cp.message = "a"; }
895 setmodel_fixsize(cp, MDL_ONS_CP_PAD1);
897 // control point placement
898 if((cp.spawnflags & 1) || cp.noalign) // don't drop to floor, just stay at fixed location
901 cp.movetype = MOVETYPE_NONE;
903 else // drop to floor, automatically find a platform and set that as spawn origin
905 setorigin(cp, cp.origin + '0 0 20');
909 cp.movetype = MOVETYPE_TOSS;
913 WaypointSprite_SpawnFixed(WP_Null, self.origin + CPGEN_WAYPOINT_OFFSET, self, sprite, RADARICON_NONE);
914 WaypointSprite_UpdateRule(self.sprite, self.team, SPRITERULE_TEAMPLAY);
916 InitializeEntity(cp, ons_DelayedControlPoint_Setup, INITPRIO_SETLOCATION);
920 // =========================
921 // Main Generator Functions
922 // =========================
924 entity ons_Generator_Waypoint(entity e)
927 return WP_OnsGenShielded;
931 void ons_Generator_UpdateSprite(entity e)
933 entity s1 = ons_Generator_Waypoint(e);
934 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
936 if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
938 e.lastteam = e.team + 2;
939 e.lastshielded = e.isshielded;
943 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, false));
945 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
950 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, false));
952 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
954 WaypointSprite_Ping(e.sprite);
958 void ons_GeneratorDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
960 if(damage <= 0) { return; }
961 if(warmup_stage || gameover) { return; }
962 if(!round_handler_IsRoundStarted()) { return; }
964 if (attacker != this)
968 // this is protected by a shield, so ignore the damage
969 if (time > this.pain_finished)
970 if (IS_PLAYER(attacker))
972 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
973 attacker.typehitsound += 1;
974 this.pain_finished = time + 1;
978 if (time > this.pain_finished)
980 this.pain_finished = time + 10;
981 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && SAME_TEAM(it, this), LAMBDA(Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK)));
982 play2team(this.team, SND(ONS_GENERATOR_UNDERATTACK));
985 this.health = this.health - damage;
986 WaypointSprite_UpdateHealth(this.sprite, this.health);
987 // choose an animation frame based on health
988 this.frame = 10 * bound(0, (1 - this.health / this.max_health), 1);
989 // see if the generator is still functional, or dying
992 this.lasthealth = this.health;
996 if (attacker == this)
997 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(this.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME_));
1000 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(this.team, INFO_ONSLAUGHT_GENDESTROYED_));
1001 PlayerScore_Add(attacker, SP_SCORE, 100);
1003 this.iscaptured = false;
1004 this.islinked = false;
1005 this.isshielded = false;
1006 this.takedamage = DAMAGE_NO; // can't be hurt anymore
1007 this.event_damage = func_null; // won't do anything if hurt
1008 this.count = 0; // reset counter
1009 this.think = func_null;
1011 //this.think(); // do the first explosion now
1013 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
1014 WaypointSprite_Ping(this.sprite);
1015 //WaypointSprite_Kill(this.sprite); // can't do this yet, code too poor
1017 onslaught_updatelinks();
1020 // Throw some flaming gibs on damage, more damage = more chance for gib
1021 if(random() < damage/220)
1023 sound(this, CH_TRIGGER, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
1027 // particles on every hit
1028 Send_Effect(EFFECT_SPARKS, hitloc, force * -1, 1);
1030 //sound on every hit
1032 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE, ATTEN_NORM);
1034 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE, ATTEN_NORM);
1037 this.SendFlags |= GSF_STATUS;
1040 void ons_GeneratorThink()
1042 self.nextthink = time + GEN_THINKRATE;
1045 if(!self.isshielded && self.wait < time)
1047 self.wait = time + 5;
1048 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA(
1049 if(SAME_TEAM(it, self))
1051 Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM);
1052 soundto(MSG_ONE, it, CHAN_AUTO, SND(KH_ALARM), VOL_BASE, ATTEN_NONE); // FIXME: unique sound?
1055 Send_Notification(NOTIF_ONE, it, MSG_CENTER, APP_TEAM_NUM_4(self.team, CENTER_ONS_NOTSHIELDED_));
1061 void ons_GeneratorReset(entity this)
1063 this.team = this.team_saved;
1064 this.lasthealth = this.max_health = this.health = autocvar_g_onslaught_gen_health;
1065 this.takedamage = DAMAGE_AIM;
1066 this.bot_attack = true;
1067 this.iscaptured = true;
1068 this.islinked = true;
1069 this.isshielded = true;
1070 this.event_damage = ons_GeneratorDamage;
1071 this.think = ons_GeneratorThink;
1072 this.nextthink = time + GEN_THINKRATE;
1074 Net_LinkEntity(this, false, 0, generator_send);
1076 this.SendFlags = GSF_SETUP; // just incase
1077 this.SendFlags |= GSF_STATUS;
1079 WaypointSprite_UpdateMaxHealth(this.sprite, this.max_health);
1080 WaypointSprite_UpdateHealth(this.sprite, this.health);
1081 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
1083 onslaught_updatelinks();
1086 void ons_DelayedGeneratorSetup()
1089 waypoint_spawnforitem_force(self, self.origin);
1090 self.nearestwaypointtimeout = 0; // activate waypointing again
1091 self.bot_basewaypoint = self.nearestwaypoint;
1093 // captureshield setup
1094 ons_CaptureShield_Spawn(self, true);
1096 onslaught_updatelinks();
1098 Net_LinkEntity(self, false, 0, generator_send);
1102 void onslaught_generator_touch()
1104 if ( IS_PLAYER(other) )
1105 if ( SAME_TEAM(self,other) )
1106 if ( self.iscaptured )
1108 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_TELEPORT);
1112 void ons_GeneratorSetup(entity gen) // called when spawning a generator entity on the map as a spawnfunc
1115 int teamnumber = gen.team;
1116 setself(gen); // for later usage with droptofloor()
1119 gen.ons_worldgeneratornext = ons_worldgeneratorlist; // link generator into ons_worldgeneratorlist
1120 ons_worldgeneratorlist = gen;
1122 gen.netname = sprintf("%s generator", Team_ColoredFullName(teamnumber));
1123 gen.classname = "onslaught_generator";
1124 gen.solid = SOLID_BBOX;
1125 gen.team_saved = teamnumber;
1126 gen.movetype = MOVETYPE_NONE;
1127 gen.lasthealth = gen.max_health = gen.health = autocvar_g_onslaught_gen_health;
1128 gen.takedamage = DAMAGE_AIM;
1129 gen.bot_attack = true;
1130 gen.event_damage = ons_GeneratorDamage;
1131 gen.reset = ons_GeneratorReset;
1132 gen.think = ons_GeneratorThink;
1133 gen.nextthink = time + GEN_THINKRATE;
1134 gen.iscaptured = true;
1135 gen.islinked = true;
1136 gen.isshielded = true;
1137 gen.touch = onslaught_generator_touch;
1140 // model handled by CSQC
1141 setsize(gen, GENERATOR_MIN, GENERATOR_MAX);
1142 setorigin(gen, (gen.origin + CPGEN_SPAWN_OFFSET));
1143 gen.colormap = 1024 + (teamnumber - 1) * 17;
1145 // generator placement
1150 WaypointSprite_SpawnFixed(WP_Null, self.origin + CPGEN_WAYPOINT_OFFSET, self, sprite, RADARICON_NONE);
1151 WaypointSprite_UpdateRule(self.sprite, self.team, SPRITERULE_TEAMPLAY);
1152 WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
1153 WaypointSprite_UpdateHealth(self.sprite, self.health);
1155 InitializeEntity(gen, ons_DelayedGeneratorSetup, INITPRIO_SETLOCATION);
1163 int total_generators;
1164 void Onslaught_count_generators()
1167 total_generators = redowned = blueowned = yellowowned = pinkowned = 0;
1168 for(e = ons_worldgeneratorlist; e; e = e.ons_worldgeneratornext)
1171 redowned += (e.team == NUM_TEAM_1 && e.health > 0);
1172 blueowned += (e.team == NUM_TEAM_2 && e.health > 0);
1173 yellowowned += (e.team == NUM_TEAM_3 && e.health > 0);
1174 pinkowned += (e.team == NUM_TEAM_4 && e.health > 0);
1178 int Onslaught_GetWinnerTeam()
1180 int winner_team = 0;
1182 winner_team = NUM_TEAM_1;
1185 if(winner_team) return 0;
1186 winner_team = NUM_TEAM_2;
1190 if(winner_team) return 0;
1191 winner_team = NUM_TEAM_3;
1195 if(winner_team) return 0;
1196 winner_team = NUM_TEAM_4;
1200 return -1; // no generators left?
1203 void nades_Clear(entity e);
1205 #define ONS_OWNED_GENERATORS() ((redowned > 0) + (blueowned > 0) + (yellowowned > 0) + (pinkowned > 0))
1206 #define ONS_OWNED_GENERATORS_OK() (ONS_OWNED_GENERATORS() > 1)
1207 bool Onslaught_CheckWinner()
1209 if ((autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60) || (round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0))
1211 ons_stalemate = true;
1213 if (!wpforenemy_announced)
1215 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT);
1216 sound(world, CH_INFO, SND_ONS_GENERATOR_DECAY, VOL_BASE, ATTEN_NONE);
1218 wpforenemy_announced = true;
1221 entity tmp_entity; // temporary entity
1223 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext) if(time >= tmp_entity.ons_overtime_damagedelay)
1225 // tmp_entity.max_health / 300 gives 5 minutes of overtime.
1226 // control points reduce the overtime duration.
1229 for(e = ons_worldcplist; e; e = e.ons_worldcpnext)
1231 if(DIFF_TEAM(e, tmp_entity))
1236 if(autocvar_g_campaign && autocvar__campaign_testrun)
1237 d = d * tmp_entity.max_health;
1239 d = d * tmp_entity.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
1241 Damage(tmp_entity, tmp_entity, tmp_entity, d, DEATH_HURTTRIGGER.m_id, tmp_entity.origin, '0 0 0');
1243 tmp_entity.sprite.SendFlags |= 16;
1245 tmp_entity.ons_overtime_damagedelay = time + 1;
1248 else { wpforenemy_announced = false; ons_stalemate = false; }
1250 Onslaught_count_generators();
1252 if(ONS_OWNED_GENERATORS_OK())
1255 int winner_team = Onslaught_GetWinnerTeam();
1259 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
1260 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
1261 TeamScore_AddToTeam(winner_team, ST_ONS_CAPS, +1);
1263 else if(winner_team == -1)
1265 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
1266 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
1269 ons_stalemate = false;
1271 play2all(SND(CTF_CAPTURE(winner_team)));
1273 round_handler_Init(7, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
1275 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
1276 it.ons_roundlost = true;
1277 it.player_blocked = true;
1285 bool Onslaught_CheckPlayers()
1290 void Onslaught_RoundStart()
1293 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(it.player_blocked = false));
1295 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1296 tmp_entity.sprite.SendFlags |= 16;
1298 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1299 tmp_entity.sprite.SendFlags |= 16;
1307 // NOTE: LEGACY CODE, needs to be re-written!
1309 void havocbot_goalrating_ons_offenseitems(float ratingscale, vector org, float sradius)
1313 bool needarmor = false, needweapons = false;
1315 // Needs armor/health?
1321 FOREACH(Weapons, it != WEP_Null, LAMBDA(
1322 if(self.weapons & (it.m_wepset))
1330 if(!needweapons && !needarmor)
1333 LOG_DEBUG(strcat(self.netname, " needs weapons ", ftos(needweapons) , "\n"));
1334 LOG_DEBUG(strcat(self.netname, " needs armor ", ftos(needarmor) , "\n"));
1336 // See what is around
1337 head = findchainfloat(bot_pickup, true);
1340 // gather health and armor only
1342 if ( ((head.health || head.armorvalue) && needarmor) || (head.weapons && needweapons ) )
1343 if (vlen(head.origin - org) < sradius)
1345 t = head.bot_pickupevalfunc(self, head);
1347 navigation_routerating(head, t * ratingscale, 500);
1353 void havocbot_role_ons_setrole(entity bot, int role)
1355 LOG_DEBUG(strcat(bot.netname," switched to "));
1358 case HAVOCBOT_ONS_ROLE_DEFENSE:
1359 LOG_DEBUG("defense");
1360 bot.havocbot_role = havocbot_role_ons_defense;
1361 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE;
1362 bot.havocbot_role_timeout = 0;
1364 case HAVOCBOT_ONS_ROLE_ASSISTANT:
1365 LOG_DEBUG("assistant");
1366 bot.havocbot_role = havocbot_role_ons_assistant;
1367 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT;
1368 bot.havocbot_role_timeout = 0;
1370 case HAVOCBOT_ONS_ROLE_OFFENSE:
1371 LOG_DEBUG("offense");
1372 bot.havocbot_role = havocbot_role_ons_offense;
1373 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE;
1374 bot.havocbot_role_timeout = 0;
1380 void havocbot_goalrating_ons_controlpoints_attack(float ratingscale)
1382 entity cp, cp1, cp2, best, wp;
1383 float radius, bestvalue;
1387 // Filter control points
1388 for(cp2 = ons_worldcplist; cp2; cp2 = cp2.ons_worldcpnext)
1391 cp2.wpconsidered = false;
1396 // Ignore owned controlpoints
1397 if(!(cp2.isgenneighbor[self.team] || cp2.iscpneighbor[self.team]))
1400 // Count team mates interested in this control point
1401 // (easier and cleaner than keeping counters per cp and teams)
1402 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
1403 if(SAME_TEAM(it, self))
1404 if(it.havocbot_role_flags & HAVOCBOT_ONS_ROLE_OFFENSE)
1405 if(it.havocbot_ons_target == cp2)
1409 // NOTE: probably decrease the cost of attackable control points
1411 cp2.wpconsidered = true;
1414 // We'll consider only the best case
1415 bestvalue = 99999999999;
1417 for(cp1 = ons_worldcplist; cp1; cp1 = cp1.ons_worldcpnext)
1419 if (!cp1.wpconsidered)
1422 if(cp1.wpcost<bestvalue)
1424 bestvalue = cp1.wpcost;
1426 self.havocbot_ons_target = cp1;
1433 LOG_DEBUG(strcat(self.netname, " chose cp ranked ", ftos(bestvalue), "\n"));
1437 // Should be attacked
1438 // Rate waypoints near it
1441 bestvalue = 99999999999;
1442 for(radius=0; radius<1000 && !found; radius+=500)
1444 for(wp=findradius(cp.origin,radius); wp; wp=wp.chain)
1446 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
1447 if(wp.classname=="waypoint")
1448 if(checkpvs(wp.origin,cp))
1451 if(wp.cnt<bestvalue)
1462 navigation_routerating(best, ratingscale, 10000);
1465 self.havocbot_attack_time = 0;
1466 if(checkpvs(self.view_ofs,cp))
1467 if(checkpvs(self.view_ofs,best))
1468 self.havocbot_attack_time = time + 2;
1472 navigation_routerating(cp, ratingscale, 10000);
1474 LOG_DEBUG(strcat(self.netname, " found an attackable controlpoint at ", vtos(cp.origin) ,"\n"));
1478 // Should be touched
1479 LOG_DEBUG(strcat(self.netname, " found a touchable controlpoint at ", vtos(cp.origin) ,"\n"));
1482 // Look for auto generated waypoint
1483 if (!bot_waypoints_for_items)
1484 for (wp = findradius(cp.origin,100); wp; wp = wp.chain)
1486 if(wp.classname=="waypoint")
1488 navigation_routerating(wp, ratingscale, 10000);
1493 // Nothing found, rate the controlpoint itself
1495 navigation_routerating(cp, ratingscale, 10000);
1499 bool havocbot_goalrating_ons_generator_attack(float ratingscale)
1501 entity g, wp, bestwp;
1505 for(g = ons_worldgeneratorlist; g; g = g.ons_worldgeneratornext)
1507 if(SAME_TEAM(g, self) || g.isshielded)
1510 // Should be attacked
1511 // Rate waypoints near it
1516 for(wp=findradius(g.origin,400); wp; wp=wp.chain)
1518 if(wp.classname=="waypoint")
1519 if(checkpvs(wp.origin,g))
1532 LOG_DEBUG("waypoints found around generator\n");
1533 navigation_routerating(bestwp, ratingscale, 10000);
1536 self.havocbot_attack_time = 0;
1537 if(checkpvs(self.view_ofs,g))
1538 if(checkpvs(self.view_ofs,bestwp))
1539 self.havocbot_attack_time = time + 5;
1545 LOG_DEBUG("generator found without waypoints around\n");
1546 // if there aren't waypoints near the generator go straight to it
1547 navigation_routerating(g, ratingscale, 10000);
1548 self.havocbot_attack_time = 0;
1555 void havocbot_role_ons_offense()
1559 self.havocbot_attack_time = 0;
1560 havocbot_ons_reset_role(self);
1564 // Set the role timeout if necessary
1565 if (!self.havocbot_role_timeout)
1566 self.havocbot_role_timeout = time + 120;
1568 if (time > self.havocbot_role_timeout)
1570 havocbot_ons_reset_role(self);
1574 if(self.havocbot_attack_time>time)
1577 if (self.bot_strategytime < time)
1579 navigation_goalrating_start();
1580 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
1581 if(!havocbot_goalrating_ons_generator_attack(20000))
1582 havocbot_goalrating_ons_controlpoints_attack(20000);
1583 havocbot_goalrating_ons_offenseitems(10000, self.origin, 10000);
1584 navigation_goalrating_end();
1586 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
1590 void havocbot_role_ons_assistant()
1592 havocbot_ons_reset_role(self);
1595 void havocbot_role_ons_defense()
1597 havocbot_ons_reset_role(self);
1600 void havocbot_ons_reset_role(entity bot)
1605 bot.havocbot_ons_target = world;
1607 // TODO: Defend control points or generator if necessary
1609 havocbot_role_ons_setrole(bot, HAVOCBOT_ONS_ROLE_OFFENSE);
1614 * Find control point or generator owned by the same team self which is nearest to pos
1615 * if max_dist is positive, only control points within this range will be considered
1617 entity ons_Nearest_ControlPoint(vector pos, float max_dist)
1619 entity tmp_entity, closest_target = world;
1620 tmp_entity = findchain(classname, "onslaught_controlpoint");
1623 if(SAME_TEAM(tmp_entity, self))
1624 if(tmp_entity.iscaptured)
1625 if(max_dist <= 0 || vlen(tmp_entity.origin - pos) <= max_dist)
1626 if(vlen(tmp_entity.origin - pos) <= vlen(closest_target.origin - pos) || closest_target == world)
1627 closest_target = tmp_entity;
1628 tmp_entity = tmp_entity.chain;
1630 tmp_entity = findchain(classname, "onslaught_generator");
1633 if(SAME_TEAM(tmp_entity, self))
1634 if(max_dist <= 0 || vlen(tmp_entity.origin - pos) < max_dist)
1635 if(vlen(tmp_entity.origin - pos) <= vlen(closest_target.origin - pos) || closest_target == world)
1636 closest_target = tmp_entity;
1637 tmp_entity = tmp_entity.chain;
1640 return closest_target;
1644 * Find control point or generator owned by the same team self which is nearest to pos
1645 * if max_dist is positive, only control points within this range will be considered
1646 * This function only check distances on the XY plane, disregarding Z
1648 entity ons_Nearest_ControlPoint_2D(vector pos, float max_dist)
1650 entity tmp_entity, closest_target = world;
1652 float smallest_distance = 0, distance;
1654 tmp_entity = findchain(classname, "onslaught_controlpoint");
1657 delta = tmp_entity.origin - pos;
1659 distance = vlen(delta);
1661 if(SAME_TEAM(tmp_entity, self))
1662 if(tmp_entity.iscaptured)
1663 if(max_dist <= 0 || distance <= max_dist)
1664 if(closest_target == world || distance <= smallest_distance )
1666 closest_target = tmp_entity;
1667 smallest_distance = distance;
1670 tmp_entity = tmp_entity.chain;
1672 tmp_entity = findchain(classname, "onslaught_generator");
1675 delta = tmp_entity.origin - pos;
1677 distance = vlen(delta);
1679 if(SAME_TEAM(tmp_entity, self))
1680 if(max_dist <= 0 || distance <= max_dist)
1681 if(closest_target == world || distance <= smallest_distance )
1683 closest_target = tmp_entity;
1684 smallest_distance = distance;
1687 tmp_entity = tmp_entity.chain;
1690 return closest_target;
1693 * find the number of control points and generators in the same team as self
1695 int ons_Count_SelfControlPoints()
1698 tmp_entity = findchain(classname, "onslaught_controlpoint");
1702 if(SAME_TEAM(tmp_entity, self))
1703 if(tmp_entity.iscaptured)
1705 tmp_entity = tmp_entity.chain;
1707 tmp_entity = findchain(classname, "onslaught_generator");
1710 if(SAME_TEAM(tmp_entity, self))
1712 tmp_entity = tmp_entity.chain;
1718 * Teleport player to a random position near tele_target
1719 * if tele_effects is true, teleport sound+particles are created
1720 * return false on failure
1722 bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effects)
1730 // narrow the range for each iteration to increase chances that a spawnpoint
1731 // can be found even if there's little room around the control point
1732 float iteration_scale = 1;
1733 for(i = 0; i < 16; ++i)
1735 iteration_scale -= i / 16;
1736 theta = random() * 2 * M_PI;
1740 loc *= random() * range * iteration_scale;
1742 loc += tele_target.origin + '0 0 128' * iteration_scale;
1744 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
1745 if(trace_fraction == 1.0 && !trace_startsolid)
1747 traceline(tele_target.origin, loc, MOVE_NOMONSTERS, tele_target); // double check to make sure we're not spawning outside the world
1748 if(trace_fraction == 1.0 && !trace_startsolid)
1752 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
1753 sound (player, CH_TRIGGER, SND_TELEPORT, VOL_BASE, ATTEN_NORM);
1755 setorigin(player, loc);
1756 player.angles = '0 1 0' * ( theta * RAD2DEG + 180 );
1757 makevectors(player.angles);
1758 player.fixangle = true;
1759 player.teleport_antispam = time + autocvar_g_onslaught_teleport_wait;
1762 Send_Effect(EFFECT_TELEPORT, player.origin + v_forward * 32, '0 0 0', 1);
1775 MUTATOR_HOOKFUNCTION(ons, reset_map_global)
1777 FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
1778 it.ons_roundlost = false;
1779 it.ons_deathloc = '0 0 0';
1780 WITH(entity, self, it, PutClientInServer());
1785 MUTATOR_HOOKFUNCTION(ons, ClientDisconnect)
1787 self.ons_deathloc = '0 0 0';
1791 MUTATOR_HOOKFUNCTION(ons, MakePlayerObserver)
1793 self.ons_deathloc = '0 0 0';
1797 MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
1799 if(!round_handler_IsRoundStarted())
1801 self.player_blocked = true;
1806 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1808 l.sprite.SendFlags |= 16;
1810 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1812 l.sprite.SendFlags |= 16;
1815 if(ons_stalemate) { Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); }
1817 if ( autocvar_g_onslaught_spawn_choose )
1818 if ( self.ons_spawn_by )
1819 if ( ons_Teleport(self,self.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) )
1821 self.ons_spawn_by = world;
1825 if(autocvar_g_onslaught_spawn_at_controlpoints)
1826 if(random() <= autocvar_g_onslaught_spawn_at_controlpoints_chance)
1828 float random_target = autocvar_g_onslaught_spawn_at_controlpoints_random;
1829 entity tmp_entity, closest_target = world;
1830 vector spawn_loc = self.ons_deathloc;
1832 // new joining player or round reset, don't bother checking
1833 if(spawn_loc == '0 0 0') { return false; }
1835 if(random_target) { RandomSelection_Init(); }
1837 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1839 if(SAME_TEAM(tmp_entity, self))
1841 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1842 else if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world)
1843 closest_target = tmp_entity;
1846 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1852 float iteration_scale = 1;
1853 for(i = 0; i < 10; ++i)
1855 iteration_scale -= i / 10;
1856 loc = closest_target.origin + '0 0 96' * iteration_scale;
1857 loc += ('0 1 0' * random()) * 128 * iteration_scale;
1858 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, self);
1859 if(trace_fraction == 1.0 && !trace_startsolid)
1861 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
1862 if(trace_fraction == 1.0 && !trace_startsolid)
1864 setorigin(self, loc);
1865 self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1873 if(autocvar_g_onslaught_spawn_at_generator)
1874 if(random() <= autocvar_g_onslaught_spawn_at_generator_chance)
1876 float random_target = autocvar_g_onslaught_spawn_at_generator_random;
1877 entity tmp_entity, closest_target = world;
1878 vector spawn_loc = self.ons_deathloc;
1880 // new joining player or round reset, don't bother checking
1881 if(spawn_loc == '0 0 0') { return false; }
1883 if(random_target) { RandomSelection_Init(); }
1885 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1888 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1891 if(SAME_TEAM(tmp_entity, self))
1892 if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world)
1893 closest_target = tmp_entity;
1897 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1903 float iteration_scale = 1;
1904 for(i = 0; i < 10; ++i)
1906 iteration_scale -= i / 10;
1907 loc = closest_target.origin + '0 0 128' * iteration_scale;
1908 loc += ('0 1 0' * random()) * 256 * iteration_scale;
1909 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, self);
1910 if(trace_fraction == 1.0 && !trace_startsolid)
1912 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
1913 if(trace_fraction == 1.0 && !trace_startsolid)
1915 setorigin(self, loc);
1916 self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1927 MUTATOR_HOOKFUNCTION(ons, PlayerDies)
1929 frag_target.ons_deathloc = frag_target.origin;
1931 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1933 l.sprite.SendFlags |= 16;
1935 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1937 l.sprite.SendFlags |= 16;
1940 if ( autocvar_g_onslaught_spawn_choose )
1941 if ( ons_Count_SelfControlPoints() > 1 )
1942 stuffcmd(self, "qc_cmd_cl hud clickradar\n");
1947 MUTATOR_HOOKFUNCTION(ons, MonsterMove)
1949 entity e = find(world, targetname, self.target);
1956 void ons_MonsterSpawn_Delayed()
1958 entity e, own = self.owner;
1960 if(!own) { remove(self); return; }
1964 e = find(world, target, own.targetname);
1977 MUTATOR_HOOKFUNCTION(ons, MonsterSpawn)
1981 InitializeEntity(e, ons_MonsterSpawn_Delayed, INITPRIO_FINDTARGET);
1986 void ons_TurretSpawn_Delayed()
1988 entity e, own = self.owner;
1990 if(!own) { remove(self); return; }
1994 e = find(world, target, own.targetname);
1998 own.active = ACTIVE_NOT;
2008 MUTATOR_HOOKFUNCTION(ons, TurretSpawn)
2012 InitializeEntity(e, ons_TurretSpawn_Delayed, INITPRIO_FINDTARGET);
2017 MUTATOR_HOOKFUNCTION(ons, HavocBot_ChooseRole)
2019 havocbot_ons_reset_role(self);
2023 MUTATOR_HOOKFUNCTION(ons, GetTeamCount)
2025 // onslaught is special
2026 for(entity tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
2028 switch(tmp_entity.team)
2030 case NUM_TEAM_1: c1 = 0; break;
2031 case NUM_TEAM_2: c2 = 0; break;
2032 case NUM_TEAM_3: c3 = 0; break;
2033 case NUM_TEAM_4: c4 = 0; break;
2040 MUTATOR_HOOKFUNCTION(ons, SpectateCopy)
2042 self.ons_roundlost = other.ons_roundlost; // make spectators see it too
2046 MUTATOR_HOOKFUNCTION(ons, SV_ParseClientCommand)
2048 if(MUTATOR_RETURNVALUE) // command was already handled?
2051 if ( cmd_name == "ons_spawn" )
2053 vector pos = self.origin;
2055 pos_x = stof(argv(1));
2057 pos_y = stof(argv(2));
2059 pos_z = stof(argv(3));
2061 if ( IS_PLAYER(self) )
2063 if ( !STAT(FROZEN, self) )
2065 entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
2067 if ( !source_point && self.health > 0 )
2069 sprint(self, "\nYou need to be next to a control point\n");
2074 entity closest_target = ons_Nearest_ControlPoint_2D(pos, autocvar_g_onslaught_click_radius);
2076 if ( closest_target == world )
2078 sprint(self, "\nNo control point found\n");
2082 if ( self.health <= 0 )
2084 self.ons_spawn_by = closest_target;
2085 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
2089 if ( source_point == closest_target )
2091 sprint(self, "\nTeleporting to the same point\n");
2095 if ( !ons_Teleport(self,closest_target,autocvar_g_onslaught_teleport_radius,true) )
2096 sprint(self, "\nUnable to teleport there\n");
2102 sprint(self, "\nNo teleportation for you\n");
2110 MUTATOR_HOOKFUNCTION(ons, PlayerUseKey)
2112 if(MUTATOR_RETURNVALUE || gameover) { return false; }
2114 if((time > self.teleport_antispam) && (!IS_DEAD(self)) && !self.vehicle)
2116 entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
2119 stuffcmd(self, "qc_cmd_cl hud clickradar\n");
2127 MUTATOR_HOOKFUNCTION(ons, PlayHitsound)
2129 return (frag_victim.classname == "onslaught_generator" && !frag_victim.isshielded)
2130 || (frag_victim.classname == "onslaught_controlpoint_icon" && !frag_victim.owner.isshielded);
2133 MUTATOR_HOOKFUNCTION(ons, SendWaypoint)
2135 if(wp_sendflags & 16)
2137 if(self.owner.classname == "onslaught_controlpoint")
2139 entity wp_owner = self.owner;
2140 entity e = WaypointSprite_getviewentity(wp_sendto);
2141 if(SAME_TEAM(e, wp_owner) && wp_owner.goalentity.health >= wp_owner.goalentity.max_health) { wp_flag |= 2; }
2142 if(!ons_ControlPoint_Attackable(wp_owner, e.team)) { wp_flag |= 2; }
2144 if(self.owner.classname == "onslaught_generator")
2146 entity wp_owner = self.owner;
2147 if(wp_owner.isshielded && wp_owner.health >= wp_owner.max_health) { wp_flag |= 2; }
2148 if(wp_owner.health <= 0) { wp_flag |= 2; }
2155 MUTATOR_HOOKFUNCTION(ons, TurretValidateTarget)
2157 if(substring(turret_target.classname, 0, 10) == "onslaught_") // don't attack onslaught targets, that's the player's job!
2166 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);