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 set_movetype(shield, 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 FOREACH_ENTITY_CLASS("ons_captureshield", true,
363 it.team = it.enemy.team;
364 it.colormap = it.enemy.colormap;
369 // ===================
370 // Main Link Functions
371 // ===================
373 bool ons_Link_Send(entity this, entity to, int sendflags)
375 WriteHeader(MSG_ENTITY, ENT_CLIENT_RADARLINK);
376 WriteByte(MSG_ENTITY, sendflags);
379 WriteCoord(MSG_ENTITY, this.goalentity.origin_x);
380 WriteCoord(MSG_ENTITY, this.goalentity.origin_y);
381 WriteCoord(MSG_ENTITY, this.goalentity.origin_z);
385 WriteCoord(MSG_ENTITY, this.enemy.origin_x);
386 WriteCoord(MSG_ENTITY, this.enemy.origin_y);
387 WriteCoord(MSG_ENTITY, this.enemy.origin_z);
391 WriteByte(MSG_ENTITY, this.clientcolors); // which is goalentity's color + enemy's color * 16
396 void ons_Link_CheckUpdate(entity this)
398 // TODO check if the two sides have moved (currently they won't move anyway)
399 float cc = 0, cc1 = 0, cc2 = 0;
401 if(this.goalentity.islinked || this.goalentity.iscaptured) { cc1 = (this.goalentity.team - 1) * 0x01; }
402 if(this.enemy.islinked || this.enemy.iscaptured) { cc2 = (this.enemy.team - 1) * 0x10; }
406 if(cc != this.clientcolors)
408 this.clientcolors = cc;
412 this.nextthink = time;
415 void ons_DelayedLinkSetup(entity this)
417 this.goalentity = find(NULL, targetname, this.target);
418 this.enemy = find(NULL, targetname, this.target2);
419 if(!this.goalentity) { objerror(this, "can not find target\n"); }
420 if(!this.enemy) { objerror(this, "can not find target2\n"); }
422 LOG_DEBUG(strcat(etos(this.goalentity), " linked with ", etos(this.enemy), "\n"));
424 setthink(this, ons_Link_CheckUpdate);
425 this.nextthink = time;
429 // =============================
430 // Main Control Point Functions
431 // =============================
433 int ons_ControlPoint_CanBeLinked(entity cp, int teamnumber)
435 if(cp.isgenneighbor[teamnumber]) { return 2; }
436 if(cp.iscpneighbor[teamnumber]) { return 1; }
441 int ons_ControlPoint_Attackable(entity cp, int teamnumber)
442 // -2: SAME TEAM, attackable by enemy!
447 // 3: attack it (HIGH PRIO)
448 // 4: touch it (HIGH PRIO)
456 else if(cp.goalentity)
458 // if there's already an icon built, nothing happens
459 if(cp.team == teamnumber)
461 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
462 if(a) // attackable by enemy?
463 return -2; // EMERGENCY!
466 // we know it can be linked, so no need to check
468 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
469 if(a == 2) // near our generator?
470 return 3; // EMERGENCY!
476 if(ons_ControlPoint_CanBeLinked(cp, teamnumber))
478 a = ons_ControlPoint_CanBeLinked(cp, teamnumber); // why was this here NUM_TEAM_1 + NUM_TEAM_2 - t
480 return 4; // GET THIS ONE NOW!
482 return 2; // TOUCH ME
488 void ons_ControlPoint_Icon_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
490 if(damage <= 0) { return; }
492 if (this.owner.isshielded)
494 // this is protected by a shield, so ignore the damage
495 if (time > this.pain_finished)
496 if (IS_PLAYER(attacker))
498 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
499 this.pain_finished = time + 1;
500 attacker.typehitsound += 1; // play both sounds (shield is way too quiet)
506 if(IS_PLAYER(attacker))
507 if(time - ons_notification_time[this.team] > 10)
509 play2team(this.team, SND(ONS_CONTROLPOINT_UNDERATTACK));
510 ons_notification_time[this.team] = time;
513 this.health = this.health - damage;
514 if(this.owner.iscaptured)
515 WaypointSprite_UpdateHealth(this.owner.sprite, this.health);
517 WaypointSprite_UpdateBuildFinished(this.owner.sprite, time + (this.max_health - this.health) / (this.count / ONS_CP_THINKRATE));
518 this.pain_finished = time + 1;
519 // particles on every hit
520 pointparticles(EFFECT_SPARKS, hitloc, force*-1, 1);
523 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE+0.3, ATTEN_NORM);
525 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE+0.3, ATTEN_NORM);
529 sound(this, CH_TRIGGER, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
530 pointparticles(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
531 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_CPDESTROYED), this.owner.message, attacker.netname);
533 PlayerScore_Add(attacker, SP_ONS_TAKES, 1);
534 PlayerScore_Add(attacker, SP_SCORE, 10);
536 this.owner.goalentity = NULL;
537 this.owner.islinked = false;
538 this.owner.iscaptured = false;
540 this.owner.colormap = 1024;
542 WaypointSprite_UpdateMaxHealth(this.owner.sprite, 0);
544 onslaught_updatelinks();
546 // Use targets now (somebody make sure this is in the right place..)
547 SUB_UseTargets(this.owner, this, NULL);
549 this.owner.waslinked = this.owner.islinked;
550 if(this.owner.model != "models/onslaught/controlpoint_pad.md3")
551 setmodel_fixsize(this.owner, MDL_ONS_CP_PAD1);
552 //setsize(this, '-32 -32 0', '32 32 8');
557 this.SendFlags |= CPSF_STATUS;
560 void ons_ControlPoint_Icon_Think(entity this)
562 this.nextthink = time + ONS_CP_THINKRATE;
564 if(autocvar_g_onslaught_cp_proxydecap)
566 int _enemy_count = 0;
567 int _friendly_count = 0;
569 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it), {
570 if(vdist(it.origin - this.origin, <, autocvar_g_onslaught_cp_proxydecap_distance))
572 if(SAME_TEAM(it, this))
579 _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
580 _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
582 this.health = bound(0, this.health + (_friendly_count - _enemy_count), this.max_health);
583 this.SendFlags |= CPSF_STATUS;
586 ons_ControlPoint_Icon_Damage(this, this, this, 1, 0, this.origin, '0 0 0');
591 if (time > this.pain_finished + 5)
593 if(this.health < this.max_health)
595 this.health = this.health + this.count;
596 if (this.health >= this.max_health)
597 this.health = this.max_health;
598 WaypointSprite_UpdateHealth(this.owner.sprite, this.health);
602 if(this.owner.islinked != this.owner.waslinked)
604 // unteam the spawnpoint if needed
605 int t = this.owner.team;
606 if(!this.owner.islinked)
609 SUB_UseTargets(this.owner, this, NULL);
613 this.owner.waslinked = this.owner.islinked;
617 if(random() < 0.6 - this.health / this.max_health)
619 Send_Effect(EFFECT_ELECTRIC_SPARKS, this.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
622 sound(this, CH_PAIN, SND_ONS_SPARK1, VOL_BASE, ATTEN_NORM);
623 else if (random() > 0.5)
624 sound(this, CH_PAIN, SND_ONS_SPARK2, VOL_BASE, ATTEN_NORM);
628 void ons_ControlPoint_Icon_BuildThink(entity this)
632 this.nextthink = time + ONS_CP_THINKRATE;
634 // only do this if there is power
635 a = ons_ControlPoint_CanBeLinked(this.owner, this.owner.team);
639 this.health = this.health + this.count;
641 this.SendFlags |= CPSF_STATUS;
643 if (this.health >= this.max_health)
645 this.health = this.max_health;
646 this.count = autocvar_g_onslaught_cp_regen * ONS_CP_THINKRATE; // slow repair rate from now on
647 setthink(this, ons_ControlPoint_Icon_Think);
648 sound(this, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILT, VOL_BASE, ATTEN_NORM);
649 this.owner.iscaptured = true;
650 this.solid = SOLID_BBOX;
652 Send_Effect(EFFECT_CAP(this.owner.team), this.owner.origin, '0 0 0', 1);
654 WaypointSprite_UpdateMaxHealth(this.owner.sprite, this.max_health);
655 WaypointSprite_UpdateHealth(this.owner.sprite, this.health);
657 if(IS_PLAYER(this.owner.ons_toucher))
659 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ONSLAUGHT_CAPTURE, this.owner.ons_toucher.netname, this.owner.message);
660 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);
661 Send_Notification(NOTIF_ONE, this.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE, this.owner.message);
662 PlayerScore_Add(this.owner.ons_toucher, SP_ONS_CAPS, 1);
663 PlayerTeamScore_AddScore(this.owner.ons_toucher, 10);
666 this.owner.ons_toucher = NULL;
668 onslaught_updatelinks();
670 // Use targets now (somebody make sure this is in the right place..)
671 SUB_UseTargets(this.owner, this, NULL);
673 this.SendFlags |= CPSF_SETUP;
675 if(this.owner.model != MDL_ONS_CP_PAD2.model_str())
676 setmodel_fixsize(this.owner, MDL_ONS_CP_PAD2);
678 if(random() < 0.9 - this.health / this.max_health)
679 Send_Effect(EFFECT_RAGE, this.origin + 10 * randomvec(), '0 0 -1', 1);
682 void onslaught_controlpoint_icon_link(entity e, void(entity this) spawnproc);
684 void ons_ControlPoint_Icon_Spawn(entity cp, entity player)
686 entity e = new(onslaught_controlpoint_icon);
688 setsize(e, CPICON_MIN, CPICON_MAX);
689 setorigin(e, cp.origin + CPICON_OFFSET);
692 e.max_health = autocvar_g_onslaught_cp_health;
693 e.health = autocvar_g_onslaught_cp_buildhealth;
695 e.takedamage = DAMAGE_AIM;
697 e.event_damage = ons_ControlPoint_Icon_Damage;
698 e.team = player.team;
699 e.colormap = 1024 + (e.team - 1) * 17;
700 e.count = (e.max_health - e.health) * ONS_CP_THINKRATE / autocvar_g_onslaught_cp_buildtime; // how long it takes to build
702 sound(e, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILD, VOL_BASE, ATTEN_NORM);
706 cp.colormap = e.colormap;
708 Send_Effect(EFFECT_FLAG_TOUCH(player.team), e.origin, '0 0 0', 1);
710 WaypointSprite_UpdateBuildFinished(cp.sprite, time + (e.max_health - e.health) / (e.count / ONS_CP_THINKRATE));
711 WaypointSprite_UpdateRule(cp.sprite,cp.team,SPRITERULE_TEAMPLAY);
712 cp.sprite.SendFlags |= 16;
714 onslaught_controlpoint_icon_link(e, ons_ControlPoint_Icon_BuildThink);
717 entity ons_ControlPoint_Waypoint(entity e)
721 int a = ons_ControlPoint_Attackable(e, e.team);
723 if(a == -2) { return WP_OnsCPDefend; } // defend now
724 if(a == -1 || a == 1 || a == 2) { return WP_OnsCP; } // touch
725 if(a == 3 || a == 4) { return WP_OnsCPAttack; } // attack
733 void ons_ControlPoint_UpdateSprite(entity e)
735 entity s1 = ons_ControlPoint_Waypoint(e);
736 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
739 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));
741 if(e.lastteam != e.team + 2 || e.lastshielded != sh || e.iscaptured != e.lastcaptured)
743 if(e.iscaptured) // don't mess up build bars!
747 WaypointSprite_UpdateMaxHealth(e.sprite, 0);
751 WaypointSprite_UpdateMaxHealth(e.sprite, e.goalentity.max_health);
752 WaypointSprite_UpdateHealth(e.sprite, e.goalentity.health);
758 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, false));
760 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
765 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, false));
767 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
769 WaypointSprite_Ping(e.sprite);
771 e.lastteam = e.team + 2;
773 e.lastcaptured = e.iscaptured;
777 void ons_ControlPoint_Touch(entity this, entity toucher)
781 if(IS_VEHICLE(toucher) && toucher.owner)
782 if(autocvar_g_onslaught_allow_vehicle_touch)
783 toucher = toucher.owner;
787 if(!IS_PLAYER(toucher)) { return; }
788 if(STAT(FROZEN, toucher)) { return; }
789 if(IS_DEAD(toucher)) { return; }
791 if ( SAME_TEAM(this,toucher) )
792 if ( this.iscaptured )
794 if(time <= toucher.teleport_antispam)
795 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT_ANTISPAM, rint(toucher.teleport_antispam - time));
797 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
800 attackable = ons_ControlPoint_Attackable(this, toucher.team);
801 if(attackable != 2 && attackable != 4)
803 // we've verified that this player has a legitimate claim to this point,
804 // so start building the captured point icon (which only captures this
805 // point if it successfully builds without being destroyed first)
806 ons_ControlPoint_Icon_Spawn(this, toucher);
808 this.ons_toucher = toucher;
810 onslaught_updatelinks();
813 void ons_ControlPoint_Think(entity this)
815 this.nextthink = time + ONS_CP_THINKRATE;
816 CSQCMODEL_AUTOUPDATE(this);
819 void ons_ControlPoint_Reset(entity this)
822 remove(this.goalentity);
824 this.goalentity = NULL;
826 this.colormap = 1024;
827 this.iscaptured = false;
828 this.islinked = false;
829 this.isshielded = true;
830 setthink(this, ons_ControlPoint_Think);
831 this.ons_toucher = NULL;
832 this.nextthink = time + ONS_CP_THINKRATE;
833 setmodel_fixsize(this, MDL_ONS_CP_PAD1);
835 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
836 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
838 onslaught_updatelinks();
840 SUB_UseTargets(this, this, NULL); // to reset the structures, playerspawns etc.
842 CSQCMODEL_AUTOUPDATE(this);
845 void ons_DelayedControlPoint_Setup(entity this)
847 onslaught_updatelinks();
849 // captureshield setup
850 ons_CaptureShield_Spawn(this, false);
852 CSQCMODEL_AUTOINIT(this);
855 void ons_ControlPoint_Setup(entity cp)
858 cp.ons_worldcpnext = ons_worldcplist; // link control point into ons_worldcplist
859 ons_worldcplist = cp;
861 cp.netname = "Control point";
863 cp.solid = SOLID_BBOX;
864 set_movetype(cp, MOVETYPE_NONE);
865 settouch(cp, ons_ControlPoint_Touch);
866 setthink(cp, ons_ControlPoint_Think);
867 cp.nextthink = time + ONS_CP_THINKRATE;
868 cp.reset = ons_ControlPoint_Reset;
870 cp.iscaptured = false;
872 cp.isshielded = true;
874 if(cp.message == "") { cp.message = "a"; }
877 setmodel_fixsize(cp, MDL_ONS_CP_PAD1);
879 // control point placement
880 if((cp.spawnflags & 1) || cp.noalign) // don't drop to floor, just stay at fixed location
883 set_movetype(cp, MOVETYPE_NONE);
885 else // drop to floor, automatically find a platform and set that as spawn origin
887 setorigin(cp, cp.origin + '0 0 20');
890 set_movetype(cp, MOVETYPE_TOSS);
894 WaypointSprite_SpawnFixed(WP_Null, cp.origin + CPGEN_WAYPOINT_OFFSET, cp, sprite, RADARICON_NONE);
895 WaypointSprite_UpdateRule(cp.sprite, cp.team, SPRITERULE_TEAMPLAY);
897 InitializeEntity(cp, ons_DelayedControlPoint_Setup, INITPRIO_SETLOCATION);
901 // =========================
902 // Main Generator Functions
903 // =========================
905 entity ons_Generator_Waypoint(entity e)
908 return WP_OnsGenShielded;
912 void ons_Generator_UpdateSprite(entity e)
914 entity s1 = ons_Generator_Waypoint(e);
915 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
917 if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
919 e.lastteam = e.team + 2;
920 e.lastshielded = e.isshielded;
924 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, false));
926 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
931 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, false));
933 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
935 WaypointSprite_Ping(e.sprite);
939 void ons_GeneratorDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
941 if(damage <= 0) { return; }
942 if(warmup_stage || gameover) { return; }
943 if(!round_handler_IsRoundStarted()) { return; }
945 if (attacker != this)
949 // this is protected by a shield, so ignore the damage
950 if (time > this.pain_finished)
951 if (IS_PLAYER(attacker))
953 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
954 attacker.typehitsound += 1;
955 this.pain_finished = time + 1;
959 if (time > this.pain_finished)
961 this.pain_finished = time + 10;
962 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && SAME_TEAM(it, this), Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK));
963 play2team(this.team, SND(ONS_GENERATOR_UNDERATTACK));
966 this.health = this.health - damage;
967 WaypointSprite_UpdateHealth(this.sprite, this.health);
968 // choose an animation frame based on health
969 this.frame = 10 * bound(0, (1 - this.health / this.max_health), 1);
970 // see if the generator is still functional, or dying
973 this.lasthealth = this.health;
977 if (attacker == this)
978 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME));
981 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED));
982 PlayerScore_Add(attacker, SP_SCORE, 100);
984 this.iscaptured = false;
985 this.islinked = false;
986 this.isshielded = false;
987 this.takedamage = DAMAGE_NO; // can't be hurt anymore
988 this.event_damage = func_null; // won't do anything if hurt
989 this.count = 0; // reset counter
990 setthink(this, func_null);
992 //this.think(); // do the first explosion now
994 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
995 WaypointSprite_Ping(this.sprite);
996 //WaypointSprite_Kill(this.sprite); // can't do this yet, code too poor
998 onslaught_updatelinks();
1001 // Throw some flaming gibs on damage, more damage = more chance for gib
1002 if(random() < damage/220)
1004 sound(this, CH_TRIGGER, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
1008 // particles on every hit
1009 Send_Effect(EFFECT_SPARKS, hitloc, force * -1, 1);
1011 //sound on every hit
1013 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE, ATTEN_NORM);
1015 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE, ATTEN_NORM);
1018 this.SendFlags |= GSF_STATUS;
1021 void ons_GeneratorThink(entity this)
1023 this.nextthink = time + GEN_THINKRATE;
1026 if(!this.isshielded && this.wait < time)
1028 this.wait = time + 5;
1029 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
1030 if(SAME_TEAM(it, this))
1032 Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM);
1033 soundto(MSG_ONE, it, CHAN_AUTO, SND(KH_ALARM), VOL_BASE, ATTEN_NONE); // FIXME: unique sound?
1036 Send_Notification(NOTIF_ONE, it, MSG_CENTER, APP_TEAM_NUM(this.team, CENTER_ONS_NOTSHIELDED));
1042 void ons_GeneratorReset(entity this)
1044 this.team = this.team_saved;
1045 this.lasthealth = this.max_health = this.health = autocvar_g_onslaught_gen_health;
1046 this.takedamage = DAMAGE_AIM;
1047 this.bot_attack = true;
1048 this.iscaptured = true;
1049 this.islinked = true;
1050 this.isshielded = true;
1051 this.event_damage = ons_GeneratorDamage;
1052 setthink(this, ons_GeneratorThink);
1053 this.nextthink = time + GEN_THINKRATE;
1055 Net_LinkEntity(this, false, 0, generator_send);
1057 this.SendFlags = GSF_SETUP; // just incase
1058 this.SendFlags |= GSF_STATUS;
1060 WaypointSprite_UpdateMaxHealth(this.sprite, this.max_health);
1061 WaypointSprite_UpdateHealth(this.sprite, this.health);
1062 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
1064 onslaught_updatelinks();
1067 void ons_DelayedGeneratorSetup(entity this)
1070 waypoint_spawnforitem_force(this, this.origin);
1071 this.nearestwaypointtimeout = 0; // activate waypointing again
1072 this.bot_basewaypoint = this.nearestwaypoint;
1074 // captureshield setup
1075 ons_CaptureShield_Spawn(this, true);
1077 onslaught_updatelinks();
1079 Net_LinkEntity(this, false, 0, generator_send);
1083 void onslaught_generator_touch(entity this, entity toucher)
1085 if ( IS_PLAYER(toucher) )
1086 if ( SAME_TEAM(this,toucher) )
1087 if ( this.iscaptured )
1089 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
1093 void ons_GeneratorSetup(entity gen) // called when spawning a generator entity on the map as a spawnfunc
1096 int teamnumber = gen.team;
1099 gen.ons_worldgeneratornext = ons_worldgeneratorlist; // link generator into ons_worldgeneratorlist
1100 ons_worldgeneratorlist = gen;
1102 gen.netname = sprintf("%s generator", Team_ColoredFullName(teamnumber));
1103 gen.classname = "onslaught_generator";
1104 gen.solid = SOLID_BBOX;
1105 gen.team_saved = teamnumber;
1106 set_movetype(gen, MOVETYPE_NONE);
1107 gen.lasthealth = gen.max_health = gen.health = autocvar_g_onslaught_gen_health;
1108 gen.takedamage = DAMAGE_AIM;
1109 gen.bot_attack = true;
1110 gen.event_damage = ons_GeneratorDamage;
1111 gen.reset = ons_GeneratorReset;
1112 setthink(gen, ons_GeneratorThink);
1113 gen.nextthink = time + GEN_THINKRATE;
1114 gen.iscaptured = true;
1115 gen.islinked = true;
1116 gen.isshielded = true;
1117 settouch(gen, onslaught_generator_touch);
1120 // model handled by CSQC
1121 setsize(gen, GENERATOR_MIN, GENERATOR_MAX);
1122 setorigin(gen, (gen.origin + CPGEN_SPAWN_OFFSET));
1123 gen.colormap = 1024 + (teamnumber - 1) * 17;
1125 // generator placement
1129 WaypointSprite_SpawnFixed(WP_Null, gen.origin + CPGEN_WAYPOINT_OFFSET, gen, sprite, RADARICON_NONE);
1130 WaypointSprite_UpdateRule(gen.sprite, gen.team, SPRITERULE_TEAMPLAY);
1131 WaypointSprite_UpdateMaxHealth(gen.sprite, gen.max_health);
1132 WaypointSprite_UpdateHealth(gen.sprite, gen.health);
1134 InitializeEntity(gen, ons_DelayedGeneratorSetup, INITPRIO_SETLOCATION);
1142 int total_generators;
1143 void Onslaught_count_generators()
1146 total_generators = redowned = blueowned = yellowowned = pinkowned = 0;
1147 for(e = ons_worldgeneratorlist; e; e = e.ons_worldgeneratornext)
1150 redowned += (e.team == NUM_TEAM_1 && e.health > 0);
1151 blueowned += (e.team == NUM_TEAM_2 && e.health > 0);
1152 yellowowned += (e.team == NUM_TEAM_3 && e.health > 0);
1153 pinkowned += (e.team == NUM_TEAM_4 && e.health > 0);
1157 int Onslaught_GetWinnerTeam()
1159 int winner_team = 0;
1161 winner_team = NUM_TEAM_1;
1164 if(winner_team) return 0;
1165 winner_team = NUM_TEAM_2;
1169 if(winner_team) return 0;
1170 winner_team = NUM_TEAM_3;
1174 if(winner_team) return 0;
1175 winner_team = NUM_TEAM_4;
1179 return -1; // no generators left?
1182 void nades_Clear(entity e);
1184 #define ONS_OWNED_GENERATORS() ((redowned > 0) + (blueowned > 0) + (yellowowned > 0) + (pinkowned > 0))
1185 #define ONS_OWNED_GENERATORS_OK() (ONS_OWNED_GENERATORS() > 1)
1186 bool Onslaught_CheckWinner()
1188 if ((autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60) || (round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0))
1190 ons_stalemate = true;
1192 if (!wpforenemy_announced)
1194 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT);
1195 sound(NULL, CH_INFO, SND_ONS_GENERATOR_DECAY, VOL_BASE, ATTEN_NONE);
1197 wpforenemy_announced = true;
1200 entity tmp_entity; // temporary entity
1202 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext) if(time >= tmp_entity.ons_overtime_damagedelay)
1204 // tmp_entity.max_health / 300 gives 5 minutes of overtime.
1205 // control points reduce the overtime duration.
1208 for(e = ons_worldcplist; e; e = e.ons_worldcpnext)
1210 if(DIFF_TEAM(e, tmp_entity))
1215 if(autocvar_g_campaign && autocvar__campaign_testrun)
1216 d = d * tmp_entity.max_health;
1218 d = d * tmp_entity.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
1220 Damage(tmp_entity, tmp_entity, tmp_entity, d, DEATH_HURTTRIGGER.m_id, tmp_entity.origin, '0 0 0');
1222 tmp_entity.sprite.SendFlags |= 16;
1224 tmp_entity.ons_overtime_damagedelay = time + 1;
1227 else { wpforenemy_announced = false; ons_stalemate = false; }
1229 Onslaught_count_generators();
1231 if(ONS_OWNED_GENERATORS_OK())
1234 int winner_team = Onslaught_GetWinnerTeam();
1238 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
1239 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
1240 TeamScore_AddToTeam(winner_team, ST_ONS_CAPS, +1);
1242 else if(winner_team == -1)
1244 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_TIED);
1245 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_TIED);
1248 ons_stalemate = false;
1250 play2all(SND(CTF_CAPTURE(winner_team)));
1252 round_handler_Init(7, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
1254 FOREACH_CLIENT(IS_PLAYER(it), {
1255 it.ons_roundlost = true;
1256 it.player_blocked = true;
1264 bool Onslaught_CheckPlayers()
1269 void Onslaught_RoundStart()
1272 FOREACH_CLIENT(IS_PLAYER(it), it.player_blocked = false);
1274 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1275 tmp_entity.sprite.SendFlags |= 16;
1277 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1278 tmp_entity.sprite.SendFlags |= 16;
1286 // NOTE: LEGACY CODE, needs to be re-written!
1288 void havocbot_goalrating_ons_offenseitems(entity this, float ratingscale, vector org, float sradius)
1290 bool needarmor = false, needweapons = false;
1292 // Needs armor/health?
1298 FOREACH(Weapons, it != WEP_Null, {
1299 if(this.weapons & (it.m_wepset))
1307 if(!needweapons && !needarmor)
1310 LOG_DEBUG(strcat(this.netname, " needs weapons ", ftos(needweapons) , "\n"));
1311 LOG_DEBUG(strcat(this.netname, " needs armor ", ftos(needarmor) , "\n"));
1313 // See what is around
1314 FOREACH_ENTITY_FLOAT(bot_pickup, true,
1316 // gather health and armor only
1318 if ( ((it.health || it.armorvalue) && needarmor) || (it.weapons && needweapons ) )
1319 if (vdist(it.origin - org, <, sradius))
1321 int t = it.bot_pickupevalfunc(this, it);
1323 navigation_routerating(this, it, t * ratingscale, 500);
1328 void havocbot_role_ons_setrole(entity this, int role)
1330 LOG_DEBUG(strcat(this.netname," switched to "));
1333 case HAVOCBOT_ONS_ROLE_DEFENSE:
1334 LOG_DEBUG("defense");
1335 this.havocbot_role = havocbot_role_ons_defense;
1336 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE;
1337 this.havocbot_role_timeout = 0;
1339 case HAVOCBOT_ONS_ROLE_ASSISTANT:
1340 LOG_DEBUG("assistant");
1341 this.havocbot_role = havocbot_role_ons_assistant;
1342 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT;
1343 this.havocbot_role_timeout = 0;
1345 case HAVOCBOT_ONS_ROLE_OFFENSE:
1346 LOG_DEBUG("offense");
1347 this.havocbot_role = havocbot_role_ons_offense;
1348 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE;
1349 this.havocbot_role_timeout = 0;
1355 void havocbot_goalrating_ons_controlpoints_attack(entity this, float ratingscale)
1357 entity cp, cp1, cp2, best, wp;
1358 float radius, bestvalue;
1362 // Filter control points
1363 for(cp2 = ons_worldcplist; cp2; cp2 = cp2.ons_worldcpnext)
1366 cp2.wpconsidered = false;
1371 // Ignore owned controlpoints
1372 if(!(cp2.isgenneighbor[this.team] || cp2.iscpneighbor[this.team]))
1375 // Count team mates interested in this control point
1376 // (easier and cleaner than keeping counters per cp and teams)
1377 FOREACH_CLIENT(IS_PLAYER(it), {
1378 if(SAME_TEAM(it, this))
1379 if(it.havocbot_role_flags & HAVOCBOT_ONS_ROLE_OFFENSE)
1380 if(it.havocbot_ons_target == cp2)
1384 // NOTE: probably decrease the cost of attackable control points
1386 cp2.wpconsidered = true;
1389 // We'll consider only the best case
1390 bestvalue = 99999999999;
1392 for(cp1 = ons_worldcplist; cp1; cp1 = cp1.ons_worldcpnext)
1394 if (!cp1.wpconsidered)
1397 if(cp1.wpcost<bestvalue)
1399 bestvalue = cp1.wpcost;
1401 this.havocbot_ons_target = cp1;
1408 LOG_DEBUG(strcat(this.netname, " chose cp ranked ", ftos(bestvalue), "\n"));
1412 // Should be attacked
1413 // Rate waypoints near it
1416 bestvalue = 99999999999;
1417 for(radius=0; radius<1000 && !found; radius+=500)
1419 for(wp=findradius(cp.origin,radius); wp; wp=wp.chain)
1421 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
1422 if(wp.classname=="waypoint")
1423 if(checkpvs(wp.origin,cp))
1426 if(wp.cnt<bestvalue)
1437 navigation_routerating(this, best, ratingscale, 10000);
1440 this.havocbot_attack_time = 0;
1441 if(checkpvs(this.view_ofs,cp))
1442 if(checkpvs(this.view_ofs,best))
1443 this.havocbot_attack_time = time + 2;
1447 navigation_routerating(this, cp, ratingscale, 10000);
1449 LOG_DEBUG(strcat(this.netname, " found an attackable controlpoint at ", vtos(cp.origin) ,"\n"));
1453 // Should be touched
1454 LOG_DEBUG(strcat(this.netname, " found a touchable controlpoint at ", vtos(cp.origin) ,"\n"));
1457 // Look for auto generated waypoint
1458 if (!bot_waypoints_for_items)
1459 for (wp = findradius(cp.origin,100); wp; wp = wp.chain)
1461 if(wp.classname=="waypoint")
1463 navigation_routerating(this, wp, ratingscale, 10000);
1468 // Nothing found, rate the controlpoint itself
1470 navigation_routerating(this, cp, ratingscale, 10000);
1474 bool havocbot_goalrating_ons_generator_attack(entity this, float ratingscale)
1476 entity g, wp, bestwp;
1480 for(g = ons_worldgeneratorlist; g; g = g.ons_worldgeneratornext)
1482 if(SAME_TEAM(g, this) || g.isshielded)
1485 // Should be attacked
1486 // Rate waypoints near it
1491 for(wp=findradius(g.origin,400); wp; wp=wp.chain)
1493 if(wp.classname=="waypoint")
1494 if(checkpvs(wp.origin,g))
1507 LOG_DEBUG("waypoints found around generator\n");
1508 navigation_routerating(this, bestwp, ratingscale, 10000);
1511 this.havocbot_attack_time = 0;
1512 if(checkpvs(this.view_ofs,g))
1513 if(checkpvs(this.view_ofs,bestwp))
1514 this.havocbot_attack_time = time + 5;
1520 LOG_DEBUG("generator found without waypoints around\n");
1521 // if there aren't waypoints near the generator go straight to it
1522 navigation_routerating(this, g, ratingscale, 10000);
1523 this.havocbot_attack_time = 0;
1530 void havocbot_role_ons_offense(entity this)
1534 this.havocbot_attack_time = 0;
1535 havocbot_ons_reset_role(this);
1539 // Set the role timeout if necessary
1540 if (!this.havocbot_role_timeout)
1541 this.havocbot_role_timeout = time + 120;
1543 if (time > this.havocbot_role_timeout)
1545 havocbot_ons_reset_role(this);
1549 if(this.havocbot_attack_time>time)
1552 if (this.bot_strategytime < time)
1554 navigation_goalrating_start(this);
1555 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
1556 if(!havocbot_goalrating_ons_generator_attack(this, 20000))
1557 havocbot_goalrating_ons_controlpoints_attack(this, 20000);
1558 havocbot_goalrating_ons_offenseitems(this, 10000, this.origin, 10000);
1559 navigation_goalrating_end(this);
1561 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
1565 void havocbot_role_ons_assistant(entity this)
1567 havocbot_ons_reset_role(this);
1570 void havocbot_role_ons_defense(entity this)
1572 havocbot_ons_reset_role(this);
1575 void havocbot_ons_reset_role(entity this)
1580 this.havocbot_ons_target = NULL;
1582 // TODO: Defend control points or generator if necessary
1584 havocbot_role_ons_setrole(this, HAVOCBOT_ONS_ROLE_OFFENSE);
1589 * Find control point or generator owned by the same team self which is nearest to pos
1590 * if max_dist is positive, only control points within this range will be considered
1592 entity ons_Nearest_ControlPoint(entity this, vector pos, float max_dist)
1594 entity closest_target = NULL;
1595 FOREACH_ENTITY_CLASS("onslaught_controlpoint", true,
1597 if(SAME_TEAM(it, this))
1599 if(max_dist <= 0 || vdist(it.origin - pos, <=, max_dist))
1600 if(vlen2(it.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
1601 closest_target = it;
1603 FOREACH_ENTITY_CLASS("onslaught_generator", true,
1605 if(SAME_TEAM(it, this))
1606 if(max_dist <= 0 || vdist(it.origin - pos, <, max_dist))
1607 if(vlen2(it.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
1608 closest_target = it;
1611 return closest_target;
1615 * Find control point or generator owned by the same team self which is nearest to pos
1616 * if max_dist is positive, only control points within this range will be considered
1617 * This function only check distances on the XY plane, disregarding Z
1619 entity ons_Nearest_ControlPoint_2D(entity this, vector pos, float max_dist)
1621 entity closest_target = NULL;
1623 float smallest_distance = 0, distance;
1625 FOREACH_ENTITY_CLASS("onslaught_controlpoint", true,
1627 delta = it.origin - pos;
1629 distance = vlen(delta);
1631 if(SAME_TEAM(it, this))
1633 if(max_dist <= 0 || distance <= max_dist)
1634 if(closest_target == NULL || distance <= smallest_distance )
1636 closest_target = it;
1637 smallest_distance = distance;
1640 FOREACH_ENTITY_CLASS("onslaught_generator", true,
1642 delta = it.origin - pos;
1644 distance = vlen(delta);
1646 if(SAME_TEAM(it, this))
1647 if(max_dist <= 0 || distance <= max_dist)
1648 if(closest_target == NULL || distance <= smallest_distance )
1650 closest_target = it;
1651 smallest_distance = distance;
1655 return closest_target;
1658 * find the number of control points and generators in the same team as this
1660 int ons_Count_SelfControlPoints(entity this)
1663 FOREACH_ENTITY_CLASS("onslaught_controlpoint", true,
1665 if(SAME_TEAM(it, this))
1669 FOREACH_ENTITY_CLASS("onslaught_generator", true,
1671 if(SAME_TEAM(it, this))
1678 * Teleport player to a random position near tele_target
1679 * if tele_effects is true, teleport sound+particles are created
1680 * return false on failure
1682 bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effects)
1690 // narrow the range for each iteration to increase chances that a spawnpoint
1691 // can be found even if there's little room around the control point
1692 float iteration_scale = 1;
1693 for(i = 0; i < 16; ++i)
1695 iteration_scale -= i / 16;
1696 theta = random() * 2 * M_PI;
1700 loc *= random() * range * iteration_scale;
1702 loc += tele_target.origin + '0 0 128' * iteration_scale;
1704 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
1705 if(trace_fraction == 1.0 && !trace_startsolid)
1707 traceline(tele_target.origin, loc, MOVE_NOMONSTERS, tele_target); // double check to make sure we're not spawning outside the NULL
1708 if(trace_fraction == 1.0 && !trace_startsolid)
1712 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
1713 sound (player, CH_TRIGGER, SND_TELEPORT, VOL_BASE, ATTEN_NORM);
1715 setorigin(player, loc);
1716 player.angles = '0 1 0' * ( theta * RAD2DEG + 180 );
1717 makevectors(player.angles);
1718 player.fixangle = true;
1719 player.teleport_antispam = time + autocvar_g_onslaught_teleport_wait;
1722 Send_Effect(EFFECT_TELEPORT, player.origin + v_forward * 32, '0 0 0', 1);
1735 MUTATOR_HOOKFUNCTION(ons, reset_map_global)
1737 FOREACH_CLIENT(IS_PLAYER(it), {
1738 it.ons_roundlost = false;
1739 it.ons_deathloc = '0 0 0';
1740 PutClientInServer(it);
1745 MUTATOR_HOOKFUNCTION(ons, ClientDisconnect)
1747 entity player = M_ARGV(0, entity);
1749 player.ons_deathloc = '0 0 0';
1752 MUTATOR_HOOKFUNCTION(ons, MakePlayerObserver)
1754 entity player = M_ARGV(0, entity);
1756 player.ons_deathloc = '0 0 0';
1759 MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
1761 entity player = M_ARGV(0, entity);
1763 if(!round_handler_IsRoundStarted())
1765 player.player_blocked = true;
1770 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1772 l.sprite.SendFlags |= 16;
1774 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1776 l.sprite.SendFlags |= 16;
1779 if(ons_stalemate) { Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); }
1781 if ( autocvar_g_onslaught_spawn_choose )
1782 if ( player.ons_spawn_by )
1783 if ( ons_Teleport(player,player.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) )
1785 player.ons_spawn_by = NULL;
1789 if(autocvar_g_onslaught_spawn_at_controlpoints)
1790 if(random() <= autocvar_g_onslaught_spawn_at_controlpoints_chance)
1792 float random_target = autocvar_g_onslaught_spawn_at_controlpoints_random;
1793 entity tmp_entity, closest_target = NULL;
1794 vector spawn_loc = player.ons_deathloc;
1796 // new joining player or round reset, don't bother checking
1797 if(spawn_loc == '0 0 0') { return false; }
1799 if(random_target) { RandomSelection_Init(); }
1801 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1803 if(SAME_TEAM(tmp_entity, player))
1805 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1806 else if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL)
1807 closest_target = tmp_entity;
1810 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1816 float iteration_scale = 1;
1817 for(i = 0; i < 10; ++i)
1819 iteration_scale -= i / 10;
1820 loc = closest_target.origin + '0 0 96' * iteration_scale;
1821 loc += ('0 1 0' * random()) * 128 * iteration_scale;
1822 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
1823 if(trace_fraction == 1.0 && !trace_startsolid)
1825 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL
1826 if(trace_fraction == 1.0 && !trace_startsolid)
1828 setorigin(player, loc);
1829 player.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1837 if(autocvar_g_onslaught_spawn_at_generator)
1838 if(random() <= autocvar_g_onslaught_spawn_at_generator_chance)
1840 float random_target = autocvar_g_onslaught_spawn_at_generator_random;
1841 entity tmp_entity, closest_target = NULL;
1842 vector spawn_loc = player.ons_deathloc;
1844 // new joining player or round reset, don't bother checking
1845 if(spawn_loc == '0 0 0') { return false; }
1847 if(random_target) { RandomSelection_Init(); }
1849 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1852 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1855 if(SAME_TEAM(tmp_entity, player))
1856 if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL)
1857 closest_target = tmp_entity;
1861 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1867 float iteration_scale = 1;
1868 for(i = 0; i < 10; ++i)
1870 iteration_scale -= i / 10;
1871 loc = closest_target.origin + '0 0 128' * iteration_scale;
1872 loc += ('0 1 0' * random()) * 256 * iteration_scale;
1873 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
1874 if(trace_fraction == 1.0 && !trace_startsolid)
1876 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL
1877 if(trace_fraction == 1.0 && !trace_startsolid)
1879 setorigin(player, loc);
1880 player.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1891 MUTATOR_HOOKFUNCTION(ons, PlayerDies)
1893 entity frag_target = M_ARGV(2, entity);
1895 frag_target.ons_deathloc = frag_target.origin;
1897 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1899 l.sprite.SendFlags |= 16;
1901 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1903 l.sprite.SendFlags |= 16;
1906 if ( autocvar_g_onslaught_spawn_choose )
1907 if ( ons_Count_SelfControlPoints(frag_target) > 1 )
1908 stuffcmd(frag_target, "qc_cmd_cl hud clickradar\n");
1913 MUTATOR_HOOKFUNCTION(ons, MonsterMove)
1915 entity mon = M_ARGV(0, entity);
1917 entity e = find(NULL, targetname, mon.target);
1922 void ons_MonsterSpawn_Delayed(entity this)
1924 entity own = this.owner;
1926 if(!own) { remove(this); return; }
1930 entity e = find(NULL, target, own.targetname);
1935 own.use(own, e, NULL);
1942 MUTATOR_HOOKFUNCTION(ons, MonsterSpawn)
1944 entity mon = M_ARGV(0, entity);
1948 InitializeEntity(e, ons_MonsterSpawn_Delayed, INITPRIO_FINDTARGET);
1951 void ons_TurretSpawn_Delayed(entity this)
1953 entity own = this.owner;
1955 if(!own) { remove(this); return; }
1959 entity e = find(NULL, target, own.targetname);
1963 own.active = ACTIVE_NOT;
1965 own.use(own, e, NULL);
1972 MUTATOR_HOOKFUNCTION(ons, TurretSpawn)
1974 entity turret = M_ARGV(0, entity);
1978 InitializeEntity(e, ons_TurretSpawn_Delayed, INITPRIO_FINDTARGET);
1983 MUTATOR_HOOKFUNCTION(ons, HavocBot_ChooseRole)
1985 entity bot = M_ARGV(0, entity);
1987 havocbot_ons_reset_role(bot);
1991 MUTATOR_HOOKFUNCTION(ons, GetTeamCount)
1993 // onslaught is special
1994 for(entity tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1996 switch(tmp_entity.team)
1998 case NUM_TEAM_1: c1 = 0; break;
1999 case NUM_TEAM_2: c2 = 0; break;
2000 case NUM_TEAM_3: c3 = 0; break;
2001 case NUM_TEAM_4: c4 = 0; break;
2008 MUTATOR_HOOKFUNCTION(ons, SpectateCopy)
2010 entity spectatee = M_ARGV(0, entity);
2011 entity client = M_ARGV(1, entity);
2013 client.ons_roundlost = spectatee.ons_roundlost; // make spectators see it too
2016 MUTATOR_HOOKFUNCTION(ons, SV_ParseClientCommand)
2018 if(MUTATOR_RETURNVALUE) // command was already handled?
2021 entity player = M_ARGV(0, entity);
2022 string cmd_name = M_ARGV(1, string);
2023 int cmd_argc = M_ARGV(2, int);
2025 if ( cmd_name == "ons_spawn" )
2027 vector pos = player.origin;
2029 pos_x = stof(argv(1));
2031 pos_y = stof(argv(2));
2033 pos_z = stof(argv(3));
2035 if ( IS_PLAYER(player) )
2037 if ( !STAT(FROZEN, player) )
2039 entity source_point = ons_Nearest_ControlPoint(player, player.origin, autocvar_g_onslaught_teleport_radius);
2041 if ( !source_point && player.health > 0 )
2043 sprint(player, "\nYou need to be next to a control point\n");
2048 entity closest_target = ons_Nearest_ControlPoint_2D(player, pos, autocvar_g_onslaught_click_radius);
2050 if ( closest_target == NULL )
2052 sprint(player, "\nNo control point found\n");
2056 if ( player.health <= 0 )
2058 player.ons_spawn_by = closest_target;
2059 player.respawn_flags = player.respawn_flags | RESPAWN_FORCE;
2063 if ( source_point == closest_target )
2065 sprint(player, "\nTeleporting to the same point\n");
2069 if ( !ons_Teleport(player,closest_target,autocvar_g_onslaught_teleport_radius,true) )
2070 sprint(player, "\nUnable to teleport there\n");
2076 sprint(player, "\nNo teleportation for you\n");
2084 MUTATOR_HOOKFUNCTION(ons, PlayerUseKey)
2086 if(MUTATOR_RETURNVALUE || gameover) { return false; }
2088 entity player = M_ARGV(0, entity);
2090 if((time > player.teleport_antispam) && (!IS_DEAD(player)) && !player.vehicle)
2092 entity source_point = ons_Nearest_ControlPoint(player, player.origin, autocvar_g_onslaught_teleport_radius);
2095 stuffcmd(player, "qc_cmd_cl hud clickradar\n");
2101 MUTATOR_HOOKFUNCTION(ons, PlayHitsound)
2103 entity frag_victim = M_ARGV(0, entity);
2105 return (frag_victim.classname == "onslaught_generator" && !frag_victim.isshielded)
2106 || (frag_victim.classname == "onslaught_controlpoint_icon" && !frag_victim.owner.isshielded);
2109 MUTATOR_HOOKFUNCTION(ons, SendWaypoint)
2111 entity wp = M_ARGV(0, entity);
2112 entity to = M_ARGV(1, entity);
2113 int sf = M_ARGV(2, int);
2114 int wp_flag = M_ARGV(3, int);
2118 if(wp.owner.classname == "onslaught_controlpoint")
2120 entity wp_owner = wp.owner;
2121 entity e = WaypointSprite_getviewentity(to);
2122 if(SAME_TEAM(e, wp_owner) && wp_owner.goalentity.health >= wp_owner.goalentity.max_health) { wp_flag |= 2; }
2123 if(!ons_ControlPoint_Attackable(wp_owner, e.team)) { wp_flag |= 2; }
2125 if(wp.owner.classname == "onslaught_generator")
2127 entity wp_owner = wp.owner;
2128 if(wp_owner.isshielded && wp_owner.health >= wp_owner.max_health) { wp_flag |= 2; }
2129 if(wp_owner.health <= 0) { wp_flag |= 2; }
2133 M_ARGV(3, int) = wp_flag;
2136 MUTATOR_HOOKFUNCTION(ons, TurretValidateTarget)
2138 entity turret_target = M_ARGV(1, entity);
2140 if(substring(turret_target.classname, 0, 10) == "onslaught_") // don't attack onslaught targets, that's the player's job!
2142 M_ARGV(3, float) = -3;
2149 MUTATOR_HOOKFUNCTION(ons, TurretThink)
2151 entity turret = M_ARGV(0, entity);
2153 // ONS uses somewhat backwards linking.
2156 entity e = find(NULL, targetname, turret.target);
2158 turret.team = e.team;
2161 if(turret.team != turret.tur_head.team)
2162 turret_respawn(turret);
2170 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
2171 Link between control points.
2173 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.
2176 "target" - first control point.
2177 "target2" - second control point.
2179 spawnfunc(onslaught_link)
2181 if(!g_onslaught) { remove(this); return; }
2183 if (this.target == "" || this.target2 == "")
2184 objerror(this, "target and target2 must be set\n");
2186 this.ons_worldlinknext = ons_worldlinklist; // link into ons_worldlinklist
2187 ons_worldlinklist = this;
2189 InitializeEntity(this, ons_DelayedLinkSetup, INITPRIO_FINDTARGET);
2190 Net_LinkEntity(this, false, 0, ons_Link_Send);
2193 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
2194 Control point. Be sure to give this enough clearance so that the shootable part has room to exist
2196 This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
2199 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2200 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
2201 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
2204 spawnfunc(onslaught_controlpoint)
2206 if(!g_onslaught) { remove(this); return; }
2208 ons_ControlPoint_Setup(this);
2211 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
2214 spawnfunc_onslaught_link entities can target this.
2217 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
2218 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2220 spawnfunc(onslaught_generator)
2222 if(!g_onslaught) { remove(this); return; }
2223 if(!this.team) { objerror(this, "team must be set"); }
2225 ons_GeneratorSetup(this);
2229 void ons_ScoreRules()
2231 CheckAllowedTeams(NULL);
2233 if(c1 >= 0) teams |= BIT(0);
2234 if(c2 >= 0) teams |= BIT(1);
2235 if(c3 >= 0) teams |= BIT(2);
2236 if(c4 >= 0) teams |= BIT(3);
2237 ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, 0, true);
2238 ScoreInfo_SetLabel_TeamScore (ST_ONS_CAPS, "destroyed", SFL_SORT_PRIO_PRIMARY);
2239 ScoreInfo_SetLabel_PlayerScore(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
2240 ScoreInfo_SetLabel_PlayerScore(SP_ONS_TAKES, "takes", 0);
2241 ScoreRules_basics_end();
2244 void ons_DelayedInit(entity this) // Do this check with a delay so we can wait for teams to be set up
2248 round_handler_Spawn(Onslaught_CheckPlayers, Onslaught_CheckWinner, Onslaught_RoundStart);
2249 round_handler_Init(5, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
2252 void ons_Initialize()
2255 ons_captureshield_force = autocvar_g_onslaught_shield_force;
2257 InitializeEntity(NULL, ons_DelayedInit, INITPRIO_GAMETYPE);