1 #include "sv_onslaught.qh"
2 #include "sv_controlpoint.qh"
3 #include "sv_generator.qh"
5 #include <server/bot/api.qh>
6 #include <server/campaign.qh>
7 #include <server/command/vote.qh>
8 #include <server/damage.qh>
9 #include <server/items/items.qh>
10 #include <server/world.qh>
11 #include <common/mapobjects/defs.qh>
12 #include <common/mapobjects/triggers.qh>
16 float autocvar_g_onslaught_teleport_wait;
17 bool autocvar_g_onslaught_spawn_at_controlpoints;
18 bool autocvar_g_onslaught_spawn_at_generator;
19 float autocvar_g_onslaught_cp_proxydecap;
20 float autocvar_g_onslaught_cp_proxydecap_distance = 512;
21 float autocvar_g_onslaught_cp_proxydecap_dps = 100;
22 float autocvar_g_onslaught_spawn_at_controlpoints_chance = 0.5;
23 float autocvar_g_onslaught_spawn_at_controlpoints_random;
24 float autocvar_g_onslaught_spawn_at_generator_chance;
25 float autocvar_g_onslaught_spawn_at_generator_random;
26 float autocvar_g_onslaught_cp_buildhealth;
27 float autocvar_g_onslaught_cp_buildtime;
28 float autocvar_g_onslaught_cp_health;
29 float autocvar_g_onslaught_cp_regen;
30 float autocvar_g_onslaught_gen_health;
31 float autocvar_g_onslaught_shield_force = 100;
32 float autocvar_g_onslaught_allow_vehicle_touch;
33 float autocvar_g_onslaught_round_timelimit;
34 float autocvar_g_onslaught_warmup;
35 float autocvar_g_onslaught_teleport_radius;
36 float autocvar_g_onslaught_spawn_choose;
37 float autocvar_g_onslaught_click_radius;
41 // =======================
42 // CaptureShield Functions
43 // =======================
45 bool clientcamera_send(entity this, entity to, int sf)
47 WriteHeader(MSG_ENTITY, ENT_ONSCAMERA);
49 WriteVector(MSG_ENTITY, this.origin);
51 WriteAngleVector(MSG_ENTITY, this.angles);
56 bool ons_CaptureShield_Customize(entity this, entity client)
58 entity e = WaypointSprite_getviewentity(client);
60 if(!this.enemy.isshielded && (ons_ControlPoint_Attackable(this.enemy, e.team) > 0 || this.enemy.classname != "onslaught_controlpoint")) { return false; }
61 if(SAME_TEAM(this, e)) { return false; }
66 void ons_CaptureShield_Touch(entity this, entity toucher)
68 if(!this.enemy.isshielded && (ons_ControlPoint_Attackable(this.enemy, toucher.team) > 0 || this.enemy.classname != "onslaught_controlpoint")) { return; }
69 if(!IS_PLAYER(toucher)) { return; }
70 if(SAME_TEAM(toucher, this)) { return; }
72 vector mymid = (this.absmin + this.absmax) * 0.5;
73 vector theirmid = (toucher.absmin + toucher.absmax) * 0.5;
75 Damage(toucher, this, this, 0, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, mymid, normalize(theirmid - mymid) * ons_captureshield_force);
77 if(IS_REAL_CLIENT(toucher))
79 play2(toucher, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
81 if(this.enemy.classname == "onslaught_generator")
82 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_GENERATOR_SHIELDED);
84 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_CONTROLPOINT_SHIELDED);
88 void ons_CaptureShield_Reset(entity this)
90 this.colormap = this.enemy.colormap;
91 this.team = this.enemy.team;
94 void ons_CaptureShield_Spawn(entity this, Model shield_model)
96 entity shield = new(ons_captureshield);
97 IL_PUSH(g_onsshields, shield);
100 shield.team = this.team;
101 shield.colormap = this.colormap;
102 shield.reset = ons_CaptureShield_Reset;
103 settouch(shield, ons_CaptureShield_Touch);
104 setcefc(shield, ons_CaptureShield_Customize);
105 shield.effects = EF_ADDITIVE;
106 set_movetype(shield, MOVETYPE_NOCLIP);
107 shield.solid = SOLID_TRIGGER;
108 shield.avelocity = '7 0 11';
109 shield.scale = this.scale;
111 float shield_extra_size = 1.20; // hitbox is 20% larger than the object itself
112 setorigin(shield, this.origin);
113 setmodel(shield, shield_model);
114 setsize(shield, shield_extra_size * this.mins, shield_extra_size * this.maxs);
122 void onslaught_updatelinks()
125 // first check if the game has ended
126 LOG_DEBUG("--- updatelinks ---");
127 // mark generators as being shielded and networked
128 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
131 LOG_DEBUG(etos(l), " (generator) belongs to team ", ftos(l.team));
133 LOG_DEBUG(etos(l), " (generator) is destroyed");
134 l.islinked = l.iscaptured;
135 l.isshielded = l.iscaptured;
136 l.sprite.SendFlags |= 16;
138 // mark points as shielded and not networked
139 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
143 l.aregensneighbor = 0;
144 l.arecpsneighbor = 0;
145 LOG_DEBUG(etos(l), " (point) belongs to team ", ftos(l.team));
146 l.sprite.SendFlags |= 16;
148 // flow power outward from the generators through the network
153 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
155 // if both points are captured by the same team, and only one of
156 // them is powered, mark the other one as powered as well
157 if (l.enemy.iscaptured && l.goalentity.iscaptured)
158 if (l.enemy.islinked != l.goalentity.islinked)
159 if(SAME_TEAM(l.enemy, l.goalentity))
161 if (!l.goalentity.islinked)
164 l.goalentity.islinked = true;
165 LOG_DEBUG(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)");
167 else if (!l.enemy.islinked)
170 l.enemy.islinked = true;
171 LOG_DEBUG(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)");
176 // now that we know which points are powered we can mark their neighbors
177 // as unshielded if team differs
178 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
180 if (l.goalentity.islinked)
182 if(DIFF_TEAM(l.goalentity, l.enemy))
184 LOG_DEBUG(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)");
185 l.enemy.isshielded = false;
187 if(l.goalentity.classname == "onslaught_generator")
188 l.enemy.aregensneighbor |= BIT(l.goalentity.team);
190 l.enemy.arecpsneighbor |= BIT(l.goalentity.team);
192 if (l.enemy.islinked)
194 if(DIFF_TEAM(l.goalentity, l.enemy))
196 LOG_DEBUG(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)");
197 l.goalentity.isshielded = false;
199 if(l.enemy.classname == "onslaught_generator")
200 l.goalentity.aregensneighbor |= BIT(l.enemy.team);
202 l.goalentity.arecpsneighbor |= BIT(l.enemy.team);
205 // now update the generators
206 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
210 LOG_DEBUG(etos(l), " (generator) is shielded");
211 l.takedamage = DAMAGE_NO;
213 IL_REMOVE(g_bot_targets, l);
214 l.bot_attack = false;
218 LOG_DEBUG(etos(l), " (generator) is not shielded");
219 l.takedamage = DAMAGE_AIM;
221 IL_PUSH(g_bot_targets, l);
225 ons_Generator_UpdateSprite(l);
227 // now update the takedamage and alpha variables on control point icons
228 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
232 LOG_DEBUG(etos(l), " (point) is shielded");
235 l.goalentity.takedamage = DAMAGE_NO;
236 if(l.goalentity.bot_attack)
237 IL_REMOVE(g_bot_targets, l.goalentity);
238 l.goalentity.bot_attack = false;
243 LOG_DEBUG(etos(l), " (point) is not shielded");
246 l.goalentity.takedamage = DAMAGE_AIM;
247 if(!l.goalentity.bot_attack)
248 IL_PUSH(g_bot_targets, l.goalentity);
249 l.goalentity.bot_attack = true;
252 ons_ControlPoint_UpdateSprite(l);
254 IL_EACH(g_onsshields, true,
256 it.team = it.enemy.team;
257 it.colormap = it.enemy.colormap;
262 // ===================
263 // Main Link Functions
264 // ===================
266 bool ons_Link_Send(entity this, entity to, int sendflags)
268 WriteHeader(MSG_ENTITY, ENT_CLIENT_RADARLINK);
269 WriteByte(MSG_ENTITY, sendflags);
272 WriteVector(MSG_ENTITY, this.goalentity.origin);
276 WriteVector(MSG_ENTITY, this.enemy.origin);
280 WriteByte(MSG_ENTITY, this.clientcolors); // which is goalentity's color + enemy's color * 16
285 void ons_Link_CheckUpdate(entity this)
287 // TODO check if the two sides have moved (currently they won't move anyway)
288 float cc = 0, cc1 = 0, cc2 = 0;
290 if(this.goalentity.islinked || this.goalentity.iscaptured) { cc1 = (this.goalentity.team - 1) * 0x01; }
291 if(this.enemy.islinked || this.enemy.iscaptured) { cc2 = (this.enemy.team - 1) * 0x10; }
295 if(cc != this.clientcolors)
297 this.clientcolors = cc;
301 this.nextthink = time;
304 void ons_DelayedLinkSetup(entity this)
306 this.goalentity = find(NULL, targetname, this.target);
307 this.enemy = find(NULL, targetname, this.target2);
308 if(!this.goalentity) { objerror(this, "can not find target\n"); }
309 if(!this.enemy) { objerror(this, "can not find target2\n"); }
311 LOG_DEBUG(etos(this.goalentity), " linked with ", etos(this.enemy));
313 setthink(this, ons_Link_CheckUpdate);
314 this.nextthink = time;
318 // =============================
319 // Main Control Point Functions
320 // =============================
322 int ons_ControlPoint_CanBeLinked(entity cp, int teamnum)
324 if(cp.aregensneighbor & BIT(teamnum)) return 2;
325 if(cp.arecpsneighbor & BIT(teamnum)) return 1;
330 int ons_ControlPoint_Attackable(entity cp, int teamnum)
331 // -2: SAME TEAM, attackable by enemy!
336 // 3: attack it (HIGH PRIO)
337 // 4: touch it (HIGH PRIO)
345 else if(cp.goalentity)
347 // if there's already an icon built, nothing happens
348 if(cp.team == teamnum)
350 a = ons_ControlPoint_CanBeLinked(cp, teamnum);
351 if(a) // attackable by enemy?
352 return -2; // EMERGENCY!
355 // we know it can be linked, so no need to check
357 a = ons_ControlPoint_CanBeLinked(cp, teamnum);
358 if(a == 2) // near our generator?
359 return 3; // EMERGENCY!
365 if(ons_ControlPoint_CanBeLinked(cp, teamnum))
367 a = ons_ControlPoint_CanBeLinked(cp, teamnum); // why was this here NUM_TEAM_1 + NUM_TEAM_2 - t
369 return 4; // GET THIS ONE NOW!
371 return 2; // TOUCH ME
377 void ons_ControlPoint_Icon_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
379 if(damage <= 0) { return; }
381 if (this.owner.isshielded)
383 // this is protected by a shield, so ignore the damage
384 if (time > this.pain_finished)
385 if (IS_PLAYER(attacker))
387 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
388 this.pain_finished = time + 1;
389 attacker.typehitsound += 1; // play both sounds (shield is way too quiet)
395 if(IS_PLAYER(attacker))
396 if(time - ons_notification_time[this.team] > 10)
398 play2team(this.team, SND(ONS_CONTROLPOINT_UNDERATTACK));
399 ons_notification_time[this.team] = time;
402 TakeResource(this, RES_HEALTH, damage);
403 if(this.owner.iscaptured)
404 WaypointSprite_UpdateHealth(this.owner.sprite, GetResource(this, RES_HEALTH));
406 WaypointSprite_UpdateBuildFinished(this.owner.sprite, time + (this.max_health - GetResource(this, RES_HEALTH)) / (this.count / ONS_CP_THINKRATE));
407 this.pain_finished = time + 1;
408 // particles on every hit
409 pointparticles(EFFECT_SPARKS, hitloc, force*-1, 1);
412 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE+0.3, ATTEN_NORM);
414 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE+0.3, ATTEN_NORM);
416 if (GetResource(this, RES_HEALTH) < 0)
418 sound(this, CH_TRIGGER, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
419 pointparticles(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
420 if (this.owner.message != "")
421 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_CPDESTROYED), this.owner.message, attacker.netname);
423 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_CPDESTROYED_NONAME), attacker.netname);
425 GameRules_scoring_add(attacker, ONS_TAKES, 1);
426 GameRules_scoring_add(attacker, SCORE, 10);
428 this.owner.goalentity = NULL;
429 this.owner.islinked = false;
430 this.owner.iscaptured = false;
432 this.owner.colormap = 1024;
434 WaypointSprite_UpdateMaxHealth(this.owner.sprite, 0);
436 onslaught_updatelinks();
438 // Use targets now (somebody make sure this is in the right place..)
439 SUB_UseTargets(this.owner, this, NULL);
441 this.owner.waslinked = this.owner.islinked;
442 if(this.owner.model != "models/onslaught/controlpoint_pad.md3")
443 setmodel(this.owner, MDL_ONS_CP_PAD1);
444 //setsize(this, '-32 -32 0', '32 32 8');
449 this.SendFlags |= CPSF_STATUS;
452 bool ons_ControlPoint_Icon_Heal(entity targ, entity inflictor, float amount, float limit)
454 float hlth = GetResource(targ, RES_HEALTH);
455 float true_limit = ((limit != RES_LIMIT_NONE) ? limit : targ.max_health);
456 if (hlth <= 0 || hlth >= true_limit)
459 GiveResourceWithLimit(targ, RES_HEALTH, amount, true_limit);
460 hlth = GetResource(targ, RES_HEALTH);
461 if(targ.owner.iscaptured)
462 WaypointSprite_UpdateHealth(targ.owner.sprite, hlth);
464 WaypointSprite_UpdateBuildFinished(targ.owner.sprite, time + (targ.max_health - hlth) / (targ.count / ONS_CP_THINKRATE));
465 targ.SendFlags |= CPSF_STATUS;
469 void ons_ControlPoint_Icon_Think(entity this)
471 this.nextthink = time + ONS_CP_THINKRATE;
473 if(autocvar_g_onslaught_cp_proxydecap)
475 int _enemy_count = 0;
476 int _friendly_count = 0;
478 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it), {
479 if(vdist(it.origin - this.origin, <, autocvar_g_onslaught_cp_proxydecap_distance))
481 if(SAME_TEAM(it, this))
488 _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
489 _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
491 GiveResourceWithLimit(this, RES_HEALTH, (_friendly_count - _enemy_count), this.max_health);
492 this.SendFlags |= CPSF_STATUS;
493 if(GetResource(this, RES_HEALTH) <= 0)
495 ons_ControlPoint_Icon_Damage(this, this, this, 1, 0, DMG_NOWEP, this.origin, '0 0 0');
500 if (time > this.pain_finished + 5)
502 if(GetResource(this, RES_HEALTH) < this.max_health)
504 GiveResourceWithLimit(this, RES_HEALTH, this.count, this.max_health);
505 WaypointSprite_UpdateHealth(this.owner.sprite, GetResource(this, RES_HEALTH));
509 if(this.owner.islinked != this.owner.waslinked)
511 // unteam the spawnpoint if needed
512 int t = this.owner.team;
513 if(!this.owner.islinked)
516 SUB_UseTargets(this.owner, this, NULL);
520 this.owner.waslinked = this.owner.islinked;
524 if(random() < 0.6 - GetResource(this, RES_HEALTH) / this.max_health)
526 Send_Effect(EFFECT_ELECTRIC_SPARKS, this.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
529 sound(this, CH_PAIN, SND_ONS_SPARK1, VOL_BASE, ATTEN_NORM);
530 else if (random() > 0.5)
531 sound(this, CH_PAIN, SND_ONS_SPARK2, VOL_BASE, ATTEN_NORM);
535 void ons_ControlPoint_Icon_BuildThink(entity this)
539 this.nextthink = time + ONS_CP_THINKRATE;
541 // only do this if there is power
542 a = ons_ControlPoint_CanBeLinked(this.owner, this.owner.team);
546 GiveResource(this, RES_HEALTH, this.count);
548 this.SendFlags |= CPSF_STATUS;
550 if (GetResource(this, RES_HEALTH) >= this.max_health)
552 SetResourceExplicit(this, RES_HEALTH, this.max_health);
553 this.count = autocvar_g_onslaught_cp_regen * ONS_CP_THINKRATE; // slow repair rate from now on
554 setthink(this, ons_ControlPoint_Icon_Think);
555 sound(this, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILT, VOL_BASE, ATTEN_NORM);
556 this.owner.iscaptured = true;
557 this.solid = SOLID_BBOX;
559 Send_Effect(EFFECT_CAP(this.owner.team), this.owner.origin, '0 0 0', 1);
561 WaypointSprite_UpdateMaxHealth(this.owner.sprite, this.max_health);
562 WaypointSprite_UpdateHealth(this.owner.sprite, GetResource(this, RES_HEALTH));
564 if(IS_PLAYER(this.owner.ons_toucher))
566 if(this.owner.message != "")
568 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ONSLAUGHT_CAPTURE, this.owner.ons_toucher.netname, this.owner.message);
569 Send_Notification(NOTIF_ALL_EXCEPT, this.owner.ons_toucher, MSG_CENTER, APP_TEAM_NUM(this.owner.ons_toucher.team, CENTER_ONS_CAPTURE_TEAM), this.owner.message);
570 Send_Notification(NOTIF_ONE, this.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE, this.owner.message);
574 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ONSLAUGHT_CAPTURE_NONAME, this.owner.ons_toucher.netname);
575 Send_Notification(NOTIF_ALL_EXCEPT, this.owner.ons_toucher, MSG_CENTER, APP_TEAM_NUM(this.owner.ons_toucher.team, CENTER_ONS_CAPTURE_TEAM_NONAME));
576 Send_Notification(NOTIF_ONE, this.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE_NONAME);
578 GameRules_scoring_add(this.owner.ons_toucher, ONS_CAPS, 1);
579 GameRules_scoring_add_team(this.owner.ons_toucher, SCORE, 10);
582 this.owner.ons_toucher = NULL;
584 onslaught_updatelinks();
586 // Use targets now (somebody make sure this is in the right place..)
587 SUB_UseTargets(this.owner, this, NULL);
589 this.SendFlags |= CPSF_SETUP;
591 if(this.owner.model != MDL_ONS_CP_PAD2.model_str())
592 setmodel(this.owner, MDL_ONS_CP_PAD2);
594 if(random() < 0.9 - GetResource(this, RES_HEALTH) / this.max_health)
595 Send_Effect(EFFECT_RAGE, this.origin + 10 * randomvec(), '0 0 -1', 1);
598 void onslaught_controlpoint_icon_link(entity e, void(entity this) spawnproc);
600 void ons_ControlPoint_Icon_Spawn(entity cp, entity player)
602 entity e = new(onslaught_controlpoint_icon);
604 e.solid = SOLID_NOT; // before setsize/setorigin to prevent area grid linking
605 setsize(e, CPICON_MIN, CPICON_MAX);
606 setorigin(e, cp.origin + CPICON_OFFSET);
609 e.max_health = autocvar_g_onslaught_cp_health;
610 SetResourceExplicit(e, RES_HEALTH, autocvar_g_onslaught_cp_buildhealth);
611 e.takedamage = DAMAGE_AIM;
613 IL_PUSH(g_bot_targets, e);
614 e.event_damage = ons_ControlPoint_Icon_Damage;
615 e.event_heal = ons_ControlPoint_Icon_Heal;
616 e.team = player.team;
617 e.colormap = 1024 + (e.team - 1) * 17;
618 e.count = (e.max_health - GetResource(e, RES_HEALTH)) * ONS_CP_THINKRATE / autocvar_g_onslaught_cp_buildtime; // how long it takes to build
620 sound(e, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILD, VOL_BASE, ATTEN_NORM);
624 cp.colormap = e.colormap;
626 Send_Effect(EFFECT_FLAG_TOUCH(player.team), e.origin, '0 0 0', 1);
628 WaypointSprite_UpdateBuildFinished(cp.sprite, time + (e.max_health - GetResource(e, RES_HEALTH)) / (e.count / ONS_CP_THINKRATE));
629 WaypointSprite_UpdateRule(cp.sprite,cp.team,SPRITERULE_TEAMPLAY);
630 cp.sprite.SendFlags |= 16;
632 onslaught_controlpoint_icon_link(e, ons_ControlPoint_Icon_BuildThink);
635 entity ons_ControlPoint_Waypoint(entity e)
639 int a = ons_ControlPoint_Attackable(e, e.team);
641 if(a == -2) { return WP_OnsCPDefend; } // defend now
642 if(a == -1 || a == 1 || a == 2) { return WP_OnsCP; } // touch
643 if(a == 3 || a == 4) { return WP_OnsCPAttack; } // attack
651 void ons_ControlPoint_UpdateSprite(entity e)
653 entity s1 = ons_ControlPoint_Waypoint(e);
654 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
657 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));
659 if(e.lastteam != e.team + 2 || e.lastshielded != sh || e.iscaptured != e.lastcaptured)
661 if(e.iscaptured) // don't mess up build bars!
665 WaypointSprite_UpdateMaxHealth(e.sprite, 0);
669 WaypointSprite_UpdateMaxHealth(e.sprite, e.goalentity.max_health);
670 WaypointSprite_UpdateHealth(e.sprite, GetResource(e.goalentity, RES_HEALTH));
676 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, false));
678 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
683 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, false));
685 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
687 WaypointSprite_Ping(e.sprite);
689 e.lastteam = e.team + 2;
691 e.lastcaptured = e.iscaptured;
695 void ons_ControlPoint_Touch(entity this, entity toucher)
699 if(IS_VEHICLE(toucher) && toucher.owner)
701 if (!autocvar_g_onslaught_allow_vehicle_touch)
703 toucher = toucher.owner;
706 if(!IS_PLAYER(toucher)) { return; }
707 if(STAT(FROZEN, toucher)) { return; }
708 if(IS_DEAD(toucher)) { return; }
710 if ( SAME_TEAM(this,toucher) )
711 if ( this.iscaptured )
713 if(time <= toucher.teleport_antispam)
714 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT_ANTISPAM, rint(toucher.teleport_antispam - time));
716 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
719 attackable = ons_ControlPoint_Attackable(this, toucher.team);
720 if(attackable != 2 && attackable != 4)
722 // we've verified that this player has a legitimate claim to this point,
723 // so start building the captured point icon (which only captures this
724 // point if it successfully builds without being destroyed first)
725 ons_ControlPoint_Icon_Spawn(this, toucher);
727 this.ons_toucher = toucher;
729 onslaught_updatelinks();
732 void ons_ControlPoint_Think(entity this)
734 this.nextthink = time + ONS_CP_THINKRATE;
735 CSQCMODEL_AUTOUPDATE(this);
738 void ons_ControlPoint_Reset(entity this)
741 delete(this.goalentity);
743 this.goalentity = NULL;
745 this.colormap = 1024;
746 this.iscaptured = false;
747 this.islinked = false;
748 this.isshielded = true;
749 setthink(this, ons_ControlPoint_Think);
750 this.ons_toucher = NULL;
751 this.nextthink = time + ONS_CP_THINKRATE;
752 setmodel(this, MDL_ONS_CP_PAD1);
754 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
755 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
757 onslaught_updatelinks();
759 SUB_UseTargets(this, this, NULL); // to reset the structures, playerspawns etc.
761 CSQCMODEL_AUTOUPDATE(this);
764 void ons_DelayedControlPoint_Setup(entity this)
766 onslaught_updatelinks();
768 // captureshield setup
769 ons_CaptureShield_Spawn(this, MDL_ONS_CP_SHIELD);
771 CSQCMODEL_AUTOINIT(this);
774 void ons_ControlPoint_Setup(entity cp)
777 cp.ons_worldcpnext = ons_worldcplist; // link control point into ons_worldcplist
778 ons_worldcplist = cp;
780 cp.netname = "Control point";
782 cp.solid = SOLID_BBOX;
783 set_movetype(cp, MOVETYPE_NONE);
784 settouch(cp, ons_ControlPoint_Touch);
785 setthink(cp, ons_ControlPoint_Think);
786 cp.nextthink = time + ONS_CP_THINKRATE;
787 cp.reset = ons_ControlPoint_Reset;
789 cp.iscaptured = false;
791 cp.isshielded = true;
794 setmodel(cp, MDL_ONS_CP_PAD1);
796 // control point placement
797 if((cp.spawnflags & 1) || cp.noalign) // don't drop to floor, just stay at fixed location
800 set_movetype(cp, MOVETYPE_NONE);
802 else // drop to floor, automatically find a platform and set that as spawn origin
804 setorigin(cp, cp.origin + '0 0 20');
807 set_movetype(cp, MOVETYPE_TOSS);
811 WaypointSprite_SpawnFixed(WP_Null, cp.origin + CPGEN_WAYPOINT_OFFSET, cp, sprite, RADARICON_NONE);
812 WaypointSprite_UpdateRule(cp.sprite, cp.team, SPRITERULE_TEAMPLAY);
814 InitializeEntity(cp, ons_DelayedControlPoint_Setup, INITPRIO_SETLOCATION);
818 // =========================
819 // Main Generator Functions
820 // =========================
822 entity ons_Generator_Waypoint(entity e)
825 return WP_OnsGenShielded;
829 void ons_Generator_UpdateSprite(entity e)
831 entity s1 = ons_Generator_Waypoint(e);
832 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
834 if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
836 e.lastteam = e.team + 2;
837 e.lastshielded = e.isshielded;
841 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, false));
843 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
848 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, false));
850 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
852 WaypointSprite_Ping(e.sprite);
856 void ons_camSetup(entity this)
859 vector ang = '0 0 0';
860 vector best_ang = '0 0 0';
861 float best_trace_fraction = 0;
864 dir = vec2(cos(ang.y * DEG2RAD), sin(ang.y * DEG2RAD));
866 traceline(this.origin, this.origin - dir, MOVE_WORLDONLY, this);
867 if(trace_fraction > best_trace_fraction)
869 best_trace_fraction = trace_fraction;
871 if(trace_fraction == 1)
878 cam.origin = this.origin;
879 setorigin(cam, cam.origin);
880 cam.angles = best_ang;
881 Net_LinkEntity(cam, false, 0, clientcamera_send);
883 FOREACH_CLIENT(true, it.clientcamera = cam;);
885 // NOTE: engine networked
886 WriteByte(MSG_ALL, SVC_SETVIEWANGLES);
887 WriteAngle(MSG_ALL, cam.angles_x);
888 WriteAngle(MSG_ALL, cam.angles_y);
889 WriteAngle(MSG_ALL, cam.angles_z);
892 void ons_GeneratorDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
894 if(damage <= 0) return;
895 if(warmup_stage || game_stopped) return;
896 if(!round_handler_IsRoundStarted()) return;
898 if (attacker != this)
902 // generator is protected by a shield, so ignore the damage
903 if (time > this.pain_finished)
904 if (IS_PLAYER(attacker))
906 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
907 attacker.typehitsound += 1;
908 this.pain_finished = time + 1;
912 if (time > this.pain_finished)
914 this.pain_finished = time + 10;
915 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && SAME_TEAM(it, this), Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK));
916 play2team(this.team, SND(ONS_GENERATOR_UNDERATTACK));
919 TakeResource(this, RES_HEALTH, damage);
920 float hlth = GetResource(this, RES_HEALTH);
921 WaypointSprite_UpdateHealth(this.sprite, hlth);
922 // choose an animation frame based on health
923 this.frame = 10 * bound(0, (1 - hlth / this.max_health), 1);
924 // see if the generator is still functional, or dying
927 this.lasthealth = hlth;
931 if (attacker == this)
932 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME));
935 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED));
936 GameRules_scoring_add(attacker, SCORE, 100);
938 this.iscaptured = false;
939 this.islinked = false;
940 this.isshielded = false;
941 this.takedamage = DAMAGE_NO; // can't be hurt anymore
942 this.event_damage = func_null; // won't do anything if hurt
943 this.event_heal = func_null;
944 this.count = 0; // reset counter
945 setthink(this, func_null);
947 //this.think(); // do the first explosion now
949 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
950 WaypointSprite_Ping(this.sprite);
951 //WaypointSprite_Kill(this.sprite); // can't do this yet, code too poor
953 onslaught_updatelinks();
958 // Throw some flaming gibs on damage, more damage = more chance for gib
959 if(random() < damage/220)
961 sound(this, CH_TRIGGER, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
965 // particles on every hit
966 Send_Effect(EFFECT_SPARKS, hitloc, force * -1, 1);
970 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE, ATTEN_NORM);
972 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE, ATTEN_NORM);
975 this.SendFlags |= GSF_STATUS;
978 bool ons_GeneratorHeal(entity targ, entity inflictor, float amount, float limit)
980 float true_limit = ((limit != RES_LIMIT_NONE) ? limit : targ.max_health);
981 float hlth = GetResource(targ, RES_HEALTH);
982 if (hlth <= 0 || hlth >= true_limit)
985 GiveResourceWithLimit(targ, RES_HEALTH, amount, true_limit);
986 hlth = GetResource(targ, RES_HEALTH);
987 WaypointSprite_UpdateHealth(targ.sprite, hlth);
988 targ.frame = 10 * bound(0, (1 - hlth / targ.max_health), 1);
989 targ.lasthealth = hlth;
990 targ.SendFlags |= GSF_STATUS;
994 void ons_GeneratorThink(entity this)
996 this.nextthink = time + GEN_THINKRATE;
998 if (game_stopped || this.isshielded || time < this.wait)
1001 this.wait = time + 5;
1002 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it),
1004 if (SAME_TEAM(it, this))
1006 Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM);
1008 soundto(MSG_ONE, this, CHAN_AUTO, SND(ONS_GENERATOR_ALARM), VOL_BASE, ATTEN_NONE, 0);
1011 Send_Notification(NOTIF_ONE, it, MSG_CENTER, APP_TEAM_NUM(this.team, CENTER_ONS_NOTSHIELDED));
1015 void ons_GeneratorReset(entity this)
1017 this.team = this.team_saved;
1018 SetResourceExplicit(this, RES_HEALTH, autocvar_g_onslaught_gen_health);
1019 this.lasthealth = this.max_health = autocvar_g_onslaught_gen_health;
1020 this.takedamage = DAMAGE_AIM;
1021 this.bot_attack = true;
1022 if(!IL_CONTAINS(g_bot_targets, this))
1023 IL_PUSH(g_bot_targets, this);
1024 this.iscaptured = true;
1025 this.islinked = true;
1026 this.isshielded = true;
1027 this.event_damage = ons_GeneratorDamage;
1028 this.event_heal = ons_GeneratorHeal;
1029 setthink(this, ons_GeneratorThink);
1030 this.nextthink = time + GEN_THINKRATE;
1032 Net_LinkEntity(this, false, 0, generator_send);
1034 this.SendFlags = GSF_SETUP; // just incase
1035 this.SendFlags |= GSF_STATUS;
1037 WaypointSprite_UpdateMaxHealth(this.sprite, this.max_health);
1038 WaypointSprite_UpdateHealth(this.sprite, GetResource(this, RES_HEALTH));
1039 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
1041 onslaught_updatelinks();
1044 void ons_DelayedGeneratorSetup(entity this)
1047 waypoint_spawnforitem_force(this, this.origin);
1048 this.nearestwaypointtimeout = 0; // activate waypointing again
1049 this.bot_basewaypoint = this.nearestwaypoint;
1051 // captureshield setup
1052 ons_CaptureShield_Spawn(this, MDL_ONS_GEN_SHIELD);
1054 onslaught_updatelinks();
1056 Net_LinkEntity(this, false, 0, generator_send);
1060 void onslaught_generator_touch(entity this, entity toucher)
1062 if ( IS_PLAYER(toucher) )
1063 if ( SAME_TEAM(this,toucher) )
1064 if ( this.iscaptured )
1066 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
1070 void ons_GeneratorSetup(entity gen) // called when spawning a generator entity on the map as a spawnfunc
1073 int teamnum = gen.team;
1076 gen.ons_worldgeneratornext = ons_worldgeneratorlist; // link generator into ons_worldgeneratorlist
1077 ons_worldgeneratorlist = gen;
1079 gen.netname = sprintf("%s generator", Team_ColoredFullName(teamnum));
1080 gen.solid = SOLID_BBOX;
1081 gen.team_saved = teamnum;
1082 IL_PUSH(g_saved_team, gen);
1083 set_movetype(gen, MOVETYPE_NONE);
1084 gen.lasthealth = gen.max_health = autocvar_g_onslaught_gen_health;
1085 SetResourceExplicit(gen, RES_HEALTH, autocvar_g_onslaught_gen_health);
1086 gen.takedamage = DAMAGE_AIM;
1087 gen.bot_attack = true;
1088 IL_PUSH(g_bot_targets, gen);
1089 gen.event_damage = ons_GeneratorDamage;
1090 gen.event_heal = ons_GeneratorHeal;
1091 gen.reset = ons_GeneratorReset;
1092 setthink(gen, ons_GeneratorThink);
1093 gen.nextthink = time + GEN_THINKRATE;
1094 gen.iscaptured = true;
1095 gen.islinked = true;
1096 gen.isshielded = true;
1097 settouch(gen, onslaught_generator_touch);
1100 // model handled by CSQC
1101 setsize(gen, GENERATOR_MIN, GENERATOR_MAX);
1102 setorigin(gen, (gen.origin + CPGEN_SPAWN_OFFSET));
1103 gen.colormap = 1024 + (teamnum - 1) * 17;
1105 // generator placement
1109 WaypointSprite_SpawnFixed(WP_Null, gen.origin + CPGEN_WAYPOINT_OFFSET, gen, sprite, RADARICON_NONE);
1110 WaypointSprite_UpdateRule(gen.sprite, gen.team, SPRITERULE_TEAMPLAY);
1111 WaypointSprite_UpdateMaxHealth(gen.sprite, gen.max_health);
1112 WaypointSprite_UpdateHealth(gen.sprite, GetResource(gen, RES_HEALTH));
1114 InitializeEntity(gen, ons_DelayedGeneratorSetup, INITPRIO_SETLOCATION);
1122 int total_generators;
1123 void Onslaught_count_generators()
1126 total_generators = 0;
1127 for (int i = 1; i <= NUM_TEAMS; ++i)
1129 Team_SetNumberOfOwnedItems(Team_GetTeamFromIndex(i), 0);
1131 for(e = ons_worldgeneratorlist; e; e = e.ons_worldgeneratornext)
1134 if (GetResource(e, RES_HEALTH) < 1)
1138 entity team_ = Entity_GetTeam(e);
1139 int num_generators = Team_GetNumberOfOwnedItems(team_);
1141 Team_SetNumberOfOwnedItems(team_, num_generators);
1145 void nades_Clear(entity e);
1147 bool Onslaught_CheckWinner()
1149 if ((autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60) || (round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0))
1151 ons_stalemate = true;
1153 if (!wpforenemy_announced)
1155 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT);
1156 sound(NULL, CH_INFO, SND_ONS_GENERATOR_DECAY, VOL_BASE, ATTEN_NONE);
1158 wpforenemy_announced = true;
1161 entity tmp_entity; // temporary entity
1163 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext) if(time >= tmp_entity.ons_overtime_damagedelay)
1165 // tmp_entity.max_health / 300 gives 5 minutes of overtime.
1166 // control points reduce the overtime duration.
1169 for(e = ons_worldcplist; e; e = e.ons_worldcpnext)
1171 if(DIFF_TEAM(e, tmp_entity))
1176 if(autocvar_g_campaign && autocvar__campaign_testrun)
1177 d = d * tmp_entity.max_health;
1179 d = d * tmp_entity.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
1181 Damage(tmp_entity, tmp_entity, tmp_entity, d, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, tmp_entity.origin, '0 0 0');
1183 tmp_entity.sprite.SendFlags |= 16;
1185 tmp_entity.ons_overtime_damagedelay = time + 1;
1188 else { wpforenemy_announced = false; ons_stalemate = false; }
1190 Onslaught_count_generators();
1191 int winner_team = Team_GetWinnerTeam_WithOwnedItems(1);
1197 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
1198 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
1199 TeamScore_AddToTeam(winner_team, ST_ONS_CAPS, +1);
1201 else if(winner_team == -1)
1203 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_TIED);
1204 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_TIED);
1207 ons_stalemate = false;
1209 play2all(SND(CTF_CAPTURE(winner_team)));
1211 round_handler_Init(7, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
1213 FOREACH_CLIENT(IS_PLAYER(it), {
1214 STAT(ROUNDLOST, it) = true;
1215 it.player_blocked = true;
1220 game_stopped = true;
1224 bool Onslaught_CheckPlayers()
1229 void Onslaught_RoundStart()
1232 FOREACH_CLIENT(IS_PLAYER(it), it.player_blocked = false);
1234 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1235 tmp_entity.sprite.SendFlags |= 16;
1237 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1238 tmp_entity.sprite.SendFlags |= 16;
1246 // NOTE: LEGACY CODE, needs to be re-written!
1248 void havocbot_role_ons_setrole(entity this, int role)
1252 case HAVOCBOT_ONS_ROLE_DEFENSE:
1253 LOG_DEBUG(this.netname, " switched to defense");
1254 this.havocbot_role = havocbot_role_ons_defense;
1255 this.havocbot_role_timeout = 0;
1257 case HAVOCBOT_ONS_ROLE_ASSISTANT:
1258 LOG_DEBUG(this.netname, " switched to assistant");
1259 this.havocbot_role = havocbot_role_ons_assistant;
1260 this.havocbot_role_timeout = 0;
1262 case HAVOCBOT_ONS_ROLE_OFFENSE:
1263 LOG_DEBUG(this.netname, " switched to offense");
1264 this.havocbot_role = havocbot_role_ons_offense;
1265 this.havocbot_role_timeout = 0;
1270 void havocbot_goalrating_ons_controlpoints_attack(entity this, float ratingscale)
1272 entity cp, cp1, cp2, best, wp;
1273 float radius, bestvalue;
1277 // Filter control points
1278 for(cp2 = ons_worldcplist; cp2; cp2 = cp2.ons_worldcpnext)
1281 cp2.wpconsidered = false;
1286 // Ignore owned controlpoints
1287 if(!((cp2.aregensneighbor & BIT(this.team)) || (cp2.arecpsneighbor & BIT(this.team))))
1290 // Count team mates interested in this control point
1291 // (easier and cleaner than keeping counters per cp and teams)
1292 FOREACH_CLIENT(it != this && IS_PLAYER(it), {
1293 if(SAME_TEAM(it, this))
1294 if(it.havocbot_role == havocbot_role_ons_offense)
1295 if(it.havocbot_ons_target == cp2)
1299 // NOTE: probably decrease the cost of attackable control points
1301 cp2.wpconsidered = true;
1304 // We'll consider only the best case
1305 bestvalue = FLOAT_MAX;
1307 for(cp1 = ons_worldcplist; cp1; cp1 = cp1.ons_worldcpnext)
1309 if (!cp1.wpconsidered)
1312 if(cp1.wpcost<bestvalue)
1314 bestvalue = cp1.wpcost;
1316 this.havocbot_ons_target = cp1;
1323 LOG_DEBUG(this.netname, " chose cp ranked ", ftos(bestvalue));
1327 // Should be attacked
1328 // Rate waypoints near it
1331 bestvalue = FLOAT_MAX;
1332 for (radius = 500; radius <= 1000 && !found; radius += 500)
1334 IL_EACH(g_waypoints, vdist(cp.origin - it.origin, <, radius),
1336 if (!(it.wpflags & WAYPOINTFLAG_GENERATED) && checkpvs(it.origin, cp))
1339 if (it.cnt < bestvalue)
1350 navigation_routerating(this, best, ratingscale, 10000);
1353 this.havocbot_attack_time = 0;
1354 if(checkpvs(this.origin + this.view_ofs, cp))
1355 if(checkpvs(this.origin + this.view_ofs, best))
1356 this.havocbot_attack_time = time + 2;
1360 navigation_routerating(this, cp, ratingscale, 10000);
1362 LOG_DEBUG(this.netname, " found an attackable controlpoint at ", vtos(cp.origin));
1366 // Should be touched
1367 LOG_DEBUG(this.netname, " found a touchable controlpoint at ", vtos(cp.origin));
1368 navigation_routerating(this, cp, ratingscale * 2, 10000);
1372 bool havocbot_goalrating_ons_generator_attack(entity this, float ratingscale)
1374 entity g, wp, bestwp;
1378 for(g = ons_worldgeneratorlist; g; g = g.ons_worldgeneratornext)
1380 if(SAME_TEAM(g, this) || g.isshielded)
1383 // Should be attacked
1384 // Rate waypoints near it
1387 bestvalue = FLOAT_MAX;
1389 IL_EACH(g_waypoints, vdist(g.origin - it.origin, <, 400),
1391 if (checkpvs(it.origin, g))
1394 if (it.cnt < bestvalue)
1404 LOG_DEBUG("waypoints found around generator");
1405 navigation_routerating(this, bestwp, ratingscale, 10000);
1408 this.havocbot_attack_time = 0;
1409 if(checkpvs(this.origin + this.view_ofs, g))
1410 if(checkpvs(this.origin + this.view_ofs, bestwp))
1411 this.havocbot_attack_time = time + 5;
1417 LOG_DEBUG("generator found without waypoints around");
1418 // if there aren't waypoints near the generator go straight to it
1419 navigation_routerating(this, g, ratingscale, 10000);
1420 this.havocbot_attack_time = 0;
1427 void havocbot_role_ons_offense(entity this)
1431 this.havocbot_attack_time = 0;
1432 havocbot_ons_reset_role(this);
1436 // Set the role timeout if necessary
1437 if (!this.havocbot_role_timeout)
1438 this.havocbot_role_timeout = time + 120;
1440 if (time > this.havocbot_role_timeout)
1442 havocbot_ons_reset_role(this);
1446 if(this.havocbot_attack_time>time)
1449 if (navigation_goalrating_timeout(this))
1451 navigation_goalrating_start(this);
1452 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
1453 if(!havocbot_goalrating_ons_generator_attack(this, 10000))
1454 havocbot_goalrating_ons_controlpoints_attack(this, 10000);
1455 havocbot_goalrating_items(this, 25000, this.origin, 10000);
1456 navigation_goalrating_end(this);
1458 navigation_goalrating_timeout_set(this);
1462 void havocbot_role_ons_assistant(entity this)
1464 havocbot_ons_reset_role(this);
1467 void havocbot_role_ons_defense(entity this)
1469 havocbot_ons_reset_role(this);
1472 void havocbot_ons_reset_role(entity this)
1477 this.havocbot_ons_target = NULL;
1479 // TODO: Defend control points or generator if necessary
1481 havocbot_role_ons_setrole(this, HAVOCBOT_ONS_ROLE_OFFENSE);
1486 * Find control point or generator owned by the same team self which is nearest to pos
1487 * if max_dist is positive, only control points within this range will be considered
1489 entity ons_Nearest_ControlPoint(entity this, vector pos, float max_dist)
1491 entity closest_target = NULL;
1492 for(entity cp = ons_worldcplist; cp; cp = cp.ons_worldcpnext)
1494 if(SAME_TEAM(cp, this))
1496 if(max_dist <= 0 || vdist(cp.origin - pos, <=, max_dist))
1497 if(vlen2(cp.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
1498 closest_target = cp;
1500 for(entity gen = ons_worldgeneratorlist; gen; gen = gen.ons_worldgeneratornext)
1502 if(SAME_TEAM(gen, this))
1503 if(max_dist <= 0 || vdist(gen.origin - pos, <, max_dist))
1504 if(vlen2(gen.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
1505 closest_target = gen;
1508 return closest_target;
1512 * Find control point or generator owned by the same team self which is nearest to pos
1513 * if max_dist is positive, only control points within this range will be considered
1514 * This function only check distances on the XY plane, disregarding Z
1516 entity ons_Nearest_ControlPoint_2D(entity this, vector pos, float max_dist)
1518 entity closest_target = NULL;
1520 float smallest_distance = 0, distance;
1522 for(entity cp = ons_worldcplist; cp; cp = cp.ons_worldcpnext)
1524 delta = cp.origin - pos;
1526 distance = vlen(delta);
1528 if(SAME_TEAM(cp, this))
1530 if(max_dist <= 0 || distance <= max_dist)
1531 if(closest_target == NULL || distance <= smallest_distance )
1533 closest_target = cp;
1534 smallest_distance = distance;
1537 for(entity gen = ons_worldgeneratorlist; gen; gen = gen.ons_worldgeneratornext)
1539 delta = gen.origin - pos;
1541 distance = vlen(delta);
1543 if(SAME_TEAM(gen, this))
1544 if(max_dist <= 0 || distance <= max_dist)
1545 if(closest_target == NULL || distance <= smallest_distance )
1547 closest_target = gen;
1548 smallest_distance = distance;
1552 return closest_target;
1555 * find the number of control points and generators in the same team as this
1557 int ons_Count_SelfControlPoints(entity this)
1560 for(entity cp = ons_worldcplist; cp; cp = cp.ons_worldcpnext)
1562 if(SAME_TEAM(cp, this))
1566 for(entity gen = ons_worldgeneratorlist; gen; gen = gen.ons_worldgeneratornext)
1568 if(SAME_TEAM(gen, this))
1575 * Teleport player to a random position near tele_target
1576 * if tele_effects is true, teleport sound+particles are created
1577 * return false on failure
1579 bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effects)
1587 // narrow the range for each iteration to increase chances that a spawnpoint
1588 // can be found even if there's little room around the control point
1589 float iteration_scale = 1;
1590 for(i = 0; i < 16; ++i)
1592 iteration_scale -= i / 16;
1593 theta = random() * 2 * M_PI;
1597 loc *= random() * range * iteration_scale;
1599 loc += tele_target.origin + '0 0 128' * iteration_scale;
1601 tracebox(loc, STAT(PL_MIN, player), STAT(PL_MAX, player), loc, MOVE_NORMAL, player);
1602 if(trace_fraction == 1.0 && !trace_startsolid)
1604 traceline(tele_target.origin, loc, MOVE_NOMONSTERS, tele_target); // double check to make sure we're not spawning outside the NULL
1605 if(trace_fraction == 1.0 && !trace_startsolid)
1609 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
1610 sound (player, CH_TRIGGER, SND_TELEPORT, VOL_BASE, ATTEN_NORM);
1612 setorigin(player, loc);
1613 player.angles = '0 1 0' * ( theta * RAD2DEG + 180 );
1614 makevectors(player.angles);
1615 player.fixangle = true;
1616 if (IS_BOT_CLIENT(player))
1618 player.v_angle = player.angles;
1619 bot_aim_reset(player);
1621 player.teleport_antispam = time + autocvar_g_onslaught_teleport_wait;
1624 Send_Effect(EFFECT_TELEPORT, player.origin + v_forward * 32, '0 0 0', 1);
1637 MUTATOR_HOOKFUNCTION(ons, reset_map_global)
1639 FOREACH_CLIENT(IS_PLAYER(it), {
1640 STAT(ROUNDLOST, it) = false;
1641 it.ons_deathloc = '0 0 0';
1642 PutClientInServer(it);
1643 it.clientcamera = it;
1648 MUTATOR_HOOKFUNCTION(ons, ClientDisconnect)
1650 entity player = M_ARGV(0, entity);
1652 player.ons_deathloc = '0 0 0';
1655 MUTATOR_HOOKFUNCTION(ons, MakePlayerObserver)
1657 entity player = M_ARGV(0, entity);
1659 player.ons_deathloc = '0 0 0';
1662 MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
1664 entity player = M_ARGV(0, entity);
1666 if(!round_handler_IsRoundStarted())
1668 player.player_blocked = true;
1673 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1675 l.sprite.SendFlags |= 16;
1677 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1679 l.sprite.SendFlags |= 16;
1682 if(ons_stalemate) { Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); }
1684 if ( autocvar_g_onslaught_spawn_choose )
1685 if ( player.ons_spawn_by )
1686 if ( ons_Teleport(player,player.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) )
1688 player.ons_spawn_by = NULL;
1692 if(autocvar_g_onslaught_spawn_at_controlpoints)
1693 if(random() <= autocvar_g_onslaught_spawn_at_controlpoints_chance)
1695 float random_target = autocvar_g_onslaught_spawn_at_controlpoints_random;
1696 entity tmp_entity, closest_target = NULL;
1697 vector spawn_loc = player.ons_deathloc;
1699 // new joining player or round reset, don't bother checking
1700 if(spawn_loc == '0 0 0') { return false; }
1702 if(random_target) { RandomSelection_Init(); }
1704 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1706 if(SAME_TEAM(tmp_entity, player))
1709 RandomSelection_AddEnt(tmp_entity, 1, 1);
1710 else if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL)
1711 closest_target = tmp_entity;
1715 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1721 float iteration_scale = 1;
1722 for(i = 0; i < 10; ++i)
1724 iteration_scale -= i / 10;
1725 loc = closest_target.origin + '0 0 96' * iteration_scale;
1726 loc += ('0 1 0' * random()) * 128 * iteration_scale;
1727 tracebox(loc, STAT(PL_MIN, player), STAT(PL_MAX, player), loc, MOVE_NORMAL, player);
1728 if(trace_fraction == 1.0 && !trace_startsolid)
1730 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL
1731 if(trace_fraction == 1.0 && !trace_startsolid)
1733 setorigin(player, loc);
1734 player.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1742 if(autocvar_g_onslaught_spawn_at_generator)
1743 if(random() <= autocvar_g_onslaught_spawn_at_generator_chance)
1745 float random_target = autocvar_g_onslaught_spawn_at_generator_random;
1746 entity tmp_entity, closest_target = NULL;
1747 vector spawn_loc = player.ons_deathloc;
1749 // new joining player or round reset, don't bother checking
1750 if(spawn_loc == '0 0 0') { return false; }
1752 if(random_target) { RandomSelection_Init(); }
1754 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1757 RandomSelection_AddEnt(tmp_entity, 1, 1);
1760 if(SAME_TEAM(tmp_entity, player))
1761 if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL)
1762 closest_target = tmp_entity;
1766 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1772 float iteration_scale = 1;
1773 for(i = 0; i < 10; ++i)
1775 iteration_scale -= i / 10;
1776 loc = closest_target.origin + '0 0 128' * iteration_scale;
1777 loc += ('0 1 0' * random()) * 256 * iteration_scale;
1778 tracebox(loc, STAT(PL_MIN, player), STAT(PL_MAX, player), loc, MOVE_NORMAL, player);
1779 if(trace_fraction == 1.0 && !trace_startsolid)
1781 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL
1782 if(trace_fraction == 1.0 && !trace_startsolid)
1784 setorigin(player, loc);
1785 player.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1796 MUTATOR_HOOKFUNCTION(ons, PlayerDies)
1798 entity frag_target = M_ARGV(2, entity);
1800 frag_target.ons_deathloc = frag_target.origin;
1802 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1804 l.sprite.SendFlags |= 16;
1806 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1808 l.sprite.SendFlags |= 16;
1811 if ( autocvar_g_onslaught_spawn_choose )
1812 if ( ons_Count_SelfControlPoints(frag_target) > 1 )
1813 stuffcmd(frag_target, "qc_cmd_cl hud clickradar\n");
1818 MUTATOR_HOOKFUNCTION(ons, MonsterMove)
1820 entity mon = M_ARGV(0, entity);
1822 entity e = find(NULL, targetname, mon.target);
1827 void ons_MonsterSpawn_Delayed(entity this)
1829 entity own = this.owner;
1831 if(!own) { delete(this); return; }
1835 entity e = find(NULL, target, own.targetname);
1840 own.use(own, e, NULL);
1847 MUTATOR_HOOKFUNCTION(ons, MonsterSpawn)
1849 entity mon = M_ARGV(0, entity);
1853 InitializeEntity(e, ons_MonsterSpawn_Delayed, INITPRIO_FINDTARGET);
1856 void ons_TurretSpawn_Delayed(entity this)
1858 entity own = this.owner;
1860 if(!own) { delete(this); return; }
1864 entity e = find(NULL, target, own.targetname);
1868 own.active = ACTIVE_NOT;
1870 own.use(own, e, NULL);
1877 MUTATOR_HOOKFUNCTION(ons, TurretSpawn)
1879 entity turret = M_ARGV(0, entity);
1883 InitializeEntity(e, ons_TurretSpawn_Delayed, INITPRIO_FINDTARGET);
1888 MUTATOR_HOOKFUNCTION(ons, HavocBot_ChooseRole)
1890 entity bot = M_ARGV(0, entity);
1892 havocbot_ons_reset_role(bot);
1896 MUTATOR_HOOKFUNCTION(ons, TeamBalance_CheckAllowedTeams)
1898 // onslaught is special
1899 for(entity tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1901 if (Team_IsValidTeam(tmp_entity.team))
1903 M_ARGV(0, float) |= Team_TeamToBit(tmp_entity.team);
1910 MUTATOR_HOOKFUNCTION(ons, SpectateCopy)
1912 entity spectatee = M_ARGV(0, entity);
1913 entity client = M_ARGV(1, entity);
1915 STAT(ROUNDLOST, client) = STAT(ROUNDLOST, spectatee); // make spectators see it too
1918 MUTATOR_HOOKFUNCTION(ons, SV_ParseClientCommand)
1920 if(MUTATOR_RETURNVALUE) // command was already handled?
1923 entity player = M_ARGV(0, entity);
1924 string cmd_name = M_ARGV(1, string);
1925 int cmd_argc = M_ARGV(2, int);
1927 if ( cmd_name == "ons_spawn" )
1929 vector pos = player.origin;
1931 pos_x = stof(argv(1));
1933 pos_y = stof(argv(2));
1935 pos_z = stof(argv(3));
1937 if ( IS_PLAYER(player) )
1939 if ( !STAT(FROZEN, player) )
1941 entity source_point = ons_Nearest_ControlPoint(player, player.origin, autocvar_g_onslaught_teleport_radius);
1943 if ( !source_point && GetResource(player, RES_HEALTH) > 0 )
1945 sprint(player, "\nYou need to be next to a control point\n");
1950 entity closest_target = ons_Nearest_ControlPoint_2D(player, pos, autocvar_g_onslaught_click_radius);
1952 if ( closest_target == NULL )
1954 sprint(player, "\nNo control point found\n");
1958 if ( GetResource(player, RES_HEALTH) <= 0 )
1960 player.ons_spawn_by = closest_target;
1961 player.respawn_flags = player.respawn_flags | RESPAWN_FORCE;
1965 if ( source_point == closest_target )
1967 sprint(player, "\nTeleporting to the same point\n");
1971 if ( !ons_Teleport(player,closest_target,autocvar_g_onslaught_teleport_radius,true) )
1972 sprint(player, "\nUnable to teleport there\n");
1978 sprint(player, "\nNo teleportation for you\n");
1986 MUTATOR_HOOKFUNCTION(ons, PlayerUseKey)
1988 if(MUTATOR_RETURNVALUE || game_stopped) return false;
1990 entity player = M_ARGV(0, entity);
1992 if((time > player.teleport_antispam) && (!IS_DEAD(player)) && !player.vehicle)
1994 entity source_point = ons_Nearest_ControlPoint(player, player.origin, autocvar_g_onslaught_teleport_radius);
1997 stuffcmd(player, "qc_cmd_cl hud clickradar\n");
2003 MUTATOR_HOOKFUNCTION(ons, PlayHitsound)
2005 entity frag_victim = M_ARGV(0, entity);
2007 return (frag_victim.classname == "onslaught_generator" && !frag_victim.isshielded)
2008 || (frag_victim.classname == "onslaught_controlpoint_icon" && !frag_victim.owner.isshielded);
2011 MUTATOR_HOOKFUNCTION(ons, SendWaypoint)
2013 entity wp = M_ARGV(0, entity);
2014 entity to = M_ARGV(1, entity);
2015 int sf = M_ARGV(2, int);
2016 int wp_flag = M_ARGV(3, int);
2020 if(wp.owner.classname == "onslaught_controlpoint")
2022 entity wp_owner = wp.owner;
2023 entity e = WaypointSprite_getviewentity(to);
2024 if(SAME_TEAM(e, wp_owner) && GetResource(wp_owner.goalentity, RES_HEALTH) >= wp_owner.goalentity.max_health) { wp_flag |= 2; }
2025 if(!ons_ControlPoint_Attackable(wp_owner, e.team)) { wp_flag |= 2; }
2027 if(wp.owner.classname == "onslaught_generator")
2029 entity wp_owner = wp.owner;
2030 if(wp_owner.isshielded && GetResource(wp_owner, RES_HEALTH) >= wp_owner.max_health) { wp_flag |= 2; }
2031 if(GetResource(wp_owner, RES_HEALTH) <= 0) { wp_flag |= 2; }
2035 M_ARGV(3, int) = wp_flag;
2038 MUTATOR_HOOKFUNCTION(ons, TurretValidateTarget)
2040 entity turret_target = M_ARGV(1, entity);
2042 if(substring(turret_target.classname, 0, 10) == "onslaught_") // don't attack onslaught targets, that's the player's job!
2044 M_ARGV(3, float) = -3;
2051 MUTATOR_HOOKFUNCTION(ons, TurretThink)
2053 entity turret = M_ARGV(0, entity);
2055 // ONS uses somewhat backwards linking.
2058 entity e = find(NULL, targetname, turret.target);
2060 turret.team = e.team;
2063 if(turret.team != turret.tur_head.team)
2064 turret_respawn(turret);
2072 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
2073 Link between control points.
2075 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.
2078 "target" - first control point.
2079 "target2" - second control point.
2081 spawnfunc(onslaught_link)
2083 if(!g_onslaught) { delete(this); return; }
2085 if (this.target == "" || this.target2 == "")
2086 objerror(this, "target and target2 must be set\n");
2088 this.ons_worldlinknext = ons_worldlinklist; // link into ons_worldlinklist
2089 ons_worldlinklist = this;
2091 InitializeEntity(this, ons_DelayedLinkSetup, INITPRIO_FINDTARGET);
2092 Net_LinkEntity(this, false, 0, ons_Link_Send);
2095 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
2096 Control point. Be sure to give this enough clearance so that the shootable part has room to exist
2098 This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
2101 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2102 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
2103 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
2106 spawnfunc(onslaught_controlpoint)
2108 if(!g_onslaught) { delete(this); return; }
2110 ons_ControlPoint_Setup(this);
2113 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
2116 spawnfunc_onslaught_link entities can target this.
2119 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
2120 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2122 spawnfunc(onslaught_generator)
2124 if(!g_onslaught) { delete(this); return; }
2125 if(!this.team) { objerror(this, "team must be set"); }
2127 ons_GeneratorSetup(this);
2131 void ons_ScoreRules()
2133 entity balance = TeamBalance_CheckAllowedTeams(NULL);
2134 int teams = TeamBalance_GetAllowedTeams(balance);
2135 TeamBalance_Destroy(balance);
2136 GameRules_scoring(teams, SFL_SORT_PRIO_PRIMARY, 0, {
2137 field_team(ST_ONS_CAPS, "destroyed", SFL_SORT_PRIO_PRIMARY);
2138 field(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
2139 field(SP_ONS_TAKES, "takes", 0);
2143 void ons_DelayedInit(entity this) // Do this check with a delay so we can wait for teams to be set up
2147 round_handler_Spawn(Onslaught_CheckPlayers, Onslaught_CheckWinner, Onslaught_RoundStart);
2148 round_handler_Init(5, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
2151 void ons_Initialize()
2154 g_onsshields = IL_NEW();
2155 ons_captureshield_force = autocvar_g_onslaught_shield_force;
2157 cam = new(objective_camera);
2159 InitializeEntity(NULL, ons_DelayedInit, INITPRIO_GAMETYPE);