1 #include "sv_onslaught.qh"
2 #include "sv_controlpoint.qh"
3 #include "sv_generator.qh"
5 #include <common/mapobjects/defs.qh>
9 float autocvar_g_onslaught_teleport_wait;
10 bool autocvar_g_onslaught_spawn_at_controlpoints;
11 bool autocvar_g_onslaught_spawn_at_generator;
12 float autocvar_g_onslaught_cp_proxydecap;
13 float autocvar_g_onslaught_cp_proxydecap_distance = 512;
14 float autocvar_g_onslaught_cp_proxydecap_dps = 100;
15 float autocvar_g_onslaught_spawn_at_controlpoints_chance = 0.5;
16 float autocvar_g_onslaught_spawn_at_controlpoints_random;
17 float autocvar_g_onslaught_spawn_at_generator_chance;
18 float autocvar_g_onslaught_spawn_at_generator_random;
19 float autocvar_g_onslaught_cp_buildhealth;
20 float autocvar_g_onslaught_cp_buildtime;
21 float autocvar_g_onslaught_cp_health;
22 float autocvar_g_onslaught_cp_regen;
23 float autocvar_g_onslaught_gen_health;
24 float autocvar_g_onslaught_shield_force = 100;
25 float autocvar_g_onslaught_allow_vehicle_touch;
26 float autocvar_g_onslaught_round_timelimit;
27 float autocvar_g_onslaught_warmup;
28 float autocvar_g_onslaught_teleport_radius;
29 float autocvar_g_onslaught_spawn_choose;
30 float autocvar_g_onslaught_click_radius;
34 // =======================
35 // CaptureShield Functions
36 // =======================
38 bool clientcamera_send(entity this, entity to, int sf)
40 WriteHeader(MSG_ENTITY, ENT_ONSCAMERA);
42 WriteVector(MSG_ENTITY, this.origin);
44 WriteAngleVector(MSG_ENTITY, this.angles);
49 bool ons_CaptureShield_Customize(entity this, entity client)
51 entity e = WaypointSprite_getviewentity(client);
53 if(!this.enemy.isshielded && (ons_ControlPoint_Attackable(this.enemy, e.team) > 0 || this.enemy.classname != "onslaught_controlpoint")) { return false; }
54 if(SAME_TEAM(this, e)) { return false; }
59 void ons_CaptureShield_Touch(entity this, entity toucher)
61 if(!this.enemy.isshielded && (ons_ControlPoint_Attackable(this.enemy, toucher.team) > 0 || this.enemy.classname != "onslaught_controlpoint")) { return; }
62 if(!IS_PLAYER(toucher)) { return; }
63 if(SAME_TEAM(toucher, this)) { return; }
65 vector mymid = (this.absmin + this.absmax) * 0.5;
66 vector theirmid = (toucher.absmin + toucher.absmax) * 0.5;
68 Damage(toucher, this, this, 0, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, mymid, normalize(theirmid - mymid) * ons_captureshield_force);
70 if(IS_REAL_CLIENT(toucher))
72 play2(toucher, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
74 if(this.enemy.classname == "onslaught_generator")
75 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_GENERATOR_SHIELDED);
77 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_CONTROLPOINT_SHIELDED);
81 void ons_CaptureShield_Reset(entity this)
83 this.colormap = this.enemy.colormap;
84 this.team = this.enemy.team;
87 void ons_CaptureShield_Spawn(entity generator, bool is_generator)
89 entity shield = new(ons_captureshield);
90 IL_PUSH(g_onsshields, shield);
92 shield.enemy = generator;
93 shield.team = generator.team;
94 shield.colormap = generator.colormap;
95 shield.reset = ons_CaptureShield_Reset;
96 settouch(shield, ons_CaptureShield_Touch);
97 setcefc(shield, ons_CaptureShield_Customize);
98 shield.effects = EF_ADDITIVE;
99 set_movetype(shield, MOVETYPE_NOCLIP);
100 shield.solid = SOLID_TRIGGER;
101 shield.avelocity = '7 0 11';
103 shield.model = ((is_generator) ? "models/onslaught/generator_shield.md3" : "models/onslaught/controlpoint_shield.md3");
105 precache_model(shield.model);
106 setorigin(shield, generator.origin);
107 _setmodel(shield, shield.model);
108 setsize(shield, shield.scale * shield.mins, shield.scale * shield.maxs);
116 void onslaught_updatelinks()
119 // first check if the game has ended
120 LOG_DEBUG("--- updatelinks ---");
121 // mark generators as being shielded and networked
122 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
125 LOG_DEBUG(etos(l), " (generator) belongs to team ", ftos(l.team));
127 LOG_DEBUG(etos(l), " (generator) is destroyed");
128 l.islinked = l.iscaptured;
129 l.isshielded = l.iscaptured;
130 l.sprite.SendFlags |= 16;
132 // mark points as shielded and not networked
133 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
137 l.aregensneighbor = 0;
138 l.arecpsneighbor = 0;
139 LOG_DEBUG(etos(l), " (point) belongs to team ", ftos(l.team));
140 l.sprite.SendFlags |= 16;
142 // flow power outward from the generators through the network
147 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
149 // if both points are captured by the same team, and only one of
150 // them is powered, mark the other one as powered as well
151 if (l.enemy.iscaptured && l.goalentity.iscaptured)
152 if (l.enemy.islinked != l.goalentity.islinked)
153 if(SAME_TEAM(l.enemy, l.goalentity))
155 if (!l.goalentity.islinked)
158 l.goalentity.islinked = true;
159 LOG_DEBUG(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)");
161 else if (!l.enemy.islinked)
164 l.enemy.islinked = true;
165 LOG_DEBUG(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)");
170 // now that we know which points are powered we can mark their neighbors
171 // as unshielded if team differs
172 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
174 if (l.goalentity.islinked)
176 if(DIFF_TEAM(l.goalentity, l.enemy))
178 LOG_DEBUG(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)");
179 l.enemy.isshielded = false;
181 if(l.goalentity.classname == "onslaught_generator")
182 l.enemy.aregensneighbor |= BIT(l.goalentity.team);
184 l.enemy.arecpsneighbor |= BIT(l.goalentity.team);
186 if (l.enemy.islinked)
188 if(DIFF_TEAM(l.goalentity, l.enemy))
190 LOG_DEBUG(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)");
191 l.goalentity.isshielded = false;
193 if(l.enemy.classname == "onslaught_generator")
194 l.goalentity.aregensneighbor |= BIT(l.enemy.team);
196 l.goalentity.arecpsneighbor |= BIT(l.enemy.team);
199 // now update the generators
200 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
204 LOG_DEBUG(etos(l), " (generator) is shielded");
205 l.takedamage = DAMAGE_NO;
207 IL_REMOVE(g_bot_targets, l);
208 l.bot_attack = false;
212 LOG_DEBUG(etos(l), " (generator) is not shielded");
213 l.takedamage = DAMAGE_AIM;
215 IL_PUSH(g_bot_targets, l);
219 ons_Generator_UpdateSprite(l);
221 // now update the takedamage and alpha variables on control point icons
222 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
226 LOG_DEBUG(etos(l), " (point) is shielded");
229 l.goalentity.takedamage = DAMAGE_NO;
230 if(l.goalentity.bot_attack)
231 IL_REMOVE(g_bot_targets, l.goalentity);
232 l.goalentity.bot_attack = false;
237 LOG_DEBUG(etos(l), " (point) is not shielded");
240 l.goalentity.takedamage = DAMAGE_AIM;
241 if(!l.goalentity.bot_attack)
242 IL_PUSH(g_bot_targets, l.goalentity);
243 l.goalentity.bot_attack = true;
246 ons_ControlPoint_UpdateSprite(l);
248 IL_EACH(g_onsshields, true,
250 it.team = it.enemy.team;
251 it.colormap = it.enemy.colormap;
256 // ===================
257 // Main Link Functions
258 // ===================
260 bool ons_Link_Send(entity this, entity to, int sendflags)
262 WriteHeader(MSG_ENTITY, ENT_CLIENT_RADARLINK);
263 WriteByte(MSG_ENTITY, sendflags);
266 WriteVector(MSG_ENTITY, this.goalentity.origin);
270 WriteVector(MSG_ENTITY, this.enemy.origin);
274 WriteByte(MSG_ENTITY, this.clientcolors); // which is goalentity's color + enemy's color * 16
279 void ons_Link_CheckUpdate(entity this)
281 // TODO check if the two sides have moved (currently they won't move anyway)
282 float cc = 0, cc1 = 0, cc2 = 0;
284 if(this.goalentity.islinked || this.goalentity.iscaptured) { cc1 = (this.goalentity.team - 1) * 0x01; }
285 if(this.enemy.islinked || this.enemy.iscaptured) { cc2 = (this.enemy.team - 1) * 0x10; }
289 if(cc != this.clientcolors)
291 this.clientcolors = cc;
295 this.nextthink = time;
298 void ons_DelayedLinkSetup(entity this)
300 this.goalentity = find(NULL, targetname, this.target);
301 this.enemy = find(NULL, targetname, this.target2);
302 if(!this.goalentity) { objerror(this, "can not find target\n"); }
303 if(!this.enemy) { objerror(this, "can not find target2\n"); }
305 LOG_DEBUG(etos(this.goalentity), " linked with ", etos(this.enemy));
307 setthink(this, ons_Link_CheckUpdate);
308 this.nextthink = time;
312 // =============================
313 // Main Control Point Functions
314 // =============================
316 int ons_ControlPoint_CanBeLinked(entity cp, int teamnum)
318 if(cp.aregensneighbor & BIT(teamnum)) return 2;
319 if(cp.arecpsneighbor & BIT(teamnum)) return 1;
324 int ons_ControlPoint_Attackable(entity cp, int teamnum)
325 // -2: SAME TEAM, attackable by enemy!
330 // 3: attack it (HIGH PRIO)
331 // 4: touch it (HIGH PRIO)
339 else if(cp.goalentity)
341 // if there's already an icon built, nothing happens
342 if(cp.team == teamnum)
344 a = ons_ControlPoint_CanBeLinked(cp, teamnum);
345 if(a) // attackable by enemy?
346 return -2; // EMERGENCY!
349 // we know it can be linked, so no need to check
351 a = ons_ControlPoint_CanBeLinked(cp, teamnum);
352 if(a == 2) // near our generator?
353 return 3; // EMERGENCY!
359 if(ons_ControlPoint_CanBeLinked(cp, teamnum))
361 a = ons_ControlPoint_CanBeLinked(cp, teamnum); // why was this here NUM_TEAM_1 + NUM_TEAM_2 - t
363 return 4; // GET THIS ONE NOW!
365 return 2; // TOUCH ME
371 void ons_ControlPoint_Icon_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
373 if(damage <= 0) { return; }
375 if (this.owner.isshielded)
377 // this is protected by a shield, so ignore the damage
378 if (time > this.pain_finished)
379 if (IS_PLAYER(attacker))
381 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
382 this.pain_finished = time + 1;
383 attacker.typehitsound += 1; // play both sounds (shield is way too quiet)
389 if(IS_PLAYER(attacker))
390 if(time - ons_notification_time[this.team] > 10)
392 play2team(this.team, SND(ONS_CONTROLPOINT_UNDERATTACK));
393 ons_notification_time[this.team] = time;
396 TakeResource(this, RES_HEALTH, damage);
397 if(this.owner.iscaptured)
398 WaypointSprite_UpdateHealth(this.owner.sprite, GetResource(this, RES_HEALTH));
400 WaypointSprite_UpdateBuildFinished(this.owner.sprite, time + (this.max_health - GetResource(this, RES_HEALTH)) / (this.count / ONS_CP_THINKRATE));
401 this.pain_finished = time + 1;
402 // particles on every hit
403 pointparticles(EFFECT_SPARKS, hitloc, force*-1, 1);
406 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE+0.3, ATTEN_NORM);
408 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE+0.3, ATTEN_NORM);
410 if (GetResource(this, RES_HEALTH) < 0)
412 sound(this, CH_TRIGGER, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
413 pointparticles(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
414 if (this.owner.message != "")
415 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_CPDESTROYED), this.owner.message, attacker.netname);
417 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_CPDESTROYED_NONAME), attacker.netname);
419 GameRules_scoring_add(attacker, ONS_TAKES, 1);
420 GameRules_scoring_add(attacker, SCORE, 10);
422 this.owner.goalentity = NULL;
423 this.owner.islinked = false;
424 this.owner.iscaptured = false;
426 this.owner.colormap = 1024;
428 WaypointSprite_UpdateMaxHealth(this.owner.sprite, 0);
430 onslaught_updatelinks();
432 // Use targets now (somebody make sure this is in the right place..)
433 SUB_UseTargets(this.owner, this, NULL);
435 this.owner.waslinked = this.owner.islinked;
436 if(this.owner.model != "models/onslaught/controlpoint_pad.md3")
437 setmodel(this.owner, MDL_ONS_CP_PAD1);
438 //setsize(this, '-32 -32 0', '32 32 8');
443 this.SendFlags |= CPSF_STATUS;
446 bool ons_ControlPoint_Icon_Heal(entity targ, entity inflictor, float amount, float limit)
448 float hlth = GetResource(targ, RES_HEALTH);
449 float true_limit = ((limit != RES_LIMIT_NONE) ? limit : targ.max_health);
450 if (hlth <= 0 || hlth >= true_limit)
453 GiveResourceWithLimit(targ, RES_HEALTH, amount, true_limit);
454 hlth = GetResource(targ, RES_HEALTH);
455 if(targ.owner.iscaptured)
456 WaypointSprite_UpdateHealth(targ.owner.sprite, hlth);
458 WaypointSprite_UpdateBuildFinished(targ.owner.sprite, time + (targ.max_health - hlth) / (targ.count / ONS_CP_THINKRATE));
459 targ.SendFlags |= CPSF_STATUS;
463 void ons_ControlPoint_Icon_Think(entity this)
465 this.nextthink = time + ONS_CP_THINKRATE;
467 if(autocvar_g_onslaught_cp_proxydecap)
469 int _enemy_count = 0;
470 int _friendly_count = 0;
472 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it), {
473 if(vdist(it.origin - this.origin, <, autocvar_g_onslaught_cp_proxydecap_distance))
475 if(SAME_TEAM(it, this))
482 _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
483 _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
485 GiveResourceWithLimit(this, RES_HEALTH, (_friendly_count - _enemy_count), this.max_health);
486 this.SendFlags |= CPSF_STATUS;
487 if(GetResource(this, RES_HEALTH) <= 0)
489 ons_ControlPoint_Icon_Damage(this, this, this, 1, 0, DMG_NOWEP, this.origin, '0 0 0');
494 if (time > this.pain_finished + 5)
496 if(GetResource(this, RES_HEALTH) < this.max_health)
498 GiveResourceWithLimit(this, RES_HEALTH, this.count, this.max_health);
499 WaypointSprite_UpdateHealth(this.owner.sprite, GetResource(this, RES_HEALTH));
503 if(this.owner.islinked != this.owner.waslinked)
505 // unteam the spawnpoint if needed
506 int t = this.owner.team;
507 if(!this.owner.islinked)
510 SUB_UseTargets(this.owner, this, NULL);
514 this.owner.waslinked = this.owner.islinked;
518 if(random() < 0.6 - GetResource(this, RES_HEALTH) / this.max_health)
520 Send_Effect(EFFECT_ELECTRIC_SPARKS, this.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
523 sound(this, CH_PAIN, SND_ONS_SPARK1, VOL_BASE, ATTEN_NORM);
524 else if (random() > 0.5)
525 sound(this, CH_PAIN, SND_ONS_SPARK2, VOL_BASE, ATTEN_NORM);
529 void ons_ControlPoint_Icon_BuildThink(entity this)
533 this.nextthink = time + ONS_CP_THINKRATE;
535 // only do this if there is power
536 a = ons_ControlPoint_CanBeLinked(this.owner, this.owner.team);
540 GiveResource(this, RES_HEALTH, this.count);
542 this.SendFlags |= CPSF_STATUS;
544 if (GetResource(this, RES_HEALTH) >= this.max_health)
546 SetResourceExplicit(this, RES_HEALTH, this.max_health);
547 this.count = autocvar_g_onslaught_cp_regen * ONS_CP_THINKRATE; // slow repair rate from now on
548 setthink(this, ons_ControlPoint_Icon_Think);
549 sound(this, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILT, VOL_BASE, ATTEN_NORM);
550 this.owner.iscaptured = true;
551 this.solid = SOLID_BBOX;
553 Send_Effect(EFFECT_CAP(this.owner.team), this.owner.origin, '0 0 0', 1);
555 WaypointSprite_UpdateMaxHealth(this.owner.sprite, this.max_health);
556 WaypointSprite_UpdateHealth(this.owner.sprite, GetResource(this, RES_HEALTH));
558 if(IS_PLAYER(this.owner.ons_toucher))
560 if(this.owner.message != "")
562 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ONSLAUGHT_CAPTURE, this.owner.ons_toucher.netname, this.owner.message);
563 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);
564 Send_Notification(NOTIF_ONE, this.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE, this.owner.message);
568 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ONSLAUGHT_CAPTURE_NONAME, this.owner.ons_toucher.netname);
569 Send_Notification(NOTIF_ALL_EXCEPT, this.owner.ons_toucher, MSG_CENTER, APP_TEAM_NUM(this.owner.ons_toucher.team, CENTER_ONS_CAPTURE_TEAM_NONAME));
570 Send_Notification(NOTIF_ONE, this.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE_NONAME);
572 GameRules_scoring_add(this.owner.ons_toucher, ONS_CAPS, 1);
573 GameRules_scoring_add_team(this.owner.ons_toucher, SCORE, 10);
576 this.owner.ons_toucher = NULL;
578 onslaught_updatelinks();
580 // Use targets now (somebody make sure this is in the right place..)
581 SUB_UseTargets(this.owner, this, NULL);
583 this.SendFlags |= CPSF_SETUP;
585 if(this.owner.model != MDL_ONS_CP_PAD2.model_str())
586 setmodel(this.owner, MDL_ONS_CP_PAD2);
588 if(random() < 0.9 - GetResource(this, RES_HEALTH) / this.max_health)
589 Send_Effect(EFFECT_RAGE, this.origin + 10 * randomvec(), '0 0 -1', 1);
592 void onslaught_controlpoint_icon_link(entity e, void(entity this) spawnproc);
594 void ons_ControlPoint_Icon_Spawn(entity cp, entity player)
596 entity e = new(onslaught_controlpoint_icon);
598 setsize(e, CPICON_MIN, CPICON_MAX);
599 setorigin(e, cp.origin + CPICON_OFFSET);
602 e.max_health = autocvar_g_onslaught_cp_health;
603 SetResourceExplicit(e, RES_HEALTH, autocvar_g_onslaught_cp_buildhealth);
605 e.takedamage = DAMAGE_AIM;
607 IL_PUSH(g_bot_targets, e);
608 e.event_damage = ons_ControlPoint_Icon_Damage;
609 e.event_heal = ons_ControlPoint_Icon_Heal;
610 e.team = player.team;
611 e.colormap = 1024 + (e.team - 1) * 17;
612 e.count = (e.max_health - GetResource(e, RES_HEALTH)) * ONS_CP_THINKRATE / autocvar_g_onslaught_cp_buildtime; // how long it takes to build
614 sound(e, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILD, VOL_BASE, ATTEN_NORM);
618 cp.colormap = e.colormap;
620 Send_Effect(EFFECT_FLAG_TOUCH(player.team), e.origin, '0 0 0', 1);
622 WaypointSprite_UpdateBuildFinished(cp.sprite, time + (e.max_health - GetResource(e, RES_HEALTH)) / (e.count / ONS_CP_THINKRATE));
623 WaypointSprite_UpdateRule(cp.sprite,cp.team,SPRITERULE_TEAMPLAY);
624 cp.sprite.SendFlags |= 16;
626 onslaught_controlpoint_icon_link(e, ons_ControlPoint_Icon_BuildThink);
629 entity ons_ControlPoint_Waypoint(entity e)
633 int a = ons_ControlPoint_Attackable(e, e.team);
635 if(a == -2) { return WP_OnsCPDefend; } // defend now
636 if(a == -1 || a == 1 || a == 2) { return WP_OnsCP; } // touch
637 if(a == 3 || a == 4) { return WP_OnsCPAttack; } // attack
645 void ons_ControlPoint_UpdateSprite(entity e)
647 entity s1 = ons_ControlPoint_Waypoint(e);
648 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
651 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));
653 if(e.lastteam != e.team + 2 || e.lastshielded != sh || e.iscaptured != e.lastcaptured)
655 if(e.iscaptured) // don't mess up build bars!
659 WaypointSprite_UpdateMaxHealth(e.sprite, 0);
663 WaypointSprite_UpdateMaxHealth(e.sprite, e.goalentity.max_health);
664 WaypointSprite_UpdateHealth(e.sprite, GetResource(e.goalentity, RES_HEALTH));
670 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, false));
672 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
677 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, false));
679 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
681 WaypointSprite_Ping(e.sprite);
683 e.lastteam = e.team + 2;
685 e.lastcaptured = e.iscaptured;
689 void ons_ControlPoint_Touch(entity this, entity toucher)
693 if(IS_VEHICLE(toucher) && toucher.owner)
695 if (!autocvar_g_onslaught_allow_vehicle_touch)
697 toucher = toucher.owner;
700 if(!IS_PLAYER(toucher)) { return; }
701 if(STAT(FROZEN, toucher)) { return; }
702 if(IS_DEAD(toucher)) { return; }
704 if ( SAME_TEAM(this,toucher) )
705 if ( this.iscaptured )
707 if(time <= toucher.teleport_antispam)
708 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT_ANTISPAM, rint(toucher.teleport_antispam - time));
710 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
713 attackable = ons_ControlPoint_Attackable(this, toucher.team);
714 if(attackable != 2 && attackable != 4)
716 // we've verified that this player has a legitimate claim to this point,
717 // so start building the captured point icon (which only captures this
718 // point if it successfully builds without being destroyed first)
719 ons_ControlPoint_Icon_Spawn(this, toucher);
721 this.ons_toucher = toucher;
723 onslaught_updatelinks();
726 void ons_ControlPoint_Think(entity this)
728 this.nextthink = time + ONS_CP_THINKRATE;
729 CSQCMODEL_AUTOUPDATE(this);
732 void ons_ControlPoint_Reset(entity this)
735 delete(this.goalentity);
737 this.goalentity = NULL;
739 this.colormap = 1024;
740 this.iscaptured = false;
741 this.islinked = false;
742 this.isshielded = true;
743 setthink(this, ons_ControlPoint_Think);
744 this.ons_toucher = NULL;
745 this.nextthink = time + ONS_CP_THINKRATE;
746 setmodel(this, MDL_ONS_CP_PAD1);
748 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
749 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
751 onslaught_updatelinks();
753 SUB_UseTargets(this, this, NULL); // to reset the structures, playerspawns etc.
755 CSQCMODEL_AUTOUPDATE(this);
758 void ons_DelayedControlPoint_Setup(entity this)
760 onslaught_updatelinks();
762 // captureshield setup
763 ons_CaptureShield_Spawn(this, false);
765 CSQCMODEL_AUTOINIT(this);
768 void ons_ControlPoint_Setup(entity cp)
771 cp.ons_worldcpnext = ons_worldcplist; // link control point into ons_worldcplist
772 ons_worldcplist = cp;
774 cp.netname = "Control point";
776 cp.solid = SOLID_BBOX;
777 set_movetype(cp, MOVETYPE_NONE);
778 settouch(cp, ons_ControlPoint_Touch);
779 setthink(cp, ons_ControlPoint_Think);
780 cp.nextthink = time + ONS_CP_THINKRATE;
781 cp.reset = ons_ControlPoint_Reset;
783 cp.iscaptured = false;
785 cp.isshielded = true;
788 setmodel(cp, MDL_ONS_CP_PAD1);
790 // control point placement
791 if((cp.spawnflags & 1) || cp.noalign) // don't drop to floor, just stay at fixed location
794 set_movetype(cp, MOVETYPE_NONE);
796 else // drop to floor, automatically find a platform and set that as spawn origin
798 setorigin(cp, cp.origin + '0 0 20');
801 set_movetype(cp, MOVETYPE_TOSS);
805 WaypointSprite_SpawnFixed(WP_Null, cp.origin + CPGEN_WAYPOINT_OFFSET, cp, sprite, RADARICON_NONE);
806 WaypointSprite_UpdateRule(cp.sprite, cp.team, SPRITERULE_TEAMPLAY);
808 InitializeEntity(cp, ons_DelayedControlPoint_Setup, INITPRIO_SETLOCATION);
812 // =========================
813 // Main Generator Functions
814 // =========================
816 entity ons_Generator_Waypoint(entity e)
819 return WP_OnsGenShielded;
823 void ons_Generator_UpdateSprite(entity e)
825 entity s1 = ons_Generator_Waypoint(e);
826 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
828 if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
830 e.lastteam = e.team + 2;
831 e.lastshielded = e.isshielded;
835 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, false));
837 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
842 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, false));
844 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
846 WaypointSprite_Ping(e.sprite);
850 void ons_camSetup(entity this)
853 vector ang = '0 0 0';
854 vector best_ang = '0 0 0';
855 float best_trace_fraction = 0;
858 dir = vec2(cos(ang.y * DEG2RAD), sin(ang.y * DEG2RAD));
860 traceline(this.origin, this.origin - dir, MOVE_WORLDONLY, this);
861 if(trace_fraction > best_trace_fraction)
863 best_trace_fraction = trace_fraction;
865 if(trace_fraction == 1)
872 cam.origin = this.origin;
873 setorigin(cam, cam.origin);
874 cam.angles = best_ang;
875 Net_LinkEntity(cam, false, 0, clientcamera_send);
877 FOREACH_CLIENT(true, it.clientcamera = cam;);
879 // NOTE: engine networked
880 WriteByte(MSG_ALL, SVC_SETVIEWANGLES);
881 WriteAngle(MSG_ALL, cam.angles_x);
882 WriteAngle(MSG_ALL, cam.angles_y);
883 WriteAngle(MSG_ALL, cam.angles_z);
886 void ons_GeneratorDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
888 if(damage <= 0) return;
889 if(warmup_stage || game_stopped) return;
890 if(!round_handler_IsRoundStarted()) return;
892 if (attacker != this)
896 // generator is protected by a shield, so ignore the damage
897 if (time > this.pain_finished)
898 if (IS_PLAYER(attacker))
900 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
901 attacker.typehitsound += 1;
902 this.pain_finished = time + 1;
906 if (time > this.pain_finished)
908 this.pain_finished = time + 10;
909 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && SAME_TEAM(it, this), Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK));
910 play2team(this.team, SND(ONS_GENERATOR_UNDERATTACK));
913 TakeResource(this, RES_HEALTH, damage);
914 float hlth = GetResource(this, RES_HEALTH);
915 WaypointSprite_UpdateHealth(this.sprite, hlth);
916 // choose an animation frame based on health
917 this.frame = 10 * bound(0, (1 - hlth / this.max_health), 1);
918 // see if the generator is still functional, or dying
921 this.lasthealth = hlth;
925 if (attacker == this)
926 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME));
929 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED));
930 GameRules_scoring_add(attacker, SCORE, 100);
932 this.iscaptured = false;
933 this.islinked = false;
934 this.isshielded = false;
935 this.takedamage = DAMAGE_NO; // can't be hurt anymore
936 this.event_damage = func_null; // won't do anything if hurt
937 this.event_heal = func_null;
938 this.count = 0; // reset counter
939 setthink(this, func_null);
941 //this.think(); // do the first explosion now
943 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
944 WaypointSprite_Ping(this.sprite);
945 //WaypointSprite_Kill(this.sprite); // can't do this yet, code too poor
947 onslaught_updatelinks();
952 // Throw some flaming gibs on damage, more damage = more chance for gib
953 if(random() < damage/220)
955 sound(this, CH_TRIGGER, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
959 // particles on every hit
960 Send_Effect(EFFECT_SPARKS, hitloc, force * -1, 1);
964 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE, ATTEN_NORM);
966 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE, ATTEN_NORM);
969 this.SendFlags |= GSF_STATUS;
972 bool ons_GeneratorHeal(entity targ, entity inflictor, float amount, float limit)
974 float true_limit = ((limit != RES_LIMIT_NONE) ? limit : targ.max_health);
975 float hlth = GetResource(targ, RES_HEALTH);
976 if (hlth <= 0 || hlth >= true_limit)
979 GiveResourceWithLimit(targ, RES_HEALTH, amount, true_limit);
980 hlth = GetResource(targ, RES_HEALTH);
981 WaypointSprite_UpdateHealth(targ.sprite, hlth);
982 targ.frame = 10 * bound(0, (1 - hlth / targ.max_health), 1);
983 targ.lasthealth = hlth;
984 targ.SendFlags |= GSF_STATUS;
988 void ons_GeneratorThink(entity this)
990 this.nextthink = time + GEN_THINKRATE;
992 if (game_stopped || this.isshielded || time < this.wait)
995 this.wait = time + 5;
996 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it),
998 if (SAME_TEAM(it, this))
1000 Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM);
1002 soundto(MSG_ONE, this, CHAN_AUTO, SND(ONS_GENERATOR_ALARM), VOL_BASE, ATTEN_NONE, 0);
1005 Send_Notification(NOTIF_ONE, it, MSG_CENTER, APP_TEAM_NUM(this.team, CENTER_ONS_NOTSHIELDED));
1009 void ons_GeneratorReset(entity this)
1011 this.team = this.team_saved;
1012 SetResourceExplicit(this, RES_HEALTH, autocvar_g_onslaught_gen_health);
1013 this.lasthealth = this.max_health = autocvar_g_onslaught_gen_health;
1014 this.takedamage = DAMAGE_AIM;
1015 this.bot_attack = true;
1016 if(!IL_CONTAINS(g_bot_targets, this))
1017 IL_PUSH(g_bot_targets, this);
1018 this.iscaptured = true;
1019 this.islinked = true;
1020 this.isshielded = true;
1021 this.event_damage = ons_GeneratorDamage;
1022 this.event_heal = ons_GeneratorHeal;
1023 setthink(this, ons_GeneratorThink);
1024 this.nextthink = time + GEN_THINKRATE;
1026 Net_LinkEntity(this, false, 0, generator_send);
1028 this.SendFlags = GSF_SETUP; // just incase
1029 this.SendFlags |= GSF_STATUS;
1031 WaypointSprite_UpdateMaxHealth(this.sprite, this.max_health);
1032 WaypointSprite_UpdateHealth(this.sprite, GetResource(this, RES_HEALTH));
1033 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
1035 onslaught_updatelinks();
1038 void ons_DelayedGeneratorSetup(entity this)
1041 waypoint_spawnforitem_force(this, this.origin);
1042 this.nearestwaypointtimeout = 0; // activate waypointing again
1043 this.bot_basewaypoint = this.nearestwaypoint;
1045 // captureshield setup
1046 ons_CaptureShield_Spawn(this, true);
1048 onslaught_updatelinks();
1050 Net_LinkEntity(this, false, 0, generator_send);
1054 void onslaught_generator_touch(entity this, entity toucher)
1056 if ( IS_PLAYER(toucher) )
1057 if ( SAME_TEAM(this,toucher) )
1058 if ( this.iscaptured )
1060 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
1064 void ons_GeneratorSetup(entity gen) // called when spawning a generator entity on the map as a spawnfunc
1067 int teamnum = gen.team;
1070 gen.ons_worldgeneratornext = ons_worldgeneratorlist; // link generator into ons_worldgeneratorlist
1071 ons_worldgeneratorlist = gen;
1073 gen.netname = sprintf("%s generator", Team_ColoredFullName(teamnum));
1074 gen.classname = "onslaught_generator";
1075 gen.solid = SOLID_BBOX;
1076 gen.team_saved = teamnum;
1077 IL_PUSH(g_saved_team, gen);
1078 set_movetype(gen, MOVETYPE_NONE);
1079 gen.lasthealth = gen.max_health = autocvar_g_onslaught_gen_health;
1080 SetResourceExplicit(gen, RES_HEALTH, autocvar_g_onslaught_gen_health);
1081 gen.takedamage = DAMAGE_AIM;
1082 gen.bot_attack = true;
1083 IL_PUSH(g_bot_targets, gen);
1084 gen.event_damage = ons_GeneratorDamage;
1085 gen.event_heal = ons_GeneratorHeal;
1086 gen.reset = ons_GeneratorReset;
1087 setthink(gen, ons_GeneratorThink);
1088 gen.nextthink = time + GEN_THINKRATE;
1089 gen.iscaptured = true;
1090 gen.islinked = true;
1091 gen.isshielded = true;
1092 settouch(gen, onslaught_generator_touch);
1095 // model handled by CSQC
1096 setsize(gen, GENERATOR_MIN, GENERATOR_MAX);
1097 setorigin(gen, (gen.origin + CPGEN_SPAWN_OFFSET));
1098 gen.colormap = 1024 + (teamnum - 1) * 17;
1100 // generator placement
1104 WaypointSprite_SpawnFixed(WP_Null, gen.origin + CPGEN_WAYPOINT_OFFSET, gen, sprite, RADARICON_NONE);
1105 WaypointSprite_UpdateRule(gen.sprite, gen.team, SPRITERULE_TEAMPLAY);
1106 WaypointSprite_UpdateMaxHealth(gen.sprite, gen.max_health);
1107 WaypointSprite_UpdateHealth(gen.sprite, GetResource(gen, RES_HEALTH));
1109 InitializeEntity(gen, ons_DelayedGeneratorSetup, INITPRIO_SETLOCATION);
1117 int total_generators;
1118 void Onslaught_count_generators()
1121 total_generators = 0;
1122 for (int i = 1; i <= NUM_TEAMS; ++i)
1124 Team_SetNumberOfControlPoints(Team_GetTeamFromIndex(i), 0);
1126 for(e = ons_worldgeneratorlist; e; e = e.ons_worldgeneratornext)
1129 if (GetResource(e, RES_HEALTH) < 1)
1133 entity team_ = Entity_GetTeam(e);
1134 int num_control_points = Team_GetNumberOfControlPoints(team_);
1135 ++num_control_points;
1136 Team_SetNumberOfControlPoints(team_, num_control_points);
1140 int Onslaught_GetWinnerTeam()
1142 int winner_team = 0;
1143 if (Team_GetNumberOfControlPoints(Team_GetTeamFromIndex(1)) >= 1)
1145 winner_team = NUM_TEAM_1;
1147 for (int i = 2; i <= NUM_TEAMS; ++i)
1149 if (Team_GetNumberOfControlPoints(Team_GetTeamFromIndex(i)) >= 1)
1151 if (winner_team != 0)
1155 winner_team = Team_IndexToTeam(i);
1162 return -1; // no generators left?
1165 void nades_Clear(entity e);
1167 bool Onslaught_CheckWinner()
1169 if ((autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60) || (round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0))
1171 ons_stalemate = true;
1173 if (!wpforenemy_announced)
1175 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT);
1176 sound(NULL, CH_INFO, SND_ONS_GENERATOR_DECAY, VOL_BASE, ATTEN_NONE);
1178 wpforenemy_announced = true;
1181 entity tmp_entity; // temporary entity
1183 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext) if(time >= tmp_entity.ons_overtime_damagedelay)
1185 // tmp_entity.max_health / 300 gives 5 minutes of overtime.
1186 // control points reduce the overtime duration.
1189 for(e = ons_worldcplist; e; e = e.ons_worldcpnext)
1191 if(DIFF_TEAM(e, tmp_entity))
1196 if(autocvar_g_campaign && autocvar__campaign_testrun)
1197 d = d * tmp_entity.max_health;
1199 d = d * tmp_entity.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
1201 Damage(tmp_entity, tmp_entity, tmp_entity, d, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, tmp_entity.origin, '0 0 0');
1203 tmp_entity.sprite.SendFlags |= 16;
1205 tmp_entity.ons_overtime_damagedelay = time + 1;
1208 else { wpforenemy_announced = false; ons_stalemate = false; }
1210 Onslaught_count_generators();
1212 if (Team_GetNumberOfTeamsWithControlPoints() > 1)
1217 int winner_team = Onslaught_GetWinnerTeam();
1221 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
1222 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
1223 TeamScore_AddToTeam(winner_team, ST_ONS_CAPS, +1);
1225 else if(winner_team == -1)
1227 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_TIED);
1228 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_TIED);
1231 ons_stalemate = false;
1233 play2all(SND(CTF_CAPTURE(winner_team)));
1235 round_handler_Init(7, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
1237 FOREACH_CLIENT(IS_PLAYER(it), {
1238 STAT(ROUNDLOST, it) = true;
1239 it.player_blocked = true;
1244 game_stopped = true;
1248 bool Onslaught_CheckPlayers()
1253 void Onslaught_RoundStart()
1256 FOREACH_CLIENT(IS_PLAYER(it), it.player_blocked = false);
1258 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1259 tmp_entity.sprite.SendFlags |= 16;
1261 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1262 tmp_entity.sprite.SendFlags |= 16;
1270 // NOTE: LEGACY CODE, needs to be re-written!
1272 void havocbot_role_ons_setrole(entity this, int role)
1276 case HAVOCBOT_ONS_ROLE_DEFENSE:
1277 LOG_DEBUG(this.netname, " switched to defense");
1278 this.havocbot_role = havocbot_role_ons_defense;
1279 this.havocbot_role_timeout = 0;
1281 case HAVOCBOT_ONS_ROLE_ASSISTANT:
1282 LOG_DEBUG(this.netname, " switched to assistant");
1283 this.havocbot_role = havocbot_role_ons_assistant;
1284 this.havocbot_role_timeout = 0;
1286 case HAVOCBOT_ONS_ROLE_OFFENSE:
1287 LOG_DEBUG(this.netname, " switched to offense");
1288 this.havocbot_role = havocbot_role_ons_offense;
1289 this.havocbot_role_timeout = 0;
1294 void havocbot_goalrating_ons_controlpoints_attack(entity this, float ratingscale)
1296 entity cp, cp1, cp2, best, wp;
1297 float radius, bestvalue;
1301 // Filter control points
1302 for(cp2 = ons_worldcplist; cp2; cp2 = cp2.ons_worldcpnext)
1305 cp2.wpconsidered = false;
1310 // Ignore owned controlpoints
1311 if(!((cp2.aregensneighbor & BIT(this.team)) || (cp2.arecpsneighbor & BIT(this.team))))
1314 // Count team mates interested in this control point
1315 // (easier and cleaner than keeping counters per cp and teams)
1316 FOREACH_CLIENT(it != this && IS_PLAYER(it), {
1317 if(SAME_TEAM(it, this))
1318 if(it.havocbot_role == havocbot_role_ons_offense)
1319 if(it.havocbot_ons_target == cp2)
1323 // NOTE: probably decrease the cost of attackable control points
1325 cp2.wpconsidered = true;
1328 // We'll consider only the best case
1329 bestvalue = FLOAT_MAX;
1331 for(cp1 = ons_worldcplist; cp1; cp1 = cp1.ons_worldcpnext)
1333 if (!cp1.wpconsidered)
1336 if(cp1.wpcost<bestvalue)
1338 bestvalue = cp1.wpcost;
1340 this.havocbot_ons_target = cp1;
1347 LOG_DEBUG(this.netname, " chose cp ranked ", ftos(bestvalue));
1351 // Should be attacked
1352 // Rate waypoints near it
1355 bestvalue = FLOAT_MAX;
1356 for (radius = 500; radius <= 1000 && !found; radius += 500)
1358 IL_EACH(g_waypoints, vdist(cp.origin - it.origin, <, radius),
1360 if (!(it.wpflags & WAYPOINTFLAG_GENERATED) && checkpvs(it.origin, cp))
1363 if (it.cnt < bestvalue)
1374 navigation_routerating(this, best, ratingscale, 10000);
1377 this.havocbot_attack_time = 0;
1378 if(checkpvs(this.origin + this.view_ofs, cp))
1379 if(checkpvs(this.origin + this.view_ofs, best))
1380 this.havocbot_attack_time = time + 2;
1384 navigation_routerating(this, cp, ratingscale, 10000);
1386 LOG_DEBUG(this.netname, " found an attackable controlpoint at ", vtos(cp.origin));
1390 // Should be touched
1391 LOG_DEBUG(this.netname, " found a touchable controlpoint at ", vtos(cp.origin));
1392 navigation_routerating(this, cp, ratingscale * 2, 10000);
1396 bool havocbot_goalrating_ons_generator_attack(entity this, float ratingscale)
1398 entity g, wp, bestwp;
1402 for(g = ons_worldgeneratorlist; g; g = g.ons_worldgeneratornext)
1404 if(SAME_TEAM(g, this) || g.isshielded)
1407 // Should be attacked
1408 // Rate waypoints near it
1411 bestvalue = FLOAT_MAX;
1413 IL_EACH(g_waypoints, vdist(g.origin - it.origin, <, 400),
1415 if (checkpvs(it.origin, g))
1418 if (it.cnt < bestvalue)
1428 LOG_DEBUG("waypoints found around generator");
1429 navigation_routerating(this, bestwp, ratingscale, 10000);
1432 this.havocbot_attack_time = 0;
1433 if(checkpvs(this.origin + this.view_ofs, g))
1434 if(checkpvs(this.origin + this.view_ofs, bestwp))
1435 this.havocbot_attack_time = time + 5;
1441 LOG_DEBUG("generator found without waypoints around");
1442 // if there aren't waypoints near the generator go straight to it
1443 navigation_routerating(this, g, ratingscale, 10000);
1444 this.havocbot_attack_time = 0;
1451 void havocbot_role_ons_offense(entity this)
1455 this.havocbot_attack_time = 0;
1456 havocbot_ons_reset_role(this);
1460 // Set the role timeout if necessary
1461 if (!this.havocbot_role_timeout)
1462 this.havocbot_role_timeout = time + 120;
1464 if (time > this.havocbot_role_timeout)
1466 havocbot_ons_reset_role(this);
1470 if(this.havocbot_attack_time>time)
1473 if (navigation_goalrating_timeout(this))
1475 navigation_goalrating_start(this);
1476 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
1477 if(!havocbot_goalrating_ons_generator_attack(this, 10000))
1478 havocbot_goalrating_ons_controlpoints_attack(this, 10000);
1479 havocbot_goalrating_items(this, 25000, this.origin, 10000);
1480 navigation_goalrating_end(this);
1482 navigation_goalrating_timeout_set(this);
1486 void havocbot_role_ons_assistant(entity this)
1488 havocbot_ons_reset_role(this);
1491 void havocbot_role_ons_defense(entity this)
1493 havocbot_ons_reset_role(this);
1496 void havocbot_ons_reset_role(entity this)
1501 this.havocbot_ons_target = NULL;
1503 // TODO: Defend control points or generator if necessary
1505 havocbot_role_ons_setrole(this, HAVOCBOT_ONS_ROLE_OFFENSE);
1510 * Find control point or generator owned by the same team self which is nearest to pos
1511 * if max_dist is positive, only control points within this range will be considered
1513 entity ons_Nearest_ControlPoint(entity this, vector pos, float max_dist)
1515 entity closest_target = NULL;
1516 for(entity cp = ons_worldcplist; cp; cp = cp.ons_worldcpnext)
1518 if(SAME_TEAM(cp, this))
1520 if(max_dist <= 0 || vdist(cp.origin - pos, <=, max_dist))
1521 if(vlen2(cp.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
1522 closest_target = cp;
1524 for(entity gen = ons_worldgeneratorlist; gen; gen = gen.ons_worldgeneratornext)
1526 if(SAME_TEAM(gen, this))
1527 if(max_dist <= 0 || vdist(gen.origin - pos, <, max_dist))
1528 if(vlen2(gen.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
1529 closest_target = gen;
1532 return closest_target;
1536 * Find control point or generator owned by the same team self which is nearest to pos
1537 * if max_dist is positive, only control points within this range will be considered
1538 * This function only check distances on the XY plane, disregarding Z
1540 entity ons_Nearest_ControlPoint_2D(entity this, vector pos, float max_dist)
1542 entity closest_target = NULL;
1544 float smallest_distance = 0, distance;
1546 for(entity cp = ons_worldcplist; cp; cp = cp.ons_worldcpnext)
1548 delta = cp.origin - pos;
1550 distance = vlen(delta);
1552 if(SAME_TEAM(cp, this))
1554 if(max_dist <= 0 || distance <= max_dist)
1555 if(closest_target == NULL || distance <= smallest_distance )
1557 closest_target = cp;
1558 smallest_distance = distance;
1561 for(entity gen = ons_worldgeneratorlist; gen; gen = gen.ons_worldgeneratornext)
1563 delta = gen.origin - pos;
1565 distance = vlen(delta);
1567 if(SAME_TEAM(gen, this))
1568 if(max_dist <= 0 || distance <= max_dist)
1569 if(closest_target == NULL || distance <= smallest_distance )
1571 closest_target = gen;
1572 smallest_distance = distance;
1576 return closest_target;
1579 * find the number of control points and generators in the same team as this
1581 int ons_Count_SelfControlPoints(entity this)
1584 for(entity cp = ons_worldcplist; cp; cp = cp.ons_worldcpnext)
1586 if(SAME_TEAM(cp, this))
1590 for(entity gen = ons_worldgeneratorlist; gen; gen = gen.ons_worldgeneratornext)
1592 if(SAME_TEAM(gen, this))
1599 * Teleport player to a random position near tele_target
1600 * if tele_effects is true, teleport sound+particles are created
1601 * return false on failure
1603 bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effects)
1611 // narrow the range for each iteration to increase chances that a spawnpoint
1612 // can be found even if there's little room around the control point
1613 float iteration_scale = 1;
1614 for(i = 0; i < 16; ++i)
1616 iteration_scale -= i / 16;
1617 theta = random() * 2 * M_PI;
1621 loc *= random() * range * iteration_scale;
1623 loc += tele_target.origin + '0 0 128' * iteration_scale;
1625 tracebox(loc, STAT(PL_MIN, player), STAT(PL_MAX, player), loc, MOVE_NORMAL, player);
1626 if(trace_fraction == 1.0 && !trace_startsolid)
1628 traceline(tele_target.origin, loc, MOVE_NOMONSTERS, tele_target); // double check to make sure we're not spawning outside the NULL
1629 if(trace_fraction == 1.0 && !trace_startsolid)
1633 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
1634 sound (player, CH_TRIGGER, SND_TELEPORT, VOL_BASE, ATTEN_NORM);
1636 setorigin(player, loc);
1637 player.angles = '0 1 0' * ( theta * RAD2DEG + 180 );
1638 makevectors(player.angles);
1639 player.fixangle = true;
1640 if (IS_BOT_CLIENT(player))
1642 player.v_angle = player.angles;
1643 bot_aim_reset(player);
1645 player.teleport_antispam = time + autocvar_g_onslaught_teleport_wait;
1648 Send_Effect(EFFECT_TELEPORT, player.origin + v_forward * 32, '0 0 0', 1);
1661 MUTATOR_HOOKFUNCTION(ons, reset_map_global)
1663 FOREACH_CLIENT(IS_PLAYER(it), {
1664 STAT(ROUNDLOST, it) = false;
1665 it.ons_deathloc = '0 0 0';
1666 PutClientInServer(it);
1667 it.clientcamera = it;
1672 MUTATOR_HOOKFUNCTION(ons, ClientDisconnect)
1674 entity player = M_ARGV(0, entity);
1676 player.ons_deathloc = '0 0 0';
1679 MUTATOR_HOOKFUNCTION(ons, MakePlayerObserver)
1681 entity player = M_ARGV(0, entity);
1683 player.ons_deathloc = '0 0 0';
1686 MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
1688 entity player = M_ARGV(0, entity);
1690 if(!round_handler_IsRoundStarted())
1692 player.player_blocked = true;
1697 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1699 l.sprite.SendFlags |= 16;
1701 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1703 l.sprite.SendFlags |= 16;
1706 if(ons_stalemate) { Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); }
1708 if ( autocvar_g_onslaught_spawn_choose )
1709 if ( player.ons_spawn_by )
1710 if ( ons_Teleport(player,player.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) )
1712 player.ons_spawn_by = NULL;
1716 if(autocvar_g_onslaught_spawn_at_controlpoints)
1717 if(random() <= autocvar_g_onslaught_spawn_at_controlpoints_chance)
1719 float random_target = autocvar_g_onslaught_spawn_at_controlpoints_random;
1720 entity tmp_entity, closest_target = NULL;
1721 vector spawn_loc = player.ons_deathloc;
1723 // new joining player or round reset, don't bother checking
1724 if(spawn_loc == '0 0 0') { return false; }
1726 if(random_target) { RandomSelection_Init(); }
1728 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1730 if(SAME_TEAM(tmp_entity, player))
1733 RandomSelection_AddEnt(tmp_entity, 1, 1);
1734 else if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL)
1735 closest_target = tmp_entity;
1739 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1745 float iteration_scale = 1;
1746 for(i = 0; i < 10; ++i)
1748 iteration_scale -= i / 10;
1749 loc = closest_target.origin + '0 0 96' * iteration_scale;
1750 loc += ('0 1 0' * random()) * 128 * iteration_scale;
1751 tracebox(loc, STAT(PL_MIN, player), STAT(PL_MAX, player), loc, MOVE_NORMAL, player);
1752 if(trace_fraction == 1.0 && !trace_startsolid)
1754 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL
1755 if(trace_fraction == 1.0 && !trace_startsolid)
1757 setorigin(player, loc);
1758 player.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1766 if(autocvar_g_onslaught_spawn_at_generator)
1767 if(random() <= autocvar_g_onslaught_spawn_at_generator_chance)
1769 float random_target = autocvar_g_onslaught_spawn_at_generator_random;
1770 entity tmp_entity, closest_target = NULL;
1771 vector spawn_loc = player.ons_deathloc;
1773 // new joining player or round reset, don't bother checking
1774 if(spawn_loc == '0 0 0') { return false; }
1776 if(random_target) { RandomSelection_Init(); }
1778 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1781 RandomSelection_AddEnt(tmp_entity, 1, 1);
1784 if(SAME_TEAM(tmp_entity, player))
1785 if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL)
1786 closest_target = tmp_entity;
1790 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1796 float iteration_scale = 1;
1797 for(i = 0; i < 10; ++i)
1799 iteration_scale -= i / 10;
1800 loc = closest_target.origin + '0 0 128' * iteration_scale;
1801 loc += ('0 1 0' * random()) * 256 * iteration_scale;
1802 tracebox(loc, STAT(PL_MIN, player), STAT(PL_MAX, player), loc, MOVE_NORMAL, player);
1803 if(trace_fraction == 1.0 && !trace_startsolid)
1805 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL
1806 if(trace_fraction == 1.0 && !trace_startsolid)
1808 setorigin(player, loc);
1809 player.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1820 MUTATOR_HOOKFUNCTION(ons, PlayerDies)
1822 entity frag_target = M_ARGV(2, entity);
1824 frag_target.ons_deathloc = frag_target.origin;
1826 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1828 l.sprite.SendFlags |= 16;
1830 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1832 l.sprite.SendFlags |= 16;
1835 if ( autocvar_g_onslaught_spawn_choose )
1836 if ( ons_Count_SelfControlPoints(frag_target) > 1 )
1837 stuffcmd(frag_target, "qc_cmd_cl hud clickradar\n");
1842 MUTATOR_HOOKFUNCTION(ons, MonsterMove)
1844 entity mon = M_ARGV(0, entity);
1846 entity e = find(NULL, targetname, mon.target);
1851 void ons_MonsterSpawn_Delayed(entity this)
1853 entity own = this.owner;
1855 if(!own) { delete(this); return; }
1859 entity e = find(NULL, target, own.targetname);
1864 own.use(own, e, NULL);
1871 MUTATOR_HOOKFUNCTION(ons, MonsterSpawn)
1873 entity mon = M_ARGV(0, entity);
1877 InitializeEntity(e, ons_MonsterSpawn_Delayed, INITPRIO_FINDTARGET);
1880 void ons_TurretSpawn_Delayed(entity this)
1882 entity own = this.owner;
1884 if(!own) { delete(this); return; }
1888 entity e = find(NULL, target, own.targetname);
1892 own.active = ACTIVE_NOT;
1894 own.use(own, e, NULL);
1901 MUTATOR_HOOKFUNCTION(ons, TurretSpawn)
1903 entity turret = M_ARGV(0, entity);
1907 InitializeEntity(e, ons_TurretSpawn_Delayed, INITPRIO_FINDTARGET);
1912 MUTATOR_HOOKFUNCTION(ons, HavocBot_ChooseRole)
1914 entity bot = M_ARGV(0, entity);
1916 havocbot_ons_reset_role(bot);
1920 MUTATOR_HOOKFUNCTION(ons, TeamBalance_CheckAllowedTeams)
1922 // onslaught is special
1923 for(entity tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1925 if (Team_IsValidTeam(tmp_entity.team))
1927 M_ARGV(0, float) |= Team_TeamToBit(tmp_entity.team);
1934 MUTATOR_HOOKFUNCTION(ons, SpectateCopy)
1936 entity spectatee = M_ARGV(0, entity);
1937 entity client = M_ARGV(1, entity);
1939 STAT(ROUNDLOST, client) = STAT(ROUNDLOST, spectatee); // make spectators see it too
1942 MUTATOR_HOOKFUNCTION(ons, SV_ParseClientCommand)
1944 if(MUTATOR_RETURNVALUE) // command was already handled?
1947 entity player = M_ARGV(0, entity);
1948 string cmd_name = M_ARGV(1, string);
1949 int cmd_argc = M_ARGV(2, int);
1951 if ( cmd_name == "ons_spawn" )
1953 vector pos = player.origin;
1955 pos_x = stof(argv(1));
1957 pos_y = stof(argv(2));
1959 pos_z = stof(argv(3));
1961 if ( IS_PLAYER(player) )
1963 if ( !STAT(FROZEN, player) )
1965 entity source_point = ons_Nearest_ControlPoint(player, player.origin, autocvar_g_onslaught_teleport_radius);
1967 if ( !source_point && GetResource(player, RES_HEALTH) > 0 )
1969 sprint(player, "\nYou need to be next to a control point\n");
1974 entity closest_target = ons_Nearest_ControlPoint_2D(player, pos, autocvar_g_onslaught_click_radius);
1976 if ( closest_target == NULL )
1978 sprint(player, "\nNo control point found\n");
1982 if ( GetResource(player, RES_HEALTH) <= 0 )
1984 player.ons_spawn_by = closest_target;
1985 player.respawn_flags = player.respawn_flags | RESPAWN_FORCE;
1989 if ( source_point == closest_target )
1991 sprint(player, "\nTeleporting to the same point\n");
1995 if ( !ons_Teleport(player,closest_target,autocvar_g_onslaught_teleport_radius,true) )
1996 sprint(player, "\nUnable to teleport there\n");
2002 sprint(player, "\nNo teleportation for you\n");
2010 MUTATOR_HOOKFUNCTION(ons, PlayerUseKey)
2012 if(MUTATOR_RETURNVALUE || game_stopped) return false;
2014 entity player = M_ARGV(0, entity);
2016 if((time > player.teleport_antispam) && (!IS_DEAD(player)) && !player.vehicle)
2018 entity source_point = ons_Nearest_ControlPoint(player, player.origin, autocvar_g_onslaught_teleport_radius);
2021 stuffcmd(player, "qc_cmd_cl hud clickradar\n");
2027 MUTATOR_HOOKFUNCTION(ons, PlayHitsound)
2029 entity frag_victim = M_ARGV(0, entity);
2031 return (frag_victim.classname == "onslaught_generator" && !frag_victim.isshielded)
2032 || (frag_victim.classname == "onslaught_controlpoint_icon" && !frag_victim.owner.isshielded);
2035 MUTATOR_HOOKFUNCTION(ons, SendWaypoint)
2037 entity wp = M_ARGV(0, entity);
2038 entity to = M_ARGV(1, entity);
2039 int sf = M_ARGV(2, int);
2040 int wp_flag = M_ARGV(3, int);
2044 if(wp.owner.classname == "onslaught_controlpoint")
2046 entity wp_owner = wp.owner;
2047 entity e = WaypointSprite_getviewentity(to);
2048 if(SAME_TEAM(e, wp_owner) && GetResource(wp_owner.goalentity, RES_HEALTH) >= wp_owner.goalentity.max_health) { wp_flag |= 2; }
2049 if(!ons_ControlPoint_Attackable(wp_owner, e.team)) { wp_flag |= 2; }
2051 if(wp.owner.classname == "onslaught_generator")
2053 entity wp_owner = wp.owner;
2054 if(wp_owner.isshielded && GetResource(wp_owner, RES_HEALTH) >= wp_owner.max_health) { wp_flag |= 2; }
2055 if(GetResource(wp_owner, RES_HEALTH) <= 0) { wp_flag |= 2; }
2059 M_ARGV(3, int) = wp_flag;
2062 MUTATOR_HOOKFUNCTION(ons, TurretValidateTarget)
2064 entity turret_target = M_ARGV(1, entity);
2066 if(substring(turret_target.classname, 0, 10) == "onslaught_") // don't attack onslaught targets, that's the player's job!
2068 M_ARGV(3, float) = -3;
2075 MUTATOR_HOOKFUNCTION(ons, TurretThink)
2077 entity turret = M_ARGV(0, entity);
2079 // ONS uses somewhat backwards linking.
2082 entity e = find(NULL, targetname, turret.target);
2084 turret.team = e.team;
2087 if(turret.team != turret.tur_head.team)
2088 turret_respawn(turret);
2096 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
2097 Link between control points.
2099 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.
2102 "target" - first control point.
2103 "target2" - second control point.
2105 spawnfunc(onslaught_link)
2107 if(!g_onslaught) { delete(this); return; }
2109 if (this.target == "" || this.target2 == "")
2110 objerror(this, "target and target2 must be set\n");
2112 this.ons_worldlinknext = ons_worldlinklist; // link into ons_worldlinklist
2113 ons_worldlinklist = this;
2115 InitializeEntity(this, ons_DelayedLinkSetup, INITPRIO_FINDTARGET);
2116 Net_LinkEntity(this, false, 0, ons_Link_Send);
2119 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
2120 Control point. Be sure to give this enough clearance so that the shootable part has room to exist
2122 This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
2125 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2126 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
2127 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
2130 spawnfunc(onslaught_controlpoint)
2132 if(!g_onslaught) { delete(this); return; }
2134 ons_ControlPoint_Setup(this);
2137 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
2140 spawnfunc_onslaught_link entities can target this.
2143 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
2144 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2146 spawnfunc(onslaught_generator)
2148 if(!g_onslaught) { delete(this); return; }
2149 if(!this.team) { objerror(this, "team must be set"); }
2151 ons_GeneratorSetup(this);
2155 void ons_ScoreRules()
2157 entity balance = TeamBalance_CheckAllowedTeams(NULL);
2158 int teams = TeamBalance_GetAllowedTeams(balance);
2159 TeamBalance_Destroy(balance);
2160 GameRules_scoring(teams, SFL_SORT_PRIO_PRIMARY, 0, {
2161 field_team(ST_ONS_CAPS, "destroyed", SFL_SORT_PRIO_PRIMARY);
2162 field(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
2163 field(SP_ONS_TAKES, "takes", 0);
2167 void ons_DelayedInit(entity this) // Do this check with a delay so we can wait for teams to be set up
2171 round_handler_Spawn(Onslaught_CheckPlayers, Onslaught_CheckWinner, Onslaught_RoundStart);
2172 round_handler_Init(5, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
2175 void ons_Initialize()
2178 ons_captureshield_force = autocvar_g_onslaught_shield_force;
2180 cam = new(objective_camera);
2182 InitializeEntity(NULL, ons_DelayedInit, INITPRIO_GAMETYPE);