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;
32 // =======================
33 // CaptureShield Functions
34 // =======================
36 bool clientcamera_send(entity this, entity to, int sf)
38 WriteHeader(MSG_ENTITY, ENT_ONSCAMERA);
40 WriteVector(MSG_ENTITY, this.origin);
42 WriteAngle(MSG_ENTITY, this.angles_x);
43 WriteAngle(MSG_ENTITY, this.angles_y);
44 WriteAngle(MSG_ENTITY, this.angles_z);
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 teamnumber)
318 if(cp.aregensneighbor & BIT(teamnumber)) return 2;
319 if(cp.arecpsneighbor & BIT(teamnumber)) return 1;
324 int ons_ControlPoint_Attackable(entity cp, int teamnumber)
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 == teamnumber)
344 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
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, teamnumber);
352 if(a == 2) // near our generator?
353 return 3; // EMERGENCY!
359 if(ons_ControlPoint_CanBeLinked(cp, teamnumber))
361 a = ons_ControlPoint_CanBeLinked(cp, teamnumber); // 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 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_CPDESTROYED), this.owner.message, attacker.netname);
416 GameRules_scoring_add(attacker, ONS_TAKES, 1);
417 GameRules_scoring_add(attacker, SCORE, 10);
419 this.owner.goalentity = NULL;
420 this.owner.islinked = false;
421 this.owner.iscaptured = false;
423 this.owner.colormap = 1024;
425 WaypointSprite_UpdateMaxHealth(this.owner.sprite, 0);
427 onslaught_updatelinks();
429 // Use targets now (somebody make sure this is in the right place..)
430 SUB_UseTargets(this.owner, this, NULL);
432 this.owner.waslinked = this.owner.islinked;
433 if(this.owner.model != "models/onslaught/controlpoint_pad.md3")
434 setmodel(this.owner, MDL_ONS_CP_PAD1);
435 //setsize(this, '-32 -32 0', '32 32 8');
440 this.SendFlags |= CPSF_STATUS;
443 bool ons_ControlPoint_Icon_Heal(entity targ, entity inflictor, float amount, float limit)
445 float hlth = GetResource(targ, RES_HEALTH);
446 float true_limit = ((limit != RES_LIMIT_NONE) ? limit : targ.max_health);
447 if (hlth <= 0 || hlth >= true_limit)
450 GiveResourceWithLimit(targ, RES_HEALTH, amount, true_limit);
451 hlth = GetResource(targ, RES_HEALTH);
452 if(targ.owner.iscaptured)
453 WaypointSprite_UpdateHealth(targ.owner.sprite, hlth);
455 WaypointSprite_UpdateBuildFinished(targ.owner.sprite, time + (targ.max_health - hlth) / (targ.count / ONS_CP_THINKRATE));
456 targ.SendFlags |= CPSF_STATUS;
460 void ons_ControlPoint_Icon_Think(entity this)
462 this.nextthink = time + ONS_CP_THINKRATE;
464 if(autocvar_g_onslaught_cp_proxydecap)
466 int _enemy_count = 0;
467 int _friendly_count = 0;
469 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it), {
470 if(vdist(it.origin - this.origin, <, autocvar_g_onslaught_cp_proxydecap_distance))
472 if(SAME_TEAM(it, this))
479 _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
480 _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
482 GiveResourceWithLimit(this, RES_HEALTH, (_friendly_count - _enemy_count), this.max_health);
483 this.SendFlags |= CPSF_STATUS;
484 if(GetResource(this, RES_HEALTH) <= 0)
486 ons_ControlPoint_Icon_Damage(this, this, this, 1, 0, DMG_NOWEP, this.origin, '0 0 0');
491 if (time > this.pain_finished + 5)
493 if(GetResource(this, RES_HEALTH) < this.max_health)
495 GiveResourceWithLimit(this, RES_HEALTH, this.count, this.max_health);
496 WaypointSprite_UpdateHealth(this.owner.sprite, GetResource(this, RES_HEALTH));
500 if(this.owner.islinked != this.owner.waslinked)
502 // unteam the spawnpoint if needed
503 int t = this.owner.team;
504 if(!this.owner.islinked)
507 SUB_UseTargets(this.owner, this, NULL);
511 this.owner.waslinked = this.owner.islinked;
515 if(random() < 0.6 - GetResource(this, RES_HEALTH) / this.max_health)
517 Send_Effect(EFFECT_ELECTRIC_SPARKS, this.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
520 sound(this, CH_PAIN, SND_ONS_SPARK1, VOL_BASE, ATTEN_NORM);
521 else if (random() > 0.5)
522 sound(this, CH_PAIN, SND_ONS_SPARK2, VOL_BASE, ATTEN_NORM);
526 void ons_ControlPoint_Icon_BuildThink(entity this)
530 this.nextthink = time + ONS_CP_THINKRATE;
532 // only do this if there is power
533 a = ons_ControlPoint_CanBeLinked(this.owner, this.owner.team);
537 GiveResource(this, RES_HEALTH, this.count);
539 this.SendFlags |= CPSF_STATUS;
541 if (GetResource(this, RES_HEALTH) >= this.max_health)
543 SetResourceExplicit(this, RES_HEALTH, this.max_health);
544 this.count = autocvar_g_onslaught_cp_regen * ONS_CP_THINKRATE; // slow repair rate from now on
545 setthink(this, ons_ControlPoint_Icon_Think);
546 sound(this, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILT, VOL_BASE, ATTEN_NORM);
547 this.owner.iscaptured = true;
548 this.solid = SOLID_BBOX;
550 Send_Effect(EFFECT_CAP(this.owner.team), this.owner.origin, '0 0 0', 1);
552 WaypointSprite_UpdateMaxHealth(this.owner.sprite, this.max_health);
553 WaypointSprite_UpdateHealth(this.owner.sprite, GetResource(this, RES_HEALTH));
555 if(IS_PLAYER(this.owner.ons_toucher))
557 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ONSLAUGHT_CAPTURE, this.owner.ons_toucher.netname, this.owner.message);
558 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);
559 Send_Notification(NOTIF_ONE, this.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE, this.owner.message);
560 GameRules_scoring_add(this.owner.ons_toucher, ONS_CAPS, 1);
561 GameRules_scoring_add_team(this.owner.ons_toucher, SCORE, 10);
564 this.owner.ons_toucher = NULL;
566 onslaught_updatelinks();
568 // Use targets now (somebody make sure this is in the right place..)
569 SUB_UseTargets(this.owner, this, NULL);
571 this.SendFlags |= CPSF_SETUP;
573 if(this.owner.model != MDL_ONS_CP_PAD2.model_str())
574 setmodel(this.owner, MDL_ONS_CP_PAD2);
576 if(random() < 0.9 - GetResource(this, RES_HEALTH) / this.max_health)
577 Send_Effect(EFFECT_RAGE, this.origin + 10 * randomvec(), '0 0 -1', 1);
580 void onslaught_controlpoint_icon_link(entity e, void(entity this) spawnproc);
582 void ons_ControlPoint_Icon_Spawn(entity cp, entity player)
584 entity e = new(onslaught_controlpoint_icon);
586 setsize(e, CPICON_MIN, CPICON_MAX);
587 setorigin(e, cp.origin + CPICON_OFFSET);
590 e.max_health = autocvar_g_onslaught_cp_health;
591 SetResourceExplicit(e, RES_HEALTH, autocvar_g_onslaught_cp_buildhealth);
593 e.takedamage = DAMAGE_AIM;
595 IL_PUSH(g_bot_targets, e);
596 e.event_damage = ons_ControlPoint_Icon_Damage;
597 e.event_heal = ons_ControlPoint_Icon_Heal;
598 e.team = player.team;
599 e.colormap = 1024 + (e.team - 1) * 17;
600 e.count = (e.max_health - GetResource(e, RES_HEALTH)) * ONS_CP_THINKRATE / autocvar_g_onslaught_cp_buildtime; // how long it takes to build
602 sound(e, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILD, VOL_BASE, ATTEN_NORM);
606 cp.colormap = e.colormap;
608 Send_Effect(EFFECT_FLAG_TOUCH(player.team), e.origin, '0 0 0', 1);
610 WaypointSprite_UpdateBuildFinished(cp.sprite, time + (e.max_health - GetResource(e, RES_HEALTH)) / (e.count / ONS_CP_THINKRATE));
611 WaypointSprite_UpdateRule(cp.sprite,cp.team,SPRITERULE_TEAMPLAY);
612 cp.sprite.SendFlags |= 16;
614 onslaught_controlpoint_icon_link(e, ons_ControlPoint_Icon_BuildThink);
617 entity ons_ControlPoint_Waypoint(entity e)
621 int a = ons_ControlPoint_Attackable(e, e.team);
623 if(a == -2) { return WP_OnsCPDefend; } // defend now
624 if(a == -1 || a == 1 || a == 2) { return WP_OnsCP; } // touch
625 if(a == 3 || a == 4) { return WP_OnsCPAttack; } // attack
633 void ons_ControlPoint_UpdateSprite(entity e)
635 entity s1 = ons_ControlPoint_Waypoint(e);
636 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
639 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));
641 if(e.lastteam != e.team + 2 || e.lastshielded != sh || e.iscaptured != e.lastcaptured)
643 if(e.iscaptured) // don't mess up build bars!
647 WaypointSprite_UpdateMaxHealth(e.sprite, 0);
651 WaypointSprite_UpdateMaxHealth(e.sprite, e.goalentity.max_health);
652 WaypointSprite_UpdateHealth(e.sprite, GetResource(e.goalentity, RES_HEALTH));
658 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, false));
660 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
665 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, false));
667 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
669 WaypointSprite_Ping(e.sprite);
671 e.lastteam = e.team + 2;
673 e.lastcaptured = e.iscaptured;
677 void ons_ControlPoint_Touch(entity this, entity toucher)
681 if(IS_VEHICLE(toucher) && toucher.owner)
683 if (!autocvar_g_onslaught_allow_vehicle_touch)
685 toucher = toucher.owner;
688 if(!IS_PLAYER(toucher)) { return; }
689 if(STAT(FROZEN, toucher)) { return; }
690 if(IS_DEAD(toucher)) { return; }
692 if ( SAME_TEAM(this,toucher) )
693 if ( this.iscaptured )
695 if(time <= toucher.teleport_antispam)
696 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT_ANTISPAM, rint(toucher.teleport_antispam - time));
698 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
701 attackable = ons_ControlPoint_Attackable(this, toucher.team);
702 if(attackable != 2 && attackable != 4)
704 // we've verified that this player has a legitimate claim to this point,
705 // so start building the captured point icon (which only captures this
706 // point if it successfully builds without being destroyed first)
707 ons_ControlPoint_Icon_Spawn(this, toucher);
709 this.ons_toucher = toucher;
711 onslaught_updatelinks();
714 void ons_ControlPoint_Think(entity this)
716 this.nextthink = time + ONS_CP_THINKRATE;
717 CSQCMODEL_AUTOUPDATE(this);
720 void ons_ControlPoint_Reset(entity this)
723 delete(this.goalentity);
725 this.goalentity = NULL;
727 this.colormap = 1024;
728 this.iscaptured = false;
729 this.islinked = false;
730 this.isshielded = true;
731 setthink(this, ons_ControlPoint_Think);
732 this.ons_toucher = NULL;
733 this.nextthink = time + ONS_CP_THINKRATE;
734 setmodel(this, MDL_ONS_CP_PAD1);
736 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
737 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
739 onslaught_updatelinks();
741 SUB_UseTargets(this, this, NULL); // to reset the structures, playerspawns etc.
743 CSQCMODEL_AUTOUPDATE(this);
746 void ons_DelayedControlPoint_Setup(entity this)
748 onslaught_updatelinks();
750 // captureshield setup
751 ons_CaptureShield_Spawn(this, false);
753 CSQCMODEL_AUTOINIT(this);
756 void ons_ControlPoint_Setup(entity cp)
759 cp.ons_worldcpnext = ons_worldcplist; // link control point into ons_worldcplist
760 ons_worldcplist = cp;
762 cp.netname = "Control point";
764 cp.solid = SOLID_BBOX;
765 set_movetype(cp, MOVETYPE_NONE);
766 settouch(cp, ons_ControlPoint_Touch);
767 setthink(cp, ons_ControlPoint_Think);
768 cp.nextthink = time + ONS_CP_THINKRATE;
769 cp.reset = ons_ControlPoint_Reset;
771 cp.iscaptured = false;
773 cp.isshielded = true;
775 if(cp.message == "") { cp.message = "a"; }
778 setmodel(cp, MDL_ONS_CP_PAD1);
780 // control point placement
781 if((cp.spawnflags & 1) || cp.noalign) // don't drop to floor, just stay at fixed location
784 set_movetype(cp, MOVETYPE_NONE);
786 else // drop to floor, automatically find a platform and set that as spawn origin
788 setorigin(cp, cp.origin + '0 0 20');
791 set_movetype(cp, MOVETYPE_TOSS);
795 WaypointSprite_SpawnFixed(WP_Null, cp.origin + CPGEN_WAYPOINT_OFFSET, cp, sprite, RADARICON_NONE);
796 WaypointSprite_UpdateRule(cp.sprite, cp.team, SPRITERULE_TEAMPLAY);
798 InitializeEntity(cp, ons_DelayedControlPoint_Setup, INITPRIO_SETLOCATION);
802 // =========================
803 // Main Generator Functions
804 // =========================
806 entity ons_Generator_Waypoint(entity e)
809 return WP_OnsGenShielded;
813 void ons_Generator_UpdateSprite(entity e)
815 entity s1 = ons_Generator_Waypoint(e);
816 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
818 if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
820 e.lastteam = e.team + 2;
821 e.lastshielded = e.isshielded;
825 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, false));
827 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
832 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, false));
834 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
836 WaypointSprite_Ping(e.sprite);
840 void ons_camSetup(entity this)
843 vector ang = '0 0 0';
844 vector best_ang = '0 0 0';
845 float best_trace_fraction = 0;
848 dir = vec2(cos(ang.y * DEG2RAD), sin(ang.y * DEG2RAD));
850 traceline(this.origin, this.origin - dir, MOVE_WORLDONLY, this);
851 if(trace_fraction > best_trace_fraction)
853 best_trace_fraction = trace_fraction;
855 if(trace_fraction == 1)
862 cam.origin = this.origin;
863 setorigin(cam, cam.origin);
864 cam.angles = best_ang;
865 Net_LinkEntity(cam, false, 0, clientcamera_send);
867 FOREACH_CLIENT(true, it.clientcamera = cam;);
869 WriteByte(MSG_ALL, SVC_SETVIEWANGLES);
870 WriteAngle(MSG_ALL, cam.angles_x);
871 WriteAngle(MSG_ALL, cam.angles_y);
872 WriteAngle(MSG_ALL, cam.angles_z);
875 void ons_GeneratorDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, .entity weaponentity, vector hitloc, vector force)
877 if(damage <= 0) return;
878 if(warmup_stage || game_stopped) return;
879 if(!round_handler_IsRoundStarted()) return;
881 if (attacker != this)
885 // generator is protected by a shield, so ignore the damage
886 if (time > this.pain_finished)
887 if (IS_PLAYER(attacker))
889 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
890 attacker.typehitsound += 1;
891 this.pain_finished = time + 1;
895 if (time > this.pain_finished)
897 this.pain_finished = time + 10;
898 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && SAME_TEAM(it, this), Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK));
899 play2team(this.team, SND(ONS_GENERATOR_UNDERATTACK));
902 TakeResource(this, RES_HEALTH, damage);
903 float hlth = GetResource(this, RES_HEALTH);
904 WaypointSprite_UpdateHealth(this.sprite, hlth);
905 // choose an animation frame based on health
906 this.frame = 10 * bound(0, (1 - hlth / this.max_health), 1);
907 // see if the generator is still functional, or dying
910 this.lasthealth = hlth;
914 if (attacker == this)
915 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME));
918 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED));
919 GameRules_scoring_add(attacker, SCORE, 100);
921 this.iscaptured = false;
922 this.islinked = false;
923 this.isshielded = false;
924 this.takedamage = DAMAGE_NO; // can't be hurt anymore
925 this.event_damage = func_null; // won't do anything if hurt
926 this.event_heal = func_null;
927 this.count = 0; // reset counter
928 setthink(this, func_null);
930 //this.think(); // do the first explosion now
932 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
933 WaypointSprite_Ping(this.sprite);
934 //WaypointSprite_Kill(this.sprite); // can't do this yet, code too poor
936 onslaught_updatelinks();
941 // Throw some flaming gibs on damage, more damage = more chance for gib
942 if(random() < damage/220)
944 sound(this, CH_TRIGGER, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
948 // particles on every hit
949 Send_Effect(EFFECT_SPARKS, hitloc, force * -1, 1);
953 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE, ATTEN_NORM);
955 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE, ATTEN_NORM);
958 this.SendFlags |= GSF_STATUS;
961 bool ons_GeneratorHeal(entity targ, entity inflictor, float amount, float limit)
963 float true_limit = ((limit != RES_LIMIT_NONE) ? limit : targ.max_health);
964 float hlth = GetResource(targ, RES_HEALTH);
965 if (hlth <= 0 || hlth >= true_limit)
968 GiveResourceWithLimit(targ, RES_HEALTH, amount, true_limit);
969 hlth = GetResource(targ, RES_HEALTH);
970 WaypointSprite_UpdateHealth(targ.sprite, hlth);
971 targ.frame = 10 * bound(0, (1 - hlth / targ.max_health), 1);
972 targ.lasthealth = hlth;
973 targ.SendFlags |= GSF_STATUS;
977 void ons_GeneratorThink(entity this)
979 this.nextthink = time + GEN_THINKRATE;
981 if (game_stopped || this.isshielded || time < this.wait)
984 this.wait = time + 5;
985 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it),
987 if (SAME_TEAM(it, this))
989 Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM);
991 soundto(MSG_ONE, this, CHAN_AUTO, SND(KH_ALARM), VOL_BASE, ATTEN_NONE); // FIXME: unique sound?
994 Send_Notification(NOTIF_ONE, it, MSG_CENTER, APP_TEAM_NUM(this.team, CENTER_ONS_NOTSHIELDED));
998 void ons_GeneratorReset(entity this)
1000 this.team = this.team_saved;
1001 SetResourceExplicit(this, RES_HEALTH, autocvar_g_onslaught_gen_health);
1002 this.lasthealth = this.max_health = autocvar_g_onslaught_gen_health;
1003 this.takedamage = DAMAGE_AIM;
1004 this.bot_attack = true;
1005 if(!IL_CONTAINS(g_bot_targets, this))
1006 IL_PUSH(g_bot_targets, this);
1007 this.iscaptured = true;
1008 this.islinked = true;
1009 this.isshielded = true;
1010 this.event_damage = ons_GeneratorDamage;
1011 this.event_heal = ons_GeneratorHeal;
1012 setthink(this, ons_GeneratorThink);
1013 this.nextthink = time + GEN_THINKRATE;
1015 Net_LinkEntity(this, false, 0, generator_send);
1017 this.SendFlags = GSF_SETUP; // just incase
1018 this.SendFlags |= GSF_STATUS;
1020 WaypointSprite_UpdateMaxHealth(this.sprite, this.max_health);
1021 WaypointSprite_UpdateHealth(this.sprite, GetResource(this, RES_HEALTH));
1022 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
1024 onslaught_updatelinks();
1027 void ons_DelayedGeneratorSetup(entity this)
1030 waypoint_spawnforitem_force(this, this.origin);
1031 this.nearestwaypointtimeout = 0; // activate waypointing again
1032 this.bot_basewaypoint = this.nearestwaypoint;
1034 // captureshield setup
1035 ons_CaptureShield_Spawn(this, true);
1037 onslaught_updatelinks();
1039 Net_LinkEntity(this, false, 0, generator_send);
1043 void onslaught_generator_touch(entity this, entity toucher)
1045 if ( IS_PLAYER(toucher) )
1046 if ( SAME_TEAM(this,toucher) )
1047 if ( this.iscaptured )
1049 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
1053 void ons_GeneratorSetup(entity gen) // called when spawning a generator entity on the map as a spawnfunc
1056 int teamnumber = gen.team;
1059 gen.ons_worldgeneratornext = ons_worldgeneratorlist; // link generator into ons_worldgeneratorlist
1060 ons_worldgeneratorlist = gen;
1062 gen.netname = sprintf("%s generator", Team_ColoredFullName(teamnumber));
1063 gen.classname = "onslaught_generator";
1064 gen.solid = SOLID_BBOX;
1065 gen.team_saved = teamnumber;
1066 IL_PUSH(g_saved_team, gen);
1067 set_movetype(gen, MOVETYPE_NONE);
1068 gen.lasthealth = gen.max_health = autocvar_g_onslaught_gen_health;
1069 SetResourceExplicit(gen, RES_HEALTH, autocvar_g_onslaught_gen_health);
1070 gen.takedamage = DAMAGE_AIM;
1071 gen.bot_attack = true;
1072 IL_PUSH(g_bot_targets, gen);
1073 gen.event_damage = ons_GeneratorDamage;
1074 gen.event_heal = ons_GeneratorHeal;
1075 gen.reset = ons_GeneratorReset;
1076 setthink(gen, ons_GeneratorThink);
1077 gen.nextthink = time + GEN_THINKRATE;
1078 gen.iscaptured = true;
1079 gen.islinked = true;
1080 gen.isshielded = true;
1081 settouch(gen, onslaught_generator_touch);
1084 // model handled by CSQC
1085 setsize(gen, GENERATOR_MIN, GENERATOR_MAX);
1086 setorigin(gen, (gen.origin + CPGEN_SPAWN_OFFSET));
1087 gen.colormap = 1024 + (teamnumber - 1) * 17;
1089 // generator placement
1093 WaypointSprite_SpawnFixed(WP_Null, gen.origin + CPGEN_WAYPOINT_OFFSET, gen, sprite, RADARICON_NONE);
1094 WaypointSprite_UpdateRule(gen.sprite, gen.team, SPRITERULE_TEAMPLAY);
1095 WaypointSprite_UpdateMaxHealth(gen.sprite, gen.max_health);
1096 WaypointSprite_UpdateHealth(gen.sprite, GetResource(gen, RES_HEALTH));
1098 InitializeEntity(gen, ons_DelayedGeneratorSetup, INITPRIO_SETLOCATION);
1106 int total_generators;
1107 void Onslaught_count_generators()
1110 total_generators = 0;
1111 for (int i = 1; i <= NUM_TEAMS; ++i)
1113 Team_SetNumberOfControlPoints(Team_GetTeamFromIndex(i), 0);
1115 for(e = ons_worldgeneratorlist; e; e = e.ons_worldgeneratornext)
1118 if (GetResource(e, RES_HEALTH) < 1)
1122 entity team_ = Entity_GetTeam(e);
1123 int num_control_points = Team_GetNumberOfControlPoints(team_);
1124 ++num_control_points;
1125 Team_SetNumberOfControlPoints(team_, num_control_points);
1129 int Onslaught_GetWinnerTeam()
1131 int winner_team = 0;
1132 if (Team_GetNumberOfControlPoints(Team_GetTeamFromIndex(1)) >= 1)
1134 winner_team = NUM_TEAM_1;
1136 for (int i = 2; i <= NUM_TEAMS; ++i)
1138 if (Team_GetNumberOfControlPoints(Team_GetTeamFromIndex(i)) >= 1)
1140 if (winner_team != 0)
1144 winner_team = Team_IndexToTeam(i);
1151 return -1; // no generators left?
1154 void nades_Clear(entity e);
1156 bool Onslaught_CheckWinner()
1158 if ((autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60) || (round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0))
1160 ons_stalemate = true;
1162 if (!wpforenemy_announced)
1164 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT);
1165 sound(NULL, CH_INFO, SND_ONS_GENERATOR_DECAY, VOL_BASE, ATTEN_NONE);
1167 wpforenemy_announced = true;
1170 entity tmp_entity; // temporary entity
1172 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext) if(time >= tmp_entity.ons_overtime_damagedelay)
1174 // tmp_entity.max_health / 300 gives 5 minutes of overtime.
1175 // control points reduce the overtime duration.
1178 for(e = ons_worldcplist; e; e = e.ons_worldcpnext)
1180 if(DIFF_TEAM(e, tmp_entity))
1185 if(autocvar_g_campaign && autocvar__campaign_testrun)
1186 d = d * tmp_entity.max_health;
1188 d = d * tmp_entity.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
1190 Damage(tmp_entity, tmp_entity, tmp_entity, d, DEATH_HURTTRIGGER.m_id, DMG_NOWEP, tmp_entity.origin, '0 0 0');
1192 tmp_entity.sprite.SendFlags |= 16;
1194 tmp_entity.ons_overtime_damagedelay = time + 1;
1197 else { wpforenemy_announced = false; ons_stalemate = false; }
1199 Onslaught_count_generators();
1201 if (Team_GetNumberOfTeamsWithControlPoints() > 1)
1206 int winner_team = Onslaught_GetWinnerTeam();
1210 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
1211 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
1212 TeamScore_AddToTeam(winner_team, ST_ONS_CAPS, +1);
1214 else if(winner_team == -1)
1216 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_TIED);
1217 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_TIED);
1220 ons_stalemate = false;
1222 play2all(SND(CTF_CAPTURE(winner_team)));
1224 round_handler_Init(7, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
1226 FOREACH_CLIENT(IS_PLAYER(it), {
1227 STAT(ROUNDLOST, it) = true;
1228 it.player_blocked = true;
1233 game_stopped = true;
1237 bool Onslaught_CheckPlayers()
1242 void Onslaught_RoundStart()
1245 FOREACH_CLIENT(IS_PLAYER(it), it.player_blocked = false);
1247 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1248 tmp_entity.sprite.SendFlags |= 16;
1250 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1251 tmp_entity.sprite.SendFlags |= 16;
1259 // NOTE: LEGACY CODE, needs to be re-written!
1261 void havocbot_role_ons_setrole(entity this, int role)
1265 case HAVOCBOT_ONS_ROLE_DEFENSE:
1266 LOG_DEBUG(this.netname, " switched to defense");
1267 this.havocbot_role = havocbot_role_ons_defense;
1268 this.havocbot_role_timeout = 0;
1270 case HAVOCBOT_ONS_ROLE_ASSISTANT:
1271 LOG_DEBUG(this.netname, " switched to assistant");
1272 this.havocbot_role = havocbot_role_ons_assistant;
1273 this.havocbot_role_timeout = 0;
1275 case HAVOCBOT_ONS_ROLE_OFFENSE:
1276 LOG_DEBUG(this.netname, " switched to offense");
1277 this.havocbot_role = havocbot_role_ons_offense;
1278 this.havocbot_role_timeout = 0;
1283 void havocbot_goalrating_ons_controlpoints_attack(entity this, float ratingscale)
1285 entity cp, cp1, cp2, best, wp;
1286 float radius, bestvalue;
1290 // Filter control points
1291 for(cp2 = ons_worldcplist; cp2; cp2 = cp2.ons_worldcpnext)
1294 cp2.wpconsidered = false;
1299 // Ignore owned controlpoints
1300 if(!((cp2.aregensneighbor & BIT(this.team)) || (cp2.arecpsneighbor & BIT(this.team))))
1303 // Count team mates interested in this control point
1304 // (easier and cleaner than keeping counters per cp and teams)
1305 FOREACH_CLIENT(it != this && IS_PLAYER(it), {
1306 if(SAME_TEAM(it, this))
1307 if(it.havocbot_role == havocbot_role_ons_offense)
1308 if(it.havocbot_ons_target == cp2)
1312 // NOTE: probably decrease the cost of attackable control points
1314 cp2.wpconsidered = true;
1317 // We'll consider only the best case
1318 bestvalue = FLOAT_MAX;
1320 for(cp1 = ons_worldcplist; cp1; cp1 = cp1.ons_worldcpnext)
1322 if (!cp1.wpconsidered)
1325 if(cp1.wpcost<bestvalue)
1327 bestvalue = cp1.wpcost;
1329 this.havocbot_ons_target = cp1;
1336 LOG_DEBUG(this.netname, " chose cp ranked ", ftos(bestvalue));
1340 // Should be attacked
1341 // Rate waypoints near it
1344 bestvalue = FLOAT_MAX;
1345 for (radius = 500; radius <= 1000 && !found; radius += 500)
1347 IL_EACH(g_waypoints, vdist(cp.origin - it.origin, <, radius),
1349 if (!(it.wpflags & WAYPOINTFLAG_GENERATED) && checkpvs(it.origin, cp))
1352 if (it.cnt < bestvalue)
1363 navigation_routerating(this, best, ratingscale, 10000);
1366 this.havocbot_attack_time = 0;
1367 if(checkpvs(this.origin + this.view_ofs, cp))
1368 if(checkpvs(this.origin + this.view_ofs, best))
1369 this.havocbot_attack_time = time + 2;
1373 navigation_routerating(this, cp, ratingscale, 10000);
1375 LOG_DEBUG(this.netname, " found an attackable controlpoint at ", vtos(cp.origin));
1379 // Should be touched
1380 LOG_DEBUG(this.netname, " found a touchable controlpoint at ", vtos(cp.origin));
1381 navigation_routerating(this, cp, ratingscale * 2, 10000);
1385 bool havocbot_goalrating_ons_generator_attack(entity this, float ratingscale)
1387 entity g, wp, bestwp;
1391 for(g = ons_worldgeneratorlist; g; g = g.ons_worldgeneratornext)
1393 if(SAME_TEAM(g, this) || g.isshielded)
1396 // Should be attacked
1397 // Rate waypoints near it
1400 bestvalue = FLOAT_MAX;
1402 IL_EACH(g_waypoints, vdist(g.origin - it.origin, <, 400),
1404 if (checkpvs(it.origin, g))
1407 if (it.cnt < bestvalue)
1417 LOG_DEBUG("waypoints found around generator");
1418 navigation_routerating(this, bestwp, ratingscale, 10000);
1421 this.havocbot_attack_time = 0;
1422 if(checkpvs(this.origin + this.view_ofs, g))
1423 if(checkpvs(this.origin + this.view_ofs, bestwp))
1424 this.havocbot_attack_time = time + 5;
1430 LOG_DEBUG("generator found without waypoints around");
1431 // if there aren't waypoints near the generator go straight to it
1432 navigation_routerating(this, g, ratingscale, 10000);
1433 this.havocbot_attack_time = 0;
1440 void havocbot_role_ons_offense(entity this)
1444 this.havocbot_attack_time = 0;
1445 havocbot_ons_reset_role(this);
1449 // Set the role timeout if necessary
1450 if (!this.havocbot_role_timeout)
1451 this.havocbot_role_timeout = time + 120;
1453 if (time > this.havocbot_role_timeout)
1455 havocbot_ons_reset_role(this);
1459 if(this.havocbot_attack_time>time)
1462 if (navigation_goalrating_timeout(this))
1464 navigation_goalrating_start(this);
1465 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
1466 if(!havocbot_goalrating_ons_generator_attack(this, 10000))
1467 havocbot_goalrating_ons_controlpoints_attack(this, 10000);
1468 havocbot_goalrating_items(this, 25000, this.origin, 10000);
1469 navigation_goalrating_end(this);
1471 navigation_goalrating_timeout_set(this);
1475 void havocbot_role_ons_assistant(entity this)
1477 havocbot_ons_reset_role(this);
1480 void havocbot_role_ons_defense(entity this)
1482 havocbot_ons_reset_role(this);
1485 void havocbot_ons_reset_role(entity this)
1490 this.havocbot_ons_target = NULL;
1492 // TODO: Defend control points or generator if necessary
1494 havocbot_role_ons_setrole(this, HAVOCBOT_ONS_ROLE_OFFENSE);
1499 * Find control point or generator owned by the same team self which is nearest to pos
1500 * if max_dist is positive, only control points within this range will be considered
1502 entity ons_Nearest_ControlPoint(entity this, vector pos, float max_dist)
1504 entity closest_target = NULL;
1505 for(entity cp = ons_worldcplist; cp; cp = cp.ons_worldcpnext)
1507 if(SAME_TEAM(cp, this))
1509 if(max_dist <= 0 || vdist(cp.origin - pos, <=, max_dist))
1510 if(vlen2(cp.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
1511 closest_target = cp;
1513 for(entity gen = ons_worldgeneratorlist; gen; gen = gen.ons_worldgeneratornext)
1515 if(SAME_TEAM(gen, this))
1516 if(max_dist <= 0 || vdist(gen.origin - pos, <, max_dist))
1517 if(vlen2(gen.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
1518 closest_target = gen;
1521 return closest_target;
1525 * Find control point or generator owned by the same team self which is nearest to pos
1526 * if max_dist is positive, only control points within this range will be considered
1527 * This function only check distances on the XY plane, disregarding Z
1529 entity ons_Nearest_ControlPoint_2D(entity this, vector pos, float max_dist)
1531 entity closest_target = NULL;
1533 float smallest_distance = 0, distance;
1535 for(entity cp = ons_worldcplist; cp; cp = cp.ons_worldcpnext)
1537 delta = cp.origin - pos;
1539 distance = vlen(delta);
1541 if(SAME_TEAM(cp, this))
1543 if(max_dist <= 0 || distance <= max_dist)
1544 if(closest_target == NULL || distance <= smallest_distance )
1546 closest_target = cp;
1547 smallest_distance = distance;
1550 for(entity gen = ons_worldgeneratorlist; gen; gen = gen.ons_worldgeneratornext)
1552 delta = gen.origin - pos;
1554 distance = vlen(delta);
1556 if(SAME_TEAM(gen, this))
1557 if(max_dist <= 0 || distance <= max_dist)
1558 if(closest_target == NULL || distance <= smallest_distance )
1560 closest_target = gen;
1561 smallest_distance = distance;
1565 return closest_target;
1568 * find the number of control points and generators in the same team as this
1570 int ons_Count_SelfControlPoints(entity this)
1573 for(entity cp = ons_worldcplist; cp; cp = cp.ons_worldcpnext)
1575 if(SAME_TEAM(cp, this))
1579 for(entity gen = ons_worldgeneratorlist; gen; gen = gen.ons_worldgeneratornext)
1581 if(SAME_TEAM(gen, this))
1588 * Teleport player to a random position near tele_target
1589 * if tele_effects is true, teleport sound+particles are created
1590 * return false on failure
1592 bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effects)
1600 // narrow the range for each iteration to increase chances that a spawnpoint
1601 // can be found even if there's little room around the control point
1602 float iteration_scale = 1;
1603 for(i = 0; i < 16; ++i)
1605 iteration_scale -= i / 16;
1606 theta = random() * 2 * M_PI;
1610 loc *= random() * range * iteration_scale;
1612 loc += tele_target.origin + '0 0 128' * iteration_scale;
1614 tracebox(loc, STAT(PL_MIN, player), STAT(PL_MAX, player), loc, MOVE_NORMAL, player);
1615 if(trace_fraction == 1.0 && !trace_startsolid)
1617 traceline(tele_target.origin, loc, MOVE_NOMONSTERS, tele_target); // double check to make sure we're not spawning outside the NULL
1618 if(trace_fraction == 1.0 && !trace_startsolid)
1622 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
1623 sound (player, CH_TRIGGER, SND_TELEPORT, VOL_BASE, ATTEN_NORM);
1625 setorigin(player, loc);
1626 player.angles = '0 1 0' * ( theta * RAD2DEG + 180 );
1627 makevectors(player.angles);
1628 player.fixangle = true;
1629 if (IS_BOT_CLIENT(player))
1631 player.v_angle = player.angles;
1632 bot_aim_reset(player);
1634 player.teleport_antispam = time + autocvar_g_onslaught_teleport_wait;
1637 Send_Effect(EFFECT_TELEPORT, player.origin + v_forward * 32, '0 0 0', 1);
1650 MUTATOR_HOOKFUNCTION(ons, reset_map_global)
1652 FOREACH_CLIENT(IS_PLAYER(it), {
1653 STAT(ROUNDLOST, it) = false;
1654 it.ons_deathloc = '0 0 0';
1655 PutClientInServer(it);
1656 it.clientcamera = it;
1661 MUTATOR_HOOKFUNCTION(ons, ClientDisconnect)
1663 entity player = M_ARGV(0, entity);
1665 player.ons_deathloc = '0 0 0';
1668 MUTATOR_HOOKFUNCTION(ons, MakePlayerObserver)
1670 entity player = M_ARGV(0, entity);
1672 player.ons_deathloc = '0 0 0';
1675 MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
1677 entity player = M_ARGV(0, entity);
1679 if(!round_handler_IsRoundStarted())
1681 player.player_blocked = true;
1686 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1688 l.sprite.SendFlags |= 16;
1690 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1692 l.sprite.SendFlags |= 16;
1695 if(ons_stalemate) { Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); }
1697 if ( autocvar_g_onslaught_spawn_choose )
1698 if ( player.ons_spawn_by )
1699 if ( ons_Teleport(player,player.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) )
1701 player.ons_spawn_by = NULL;
1705 if(autocvar_g_onslaught_spawn_at_controlpoints)
1706 if(random() <= autocvar_g_onslaught_spawn_at_controlpoints_chance)
1708 float random_target = autocvar_g_onslaught_spawn_at_controlpoints_random;
1709 entity tmp_entity, closest_target = NULL;
1710 vector spawn_loc = player.ons_deathloc;
1712 // new joining player or round reset, don't bother checking
1713 if(spawn_loc == '0 0 0') { return false; }
1715 if(random_target) { RandomSelection_Init(); }
1717 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1719 if(SAME_TEAM(tmp_entity, player))
1722 RandomSelection_AddEnt(tmp_entity, 1, 1);
1723 else if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL)
1724 closest_target = tmp_entity;
1728 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1734 float iteration_scale = 1;
1735 for(i = 0; i < 10; ++i)
1737 iteration_scale -= i / 10;
1738 loc = closest_target.origin + '0 0 96' * iteration_scale;
1739 loc += ('0 1 0' * random()) * 128 * iteration_scale;
1740 tracebox(loc, STAT(PL_MIN, player), STAT(PL_MAX, player), loc, MOVE_NORMAL, player);
1741 if(trace_fraction == 1.0 && !trace_startsolid)
1743 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL
1744 if(trace_fraction == 1.0 && !trace_startsolid)
1746 setorigin(player, loc);
1747 player.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1755 if(autocvar_g_onslaught_spawn_at_generator)
1756 if(random() <= autocvar_g_onslaught_spawn_at_generator_chance)
1758 float random_target = autocvar_g_onslaught_spawn_at_generator_random;
1759 entity tmp_entity, closest_target = NULL;
1760 vector spawn_loc = player.ons_deathloc;
1762 // new joining player or round reset, don't bother checking
1763 if(spawn_loc == '0 0 0') { return false; }
1765 if(random_target) { RandomSelection_Init(); }
1767 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1770 RandomSelection_AddEnt(tmp_entity, 1, 1);
1773 if(SAME_TEAM(tmp_entity, player))
1774 if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL)
1775 closest_target = tmp_entity;
1779 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1785 float iteration_scale = 1;
1786 for(i = 0; i < 10; ++i)
1788 iteration_scale -= i / 10;
1789 loc = closest_target.origin + '0 0 128' * iteration_scale;
1790 loc += ('0 1 0' * random()) * 256 * iteration_scale;
1791 tracebox(loc, STAT(PL_MIN, player), STAT(PL_MAX, player), loc, MOVE_NORMAL, player);
1792 if(trace_fraction == 1.0 && !trace_startsolid)
1794 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL
1795 if(trace_fraction == 1.0 && !trace_startsolid)
1797 setorigin(player, loc);
1798 player.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1809 MUTATOR_HOOKFUNCTION(ons, PlayerDies)
1811 entity frag_target = M_ARGV(2, entity);
1813 frag_target.ons_deathloc = frag_target.origin;
1815 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1817 l.sprite.SendFlags |= 16;
1819 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1821 l.sprite.SendFlags |= 16;
1824 if ( autocvar_g_onslaught_spawn_choose )
1825 if ( ons_Count_SelfControlPoints(frag_target) > 1 )
1826 stuffcmd(frag_target, "qc_cmd_cl hud clickradar\n");
1831 MUTATOR_HOOKFUNCTION(ons, MonsterMove)
1833 entity mon = M_ARGV(0, entity);
1835 entity e = find(NULL, targetname, mon.target);
1840 void ons_MonsterSpawn_Delayed(entity this)
1842 entity own = this.owner;
1844 if(!own) { delete(this); return; }
1848 entity e = find(NULL, target, own.targetname);
1853 own.use(own, e, NULL);
1860 MUTATOR_HOOKFUNCTION(ons, MonsterSpawn)
1862 entity mon = M_ARGV(0, entity);
1866 InitializeEntity(e, ons_MonsterSpawn_Delayed, INITPRIO_FINDTARGET);
1869 void ons_TurretSpawn_Delayed(entity this)
1871 entity own = this.owner;
1873 if(!own) { delete(this); return; }
1877 entity e = find(NULL, target, own.targetname);
1881 own.active = ACTIVE_NOT;
1883 own.use(own, e, NULL);
1890 MUTATOR_HOOKFUNCTION(ons, TurretSpawn)
1892 entity turret = M_ARGV(0, entity);
1896 InitializeEntity(e, ons_TurretSpawn_Delayed, INITPRIO_FINDTARGET);
1901 MUTATOR_HOOKFUNCTION(ons, HavocBot_ChooseRole)
1903 entity bot = M_ARGV(0, entity);
1905 havocbot_ons_reset_role(bot);
1909 MUTATOR_HOOKFUNCTION(ons, TeamBalance_CheckAllowedTeams)
1911 // onslaught is special
1912 for(entity tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1914 if (Team_IsValidTeam(tmp_entity.team))
1916 M_ARGV(0, float) |= Team_TeamToBit(tmp_entity.team);
1923 MUTATOR_HOOKFUNCTION(ons, SpectateCopy)
1925 entity spectatee = M_ARGV(0, entity);
1926 entity client = M_ARGV(1, entity);
1928 STAT(ROUNDLOST, client) = STAT(ROUNDLOST, spectatee); // make spectators see it too
1931 MUTATOR_HOOKFUNCTION(ons, SV_ParseClientCommand)
1933 if(MUTATOR_RETURNVALUE) // command was already handled?
1936 entity player = M_ARGV(0, entity);
1937 string cmd_name = M_ARGV(1, string);
1938 int cmd_argc = M_ARGV(2, int);
1940 if ( cmd_name == "ons_spawn" )
1942 vector pos = player.origin;
1944 pos_x = stof(argv(1));
1946 pos_y = stof(argv(2));
1948 pos_z = stof(argv(3));
1950 if ( IS_PLAYER(player) )
1952 if ( !STAT(FROZEN, player) )
1954 entity source_point = ons_Nearest_ControlPoint(player, player.origin, autocvar_g_onslaught_teleport_radius);
1956 if ( !source_point && GetResource(player, RES_HEALTH) > 0 )
1958 sprint(player, "\nYou need to be next to a control point\n");
1963 entity closest_target = ons_Nearest_ControlPoint_2D(player, pos, autocvar_g_onslaught_click_radius);
1965 if ( closest_target == NULL )
1967 sprint(player, "\nNo control point found\n");
1971 if ( GetResource(player, RES_HEALTH) <= 0 )
1973 player.ons_spawn_by = closest_target;
1974 player.respawn_flags = player.respawn_flags | RESPAWN_FORCE;
1978 if ( source_point == closest_target )
1980 sprint(player, "\nTeleporting to the same point\n");
1984 if ( !ons_Teleport(player,closest_target,autocvar_g_onslaught_teleport_radius,true) )
1985 sprint(player, "\nUnable to teleport there\n");
1991 sprint(player, "\nNo teleportation for you\n");
1999 MUTATOR_HOOKFUNCTION(ons, PlayerUseKey)
2001 if(MUTATOR_RETURNVALUE || game_stopped) return false;
2003 entity player = M_ARGV(0, entity);
2005 if((time > player.teleport_antispam) && (!IS_DEAD(player)) && !player.vehicle)
2007 entity source_point = ons_Nearest_ControlPoint(player, player.origin, autocvar_g_onslaught_teleport_radius);
2010 stuffcmd(player, "qc_cmd_cl hud clickradar\n");
2016 MUTATOR_HOOKFUNCTION(ons, PlayHitsound)
2018 entity frag_victim = M_ARGV(0, entity);
2020 return (frag_victim.classname == "onslaught_generator" && !frag_victim.isshielded)
2021 || (frag_victim.classname == "onslaught_controlpoint_icon" && !frag_victim.owner.isshielded);
2024 MUTATOR_HOOKFUNCTION(ons, SendWaypoint)
2026 entity wp = M_ARGV(0, entity);
2027 entity to = M_ARGV(1, entity);
2028 int sf = M_ARGV(2, int);
2029 int wp_flag = M_ARGV(3, int);
2033 if(wp.owner.classname == "onslaught_controlpoint")
2035 entity wp_owner = wp.owner;
2036 entity e = WaypointSprite_getviewentity(to);
2037 if(SAME_TEAM(e, wp_owner) && GetResource(wp_owner.goalentity, RES_HEALTH) >= wp_owner.goalentity.max_health) { wp_flag |= 2; }
2038 if(!ons_ControlPoint_Attackable(wp_owner, e.team)) { wp_flag |= 2; }
2040 if(wp.owner.classname == "onslaught_generator")
2042 entity wp_owner = wp.owner;
2043 if(wp_owner.isshielded && GetResource(wp_owner, RES_HEALTH) >= wp_owner.max_health) { wp_flag |= 2; }
2044 if(GetResource(wp_owner, RES_HEALTH) <= 0) { wp_flag |= 2; }
2048 M_ARGV(3, int) = wp_flag;
2051 MUTATOR_HOOKFUNCTION(ons, TurretValidateTarget)
2053 entity turret_target = M_ARGV(1, entity);
2055 if(substring(turret_target.classname, 0, 10) == "onslaught_") // don't attack onslaught targets, that's the player's job!
2057 M_ARGV(3, float) = -3;
2064 MUTATOR_HOOKFUNCTION(ons, TurretThink)
2066 entity turret = M_ARGV(0, entity);
2068 // ONS uses somewhat backwards linking.
2071 entity e = find(NULL, targetname, turret.target);
2073 turret.team = e.team;
2076 if(turret.team != turret.tur_head.team)
2077 turret_respawn(turret);
2085 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
2086 Link between control points.
2088 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.
2091 "target" - first control point.
2092 "target2" - second control point.
2094 spawnfunc(onslaught_link)
2096 if(!g_onslaught) { delete(this); return; }
2098 if (this.target == "" || this.target2 == "")
2099 objerror(this, "target and target2 must be set\n");
2101 this.ons_worldlinknext = ons_worldlinklist; // link into ons_worldlinklist
2102 ons_worldlinklist = this;
2104 InitializeEntity(this, ons_DelayedLinkSetup, INITPRIO_FINDTARGET);
2105 Net_LinkEntity(this, false, 0, ons_Link_Send);
2108 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
2109 Control point. Be sure to give this enough clearance so that the shootable part has room to exist
2111 This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
2114 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2115 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
2116 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
2119 spawnfunc(onslaught_controlpoint)
2121 if(!g_onslaught) { delete(this); return; }
2123 ons_ControlPoint_Setup(this);
2126 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
2129 spawnfunc_onslaught_link entities can target this.
2132 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
2133 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2135 spawnfunc(onslaught_generator)
2137 if(!g_onslaught) { delete(this); return; }
2138 if(!this.team) { objerror(this, "team must be set"); }
2140 ons_GeneratorSetup(this);
2144 void ons_ScoreRules()
2146 entity balance = TeamBalance_CheckAllowedTeams(NULL);
2147 int teams = TeamBalance_GetAllowedTeams(balance);
2148 TeamBalance_Destroy(balance);
2149 GameRules_scoring(teams, SFL_SORT_PRIO_PRIMARY, 0, {
2150 field_team(ST_ONS_CAPS, "destroyed", SFL_SORT_PRIO_PRIMARY);
2151 field(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
2152 field(SP_ONS_TAKES, "takes", 0);
2156 void ons_DelayedInit(entity this) // Do this check with a delay so we can wait for teams to be set up
2160 round_handler_Spawn(Onslaught_CheckPlayers, Onslaught_CheckWinner, Onslaught_RoundStart);
2161 round_handler_Init(5, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
2164 void ons_Initialize()
2167 ons_captureshield_force = autocvar_g_onslaught_shield_force;
2169 cam = new(objective_camera);
2171 InitializeEntity(NULL, ons_DelayedInit, INITPRIO_GAMETYPE);