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;
127 #ifdef IMPLEMENTATION
129 #include "sv_controlpoint.qh"
130 #include "sv_generator.qh"
134 float autocvar_g_onslaught_teleport_wait;
135 bool autocvar_g_onslaught_spawn_at_controlpoints;
136 bool autocvar_g_onslaught_spawn_at_generator;
137 float autocvar_g_onslaught_cp_proxydecap;
138 float autocvar_g_onslaught_cp_proxydecap_distance = 512;
139 float autocvar_g_onslaught_cp_proxydecap_dps = 100;
140 float autocvar_g_onslaught_spawn_at_controlpoints_chance = 0.5;
141 float autocvar_g_onslaught_spawn_at_controlpoints_random;
142 float autocvar_g_onslaught_spawn_at_generator_chance;
143 float autocvar_g_onslaught_spawn_at_generator_random;
144 float autocvar_g_onslaught_cp_buildhealth;
145 float autocvar_g_onslaught_cp_buildtime;
146 float autocvar_g_onslaught_cp_health;
147 float autocvar_g_onslaught_cp_regen;
148 float autocvar_g_onslaught_gen_health;
149 float autocvar_g_onslaught_shield_force = 100;
150 float autocvar_g_onslaught_allow_vehicle_touch;
151 float autocvar_g_onslaught_round_timelimit;
152 float autocvar_g_onslaught_warmup;
153 float autocvar_g_onslaught_teleport_radius;
154 float autocvar_g_onslaught_spawn_choose;
155 float autocvar_g_onslaught_click_radius;
157 void FixSize(entity e);
159 // =======================
160 // CaptureShield Functions
161 // =======================
163 bool ons_CaptureShield_Customize()
165 entity e = WaypointSprite_getviewentity(other);
167 if(!self.enemy.isshielded && (ons_ControlPoint_Attackable(self.enemy, e.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return false; }
168 if(SAME_TEAM(self, e)) { return false; }
173 void ons_CaptureShield_Touch()
175 if(!self.enemy.isshielded && (ons_ControlPoint_Attackable(self.enemy, other.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return; }
176 if(!IS_PLAYER(other)) { return; }
177 if(SAME_TEAM(other, self)) { return; }
179 vector mymid = (self.absmin + self.absmax) * 0.5;
180 vector othermid = (other.absmin + other.absmax) * 0.5;
182 Damage(other, self, self, 0, DEATH_HURTTRIGGER.m_id, mymid, normalize(othermid - mymid) * ons_captureshield_force);
184 if(IS_REAL_CLIENT(other))
186 play2(other, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
188 if(self.enemy.classname == "onslaught_generator")
189 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_GENERATOR_SHIELDED);
191 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_CONTROLPOINT_SHIELDED);
195 void ons_CaptureShield_Reset(entity this)
197 this.colormap = this.enemy.colormap;
198 this.team = this.enemy.team;
201 void ons_CaptureShield_Spawn(entity generator, bool is_generator)
203 entity shield = new(ons_captureshield);
205 shield.enemy = generator;
206 shield.team = generator.team;
207 shield.colormap = generator.colormap;
208 shield.reset = ons_CaptureShield_Reset;
209 shield.touch = ons_CaptureShield_Touch;
210 shield.customizeentityforclient = ons_CaptureShield_Customize;
211 shield.effects = EF_ADDITIVE;
212 shield.movetype = MOVETYPE_NOCLIP;
213 shield.solid = SOLID_TRIGGER;
214 shield.avelocity = '7 0 11';
216 shield.model = ((is_generator) ? "models/onslaught/generator_shield.md3" : "models/onslaught/controlpoint_shield.md3");
218 precache_model(shield.model);
219 setorigin(shield, generator.origin);
220 _setmodel(shield, shield.model);
221 setsize(shield, shield.scale * shield.mins, shield.scale * shield.maxs);
229 void setmodel_fixsize(entity e, Model m)
235 void onslaught_updatelinks()
238 // first check if the game has ended
239 LOG_DEBUG("--- updatelinks ---\n");
240 // mark generators as being shielded and networked
241 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
244 LOG_DEBUG(strcat(etos(l), " (generator) belongs to team ", ftos(l.team), "\n"));
246 LOG_DEBUG(strcat(etos(l), " (generator) is destroyed\n"));
247 l.islinked = l.iscaptured;
248 l.isshielded = l.iscaptured;
249 l.sprite.SendFlags |= 16;
251 // mark points as shielded and not networked
252 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
257 for(i = 0; i < 17; ++i) { l.isgenneighbor[i] = false; l.iscpneighbor[i] = false; }
258 LOG_DEBUG(strcat(etos(l), " (point) belongs to team ", ftos(l.team), "\n"));
259 l.sprite.SendFlags |= 16;
261 // flow power outward from the generators through the network
266 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
268 // if both points are captured by the same team, and only one of
269 // them is powered, mark the other one as powered as well
270 if (l.enemy.iscaptured && l.goalentity.iscaptured)
271 if (l.enemy.islinked != l.goalentity.islinked)
272 if(SAME_TEAM(l.enemy, l.goalentity))
274 if (!l.goalentity.islinked)
277 l.goalentity.islinked = true;
278 LOG_DEBUG(strcat(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)\n"));
280 else if (!l.enemy.islinked)
283 l.enemy.islinked = true;
284 LOG_DEBUG(strcat(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)\n"));
289 // now that we know which points are powered we can mark their neighbors
290 // as unshielded if team differs
291 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
293 if (l.goalentity.islinked)
295 if(DIFF_TEAM(l.goalentity, l.enemy))
297 LOG_DEBUG(strcat(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)\n"));
298 l.enemy.isshielded = false;
300 if(l.goalentity.classname == "onslaught_generator")
301 l.enemy.isgenneighbor[l.goalentity.team] = true;
303 l.enemy.iscpneighbor[l.goalentity.team] = true;
305 if (l.enemy.islinked)
307 if(DIFF_TEAM(l.goalentity, l.enemy))
309 LOG_DEBUG(strcat(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)\n"));
310 l.goalentity.isshielded = false;
312 if(l.enemy.classname == "onslaught_generator")
313 l.goalentity.isgenneighbor[l.enemy.team] = true;
315 l.goalentity.iscpneighbor[l.enemy.team] = true;
318 // now update the generators
319 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
323 LOG_DEBUG(strcat(etos(l), " (generator) is shielded\n"));
324 l.takedamage = DAMAGE_NO;
325 l.bot_attack = false;
329 LOG_DEBUG(strcat(etos(l), " (generator) is not shielded\n"));
330 l.takedamage = DAMAGE_AIM;
334 ons_Generator_UpdateSprite(l);
336 // now update the takedamage and alpha variables on control point icons
337 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
341 LOG_DEBUG(strcat(etos(l), " (point) is shielded\n"));
344 l.goalentity.takedamage = DAMAGE_NO;
345 l.goalentity.bot_attack = false;
350 LOG_DEBUG(strcat(etos(l), " (point) is not shielded\n"));
353 l.goalentity.takedamage = DAMAGE_AIM;
354 l.goalentity.bot_attack = true;
357 ons_ControlPoint_UpdateSprite(l);
359 l = findchain(classname, "ons_captureshield");
362 l.team = l.enemy.team;
363 l.colormap = l.enemy.colormap;
369 // ===================
370 // Main Link Functions
371 // ===================
373 bool ons_Link_Send(entity this, entity to, int sendflags)
375 WriteHeader(MSG_ENTITY, ENT_CLIENT_RADARLINK);
376 WriteByte(MSG_ENTITY, sendflags);
379 WriteCoord(MSG_ENTITY, self.goalentity.origin_x);
380 WriteCoord(MSG_ENTITY, self.goalentity.origin_y);
381 WriteCoord(MSG_ENTITY, self.goalentity.origin_z);
385 WriteCoord(MSG_ENTITY, self.enemy.origin_x);
386 WriteCoord(MSG_ENTITY, self.enemy.origin_y);
387 WriteCoord(MSG_ENTITY, self.enemy.origin_z);
391 WriteByte(MSG_ENTITY, self.clientcolors); // which is goalentity's color + enemy's color * 16
396 void ons_Link_CheckUpdate()
398 // TODO check if the two sides have moved (currently they won't move anyway)
399 float cc = 0, cc1 = 0, cc2 = 0;
401 if(self.goalentity.islinked || self.goalentity.iscaptured) { cc1 = (self.goalentity.team - 1) * 0x01; }
402 if(self.enemy.islinked || self.enemy.iscaptured) { cc2 = (self.enemy.team - 1) * 0x10; }
406 if(cc != self.clientcolors)
408 self.clientcolors = cc;
412 self.nextthink = time;
415 void ons_DelayedLinkSetup(entity this)
417 self.goalentity = find(world, targetname, self.target);
418 self.enemy = find(world, targetname, self.target2);
419 if(!self.goalentity) { objerror("can not find target\n"); }
420 if(!self.enemy) { objerror("can not find target2\n"); }
422 LOG_DEBUG(strcat(etos(self.goalentity), " linked with ", etos(self.enemy), "\n"));
424 self.think = ons_Link_CheckUpdate;
425 self.nextthink = time;
429 // =============================
430 // Main Control Point Functions
431 // =============================
433 int ons_ControlPoint_CanBeLinked(entity cp, int teamnumber)
435 if(cp.isgenneighbor[teamnumber]) { return 2; }
436 if(cp.iscpneighbor[teamnumber]) { return 1; }
441 int ons_ControlPoint_Attackable(entity cp, int teamnumber)
442 // -2: SAME TEAM, attackable by enemy!
447 // 3: attack it (HIGH PRIO)
448 // 4: touch it (HIGH PRIO)
456 else if(cp.goalentity)
458 // if there's already an icon built, nothing happens
459 if(cp.team == teamnumber)
461 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
462 if(a) // attackable by enemy?
463 return -2; // EMERGENCY!
466 // we know it can be linked, so no need to check
468 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
469 if(a == 2) // near our generator?
470 return 3; // EMERGENCY!
476 if(ons_ControlPoint_CanBeLinked(cp, teamnumber))
478 a = ons_ControlPoint_CanBeLinked(cp, teamnumber); // why was this here NUM_TEAM_1 + NUM_TEAM_2 - t
480 return 4; // GET THIS ONE NOW!
482 return 2; // TOUCH ME
488 void ons_ControlPoint_Icon_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
490 if(damage <= 0) { return; }
492 if (this.owner.isshielded)
494 // this is protected by a shield, so ignore the damage
495 if (time > this.pain_finished)
496 if (IS_PLAYER(attacker))
498 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
499 this.pain_finished = time + 1;
500 attacker.typehitsound += 1; // play both sounds (shield is way too quiet)
506 if(IS_PLAYER(attacker))
507 if(time - ons_notification_time[this.team] > 10)
509 play2team(this.team, SND(ONS_CONTROLPOINT_UNDERATTACK));
510 ons_notification_time[this.team] = time;
513 this.health = this.health - damage;
514 if(this.owner.iscaptured)
515 WaypointSprite_UpdateHealth(this.owner.sprite, this.health);
517 WaypointSprite_UpdateBuildFinished(this.owner.sprite, time + (this.max_health - this.health) / (this.count / ONS_CP_THINKRATE));
518 this.pain_finished = time + 1;
519 // particles on every hit
520 pointparticles(EFFECT_SPARKS, hitloc, force*-1, 1);
523 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE+0.3, ATTEN_NORM);
525 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE+0.3, ATTEN_NORM);
529 sound(this, CH_TRIGGER, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
530 pointparticles(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
531 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_CPDESTROYED), this.owner.message, attacker.netname);
533 PlayerScore_Add(attacker, SP_ONS_TAKES, 1);
534 PlayerScore_Add(attacker, SP_SCORE, 10);
536 this.owner.goalentity = world;
537 this.owner.islinked = false;
538 this.owner.iscaptured = false;
540 this.owner.colormap = 1024;
542 WaypointSprite_UpdateMaxHealth(this.owner.sprite, 0);
544 onslaught_updatelinks();
546 // Use targets now (somebody make sure this is in the right place..)
549 WITHSELF(this, SUB_UseTargets());
552 this.owner.waslinked = this.owner.islinked;
553 if(this.owner.model != "models/onslaught/controlpoint_pad.md3")
554 setmodel_fixsize(this.owner, MDL_ONS_CP_PAD1);
555 //setsize(this, '-32 -32 0', '32 32 8');
560 this.SendFlags |= CPSF_STATUS;
563 void ons_ControlPoint_Icon_Think()
565 self.nextthink = time + ONS_CP_THINKRATE;
567 if(autocvar_g_onslaught_cp_proxydecap)
569 int _enemy_count = 0;
570 int _friendly_count = 0;
572 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it), {
573 if(vdist(it.origin - self.origin, <, autocvar_g_onslaught_cp_proxydecap_distance))
575 if(SAME_TEAM(it, self))
582 _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
583 _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
585 self.health = bound(0, self.health + (_friendly_count - _enemy_count), self.max_health);
586 self.SendFlags |= CPSF_STATUS;
589 ons_ControlPoint_Icon_Damage(self, self, self, 1, 0, self.origin, '0 0 0');
594 if (time > self.pain_finished + 5)
596 if(self.health < self.max_health)
598 self.health = self.health + self.count;
599 if (self.health >= self.max_health)
600 self.health = self.max_health;
601 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
605 if(self.owner.islinked != self.owner.waslinked)
607 // unteam the spawnpoint if needed
608 int t = self.owner.team;
609 if(!self.owner.islinked)
619 self.owner.waslinked = self.owner.islinked;
623 if(random() < 0.6 - self.health / self.max_health)
625 Send_Effect(EFFECT_ELECTRIC_SPARKS, self.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
628 sound(self, CH_PAIN, SND_ONS_SPARK1, VOL_BASE, ATTEN_NORM);
629 else if (random() > 0.5)
630 sound(self, CH_PAIN, SND_ONS_SPARK2, VOL_BASE, ATTEN_NORM);
634 void ons_ControlPoint_Icon_BuildThink()
638 self.nextthink = time + ONS_CP_THINKRATE;
640 // only do this if there is power
641 a = ons_ControlPoint_CanBeLinked(self.owner, self.owner.team);
645 self.health = self.health + self.count;
647 self.SendFlags |= CPSF_STATUS;
649 if (self.health >= self.max_health)
651 self.health = self.max_health;
652 self.count = autocvar_g_onslaught_cp_regen * ONS_CP_THINKRATE; // slow repair rate from now on
653 self.think = ons_ControlPoint_Icon_Think;
654 sound(self, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILT, VOL_BASE, ATTEN_NORM);
655 self.owner.iscaptured = true;
656 self.solid = SOLID_BBOX;
658 Send_Effect(EFFECT_CAP(self.owner.team), self.owner.origin, '0 0 0', 1);
660 WaypointSprite_UpdateMaxHealth(self.owner.sprite, self.max_health);
661 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
663 if(IS_PLAYER(self.owner.ons_toucher))
665 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ONSLAUGHT_CAPTURE, self.owner.ons_toucher.netname, self.owner.message);
666 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);
667 Send_Notification(NOTIF_ONE, self.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE, self.owner.message);
668 PlayerScore_Add(self.owner.ons_toucher, SP_ONS_CAPS, 1);
669 PlayerTeamScore_AddScore(self.owner.ons_toucher, 10);
672 self.owner.ons_toucher = world;
674 onslaught_updatelinks();
676 // Use targets now (somebody make sure this is in the right place..)
682 self.SendFlags |= CPSF_SETUP;
684 if(self.owner.model != MDL_ONS_CP_PAD2.model_str())
685 setmodel_fixsize(self.owner, MDL_ONS_CP_PAD2);
687 if(random() < 0.9 - self.health / self.max_health)
688 Send_Effect(EFFECT_RAGE, self.origin + 10 * randomvec(), '0 0 -1', 1);
691 void onslaught_controlpoint_icon_link(entity e, void() spawnproc);
693 void ons_ControlPoint_Icon_Spawn(entity cp, entity player)
695 entity e = new(onslaught_controlpoint_icon);
697 setsize(e, CPICON_MIN, CPICON_MAX);
698 setorigin(e, cp.origin + CPICON_OFFSET);
701 e.max_health = autocvar_g_onslaught_cp_health;
702 e.health = autocvar_g_onslaught_cp_buildhealth;
704 e.takedamage = DAMAGE_AIM;
706 e.event_damage = ons_ControlPoint_Icon_Damage;
707 e.team = player.team;
708 e.colormap = 1024 + (e.team - 1) * 17;
709 e.count = (e.max_health - e.health) * ONS_CP_THINKRATE / autocvar_g_onslaught_cp_buildtime; // how long it takes to build
711 sound(e, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILD, VOL_BASE, ATTEN_NORM);
715 cp.colormap = e.colormap;
717 Send_Effect(EFFECT_FLAG_TOUCH(player.team), e.origin, '0 0 0', 1);
719 WaypointSprite_UpdateBuildFinished(cp.sprite, time + (e.max_health - e.health) / (e.count / ONS_CP_THINKRATE));
720 WaypointSprite_UpdateRule(cp.sprite,cp.team,SPRITERULE_TEAMPLAY);
721 cp.sprite.SendFlags |= 16;
723 onslaught_controlpoint_icon_link(e, ons_ControlPoint_Icon_BuildThink);
726 entity ons_ControlPoint_Waypoint(entity e)
730 int a = ons_ControlPoint_Attackable(e, e.team);
732 if(a == -2) { return WP_OnsCPDefend; } // defend now
733 if(a == -1 || a == 1 || a == 2) { return WP_OnsCP; } // touch
734 if(a == 3 || a == 4) { return WP_OnsCPAttack; } // attack
742 void ons_ControlPoint_UpdateSprite(entity e)
744 entity s1 = ons_ControlPoint_Waypoint(e);
745 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
748 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));
750 if(e.lastteam != e.team + 2 || e.lastshielded != sh || e.iscaptured != e.lastcaptured)
752 if(e.iscaptured) // don't mess up build bars!
756 WaypointSprite_UpdateMaxHealth(e.sprite, 0);
760 WaypointSprite_UpdateMaxHealth(e.sprite, e.goalentity.max_health);
761 WaypointSprite_UpdateHealth(e.sprite, e.goalentity.health);
767 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, false));
769 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
774 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, false));
776 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
778 WaypointSprite_Ping(e.sprite);
780 e.lastteam = e.team + 2;
782 e.lastcaptured = e.iscaptured;
786 void ons_ControlPoint_Touch()
788 entity toucher = other;
791 if(IS_VEHICLE(toucher) && toucher.owner)
792 if(autocvar_g_onslaught_allow_vehicle_touch)
793 toucher = toucher.owner;
797 if(!IS_PLAYER(toucher)) { return; }
798 if(STAT(FROZEN, toucher)) { return; }
799 if(IS_DEAD(toucher)) { return; }
801 if ( SAME_TEAM(self,toucher) )
802 if ( self.iscaptured )
804 if(time <= toucher.teleport_antispam)
805 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT_ANTISPAM, rint(toucher.teleport_antispam - time));
807 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
810 attackable = ons_ControlPoint_Attackable(self, toucher.team);
811 if(attackable != 2 && attackable != 4)
813 // we've verified that this player has a legitimate claim to this point,
814 // so start building the captured point icon (which only captures this
815 // point if it successfully builds without being destroyed first)
816 ons_ControlPoint_Icon_Spawn(self, toucher);
818 self.ons_toucher = toucher;
820 onslaught_updatelinks();
823 void ons_ControlPoint_Think()
825 self.nextthink = time + ONS_CP_THINKRATE;
826 CSQCMODEL_AUTOUPDATE(self);
829 void ons_ControlPoint_Reset(entity this)
832 remove(this.goalentity);
834 this.goalentity = world;
836 this.colormap = 1024;
837 this.iscaptured = false;
838 this.islinked = false;
839 this.isshielded = true;
840 this.think = ons_ControlPoint_Think;
841 this.ons_toucher = world;
842 this.nextthink = time + ONS_CP_THINKRATE;
843 setmodel_fixsize(this, MDL_ONS_CP_PAD1);
845 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
846 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
848 onslaught_updatelinks();
851 SUB_UseTargets(); // to reset the structures, playerspawns etc.
853 CSQCMODEL_AUTOUPDATE(this);
856 void ons_DelayedControlPoint_Setup(entity this)
858 onslaught_updatelinks();
860 // captureshield setup
861 ons_CaptureShield_Spawn(self, false);
863 CSQCMODEL_AUTOINIT(self);
866 void ons_ControlPoint_Setup(entity cp)
869 setself(cp); // for later usage with droptofloor()
872 cp.ons_worldcpnext = ons_worldcplist; // link control point into ons_worldcplist
873 ons_worldcplist = cp;
875 cp.netname = "Control point";
877 cp.solid = SOLID_BBOX;
878 cp.movetype = MOVETYPE_NONE;
879 cp.touch = ons_ControlPoint_Touch;
880 cp.think = ons_ControlPoint_Think;
881 cp.nextthink = time + ONS_CP_THINKRATE;
882 cp.reset = ons_ControlPoint_Reset;
884 cp.iscaptured = false;
886 cp.isshielded = true;
888 if(cp.message == "") { cp.message = "a"; }
891 setmodel_fixsize(cp, MDL_ONS_CP_PAD1);
893 // control point placement
894 if((cp.spawnflags & 1) || cp.noalign) // don't drop to floor, just stay at fixed location
897 cp.movetype = MOVETYPE_NONE;
899 else // drop to floor, automatically find a platform and set that as spawn origin
901 setorigin(cp, cp.origin + '0 0 20');
905 cp.movetype = MOVETYPE_TOSS;
909 WaypointSprite_SpawnFixed(WP_Null, self.origin + CPGEN_WAYPOINT_OFFSET, self, sprite, RADARICON_NONE);
910 WaypointSprite_UpdateRule(self.sprite, self.team, SPRITERULE_TEAMPLAY);
912 InitializeEntity(cp, ons_DelayedControlPoint_Setup, INITPRIO_SETLOCATION);
916 // =========================
917 // Main Generator Functions
918 // =========================
920 entity ons_Generator_Waypoint(entity e)
923 return WP_OnsGenShielded;
927 void ons_Generator_UpdateSprite(entity e)
929 entity s1 = ons_Generator_Waypoint(e);
930 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
932 if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
934 e.lastteam = e.team + 2;
935 e.lastshielded = e.isshielded;
939 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, false));
941 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
946 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, false));
948 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
950 WaypointSprite_Ping(e.sprite);
954 void ons_GeneratorDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
956 if(damage <= 0) { return; }
957 if(warmup_stage || gameover) { return; }
958 if(!round_handler_IsRoundStarted()) { return; }
960 if (attacker != this)
964 // this is protected by a shield, so ignore the damage
965 if (time > this.pain_finished)
966 if (IS_PLAYER(attacker))
968 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
969 attacker.typehitsound += 1;
970 this.pain_finished = time + 1;
974 if (time > this.pain_finished)
976 this.pain_finished = time + 10;
977 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && SAME_TEAM(it, this), Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK));
978 play2team(this.team, SND(ONS_GENERATOR_UNDERATTACK));
981 this.health = this.health - damage;
982 WaypointSprite_UpdateHealth(this.sprite, this.health);
983 // choose an animation frame based on health
984 this.frame = 10 * bound(0, (1 - this.health / this.max_health), 1);
985 // see if the generator is still functional, or dying
988 this.lasthealth = this.health;
992 if (attacker == this)
993 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME));
996 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED));
997 PlayerScore_Add(attacker, SP_SCORE, 100);
999 this.iscaptured = false;
1000 this.islinked = false;
1001 this.isshielded = false;
1002 this.takedamage = DAMAGE_NO; // can't be hurt anymore
1003 this.event_damage = func_null; // won't do anything if hurt
1004 this.count = 0; // reset counter
1005 this.think = func_null;
1007 //this.think(); // do the first explosion now
1009 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
1010 WaypointSprite_Ping(this.sprite);
1011 //WaypointSprite_Kill(this.sprite); // can't do this yet, code too poor
1013 onslaught_updatelinks();
1016 // Throw some flaming gibs on damage, more damage = more chance for gib
1017 if(random() < damage/220)
1019 sound(this, CH_TRIGGER, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
1023 // particles on every hit
1024 Send_Effect(EFFECT_SPARKS, hitloc, force * -1, 1);
1026 //sound on every hit
1028 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE, ATTEN_NORM);
1030 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE, ATTEN_NORM);
1033 this.SendFlags |= GSF_STATUS;
1036 void ons_GeneratorThink()
1038 self.nextthink = time + GEN_THINKRATE;
1041 if(!self.isshielded && self.wait < time)
1043 self.wait = time + 5;
1044 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
1045 if(SAME_TEAM(it, self))
1047 Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM);
1048 soundto(MSG_ONE, it, CHAN_AUTO, SND(KH_ALARM), VOL_BASE, ATTEN_NONE); // FIXME: unique sound?
1051 Send_Notification(NOTIF_ONE, it, MSG_CENTER, APP_TEAM_NUM(self.team, CENTER_ONS_NOTSHIELDED));
1057 void ons_GeneratorReset(entity this)
1059 this.team = this.team_saved;
1060 this.lasthealth = this.max_health = this.health = autocvar_g_onslaught_gen_health;
1061 this.takedamage = DAMAGE_AIM;
1062 this.bot_attack = true;
1063 this.iscaptured = true;
1064 this.islinked = true;
1065 this.isshielded = true;
1066 this.event_damage = ons_GeneratorDamage;
1067 this.think = ons_GeneratorThink;
1068 this.nextthink = time + GEN_THINKRATE;
1070 Net_LinkEntity(this, false, 0, generator_send);
1072 this.SendFlags = GSF_SETUP; // just incase
1073 this.SendFlags |= GSF_STATUS;
1075 WaypointSprite_UpdateMaxHealth(this.sprite, this.max_health);
1076 WaypointSprite_UpdateHealth(this.sprite, this.health);
1077 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
1079 onslaught_updatelinks();
1082 void ons_DelayedGeneratorSetup(entity this)
1085 waypoint_spawnforitem_force(self, self.origin);
1086 self.nearestwaypointtimeout = 0; // activate waypointing again
1087 self.bot_basewaypoint = self.nearestwaypoint;
1089 // captureshield setup
1090 ons_CaptureShield_Spawn(self, true);
1092 onslaught_updatelinks();
1094 Net_LinkEntity(self, false, 0, generator_send);
1098 void onslaught_generator_touch()
1100 if ( IS_PLAYER(other) )
1101 if ( SAME_TEAM(self,other) )
1102 if ( self.iscaptured )
1104 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_TELEPORT);
1108 void ons_GeneratorSetup(entity gen) // called when spawning a generator entity on the map as a spawnfunc
1111 int teamnumber = gen.team;
1112 setself(gen); // for later usage with droptofloor()
1115 gen.ons_worldgeneratornext = ons_worldgeneratorlist; // link generator into ons_worldgeneratorlist
1116 ons_worldgeneratorlist = gen;
1118 gen.netname = sprintf("%s generator", Team_ColoredFullName(teamnumber));
1119 gen.classname = "onslaught_generator";
1120 gen.solid = SOLID_BBOX;
1121 gen.team_saved = teamnumber;
1122 gen.movetype = MOVETYPE_NONE;
1123 gen.lasthealth = gen.max_health = gen.health = autocvar_g_onslaught_gen_health;
1124 gen.takedamage = DAMAGE_AIM;
1125 gen.bot_attack = true;
1126 gen.event_damage = ons_GeneratorDamage;
1127 gen.reset = ons_GeneratorReset;
1128 gen.think = ons_GeneratorThink;
1129 gen.nextthink = time + GEN_THINKRATE;
1130 gen.iscaptured = true;
1131 gen.islinked = true;
1132 gen.isshielded = true;
1133 gen.touch = onslaught_generator_touch;
1136 // model handled by CSQC
1137 setsize(gen, GENERATOR_MIN, GENERATOR_MAX);
1138 setorigin(gen, (gen.origin + CPGEN_SPAWN_OFFSET));
1139 gen.colormap = 1024 + (teamnumber - 1) * 17;
1141 // generator placement
1146 WaypointSprite_SpawnFixed(WP_Null, self.origin + CPGEN_WAYPOINT_OFFSET, self, sprite, RADARICON_NONE);
1147 WaypointSprite_UpdateRule(self.sprite, self.team, SPRITERULE_TEAMPLAY);
1148 WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
1149 WaypointSprite_UpdateHealth(self.sprite, self.health);
1151 InitializeEntity(gen, ons_DelayedGeneratorSetup, INITPRIO_SETLOCATION);
1159 int total_generators;
1160 void Onslaught_count_generators()
1163 total_generators = redowned = blueowned = yellowowned = pinkowned = 0;
1164 for(e = ons_worldgeneratorlist; e; e = e.ons_worldgeneratornext)
1167 redowned += (e.team == NUM_TEAM_1 && e.health > 0);
1168 blueowned += (e.team == NUM_TEAM_2 && e.health > 0);
1169 yellowowned += (e.team == NUM_TEAM_3 && e.health > 0);
1170 pinkowned += (e.team == NUM_TEAM_4 && e.health > 0);
1174 int Onslaught_GetWinnerTeam()
1176 int winner_team = 0;
1178 winner_team = NUM_TEAM_1;
1181 if(winner_team) return 0;
1182 winner_team = NUM_TEAM_2;
1186 if(winner_team) return 0;
1187 winner_team = NUM_TEAM_3;
1191 if(winner_team) return 0;
1192 winner_team = NUM_TEAM_4;
1196 return -1; // no generators left?
1199 void nades_Clear(entity e);
1201 #define ONS_OWNED_GENERATORS() ((redowned > 0) + (blueowned > 0) + (yellowowned > 0) + (pinkowned > 0))
1202 #define ONS_OWNED_GENERATORS_OK() (ONS_OWNED_GENERATORS() > 1)
1203 bool Onslaught_CheckWinner()
1205 if ((autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60) || (round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0))
1207 ons_stalemate = true;
1209 if (!wpforenemy_announced)
1211 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT);
1212 sound(world, CH_INFO, SND_ONS_GENERATOR_DECAY, VOL_BASE, ATTEN_NONE);
1214 wpforenemy_announced = true;
1217 entity tmp_entity; // temporary entity
1219 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext) if(time >= tmp_entity.ons_overtime_damagedelay)
1221 // tmp_entity.max_health / 300 gives 5 minutes of overtime.
1222 // control points reduce the overtime duration.
1225 for(e = ons_worldcplist; e; e = e.ons_worldcpnext)
1227 if(DIFF_TEAM(e, tmp_entity))
1232 if(autocvar_g_campaign && autocvar__campaign_testrun)
1233 d = d * tmp_entity.max_health;
1235 d = d * tmp_entity.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
1237 Damage(tmp_entity, tmp_entity, tmp_entity, d, DEATH_HURTTRIGGER.m_id, tmp_entity.origin, '0 0 0');
1239 tmp_entity.sprite.SendFlags |= 16;
1241 tmp_entity.ons_overtime_damagedelay = time + 1;
1244 else { wpforenemy_announced = false; ons_stalemate = false; }
1246 Onslaught_count_generators();
1248 if(ONS_OWNED_GENERATORS_OK())
1251 int winner_team = Onslaught_GetWinnerTeam();
1255 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
1256 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
1257 TeamScore_AddToTeam(winner_team, ST_ONS_CAPS, +1);
1259 else if(winner_team == -1)
1261 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
1262 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
1265 ons_stalemate = false;
1267 play2all(SND(CTF_CAPTURE(winner_team)));
1269 round_handler_Init(7, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
1271 FOREACH_CLIENT(IS_PLAYER(it), {
1272 it.ons_roundlost = true;
1273 it.player_blocked = true;
1281 bool Onslaught_CheckPlayers()
1286 void Onslaught_RoundStart()
1289 FOREACH_CLIENT(IS_PLAYER(it), it.player_blocked = false);
1291 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1292 tmp_entity.sprite.SendFlags |= 16;
1294 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1295 tmp_entity.sprite.SendFlags |= 16;
1303 // NOTE: LEGACY CODE, needs to be re-written!
1305 void havocbot_goalrating_ons_offenseitems(entity this, float ratingscale, vector org, float sradius)
1309 bool needarmor = false, needweapons = false;
1311 // Needs armor/health?
1317 FOREACH(Weapons, it != WEP_Null, {
1318 if(this.weapons & (it.m_wepset))
1326 if(!needweapons && !needarmor)
1329 LOG_DEBUG(strcat(this.netname, " needs weapons ", ftos(needweapons) , "\n"));
1330 LOG_DEBUG(strcat(this.netname, " needs armor ", ftos(needarmor) , "\n"));
1332 // See what is around
1333 head = findchainfloat(bot_pickup, true);
1336 // gather health and armor only
1338 if ( ((head.health || head.armorvalue) && needarmor) || (head.weapons && needweapons ) )
1339 if (vlen(head.origin - org) < sradius)
1341 t = head.bot_pickupevalfunc(this, head);
1343 navigation_routerating(this, head, t * ratingscale, 500);
1349 void havocbot_role_ons_setrole(entity this, int role)
1351 LOG_DEBUG(strcat(this.netname," switched to "));
1354 case HAVOCBOT_ONS_ROLE_DEFENSE:
1355 LOG_DEBUG("defense");
1356 this.havocbot_role = havocbot_role_ons_defense;
1357 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE;
1358 this.havocbot_role_timeout = 0;
1360 case HAVOCBOT_ONS_ROLE_ASSISTANT:
1361 LOG_DEBUG("assistant");
1362 this.havocbot_role = havocbot_role_ons_assistant;
1363 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT;
1364 this.havocbot_role_timeout = 0;
1366 case HAVOCBOT_ONS_ROLE_OFFENSE:
1367 LOG_DEBUG("offense");
1368 this.havocbot_role = havocbot_role_ons_offense;
1369 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE;
1370 this.havocbot_role_timeout = 0;
1376 void havocbot_goalrating_ons_controlpoints_attack(entity this, float ratingscale)
1378 entity cp, cp1, cp2, best, wp;
1379 float radius, bestvalue;
1383 // Filter control points
1384 for(cp2 = ons_worldcplist; cp2; cp2 = cp2.ons_worldcpnext)
1387 cp2.wpconsidered = false;
1392 // Ignore owned controlpoints
1393 if(!(cp2.isgenneighbor[this.team] || cp2.iscpneighbor[this.team]))
1396 // Count team mates interested in this control point
1397 // (easier and cleaner than keeping counters per cp and teams)
1398 FOREACH_CLIENT(IS_PLAYER(it), {
1399 if(SAME_TEAM(it, this))
1400 if(it.havocbot_role_flags & HAVOCBOT_ONS_ROLE_OFFENSE)
1401 if(it.havocbot_ons_target == cp2)
1405 // NOTE: probably decrease the cost of attackable control points
1407 cp2.wpconsidered = true;
1410 // We'll consider only the best case
1411 bestvalue = 99999999999;
1413 for(cp1 = ons_worldcplist; cp1; cp1 = cp1.ons_worldcpnext)
1415 if (!cp1.wpconsidered)
1418 if(cp1.wpcost<bestvalue)
1420 bestvalue = cp1.wpcost;
1422 this.havocbot_ons_target = cp1;
1429 LOG_DEBUG(strcat(this.netname, " chose cp ranked ", ftos(bestvalue), "\n"));
1433 // Should be attacked
1434 // Rate waypoints near it
1437 bestvalue = 99999999999;
1438 for(radius=0; radius<1000 && !found; radius+=500)
1440 for(wp=findradius(cp.origin,radius); wp; wp=wp.chain)
1442 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
1443 if(wp.classname=="waypoint")
1444 if(checkpvs(wp.origin,cp))
1447 if(wp.cnt<bestvalue)
1458 navigation_routerating(this, best, ratingscale, 10000);
1461 this.havocbot_attack_time = 0;
1462 if(checkpvs(this.view_ofs,cp))
1463 if(checkpvs(this.view_ofs,best))
1464 this.havocbot_attack_time = time + 2;
1468 navigation_routerating(this, cp, ratingscale, 10000);
1470 LOG_DEBUG(strcat(this.netname, " found an attackable controlpoint at ", vtos(cp.origin) ,"\n"));
1474 // Should be touched
1475 LOG_DEBUG(strcat(this.netname, " found a touchable controlpoint at ", vtos(cp.origin) ,"\n"));
1478 // Look for auto generated waypoint
1479 if (!bot_waypoints_for_items)
1480 for (wp = findradius(cp.origin,100); wp; wp = wp.chain)
1482 if(wp.classname=="waypoint")
1484 navigation_routerating(this, wp, ratingscale, 10000);
1489 // Nothing found, rate the controlpoint itself
1491 navigation_routerating(this, cp, ratingscale, 10000);
1495 bool havocbot_goalrating_ons_generator_attack(entity this, float ratingscale)
1497 entity g, wp, bestwp;
1501 for(g = ons_worldgeneratorlist; g; g = g.ons_worldgeneratornext)
1503 if(SAME_TEAM(g, this) || g.isshielded)
1506 // Should be attacked
1507 // Rate waypoints near it
1512 for(wp=findradius(g.origin,400); wp; wp=wp.chain)
1514 if(wp.classname=="waypoint")
1515 if(checkpvs(wp.origin,g))
1528 LOG_DEBUG("waypoints found around generator\n");
1529 navigation_routerating(this, bestwp, ratingscale, 10000);
1532 this.havocbot_attack_time = 0;
1533 if(checkpvs(this.view_ofs,g))
1534 if(checkpvs(this.view_ofs,bestwp))
1535 this.havocbot_attack_time = time + 5;
1541 LOG_DEBUG("generator found without waypoints around\n");
1542 // if there aren't waypoints near the generator go straight to it
1543 navigation_routerating(this, g, ratingscale, 10000);
1544 this.havocbot_attack_time = 0;
1551 void havocbot_role_ons_offense(entity this)
1555 this.havocbot_attack_time = 0;
1556 havocbot_ons_reset_role(this);
1560 // Set the role timeout if necessary
1561 if (!this.havocbot_role_timeout)
1562 this.havocbot_role_timeout = time + 120;
1564 if (time > this.havocbot_role_timeout)
1566 havocbot_ons_reset_role(this);
1570 if(this.havocbot_attack_time>time)
1573 if (this.bot_strategytime < time)
1575 navigation_goalrating_start(this);
1576 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
1577 if(!havocbot_goalrating_ons_generator_attack(this, 20000))
1578 havocbot_goalrating_ons_controlpoints_attack(this, 20000);
1579 havocbot_goalrating_ons_offenseitems(this, 10000, this.origin, 10000);
1580 navigation_goalrating_end(this);
1582 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
1586 void havocbot_role_ons_assistant(entity this)
1588 havocbot_ons_reset_role(this);
1591 void havocbot_role_ons_defense(entity this)
1593 havocbot_ons_reset_role(this);
1596 void havocbot_ons_reset_role(entity this)
1601 this.havocbot_ons_target = world;
1603 // TODO: Defend control points or generator if necessary
1605 havocbot_role_ons_setrole(this, HAVOCBOT_ONS_ROLE_OFFENSE);
1610 * Find control point or generator owned by the same team self which is nearest to pos
1611 * if max_dist is positive, only control points within this range will be considered
1613 entity ons_Nearest_ControlPoint(vector pos, float max_dist)
1615 entity tmp_entity, closest_target = world;
1616 tmp_entity = findchain(classname, "onslaught_controlpoint");
1619 if(SAME_TEAM(tmp_entity, self))
1620 if(tmp_entity.iscaptured)
1621 if(max_dist <= 0 || vdist(tmp_entity.origin - pos, <=, max_dist))
1622 if(vlen2(tmp_entity.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == world)
1623 closest_target = tmp_entity;
1624 tmp_entity = tmp_entity.chain;
1626 tmp_entity = findchain(classname, "onslaught_generator");
1629 if(SAME_TEAM(tmp_entity, self))
1630 if(max_dist <= 0 || vdist(tmp_entity.origin - pos, <, max_dist))
1631 if(vlen2(tmp_entity.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == world)
1632 closest_target = tmp_entity;
1633 tmp_entity = tmp_entity.chain;
1636 return closest_target;
1640 * Find control point or generator owned by the same team self which is nearest to pos
1641 * if max_dist is positive, only control points within this range will be considered
1642 * This function only check distances on the XY plane, disregarding Z
1644 entity ons_Nearest_ControlPoint_2D(vector pos, float max_dist)
1646 entity tmp_entity, closest_target = world;
1648 float smallest_distance = 0, distance;
1650 tmp_entity = findchain(classname, "onslaught_controlpoint");
1653 delta = tmp_entity.origin - pos;
1655 distance = vlen(delta);
1657 if(SAME_TEAM(tmp_entity, self))
1658 if(tmp_entity.iscaptured)
1659 if(max_dist <= 0 || distance <= max_dist)
1660 if(closest_target == world || distance <= smallest_distance )
1662 closest_target = tmp_entity;
1663 smallest_distance = distance;
1666 tmp_entity = tmp_entity.chain;
1668 tmp_entity = findchain(classname, "onslaught_generator");
1671 delta = tmp_entity.origin - pos;
1673 distance = vlen(delta);
1675 if(SAME_TEAM(tmp_entity, self))
1676 if(max_dist <= 0 || distance <= max_dist)
1677 if(closest_target == world || distance <= smallest_distance )
1679 closest_target = tmp_entity;
1680 smallest_distance = distance;
1683 tmp_entity = tmp_entity.chain;
1686 return closest_target;
1689 * find the number of control points and generators in the same team as this
1691 int ons_Count_SelfControlPoints(entity this)
1694 tmp_entity = findchain(classname, "onslaught_controlpoint");
1698 if(SAME_TEAM(tmp_entity, this))
1699 if(tmp_entity.iscaptured)
1701 tmp_entity = tmp_entity.chain;
1703 tmp_entity = findchain(classname, "onslaught_generator");
1706 if(SAME_TEAM(tmp_entity, this))
1708 tmp_entity = tmp_entity.chain;
1714 * Teleport player to a random position near tele_target
1715 * if tele_effects is true, teleport sound+particles are created
1716 * return false on failure
1718 bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effects)
1726 // narrow the range for each iteration to increase chances that a spawnpoint
1727 // can be found even if there's little room around the control point
1728 float iteration_scale = 1;
1729 for(i = 0; i < 16; ++i)
1731 iteration_scale -= i / 16;
1732 theta = random() * 2 * M_PI;
1736 loc *= random() * range * iteration_scale;
1738 loc += tele_target.origin + '0 0 128' * iteration_scale;
1740 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
1741 if(trace_fraction == 1.0 && !trace_startsolid)
1743 traceline(tele_target.origin, loc, MOVE_NOMONSTERS, tele_target); // double check to make sure we're not spawning outside the world
1744 if(trace_fraction == 1.0 && !trace_startsolid)
1748 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
1749 sound (player, CH_TRIGGER, SND_TELEPORT, VOL_BASE, ATTEN_NORM);
1751 setorigin(player, loc);
1752 player.angles = '0 1 0' * ( theta * RAD2DEG + 180 );
1753 makevectors(player.angles);
1754 player.fixangle = true;
1755 player.teleport_antispam = time + autocvar_g_onslaught_teleport_wait;
1758 Send_Effect(EFFECT_TELEPORT, player.origin + v_forward * 32, '0 0 0', 1);
1771 MUTATOR_HOOKFUNCTION(ons, reset_map_global)
1773 FOREACH_CLIENT(IS_PLAYER(it), {
1774 it.ons_roundlost = false;
1775 it.ons_deathloc = '0 0 0';
1776 WITHSELF(it, PutClientInServer());
1781 MUTATOR_HOOKFUNCTION(ons, ClientDisconnect)
1783 self.ons_deathloc = '0 0 0';
1787 MUTATOR_HOOKFUNCTION(ons, MakePlayerObserver)
1789 self.ons_deathloc = '0 0 0';
1793 MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
1795 if(!round_handler_IsRoundStarted())
1797 self.player_blocked = true;
1802 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1804 l.sprite.SendFlags |= 16;
1806 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1808 l.sprite.SendFlags |= 16;
1811 if(ons_stalemate) { Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); }
1813 if ( autocvar_g_onslaught_spawn_choose )
1814 if ( self.ons_spawn_by )
1815 if ( ons_Teleport(self,self.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) )
1817 self.ons_spawn_by = world;
1821 if(autocvar_g_onslaught_spawn_at_controlpoints)
1822 if(random() <= autocvar_g_onslaught_spawn_at_controlpoints_chance)
1824 float random_target = autocvar_g_onslaught_spawn_at_controlpoints_random;
1825 entity tmp_entity, closest_target = world;
1826 vector spawn_loc = self.ons_deathloc;
1828 // new joining player or round reset, don't bother checking
1829 if(spawn_loc == '0 0 0') { return false; }
1831 if(random_target) { RandomSelection_Init(); }
1833 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1835 if(SAME_TEAM(tmp_entity, self))
1837 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1838 else if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world)
1839 closest_target = tmp_entity;
1842 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1848 float iteration_scale = 1;
1849 for(i = 0; i < 10; ++i)
1851 iteration_scale -= i / 10;
1852 loc = closest_target.origin + '0 0 96' * iteration_scale;
1853 loc += ('0 1 0' * random()) * 128 * iteration_scale;
1854 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, self);
1855 if(trace_fraction == 1.0 && !trace_startsolid)
1857 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
1858 if(trace_fraction == 1.0 && !trace_startsolid)
1860 setorigin(self, loc);
1861 self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1869 if(autocvar_g_onslaught_spawn_at_generator)
1870 if(random() <= autocvar_g_onslaught_spawn_at_generator_chance)
1872 float random_target = autocvar_g_onslaught_spawn_at_generator_random;
1873 entity tmp_entity, closest_target = world;
1874 vector spawn_loc = self.ons_deathloc;
1876 // new joining player or round reset, don't bother checking
1877 if(spawn_loc == '0 0 0') { return false; }
1879 if(random_target) { RandomSelection_Init(); }
1881 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1884 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1887 if(SAME_TEAM(tmp_entity, self))
1888 if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world)
1889 closest_target = tmp_entity;
1893 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1899 float iteration_scale = 1;
1900 for(i = 0; i < 10; ++i)
1902 iteration_scale -= i / 10;
1903 loc = closest_target.origin + '0 0 128' * iteration_scale;
1904 loc += ('0 1 0' * random()) * 256 * iteration_scale;
1905 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, self);
1906 if(trace_fraction == 1.0 && !trace_startsolid)
1908 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
1909 if(trace_fraction == 1.0 && !trace_startsolid)
1911 setorigin(self, loc);
1912 self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1923 MUTATOR_HOOKFUNCTION(ons, PlayerDies)
1925 frag_target.ons_deathloc = frag_target.origin;
1927 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1929 l.sprite.SendFlags |= 16;
1931 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1933 l.sprite.SendFlags |= 16;
1936 if ( autocvar_g_onslaught_spawn_choose )
1937 if ( ons_Count_SelfControlPoints(frag_target) > 1 )
1938 stuffcmd(frag_target, "qc_cmd_cl hud clickradar\n");
1943 MUTATOR_HOOKFUNCTION(ons, MonsterMove)
1945 entity e = find(world, targetname, self.target);
1952 void ons_MonsterSpawn_Delayed(entity this)
1954 entity e, own = self.owner;
1956 if(!own) { remove(self); return; }
1960 e = find(world, target, own.targetname);
1973 MUTATOR_HOOKFUNCTION(ons, MonsterSpawn)
1977 InitializeEntity(e, ons_MonsterSpawn_Delayed, INITPRIO_FINDTARGET);
1982 void ons_TurretSpawn_Delayed(entity this)
1984 entity e, own = self.owner;
1986 if(!own) { remove(self); return; }
1990 e = find(world, target, own.targetname);
1994 own.active = ACTIVE_NOT;
2004 MUTATOR_HOOKFUNCTION(ons, TurretSpawn)
2008 InitializeEntity(e, ons_TurretSpawn_Delayed, INITPRIO_FINDTARGET);
2013 MUTATOR_HOOKFUNCTION(ons, HavocBot_ChooseRole)
2015 havocbot_ons_reset_role(self);
2019 MUTATOR_HOOKFUNCTION(ons, GetTeamCount)
2021 // onslaught is special
2022 for(entity tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
2024 switch(tmp_entity.team)
2026 case NUM_TEAM_1: c1 = 0; break;
2027 case NUM_TEAM_2: c2 = 0; break;
2028 case NUM_TEAM_3: c3 = 0; break;
2029 case NUM_TEAM_4: c4 = 0; break;
2036 MUTATOR_HOOKFUNCTION(ons, SpectateCopy)
2038 self.ons_roundlost = other.ons_roundlost; // make spectators see it too
2042 MUTATOR_HOOKFUNCTION(ons, SV_ParseClientCommand)
2044 if(MUTATOR_RETURNVALUE) // command was already handled?
2047 if ( cmd_name == "ons_spawn" )
2049 vector pos = self.origin;
2051 pos_x = stof(argv(1));
2053 pos_y = stof(argv(2));
2055 pos_z = stof(argv(3));
2057 if ( IS_PLAYER(self) )
2059 if ( !STAT(FROZEN, self) )
2061 entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
2063 if ( !source_point && self.health > 0 )
2065 sprint(self, "\nYou need to be next to a control point\n");
2070 entity closest_target = ons_Nearest_ControlPoint_2D(pos, autocvar_g_onslaught_click_radius);
2072 if ( closest_target == world )
2074 sprint(self, "\nNo control point found\n");
2078 if ( self.health <= 0 )
2080 self.ons_spawn_by = closest_target;
2081 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
2085 if ( source_point == closest_target )
2087 sprint(self, "\nTeleporting to the same point\n");
2091 if ( !ons_Teleport(self,closest_target,autocvar_g_onslaught_teleport_radius,true) )
2092 sprint(self, "\nUnable to teleport there\n");
2098 sprint(self, "\nNo teleportation for you\n");
2106 MUTATOR_HOOKFUNCTION(ons, PlayerUseKey)
2108 if(MUTATOR_RETURNVALUE || gameover) { return false; }
2110 if((time > self.teleport_antispam) && (!IS_DEAD(self)) && !self.vehicle)
2112 entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
2115 stuffcmd(self, "qc_cmd_cl hud clickradar\n");
2123 MUTATOR_HOOKFUNCTION(ons, PlayHitsound)
2125 return (frag_victim.classname == "onslaught_generator" && !frag_victim.isshielded)
2126 || (frag_victim.classname == "onslaught_controlpoint_icon" && !frag_victim.owner.isshielded);
2129 MUTATOR_HOOKFUNCTION(ons, SendWaypoint)
2132 if(wp_sendflags & 16)
2134 if(self.owner.classname == "onslaught_controlpoint")
2136 entity wp_owner = self.owner;
2137 entity e = WaypointSprite_getviewentity(wp_sendto);
2138 if(SAME_TEAM(e, wp_owner) && wp_owner.goalentity.health >= wp_owner.goalentity.max_health) { wp_flag |= 2; }
2139 if(!ons_ControlPoint_Attackable(wp_owner, e.team)) { wp_flag |= 2; }
2141 if(self.owner.classname == "onslaught_generator")
2143 entity wp_owner = self.owner;
2144 if(wp_owner.isshielded && wp_owner.health >= wp_owner.max_health) { wp_flag |= 2; }
2145 if(wp_owner.health <= 0) { wp_flag |= 2; }
2152 MUTATOR_HOOKFUNCTION(ons, TurretValidateTarget)
2154 if(substring(turret_target.classname, 0, 10) == "onslaught_") // don't attack onslaught targets, that's the player's job!
2163 MUTATOR_HOOKFUNCTION(ons, TurretThink)
2166 // ONS uses somewhat backwards linking.
2169 entity e = find(world, targetname, self.target);
2174 if(self.team != self.tur_head.team)
2185 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
2186 Link between control points.
2188 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.
2191 "target" - first control point.
2192 "target2" - second control point.
2194 spawnfunc(onslaught_link)
2196 if(!g_onslaught) { remove(self); return; }
2198 if (self.target == "" || self.target2 == "")
2199 objerror("target and target2 must be set\n");
2201 self.ons_worldlinknext = ons_worldlinklist; // link into ons_worldlinklist
2202 ons_worldlinklist = self;
2204 InitializeEntity(self, ons_DelayedLinkSetup, INITPRIO_FINDTARGET);
2205 Net_LinkEntity(self, false, 0, ons_Link_Send);
2208 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
2209 Control point. Be sure to give this enough clearance so that the shootable part has room to exist
2211 This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
2214 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2215 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
2216 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
2219 spawnfunc(onslaught_controlpoint)
2221 if(!g_onslaught) { remove(self); return; }
2223 ons_ControlPoint_Setup(self);
2226 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
2229 spawnfunc_onslaught_link entities can target this.
2232 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
2233 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2235 spawnfunc(onslaught_generator)
2237 if(!g_onslaught) { remove(self); return; }
2238 if(!self.team) { objerror("team must be set"); }
2240 ons_GeneratorSetup(self);
2244 void ons_ScoreRules()
2246 CheckAllowedTeams(world);
2247 ScoreRules_basics(((c4>=0) ? 4 : (c3>=0) ? 3 : 2), SFL_SORT_PRIO_PRIMARY, 0, true);
2248 ScoreInfo_SetLabel_TeamScore (ST_ONS_CAPS, "destroyed", SFL_SORT_PRIO_PRIMARY);
2249 ScoreInfo_SetLabel_PlayerScore(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
2250 ScoreInfo_SetLabel_PlayerScore(SP_ONS_TAKES, "takes", 0);
2251 ScoreRules_basics_end();
2254 void ons_DelayedInit(entity this) // Do this check with a delay so we can wait for teams to be set up
2258 round_handler_Spawn(Onslaught_CheckPlayers, Onslaught_CheckWinner, Onslaught_RoundStart);
2259 round_handler_Init(5, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
2262 void ons_Initialize()
2265 ons_captureshield_force = autocvar_g_onslaught_shield_force;
2267 InitializeEntity(world, ons_DelayedInit, INITPRIO_GAMETYPE);