1 #include "sv_onslaught.qh"
2 #include "sv_controlpoint.qh"
3 #include "sv_generator.qh"
7 float autocvar_g_onslaught_teleport_wait;
8 bool autocvar_g_onslaught_spawn_at_controlpoints;
9 bool autocvar_g_onslaught_spawn_at_generator;
10 float autocvar_g_onslaught_cp_proxydecap;
11 float autocvar_g_onslaught_cp_proxydecap_distance = 512;
12 float autocvar_g_onslaught_cp_proxydecap_dps = 100;
13 float autocvar_g_onslaught_spawn_at_controlpoints_chance = 0.5;
14 float autocvar_g_onslaught_spawn_at_controlpoints_random;
15 float autocvar_g_onslaught_spawn_at_generator_chance;
16 float autocvar_g_onslaught_spawn_at_generator_random;
17 float autocvar_g_onslaught_cp_buildhealth;
18 float autocvar_g_onslaught_cp_buildtime;
19 float autocvar_g_onslaught_cp_health;
20 float autocvar_g_onslaught_cp_regen;
21 float autocvar_g_onslaught_gen_health;
22 float autocvar_g_onslaught_shield_force = 100;
23 float autocvar_g_onslaught_allow_vehicle_touch;
24 float autocvar_g_onslaught_round_timelimit;
25 float autocvar_g_onslaught_warmup;
26 float autocvar_g_onslaught_teleport_radius;
27 float autocvar_g_onslaught_spawn_choose;
28 float autocvar_g_onslaught_click_radius;
30 void FixSize(entity e);
32 // =======================
33 // CaptureShield Functions
34 // =======================
36 bool ons_CaptureShield_Customize(entity this, entity client)
38 entity e = WaypointSprite_getviewentity(client);
40 if(!this.enemy.isshielded && (ons_ControlPoint_Attackable(this.enemy, e.team) > 0 || this.enemy.classname != "onslaught_controlpoint")) { return false; }
41 if(SAME_TEAM(this, e)) { return false; }
46 void ons_CaptureShield_Touch(entity this, entity toucher)
48 if(!this.enemy.isshielded && (ons_ControlPoint_Attackable(this.enemy, toucher.team) > 0 || this.enemy.classname != "onslaught_controlpoint")) { return; }
49 if(!IS_PLAYER(toucher)) { return; }
50 if(SAME_TEAM(toucher, this)) { return; }
52 vector mymid = (this.absmin + this.absmax) * 0.5;
53 vector theirmid = (toucher.absmin + toucher.absmax) * 0.5;
55 Damage(toucher, this, this, 0, DEATH_HURTTRIGGER.m_id, mymid, normalize(theirmid - mymid) * ons_captureshield_force);
57 if(IS_REAL_CLIENT(toucher))
59 play2(toucher, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
61 if(this.enemy.classname == "onslaught_generator")
62 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_GENERATOR_SHIELDED);
64 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_CONTROLPOINT_SHIELDED);
68 void ons_CaptureShield_Reset(entity this)
70 this.colormap = this.enemy.colormap;
71 this.team = this.enemy.team;
74 void ons_CaptureShield_Spawn(entity generator, bool is_generator)
76 entity shield = new(ons_captureshield);
77 IL_PUSH(g_onsshields, shield);
79 shield.enemy = generator;
80 shield.team = generator.team;
81 shield.colormap = generator.colormap;
82 shield.reset = ons_CaptureShield_Reset;
83 settouch(shield, ons_CaptureShield_Touch);
84 setcefc(shield, ons_CaptureShield_Customize);
85 shield.effects = EF_ADDITIVE;
86 set_movetype(shield, MOVETYPE_NOCLIP);
87 shield.solid = SOLID_TRIGGER;
88 shield.avelocity = '7 0 11';
90 shield.model = ((is_generator) ? "models/onslaught/generator_shield.md3" : "models/onslaught/controlpoint_shield.md3");
92 precache_model(shield.model);
93 setorigin(shield, generator.origin);
94 _setmodel(shield, shield.model);
95 setsize(shield, shield.scale * shield.mins, shield.scale * shield.maxs);
103 void setmodel_fixsize(entity e, Model m)
109 void onslaught_updatelinks()
112 // first check if the game has ended
113 LOG_DEBUG("--- updatelinks ---");
114 // mark generators as being shielded and networked
115 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
118 LOG_DEBUG(etos(l), " (generator) belongs to team ", ftos(l.team));
120 LOG_DEBUG(etos(l), " (generator) is destroyed");
121 l.islinked = l.iscaptured;
122 l.isshielded = l.iscaptured;
123 l.sprite.SendFlags |= 16;
125 // mark points as shielded and not networked
126 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
131 for(i = 0; i < 17; ++i) { l.isgenneighbor[i] = false; l.iscpneighbor[i] = false; }
132 LOG_DEBUG(etos(l), " (point) belongs to team ", ftos(l.team));
133 l.sprite.SendFlags |= 16;
135 // flow power outward from the generators through the network
140 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
142 // if both points are captured by the same team, and only one of
143 // them is powered, mark the other one as powered as well
144 if (l.enemy.iscaptured && l.goalentity.iscaptured)
145 if (l.enemy.islinked != l.goalentity.islinked)
146 if(SAME_TEAM(l.enemy, l.goalentity))
148 if (!l.goalentity.islinked)
151 l.goalentity.islinked = true;
152 LOG_DEBUG(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)");
154 else if (!l.enemy.islinked)
157 l.enemy.islinked = true;
158 LOG_DEBUG(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)");
163 // now that we know which points are powered we can mark their neighbors
164 // as unshielded if team differs
165 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
167 if (l.goalentity.islinked)
169 if(DIFF_TEAM(l.goalentity, l.enemy))
171 LOG_DEBUG(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)");
172 l.enemy.isshielded = false;
174 if(l.goalentity.classname == "onslaught_generator")
175 l.enemy.isgenneighbor[l.goalentity.team] = true;
177 l.enemy.iscpneighbor[l.goalentity.team] = true;
179 if (l.enemy.islinked)
181 if(DIFF_TEAM(l.goalentity, l.enemy))
183 LOG_DEBUG(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)");
184 l.goalentity.isshielded = false;
186 if(l.enemy.classname == "onslaught_generator")
187 l.goalentity.isgenneighbor[l.enemy.team] = true;
189 l.goalentity.iscpneighbor[l.enemy.team] = true;
192 // now update the generators
193 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
197 LOG_DEBUG(etos(l), " (generator) is shielded");
198 l.takedamage = DAMAGE_NO;
200 IL_REMOVE(g_bot_targets, l);
201 l.bot_attack = false;
205 LOG_DEBUG(etos(l), " (generator) is not shielded");
206 l.takedamage = DAMAGE_AIM;
208 IL_PUSH(g_bot_targets, l);
212 ons_Generator_UpdateSprite(l);
214 // now update the takedamage and alpha variables on control point icons
215 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
219 LOG_DEBUG(etos(l), " (point) is shielded");
222 l.goalentity.takedamage = DAMAGE_NO;
223 if(l.goalentity.bot_attack)
224 IL_REMOVE(g_bot_targets, l.goalentity);
225 l.goalentity.bot_attack = false;
230 LOG_DEBUG(etos(l), " (point) is not shielded");
233 l.goalentity.takedamage = DAMAGE_AIM;
234 if(!l.goalentity.bot_attack)
235 IL_PUSH(g_bot_targets, l.goalentity);
236 l.goalentity.bot_attack = true;
239 ons_ControlPoint_UpdateSprite(l);
241 IL_EACH(g_onsshields, true,
243 it.team = it.enemy.team;
244 it.colormap = it.enemy.colormap;
249 // ===================
250 // Main Link Functions
251 // ===================
253 bool ons_Link_Send(entity this, entity to, int sendflags)
255 WriteHeader(MSG_ENTITY, ENT_CLIENT_RADARLINK);
256 WriteByte(MSG_ENTITY, sendflags);
259 WriteCoord(MSG_ENTITY, this.goalentity.origin_x);
260 WriteCoord(MSG_ENTITY, this.goalentity.origin_y);
261 WriteCoord(MSG_ENTITY, this.goalentity.origin_z);
265 WriteCoord(MSG_ENTITY, this.enemy.origin_x);
266 WriteCoord(MSG_ENTITY, this.enemy.origin_y);
267 WriteCoord(MSG_ENTITY, this.enemy.origin_z);
271 WriteByte(MSG_ENTITY, this.clientcolors); // which is goalentity's color + enemy's color * 16
276 void ons_Link_CheckUpdate(entity this)
278 // TODO check if the two sides have moved (currently they won't move anyway)
279 float cc = 0, cc1 = 0, cc2 = 0;
281 if(this.goalentity.islinked || this.goalentity.iscaptured) { cc1 = (this.goalentity.team - 1) * 0x01; }
282 if(this.enemy.islinked || this.enemy.iscaptured) { cc2 = (this.enemy.team - 1) * 0x10; }
286 if(cc != this.clientcolors)
288 this.clientcolors = cc;
292 this.nextthink = time;
295 void ons_DelayedLinkSetup(entity this)
297 this.goalentity = find(NULL, targetname, this.target);
298 this.enemy = find(NULL, targetname, this.target2);
299 if(!this.goalentity) { objerror(this, "can not find target\n"); }
300 if(!this.enemy) { objerror(this, "can not find target2\n"); }
302 LOG_DEBUG(etos(this.goalentity), " linked with ", etos(this.enemy));
304 setthink(this, ons_Link_CheckUpdate);
305 this.nextthink = time;
309 // =============================
310 // Main Control Point Functions
311 // =============================
313 int ons_ControlPoint_CanBeLinked(entity cp, int teamnumber)
315 if(cp.isgenneighbor[teamnumber]) { return 2; }
316 if(cp.iscpneighbor[teamnumber]) { return 1; }
321 int ons_ControlPoint_Attackable(entity cp, int teamnumber)
322 // -2: SAME TEAM, attackable by enemy!
327 // 3: attack it (HIGH PRIO)
328 // 4: touch it (HIGH PRIO)
336 else if(cp.goalentity)
338 // if there's already an icon built, nothing happens
339 if(cp.team == teamnumber)
341 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
342 if(a) // attackable by enemy?
343 return -2; // EMERGENCY!
346 // we know it can be linked, so no need to check
348 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
349 if(a == 2) // near our generator?
350 return 3; // EMERGENCY!
356 if(ons_ControlPoint_CanBeLinked(cp, teamnumber))
358 a = ons_ControlPoint_CanBeLinked(cp, teamnumber); // why was this here NUM_TEAM_1 + NUM_TEAM_2 - t
360 return 4; // GET THIS ONE NOW!
362 return 2; // TOUCH ME
368 void ons_ControlPoint_Icon_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
370 if(damage <= 0) { return; }
372 if (this.owner.isshielded)
374 // this is protected by a shield, so ignore the damage
375 if (time > this.pain_finished)
376 if (IS_PLAYER(attacker))
378 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
379 this.pain_finished = time + 1;
380 attacker.typehitsound += 1; // play both sounds (shield is way too quiet)
386 if(IS_PLAYER(attacker))
387 if(time - ons_notification_time[this.team] > 10)
389 play2team(this.team, SND(ONS_CONTROLPOINT_UNDERATTACK));
390 ons_notification_time[this.team] = time;
393 this.health = this.health - damage;
394 if(this.owner.iscaptured)
395 WaypointSprite_UpdateHealth(this.owner.sprite, this.health);
397 WaypointSprite_UpdateBuildFinished(this.owner.sprite, time + (this.max_health - this.health) / (this.count / ONS_CP_THINKRATE));
398 this.pain_finished = time + 1;
399 // particles on every hit
400 pointparticles(EFFECT_SPARKS, hitloc, force*-1, 1);
403 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE+0.3, ATTEN_NORM);
405 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE+0.3, ATTEN_NORM);
409 sound(this, CH_TRIGGER, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
410 pointparticles(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
411 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_CPDESTROYED), this.owner.message, attacker.netname);
413 PlayerScore_Add(attacker, SP_ONS_TAKES, 1);
414 PlayerScore_Add(attacker, SP_SCORE, 10);
416 this.owner.goalentity = NULL;
417 this.owner.islinked = false;
418 this.owner.iscaptured = false;
420 this.owner.colormap = 1024;
422 WaypointSprite_UpdateMaxHealth(this.owner.sprite, 0);
424 onslaught_updatelinks();
426 // Use targets now (somebody make sure this is in the right place..)
427 SUB_UseTargets(this.owner, this, NULL);
429 this.owner.waslinked = this.owner.islinked;
430 if(this.owner.model != "models/onslaught/controlpoint_pad.md3")
431 setmodel_fixsize(this.owner, MDL_ONS_CP_PAD1);
432 //setsize(this, '-32 -32 0', '32 32 8');
437 this.SendFlags |= CPSF_STATUS;
440 void ons_ControlPoint_Icon_Think(entity this)
442 this.nextthink = time + ONS_CP_THINKRATE;
444 if(autocvar_g_onslaught_cp_proxydecap)
446 int _enemy_count = 0;
447 int _friendly_count = 0;
449 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it), {
450 if(vdist(it.origin - this.origin, <, autocvar_g_onslaught_cp_proxydecap_distance))
452 if(SAME_TEAM(it, this))
459 _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
460 _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
462 this.health = bound(0, this.health + (_friendly_count - _enemy_count), this.max_health);
463 this.SendFlags |= CPSF_STATUS;
466 ons_ControlPoint_Icon_Damage(this, this, this, 1, 0, this.origin, '0 0 0');
471 if (time > this.pain_finished + 5)
473 if(this.health < this.max_health)
475 this.health = this.health + this.count;
476 if (this.health >= this.max_health)
477 this.health = this.max_health;
478 WaypointSprite_UpdateHealth(this.owner.sprite, this.health);
482 if(this.owner.islinked != this.owner.waslinked)
484 // unteam the spawnpoint if needed
485 int t = this.owner.team;
486 if(!this.owner.islinked)
489 SUB_UseTargets(this.owner, this, NULL);
493 this.owner.waslinked = this.owner.islinked;
497 if(random() < 0.6 - this.health / this.max_health)
499 Send_Effect(EFFECT_ELECTRIC_SPARKS, this.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
502 sound(this, CH_PAIN, SND_ONS_SPARK1, VOL_BASE, ATTEN_NORM);
503 else if (random() > 0.5)
504 sound(this, CH_PAIN, SND_ONS_SPARK2, VOL_BASE, ATTEN_NORM);
508 void ons_ControlPoint_Icon_BuildThink(entity this)
512 this.nextthink = time + ONS_CP_THINKRATE;
514 // only do this if there is power
515 a = ons_ControlPoint_CanBeLinked(this.owner, this.owner.team);
519 this.health = this.health + this.count;
521 this.SendFlags |= CPSF_STATUS;
523 if (this.health >= this.max_health)
525 this.health = this.max_health;
526 this.count = autocvar_g_onslaught_cp_regen * ONS_CP_THINKRATE; // slow repair rate from now on
527 setthink(this, ons_ControlPoint_Icon_Think);
528 sound(this, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILT, VOL_BASE, ATTEN_NORM);
529 this.owner.iscaptured = true;
530 this.solid = SOLID_BBOX;
532 Send_Effect(EFFECT_CAP(this.owner.team), this.owner.origin, '0 0 0', 1);
534 WaypointSprite_UpdateMaxHealth(this.owner.sprite, this.max_health);
535 WaypointSprite_UpdateHealth(this.owner.sprite, this.health);
537 if(IS_PLAYER(this.owner.ons_toucher))
539 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ONSLAUGHT_CAPTURE, this.owner.ons_toucher.netname, this.owner.message);
540 Send_Notification(NOTIF_ALL_EXCEPT, this.owner.ons_toucher, MSG_CENTER, APP_TEAM_NUM(this.owner.ons_toucher.team, CENTER_ONS_CAPTURE), this.owner.message);
541 Send_Notification(NOTIF_ONE, this.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE, this.owner.message);
542 PlayerScore_Add(this.owner.ons_toucher, SP_ONS_CAPS, 1);
543 PlayerTeamScore_AddScore(this.owner.ons_toucher, 10);
546 this.owner.ons_toucher = NULL;
548 onslaught_updatelinks();
550 // Use targets now (somebody make sure this is in the right place..)
551 SUB_UseTargets(this.owner, this, NULL);
553 this.SendFlags |= CPSF_SETUP;
555 if(this.owner.model != MDL_ONS_CP_PAD2.model_str())
556 setmodel_fixsize(this.owner, MDL_ONS_CP_PAD2);
558 if(random() < 0.9 - this.health / this.max_health)
559 Send_Effect(EFFECT_RAGE, this.origin + 10 * randomvec(), '0 0 -1', 1);
562 void onslaught_controlpoint_icon_link(entity e, void(entity this) spawnproc);
564 void ons_ControlPoint_Icon_Spawn(entity cp, entity player)
566 entity e = new(onslaught_controlpoint_icon);
568 setsize(e, CPICON_MIN, CPICON_MAX);
569 setorigin(e, cp.origin + CPICON_OFFSET);
572 e.max_health = autocvar_g_onslaught_cp_health;
573 e.health = autocvar_g_onslaught_cp_buildhealth;
575 e.takedamage = DAMAGE_AIM;
577 IL_PUSH(g_bot_targets, e);
578 e.event_damage = ons_ControlPoint_Icon_Damage;
579 e.team = player.team;
580 e.colormap = 1024 + (e.team - 1) * 17;
581 e.count = (e.max_health - e.health) * ONS_CP_THINKRATE / autocvar_g_onslaught_cp_buildtime; // how long it takes to build
583 sound(e, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILD, VOL_BASE, ATTEN_NORM);
587 cp.colormap = e.colormap;
589 Send_Effect(EFFECT_FLAG_TOUCH(player.team), e.origin, '0 0 0', 1);
591 WaypointSprite_UpdateBuildFinished(cp.sprite, time + (e.max_health - e.health) / (e.count / ONS_CP_THINKRATE));
592 WaypointSprite_UpdateRule(cp.sprite,cp.team,SPRITERULE_TEAMPLAY);
593 cp.sprite.SendFlags |= 16;
595 onslaught_controlpoint_icon_link(e, ons_ControlPoint_Icon_BuildThink);
598 entity ons_ControlPoint_Waypoint(entity e)
602 int a = ons_ControlPoint_Attackable(e, e.team);
604 if(a == -2) { return WP_OnsCPDefend; } // defend now
605 if(a == -1 || a == 1 || a == 2) { return WP_OnsCP; } // touch
606 if(a == 3 || a == 4) { return WP_OnsCPAttack; } // attack
614 void ons_ControlPoint_UpdateSprite(entity e)
616 entity s1 = ons_ControlPoint_Waypoint(e);
617 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
620 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));
622 if(e.lastteam != e.team + 2 || e.lastshielded != sh || e.iscaptured != e.lastcaptured)
624 if(e.iscaptured) // don't mess up build bars!
628 WaypointSprite_UpdateMaxHealth(e.sprite, 0);
632 WaypointSprite_UpdateMaxHealth(e.sprite, e.goalentity.max_health);
633 WaypointSprite_UpdateHealth(e.sprite, e.goalentity.health);
639 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, false));
641 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
646 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, false));
648 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
650 WaypointSprite_Ping(e.sprite);
652 e.lastteam = e.team + 2;
654 e.lastcaptured = e.iscaptured;
658 void ons_ControlPoint_Touch(entity this, entity toucher)
662 if(IS_VEHICLE(toucher) && toucher.owner)
663 if(autocvar_g_onslaught_allow_vehicle_touch)
664 toucher = toucher.owner;
668 if(!IS_PLAYER(toucher)) { return; }
669 if(STAT(FROZEN, toucher)) { return; }
670 if(IS_DEAD(toucher)) { return; }
672 if ( SAME_TEAM(this,toucher) )
673 if ( this.iscaptured )
675 if(time <= toucher.teleport_antispam)
676 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT_ANTISPAM, rint(toucher.teleport_antispam - time));
678 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
681 attackable = ons_ControlPoint_Attackable(this, toucher.team);
682 if(attackable != 2 && attackable != 4)
684 // we've verified that this player has a legitimate claim to this point,
685 // so start building the captured point icon (which only captures this
686 // point if it successfully builds without being destroyed first)
687 ons_ControlPoint_Icon_Spawn(this, toucher);
689 this.ons_toucher = toucher;
691 onslaught_updatelinks();
694 void ons_ControlPoint_Think(entity this)
696 this.nextthink = time + ONS_CP_THINKRATE;
697 CSQCMODEL_AUTOUPDATE(this);
700 void ons_ControlPoint_Reset(entity this)
703 delete(this.goalentity);
705 this.goalentity = NULL;
707 this.colormap = 1024;
708 this.iscaptured = false;
709 this.islinked = false;
710 this.isshielded = true;
711 setthink(this, ons_ControlPoint_Think);
712 this.ons_toucher = NULL;
713 this.nextthink = time + ONS_CP_THINKRATE;
714 setmodel_fixsize(this, MDL_ONS_CP_PAD1);
716 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
717 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
719 onslaught_updatelinks();
721 SUB_UseTargets(this, this, NULL); // to reset the structures, playerspawns etc.
723 CSQCMODEL_AUTOUPDATE(this);
726 void ons_DelayedControlPoint_Setup(entity this)
728 onslaught_updatelinks();
730 // captureshield setup
731 ons_CaptureShield_Spawn(this, false);
733 CSQCMODEL_AUTOINIT(this);
736 void ons_ControlPoint_Setup(entity cp)
739 cp.ons_worldcpnext = ons_worldcplist; // link control point into ons_worldcplist
740 ons_worldcplist = cp;
742 cp.netname = "Control point";
744 cp.solid = SOLID_BBOX;
745 set_movetype(cp, MOVETYPE_NONE);
746 settouch(cp, ons_ControlPoint_Touch);
747 setthink(cp, ons_ControlPoint_Think);
748 cp.nextthink = time + ONS_CP_THINKRATE;
749 cp.reset = ons_ControlPoint_Reset;
751 cp.iscaptured = false;
753 cp.isshielded = true;
755 if(cp.message == "") { cp.message = "a"; }
758 setmodel_fixsize(cp, MDL_ONS_CP_PAD1);
760 // control point placement
761 if((cp.spawnflags & 1) || cp.noalign) // don't drop to floor, just stay at fixed location
764 set_movetype(cp, MOVETYPE_NONE);
766 else // drop to floor, automatically find a platform and set that as spawn origin
768 setorigin(cp, cp.origin + '0 0 20');
771 set_movetype(cp, MOVETYPE_TOSS);
775 WaypointSprite_SpawnFixed(WP_Null, cp.origin + CPGEN_WAYPOINT_OFFSET, cp, sprite, RADARICON_NONE);
776 WaypointSprite_UpdateRule(cp.sprite, cp.team, SPRITERULE_TEAMPLAY);
778 InitializeEntity(cp, ons_DelayedControlPoint_Setup, INITPRIO_SETLOCATION);
782 // =========================
783 // Main Generator Functions
784 // =========================
786 entity ons_Generator_Waypoint(entity e)
789 return WP_OnsGenShielded;
793 void ons_Generator_UpdateSprite(entity e)
795 entity s1 = ons_Generator_Waypoint(e);
796 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
798 if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
800 e.lastteam = e.team + 2;
801 e.lastshielded = e.isshielded;
805 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, false));
807 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
812 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, false));
814 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
816 WaypointSprite_Ping(e.sprite);
820 void ons_GeneratorDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
822 if(damage <= 0) { return; }
823 if(warmup_stage || gameover) { return; }
824 if(!round_handler_IsRoundStarted()) { return; }
826 if (attacker != this)
830 // generator is protected by a shield, so ignore the damage
831 if (time > this.pain_finished)
832 if (IS_PLAYER(attacker))
834 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
835 attacker.typehitsound += 1;
836 this.pain_finished = time + 1;
840 if (time > this.pain_finished)
842 this.pain_finished = time + 10;
843 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && SAME_TEAM(it, this), Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK));
844 play2team(this.team, SND(ONS_GENERATOR_UNDERATTACK));
847 this.health = this.health - damage;
848 WaypointSprite_UpdateHealth(this.sprite, this.health);
849 // choose an animation frame based on health
850 this.frame = 10 * bound(0, (1 - this.health / this.max_health), 1);
851 // see if the generator is still functional, or dying
854 this.lasthealth = this.health;
858 if (attacker == this)
859 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME));
862 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED));
863 PlayerScore_Add(attacker, SP_SCORE, 100);
865 this.iscaptured = false;
866 this.islinked = false;
867 this.isshielded = false;
868 this.takedamage = DAMAGE_NO; // can't be hurt anymore
869 this.event_damage = func_null; // won't do anything if hurt
870 this.count = 0; // reset counter
871 setthink(this, func_null);
873 //this.think(); // do the first explosion now
875 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
876 WaypointSprite_Ping(this.sprite);
877 //WaypointSprite_Kill(this.sprite); // can't do this yet, code too poor
879 onslaught_updatelinks();
882 // Throw some flaming gibs on damage, more damage = more chance for gib
883 if(random() < damage/220)
885 sound(this, CH_TRIGGER, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
889 // particles on every hit
890 Send_Effect(EFFECT_SPARKS, hitloc, force * -1, 1);
894 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE, ATTEN_NORM);
896 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE, ATTEN_NORM);
899 this.SendFlags |= GSF_STATUS;
902 void ons_GeneratorThink(entity this)
904 this.nextthink = time + GEN_THINKRATE;
907 if(!this.isshielded && this.wait < time)
909 this.wait = time + 5;
910 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
911 if(SAME_TEAM(it, this))
913 Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM);
914 soundto(MSG_ONE, it, CHAN_AUTO, SND(KH_ALARM), VOL_BASE, ATTEN_NONE); // FIXME: unique sound?
917 Send_Notification(NOTIF_ONE, it, MSG_CENTER, APP_TEAM_NUM(this.team, CENTER_ONS_NOTSHIELDED));
923 void ons_GeneratorReset(entity this)
925 this.team = this.team_saved;
926 this.lasthealth = this.max_health = this.health = autocvar_g_onslaught_gen_health;
927 this.takedamage = DAMAGE_AIM;
928 this.bot_attack = true;
929 IL_PUSH(g_bot_targets, this);
930 this.iscaptured = true;
931 this.islinked = true;
932 this.isshielded = true;
933 this.event_damage = ons_GeneratorDamage;
934 setthink(this, ons_GeneratorThink);
935 this.nextthink = time + GEN_THINKRATE;
937 Net_LinkEntity(this, false, 0, generator_send);
939 this.SendFlags = GSF_SETUP; // just incase
940 this.SendFlags |= GSF_STATUS;
942 WaypointSprite_UpdateMaxHealth(this.sprite, this.max_health);
943 WaypointSprite_UpdateHealth(this.sprite, this.health);
944 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
946 onslaught_updatelinks();
949 void ons_DelayedGeneratorSetup(entity this)
952 waypoint_spawnforitem_force(this, this.origin);
953 this.nearestwaypointtimeout = 0; // activate waypointing again
954 this.bot_basewaypoint = this.nearestwaypoint;
956 // captureshield setup
957 ons_CaptureShield_Spawn(this, true);
959 onslaught_updatelinks();
961 Net_LinkEntity(this, false, 0, generator_send);
965 void onslaught_generator_touch(entity this, entity toucher)
967 if ( IS_PLAYER(toucher) )
968 if ( SAME_TEAM(this,toucher) )
969 if ( this.iscaptured )
971 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
975 void ons_GeneratorSetup(entity gen) // called when spawning a generator entity on the map as a spawnfunc
978 int teamnumber = gen.team;
981 gen.ons_worldgeneratornext = ons_worldgeneratorlist; // link generator into ons_worldgeneratorlist
982 ons_worldgeneratorlist = gen;
984 gen.netname = sprintf("%s generator", Team_ColoredFullName(teamnumber));
985 gen.classname = "onslaught_generator";
986 gen.solid = SOLID_BBOX;
987 gen.team_saved = teamnumber;
988 set_movetype(gen, MOVETYPE_NONE);
989 gen.lasthealth = gen.max_health = gen.health = autocvar_g_onslaught_gen_health;
990 gen.takedamage = DAMAGE_AIM;
991 gen.bot_attack = true;
992 IL_PUSH(g_bot_targets, gen);
993 gen.event_damage = ons_GeneratorDamage;
994 gen.reset = ons_GeneratorReset;
995 setthink(gen, ons_GeneratorThink);
996 gen.nextthink = time + GEN_THINKRATE;
997 gen.iscaptured = true;
999 gen.isshielded = true;
1000 settouch(gen, onslaught_generator_touch);
1003 // model handled by CSQC
1004 setsize(gen, GENERATOR_MIN, GENERATOR_MAX);
1005 setorigin(gen, (gen.origin + CPGEN_SPAWN_OFFSET));
1006 gen.colormap = 1024 + (teamnumber - 1) * 17;
1008 // generator placement
1012 WaypointSprite_SpawnFixed(WP_Null, gen.origin + CPGEN_WAYPOINT_OFFSET, gen, sprite, RADARICON_NONE);
1013 WaypointSprite_UpdateRule(gen.sprite, gen.team, SPRITERULE_TEAMPLAY);
1014 WaypointSprite_UpdateMaxHealth(gen.sprite, gen.max_health);
1015 WaypointSprite_UpdateHealth(gen.sprite, gen.health);
1017 InitializeEntity(gen, ons_DelayedGeneratorSetup, INITPRIO_SETLOCATION);
1025 int total_generators;
1026 void Onslaught_count_generators()
1029 total_generators = redowned = blueowned = yellowowned = pinkowned = 0;
1030 for(e = ons_worldgeneratorlist; e; e = e.ons_worldgeneratornext)
1033 redowned += (e.team == NUM_TEAM_1 && e.health > 0);
1034 blueowned += (e.team == NUM_TEAM_2 && e.health > 0);
1035 yellowowned += (e.team == NUM_TEAM_3 && e.health > 0);
1036 pinkowned += (e.team == NUM_TEAM_4 && e.health > 0);
1040 int Onslaught_GetWinnerTeam()
1042 int winner_team = 0;
1044 winner_team = NUM_TEAM_1;
1047 if(winner_team) return 0;
1048 winner_team = NUM_TEAM_2;
1052 if(winner_team) return 0;
1053 winner_team = NUM_TEAM_3;
1057 if(winner_team) return 0;
1058 winner_team = NUM_TEAM_4;
1062 return -1; // no generators left?
1065 void nades_Clear(entity e);
1067 #define ONS_OWNED_GENERATORS() ((redowned > 0) + (blueowned > 0) + (yellowowned > 0) + (pinkowned > 0))
1068 #define ONS_OWNED_GENERATORS_OK() (ONS_OWNED_GENERATORS() > 1)
1069 bool Onslaught_CheckWinner()
1071 if ((autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60) || (round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0))
1073 ons_stalemate = true;
1075 if (!wpforenemy_announced)
1077 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT);
1078 sound(NULL, CH_INFO, SND_ONS_GENERATOR_DECAY, VOL_BASE, ATTEN_NONE);
1080 wpforenemy_announced = true;
1083 entity tmp_entity; // temporary entity
1085 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext) if(time >= tmp_entity.ons_overtime_damagedelay)
1087 // tmp_entity.max_health / 300 gives 5 minutes of overtime.
1088 // control points reduce the overtime duration.
1091 for(e = ons_worldcplist; e; e = e.ons_worldcpnext)
1093 if(DIFF_TEAM(e, tmp_entity))
1098 if(autocvar_g_campaign && autocvar__campaign_testrun)
1099 d = d * tmp_entity.max_health;
1101 d = d * tmp_entity.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
1103 Damage(tmp_entity, tmp_entity, tmp_entity, d, DEATH_HURTTRIGGER.m_id, tmp_entity.origin, '0 0 0');
1105 tmp_entity.sprite.SendFlags |= 16;
1107 tmp_entity.ons_overtime_damagedelay = time + 1;
1110 else { wpforenemy_announced = false; ons_stalemate = false; }
1112 Onslaught_count_generators();
1114 if(ONS_OWNED_GENERATORS_OK())
1117 int winner_team = Onslaught_GetWinnerTeam();
1121 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
1122 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
1123 TeamScore_AddToTeam(winner_team, ST_ONS_CAPS, +1);
1125 else if(winner_team == -1)
1127 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_TIED);
1128 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_TIED);
1131 ons_stalemate = false;
1133 play2all(SND(CTF_CAPTURE(winner_team)));
1135 round_handler_Init(7, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
1137 FOREACH_CLIENT(IS_PLAYER(it), {
1138 STAT(ROUNDLOST, it) = true;
1139 it.player_blocked = true;
1147 bool Onslaught_CheckPlayers()
1152 void Onslaught_RoundStart()
1155 FOREACH_CLIENT(IS_PLAYER(it), it.player_blocked = false);
1157 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1158 tmp_entity.sprite.SendFlags |= 16;
1160 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1161 tmp_entity.sprite.SendFlags |= 16;
1169 // NOTE: LEGACY CODE, needs to be re-written!
1171 void havocbot_goalrating_ons_offenseitems(entity this, float ratingscale, vector org, float sradius)
1173 bool needarmor = false, needweapons = false;
1175 // Needs armor/health?
1181 FOREACH(Weapons, it != WEP_Null, {
1182 if(this.weapons & (it.m_wepset))
1190 if(!needweapons && !needarmor)
1193 LOG_DEBUG(this.netname, " needs weapons ", ftos(needweapons));
1194 LOG_DEBUG(this.netname, " needs armor ", ftos(needarmor));
1196 // See what is around
1197 IL_EACH(g_items, it.bot_pickup,
1199 // gather health and armor only
1201 if ( ((it.health || it.armorvalue) && needarmor) || (it.weapons && needweapons ) )
1202 if (vdist(it.origin - org, <, sradius))
1204 int t = it.bot_pickupevalfunc(this, it);
1206 navigation_routerating(this, it, t * ratingscale, 500);
1211 void havocbot_role_ons_setrole(entity this, int role)
1213 LOG_DEBUG(this.netname," switched to ");
1216 case HAVOCBOT_ONS_ROLE_DEFENSE:
1217 LOG_DEBUG("defense");
1218 this.havocbot_role = havocbot_role_ons_defense;
1219 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE;
1220 this.havocbot_role_timeout = 0;
1222 case HAVOCBOT_ONS_ROLE_ASSISTANT:
1223 LOG_DEBUG("assistant");
1224 this.havocbot_role = havocbot_role_ons_assistant;
1225 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT;
1226 this.havocbot_role_timeout = 0;
1228 case HAVOCBOT_ONS_ROLE_OFFENSE:
1229 LOG_DEBUG("offense");
1230 this.havocbot_role = havocbot_role_ons_offense;
1231 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE;
1232 this.havocbot_role_timeout = 0;
1238 void havocbot_goalrating_ons_controlpoints_attack(entity this, float ratingscale)
1240 entity cp, cp1, cp2, best, wp;
1241 float radius, bestvalue;
1245 // Filter control points
1246 for(cp2 = ons_worldcplist; cp2; cp2 = cp2.ons_worldcpnext)
1249 cp2.wpconsidered = false;
1254 // Ignore owned controlpoints
1255 if(!(cp2.isgenneighbor[this.team] || cp2.iscpneighbor[this.team]))
1258 // Count team mates interested in this control point
1259 // (easier and cleaner than keeping counters per cp and teams)
1260 FOREACH_CLIENT(IS_PLAYER(it), {
1261 if(SAME_TEAM(it, this))
1262 if(it.havocbot_role_flags & HAVOCBOT_ONS_ROLE_OFFENSE)
1263 if(it.havocbot_ons_target == cp2)
1267 // NOTE: probably decrease the cost of attackable control points
1269 cp2.wpconsidered = true;
1272 // We'll consider only the best case
1273 bestvalue = 99999999999;
1275 for(cp1 = ons_worldcplist; cp1; cp1 = cp1.ons_worldcpnext)
1277 if (!cp1.wpconsidered)
1280 if(cp1.wpcost<bestvalue)
1282 bestvalue = cp1.wpcost;
1284 this.havocbot_ons_target = cp1;
1291 LOG_DEBUG(this.netname, " chose cp ranked ", ftos(bestvalue));
1295 // Should be attacked
1296 // Rate waypoints near it
1299 bestvalue = 99999999999;
1300 for(radius=0; radius<1000 && !found; radius+=500)
1302 for(wp=findradius(cp.origin,radius); wp; wp=wp.chain)
1304 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
1305 if(wp.classname=="waypoint")
1306 if(checkpvs(wp.origin,cp))
1309 if(wp.cnt<bestvalue)
1320 navigation_routerating(this, best, ratingscale, 10000);
1323 this.havocbot_attack_time = 0;
1324 if(checkpvs(this.view_ofs,cp))
1325 if(checkpvs(this.view_ofs,best))
1326 this.havocbot_attack_time = time + 2;
1330 navigation_routerating(this, cp, ratingscale, 10000);
1332 LOG_DEBUG(this.netname, " found an attackable controlpoint at ", vtos(cp.origin));
1336 // Should be touched
1337 LOG_DEBUG(this.netname, " found a touchable controlpoint at ", vtos(cp.origin));
1340 // Look for auto generated waypoint
1341 if (!bot_waypoints_for_items)
1342 for (wp = findradius(cp.origin,100); wp; wp = wp.chain)
1344 if(wp.classname=="waypoint")
1346 navigation_routerating(this, wp, ratingscale, 10000);
1351 // Nothing found, rate the controlpoint itself
1353 navigation_routerating(this, cp, ratingscale, 10000);
1357 bool havocbot_goalrating_ons_generator_attack(entity this, float ratingscale)
1359 entity g, wp, bestwp;
1363 for(g = ons_worldgeneratorlist; g; g = g.ons_worldgeneratornext)
1365 if(SAME_TEAM(g, this) || g.isshielded)
1368 // Should be attacked
1369 // Rate waypoints near it
1374 for(wp=findradius(g.origin,400); wp; wp=wp.chain)
1376 if(wp.classname=="waypoint")
1377 if(checkpvs(wp.origin,g))
1390 LOG_DEBUG("waypoints found around generator");
1391 navigation_routerating(this, bestwp, ratingscale, 10000);
1394 this.havocbot_attack_time = 0;
1395 if(checkpvs(this.view_ofs,g))
1396 if(checkpvs(this.view_ofs,bestwp))
1397 this.havocbot_attack_time = time + 5;
1403 LOG_DEBUG("generator found without waypoints around");
1404 // if there aren't waypoints near the generator go straight to it
1405 navigation_routerating(this, g, ratingscale, 10000);
1406 this.havocbot_attack_time = 0;
1413 void havocbot_role_ons_offense(entity this)
1417 this.havocbot_attack_time = 0;
1418 havocbot_ons_reset_role(this);
1422 // Set the role timeout if necessary
1423 if (!this.havocbot_role_timeout)
1424 this.havocbot_role_timeout = time + 120;
1426 if (time > this.havocbot_role_timeout)
1428 havocbot_ons_reset_role(this);
1432 if(this.havocbot_attack_time>time)
1435 if (this.bot_strategytime < time)
1437 navigation_goalrating_start(this);
1438 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
1439 if(!havocbot_goalrating_ons_generator_attack(this, 20000))
1440 havocbot_goalrating_ons_controlpoints_attack(this, 20000);
1441 havocbot_goalrating_ons_offenseitems(this, 10000, this.origin, 10000);
1442 navigation_goalrating_end(this);
1444 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
1448 void havocbot_role_ons_assistant(entity this)
1450 havocbot_ons_reset_role(this);
1453 void havocbot_role_ons_defense(entity this)
1455 havocbot_ons_reset_role(this);
1458 void havocbot_ons_reset_role(entity this)
1463 this.havocbot_ons_target = NULL;
1465 // TODO: Defend control points or generator if necessary
1467 havocbot_role_ons_setrole(this, HAVOCBOT_ONS_ROLE_OFFENSE);
1472 * Find control point or generator owned by the same team self which is nearest to pos
1473 * if max_dist is positive, only control points within this range will be considered
1475 entity ons_Nearest_ControlPoint(entity this, vector pos, float max_dist)
1477 entity closest_target = NULL;
1478 for(entity cp = ons_worldcplist; cp; cp = cp.ons_worldcpnext)
1480 if(SAME_TEAM(cp, this))
1482 if(max_dist <= 0 || vdist(cp.origin - pos, <=, max_dist))
1483 if(vlen2(cp.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
1484 closest_target = cp;
1486 for(entity gen = ons_worldgeneratorlist; gen; gen = gen.ons_worldgeneratornext)
1488 if(SAME_TEAM(gen, this))
1489 if(max_dist <= 0 || vdist(gen.origin - pos, <, max_dist))
1490 if(vlen2(gen.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
1491 closest_target = gen;
1494 return closest_target;
1498 * Find control point or generator owned by the same team self which is nearest to pos
1499 * if max_dist is positive, only control points within this range will be considered
1500 * This function only check distances on the XY plane, disregarding Z
1502 entity ons_Nearest_ControlPoint_2D(entity this, vector pos, float max_dist)
1504 entity closest_target = NULL;
1506 float smallest_distance = 0, distance;
1508 for(entity cp = ons_worldcplist; cp; cp = cp.ons_worldcpnext)
1510 delta = cp.origin - pos;
1512 distance = vlen(delta);
1514 if(SAME_TEAM(cp, this))
1516 if(max_dist <= 0 || distance <= max_dist)
1517 if(closest_target == NULL || distance <= smallest_distance )
1519 closest_target = cp;
1520 smallest_distance = distance;
1523 for(entity gen = ons_worldgeneratorlist; gen; gen = gen.ons_worldgeneratornext)
1525 delta = gen.origin - pos;
1527 distance = vlen(delta);
1529 if(SAME_TEAM(gen, this))
1530 if(max_dist <= 0 || distance <= max_dist)
1531 if(closest_target == NULL || distance <= smallest_distance )
1533 closest_target = gen;
1534 smallest_distance = distance;
1538 return closest_target;
1541 * find the number of control points and generators in the same team as this
1543 int ons_Count_SelfControlPoints(entity this)
1546 for(entity cp = ons_worldcplist; cp; cp = cp.ons_worldcpnext)
1548 if(SAME_TEAM(cp, this))
1552 for(entity gen = ons_worldgeneratorlist; gen; gen = gen.ons_worldgeneratornext)
1554 if(SAME_TEAM(gen, this))
1561 * Teleport player to a random position near tele_target
1562 * if tele_effects is true, teleport sound+particles are created
1563 * return false on failure
1565 bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effects)
1573 // narrow the range for each iteration to increase chances that a spawnpoint
1574 // can be found even if there's little room around the control point
1575 float iteration_scale = 1;
1576 for(i = 0; i < 16; ++i)
1578 iteration_scale -= i / 16;
1579 theta = random() * 2 * M_PI;
1583 loc *= random() * range * iteration_scale;
1585 loc += tele_target.origin + '0 0 128' * iteration_scale;
1587 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
1588 if(trace_fraction == 1.0 && !trace_startsolid)
1590 traceline(tele_target.origin, loc, MOVE_NOMONSTERS, tele_target); // double check to make sure we're not spawning outside the NULL
1591 if(trace_fraction == 1.0 && !trace_startsolid)
1595 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
1596 sound (player, CH_TRIGGER, SND_TELEPORT, VOL_BASE, ATTEN_NORM);
1598 setorigin(player, loc);
1599 player.angles = '0 1 0' * ( theta * RAD2DEG + 180 );
1600 makevectors(player.angles);
1601 player.fixangle = true;
1602 player.teleport_antispam = time + autocvar_g_onslaught_teleport_wait;
1605 Send_Effect(EFFECT_TELEPORT, player.origin + v_forward * 32, '0 0 0', 1);
1618 MUTATOR_HOOKFUNCTION(ons, reset_map_global)
1620 FOREACH_CLIENT(IS_PLAYER(it), {
1621 STAT(ROUNDLOST, it) = false;
1622 it.ons_deathloc = '0 0 0';
1623 PutClientInServer(it);
1628 MUTATOR_HOOKFUNCTION(ons, ClientDisconnect)
1630 entity player = M_ARGV(0, entity);
1632 player.ons_deathloc = '0 0 0';
1635 MUTATOR_HOOKFUNCTION(ons, MakePlayerObserver)
1637 entity player = M_ARGV(0, entity);
1639 player.ons_deathloc = '0 0 0';
1642 MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
1644 entity player = M_ARGV(0, entity);
1646 if(!round_handler_IsRoundStarted())
1648 player.player_blocked = true;
1653 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1655 l.sprite.SendFlags |= 16;
1657 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1659 l.sprite.SendFlags |= 16;
1662 if(ons_stalemate) { Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); }
1664 if ( autocvar_g_onslaught_spawn_choose )
1665 if ( player.ons_spawn_by )
1666 if ( ons_Teleport(player,player.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) )
1668 player.ons_spawn_by = NULL;
1672 if(autocvar_g_onslaught_spawn_at_controlpoints)
1673 if(random() <= autocvar_g_onslaught_spawn_at_controlpoints_chance)
1675 float random_target = autocvar_g_onslaught_spawn_at_controlpoints_random;
1676 entity tmp_entity, closest_target = NULL;
1677 vector spawn_loc = player.ons_deathloc;
1679 // new joining player or round reset, don't bother checking
1680 if(spawn_loc == '0 0 0') { return false; }
1682 if(random_target) { RandomSelection_Init(); }
1684 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1686 if(SAME_TEAM(tmp_entity, player))
1688 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1689 else if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL)
1690 closest_target = tmp_entity;
1693 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1699 float iteration_scale = 1;
1700 for(i = 0; i < 10; ++i)
1702 iteration_scale -= i / 10;
1703 loc = closest_target.origin + '0 0 96' * iteration_scale;
1704 loc += ('0 1 0' * random()) * 128 * iteration_scale;
1705 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
1706 if(trace_fraction == 1.0 && !trace_startsolid)
1708 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL
1709 if(trace_fraction == 1.0 && !trace_startsolid)
1711 setorigin(player, loc);
1712 player.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1720 if(autocvar_g_onslaught_spawn_at_generator)
1721 if(random() <= autocvar_g_onslaught_spawn_at_generator_chance)
1723 float random_target = autocvar_g_onslaught_spawn_at_generator_random;
1724 entity tmp_entity, closest_target = NULL;
1725 vector spawn_loc = player.ons_deathloc;
1727 // new joining player or round reset, don't bother checking
1728 if(spawn_loc == '0 0 0') { return false; }
1730 if(random_target) { RandomSelection_Init(); }
1732 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1735 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1738 if(SAME_TEAM(tmp_entity, player))
1739 if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL)
1740 closest_target = tmp_entity;
1744 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1750 float iteration_scale = 1;
1751 for(i = 0; i < 10; ++i)
1753 iteration_scale -= i / 10;
1754 loc = closest_target.origin + '0 0 128' * iteration_scale;
1755 loc += ('0 1 0' * random()) * 256 * iteration_scale;
1756 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
1757 if(trace_fraction == 1.0 && !trace_startsolid)
1759 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL
1760 if(trace_fraction == 1.0 && !trace_startsolid)
1762 setorigin(player, loc);
1763 player.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1774 MUTATOR_HOOKFUNCTION(ons, PlayerDies)
1776 entity frag_target = M_ARGV(2, entity);
1778 frag_target.ons_deathloc = frag_target.origin;
1780 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1782 l.sprite.SendFlags |= 16;
1784 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1786 l.sprite.SendFlags |= 16;
1789 if ( autocvar_g_onslaught_spawn_choose )
1790 if ( ons_Count_SelfControlPoints(frag_target) > 1 )
1791 stuffcmd(frag_target, "qc_cmd_cl hud clickradar\n");
1796 MUTATOR_HOOKFUNCTION(ons, MonsterMove)
1798 entity mon = M_ARGV(0, entity);
1800 entity e = find(NULL, targetname, mon.target);
1805 void ons_MonsterSpawn_Delayed(entity this)
1807 entity own = this.owner;
1809 if(!own) { delete(this); return; }
1813 entity e = find(NULL, target, own.targetname);
1818 own.use(own, e, NULL);
1825 MUTATOR_HOOKFUNCTION(ons, MonsterSpawn)
1827 entity mon = M_ARGV(0, entity);
1831 InitializeEntity(e, ons_MonsterSpawn_Delayed, INITPRIO_FINDTARGET);
1834 void ons_TurretSpawn_Delayed(entity this)
1836 entity own = this.owner;
1838 if(!own) { delete(this); return; }
1842 entity e = find(NULL, target, own.targetname);
1846 own.active = ACTIVE_NOT;
1848 own.use(own, e, NULL);
1855 MUTATOR_HOOKFUNCTION(ons, TurretSpawn)
1857 entity turret = M_ARGV(0, entity);
1861 InitializeEntity(e, ons_TurretSpawn_Delayed, INITPRIO_FINDTARGET);
1866 MUTATOR_HOOKFUNCTION(ons, HavocBot_ChooseRole)
1868 entity bot = M_ARGV(0, entity);
1870 havocbot_ons_reset_role(bot);
1874 MUTATOR_HOOKFUNCTION(ons, CheckAllowedTeams)
1876 // onslaught is special
1877 for(entity tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1879 switch(tmp_entity.team)
1881 case NUM_TEAM_1: c1 = 0; break;
1882 case NUM_TEAM_2: c2 = 0; break;
1883 case NUM_TEAM_3: c3 = 0; break;
1884 case NUM_TEAM_4: c4 = 0; break;
1891 MUTATOR_HOOKFUNCTION(ons, SpectateCopy)
1893 entity spectatee = M_ARGV(0, entity);
1894 entity client = M_ARGV(1, entity);
1896 STAT(ROUNDLOST, client) = STAT(ROUNDLOST, spectatee); // make spectators see it too
1899 MUTATOR_HOOKFUNCTION(ons, SV_ParseClientCommand)
1901 if(MUTATOR_RETURNVALUE) // command was already handled?
1904 entity player = M_ARGV(0, entity);
1905 string cmd_name = M_ARGV(1, string);
1906 int cmd_argc = M_ARGV(2, int);
1908 if ( cmd_name == "ons_spawn" )
1910 vector pos = player.origin;
1912 pos_x = stof(argv(1));
1914 pos_y = stof(argv(2));
1916 pos_z = stof(argv(3));
1918 if ( IS_PLAYER(player) )
1920 if ( !STAT(FROZEN, player) )
1922 entity source_point = ons_Nearest_ControlPoint(player, player.origin, autocvar_g_onslaught_teleport_radius);
1924 if ( !source_point && player.health > 0 )
1926 sprint(player, "\nYou need to be next to a control point\n");
1931 entity closest_target = ons_Nearest_ControlPoint_2D(player, pos, autocvar_g_onslaught_click_radius);
1933 if ( closest_target == NULL )
1935 sprint(player, "\nNo control point found\n");
1939 if ( player.health <= 0 )
1941 player.ons_spawn_by = closest_target;
1942 player.respawn_flags = player.respawn_flags | RESPAWN_FORCE;
1946 if ( source_point == closest_target )
1948 sprint(player, "\nTeleporting to the same point\n");
1952 if ( !ons_Teleport(player,closest_target,autocvar_g_onslaught_teleport_radius,true) )
1953 sprint(player, "\nUnable to teleport there\n");
1959 sprint(player, "\nNo teleportation for you\n");
1967 MUTATOR_HOOKFUNCTION(ons, PlayerUseKey)
1969 if(MUTATOR_RETURNVALUE || gameover) { return false; }
1971 entity player = M_ARGV(0, entity);
1973 if((time > player.teleport_antispam) && (!IS_DEAD(player)) && !player.vehicle)
1975 entity source_point = ons_Nearest_ControlPoint(player, player.origin, autocvar_g_onslaught_teleport_radius);
1978 stuffcmd(player, "qc_cmd_cl hud clickradar\n");
1984 MUTATOR_HOOKFUNCTION(ons, PlayHitsound)
1986 entity frag_victim = M_ARGV(0, entity);
1988 return (frag_victim.classname == "onslaught_generator" && !frag_victim.isshielded)
1989 || (frag_victim.classname == "onslaught_controlpoint_icon" && !frag_victim.owner.isshielded);
1992 MUTATOR_HOOKFUNCTION(ons, SendWaypoint)
1994 entity wp = M_ARGV(0, entity);
1995 entity to = M_ARGV(1, entity);
1996 int sf = M_ARGV(2, int);
1997 int wp_flag = M_ARGV(3, int);
2001 if(wp.owner.classname == "onslaught_controlpoint")
2003 entity wp_owner = wp.owner;
2004 entity e = WaypointSprite_getviewentity(to);
2005 if(SAME_TEAM(e, wp_owner) && wp_owner.goalentity.health >= wp_owner.goalentity.max_health) { wp_flag |= 2; }
2006 if(!ons_ControlPoint_Attackable(wp_owner, e.team)) { wp_flag |= 2; }
2008 if(wp.owner.classname == "onslaught_generator")
2010 entity wp_owner = wp.owner;
2011 if(wp_owner.isshielded && wp_owner.health >= wp_owner.max_health) { wp_flag |= 2; }
2012 if(wp_owner.health <= 0) { wp_flag |= 2; }
2016 M_ARGV(3, int) = wp_flag;
2019 MUTATOR_HOOKFUNCTION(ons, TurretValidateTarget)
2021 entity turret_target = M_ARGV(1, entity);
2023 if(substring(turret_target.classname, 0, 10) == "onslaught_") // don't attack onslaught targets, that's the player's job!
2025 M_ARGV(3, float) = -3;
2032 MUTATOR_HOOKFUNCTION(ons, TurretThink)
2034 entity turret = M_ARGV(0, entity);
2036 // ONS uses somewhat backwards linking.
2039 entity e = find(NULL, targetname, turret.target);
2041 turret.team = e.team;
2044 if(turret.team != turret.tur_head.team)
2045 turret_respawn(turret);
2053 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
2054 Link between control points.
2056 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.
2059 "target" - first control point.
2060 "target2" - second control point.
2062 spawnfunc(onslaught_link)
2064 if(!g_onslaught) { delete(this); return; }
2066 if (this.target == "" || this.target2 == "")
2067 objerror(this, "target and target2 must be set\n");
2069 this.ons_worldlinknext = ons_worldlinklist; // link into ons_worldlinklist
2070 ons_worldlinklist = this;
2072 InitializeEntity(this, ons_DelayedLinkSetup, INITPRIO_FINDTARGET);
2073 Net_LinkEntity(this, false, 0, ons_Link_Send);
2076 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
2077 Control point. Be sure to give this enough clearance so that the shootable part has room to exist
2079 This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
2082 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2083 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
2084 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
2087 spawnfunc(onslaught_controlpoint)
2089 if(!g_onslaught) { delete(this); return; }
2091 ons_ControlPoint_Setup(this);
2094 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
2097 spawnfunc_onslaught_link entities can target this.
2100 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
2101 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2103 spawnfunc(onslaught_generator)
2105 if(!g_onslaught) { delete(this); return; }
2106 if(!this.team) { objerror(this, "team must be set"); }
2108 ons_GeneratorSetup(this);
2112 void ons_ScoreRules()
2114 CheckAllowedTeams(NULL);
2116 if(c1 >= 0) teams |= BIT(0);
2117 if(c2 >= 0) teams |= BIT(1);
2118 if(c3 >= 0) teams |= BIT(2);
2119 if(c4 >= 0) teams |= BIT(3);
2120 ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, 0, true);
2121 ScoreInfo_SetLabel_TeamScore (ST_ONS_CAPS, "destroyed", SFL_SORT_PRIO_PRIMARY);
2122 ScoreInfo_SetLabel_PlayerScore(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
2123 ScoreInfo_SetLabel_PlayerScore(SP_ONS_TAKES, "takes", 0);
2124 ScoreRules_basics_end();
2127 void ons_DelayedInit(entity this) // Do this check with a delay so we can wait for teams to be set up
2131 round_handler_Spawn(Onslaught_CheckPlayers, Onslaught_CheckWinner, Onslaught_RoundStart);
2132 round_handler_Init(5, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
2135 void ons_Initialize()
2138 ons_captureshield_force = autocvar_g_onslaught_shield_force;
2140 InitializeEntity(NULL, ons_DelayedInit, INITPRIO_GAMETYPE);