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, autocvar_leadlimit_override, autocvar_timelimit_override, -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;
80 .entity bot_basewaypoint; // generator waypointsprite
82 .bool isgenneighbor[17];
83 .bool iscpneighbor[17];
84 float ons_notification_time[17];
86 .float ons_overtime_damagedelay;
92 // declarations for functions used outside gamemode_onslaught.qc
93 void ons_Generator_UpdateSprite(entity e);
94 void ons_ControlPoint_UpdateSprite(entity e);
95 bool ons_ControlPoint_Attackable(entity cp, int teamnumber);
97 // CaptureShield: Prevent capturing or destroying control point/generator if it is not available yet
98 float ons_captureshield_force; // push force of the shield
101 const int HAVOCBOT_ONS_ROLE_NONE = 0;
102 const int HAVOCBOT_ONS_ROLE_DEFENSE = 2;
103 const int HAVOCBOT_ONS_ROLE_ASSISTANT = 4;
104 const int HAVOCBOT_ONS_ROLE_OFFENSE = 8;
106 .entity havocbot_ons_target;
108 .int havocbot_role_flags;
109 .float havocbot_attack_time;
111 void havocbot_role_ons_defense(entity this);
112 void havocbot_role_ons_offense(entity this);
113 void havocbot_role_ons_assistant(entity this);
115 void havocbot_ons_reset_role(entity this);
116 void havocbot_goalrating_items(entity this, float ratingscale, vector org, float sradius);
117 void havocbot_goalrating_enemyplayers(entity this, float ratingscale, vector org, float sradius);
119 // score rule declarations
120 const int ST_ONS_CAPS = 1;
125 #ifdef IMPLEMENTATION
127 #include "sv_controlpoint.qh"
128 #include "sv_generator.qh"
132 float autocvar_g_onslaught_teleport_wait;
133 bool autocvar_g_onslaught_spawn_at_controlpoints;
134 bool autocvar_g_onslaught_spawn_at_generator;
135 float autocvar_g_onslaught_cp_proxydecap;
136 float autocvar_g_onslaught_cp_proxydecap_distance = 512;
137 float autocvar_g_onslaught_cp_proxydecap_dps = 100;
138 float autocvar_g_onslaught_spawn_at_controlpoints_chance = 0.5;
139 float autocvar_g_onslaught_spawn_at_controlpoints_random;
140 float autocvar_g_onslaught_spawn_at_generator_chance;
141 float autocvar_g_onslaught_spawn_at_generator_random;
142 float autocvar_g_onslaught_cp_buildhealth;
143 float autocvar_g_onslaught_cp_buildtime;
144 float autocvar_g_onslaught_cp_health;
145 float autocvar_g_onslaught_cp_regen;
146 float autocvar_g_onslaught_gen_health;
147 float autocvar_g_onslaught_shield_force = 100;
148 float autocvar_g_onslaught_allow_vehicle_touch;
149 float autocvar_g_onslaught_round_timelimit;
150 float autocvar_g_onslaught_warmup;
151 float autocvar_g_onslaught_teleport_radius;
152 float autocvar_g_onslaught_spawn_choose;
153 float autocvar_g_onslaught_click_radius;
155 void FixSize(entity e);
157 // =======================
158 // CaptureShield Functions
159 // =======================
161 bool ons_CaptureShield_Customize(entity this, entity client)
163 entity e = WaypointSprite_getviewentity(client);
165 if(!this.enemy.isshielded && (ons_ControlPoint_Attackable(this.enemy, e.team) > 0 || this.enemy.classname != "onslaught_controlpoint")) { return false; }
166 if(SAME_TEAM(this, e)) { return false; }
171 void ons_CaptureShield_Touch(entity this, entity toucher)
173 if(!this.enemy.isshielded && (ons_ControlPoint_Attackable(this.enemy, toucher.team) > 0 || this.enemy.classname != "onslaught_controlpoint")) { return; }
174 if(!IS_PLAYER(toucher)) { return; }
175 if(SAME_TEAM(toucher, this)) { return; }
177 vector mymid = (this.absmin + this.absmax) * 0.5;
178 vector theirmid = (toucher.absmin + toucher.absmax) * 0.5;
180 Damage(toucher, this, this, 0, DEATH_HURTTRIGGER.m_id, mymid, normalize(theirmid - mymid) * ons_captureshield_force);
182 if(IS_REAL_CLIENT(toucher))
184 play2(toucher, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
186 if(this.enemy.classname == "onslaught_generator")
187 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_GENERATOR_SHIELDED);
189 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_CONTROLPOINT_SHIELDED);
193 void ons_CaptureShield_Reset(entity this)
195 this.colormap = this.enemy.colormap;
196 this.team = this.enemy.team;
199 void ons_CaptureShield_Spawn(entity generator, bool is_generator)
201 entity shield = new(ons_captureshield);
203 shield.enemy = generator;
204 shield.team = generator.team;
205 shield.colormap = generator.colormap;
206 shield.reset = ons_CaptureShield_Reset;
207 settouch(shield, ons_CaptureShield_Touch);
208 setcefc(shield, ons_CaptureShield_Customize);
209 shield.effects = EF_ADDITIVE;
210 set_movetype(shield, MOVETYPE_NOCLIP);
211 shield.solid = SOLID_TRIGGER;
212 shield.avelocity = '7 0 11';
214 shield.model = ((is_generator) ? "models/onslaught/generator_shield.md3" : "models/onslaught/controlpoint_shield.md3");
216 precache_model(shield.model);
217 setorigin(shield, generator.origin);
218 _setmodel(shield, shield.model);
219 setsize(shield, shield.scale * shield.mins, shield.scale * shield.maxs);
227 void setmodel_fixsize(entity e, Model m)
233 void onslaught_updatelinks()
236 // first check if the game has ended
237 LOG_DEBUG("--- updatelinks ---");
238 // mark generators as being shielded and networked
239 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
242 LOG_DEBUG(etos(l), " (generator) belongs to team ", ftos(l.team));
244 LOG_DEBUG(etos(l), " (generator) is destroyed");
245 l.islinked = l.iscaptured;
246 l.isshielded = l.iscaptured;
247 l.sprite.SendFlags |= 16;
249 // mark points as shielded and not networked
250 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
255 for(i = 0; i < 17; ++i) { l.isgenneighbor[i] = false; l.iscpneighbor[i] = false; }
256 LOG_DEBUG(etos(l), " (point) belongs to team ", ftos(l.team));
257 l.sprite.SendFlags |= 16;
259 // flow power outward from the generators through the network
264 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
266 // if both points are captured by the same team, and only one of
267 // them is powered, mark the other one as powered as well
268 if (l.enemy.iscaptured && l.goalentity.iscaptured)
269 if (l.enemy.islinked != l.goalentity.islinked)
270 if(SAME_TEAM(l.enemy, l.goalentity))
272 if (!l.goalentity.islinked)
275 l.goalentity.islinked = true;
276 LOG_DEBUG(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)");
278 else if (!l.enemy.islinked)
281 l.enemy.islinked = true;
282 LOG_DEBUG(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)");
287 // now that we know which points are powered we can mark their neighbors
288 // as unshielded if team differs
289 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
291 if (l.goalentity.islinked)
293 if(DIFF_TEAM(l.goalentity, l.enemy))
295 LOG_DEBUG(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)");
296 l.enemy.isshielded = false;
298 if(l.goalentity.classname == "onslaught_generator")
299 l.enemy.isgenneighbor[l.goalentity.team] = true;
301 l.enemy.iscpneighbor[l.goalentity.team] = true;
303 if (l.enemy.islinked)
305 if(DIFF_TEAM(l.goalentity, l.enemy))
307 LOG_DEBUG(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)");
308 l.goalentity.isshielded = false;
310 if(l.enemy.classname == "onslaught_generator")
311 l.goalentity.isgenneighbor[l.enemy.team] = true;
313 l.goalentity.iscpneighbor[l.enemy.team] = true;
316 // now update the generators
317 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
321 LOG_DEBUG(etos(l), " (generator) is shielded");
322 l.takedamage = DAMAGE_NO;
323 l.bot_attack = false;
327 LOG_DEBUG(etos(l), " (generator) is not shielded");
328 l.takedamage = DAMAGE_AIM;
332 ons_Generator_UpdateSprite(l);
334 // now update the takedamage and alpha variables on control point icons
335 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
339 LOG_DEBUG(etos(l), " (point) is shielded");
342 l.goalentity.takedamage = DAMAGE_NO;
343 l.goalentity.bot_attack = false;
348 LOG_DEBUG(etos(l), " (point) is not shielded");
351 l.goalentity.takedamage = DAMAGE_AIM;
352 l.goalentity.bot_attack = true;
355 ons_ControlPoint_UpdateSprite(l);
357 FOREACH_ENTITY_CLASS("ons_captureshield", true,
359 it.team = it.enemy.team;
360 it.colormap = it.enemy.colormap;
365 // ===================
366 // Main Link Functions
367 // ===================
369 bool ons_Link_Send(entity this, entity to, int sendflags)
371 WriteHeader(MSG_ENTITY, ENT_CLIENT_RADARLINK);
372 WriteByte(MSG_ENTITY, sendflags);
375 WriteCoord(MSG_ENTITY, this.goalentity.origin_x);
376 WriteCoord(MSG_ENTITY, this.goalentity.origin_y);
377 WriteCoord(MSG_ENTITY, this.goalentity.origin_z);
381 WriteCoord(MSG_ENTITY, this.enemy.origin_x);
382 WriteCoord(MSG_ENTITY, this.enemy.origin_y);
383 WriteCoord(MSG_ENTITY, this.enemy.origin_z);
387 WriteByte(MSG_ENTITY, this.clientcolors); // which is goalentity's color + enemy's color * 16
392 void ons_Link_CheckUpdate(entity this)
394 // TODO check if the two sides have moved (currently they won't move anyway)
395 float cc = 0, cc1 = 0, cc2 = 0;
397 if(this.goalentity.islinked || this.goalentity.iscaptured) { cc1 = (this.goalentity.team - 1) * 0x01; }
398 if(this.enemy.islinked || this.enemy.iscaptured) { cc2 = (this.enemy.team - 1) * 0x10; }
402 if(cc != this.clientcolors)
404 this.clientcolors = cc;
408 this.nextthink = time;
411 void ons_DelayedLinkSetup(entity this)
413 this.goalentity = find(NULL, targetname, this.target);
414 this.enemy = find(NULL, targetname, this.target2);
415 if(!this.goalentity) { objerror(this, "can not find target\n"); }
416 if(!this.enemy) { objerror(this, "can not find target2\n"); }
418 LOG_DEBUG(etos(this.goalentity), " linked with ", etos(this.enemy));
420 setthink(this, ons_Link_CheckUpdate);
421 this.nextthink = time;
425 // =============================
426 // Main Control Point Functions
427 // =============================
429 int ons_ControlPoint_CanBeLinked(entity cp, int teamnumber)
431 if(cp.isgenneighbor[teamnumber]) { return 2; }
432 if(cp.iscpneighbor[teamnumber]) { return 1; }
437 int ons_ControlPoint_Attackable(entity cp, int teamnumber)
438 // -2: SAME TEAM, attackable by enemy!
443 // 3: attack it (HIGH PRIO)
444 // 4: touch it (HIGH PRIO)
452 else if(cp.goalentity)
454 // if there's already an icon built, nothing happens
455 if(cp.team == teamnumber)
457 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
458 if(a) // attackable by enemy?
459 return -2; // EMERGENCY!
462 // we know it can be linked, so no need to check
464 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
465 if(a == 2) // near our generator?
466 return 3; // EMERGENCY!
472 if(ons_ControlPoint_CanBeLinked(cp, teamnumber))
474 a = ons_ControlPoint_CanBeLinked(cp, teamnumber); // why was this here NUM_TEAM_1 + NUM_TEAM_2 - t
476 return 4; // GET THIS ONE NOW!
478 return 2; // TOUCH ME
484 void ons_ControlPoint_Icon_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
486 if(damage <= 0) { return; }
488 if (this.owner.isshielded)
490 // this is protected by a shield, so ignore the damage
491 if (time > this.pain_finished)
492 if (IS_PLAYER(attacker))
494 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
495 this.pain_finished = time + 1;
496 attacker.typehitsound += 1; // play both sounds (shield is way too quiet)
502 if(IS_PLAYER(attacker))
503 if(time - ons_notification_time[this.team] > 10)
505 play2team(this.team, SND(ONS_CONTROLPOINT_UNDERATTACK));
506 ons_notification_time[this.team] = time;
509 this.health = this.health - damage;
510 if(this.owner.iscaptured)
511 WaypointSprite_UpdateHealth(this.owner.sprite, this.health);
513 WaypointSprite_UpdateBuildFinished(this.owner.sprite, time + (this.max_health - this.health) / (this.count / ONS_CP_THINKRATE));
514 this.pain_finished = time + 1;
515 // particles on every hit
516 pointparticles(EFFECT_SPARKS, hitloc, force*-1, 1);
519 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE+0.3, ATTEN_NORM);
521 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE+0.3, ATTEN_NORM);
525 sound(this, CH_TRIGGER, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
526 pointparticles(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
527 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_CPDESTROYED), this.owner.message, attacker.netname);
529 PlayerScore_Add(attacker, SP_ONS_TAKES, 1);
530 PlayerScore_Add(attacker, SP_SCORE, 10);
532 this.owner.goalentity = NULL;
533 this.owner.islinked = false;
534 this.owner.iscaptured = false;
536 this.owner.colormap = 1024;
538 WaypointSprite_UpdateMaxHealth(this.owner.sprite, 0);
540 onslaught_updatelinks();
542 // Use targets now (somebody make sure this is in the right place..)
543 SUB_UseTargets(this.owner, this, NULL);
545 this.owner.waslinked = this.owner.islinked;
546 if(this.owner.model != "models/onslaught/controlpoint_pad.md3")
547 setmodel_fixsize(this.owner, MDL_ONS_CP_PAD1);
548 //setsize(this, '-32 -32 0', '32 32 8');
553 this.SendFlags |= CPSF_STATUS;
556 void ons_ControlPoint_Icon_Think(entity this)
558 this.nextthink = time + ONS_CP_THINKRATE;
560 if(autocvar_g_onslaught_cp_proxydecap)
562 int _enemy_count = 0;
563 int _friendly_count = 0;
565 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it), {
566 if(vdist(it.origin - this.origin, <, autocvar_g_onslaught_cp_proxydecap_distance))
568 if(SAME_TEAM(it, this))
575 _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
576 _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
578 this.health = bound(0, this.health + (_friendly_count - _enemy_count), this.max_health);
579 this.SendFlags |= CPSF_STATUS;
582 ons_ControlPoint_Icon_Damage(this, this, this, 1, 0, this.origin, '0 0 0');
587 if (time > this.pain_finished + 5)
589 if(this.health < this.max_health)
591 this.health = this.health + this.count;
592 if (this.health >= this.max_health)
593 this.health = this.max_health;
594 WaypointSprite_UpdateHealth(this.owner.sprite, this.health);
598 if(this.owner.islinked != this.owner.waslinked)
600 // unteam the spawnpoint if needed
601 int t = this.owner.team;
602 if(!this.owner.islinked)
605 SUB_UseTargets(this.owner, this, NULL);
609 this.owner.waslinked = this.owner.islinked;
613 if(random() < 0.6 - this.health / this.max_health)
615 Send_Effect(EFFECT_ELECTRIC_SPARKS, this.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
618 sound(this, CH_PAIN, SND_ONS_SPARK1, VOL_BASE, ATTEN_NORM);
619 else if (random() > 0.5)
620 sound(this, CH_PAIN, SND_ONS_SPARK2, VOL_BASE, ATTEN_NORM);
624 void ons_ControlPoint_Icon_BuildThink(entity this)
628 this.nextthink = time + ONS_CP_THINKRATE;
630 // only do this if there is power
631 a = ons_ControlPoint_CanBeLinked(this.owner, this.owner.team);
635 this.health = this.health + this.count;
637 this.SendFlags |= CPSF_STATUS;
639 if (this.health >= this.max_health)
641 this.health = this.max_health;
642 this.count = autocvar_g_onslaught_cp_regen * ONS_CP_THINKRATE; // slow repair rate from now on
643 setthink(this, ons_ControlPoint_Icon_Think);
644 sound(this, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILT, VOL_BASE, ATTEN_NORM);
645 this.owner.iscaptured = true;
646 this.solid = SOLID_BBOX;
648 Send_Effect(EFFECT_CAP(this.owner.team), this.owner.origin, '0 0 0', 1);
650 WaypointSprite_UpdateMaxHealth(this.owner.sprite, this.max_health);
651 WaypointSprite_UpdateHealth(this.owner.sprite, this.health);
653 if(IS_PLAYER(this.owner.ons_toucher))
655 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ONSLAUGHT_CAPTURE, this.owner.ons_toucher.netname, this.owner.message);
656 Send_Notification(NOTIF_ALL_EXCEPT, this.owner.ons_toucher, MSG_CENTER, APP_TEAM_NUM(this.owner.ons_toucher.team, CENTER_ONS_CAPTURE), this.owner.message);
657 Send_Notification(NOTIF_ONE, this.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE, this.owner.message);
658 PlayerScore_Add(this.owner.ons_toucher, SP_ONS_CAPS, 1);
659 PlayerTeamScore_AddScore(this.owner.ons_toucher, 10);
662 this.owner.ons_toucher = NULL;
664 onslaught_updatelinks();
666 // Use targets now (somebody make sure this is in the right place..)
667 SUB_UseTargets(this.owner, this, NULL);
669 this.SendFlags |= CPSF_SETUP;
671 if(this.owner.model != MDL_ONS_CP_PAD2.model_str())
672 setmodel_fixsize(this.owner, MDL_ONS_CP_PAD2);
674 if(random() < 0.9 - this.health / this.max_health)
675 Send_Effect(EFFECT_RAGE, this.origin + 10 * randomvec(), '0 0 -1', 1);
678 void onslaught_controlpoint_icon_link(entity e, void(entity this) spawnproc);
680 void ons_ControlPoint_Icon_Spawn(entity cp, entity player)
682 entity e = new(onslaught_controlpoint_icon);
684 setsize(e, CPICON_MIN, CPICON_MAX);
685 setorigin(e, cp.origin + CPICON_OFFSET);
688 e.max_health = autocvar_g_onslaught_cp_health;
689 e.health = autocvar_g_onslaught_cp_buildhealth;
691 e.takedamage = DAMAGE_AIM;
693 e.event_damage = ons_ControlPoint_Icon_Damage;
694 e.team = player.team;
695 e.colormap = 1024 + (e.team - 1) * 17;
696 e.count = (e.max_health - e.health) * ONS_CP_THINKRATE / autocvar_g_onslaught_cp_buildtime; // how long it takes to build
698 sound(e, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILD, VOL_BASE, ATTEN_NORM);
702 cp.colormap = e.colormap;
704 Send_Effect(EFFECT_FLAG_TOUCH(player.team), e.origin, '0 0 0', 1);
706 WaypointSprite_UpdateBuildFinished(cp.sprite, time + (e.max_health - e.health) / (e.count / ONS_CP_THINKRATE));
707 WaypointSprite_UpdateRule(cp.sprite,cp.team,SPRITERULE_TEAMPLAY);
708 cp.sprite.SendFlags |= 16;
710 onslaught_controlpoint_icon_link(e, ons_ControlPoint_Icon_BuildThink);
713 entity ons_ControlPoint_Waypoint(entity e)
717 int a = ons_ControlPoint_Attackable(e, e.team);
719 if(a == -2) { return WP_OnsCPDefend; } // defend now
720 if(a == -1 || a == 1 || a == 2) { return WP_OnsCP; } // touch
721 if(a == 3 || a == 4) { return WP_OnsCPAttack; } // attack
729 void ons_ControlPoint_UpdateSprite(entity e)
731 entity s1 = ons_ControlPoint_Waypoint(e);
732 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
735 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));
737 if(e.lastteam != e.team + 2 || e.lastshielded != sh || e.iscaptured != e.lastcaptured)
739 if(e.iscaptured) // don't mess up build bars!
743 WaypointSprite_UpdateMaxHealth(e.sprite, 0);
747 WaypointSprite_UpdateMaxHealth(e.sprite, e.goalentity.max_health);
748 WaypointSprite_UpdateHealth(e.sprite, e.goalentity.health);
754 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, false));
756 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
761 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, false));
763 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
765 WaypointSprite_Ping(e.sprite);
767 e.lastteam = e.team + 2;
769 e.lastcaptured = e.iscaptured;
773 void ons_ControlPoint_Touch(entity this, entity toucher)
777 if(IS_VEHICLE(toucher) && toucher.owner)
778 if(autocvar_g_onslaught_allow_vehicle_touch)
779 toucher = toucher.owner;
783 if(!IS_PLAYER(toucher)) { return; }
784 if(STAT(FROZEN, toucher)) { return; }
785 if(IS_DEAD(toucher)) { return; }
787 if ( SAME_TEAM(this,toucher) )
788 if ( this.iscaptured )
790 if(time <= toucher.teleport_antispam)
791 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT_ANTISPAM, rint(toucher.teleport_antispam - time));
793 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
796 attackable = ons_ControlPoint_Attackable(this, toucher.team);
797 if(attackable != 2 && attackable != 4)
799 // we've verified that this player has a legitimate claim to this point,
800 // so start building the captured point icon (which only captures this
801 // point if it successfully builds without being destroyed first)
802 ons_ControlPoint_Icon_Spawn(this, toucher);
804 this.ons_toucher = toucher;
806 onslaught_updatelinks();
809 void ons_ControlPoint_Think(entity this)
811 this.nextthink = time + ONS_CP_THINKRATE;
812 CSQCMODEL_AUTOUPDATE(this);
815 void ons_ControlPoint_Reset(entity this)
818 delete(this.goalentity);
820 this.goalentity = NULL;
822 this.colormap = 1024;
823 this.iscaptured = false;
824 this.islinked = false;
825 this.isshielded = true;
826 setthink(this, ons_ControlPoint_Think);
827 this.ons_toucher = NULL;
828 this.nextthink = time + ONS_CP_THINKRATE;
829 setmodel_fixsize(this, MDL_ONS_CP_PAD1);
831 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
832 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
834 onslaught_updatelinks();
836 SUB_UseTargets(this, this, NULL); // to reset the structures, playerspawns etc.
838 CSQCMODEL_AUTOUPDATE(this);
841 void ons_DelayedControlPoint_Setup(entity this)
843 onslaught_updatelinks();
845 // captureshield setup
846 ons_CaptureShield_Spawn(this, false);
848 CSQCMODEL_AUTOINIT(this);
851 void ons_ControlPoint_Setup(entity cp)
854 cp.ons_worldcpnext = ons_worldcplist; // link control point into ons_worldcplist
855 ons_worldcplist = cp;
857 cp.netname = "Control point";
859 cp.solid = SOLID_BBOX;
860 set_movetype(cp, MOVETYPE_NONE);
861 settouch(cp, ons_ControlPoint_Touch);
862 setthink(cp, ons_ControlPoint_Think);
863 cp.nextthink = time + ONS_CP_THINKRATE;
864 cp.reset = ons_ControlPoint_Reset;
866 cp.iscaptured = false;
868 cp.isshielded = true;
870 if(cp.message == "") { cp.message = "a"; }
873 setmodel_fixsize(cp, MDL_ONS_CP_PAD1);
875 // control point placement
876 if((cp.spawnflags & 1) || cp.noalign) // don't drop to floor, just stay at fixed location
879 set_movetype(cp, MOVETYPE_NONE);
881 else // drop to floor, automatically find a platform and set that as spawn origin
883 setorigin(cp, cp.origin + '0 0 20');
886 set_movetype(cp, MOVETYPE_TOSS);
890 WaypointSprite_SpawnFixed(WP_Null, cp.origin + CPGEN_WAYPOINT_OFFSET, cp, sprite, RADARICON_NONE);
891 WaypointSprite_UpdateRule(cp.sprite, cp.team, SPRITERULE_TEAMPLAY);
893 InitializeEntity(cp, ons_DelayedControlPoint_Setup, INITPRIO_SETLOCATION);
897 // =========================
898 // Main Generator Functions
899 // =========================
901 entity ons_Generator_Waypoint(entity e)
904 return WP_OnsGenShielded;
908 void ons_Generator_UpdateSprite(entity e)
910 entity s1 = ons_Generator_Waypoint(e);
911 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
913 if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
915 e.lastteam = e.team + 2;
916 e.lastshielded = e.isshielded;
920 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, false));
922 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
927 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, false));
929 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
931 WaypointSprite_Ping(e.sprite);
935 void ons_GeneratorDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
937 if(damage <= 0) { return; }
938 if(warmup_stage || gameover) { return; }
939 if(!round_handler_IsRoundStarted()) { return; }
941 if (attacker != this)
945 // this is protected by a shield, so ignore the damage
946 if (time > this.pain_finished)
947 if (IS_PLAYER(attacker))
949 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
950 attacker.typehitsound += 1;
951 this.pain_finished = time + 1;
955 if (time > this.pain_finished)
957 this.pain_finished = time + 10;
958 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && SAME_TEAM(it, this), Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK));
959 play2team(this.team, SND(ONS_GENERATOR_UNDERATTACK));
962 this.health = this.health - damage;
963 WaypointSprite_UpdateHealth(this.sprite, this.health);
964 // choose an animation frame based on health
965 this.frame = 10 * bound(0, (1 - this.health / this.max_health), 1);
966 // see if the generator is still functional, or dying
969 this.lasthealth = this.health;
973 if (attacker == this)
974 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME));
977 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED));
978 PlayerScore_Add(attacker, SP_SCORE, 100);
980 this.iscaptured = false;
981 this.islinked = false;
982 this.isshielded = false;
983 this.takedamage = DAMAGE_NO; // can't be hurt anymore
984 this.event_damage = func_null; // won't do anything if hurt
985 this.count = 0; // reset counter
986 setthink(this, func_null);
988 //this.think(); // do the first explosion now
990 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
991 WaypointSprite_Ping(this.sprite);
992 //WaypointSprite_Kill(this.sprite); // can't do this yet, code too poor
994 onslaught_updatelinks();
997 // Throw some flaming gibs on damage, more damage = more chance for gib
998 if(random() < damage/220)
1000 sound(this, CH_TRIGGER, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
1004 // particles on every hit
1005 Send_Effect(EFFECT_SPARKS, hitloc, force * -1, 1);
1007 //sound on every hit
1009 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE, ATTEN_NORM);
1011 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE, ATTEN_NORM);
1014 this.SendFlags |= GSF_STATUS;
1017 void ons_GeneratorThink(entity this)
1019 this.nextthink = time + GEN_THINKRATE;
1022 if(!this.isshielded && this.wait < time)
1024 this.wait = time + 5;
1025 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
1026 if(SAME_TEAM(it, this))
1028 Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM);
1029 soundto(MSG_ONE, it, CHAN_AUTO, SND(KH_ALARM), VOL_BASE, ATTEN_NONE); // FIXME: unique sound?
1032 Send_Notification(NOTIF_ONE, it, MSG_CENTER, APP_TEAM_NUM(this.team, CENTER_ONS_NOTSHIELDED));
1038 void ons_GeneratorReset(entity this)
1040 this.team = this.team_saved;
1041 this.lasthealth = this.max_health = this.health = autocvar_g_onslaught_gen_health;
1042 this.takedamage = DAMAGE_AIM;
1043 this.bot_attack = true;
1044 this.iscaptured = true;
1045 this.islinked = true;
1046 this.isshielded = true;
1047 this.event_damage = ons_GeneratorDamage;
1048 setthink(this, ons_GeneratorThink);
1049 this.nextthink = time + GEN_THINKRATE;
1051 Net_LinkEntity(this, false, 0, generator_send);
1053 this.SendFlags = GSF_SETUP; // just incase
1054 this.SendFlags |= GSF_STATUS;
1056 WaypointSprite_UpdateMaxHealth(this.sprite, this.max_health);
1057 WaypointSprite_UpdateHealth(this.sprite, this.health);
1058 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
1060 onslaught_updatelinks();
1063 void ons_DelayedGeneratorSetup(entity this)
1066 waypoint_spawnforitem_force(this, this.origin);
1067 this.nearestwaypointtimeout = 0; // activate waypointing again
1068 this.bot_basewaypoint = this.nearestwaypoint;
1070 // captureshield setup
1071 ons_CaptureShield_Spawn(this, true);
1073 onslaught_updatelinks();
1075 Net_LinkEntity(this, false, 0, generator_send);
1079 void onslaught_generator_touch(entity this, entity toucher)
1081 if ( IS_PLAYER(toucher) )
1082 if ( SAME_TEAM(this,toucher) )
1083 if ( this.iscaptured )
1085 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
1089 void ons_GeneratorSetup(entity gen) // called when spawning a generator entity on the map as a spawnfunc
1092 int teamnumber = gen.team;
1095 gen.ons_worldgeneratornext = ons_worldgeneratorlist; // link generator into ons_worldgeneratorlist
1096 ons_worldgeneratorlist = gen;
1098 gen.netname = sprintf("%s generator", Team_ColoredFullName(teamnumber));
1099 gen.classname = "onslaught_generator";
1100 gen.solid = SOLID_BBOX;
1101 gen.team_saved = teamnumber;
1102 set_movetype(gen, MOVETYPE_NONE);
1103 gen.lasthealth = gen.max_health = gen.health = autocvar_g_onslaught_gen_health;
1104 gen.takedamage = DAMAGE_AIM;
1105 gen.bot_attack = true;
1106 gen.event_damage = ons_GeneratorDamage;
1107 gen.reset = ons_GeneratorReset;
1108 setthink(gen, ons_GeneratorThink);
1109 gen.nextthink = time + GEN_THINKRATE;
1110 gen.iscaptured = true;
1111 gen.islinked = true;
1112 gen.isshielded = true;
1113 settouch(gen, onslaught_generator_touch);
1116 // model handled by CSQC
1117 setsize(gen, GENERATOR_MIN, GENERATOR_MAX);
1118 setorigin(gen, (gen.origin + CPGEN_SPAWN_OFFSET));
1119 gen.colormap = 1024 + (teamnumber - 1) * 17;
1121 // generator placement
1125 WaypointSprite_SpawnFixed(WP_Null, gen.origin + CPGEN_WAYPOINT_OFFSET, gen, sprite, RADARICON_NONE);
1126 WaypointSprite_UpdateRule(gen.sprite, gen.team, SPRITERULE_TEAMPLAY);
1127 WaypointSprite_UpdateMaxHealth(gen.sprite, gen.max_health);
1128 WaypointSprite_UpdateHealth(gen.sprite, gen.health);
1130 InitializeEntity(gen, ons_DelayedGeneratorSetup, INITPRIO_SETLOCATION);
1138 int total_generators;
1139 void Onslaught_count_generators()
1142 total_generators = redowned = blueowned = yellowowned = pinkowned = 0;
1143 for(e = ons_worldgeneratorlist; e; e = e.ons_worldgeneratornext)
1146 redowned += (e.team == NUM_TEAM_1 && e.health > 0);
1147 blueowned += (e.team == NUM_TEAM_2 && e.health > 0);
1148 yellowowned += (e.team == NUM_TEAM_3 && e.health > 0);
1149 pinkowned += (e.team == NUM_TEAM_4 && e.health > 0);
1153 int Onslaught_GetWinnerTeam()
1155 int winner_team = 0;
1157 winner_team = NUM_TEAM_1;
1160 if(winner_team) return 0;
1161 winner_team = NUM_TEAM_2;
1165 if(winner_team) return 0;
1166 winner_team = NUM_TEAM_3;
1170 if(winner_team) return 0;
1171 winner_team = NUM_TEAM_4;
1175 return -1; // no generators left?
1178 void nades_Clear(entity e);
1180 #define ONS_OWNED_GENERATORS() ((redowned > 0) + (blueowned > 0) + (yellowowned > 0) + (pinkowned > 0))
1181 #define ONS_OWNED_GENERATORS_OK() (ONS_OWNED_GENERATORS() > 1)
1182 bool Onslaught_CheckWinner()
1184 if ((autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60) || (round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0))
1186 ons_stalemate = true;
1188 if (!wpforenemy_announced)
1190 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT);
1191 sound(NULL, CH_INFO, SND_ONS_GENERATOR_DECAY, VOL_BASE, ATTEN_NONE);
1193 wpforenemy_announced = true;
1196 entity tmp_entity; // temporary entity
1198 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext) if(time >= tmp_entity.ons_overtime_damagedelay)
1200 // tmp_entity.max_health / 300 gives 5 minutes of overtime.
1201 // control points reduce the overtime duration.
1204 for(e = ons_worldcplist; e; e = e.ons_worldcpnext)
1206 if(DIFF_TEAM(e, tmp_entity))
1211 if(autocvar_g_campaign && autocvar__campaign_testrun)
1212 d = d * tmp_entity.max_health;
1214 d = d * tmp_entity.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
1216 Damage(tmp_entity, tmp_entity, tmp_entity, d, DEATH_HURTTRIGGER.m_id, tmp_entity.origin, '0 0 0');
1218 tmp_entity.sprite.SendFlags |= 16;
1220 tmp_entity.ons_overtime_damagedelay = time + 1;
1223 else { wpforenemy_announced = false; ons_stalemate = false; }
1225 Onslaught_count_generators();
1227 if(ONS_OWNED_GENERATORS_OK())
1230 int winner_team = Onslaught_GetWinnerTeam();
1234 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
1235 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
1236 TeamScore_AddToTeam(winner_team, ST_ONS_CAPS, +1);
1238 else if(winner_team == -1)
1240 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_TIED);
1241 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_TIED);
1244 ons_stalemate = false;
1246 play2all(SND(CTF_CAPTURE(winner_team)));
1248 round_handler_Init(7, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
1250 FOREACH_CLIENT(IS_PLAYER(it), {
1251 STAT(ROUNDLOST, it) = true;
1252 it.player_blocked = true;
1260 bool Onslaught_CheckPlayers()
1265 void Onslaught_RoundStart()
1268 FOREACH_CLIENT(IS_PLAYER(it), it.player_blocked = false);
1270 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1271 tmp_entity.sprite.SendFlags |= 16;
1273 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1274 tmp_entity.sprite.SendFlags |= 16;
1282 // NOTE: LEGACY CODE, needs to be re-written!
1284 void havocbot_goalrating_ons_offenseitems(entity this, float ratingscale, vector org, float sradius)
1286 bool needarmor = false, needweapons = false;
1288 // Needs armor/health?
1294 FOREACH(Weapons, it != WEP_Null, {
1295 if(this.weapons & (it.m_wepset))
1303 if(!needweapons && !needarmor)
1306 LOG_DEBUG(this.netname, " needs weapons ", ftos(needweapons));
1307 LOG_DEBUG(this.netname, " needs armor ", ftos(needarmor));
1309 // See what is around
1310 FOREACH_ENTITY_FLOAT(bot_pickup, true,
1312 // gather health and armor only
1314 if ( ((it.health || it.armorvalue) && needarmor) || (it.weapons && needweapons ) )
1315 if (vdist(it.origin - org, <, sradius))
1317 int t = it.bot_pickupevalfunc(this, it);
1319 navigation_routerating(this, it, t * ratingscale, 500);
1324 void havocbot_role_ons_setrole(entity this, int role)
1326 LOG_DEBUG(this.netname," switched to ");
1329 case HAVOCBOT_ONS_ROLE_DEFENSE:
1330 LOG_DEBUG("defense");
1331 this.havocbot_role = havocbot_role_ons_defense;
1332 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE;
1333 this.havocbot_role_timeout = 0;
1335 case HAVOCBOT_ONS_ROLE_ASSISTANT:
1336 LOG_DEBUG("assistant");
1337 this.havocbot_role = havocbot_role_ons_assistant;
1338 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT;
1339 this.havocbot_role_timeout = 0;
1341 case HAVOCBOT_ONS_ROLE_OFFENSE:
1342 LOG_DEBUG("offense");
1343 this.havocbot_role = havocbot_role_ons_offense;
1344 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE;
1345 this.havocbot_role_timeout = 0;
1351 void havocbot_goalrating_ons_controlpoints_attack(entity this, float ratingscale)
1353 entity cp, cp1, cp2, best, wp;
1354 float radius, bestvalue;
1358 // Filter control points
1359 for(cp2 = ons_worldcplist; cp2; cp2 = cp2.ons_worldcpnext)
1362 cp2.wpconsidered = false;
1367 // Ignore owned controlpoints
1368 if(!(cp2.isgenneighbor[this.team] || cp2.iscpneighbor[this.team]))
1371 // Count team mates interested in this control point
1372 // (easier and cleaner than keeping counters per cp and teams)
1373 FOREACH_CLIENT(IS_PLAYER(it), {
1374 if(SAME_TEAM(it, this))
1375 if(it.havocbot_role_flags & HAVOCBOT_ONS_ROLE_OFFENSE)
1376 if(it.havocbot_ons_target == cp2)
1380 // NOTE: probably decrease the cost of attackable control points
1382 cp2.wpconsidered = true;
1385 // We'll consider only the best case
1386 bestvalue = 99999999999;
1388 for(cp1 = ons_worldcplist; cp1; cp1 = cp1.ons_worldcpnext)
1390 if (!cp1.wpconsidered)
1393 if(cp1.wpcost<bestvalue)
1395 bestvalue = cp1.wpcost;
1397 this.havocbot_ons_target = cp1;
1404 LOG_DEBUG(this.netname, " chose cp ranked ", ftos(bestvalue));
1408 // Should be attacked
1409 // Rate waypoints near it
1412 bestvalue = 99999999999;
1413 for(radius=0; radius<1000 && !found; radius+=500)
1415 for(wp=findradius(cp.origin,radius); wp; wp=wp.chain)
1417 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
1418 if(wp.classname=="waypoint")
1419 if(checkpvs(wp.origin,cp))
1422 if(wp.cnt<bestvalue)
1433 navigation_routerating(this, best, ratingscale, 10000);
1436 this.havocbot_attack_time = 0;
1437 if(checkpvs(this.view_ofs,cp))
1438 if(checkpvs(this.view_ofs,best))
1439 this.havocbot_attack_time = time + 2;
1443 navigation_routerating(this, cp, ratingscale, 10000);
1445 LOG_DEBUG(this.netname, " found an attackable controlpoint at ", vtos(cp.origin));
1449 // Should be touched
1450 LOG_DEBUG(this.netname, " found a touchable controlpoint at ", vtos(cp.origin));
1453 // Look for auto generated waypoint
1454 if (!bot_waypoints_for_items)
1455 for (wp = findradius(cp.origin,100); wp; wp = wp.chain)
1457 if(wp.classname=="waypoint")
1459 navigation_routerating(this, wp, ratingscale, 10000);
1464 // Nothing found, rate the controlpoint itself
1466 navigation_routerating(this, cp, ratingscale, 10000);
1470 bool havocbot_goalrating_ons_generator_attack(entity this, float ratingscale)
1472 entity g, wp, bestwp;
1476 for(g = ons_worldgeneratorlist; g; g = g.ons_worldgeneratornext)
1478 if(SAME_TEAM(g, this) || g.isshielded)
1481 // Should be attacked
1482 // Rate waypoints near it
1487 for(wp=findradius(g.origin,400); wp; wp=wp.chain)
1489 if(wp.classname=="waypoint")
1490 if(checkpvs(wp.origin,g))
1503 LOG_DEBUG("waypoints found around generator");
1504 navigation_routerating(this, bestwp, ratingscale, 10000);
1507 this.havocbot_attack_time = 0;
1508 if(checkpvs(this.view_ofs,g))
1509 if(checkpvs(this.view_ofs,bestwp))
1510 this.havocbot_attack_time = time + 5;
1516 LOG_DEBUG("generator found without waypoints around");
1517 // if there aren't waypoints near the generator go straight to it
1518 navigation_routerating(this, g, ratingscale, 10000);
1519 this.havocbot_attack_time = 0;
1526 void havocbot_role_ons_offense(entity this)
1530 this.havocbot_attack_time = 0;
1531 havocbot_ons_reset_role(this);
1535 // Set the role timeout if necessary
1536 if (!this.havocbot_role_timeout)
1537 this.havocbot_role_timeout = time + 120;
1539 if (time > this.havocbot_role_timeout)
1541 havocbot_ons_reset_role(this);
1545 if(this.havocbot_attack_time>time)
1548 if (this.bot_strategytime < time)
1550 navigation_goalrating_start(this);
1551 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
1552 if(!havocbot_goalrating_ons_generator_attack(this, 20000))
1553 havocbot_goalrating_ons_controlpoints_attack(this, 20000);
1554 havocbot_goalrating_ons_offenseitems(this, 10000, this.origin, 10000);
1555 navigation_goalrating_end(this);
1557 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
1561 void havocbot_role_ons_assistant(entity this)
1563 havocbot_ons_reset_role(this);
1566 void havocbot_role_ons_defense(entity this)
1568 havocbot_ons_reset_role(this);
1571 void havocbot_ons_reset_role(entity this)
1576 this.havocbot_ons_target = NULL;
1578 // TODO: Defend control points or generator if necessary
1580 havocbot_role_ons_setrole(this, HAVOCBOT_ONS_ROLE_OFFENSE);
1585 * Find control point or generator owned by the same team self which is nearest to pos
1586 * if max_dist is positive, only control points within this range will be considered
1588 entity ons_Nearest_ControlPoint(entity this, vector pos, float max_dist)
1590 entity closest_target = NULL;
1591 FOREACH_ENTITY_CLASS("onslaught_controlpoint", true,
1593 if(SAME_TEAM(it, this))
1595 if(max_dist <= 0 || vdist(it.origin - pos, <=, max_dist))
1596 if(vlen2(it.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
1597 closest_target = it;
1599 FOREACH_ENTITY_CLASS("onslaught_generator", true,
1601 if(SAME_TEAM(it, this))
1602 if(max_dist <= 0 || vdist(it.origin - pos, <, max_dist))
1603 if(vlen2(it.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
1604 closest_target = it;
1607 return closest_target;
1611 * Find control point or generator owned by the same team self which is nearest to pos
1612 * if max_dist is positive, only control points within this range will be considered
1613 * This function only check distances on the XY plane, disregarding Z
1615 entity ons_Nearest_ControlPoint_2D(entity this, vector pos, float max_dist)
1617 entity closest_target = NULL;
1619 float smallest_distance = 0, distance;
1621 FOREACH_ENTITY_CLASS("onslaught_controlpoint", true,
1623 delta = it.origin - pos;
1625 distance = vlen(delta);
1627 if(SAME_TEAM(it, this))
1629 if(max_dist <= 0 || distance <= max_dist)
1630 if(closest_target == NULL || distance <= smallest_distance )
1632 closest_target = it;
1633 smallest_distance = distance;
1636 FOREACH_ENTITY_CLASS("onslaught_generator", true,
1638 delta = it.origin - pos;
1640 distance = vlen(delta);
1642 if(SAME_TEAM(it, this))
1643 if(max_dist <= 0 || distance <= max_dist)
1644 if(closest_target == NULL || distance <= smallest_distance )
1646 closest_target = it;
1647 smallest_distance = distance;
1651 return closest_target;
1654 * find the number of control points and generators in the same team as this
1656 int ons_Count_SelfControlPoints(entity this)
1659 FOREACH_ENTITY_CLASS("onslaught_controlpoint", true,
1661 if(SAME_TEAM(it, this))
1665 FOREACH_ENTITY_CLASS("onslaught_generator", true,
1667 if(SAME_TEAM(it, this))
1674 * Teleport player to a random position near tele_target
1675 * if tele_effects is true, teleport sound+particles are created
1676 * return false on failure
1678 bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effects)
1686 // narrow the range for each iteration to increase chances that a spawnpoint
1687 // can be found even if there's little room around the control point
1688 float iteration_scale = 1;
1689 for(i = 0; i < 16; ++i)
1691 iteration_scale -= i / 16;
1692 theta = random() * 2 * M_PI;
1696 loc *= random() * range * iteration_scale;
1698 loc += tele_target.origin + '0 0 128' * iteration_scale;
1700 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
1701 if(trace_fraction == 1.0 && !trace_startsolid)
1703 traceline(tele_target.origin, loc, MOVE_NOMONSTERS, tele_target); // double check to make sure we're not spawning outside the NULL
1704 if(trace_fraction == 1.0 && !trace_startsolid)
1708 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
1709 sound (player, CH_TRIGGER, SND_TELEPORT, VOL_BASE, ATTEN_NORM);
1711 setorigin(player, loc);
1712 player.angles = '0 1 0' * ( theta * RAD2DEG + 180 );
1713 makevectors(player.angles);
1714 player.fixangle = true;
1715 player.teleport_antispam = time + autocvar_g_onslaught_teleport_wait;
1718 Send_Effect(EFFECT_TELEPORT, player.origin + v_forward * 32, '0 0 0', 1);
1731 MUTATOR_HOOKFUNCTION(ons, reset_map_global)
1733 FOREACH_CLIENT(IS_PLAYER(it), {
1734 STAT(ROUNDLOST, it) = false;
1735 it.ons_deathloc = '0 0 0';
1736 PutClientInServer(it);
1741 MUTATOR_HOOKFUNCTION(ons, ClientDisconnect)
1743 entity player = M_ARGV(0, entity);
1745 player.ons_deathloc = '0 0 0';
1748 MUTATOR_HOOKFUNCTION(ons, MakePlayerObserver)
1750 entity player = M_ARGV(0, entity);
1752 player.ons_deathloc = '0 0 0';
1755 MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
1757 entity player = M_ARGV(0, entity);
1759 if(!round_handler_IsRoundStarted())
1761 player.player_blocked = true;
1766 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1768 l.sprite.SendFlags |= 16;
1770 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1772 l.sprite.SendFlags |= 16;
1775 if(ons_stalemate) { Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); }
1777 if ( autocvar_g_onslaught_spawn_choose )
1778 if ( player.ons_spawn_by )
1779 if ( ons_Teleport(player,player.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) )
1781 player.ons_spawn_by = NULL;
1785 if(autocvar_g_onslaught_spawn_at_controlpoints)
1786 if(random() <= autocvar_g_onslaught_spawn_at_controlpoints_chance)
1788 float random_target = autocvar_g_onslaught_spawn_at_controlpoints_random;
1789 entity tmp_entity, closest_target = NULL;
1790 vector spawn_loc = player.ons_deathloc;
1792 // new joining player or round reset, don't bother checking
1793 if(spawn_loc == '0 0 0') { return false; }
1795 if(random_target) { RandomSelection_Init(); }
1797 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1799 if(SAME_TEAM(tmp_entity, player))
1801 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1802 else if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL)
1803 closest_target = tmp_entity;
1806 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1812 float iteration_scale = 1;
1813 for(i = 0; i < 10; ++i)
1815 iteration_scale -= i / 10;
1816 loc = closest_target.origin + '0 0 96' * iteration_scale;
1817 loc += ('0 1 0' * random()) * 128 * iteration_scale;
1818 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
1819 if(trace_fraction == 1.0 && !trace_startsolid)
1821 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL
1822 if(trace_fraction == 1.0 && !trace_startsolid)
1824 setorigin(player, loc);
1825 player.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1833 if(autocvar_g_onslaught_spawn_at_generator)
1834 if(random() <= autocvar_g_onslaught_spawn_at_generator_chance)
1836 float random_target = autocvar_g_onslaught_spawn_at_generator_random;
1837 entity tmp_entity, closest_target = NULL;
1838 vector spawn_loc = player.ons_deathloc;
1840 // new joining player or round reset, don't bother checking
1841 if(spawn_loc == '0 0 0') { return false; }
1843 if(random_target) { RandomSelection_Init(); }
1845 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1848 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1851 if(SAME_TEAM(tmp_entity, player))
1852 if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL)
1853 closest_target = tmp_entity;
1857 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1863 float iteration_scale = 1;
1864 for(i = 0; i < 10; ++i)
1866 iteration_scale -= i / 10;
1867 loc = closest_target.origin + '0 0 128' * iteration_scale;
1868 loc += ('0 1 0' * random()) * 256 * iteration_scale;
1869 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
1870 if(trace_fraction == 1.0 && !trace_startsolid)
1872 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL
1873 if(trace_fraction == 1.0 && !trace_startsolid)
1875 setorigin(player, loc);
1876 player.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1887 MUTATOR_HOOKFUNCTION(ons, PlayerDies)
1889 entity frag_target = M_ARGV(2, entity);
1891 frag_target.ons_deathloc = frag_target.origin;
1893 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1895 l.sprite.SendFlags |= 16;
1897 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1899 l.sprite.SendFlags |= 16;
1902 if ( autocvar_g_onslaught_spawn_choose )
1903 if ( ons_Count_SelfControlPoints(frag_target) > 1 )
1904 stuffcmd(frag_target, "qc_cmd_cl hud clickradar\n");
1909 MUTATOR_HOOKFUNCTION(ons, MonsterMove)
1911 entity mon = M_ARGV(0, entity);
1913 entity e = find(NULL, targetname, mon.target);
1918 void ons_MonsterSpawn_Delayed(entity this)
1920 entity own = this.owner;
1922 if(!own) { delete(this); return; }
1926 entity e = find(NULL, target, own.targetname);
1931 own.use(own, e, NULL);
1938 MUTATOR_HOOKFUNCTION(ons, MonsterSpawn)
1940 entity mon = M_ARGV(0, entity);
1944 InitializeEntity(e, ons_MonsterSpawn_Delayed, INITPRIO_FINDTARGET);
1947 void ons_TurretSpawn_Delayed(entity this)
1949 entity own = this.owner;
1951 if(!own) { delete(this); return; }
1955 entity e = find(NULL, target, own.targetname);
1959 own.active = ACTIVE_NOT;
1961 own.use(own, e, NULL);
1968 MUTATOR_HOOKFUNCTION(ons, TurretSpawn)
1970 entity turret = M_ARGV(0, entity);
1974 InitializeEntity(e, ons_TurretSpawn_Delayed, INITPRIO_FINDTARGET);
1979 MUTATOR_HOOKFUNCTION(ons, HavocBot_ChooseRole)
1981 entity bot = M_ARGV(0, entity);
1983 havocbot_ons_reset_role(bot);
1987 MUTATOR_HOOKFUNCTION(ons, GetTeamCount)
1989 // onslaught is special
1990 for(entity tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1992 switch(tmp_entity.team)
1994 case NUM_TEAM_1: c1 = 0; break;
1995 case NUM_TEAM_2: c2 = 0; break;
1996 case NUM_TEAM_3: c3 = 0; break;
1997 case NUM_TEAM_4: c4 = 0; break;
2004 MUTATOR_HOOKFUNCTION(ons, SpectateCopy)
2006 entity spectatee = M_ARGV(0, entity);
2007 entity client = M_ARGV(1, entity);
2009 STAT(ROUNDLOST, client) = STAT(ROUNDLOST, spectatee); // make spectators see it too
2012 MUTATOR_HOOKFUNCTION(ons, SV_ParseClientCommand)
2014 if(MUTATOR_RETURNVALUE) // command was already handled?
2017 entity player = M_ARGV(0, entity);
2018 string cmd_name = M_ARGV(1, string);
2019 int cmd_argc = M_ARGV(2, int);
2021 if ( cmd_name == "ons_spawn" )
2023 vector pos = player.origin;
2025 pos_x = stof(argv(1));
2027 pos_y = stof(argv(2));
2029 pos_z = stof(argv(3));
2031 if ( IS_PLAYER(player) )
2033 if ( !STAT(FROZEN, player) )
2035 entity source_point = ons_Nearest_ControlPoint(player, player.origin, autocvar_g_onslaught_teleport_radius);
2037 if ( !source_point && player.health > 0 )
2039 sprint(player, "\nYou need to be next to a control point\n");
2044 entity closest_target = ons_Nearest_ControlPoint_2D(player, pos, autocvar_g_onslaught_click_radius);
2046 if ( closest_target == NULL )
2048 sprint(player, "\nNo control point found\n");
2052 if ( player.health <= 0 )
2054 player.ons_spawn_by = closest_target;
2055 player.respawn_flags = player.respawn_flags | RESPAWN_FORCE;
2059 if ( source_point == closest_target )
2061 sprint(player, "\nTeleporting to the same point\n");
2065 if ( !ons_Teleport(player,closest_target,autocvar_g_onslaught_teleport_radius,true) )
2066 sprint(player, "\nUnable to teleport there\n");
2072 sprint(player, "\nNo teleportation for you\n");
2080 MUTATOR_HOOKFUNCTION(ons, PlayerUseKey)
2082 if(MUTATOR_RETURNVALUE || gameover) { return false; }
2084 entity player = M_ARGV(0, entity);
2086 if((time > player.teleport_antispam) && (!IS_DEAD(player)) && !player.vehicle)
2088 entity source_point = ons_Nearest_ControlPoint(player, player.origin, autocvar_g_onslaught_teleport_radius);
2091 stuffcmd(player, "qc_cmd_cl hud clickradar\n");
2097 MUTATOR_HOOKFUNCTION(ons, PlayHitsound)
2099 entity frag_victim = M_ARGV(0, entity);
2101 return (frag_victim.classname == "onslaught_generator" && !frag_victim.isshielded)
2102 || (frag_victim.classname == "onslaught_controlpoint_icon" && !frag_victim.owner.isshielded);
2105 MUTATOR_HOOKFUNCTION(ons, SendWaypoint)
2107 entity wp = M_ARGV(0, entity);
2108 entity to = M_ARGV(1, entity);
2109 int sf = M_ARGV(2, int);
2110 int wp_flag = M_ARGV(3, int);
2114 if(wp.owner.classname == "onslaught_controlpoint")
2116 entity wp_owner = wp.owner;
2117 entity e = WaypointSprite_getviewentity(to);
2118 if(SAME_TEAM(e, wp_owner) && wp_owner.goalentity.health >= wp_owner.goalentity.max_health) { wp_flag |= 2; }
2119 if(!ons_ControlPoint_Attackable(wp_owner, e.team)) { wp_flag |= 2; }
2121 if(wp.owner.classname == "onslaught_generator")
2123 entity wp_owner = wp.owner;
2124 if(wp_owner.isshielded && wp_owner.health >= wp_owner.max_health) { wp_flag |= 2; }
2125 if(wp_owner.health <= 0) { wp_flag |= 2; }
2129 M_ARGV(3, int) = wp_flag;
2132 MUTATOR_HOOKFUNCTION(ons, TurretValidateTarget)
2134 entity turret_target = M_ARGV(1, entity);
2136 if(substring(turret_target.classname, 0, 10) == "onslaught_") // don't attack onslaught targets, that's the player's job!
2138 M_ARGV(3, float) = -3;
2145 MUTATOR_HOOKFUNCTION(ons, TurretThink)
2147 entity turret = M_ARGV(0, entity);
2149 // ONS uses somewhat backwards linking.
2152 entity e = find(NULL, targetname, turret.target);
2154 turret.team = e.team;
2157 if(turret.team != turret.tur_head.team)
2158 turret_respawn(turret);
2166 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
2167 Link between control points.
2169 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.
2172 "target" - first control point.
2173 "target2" - second control point.
2175 spawnfunc(onslaught_link)
2177 if(!g_onslaught) { delete(this); return; }
2179 if (this.target == "" || this.target2 == "")
2180 objerror(this, "target and target2 must be set\n");
2182 this.ons_worldlinknext = ons_worldlinklist; // link into ons_worldlinklist
2183 ons_worldlinklist = this;
2185 InitializeEntity(this, ons_DelayedLinkSetup, INITPRIO_FINDTARGET);
2186 Net_LinkEntity(this, false, 0, ons_Link_Send);
2189 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
2190 Control point. Be sure to give this enough clearance so that the shootable part has room to exist
2192 This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
2195 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2196 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
2197 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
2200 spawnfunc(onslaught_controlpoint)
2202 if(!g_onslaught) { delete(this); return; }
2204 ons_ControlPoint_Setup(this);
2207 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
2210 spawnfunc_onslaught_link entities can target this.
2213 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
2214 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2216 spawnfunc(onslaught_generator)
2218 if(!g_onslaught) { delete(this); return; }
2219 if(!this.team) { objerror(this, "team must be set"); }
2221 ons_GeneratorSetup(this);
2225 void ons_ScoreRules()
2227 CheckAllowedTeams(NULL);
2229 if(c1 >= 0) teams |= BIT(0);
2230 if(c2 >= 0) teams |= BIT(1);
2231 if(c3 >= 0) teams |= BIT(2);
2232 if(c4 >= 0) teams |= BIT(3);
2233 ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, 0, true);
2234 ScoreInfo_SetLabel_TeamScore (ST_ONS_CAPS, "destroyed", SFL_SORT_PRIO_PRIMARY);
2235 ScoreInfo_SetLabel_PlayerScore(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
2236 ScoreInfo_SetLabel_PlayerScore(SP_ONS_TAKES, "takes", 0);
2237 ScoreRules_basics_end();
2240 void ons_DelayedInit(entity this) // Do this check with a delay so we can wait for teams to be set up
2244 round_handler_Spawn(Onslaught_CheckPlayers, Onslaught_CheckWinner, Onslaught_RoundStart);
2245 round_handler_Init(5, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
2248 void ons_Initialize()
2251 ons_captureshield_force = autocvar_g_onslaught_shield_force;
2253 InitializeEntity(NULL, ons_DelayedInit, INITPRIO_GAMETYPE);