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;
79 .bool ons_roundlost = _STAT(ROUNDLOST);
82 .entity bot_basewaypoint; // generator waypointsprite
84 .bool isgenneighbor[17];
85 .bool iscpneighbor[17];
86 float ons_notification_time[17];
88 .float ons_overtime_damagedelay;
94 // declarations for functions used outside gamemode_onslaught.qc
95 void ons_Generator_UpdateSprite(entity e);
96 void ons_ControlPoint_UpdateSprite(entity e);
97 bool ons_ControlPoint_Attackable(entity cp, int teamnumber);
99 // CaptureShield: Prevent capturing or destroying control point/generator if it is not available yet
100 float ons_captureshield_force; // push force of the shield
103 const int HAVOCBOT_ONS_ROLE_NONE = 0;
104 const int HAVOCBOT_ONS_ROLE_DEFENSE = 2;
105 const int HAVOCBOT_ONS_ROLE_ASSISTANT = 4;
106 const int HAVOCBOT_ONS_ROLE_OFFENSE = 8;
108 .entity havocbot_ons_target;
110 .int havocbot_role_flags;
111 .float havocbot_attack_time;
113 void havocbot_role_ons_defense(entity this);
114 void havocbot_role_ons_offense(entity this);
115 void havocbot_role_ons_assistant(entity this);
117 void havocbot_ons_reset_role(entity this);
118 void havocbot_goalrating_items(entity this, float ratingscale, vector org, float sradius);
119 void havocbot_goalrating_enemyplayers(entity this, float ratingscale, vector org, float sradius);
121 // score rule declarations
122 const int ST_ONS_CAPS = 1;
123 const int SP_ONS_CAPS = 4;
124 const int SP_ONS_TAKES = 6;
129 #ifdef IMPLEMENTATION
131 #include "sv_controlpoint.qh"
132 #include "sv_generator.qh"
136 float autocvar_g_onslaught_teleport_wait;
137 bool autocvar_g_onslaught_spawn_at_controlpoints;
138 bool autocvar_g_onslaught_spawn_at_generator;
139 float autocvar_g_onslaught_cp_proxydecap;
140 float autocvar_g_onslaught_cp_proxydecap_distance = 512;
141 float autocvar_g_onslaught_cp_proxydecap_dps = 100;
142 float autocvar_g_onslaught_spawn_at_controlpoints_chance = 0.5;
143 float autocvar_g_onslaught_spawn_at_controlpoints_random;
144 float autocvar_g_onslaught_spawn_at_generator_chance;
145 float autocvar_g_onslaught_spawn_at_generator_random;
146 float autocvar_g_onslaught_cp_buildhealth;
147 float autocvar_g_onslaught_cp_buildtime;
148 float autocvar_g_onslaught_cp_health;
149 float autocvar_g_onslaught_cp_regen;
150 float autocvar_g_onslaught_gen_health;
151 float autocvar_g_onslaught_shield_force = 100;
152 float autocvar_g_onslaught_allow_vehicle_touch;
153 float autocvar_g_onslaught_round_timelimit;
154 float autocvar_g_onslaught_warmup;
155 float autocvar_g_onslaught_teleport_radius;
156 float autocvar_g_onslaught_spawn_choose;
157 float autocvar_g_onslaught_click_radius;
159 void FixSize(entity e);
161 // =======================
162 // CaptureShield Functions
163 // =======================
165 bool ons_CaptureShield_Customize(entity this, entity client)
167 entity e = WaypointSprite_getviewentity(client);
169 if(!this.enemy.isshielded && (ons_ControlPoint_Attackable(this.enemy, e.team) > 0 || this.enemy.classname != "onslaught_controlpoint")) { return false; }
170 if(SAME_TEAM(this, e)) { return false; }
175 void ons_CaptureShield_Touch(entity this, entity toucher)
177 if(!this.enemy.isshielded && (ons_ControlPoint_Attackable(this.enemy, toucher.team) > 0 || this.enemy.classname != "onslaught_controlpoint")) { return; }
178 if(!IS_PLAYER(toucher)) { return; }
179 if(SAME_TEAM(toucher, this)) { return; }
181 vector mymid = (this.absmin + this.absmax) * 0.5;
182 vector theirmid = (toucher.absmin + toucher.absmax) * 0.5;
184 Damage(toucher, this, this, 0, DEATH_HURTTRIGGER.m_id, mymid, normalize(theirmid - mymid) * ons_captureshield_force);
186 if(IS_REAL_CLIENT(toucher))
188 play2(toucher, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
190 if(this.enemy.classname == "onslaught_generator")
191 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_GENERATOR_SHIELDED);
193 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_CONTROLPOINT_SHIELDED);
197 void ons_CaptureShield_Reset(entity this)
199 this.colormap = this.enemy.colormap;
200 this.team = this.enemy.team;
203 void ons_CaptureShield_Spawn(entity generator, bool is_generator)
205 entity shield = new(ons_captureshield);
207 shield.enemy = generator;
208 shield.team = generator.team;
209 shield.colormap = generator.colormap;
210 shield.reset = ons_CaptureShield_Reset;
211 settouch(shield, ons_CaptureShield_Touch);
212 setcefc(shield, ons_CaptureShield_Customize);
213 shield.effects = EF_ADDITIVE;
214 shield.movetype = MOVETYPE_NOCLIP;
215 shield.solid = SOLID_TRIGGER;
216 shield.avelocity = '7 0 11';
218 shield.model = ((is_generator) ? "models/onslaught/generator_shield.md3" : "models/onslaught/controlpoint_shield.md3");
220 precache_model(shield.model);
221 setorigin(shield, generator.origin);
222 _setmodel(shield, shield.model);
223 setsize(shield, shield.scale * shield.mins, shield.scale * shield.maxs);
231 void setmodel_fixsize(entity e, Model m)
237 void onslaught_updatelinks()
240 // first check if the game has ended
241 LOG_DEBUG("--- updatelinks ---\n");
242 // mark generators as being shielded and networked
243 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
246 LOG_DEBUG(strcat(etos(l), " (generator) belongs to team ", ftos(l.team), "\n"));
248 LOG_DEBUG(strcat(etos(l), " (generator) is destroyed\n"));
249 l.islinked = l.iscaptured;
250 l.isshielded = l.iscaptured;
251 l.sprite.SendFlags |= 16;
253 // mark points as shielded and not networked
254 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
259 for(i = 0; i < 17; ++i) { l.isgenneighbor[i] = false; l.iscpneighbor[i] = false; }
260 LOG_DEBUG(strcat(etos(l), " (point) belongs to team ", ftos(l.team), "\n"));
261 l.sprite.SendFlags |= 16;
263 // flow power outward from the generators through the network
268 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
270 // if both points are captured by the same team, and only one of
271 // them is powered, mark the other one as powered as well
272 if (l.enemy.iscaptured && l.goalentity.iscaptured)
273 if (l.enemy.islinked != l.goalentity.islinked)
274 if(SAME_TEAM(l.enemy, l.goalentity))
276 if (!l.goalentity.islinked)
279 l.goalentity.islinked = true;
280 LOG_DEBUG(strcat(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)\n"));
282 else if (!l.enemy.islinked)
285 l.enemy.islinked = true;
286 LOG_DEBUG(strcat(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)\n"));
291 // now that we know which points are powered we can mark their neighbors
292 // as unshielded if team differs
293 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
295 if (l.goalentity.islinked)
297 if(DIFF_TEAM(l.goalentity, l.enemy))
299 LOG_DEBUG(strcat(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)\n"));
300 l.enemy.isshielded = false;
302 if(l.goalentity.classname == "onslaught_generator")
303 l.enemy.isgenneighbor[l.goalentity.team] = true;
305 l.enemy.iscpneighbor[l.goalentity.team] = true;
307 if (l.enemy.islinked)
309 if(DIFF_TEAM(l.goalentity, l.enemy))
311 LOG_DEBUG(strcat(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)\n"));
312 l.goalentity.isshielded = false;
314 if(l.enemy.classname == "onslaught_generator")
315 l.goalentity.isgenneighbor[l.enemy.team] = true;
317 l.goalentity.iscpneighbor[l.enemy.team] = true;
320 // now update the generators
321 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
325 LOG_DEBUG(strcat(etos(l), " (generator) is shielded\n"));
326 l.takedamage = DAMAGE_NO;
327 l.bot_attack = false;
331 LOG_DEBUG(strcat(etos(l), " (generator) is not shielded\n"));
332 l.takedamage = DAMAGE_AIM;
336 ons_Generator_UpdateSprite(l);
338 // now update the takedamage and alpha variables on control point icons
339 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
343 LOG_DEBUG(strcat(etos(l), " (point) is shielded\n"));
346 l.goalentity.takedamage = DAMAGE_NO;
347 l.goalentity.bot_attack = false;
352 LOG_DEBUG(strcat(etos(l), " (point) is not shielded\n"));
355 l.goalentity.takedamage = DAMAGE_AIM;
356 l.goalentity.bot_attack = true;
359 ons_ControlPoint_UpdateSprite(l);
361 l = findchain(classname, "ons_captureshield");
364 l.team = l.enemy.team;
365 l.colormap = l.enemy.colormap;
371 // ===================
372 // Main Link Functions
373 // ===================
375 bool ons_Link_Send(entity this, entity to, int sendflags)
377 WriteHeader(MSG_ENTITY, ENT_CLIENT_RADARLINK);
378 WriteByte(MSG_ENTITY, sendflags);
381 WriteCoord(MSG_ENTITY, this.goalentity.origin_x);
382 WriteCoord(MSG_ENTITY, this.goalentity.origin_y);
383 WriteCoord(MSG_ENTITY, this.goalentity.origin_z);
387 WriteCoord(MSG_ENTITY, this.enemy.origin_x);
388 WriteCoord(MSG_ENTITY, this.enemy.origin_y);
389 WriteCoord(MSG_ENTITY, this.enemy.origin_z);
393 WriteByte(MSG_ENTITY, this.clientcolors); // which is goalentity's color + enemy's color * 16
398 void ons_Link_CheckUpdate(entity this)
400 // TODO check if the two sides have moved (currently they won't move anyway)
401 float cc = 0, cc1 = 0, cc2 = 0;
403 if(this.goalentity.islinked || this.goalentity.iscaptured) { cc1 = (this.goalentity.team - 1) * 0x01; }
404 if(this.enemy.islinked || this.enemy.iscaptured) { cc2 = (this.enemy.team - 1) * 0x10; }
408 if(cc != this.clientcolors)
410 this.clientcolors = cc;
414 this.nextthink = time;
417 void ons_DelayedLinkSetup(entity this)
419 this.goalentity = find(NULL, targetname, this.target);
420 this.enemy = find(NULL, targetname, this.target2);
421 if(!this.goalentity) { objerror(this, "can not find target\n"); }
422 if(!this.enemy) { objerror(this, "can not find target2\n"); }
424 LOG_DEBUG(strcat(etos(this.goalentity), " linked with ", etos(this.enemy), "\n"));
426 setthink(this, ons_Link_CheckUpdate);
427 this.nextthink = time;
431 // =============================
432 // Main Control Point Functions
433 // =============================
435 int ons_ControlPoint_CanBeLinked(entity cp, int teamnumber)
437 if(cp.isgenneighbor[teamnumber]) { return 2; }
438 if(cp.iscpneighbor[teamnumber]) { return 1; }
443 int ons_ControlPoint_Attackable(entity cp, int teamnumber)
444 // -2: SAME TEAM, attackable by enemy!
449 // 3: attack it (HIGH PRIO)
450 // 4: touch it (HIGH PRIO)
458 else if(cp.goalentity)
460 // if there's already an icon built, nothing happens
461 if(cp.team == teamnumber)
463 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
464 if(a) // attackable by enemy?
465 return -2; // EMERGENCY!
468 // we know it can be linked, so no need to check
470 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
471 if(a == 2) // near our generator?
472 return 3; // EMERGENCY!
478 if(ons_ControlPoint_CanBeLinked(cp, teamnumber))
480 a = ons_ControlPoint_CanBeLinked(cp, teamnumber); // why was this here NUM_TEAM_1 + NUM_TEAM_2 - t
482 return 4; // GET THIS ONE NOW!
484 return 2; // TOUCH ME
490 void ons_ControlPoint_Icon_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
492 if(damage <= 0) { return; }
494 if (this.owner.isshielded)
496 // this is protected by a shield, so ignore the damage
497 if (time > this.pain_finished)
498 if (IS_PLAYER(attacker))
500 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
501 this.pain_finished = time + 1;
502 attacker.typehitsound += 1; // play both sounds (shield is way too quiet)
508 if(IS_PLAYER(attacker))
509 if(time - ons_notification_time[this.team] > 10)
511 play2team(this.team, SND(ONS_CONTROLPOINT_UNDERATTACK));
512 ons_notification_time[this.team] = time;
515 this.health = this.health - damage;
516 if(this.owner.iscaptured)
517 WaypointSprite_UpdateHealth(this.owner.sprite, this.health);
519 WaypointSprite_UpdateBuildFinished(this.owner.sprite, time + (this.max_health - this.health) / (this.count / ONS_CP_THINKRATE));
520 this.pain_finished = time + 1;
521 // particles on every hit
522 pointparticles(EFFECT_SPARKS, hitloc, force*-1, 1);
525 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE+0.3, ATTEN_NORM);
527 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE+0.3, ATTEN_NORM);
531 sound(this, CH_TRIGGER, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
532 pointparticles(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
533 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_CPDESTROYED), this.owner.message, attacker.netname);
535 PlayerScore_Add(attacker, SP_ONS_TAKES, 1);
536 PlayerScore_Add(attacker, SP_SCORE, 10);
538 this.owner.goalentity = NULL;
539 this.owner.islinked = false;
540 this.owner.iscaptured = false;
542 this.owner.colormap = 1024;
544 WaypointSprite_UpdateMaxHealth(this.owner.sprite, 0);
546 onslaught_updatelinks();
548 // Use targets now (somebody make sure this is in the right place..)
549 SUB_UseTargets(this.owner, this, NULL);
551 this.owner.waslinked = this.owner.islinked;
552 if(this.owner.model != "models/onslaught/controlpoint_pad.md3")
553 setmodel_fixsize(this.owner, MDL_ONS_CP_PAD1);
554 //setsize(this, '-32 -32 0', '32 32 8');
559 this.SendFlags |= CPSF_STATUS;
562 void ons_ControlPoint_Icon_Think(entity this)
564 this.nextthink = time + ONS_CP_THINKRATE;
566 if(autocvar_g_onslaught_cp_proxydecap)
568 int _enemy_count = 0;
569 int _friendly_count = 0;
571 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it), {
572 if(vdist(it.origin - this.origin, <, autocvar_g_onslaught_cp_proxydecap_distance))
574 if(SAME_TEAM(it, this))
581 _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
582 _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
584 this.health = bound(0, this.health + (_friendly_count - _enemy_count), this.max_health);
585 this.SendFlags |= CPSF_STATUS;
588 ons_ControlPoint_Icon_Damage(this, this, this, 1, 0, this.origin, '0 0 0');
593 if (time > this.pain_finished + 5)
595 if(this.health < this.max_health)
597 this.health = this.health + this.count;
598 if (this.health >= this.max_health)
599 this.health = this.max_health;
600 WaypointSprite_UpdateHealth(this.owner.sprite, this.health);
604 if(this.owner.islinked != this.owner.waslinked)
606 // unteam the spawnpoint if needed
607 int t = this.owner.team;
608 if(!this.owner.islinked)
611 SUB_UseTargets(this.owner, this, NULL);
615 this.owner.waslinked = this.owner.islinked;
619 if(random() < 0.6 - this.health / this.max_health)
621 Send_Effect(EFFECT_ELECTRIC_SPARKS, this.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
624 sound(this, CH_PAIN, SND_ONS_SPARK1, VOL_BASE, ATTEN_NORM);
625 else if (random() > 0.5)
626 sound(this, CH_PAIN, SND_ONS_SPARK2, VOL_BASE, ATTEN_NORM);
630 void ons_ControlPoint_Icon_BuildThink(entity this)
634 this.nextthink = time + ONS_CP_THINKRATE;
636 // only do this if there is power
637 a = ons_ControlPoint_CanBeLinked(this.owner, this.owner.team);
641 this.health = this.health + this.count;
643 this.SendFlags |= CPSF_STATUS;
645 if (this.health >= this.max_health)
647 this.health = this.max_health;
648 this.count = autocvar_g_onslaught_cp_regen * ONS_CP_THINKRATE; // slow repair rate from now on
649 setthink(this, ons_ControlPoint_Icon_Think);
650 sound(this, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILT, VOL_BASE, ATTEN_NORM);
651 this.owner.iscaptured = true;
652 this.solid = SOLID_BBOX;
654 Send_Effect(EFFECT_CAP(this.owner.team), this.owner.origin, '0 0 0', 1);
656 WaypointSprite_UpdateMaxHealth(this.owner.sprite, this.max_health);
657 WaypointSprite_UpdateHealth(this.owner.sprite, this.health);
659 if(IS_PLAYER(this.owner.ons_toucher))
661 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ONSLAUGHT_CAPTURE, this.owner.ons_toucher.netname, this.owner.message);
662 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);
663 Send_Notification(NOTIF_ONE, this.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE, this.owner.message);
664 PlayerScore_Add(this.owner.ons_toucher, SP_ONS_CAPS, 1);
665 PlayerTeamScore_AddScore(this.owner.ons_toucher, 10);
668 this.owner.ons_toucher = NULL;
670 onslaught_updatelinks();
672 // Use targets now (somebody make sure this is in the right place..)
673 SUB_UseTargets(this.owner, this, NULL);
675 this.SendFlags |= CPSF_SETUP;
677 if(this.owner.model != MDL_ONS_CP_PAD2.model_str())
678 setmodel_fixsize(this.owner, MDL_ONS_CP_PAD2);
680 if(random() < 0.9 - this.health / this.max_health)
681 Send_Effect(EFFECT_RAGE, this.origin + 10 * randomvec(), '0 0 -1', 1);
684 void onslaught_controlpoint_icon_link(entity e, void(entity this) spawnproc);
686 void ons_ControlPoint_Icon_Spawn(entity cp, entity player)
688 entity e = new(onslaught_controlpoint_icon);
690 setsize(e, CPICON_MIN, CPICON_MAX);
691 setorigin(e, cp.origin + CPICON_OFFSET);
694 e.max_health = autocvar_g_onslaught_cp_health;
695 e.health = autocvar_g_onslaught_cp_buildhealth;
697 e.takedamage = DAMAGE_AIM;
699 e.event_damage = ons_ControlPoint_Icon_Damage;
700 e.team = player.team;
701 e.colormap = 1024 + (e.team - 1) * 17;
702 e.count = (e.max_health - e.health) * ONS_CP_THINKRATE / autocvar_g_onslaught_cp_buildtime; // how long it takes to build
704 sound(e, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILD, VOL_BASE, ATTEN_NORM);
708 cp.colormap = e.colormap;
710 Send_Effect(EFFECT_FLAG_TOUCH(player.team), e.origin, '0 0 0', 1);
712 WaypointSprite_UpdateBuildFinished(cp.sprite, time + (e.max_health - e.health) / (e.count / ONS_CP_THINKRATE));
713 WaypointSprite_UpdateRule(cp.sprite,cp.team,SPRITERULE_TEAMPLAY);
714 cp.sprite.SendFlags |= 16;
716 onslaught_controlpoint_icon_link(e, ons_ControlPoint_Icon_BuildThink);
719 entity ons_ControlPoint_Waypoint(entity e)
723 int a = ons_ControlPoint_Attackable(e, e.team);
725 if(a == -2) { return WP_OnsCPDefend; } // defend now
726 if(a == -1 || a == 1 || a == 2) { return WP_OnsCP; } // touch
727 if(a == 3 || a == 4) { return WP_OnsCPAttack; } // attack
735 void ons_ControlPoint_UpdateSprite(entity e)
737 entity s1 = ons_ControlPoint_Waypoint(e);
738 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
741 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));
743 if(e.lastteam != e.team + 2 || e.lastshielded != sh || e.iscaptured != e.lastcaptured)
745 if(e.iscaptured) // don't mess up build bars!
749 WaypointSprite_UpdateMaxHealth(e.sprite, 0);
753 WaypointSprite_UpdateMaxHealth(e.sprite, e.goalentity.max_health);
754 WaypointSprite_UpdateHealth(e.sprite, e.goalentity.health);
760 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, false));
762 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
767 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, false));
769 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
771 WaypointSprite_Ping(e.sprite);
773 e.lastteam = e.team + 2;
775 e.lastcaptured = e.iscaptured;
779 void ons_ControlPoint_Touch(entity this, entity toucher)
783 if(IS_VEHICLE(toucher) && toucher.owner)
784 if(autocvar_g_onslaught_allow_vehicle_touch)
785 toucher = toucher.owner;
789 if(!IS_PLAYER(toucher)) { return; }
790 if(STAT(FROZEN, toucher)) { return; }
791 if(IS_DEAD(toucher)) { return; }
793 if ( SAME_TEAM(this,toucher) )
794 if ( this.iscaptured )
796 if(time <= toucher.teleport_antispam)
797 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT_ANTISPAM, rint(toucher.teleport_antispam - time));
799 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
802 attackable = ons_ControlPoint_Attackable(this, toucher.team);
803 if(attackable != 2 && attackable != 4)
805 // we've verified that this player has a legitimate claim to this point,
806 // so start building the captured point icon (which only captures this
807 // point if it successfully builds without being destroyed first)
808 ons_ControlPoint_Icon_Spawn(this, toucher);
810 this.ons_toucher = toucher;
812 onslaught_updatelinks();
815 void ons_ControlPoint_Think(entity this)
817 this.nextthink = time + ONS_CP_THINKRATE;
818 CSQCMODEL_AUTOUPDATE(this);
821 void ons_ControlPoint_Reset(entity this)
824 remove(this.goalentity);
826 this.goalentity = NULL;
828 this.colormap = 1024;
829 this.iscaptured = false;
830 this.islinked = false;
831 this.isshielded = true;
832 setthink(this, ons_ControlPoint_Think);
833 this.ons_toucher = NULL;
834 this.nextthink = time + ONS_CP_THINKRATE;
835 setmodel_fixsize(this, MDL_ONS_CP_PAD1);
837 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
838 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
840 onslaught_updatelinks();
842 SUB_UseTargets(this, this, NULL); // to reset the structures, playerspawns etc.
844 CSQCMODEL_AUTOUPDATE(this);
847 void ons_DelayedControlPoint_Setup(entity this)
849 onslaught_updatelinks();
851 // captureshield setup
852 ons_CaptureShield_Spawn(this, false);
854 CSQCMODEL_AUTOINIT(this);
857 void ons_ControlPoint_Setup(entity cp)
860 cp.ons_worldcpnext = ons_worldcplist; // link control point into ons_worldcplist
861 ons_worldcplist = cp;
863 cp.netname = "Control point";
865 cp.solid = SOLID_BBOX;
866 cp.movetype = MOVETYPE_NONE;
867 settouch(cp, ons_ControlPoint_Touch);
868 setthink(cp, ons_ControlPoint_Think);
869 cp.nextthink = time + ONS_CP_THINKRATE;
870 cp.reset = ons_ControlPoint_Reset;
872 cp.iscaptured = false;
874 cp.isshielded = true;
876 if(cp.message == "") { cp.message = "a"; }
879 setmodel_fixsize(cp, MDL_ONS_CP_PAD1);
881 // control point placement
882 if((cp.spawnflags & 1) || cp.noalign) // don't drop to floor, just stay at fixed location
885 cp.movetype = MOVETYPE_NONE;
887 else // drop to floor, automatically find a platform and set that as spawn origin
889 setorigin(cp, cp.origin + '0 0 20');
892 cp.movetype = MOVETYPE_TOSS;
896 WaypointSprite_SpawnFixed(WP_Null, cp.origin + CPGEN_WAYPOINT_OFFSET, cp, sprite, RADARICON_NONE);
897 WaypointSprite_UpdateRule(cp.sprite, cp.team, SPRITERULE_TEAMPLAY);
899 InitializeEntity(cp, ons_DelayedControlPoint_Setup, INITPRIO_SETLOCATION);
903 // =========================
904 // Main Generator Functions
905 // =========================
907 entity ons_Generator_Waypoint(entity e)
910 return WP_OnsGenShielded;
914 void ons_Generator_UpdateSprite(entity e)
916 entity s1 = ons_Generator_Waypoint(e);
917 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
919 if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
921 e.lastteam = e.team + 2;
922 e.lastshielded = e.isshielded;
926 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, false));
928 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
933 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, false));
935 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
937 WaypointSprite_Ping(e.sprite);
941 void ons_GeneratorDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
943 if(damage <= 0) { return; }
944 if(warmup_stage || gameover) { return; }
945 if(!round_handler_IsRoundStarted()) { return; }
947 if (attacker != this)
951 // this is protected by a shield, so ignore the damage
952 if (time > this.pain_finished)
953 if (IS_PLAYER(attacker))
955 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
956 attacker.typehitsound += 1;
957 this.pain_finished = time + 1;
961 if (time > this.pain_finished)
963 this.pain_finished = time + 10;
964 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && SAME_TEAM(it, this), Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK));
965 play2team(this.team, SND(ONS_GENERATOR_UNDERATTACK));
968 this.health = this.health - damage;
969 WaypointSprite_UpdateHealth(this.sprite, this.health);
970 // choose an animation frame based on health
971 this.frame = 10 * bound(0, (1 - this.health / this.max_health), 1);
972 // see if the generator is still functional, or dying
975 this.lasthealth = this.health;
979 if (attacker == this)
980 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME));
983 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED));
984 PlayerScore_Add(attacker, SP_SCORE, 100);
986 this.iscaptured = false;
987 this.islinked = false;
988 this.isshielded = false;
989 this.takedamage = DAMAGE_NO; // can't be hurt anymore
990 this.event_damage = func_null; // won't do anything if hurt
991 this.count = 0; // reset counter
992 setthink(this, func_null);
994 //this.think(); // do the first explosion now
996 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
997 WaypointSprite_Ping(this.sprite);
998 //WaypointSprite_Kill(this.sprite); // can't do this yet, code too poor
1000 onslaught_updatelinks();
1003 // Throw some flaming gibs on damage, more damage = more chance for gib
1004 if(random() < damage/220)
1006 sound(this, CH_TRIGGER, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
1010 // particles on every hit
1011 Send_Effect(EFFECT_SPARKS, hitloc, force * -1, 1);
1013 //sound on every hit
1015 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE, ATTEN_NORM);
1017 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE, ATTEN_NORM);
1020 this.SendFlags |= GSF_STATUS;
1023 void ons_GeneratorThink(entity this)
1025 this.nextthink = time + GEN_THINKRATE;
1028 if(!this.isshielded && this.wait < time)
1030 this.wait = time + 5;
1031 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
1032 if(SAME_TEAM(it, this))
1034 Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM);
1035 soundto(MSG_ONE, it, CHAN_AUTO, SND(KH_ALARM), VOL_BASE, ATTEN_NONE); // FIXME: unique sound?
1038 Send_Notification(NOTIF_ONE, it, MSG_CENTER, APP_TEAM_NUM(this.team, CENTER_ONS_NOTSHIELDED));
1044 void ons_GeneratorReset(entity this)
1046 this.team = this.team_saved;
1047 this.lasthealth = this.max_health = this.health = autocvar_g_onslaught_gen_health;
1048 this.takedamage = DAMAGE_AIM;
1049 this.bot_attack = true;
1050 this.iscaptured = true;
1051 this.islinked = true;
1052 this.isshielded = true;
1053 this.event_damage = ons_GeneratorDamage;
1054 setthink(this, ons_GeneratorThink);
1055 this.nextthink = time + GEN_THINKRATE;
1057 Net_LinkEntity(this, false, 0, generator_send);
1059 this.SendFlags = GSF_SETUP; // just incase
1060 this.SendFlags |= GSF_STATUS;
1062 WaypointSprite_UpdateMaxHealth(this.sprite, this.max_health);
1063 WaypointSprite_UpdateHealth(this.sprite, this.health);
1064 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
1066 onslaught_updatelinks();
1069 void ons_DelayedGeneratorSetup(entity this)
1072 waypoint_spawnforitem_force(this, this.origin);
1073 this.nearestwaypointtimeout = 0; // activate waypointing again
1074 this.bot_basewaypoint = this.nearestwaypoint;
1076 // captureshield setup
1077 ons_CaptureShield_Spawn(this, true);
1079 onslaught_updatelinks();
1081 Net_LinkEntity(this, false, 0, generator_send);
1085 void onslaught_generator_touch(entity this, entity toucher)
1087 if ( IS_PLAYER(toucher) )
1088 if ( SAME_TEAM(this,toucher) )
1089 if ( this.iscaptured )
1091 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
1095 void ons_GeneratorSetup(entity gen) // called when spawning a generator entity on the map as a spawnfunc
1098 int teamnumber = gen.team;
1101 gen.ons_worldgeneratornext = ons_worldgeneratorlist; // link generator into ons_worldgeneratorlist
1102 ons_worldgeneratorlist = gen;
1104 gen.netname = sprintf("%s generator", Team_ColoredFullName(teamnumber));
1105 gen.classname = "onslaught_generator";
1106 gen.solid = SOLID_BBOX;
1107 gen.team_saved = teamnumber;
1108 gen.movetype = MOVETYPE_NONE;
1109 gen.lasthealth = gen.max_health = gen.health = autocvar_g_onslaught_gen_health;
1110 gen.takedamage = DAMAGE_AIM;
1111 gen.bot_attack = true;
1112 gen.event_damage = ons_GeneratorDamage;
1113 gen.reset = ons_GeneratorReset;
1114 setthink(gen, ons_GeneratorThink);
1115 gen.nextthink = time + GEN_THINKRATE;
1116 gen.iscaptured = true;
1117 gen.islinked = true;
1118 gen.isshielded = true;
1119 settouch(gen, onslaught_generator_touch);
1122 // model handled by CSQC
1123 setsize(gen, GENERATOR_MIN, GENERATOR_MAX);
1124 setorigin(gen, (gen.origin + CPGEN_SPAWN_OFFSET));
1125 gen.colormap = 1024 + (teamnumber - 1) * 17;
1127 // generator placement
1131 WaypointSprite_SpawnFixed(WP_Null, gen.origin + CPGEN_WAYPOINT_OFFSET, gen, sprite, RADARICON_NONE);
1132 WaypointSprite_UpdateRule(gen.sprite, gen.team, SPRITERULE_TEAMPLAY);
1133 WaypointSprite_UpdateMaxHealth(gen.sprite, gen.max_health);
1134 WaypointSprite_UpdateHealth(gen.sprite, gen.health);
1136 InitializeEntity(gen, ons_DelayedGeneratorSetup, INITPRIO_SETLOCATION);
1144 int total_generators;
1145 void Onslaught_count_generators()
1148 total_generators = redowned = blueowned = yellowowned = pinkowned = 0;
1149 for(e = ons_worldgeneratorlist; e; e = e.ons_worldgeneratornext)
1152 redowned += (e.team == NUM_TEAM_1 && e.health > 0);
1153 blueowned += (e.team == NUM_TEAM_2 && e.health > 0);
1154 yellowowned += (e.team == NUM_TEAM_3 && e.health > 0);
1155 pinkowned += (e.team == NUM_TEAM_4 && e.health > 0);
1159 int Onslaught_GetWinnerTeam()
1161 int winner_team = 0;
1163 winner_team = NUM_TEAM_1;
1166 if(winner_team) return 0;
1167 winner_team = NUM_TEAM_2;
1171 if(winner_team) return 0;
1172 winner_team = NUM_TEAM_3;
1176 if(winner_team) return 0;
1177 winner_team = NUM_TEAM_4;
1181 return -1; // no generators left?
1184 void nades_Clear(entity e);
1186 #define ONS_OWNED_GENERATORS() ((redowned > 0) + (blueowned > 0) + (yellowowned > 0) + (pinkowned > 0))
1187 #define ONS_OWNED_GENERATORS_OK() (ONS_OWNED_GENERATORS() > 1)
1188 bool Onslaught_CheckWinner()
1190 if ((autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60) || (round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0))
1192 ons_stalemate = true;
1194 if (!wpforenemy_announced)
1196 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT);
1197 sound(NULL, CH_INFO, SND_ONS_GENERATOR_DECAY, VOL_BASE, ATTEN_NONE);
1199 wpforenemy_announced = true;
1202 entity tmp_entity; // temporary entity
1204 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext) if(time >= tmp_entity.ons_overtime_damagedelay)
1206 // tmp_entity.max_health / 300 gives 5 minutes of overtime.
1207 // control points reduce the overtime duration.
1210 for(e = ons_worldcplist; e; e = e.ons_worldcpnext)
1212 if(DIFF_TEAM(e, tmp_entity))
1217 if(autocvar_g_campaign && autocvar__campaign_testrun)
1218 d = d * tmp_entity.max_health;
1220 d = d * tmp_entity.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
1222 Damage(tmp_entity, tmp_entity, tmp_entity, d, DEATH_HURTTRIGGER.m_id, tmp_entity.origin, '0 0 0');
1224 tmp_entity.sprite.SendFlags |= 16;
1226 tmp_entity.ons_overtime_damagedelay = time + 1;
1229 else { wpforenemy_announced = false; ons_stalemate = false; }
1231 Onslaught_count_generators();
1233 if(ONS_OWNED_GENERATORS_OK())
1236 int winner_team = Onslaught_GetWinnerTeam();
1240 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
1241 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
1242 TeamScore_AddToTeam(winner_team, ST_ONS_CAPS, +1);
1244 else if(winner_team == -1)
1246 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_TIED);
1247 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_TIED);
1250 ons_stalemate = false;
1252 play2all(SND(CTF_CAPTURE(winner_team)));
1254 round_handler_Init(7, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
1256 FOREACH_CLIENT(IS_PLAYER(it), {
1257 it.ons_roundlost = true;
1258 it.player_blocked = true;
1266 bool Onslaught_CheckPlayers()
1271 void Onslaught_RoundStart()
1274 FOREACH_CLIENT(IS_PLAYER(it), it.player_blocked = false);
1276 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1277 tmp_entity.sprite.SendFlags |= 16;
1279 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1280 tmp_entity.sprite.SendFlags |= 16;
1288 // NOTE: LEGACY CODE, needs to be re-written!
1290 void havocbot_goalrating_ons_offenseitems(entity this, float ratingscale, vector org, float sradius)
1294 bool needarmor = false, needweapons = false;
1296 // Needs armor/health?
1302 FOREACH(Weapons, it != WEP_Null, {
1303 if(this.weapons & (it.m_wepset))
1311 if(!needweapons && !needarmor)
1314 LOG_DEBUG(strcat(this.netname, " needs weapons ", ftos(needweapons) , "\n"));
1315 LOG_DEBUG(strcat(this.netname, " needs armor ", ftos(needarmor) , "\n"));
1317 // See what is around
1318 head = findchainfloat(bot_pickup, true);
1321 // gather health and armor only
1323 if ( ((head.health || head.armorvalue) && needarmor) || (head.weapons && needweapons ) )
1324 if (vdist(head.origin - org, <, sradius))
1326 t = head.bot_pickupevalfunc(this, head);
1328 navigation_routerating(this, head, t * ratingscale, 500);
1334 void havocbot_role_ons_setrole(entity this, int role)
1336 LOG_DEBUG(strcat(this.netname," switched to "));
1339 case HAVOCBOT_ONS_ROLE_DEFENSE:
1340 LOG_DEBUG("defense");
1341 this.havocbot_role = havocbot_role_ons_defense;
1342 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE;
1343 this.havocbot_role_timeout = 0;
1345 case HAVOCBOT_ONS_ROLE_ASSISTANT:
1346 LOG_DEBUG("assistant");
1347 this.havocbot_role = havocbot_role_ons_assistant;
1348 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT;
1349 this.havocbot_role_timeout = 0;
1351 case HAVOCBOT_ONS_ROLE_OFFENSE:
1352 LOG_DEBUG("offense");
1353 this.havocbot_role = havocbot_role_ons_offense;
1354 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE;
1355 this.havocbot_role_timeout = 0;
1361 void havocbot_goalrating_ons_controlpoints_attack(entity this, float ratingscale)
1363 entity cp, cp1, cp2, best, wp;
1364 float radius, bestvalue;
1368 // Filter control points
1369 for(cp2 = ons_worldcplist; cp2; cp2 = cp2.ons_worldcpnext)
1372 cp2.wpconsidered = false;
1377 // Ignore owned controlpoints
1378 if(!(cp2.isgenneighbor[this.team] || cp2.iscpneighbor[this.team]))
1381 // Count team mates interested in this control point
1382 // (easier and cleaner than keeping counters per cp and teams)
1383 FOREACH_CLIENT(IS_PLAYER(it), {
1384 if(SAME_TEAM(it, this))
1385 if(it.havocbot_role_flags & HAVOCBOT_ONS_ROLE_OFFENSE)
1386 if(it.havocbot_ons_target == cp2)
1390 // NOTE: probably decrease the cost of attackable control points
1392 cp2.wpconsidered = true;
1395 // We'll consider only the best case
1396 bestvalue = 99999999999;
1398 for(cp1 = ons_worldcplist; cp1; cp1 = cp1.ons_worldcpnext)
1400 if (!cp1.wpconsidered)
1403 if(cp1.wpcost<bestvalue)
1405 bestvalue = cp1.wpcost;
1407 this.havocbot_ons_target = cp1;
1414 LOG_DEBUG(strcat(this.netname, " chose cp ranked ", ftos(bestvalue), "\n"));
1418 // Should be attacked
1419 // Rate waypoints near it
1422 bestvalue = 99999999999;
1423 for(radius=0; radius<1000 && !found; radius+=500)
1425 for(wp=findradius(cp.origin,radius); wp; wp=wp.chain)
1427 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
1428 if(wp.classname=="waypoint")
1429 if(checkpvs(wp.origin,cp))
1432 if(wp.cnt<bestvalue)
1443 navigation_routerating(this, best, ratingscale, 10000);
1446 this.havocbot_attack_time = 0;
1447 if(checkpvs(this.view_ofs,cp))
1448 if(checkpvs(this.view_ofs,best))
1449 this.havocbot_attack_time = time + 2;
1453 navigation_routerating(this, cp, ratingscale, 10000);
1455 LOG_DEBUG(strcat(this.netname, " found an attackable controlpoint at ", vtos(cp.origin) ,"\n"));
1459 // Should be touched
1460 LOG_DEBUG(strcat(this.netname, " found a touchable controlpoint at ", vtos(cp.origin) ,"\n"));
1463 // Look for auto generated waypoint
1464 if (!bot_waypoints_for_items)
1465 for (wp = findradius(cp.origin,100); wp; wp = wp.chain)
1467 if(wp.classname=="waypoint")
1469 navigation_routerating(this, wp, ratingscale, 10000);
1474 // Nothing found, rate the controlpoint itself
1476 navigation_routerating(this, cp, ratingscale, 10000);
1480 bool havocbot_goalrating_ons_generator_attack(entity this, float ratingscale)
1482 entity g, wp, bestwp;
1486 for(g = ons_worldgeneratorlist; g; g = g.ons_worldgeneratornext)
1488 if(SAME_TEAM(g, this) || g.isshielded)
1491 // Should be attacked
1492 // Rate waypoints near it
1497 for(wp=findradius(g.origin,400); wp; wp=wp.chain)
1499 if(wp.classname=="waypoint")
1500 if(checkpvs(wp.origin,g))
1513 LOG_DEBUG("waypoints found around generator\n");
1514 navigation_routerating(this, bestwp, ratingscale, 10000);
1517 this.havocbot_attack_time = 0;
1518 if(checkpvs(this.view_ofs,g))
1519 if(checkpvs(this.view_ofs,bestwp))
1520 this.havocbot_attack_time = time + 5;
1526 LOG_DEBUG("generator found without waypoints around\n");
1527 // if there aren't waypoints near the generator go straight to it
1528 navigation_routerating(this, g, ratingscale, 10000);
1529 this.havocbot_attack_time = 0;
1536 void havocbot_role_ons_offense(entity this)
1540 this.havocbot_attack_time = 0;
1541 havocbot_ons_reset_role(this);
1545 // Set the role timeout if necessary
1546 if (!this.havocbot_role_timeout)
1547 this.havocbot_role_timeout = time + 120;
1549 if (time > this.havocbot_role_timeout)
1551 havocbot_ons_reset_role(this);
1555 if(this.havocbot_attack_time>time)
1558 if (this.bot_strategytime < time)
1560 navigation_goalrating_start(this);
1561 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
1562 if(!havocbot_goalrating_ons_generator_attack(this, 20000))
1563 havocbot_goalrating_ons_controlpoints_attack(this, 20000);
1564 havocbot_goalrating_ons_offenseitems(this, 10000, this.origin, 10000);
1565 navigation_goalrating_end(this);
1567 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
1571 void havocbot_role_ons_assistant(entity this)
1573 havocbot_ons_reset_role(this);
1576 void havocbot_role_ons_defense(entity this)
1578 havocbot_ons_reset_role(this);
1581 void havocbot_ons_reset_role(entity this)
1586 this.havocbot_ons_target = NULL;
1588 // TODO: Defend control points or generator if necessary
1590 havocbot_role_ons_setrole(this, HAVOCBOT_ONS_ROLE_OFFENSE);
1595 * Find control point or generator owned by the same team self which is nearest to pos
1596 * if max_dist is positive, only control points within this range will be considered
1598 entity ons_Nearest_ControlPoint(entity this, vector pos, float max_dist)
1600 entity tmp_entity, closest_target = NULL;
1601 tmp_entity = findchain(classname, "onslaught_controlpoint");
1604 if(SAME_TEAM(tmp_entity, this))
1605 if(tmp_entity.iscaptured)
1606 if(max_dist <= 0 || vdist(tmp_entity.origin - pos, <=, max_dist))
1607 if(vlen2(tmp_entity.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
1608 closest_target = tmp_entity;
1609 tmp_entity = tmp_entity.chain;
1611 tmp_entity = findchain(classname, "onslaught_generator");
1614 if(SAME_TEAM(tmp_entity, this))
1615 if(max_dist <= 0 || vdist(tmp_entity.origin - pos, <, max_dist))
1616 if(vlen2(tmp_entity.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
1617 closest_target = tmp_entity;
1618 tmp_entity = tmp_entity.chain;
1621 return closest_target;
1625 * Find control point or generator owned by the same team self which is nearest to pos
1626 * if max_dist is positive, only control points within this range will be considered
1627 * This function only check distances on the XY plane, disregarding Z
1629 entity ons_Nearest_ControlPoint_2D(entity this, vector pos, float max_dist)
1631 entity tmp_entity, closest_target = NULL;
1633 float smallest_distance = 0, distance;
1635 tmp_entity = findchain(classname, "onslaught_controlpoint");
1638 delta = tmp_entity.origin - pos;
1640 distance = vlen(delta);
1642 if(SAME_TEAM(tmp_entity, this))
1643 if(tmp_entity.iscaptured)
1644 if(max_dist <= 0 || distance <= max_dist)
1645 if(closest_target == NULL || distance <= smallest_distance )
1647 closest_target = tmp_entity;
1648 smallest_distance = distance;
1651 tmp_entity = tmp_entity.chain;
1653 tmp_entity = findchain(classname, "onslaught_generator");
1656 delta = tmp_entity.origin - pos;
1658 distance = vlen(delta);
1660 if(SAME_TEAM(tmp_entity, this))
1661 if(max_dist <= 0 || distance <= max_dist)
1662 if(closest_target == NULL || distance <= smallest_distance )
1664 closest_target = tmp_entity;
1665 smallest_distance = distance;
1668 tmp_entity = tmp_entity.chain;
1671 return closest_target;
1674 * find the number of control points and generators in the same team as this
1676 int ons_Count_SelfControlPoints(entity this)
1679 tmp_entity = findchain(classname, "onslaught_controlpoint");
1683 if(SAME_TEAM(tmp_entity, this))
1684 if(tmp_entity.iscaptured)
1686 tmp_entity = tmp_entity.chain;
1688 tmp_entity = findchain(classname, "onslaught_generator");
1691 if(SAME_TEAM(tmp_entity, this))
1693 tmp_entity = tmp_entity.chain;
1699 * Teleport player to a random position near tele_target
1700 * if tele_effects is true, teleport sound+particles are created
1701 * return false on failure
1703 bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effects)
1711 // narrow the range for each iteration to increase chances that a spawnpoint
1712 // can be found even if there's little room around the control point
1713 float iteration_scale = 1;
1714 for(i = 0; i < 16; ++i)
1716 iteration_scale -= i / 16;
1717 theta = random() * 2 * M_PI;
1721 loc *= random() * range * iteration_scale;
1723 loc += tele_target.origin + '0 0 128' * iteration_scale;
1725 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
1726 if(trace_fraction == 1.0 && !trace_startsolid)
1728 traceline(tele_target.origin, loc, MOVE_NOMONSTERS, tele_target); // double check to make sure we're not spawning outside the NULL
1729 if(trace_fraction == 1.0 && !trace_startsolid)
1733 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
1734 sound (player, CH_TRIGGER, SND_TELEPORT, VOL_BASE, ATTEN_NORM);
1736 setorigin(player, loc);
1737 player.angles = '0 1 0' * ( theta * RAD2DEG + 180 );
1738 makevectors(player.angles);
1739 player.fixangle = true;
1740 player.teleport_antispam = time + autocvar_g_onslaught_teleport_wait;
1743 Send_Effect(EFFECT_TELEPORT, player.origin + v_forward * 32, '0 0 0', 1);
1756 MUTATOR_HOOKFUNCTION(ons, reset_map_global)
1758 FOREACH_CLIENT(IS_PLAYER(it), {
1759 it.ons_roundlost = false;
1760 it.ons_deathloc = '0 0 0';
1761 PutClientInServer(it);
1766 MUTATOR_HOOKFUNCTION(ons, ClientDisconnect)
1768 entity player = M_ARGV(0, entity);
1770 player.ons_deathloc = '0 0 0';
1773 MUTATOR_HOOKFUNCTION(ons, MakePlayerObserver)
1775 entity player = M_ARGV(0, entity);
1777 player.ons_deathloc = '0 0 0';
1780 MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
1782 entity player = M_ARGV(0, entity);
1784 if(!round_handler_IsRoundStarted())
1786 player.player_blocked = true;
1791 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1793 l.sprite.SendFlags |= 16;
1795 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1797 l.sprite.SendFlags |= 16;
1800 if(ons_stalemate) { Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); }
1802 if ( autocvar_g_onslaught_spawn_choose )
1803 if ( player.ons_spawn_by )
1804 if ( ons_Teleport(player,player.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) )
1806 player.ons_spawn_by = NULL;
1810 if(autocvar_g_onslaught_spawn_at_controlpoints)
1811 if(random() <= autocvar_g_onslaught_spawn_at_controlpoints_chance)
1813 float random_target = autocvar_g_onslaught_spawn_at_controlpoints_random;
1814 entity tmp_entity, closest_target = NULL;
1815 vector spawn_loc = player.ons_deathloc;
1817 // new joining player or round reset, don't bother checking
1818 if(spawn_loc == '0 0 0') { return false; }
1820 if(random_target) { RandomSelection_Init(); }
1822 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1824 if(SAME_TEAM(tmp_entity, player))
1826 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1827 else if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL)
1828 closest_target = tmp_entity;
1831 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1837 float iteration_scale = 1;
1838 for(i = 0; i < 10; ++i)
1840 iteration_scale -= i / 10;
1841 loc = closest_target.origin + '0 0 96' * iteration_scale;
1842 loc += ('0 1 0' * random()) * 128 * iteration_scale;
1843 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
1844 if(trace_fraction == 1.0 && !trace_startsolid)
1846 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL
1847 if(trace_fraction == 1.0 && !trace_startsolid)
1849 setorigin(player, loc);
1850 player.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1858 if(autocvar_g_onslaught_spawn_at_generator)
1859 if(random() <= autocvar_g_onslaught_spawn_at_generator_chance)
1861 float random_target = autocvar_g_onslaught_spawn_at_generator_random;
1862 entity tmp_entity, closest_target = NULL;
1863 vector spawn_loc = player.ons_deathloc;
1865 // new joining player or round reset, don't bother checking
1866 if(spawn_loc == '0 0 0') { return false; }
1868 if(random_target) { RandomSelection_Init(); }
1870 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1873 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1876 if(SAME_TEAM(tmp_entity, player))
1877 if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL)
1878 closest_target = tmp_entity;
1882 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1888 float iteration_scale = 1;
1889 for(i = 0; i < 10; ++i)
1891 iteration_scale -= i / 10;
1892 loc = closest_target.origin + '0 0 128' * iteration_scale;
1893 loc += ('0 1 0' * random()) * 256 * iteration_scale;
1894 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
1895 if(trace_fraction == 1.0 && !trace_startsolid)
1897 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL
1898 if(trace_fraction == 1.0 && !trace_startsolid)
1900 setorigin(player, loc);
1901 player.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1912 MUTATOR_HOOKFUNCTION(ons, PlayerDies)
1914 entity frag_target = M_ARGV(2, entity);
1916 frag_target.ons_deathloc = frag_target.origin;
1918 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1920 l.sprite.SendFlags |= 16;
1922 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1924 l.sprite.SendFlags |= 16;
1927 if ( autocvar_g_onslaught_spawn_choose )
1928 if ( ons_Count_SelfControlPoints(frag_target) > 1 )
1929 stuffcmd(frag_target, "qc_cmd_cl hud clickradar\n");
1934 MUTATOR_HOOKFUNCTION(ons, MonsterMove)
1936 entity mon = M_ARGV(0, entity);
1938 entity e = find(NULL, targetname, mon.target);
1943 void ons_MonsterSpawn_Delayed(entity this)
1945 entity own = this.owner;
1947 if(!own) { remove(this); return; }
1951 entity e = find(NULL, target, own.targetname);
1956 own.use(own, e, NULL);
1963 MUTATOR_HOOKFUNCTION(ons, MonsterSpawn)
1965 entity mon = M_ARGV(0, entity);
1969 InitializeEntity(e, ons_MonsterSpawn_Delayed, INITPRIO_FINDTARGET);
1972 void ons_TurretSpawn_Delayed(entity this)
1974 entity own = this.owner;
1976 if(!own) { remove(this); return; }
1980 entity e = find(NULL, target, own.targetname);
1984 own.active = ACTIVE_NOT;
1986 own.use(own, e, NULL);
1993 MUTATOR_HOOKFUNCTION(ons, TurretSpawn)
1995 entity turret = M_ARGV(0, entity);
1999 InitializeEntity(e, ons_TurretSpawn_Delayed, INITPRIO_FINDTARGET);
2004 MUTATOR_HOOKFUNCTION(ons, HavocBot_ChooseRole)
2006 entity bot = M_ARGV(0, entity);
2008 havocbot_ons_reset_role(bot);
2012 MUTATOR_HOOKFUNCTION(ons, GetTeamCount)
2014 // onslaught is special
2015 for(entity tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
2017 switch(tmp_entity.team)
2019 case NUM_TEAM_1: c1 = 0; break;
2020 case NUM_TEAM_2: c2 = 0; break;
2021 case NUM_TEAM_3: c3 = 0; break;
2022 case NUM_TEAM_4: c4 = 0; break;
2029 MUTATOR_HOOKFUNCTION(ons, SpectateCopy)
2031 entity spectatee = M_ARGV(0, entity);
2032 entity client = M_ARGV(1, entity);
2034 client.ons_roundlost = spectatee.ons_roundlost; // make spectators see it too
2037 MUTATOR_HOOKFUNCTION(ons, SV_ParseClientCommand)
2039 if(MUTATOR_RETURNVALUE) // command was already handled?
2042 entity player = M_ARGV(0, entity);
2043 string cmd_name = M_ARGV(1, string);
2044 int cmd_argc = M_ARGV(2, int);
2046 if ( cmd_name == "ons_spawn" )
2048 vector pos = player.origin;
2050 pos_x = stof(argv(1));
2052 pos_y = stof(argv(2));
2054 pos_z = stof(argv(3));
2056 if ( IS_PLAYER(player) )
2058 if ( !STAT(FROZEN, player) )
2060 entity source_point = ons_Nearest_ControlPoint(player, player.origin, autocvar_g_onslaught_teleport_radius);
2062 if ( !source_point && player.health > 0 )
2064 sprint(player, "\nYou need to be next to a control point\n");
2069 entity closest_target = ons_Nearest_ControlPoint_2D(player, pos, autocvar_g_onslaught_click_radius);
2071 if ( closest_target == NULL )
2073 sprint(player, "\nNo control point found\n");
2077 if ( player.health <= 0 )
2079 player.ons_spawn_by = closest_target;
2080 player.respawn_flags = player.respawn_flags | RESPAWN_FORCE;
2084 if ( source_point == closest_target )
2086 sprint(player, "\nTeleporting to the same point\n");
2090 if ( !ons_Teleport(player,closest_target,autocvar_g_onslaught_teleport_radius,true) )
2091 sprint(player, "\nUnable to teleport there\n");
2097 sprint(player, "\nNo teleportation for you\n");
2105 MUTATOR_HOOKFUNCTION(ons, PlayerUseKey)
2107 if(MUTATOR_RETURNVALUE || gameover) { return false; }
2109 entity player = M_ARGV(0, entity);
2111 if((time > player.teleport_antispam) && (!IS_DEAD(player)) && !player.vehicle)
2113 entity source_point = ons_Nearest_ControlPoint(player, player.origin, autocvar_g_onslaught_teleport_radius);
2116 stuffcmd(player, "qc_cmd_cl hud clickradar\n");
2122 MUTATOR_HOOKFUNCTION(ons, PlayHitsound)
2124 entity frag_victim = M_ARGV(0, entity);
2126 return (frag_victim.classname == "onslaught_generator" && !frag_victim.isshielded)
2127 || (frag_victim.classname == "onslaught_controlpoint_icon" && !frag_victim.owner.isshielded);
2130 MUTATOR_HOOKFUNCTION(ons, SendWaypoint)
2132 entity wp = M_ARGV(0, entity);
2133 entity to = M_ARGV(1, entity);
2134 int sf = M_ARGV(2, int);
2135 int wp_flag = M_ARGV(3, int);
2139 if(wp.owner.classname == "onslaught_controlpoint")
2141 entity wp_owner = wp.owner;
2142 entity e = WaypointSprite_getviewentity(to);
2143 if(SAME_TEAM(e, wp_owner) && wp_owner.goalentity.health >= wp_owner.goalentity.max_health) { wp_flag |= 2; }
2144 if(!ons_ControlPoint_Attackable(wp_owner, e.team)) { wp_flag |= 2; }
2146 if(wp.owner.classname == "onslaught_generator")
2148 entity wp_owner = wp.owner;
2149 if(wp_owner.isshielded && wp_owner.health >= wp_owner.max_health) { wp_flag |= 2; }
2150 if(wp_owner.health <= 0) { wp_flag |= 2; }
2154 M_ARGV(3, int) = wp_flag;
2157 MUTATOR_HOOKFUNCTION(ons, TurretValidateTarget)
2159 entity turret_target = M_ARGV(1, entity);
2161 if(substring(turret_target.classname, 0, 10) == "onslaught_") // don't attack onslaught targets, that's the player's job!
2163 M_ARGV(3, float) = -3;
2170 MUTATOR_HOOKFUNCTION(ons, TurretThink)
2172 entity turret = M_ARGV(0, entity);
2174 // ONS uses somewhat backwards linking.
2177 entity e = find(NULL, targetname, turret.target);
2179 turret.team = e.team;
2182 if(turret.team != turret.tur_head.team)
2183 turret_respawn(turret);
2191 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
2192 Link between control points.
2194 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.
2197 "target" - first control point.
2198 "target2" - second control point.
2200 spawnfunc(onslaught_link)
2202 if(!g_onslaught) { remove(this); return; }
2204 if (this.target == "" || this.target2 == "")
2205 objerror(this, "target and target2 must be set\n");
2207 this.ons_worldlinknext = ons_worldlinklist; // link into ons_worldlinklist
2208 ons_worldlinklist = this;
2210 InitializeEntity(this, ons_DelayedLinkSetup, INITPRIO_FINDTARGET);
2211 Net_LinkEntity(this, false, 0, ons_Link_Send);
2214 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
2215 Control point. Be sure to give this enough clearance so that the shootable part has room to exist
2217 This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
2220 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2221 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
2222 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
2225 spawnfunc(onslaught_controlpoint)
2227 if(!g_onslaught) { remove(this); return; }
2229 ons_ControlPoint_Setup(this);
2232 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
2235 spawnfunc_onslaught_link entities can target this.
2238 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
2239 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2241 spawnfunc(onslaught_generator)
2243 if(!g_onslaught) { remove(this); return; }
2244 if(!this.team) { objerror(this, "team must be set"); }
2246 ons_GeneratorSetup(this);
2250 void ons_ScoreRules()
2252 CheckAllowedTeams(NULL);
2254 if(c1 >= 0) teams |= BIT(0);
2255 if(c2 >= 0) teams |= BIT(1);
2256 if(c3 >= 0) teams |= BIT(2);
2257 if(c4 >= 0) teams |= BIT(3);
2258 ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, 0, true);
2259 ScoreInfo_SetLabel_TeamScore (ST_ONS_CAPS, "destroyed", SFL_SORT_PRIO_PRIMARY);
2260 ScoreInfo_SetLabel_PlayerScore(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
2261 ScoreInfo_SetLabel_PlayerScore(SP_ONS_TAKES, "takes", 0);
2262 ScoreRules_basics_end();
2265 void ons_DelayedInit(entity this) // Do this check with a delay so we can wait for teams to be set up
2269 round_handler_Spawn(Onslaught_CheckPlayers, Onslaught_CheckWinner, Onslaught_RoundStart);
2270 round_handler_Init(5, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
2273 void ons_Initialize()
2276 ons_captureshield_force = autocvar_g_onslaught_shield_force;
2278 InitializeEntity(NULL, ons_DelayedInit, INITPRIO_GAMETYPE);