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);
33 // =======================
34 // CaptureShield Functions
35 // =======================
37 bool clientcamera_send(entity this, entity to, int sf)
39 WriteHeader(MSG_ENTITY, ENT_ONSCAMERA);
41 WriteCoord(MSG_ENTITY, this.origin_x);
42 WriteCoord(MSG_ENTITY, this.origin_y);
43 WriteCoord(MSG_ENTITY, this.origin_z);
45 WriteAngle(MSG_ENTITY, this.angles_x);
46 WriteAngle(MSG_ENTITY, this.angles_y);
47 WriteAngle(MSG_ENTITY, this.angles_z);
52 bool ons_CaptureShield_Customize(entity this, entity client)
54 entity e = WaypointSprite_getviewentity(client);
56 if(!this.enemy.isshielded && (ons_ControlPoint_Attackable(this.enemy, e.team) > 0 || this.enemy.classname != "onslaught_controlpoint")) { return false; }
57 if(SAME_TEAM(this, e)) { return false; }
62 void ons_CaptureShield_Touch(entity this, entity toucher)
64 if(!this.enemy.isshielded && (ons_ControlPoint_Attackable(this.enemy, toucher.team) > 0 || this.enemy.classname != "onslaught_controlpoint")) { return; }
65 if(!IS_PLAYER(toucher)) { return; }
66 if(SAME_TEAM(toucher, this)) { return; }
68 vector mymid = (this.absmin + this.absmax) * 0.5;
69 vector theirmid = (toucher.absmin + toucher.absmax) * 0.5;
71 Damage(toucher, this, this, 0, DEATH_HURTTRIGGER.m_id, mymid, normalize(theirmid - mymid) * ons_captureshield_force);
73 if(IS_REAL_CLIENT(toucher))
75 play2(toucher, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
77 if(this.enemy.classname == "onslaught_generator")
78 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_GENERATOR_SHIELDED);
80 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_CONTROLPOINT_SHIELDED);
84 void ons_CaptureShield_Reset(entity this)
86 this.colormap = this.enemy.colormap;
87 this.team = this.enemy.team;
90 void ons_CaptureShield_Spawn(entity generator, bool is_generator)
92 entity shield = new(ons_captureshield);
93 IL_PUSH(g_onsshields, shield);
95 shield.enemy = generator;
96 shield.team = generator.team;
97 shield.colormap = generator.colormap;
98 shield.reset = ons_CaptureShield_Reset;
99 settouch(shield, ons_CaptureShield_Touch);
100 setcefc(shield, ons_CaptureShield_Customize);
101 shield.effects = EF_ADDITIVE;
102 set_movetype(shield, MOVETYPE_NOCLIP);
103 shield.solid = SOLID_TRIGGER;
104 shield.avelocity = '7 0 11';
106 shield.model = ((is_generator) ? "models/onslaught/generator_shield.md3" : "models/onslaught/controlpoint_shield.md3");
108 precache_model(shield.model);
109 setorigin(shield, generator.origin);
110 _setmodel(shield, shield.model);
111 setsize(shield, shield.scale * shield.mins, shield.scale * shield.maxs);
119 void setmodel_fixsize(entity e, Model m)
125 void onslaught_updatelinks()
128 // first check if the game has ended
129 LOG_DEBUG("--- updatelinks ---");
130 // mark generators as being shielded and networked
131 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
134 LOG_DEBUG(etos(l), " (generator) belongs to team ", ftos(l.team));
136 LOG_DEBUG(etos(l), " (generator) is destroyed");
137 l.islinked = l.iscaptured;
138 l.isshielded = l.iscaptured;
139 l.sprite.SendFlags |= 16;
141 // mark points as shielded and not networked
142 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
146 l.aregensneighbor = 0;
147 l.arecpsneighbor = 0;
148 LOG_DEBUG(etos(l), " (point) belongs to team ", ftos(l.team));
149 l.sprite.SendFlags |= 16;
151 // flow power outward from the generators through the network
156 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
158 // if both points are captured by the same team, and only one of
159 // them is powered, mark the other one as powered as well
160 if (l.enemy.iscaptured && l.goalentity.iscaptured)
161 if (l.enemy.islinked != l.goalentity.islinked)
162 if(SAME_TEAM(l.enemy, l.goalentity))
164 if (!l.goalentity.islinked)
167 l.goalentity.islinked = true;
168 LOG_DEBUG(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)");
170 else if (!l.enemy.islinked)
173 l.enemy.islinked = true;
174 LOG_DEBUG(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)");
179 // now that we know which points are powered we can mark their neighbors
180 // as unshielded if team differs
181 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
183 if (l.goalentity.islinked)
185 if(DIFF_TEAM(l.goalentity, l.enemy))
187 LOG_DEBUG(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)");
188 l.enemy.isshielded = false;
190 if(l.goalentity.classname == "onslaught_generator")
191 l.enemy.aregensneighbor |= BIT(l.goalentity.team);
193 l.enemy.arecpsneighbor |= BIT(l.goalentity.team);
195 if (l.enemy.islinked)
197 if(DIFF_TEAM(l.goalentity, l.enemy))
199 LOG_DEBUG(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)");
200 l.goalentity.isshielded = false;
202 if(l.enemy.classname == "onslaught_generator")
203 l.goalentity.aregensneighbor |= BIT(l.enemy.team);
205 l.goalentity.arecpsneighbor |= BIT(l.enemy.team);
208 // now update the generators
209 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
213 LOG_DEBUG(etos(l), " (generator) is shielded");
214 l.takedamage = DAMAGE_NO;
216 IL_REMOVE(g_bot_targets, l);
217 l.bot_attack = false;
221 LOG_DEBUG(etos(l), " (generator) is not shielded");
222 l.takedamage = DAMAGE_AIM;
224 IL_PUSH(g_bot_targets, l);
228 ons_Generator_UpdateSprite(l);
230 // now update the takedamage and alpha variables on control point icons
231 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
235 LOG_DEBUG(etos(l), " (point) is shielded");
238 l.goalentity.takedamage = DAMAGE_NO;
239 if(l.goalentity.bot_attack)
240 IL_REMOVE(g_bot_targets, l.goalentity);
241 l.goalentity.bot_attack = false;
246 LOG_DEBUG(etos(l), " (point) is not shielded");
249 l.goalentity.takedamage = DAMAGE_AIM;
250 if(!l.goalentity.bot_attack)
251 IL_PUSH(g_bot_targets, l.goalentity);
252 l.goalentity.bot_attack = true;
255 ons_ControlPoint_UpdateSprite(l);
257 IL_EACH(g_onsshields, true,
259 it.team = it.enemy.team;
260 it.colormap = it.enemy.colormap;
265 // ===================
266 // Main Link Functions
267 // ===================
269 bool ons_Link_Send(entity this, entity to, int sendflags)
271 WriteHeader(MSG_ENTITY, ENT_CLIENT_RADARLINK);
272 WriteByte(MSG_ENTITY, sendflags);
275 WriteCoord(MSG_ENTITY, this.goalentity.origin_x);
276 WriteCoord(MSG_ENTITY, this.goalentity.origin_y);
277 WriteCoord(MSG_ENTITY, this.goalentity.origin_z);
281 WriteCoord(MSG_ENTITY, this.enemy.origin_x);
282 WriteCoord(MSG_ENTITY, this.enemy.origin_y);
283 WriteCoord(MSG_ENTITY, this.enemy.origin_z);
287 WriteByte(MSG_ENTITY, this.clientcolors); // which is goalentity's color + enemy's color * 16
292 void ons_Link_CheckUpdate(entity this)
294 // TODO check if the two sides have moved (currently they won't move anyway)
295 float cc = 0, cc1 = 0, cc2 = 0;
297 if(this.goalentity.islinked || this.goalentity.iscaptured) { cc1 = (this.goalentity.team - 1) * 0x01; }
298 if(this.enemy.islinked || this.enemy.iscaptured) { cc2 = (this.enemy.team - 1) * 0x10; }
302 if(cc != this.clientcolors)
304 this.clientcolors = cc;
308 this.nextthink = time;
311 void ons_DelayedLinkSetup(entity this)
313 this.goalentity = find(NULL, targetname, this.target);
314 this.enemy = find(NULL, targetname, this.target2);
315 if(!this.goalentity) { objerror(this, "can not find target\n"); }
316 if(!this.enemy) { objerror(this, "can not find target2\n"); }
318 LOG_DEBUG(etos(this.goalentity), " linked with ", etos(this.enemy));
320 setthink(this, ons_Link_CheckUpdate);
321 this.nextthink = time;
325 // =============================
326 // Main Control Point Functions
327 // =============================
329 int ons_ControlPoint_CanBeLinked(entity cp, int teamnumber)
331 if(cp.aregensneighbor & BIT(teamnumber)) return 2;
332 if(cp.arecpsneighbor & BIT(teamnumber)) return 1;
337 int ons_ControlPoint_Attackable(entity cp, int teamnumber)
338 // -2: SAME TEAM, attackable by enemy!
343 // 3: attack it (HIGH PRIO)
344 // 4: touch it (HIGH PRIO)
352 else if(cp.goalentity)
354 // if there's already an icon built, nothing happens
355 if(cp.team == teamnumber)
357 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
358 if(a) // attackable by enemy?
359 return -2; // EMERGENCY!
362 // we know it can be linked, so no need to check
364 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
365 if(a == 2) // near our generator?
366 return 3; // EMERGENCY!
372 if(ons_ControlPoint_CanBeLinked(cp, teamnumber))
374 a = ons_ControlPoint_CanBeLinked(cp, teamnumber); // why was this here NUM_TEAM_1 + NUM_TEAM_2 - t
376 return 4; // GET THIS ONE NOW!
378 return 2; // TOUCH ME
384 void ons_ControlPoint_Icon_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
386 if(damage <= 0) { return; }
388 if (this.owner.isshielded)
390 // this is protected by a shield, so ignore the damage
391 if (time > this.pain_finished)
392 if (IS_PLAYER(attacker))
394 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
395 this.pain_finished = time + 1;
396 attacker.typehitsound += 1; // play both sounds (shield is way too quiet)
402 if(IS_PLAYER(attacker))
403 if(time - ons_notification_time[this.team] > 10)
405 play2team(this.team, SND(ONS_CONTROLPOINT_UNDERATTACK));
406 ons_notification_time[this.team] = time;
409 this.health = this.health - damage;
410 if(this.owner.iscaptured)
411 WaypointSprite_UpdateHealth(this.owner.sprite, this.health);
413 WaypointSprite_UpdateBuildFinished(this.owner.sprite, time + (this.max_health - this.health) / (this.count / ONS_CP_THINKRATE));
414 this.pain_finished = time + 1;
415 // particles on every hit
416 pointparticles(EFFECT_SPARKS, hitloc, force*-1, 1);
419 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE+0.3, ATTEN_NORM);
421 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE+0.3, ATTEN_NORM);
425 sound(this, CH_TRIGGER, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
426 pointparticles(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
427 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_CPDESTROYED), this.owner.message, attacker.netname);
429 GameRules_scoring_add(attacker, ONS_TAKES, 1);
430 GameRules_scoring_add(attacker, SCORE, 10);
432 this.owner.goalentity = NULL;
433 this.owner.islinked = false;
434 this.owner.iscaptured = false;
436 this.owner.colormap = 1024;
438 WaypointSprite_UpdateMaxHealth(this.owner.sprite, 0);
440 onslaught_updatelinks();
442 // Use targets now (somebody make sure this is in the right place..)
443 SUB_UseTargets(this.owner, this, NULL);
445 this.owner.waslinked = this.owner.islinked;
446 if(this.owner.model != "models/onslaught/controlpoint_pad.md3")
447 setmodel_fixsize(this.owner, MDL_ONS_CP_PAD1);
448 //setsize(this, '-32 -32 0', '32 32 8');
453 this.SendFlags |= CPSF_STATUS;
456 void ons_ControlPoint_Icon_Think(entity this)
458 this.nextthink = time + ONS_CP_THINKRATE;
460 if(autocvar_g_onslaught_cp_proxydecap)
462 int _enemy_count = 0;
463 int _friendly_count = 0;
465 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it), {
466 if(vdist(it.origin - this.origin, <, autocvar_g_onslaught_cp_proxydecap_distance))
468 if(SAME_TEAM(it, this))
475 _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
476 _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
478 this.health = bound(0, this.health + (_friendly_count - _enemy_count), this.max_health);
479 this.SendFlags |= CPSF_STATUS;
482 ons_ControlPoint_Icon_Damage(this, this, this, 1, 0, this.origin, '0 0 0');
487 if (time > this.pain_finished + 5)
489 if(this.health < this.max_health)
491 this.health = this.health + this.count;
492 if (this.health >= this.max_health)
493 this.health = this.max_health;
494 WaypointSprite_UpdateHealth(this.owner.sprite, this.health);
498 if(this.owner.islinked != this.owner.waslinked)
500 // unteam the spawnpoint if needed
501 int t = this.owner.team;
502 if(!this.owner.islinked)
505 SUB_UseTargets(this.owner, this, NULL);
509 this.owner.waslinked = this.owner.islinked;
513 if(random() < 0.6 - this.health / this.max_health)
515 Send_Effect(EFFECT_ELECTRIC_SPARKS, this.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
518 sound(this, CH_PAIN, SND_ONS_SPARK1, VOL_BASE, ATTEN_NORM);
519 else if (random() > 0.5)
520 sound(this, CH_PAIN, SND_ONS_SPARK2, VOL_BASE, ATTEN_NORM);
524 void ons_ControlPoint_Icon_BuildThink(entity this)
528 this.nextthink = time + ONS_CP_THINKRATE;
530 // only do this if there is power
531 a = ons_ControlPoint_CanBeLinked(this.owner, this.owner.team);
535 this.health = this.health + this.count;
537 this.SendFlags |= CPSF_STATUS;
539 if (this.health >= this.max_health)
541 this.health = this.max_health;
542 this.count = autocvar_g_onslaught_cp_regen * ONS_CP_THINKRATE; // slow repair rate from now on
543 setthink(this, ons_ControlPoint_Icon_Think);
544 sound(this, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILT, VOL_BASE, ATTEN_NORM);
545 this.owner.iscaptured = true;
546 this.solid = SOLID_BBOX;
548 Send_Effect(EFFECT_CAP(this.owner.team), this.owner.origin, '0 0 0', 1);
550 WaypointSprite_UpdateMaxHealth(this.owner.sprite, this.max_health);
551 WaypointSprite_UpdateHealth(this.owner.sprite, this.health);
553 if(IS_PLAYER(this.owner.ons_toucher))
555 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ONSLAUGHT_CAPTURE, this.owner.ons_toucher.netname, this.owner.message);
556 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);
557 Send_Notification(NOTIF_ONE, this.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE, this.owner.message);
558 GameRules_scoring_add(this.owner.ons_toucher, ONS_CAPS, 1);
559 GameRules_scoring_add_team(this.owner.ons_toucher, SCORE, 10);
562 this.owner.ons_toucher = NULL;
564 onslaught_updatelinks();
566 // Use targets now (somebody make sure this is in the right place..)
567 SUB_UseTargets(this.owner, this, NULL);
569 this.SendFlags |= CPSF_SETUP;
571 if(this.owner.model != MDL_ONS_CP_PAD2.model_str())
572 setmodel_fixsize(this.owner, MDL_ONS_CP_PAD2);
574 if(random() < 0.9 - this.health / this.max_health)
575 Send_Effect(EFFECT_RAGE, this.origin + 10 * randomvec(), '0 0 -1', 1);
578 void onslaught_controlpoint_icon_link(entity e, void(entity this) spawnproc);
580 void ons_ControlPoint_Icon_Spawn(entity cp, entity player)
582 entity e = new(onslaught_controlpoint_icon);
584 setsize(e, CPICON_MIN, CPICON_MAX);
585 setorigin(e, cp.origin + CPICON_OFFSET);
588 e.max_health = autocvar_g_onslaught_cp_health;
589 e.health = autocvar_g_onslaught_cp_buildhealth;
591 e.takedamage = DAMAGE_AIM;
593 IL_PUSH(g_bot_targets, e);
594 e.event_damage = ons_ControlPoint_Icon_Damage;
595 e.team = player.team;
596 e.colormap = 1024 + (e.team - 1) * 17;
597 e.count = (e.max_health - e.health) * ONS_CP_THINKRATE / autocvar_g_onslaught_cp_buildtime; // how long it takes to build
599 sound(e, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILD, VOL_BASE, ATTEN_NORM);
603 cp.colormap = e.colormap;
605 Send_Effect(EFFECT_FLAG_TOUCH(player.team), e.origin, '0 0 0', 1);
607 WaypointSprite_UpdateBuildFinished(cp.sprite, time + (e.max_health - e.health) / (e.count / ONS_CP_THINKRATE));
608 WaypointSprite_UpdateRule(cp.sprite,cp.team,SPRITERULE_TEAMPLAY);
609 cp.sprite.SendFlags |= 16;
611 onslaught_controlpoint_icon_link(e, ons_ControlPoint_Icon_BuildThink);
614 entity ons_ControlPoint_Waypoint(entity e)
618 int a = ons_ControlPoint_Attackable(e, e.team);
620 if(a == -2) { return WP_OnsCPDefend; } // defend now
621 if(a == -1 || a == 1 || a == 2) { return WP_OnsCP; } // touch
622 if(a == 3 || a == 4) { return WP_OnsCPAttack; } // attack
630 void ons_ControlPoint_UpdateSprite(entity e)
632 entity s1 = ons_ControlPoint_Waypoint(e);
633 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
636 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));
638 if(e.lastteam != e.team + 2 || e.lastshielded != sh || e.iscaptured != e.lastcaptured)
640 if(e.iscaptured) // don't mess up build bars!
644 WaypointSprite_UpdateMaxHealth(e.sprite, 0);
648 WaypointSprite_UpdateMaxHealth(e.sprite, e.goalentity.max_health);
649 WaypointSprite_UpdateHealth(e.sprite, e.goalentity.health);
655 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, false));
657 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
662 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, false));
664 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
666 WaypointSprite_Ping(e.sprite);
668 e.lastteam = e.team + 2;
670 e.lastcaptured = e.iscaptured;
674 void ons_ControlPoint_Touch(entity this, entity toucher)
678 if(IS_VEHICLE(toucher) && toucher.owner)
679 if(autocvar_g_onslaught_allow_vehicle_touch)
680 toucher = toucher.owner;
684 if(!IS_PLAYER(toucher)) { return; }
685 if(STAT(FROZEN, toucher)) { return; }
686 if(IS_DEAD(toucher)) { return; }
688 if ( SAME_TEAM(this,toucher) )
689 if ( this.iscaptured )
691 if(time <= toucher.teleport_antispam)
692 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT_ANTISPAM, rint(toucher.teleport_antispam - time));
694 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
697 attackable = ons_ControlPoint_Attackable(this, toucher.team);
698 if(attackable != 2 && attackable != 4)
700 // we've verified that this player has a legitimate claim to this point,
701 // so start building the captured point icon (which only captures this
702 // point if it successfully builds without being destroyed first)
703 ons_ControlPoint_Icon_Spawn(this, toucher);
705 this.ons_toucher = toucher;
707 onslaught_updatelinks();
710 void ons_ControlPoint_Think(entity this)
712 this.nextthink = time + ONS_CP_THINKRATE;
713 CSQCMODEL_AUTOUPDATE(this);
716 void ons_ControlPoint_Reset(entity this)
719 delete(this.goalentity);
721 this.goalentity = NULL;
723 this.colormap = 1024;
724 this.iscaptured = false;
725 this.islinked = false;
726 this.isshielded = true;
727 setthink(this, ons_ControlPoint_Think);
728 this.ons_toucher = NULL;
729 this.nextthink = time + ONS_CP_THINKRATE;
730 setmodel_fixsize(this, MDL_ONS_CP_PAD1);
732 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
733 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
735 onslaught_updatelinks();
737 SUB_UseTargets(this, this, NULL); // to reset the structures, playerspawns etc.
739 CSQCMODEL_AUTOUPDATE(this);
742 void ons_DelayedControlPoint_Setup(entity this)
744 onslaught_updatelinks();
746 // captureshield setup
747 ons_CaptureShield_Spawn(this, false);
749 CSQCMODEL_AUTOINIT(this);
752 void ons_ControlPoint_Setup(entity cp)
755 cp.ons_worldcpnext = ons_worldcplist; // link control point into ons_worldcplist
756 ons_worldcplist = cp;
758 cp.netname = "Control point";
760 cp.solid = SOLID_BBOX;
761 set_movetype(cp, MOVETYPE_NONE);
762 settouch(cp, ons_ControlPoint_Touch);
763 setthink(cp, ons_ControlPoint_Think);
764 cp.nextthink = time + ONS_CP_THINKRATE;
765 cp.reset = ons_ControlPoint_Reset;
767 cp.iscaptured = false;
769 cp.isshielded = true;
771 if(cp.message == "") { cp.message = "a"; }
774 setmodel_fixsize(cp, MDL_ONS_CP_PAD1);
776 // control point placement
777 if((cp.spawnflags & 1) || cp.noalign) // don't drop to floor, just stay at fixed location
780 set_movetype(cp, MOVETYPE_NONE);
782 else // drop to floor, automatically find a platform and set that as spawn origin
784 setorigin(cp, cp.origin + '0 0 20');
787 set_movetype(cp, MOVETYPE_TOSS);
791 WaypointSprite_SpawnFixed(WP_Null, cp.origin + CPGEN_WAYPOINT_OFFSET, cp, sprite, RADARICON_NONE);
792 WaypointSprite_UpdateRule(cp.sprite, cp.team, SPRITERULE_TEAMPLAY);
794 InitializeEntity(cp, ons_DelayedControlPoint_Setup, INITPRIO_SETLOCATION);
798 // =========================
799 // Main Generator Functions
800 // =========================
802 entity ons_Generator_Waypoint(entity e)
805 return WP_OnsGenShielded;
809 void ons_Generator_UpdateSprite(entity e)
811 entity s1 = ons_Generator_Waypoint(e);
812 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
814 if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
816 e.lastteam = e.team + 2;
817 e.lastshielded = e.isshielded;
821 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, false));
823 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
828 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, false));
830 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
832 WaypointSprite_Ping(e.sprite);
836 void ons_camSetup(entity this)
839 vector ang = '0 0 0';
840 vector best_ang = '0 0 0';
841 float best_trace_fraction = 0;
844 dir = vec2(cos(ang.y * DEG2RAD), sin(ang.y * DEG2RAD));
846 traceline(this.origin, this.origin - dir, MOVE_WORLDONLY, this);
847 if(trace_fraction > best_trace_fraction)
849 best_trace_fraction = trace_fraction;
851 if(trace_fraction == 1)
858 cam.origin = this.origin;
859 setorigin(cam, cam.origin);
860 cam.angles = best_ang;
861 Net_LinkEntity(cam, false, 0, clientcamera_send);
863 FOREACH_CLIENT(true, it.clientcamera = cam;);
865 WriteByte(MSG_ALL, SVC_SETVIEWANGLES);
866 WriteAngle(MSG_ALL, cam.angles_x);
867 WriteAngle(MSG_ALL, cam.angles_y);
868 WriteAngle(MSG_ALL, cam.angles_z);
871 void ons_GeneratorDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
873 if(damage <= 0) return;
874 if(warmup_stage || game_stopped) return;
875 if(!round_handler_IsRoundStarted()) return;
877 if (attacker != this)
881 // generator is protected by a shield, so ignore the damage
882 if (time > this.pain_finished)
883 if (IS_PLAYER(attacker))
885 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
886 attacker.typehitsound += 1;
887 this.pain_finished = time + 1;
891 if (time > this.pain_finished)
893 this.pain_finished = time + 10;
894 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && SAME_TEAM(it, this), Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK));
895 play2team(this.team, SND(ONS_GENERATOR_UNDERATTACK));
898 this.health = this.health - damage;
899 WaypointSprite_UpdateHealth(this.sprite, this.health);
900 // choose an animation frame based on health
901 this.frame = 10 * bound(0, (1 - this.health / this.max_health), 1);
902 // see if the generator is still functional, or dying
905 this.lasthealth = this.health;
909 if (attacker == this)
910 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME));
913 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED));
914 GameRules_scoring_add(attacker, SCORE, 100);
916 this.iscaptured = false;
917 this.islinked = false;
918 this.isshielded = false;
919 this.takedamage = DAMAGE_NO; // can't be hurt anymore
920 this.event_damage = func_null; // won't do anything if hurt
921 this.count = 0; // reset counter
922 setthink(this, func_null);
924 //this.think(); // do the first explosion now
926 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
927 WaypointSprite_Ping(this.sprite);
928 //WaypointSprite_Kill(this.sprite); // can't do this yet, code too poor
930 onslaught_updatelinks();
935 // Throw some flaming gibs on damage, more damage = more chance for gib
936 if(random() < damage/220)
938 sound(this, CH_TRIGGER, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
942 // particles on every hit
943 Send_Effect(EFFECT_SPARKS, hitloc, force * -1, 1);
947 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE, ATTEN_NORM);
949 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE, ATTEN_NORM);
952 this.SendFlags |= GSF_STATUS;
955 void ons_GeneratorThink(entity this)
957 this.nextthink = time + GEN_THINKRATE;
960 if(!this.isshielded && this.wait < time)
962 this.wait = time + 5;
963 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
964 if(SAME_TEAM(it, this))
966 Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM);
967 soundto(MSG_ONE, it, CHAN_AUTO, SND(KH_ALARM), VOL_BASE, ATTEN_NONE); // FIXME: unique sound?
970 Send_Notification(NOTIF_ONE, it, MSG_CENTER, APP_TEAM_NUM(this.team, CENTER_ONS_NOTSHIELDED));
976 void ons_GeneratorReset(entity this)
978 this.team = this.team_saved;
979 this.lasthealth = this.max_health = this.health = autocvar_g_onslaught_gen_health;
980 this.takedamage = DAMAGE_AIM;
981 this.bot_attack = true;
982 if(!IL_CONTAINS(g_bot_targets, this))
983 IL_PUSH(g_bot_targets, this);
984 this.iscaptured = true;
985 this.islinked = true;
986 this.isshielded = true;
987 this.event_damage = ons_GeneratorDamage;
988 setthink(this, ons_GeneratorThink);
989 this.nextthink = time + GEN_THINKRATE;
991 Net_LinkEntity(this, false, 0, generator_send);
993 this.SendFlags = GSF_SETUP; // just incase
994 this.SendFlags |= GSF_STATUS;
996 WaypointSprite_UpdateMaxHealth(this.sprite, this.max_health);
997 WaypointSprite_UpdateHealth(this.sprite, this.health);
998 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
1000 onslaught_updatelinks();
1003 void ons_DelayedGeneratorSetup(entity this)
1006 waypoint_spawnforitem_force(this, this.origin);
1007 this.nearestwaypointtimeout = 0; // activate waypointing again
1008 this.bot_basewaypoint = this.nearestwaypoint;
1010 // captureshield setup
1011 ons_CaptureShield_Spawn(this, true);
1013 onslaught_updatelinks();
1015 Net_LinkEntity(this, false, 0, generator_send);
1019 void onslaught_generator_touch(entity this, entity toucher)
1021 if ( IS_PLAYER(toucher) )
1022 if ( SAME_TEAM(this,toucher) )
1023 if ( this.iscaptured )
1025 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
1029 void ons_GeneratorSetup(entity gen) // called when spawning a generator entity on the map as a spawnfunc
1032 int teamnumber = gen.team;
1035 gen.ons_worldgeneratornext = ons_worldgeneratorlist; // link generator into ons_worldgeneratorlist
1036 ons_worldgeneratorlist = gen;
1038 gen.netname = sprintf("%s generator", Team_ColoredFullName(teamnumber));
1039 gen.classname = "onslaught_generator";
1040 gen.solid = SOLID_BBOX;
1041 gen.team_saved = teamnumber;
1042 IL_PUSH(g_saved_team, gen);
1043 set_movetype(gen, MOVETYPE_NONE);
1044 gen.lasthealth = gen.max_health = gen.health = autocvar_g_onslaught_gen_health;
1045 gen.takedamage = DAMAGE_AIM;
1046 gen.bot_attack = true;
1047 IL_PUSH(g_bot_targets, gen);
1048 gen.event_damage = ons_GeneratorDamage;
1049 gen.reset = ons_GeneratorReset;
1050 setthink(gen, ons_GeneratorThink);
1051 gen.nextthink = time + GEN_THINKRATE;
1052 gen.iscaptured = true;
1053 gen.islinked = true;
1054 gen.isshielded = true;
1055 settouch(gen, onslaught_generator_touch);
1058 // model handled by CSQC
1059 setsize(gen, GENERATOR_MIN, GENERATOR_MAX);
1060 setorigin(gen, (gen.origin + CPGEN_SPAWN_OFFSET));
1061 gen.colormap = 1024 + (teamnumber - 1) * 17;
1063 // generator placement
1067 WaypointSprite_SpawnFixed(WP_Null, gen.origin + CPGEN_WAYPOINT_OFFSET, gen, sprite, RADARICON_NONE);
1068 WaypointSprite_UpdateRule(gen.sprite, gen.team, SPRITERULE_TEAMPLAY);
1069 WaypointSprite_UpdateMaxHealth(gen.sprite, gen.max_health);
1070 WaypointSprite_UpdateHealth(gen.sprite, gen.health);
1072 InitializeEntity(gen, ons_DelayedGeneratorSetup, INITPRIO_SETLOCATION);
1080 int total_generators;
1081 void Onslaught_count_generators()
1084 total_generators = redowned = blueowned = yellowowned = pinkowned = 0;
1085 for(e = ons_worldgeneratorlist; e; e = e.ons_worldgeneratornext)
1088 redowned += (e.team == NUM_TEAM_1 && e.health > 0);
1089 blueowned += (e.team == NUM_TEAM_2 && e.health > 0);
1090 yellowowned += (e.team == NUM_TEAM_3 && e.health > 0);
1091 pinkowned += (e.team == NUM_TEAM_4 && e.health > 0);
1095 int Onslaught_GetWinnerTeam()
1097 int winner_team = 0;
1099 winner_team = NUM_TEAM_1;
1102 if(winner_team) return 0;
1103 winner_team = NUM_TEAM_2;
1107 if(winner_team) return 0;
1108 winner_team = NUM_TEAM_3;
1112 if(winner_team) return 0;
1113 winner_team = NUM_TEAM_4;
1117 return -1; // no generators left?
1120 void nades_Clear(entity e);
1122 #define ONS_OWNED_GENERATORS() ((redowned > 0) + (blueowned > 0) + (yellowowned > 0) + (pinkowned > 0))
1123 #define ONS_OWNED_GENERATORS_OK() (ONS_OWNED_GENERATORS() > 1)
1124 bool Onslaught_CheckWinner()
1126 if ((autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60) || (round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0))
1128 ons_stalemate = true;
1130 if (!wpforenemy_announced)
1132 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT);
1133 sound(NULL, CH_INFO, SND_ONS_GENERATOR_DECAY, VOL_BASE, ATTEN_NONE);
1135 wpforenemy_announced = true;
1138 entity tmp_entity; // temporary entity
1140 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext) if(time >= tmp_entity.ons_overtime_damagedelay)
1142 // tmp_entity.max_health / 300 gives 5 minutes of overtime.
1143 // control points reduce the overtime duration.
1146 for(e = ons_worldcplist; e; e = e.ons_worldcpnext)
1148 if(DIFF_TEAM(e, tmp_entity))
1153 if(autocvar_g_campaign && autocvar__campaign_testrun)
1154 d = d * tmp_entity.max_health;
1156 d = d * tmp_entity.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
1158 Damage(tmp_entity, tmp_entity, tmp_entity, d, DEATH_HURTTRIGGER.m_id, tmp_entity.origin, '0 0 0');
1160 tmp_entity.sprite.SendFlags |= 16;
1162 tmp_entity.ons_overtime_damagedelay = time + 1;
1165 else { wpforenemy_announced = false; ons_stalemate = false; }
1167 Onslaught_count_generators();
1169 if(ONS_OWNED_GENERATORS_OK())
1172 int winner_team = Onslaught_GetWinnerTeam();
1176 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
1177 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
1178 TeamScore_AddToTeam(winner_team, ST_ONS_CAPS, +1);
1180 else if(winner_team == -1)
1182 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_TIED);
1183 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_TIED);
1186 ons_stalemate = false;
1188 play2all(SND(CTF_CAPTURE(winner_team)));
1190 round_handler_Init(7, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
1192 FOREACH_CLIENT(IS_PLAYER(it), {
1193 STAT(ROUNDLOST, it) = true;
1194 it.player_blocked = true;
1199 game_stopped = true;
1203 bool Onslaught_CheckPlayers()
1208 void Onslaught_RoundStart()
1211 FOREACH_CLIENT(IS_PLAYER(it), it.player_blocked = false);
1213 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1214 tmp_entity.sprite.SendFlags |= 16;
1216 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1217 tmp_entity.sprite.SendFlags |= 16;
1225 // NOTE: LEGACY CODE, needs to be re-written!
1227 void havocbot_goalrating_ons_offenseitems(entity this, float ratingscale, vector org, float sradius)
1229 bool needarmor = false, needweapons = false;
1231 // Needs armor/health?
1237 FOREACH(Weapons, it != WEP_Null, {
1238 if(this.weapons & (it.m_wepset))
1246 if(!needweapons && !needarmor)
1249 LOG_DEBUG(this.netname, " needs weapons ", ftos(needweapons));
1250 LOG_DEBUG(this.netname, " needs armor ", ftos(needarmor));
1252 // See what is around
1253 IL_EACH(g_items, it.bot_pickup,
1255 // gather health and armor only
1257 if ( ((it.health || it.armorvalue) && needarmor) || (it.weapons && needweapons ) )
1258 if (vdist(it.origin - org, <, sradius))
1260 int t = it.bot_pickupevalfunc(this, it);
1262 navigation_routerating(this, it, t * ratingscale, 500);
1267 void havocbot_role_ons_setrole(entity this, int role)
1269 LOG_DEBUG(this.netname," switched to ");
1272 case HAVOCBOT_ONS_ROLE_DEFENSE:
1273 LOG_DEBUG("defense");
1274 this.havocbot_role = havocbot_role_ons_defense;
1275 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE;
1276 this.havocbot_role_timeout = 0;
1278 case HAVOCBOT_ONS_ROLE_ASSISTANT:
1279 LOG_DEBUG("assistant");
1280 this.havocbot_role = havocbot_role_ons_assistant;
1281 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT;
1282 this.havocbot_role_timeout = 0;
1284 case HAVOCBOT_ONS_ROLE_OFFENSE:
1285 LOG_DEBUG("offense");
1286 this.havocbot_role = havocbot_role_ons_offense;
1287 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE;
1288 this.havocbot_role_timeout = 0;
1294 void havocbot_goalrating_ons_controlpoints_attack(entity this, float ratingscale)
1296 entity cp, cp1, cp2, best, wp;
1297 float radius, bestvalue;
1301 // Filter control points
1302 for(cp2 = ons_worldcplist; cp2; cp2 = cp2.ons_worldcpnext)
1305 cp2.wpconsidered = false;
1310 // Ignore owned controlpoints
1311 if(!((cp2.aregensneighbor & BIT(this.team)) || (cp2.arecpsneighbor & BIT(this.team))))
1314 // Count team mates interested in this control point
1315 // (easier and cleaner than keeping counters per cp and teams)
1316 FOREACH_CLIENT(IS_PLAYER(it), {
1317 if(SAME_TEAM(it, this))
1318 if(it.havocbot_role_flags & HAVOCBOT_ONS_ROLE_OFFENSE)
1319 if(it.havocbot_ons_target == cp2)
1323 // NOTE: probably decrease the cost of attackable control points
1325 cp2.wpconsidered = true;
1328 // We'll consider only the best case
1329 bestvalue = 99999999999;
1331 for(cp1 = ons_worldcplist; cp1; cp1 = cp1.ons_worldcpnext)
1333 if (!cp1.wpconsidered)
1336 if(cp1.wpcost<bestvalue)
1338 bestvalue = cp1.wpcost;
1340 this.havocbot_ons_target = cp1;
1347 LOG_DEBUG(this.netname, " chose cp ranked ", ftos(bestvalue));
1351 // Should be attacked
1352 // Rate waypoints near it
1355 bestvalue = 99999999999;
1356 for(radius=0; radius<1000 && !found; radius+=500)
1358 for(wp=findradius(cp.origin,radius); wp; wp=wp.chain)
1360 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
1361 if(wp.classname=="waypoint")
1362 if(checkpvs(wp.origin,cp))
1365 if(wp.cnt<bestvalue)
1376 navigation_routerating(this, best, ratingscale, 10000);
1379 this.havocbot_attack_time = 0;
1380 if(checkpvs(this.origin + this.view_ofs, cp))
1381 if(checkpvs(this.origin + this.view_ofs, best))
1382 this.havocbot_attack_time = time + 2;
1386 navigation_routerating(this, cp, ratingscale, 10000);
1388 LOG_DEBUG(this.netname, " found an attackable controlpoint at ", vtos(cp.origin));
1392 // Should be touched
1393 LOG_DEBUG(this.netname, " found a touchable controlpoint at ", vtos(cp.origin));
1396 // Look for auto generated waypoint
1397 if (!bot_waypoints_for_items)
1398 for (wp = findradius(cp.origin,100); wp; wp = wp.chain)
1400 if(wp.classname=="waypoint")
1402 navigation_routerating(this, wp, ratingscale, 10000);
1407 // Nothing found, rate the controlpoint itself
1409 navigation_routerating(this, cp, ratingscale, 10000);
1413 bool havocbot_goalrating_ons_generator_attack(entity this, float ratingscale)
1415 entity g, wp, bestwp;
1419 for(g = ons_worldgeneratorlist; g; g = g.ons_worldgeneratornext)
1421 if(SAME_TEAM(g, this) || g.isshielded)
1424 // Should be attacked
1425 // Rate waypoints near it
1430 for(wp=findradius(g.origin,400); wp; wp=wp.chain)
1432 if(wp.classname=="waypoint")
1433 if(checkpvs(wp.origin,g))
1446 LOG_DEBUG("waypoints found around generator");
1447 navigation_routerating(this, bestwp, ratingscale, 10000);
1450 this.havocbot_attack_time = 0;
1451 if(checkpvs(this.origin + this.view_ofs, g))
1452 if(checkpvs(this.origin + this.view_ofs, bestwp))
1453 this.havocbot_attack_time = time + 5;
1459 LOG_DEBUG("generator found without waypoints around");
1460 // if there aren't waypoints near the generator go straight to it
1461 navigation_routerating(this, g, ratingscale, 10000);
1462 this.havocbot_attack_time = 0;
1469 void havocbot_role_ons_offense(entity this)
1473 this.havocbot_attack_time = 0;
1474 havocbot_ons_reset_role(this);
1478 // Set the role timeout if necessary
1479 if (!this.havocbot_role_timeout)
1480 this.havocbot_role_timeout = time + 120;
1482 if (time > this.havocbot_role_timeout)
1484 havocbot_ons_reset_role(this);
1488 if(this.havocbot_attack_time>time)
1491 if (this.bot_strategytime < time)
1493 navigation_goalrating_start(this);
1494 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
1495 if(!havocbot_goalrating_ons_generator_attack(this, 20000))
1496 havocbot_goalrating_ons_controlpoints_attack(this, 20000);
1497 havocbot_goalrating_ons_offenseitems(this, 10000, this.origin, 10000);
1498 navigation_goalrating_end(this);
1500 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
1504 void havocbot_role_ons_assistant(entity this)
1506 havocbot_ons_reset_role(this);
1509 void havocbot_role_ons_defense(entity this)
1511 havocbot_ons_reset_role(this);
1514 void havocbot_ons_reset_role(entity this)
1519 this.havocbot_ons_target = NULL;
1521 // TODO: Defend control points or generator if necessary
1523 havocbot_role_ons_setrole(this, HAVOCBOT_ONS_ROLE_OFFENSE);
1528 * Find control point or generator owned by the same team self which is nearest to pos
1529 * if max_dist is positive, only control points within this range will be considered
1531 entity ons_Nearest_ControlPoint(entity this, vector pos, float max_dist)
1533 entity closest_target = NULL;
1534 for(entity cp = ons_worldcplist; cp; cp = cp.ons_worldcpnext)
1536 if(SAME_TEAM(cp, this))
1538 if(max_dist <= 0 || vdist(cp.origin - pos, <=, max_dist))
1539 if(vlen2(cp.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
1540 closest_target = cp;
1542 for(entity gen = ons_worldgeneratorlist; gen; gen = gen.ons_worldgeneratornext)
1544 if(SAME_TEAM(gen, this))
1545 if(max_dist <= 0 || vdist(gen.origin - pos, <, max_dist))
1546 if(vlen2(gen.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
1547 closest_target = gen;
1550 return closest_target;
1554 * Find control point or generator owned by the same team self which is nearest to pos
1555 * if max_dist is positive, only control points within this range will be considered
1556 * This function only check distances on the XY plane, disregarding Z
1558 entity ons_Nearest_ControlPoint_2D(entity this, vector pos, float max_dist)
1560 entity closest_target = NULL;
1562 float smallest_distance = 0, distance;
1564 for(entity cp = ons_worldcplist; cp; cp = cp.ons_worldcpnext)
1566 delta = cp.origin - pos;
1568 distance = vlen(delta);
1570 if(SAME_TEAM(cp, this))
1572 if(max_dist <= 0 || distance <= max_dist)
1573 if(closest_target == NULL || distance <= smallest_distance )
1575 closest_target = cp;
1576 smallest_distance = distance;
1579 for(entity gen = ons_worldgeneratorlist; gen; gen = gen.ons_worldgeneratornext)
1581 delta = gen.origin - pos;
1583 distance = vlen(delta);
1585 if(SAME_TEAM(gen, this))
1586 if(max_dist <= 0 || distance <= max_dist)
1587 if(closest_target == NULL || distance <= smallest_distance )
1589 closest_target = gen;
1590 smallest_distance = distance;
1594 return closest_target;
1597 * find the number of control points and generators in the same team as this
1599 int ons_Count_SelfControlPoints(entity this)
1602 for(entity cp = ons_worldcplist; cp; cp = cp.ons_worldcpnext)
1604 if(SAME_TEAM(cp, this))
1608 for(entity gen = ons_worldgeneratorlist; gen; gen = gen.ons_worldgeneratornext)
1610 if(SAME_TEAM(gen, this))
1617 * Teleport player to a random position near tele_target
1618 * if tele_effects is true, teleport sound+particles are created
1619 * return false on failure
1621 bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effects)
1629 // narrow the range for each iteration to increase chances that a spawnpoint
1630 // can be found even if there's little room around the control point
1631 float iteration_scale = 1;
1632 for(i = 0; i < 16; ++i)
1634 iteration_scale -= i / 16;
1635 theta = random() * 2 * M_PI;
1639 loc *= random() * range * iteration_scale;
1641 loc += tele_target.origin + '0 0 128' * iteration_scale;
1643 tracebox(loc, STAT(PL_MIN, player), STAT(PL_MAX, player), loc, MOVE_NORMAL, player);
1644 if(trace_fraction == 1.0 && !trace_startsolid)
1646 traceline(tele_target.origin, loc, MOVE_NOMONSTERS, tele_target); // double check to make sure we're not spawning outside the NULL
1647 if(trace_fraction == 1.0 && !trace_startsolid)
1651 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
1652 sound (player, CH_TRIGGER, SND_TELEPORT, VOL_BASE, ATTEN_NORM);
1654 setorigin(player, loc);
1655 player.angles = '0 1 0' * ( theta * RAD2DEG + 180 );
1656 makevectors(player.angles);
1657 player.fixangle = true;
1658 player.teleport_antispam = time + autocvar_g_onslaught_teleport_wait;
1661 Send_Effect(EFFECT_TELEPORT, player.origin + v_forward * 32, '0 0 0', 1);
1674 MUTATOR_HOOKFUNCTION(ons, reset_map_global)
1676 FOREACH_CLIENT(IS_PLAYER(it), {
1677 STAT(ROUNDLOST, it) = false;
1678 it.ons_deathloc = '0 0 0';
1679 PutClientInServer(it);
1680 it.clientcamera = it;
1685 MUTATOR_HOOKFUNCTION(ons, ClientDisconnect)
1687 entity player = M_ARGV(0, entity);
1689 player.ons_deathloc = '0 0 0';
1692 MUTATOR_HOOKFUNCTION(ons, MakePlayerObserver)
1694 entity player = M_ARGV(0, entity);
1696 player.ons_deathloc = '0 0 0';
1699 MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
1701 entity player = M_ARGV(0, entity);
1703 if(!round_handler_IsRoundStarted())
1705 player.player_blocked = true;
1710 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1712 l.sprite.SendFlags |= 16;
1714 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1716 l.sprite.SendFlags |= 16;
1719 if(ons_stalemate) { Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); }
1721 if ( autocvar_g_onslaught_spawn_choose )
1722 if ( player.ons_spawn_by )
1723 if ( ons_Teleport(player,player.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) )
1725 player.ons_spawn_by = NULL;
1729 if(autocvar_g_onslaught_spawn_at_controlpoints)
1730 if(random() <= autocvar_g_onslaught_spawn_at_controlpoints_chance)
1732 float random_target = autocvar_g_onslaught_spawn_at_controlpoints_random;
1733 entity tmp_entity, closest_target = NULL;
1734 vector spawn_loc = player.ons_deathloc;
1736 // new joining player or round reset, don't bother checking
1737 if(spawn_loc == '0 0 0') { return false; }
1739 if(random_target) { RandomSelection_Init(); }
1741 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1743 if(SAME_TEAM(tmp_entity, player))
1745 RandomSelection_AddEnt(tmp_entity, 1, 1);
1746 else if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL)
1747 closest_target = tmp_entity;
1750 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1756 float iteration_scale = 1;
1757 for(i = 0; i < 10; ++i)
1759 iteration_scale -= i / 10;
1760 loc = closest_target.origin + '0 0 96' * iteration_scale;
1761 loc += ('0 1 0' * random()) * 128 * iteration_scale;
1762 tracebox(loc, STAT(PL_MIN, player), STAT(PL_MAX, player), loc, MOVE_NORMAL, player);
1763 if(trace_fraction == 1.0 && !trace_startsolid)
1765 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL
1766 if(trace_fraction == 1.0 && !trace_startsolid)
1768 setorigin(player, loc);
1769 player.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1777 if(autocvar_g_onslaught_spawn_at_generator)
1778 if(random() <= autocvar_g_onslaught_spawn_at_generator_chance)
1780 float random_target = autocvar_g_onslaught_spawn_at_generator_random;
1781 entity tmp_entity, closest_target = NULL;
1782 vector spawn_loc = player.ons_deathloc;
1784 // new joining player or round reset, don't bother checking
1785 if(spawn_loc == '0 0 0') { return false; }
1787 if(random_target) { RandomSelection_Init(); }
1789 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1792 RandomSelection_AddEnt(tmp_entity, 1, 1);
1795 if(SAME_TEAM(tmp_entity, player))
1796 if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL)
1797 closest_target = tmp_entity;
1801 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1807 float iteration_scale = 1;
1808 for(i = 0; i < 10; ++i)
1810 iteration_scale -= i / 10;
1811 loc = closest_target.origin + '0 0 128' * iteration_scale;
1812 loc += ('0 1 0' * random()) * 256 * iteration_scale;
1813 tracebox(loc, STAT(PL_MIN, player), STAT(PL_MAX, player), loc, MOVE_NORMAL, player);
1814 if(trace_fraction == 1.0 && !trace_startsolid)
1816 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL
1817 if(trace_fraction == 1.0 && !trace_startsolid)
1819 setorigin(player, loc);
1820 player.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1831 MUTATOR_HOOKFUNCTION(ons, PlayerDies)
1833 entity frag_target = M_ARGV(2, entity);
1835 frag_target.ons_deathloc = frag_target.origin;
1837 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1839 l.sprite.SendFlags |= 16;
1841 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1843 l.sprite.SendFlags |= 16;
1846 if ( autocvar_g_onslaught_spawn_choose )
1847 if ( ons_Count_SelfControlPoints(frag_target) > 1 )
1848 stuffcmd(frag_target, "qc_cmd_cl hud clickradar\n");
1853 MUTATOR_HOOKFUNCTION(ons, MonsterMove)
1855 entity mon = M_ARGV(0, entity);
1857 entity e = find(NULL, targetname, mon.target);
1862 void ons_MonsterSpawn_Delayed(entity this)
1864 entity own = this.owner;
1866 if(!own) { delete(this); return; }
1870 entity e = find(NULL, target, own.targetname);
1875 own.use(own, e, NULL);
1882 MUTATOR_HOOKFUNCTION(ons, MonsterSpawn)
1884 entity mon = M_ARGV(0, entity);
1888 InitializeEntity(e, ons_MonsterSpawn_Delayed, INITPRIO_FINDTARGET);
1891 void ons_TurretSpawn_Delayed(entity this)
1893 entity own = this.owner;
1895 if(!own) { delete(this); return; }
1899 entity e = find(NULL, target, own.targetname);
1903 own.active = ACTIVE_NOT;
1905 own.use(own, e, NULL);
1912 MUTATOR_HOOKFUNCTION(ons, TurretSpawn)
1914 entity turret = M_ARGV(0, entity);
1918 InitializeEntity(e, ons_TurretSpawn_Delayed, INITPRIO_FINDTARGET);
1923 MUTATOR_HOOKFUNCTION(ons, HavocBot_ChooseRole)
1925 entity bot = M_ARGV(0, entity);
1927 havocbot_ons_reset_role(bot);
1931 MUTATOR_HOOKFUNCTION(ons, CheckAllowedTeams)
1933 // onslaught is special
1934 for(entity tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1936 switch(tmp_entity.team)
1938 case NUM_TEAM_1: c1 = 0; break;
1939 case NUM_TEAM_2: c2 = 0; break;
1940 case NUM_TEAM_3: c3 = 0; break;
1941 case NUM_TEAM_4: c4 = 0; break;
1948 MUTATOR_HOOKFUNCTION(ons, SpectateCopy)
1950 entity spectatee = M_ARGV(0, entity);
1951 entity client = M_ARGV(1, entity);
1953 STAT(ROUNDLOST, client) = STAT(ROUNDLOST, spectatee); // make spectators see it too
1956 MUTATOR_HOOKFUNCTION(ons, SV_ParseClientCommand)
1958 if(MUTATOR_RETURNVALUE) // command was already handled?
1961 entity player = M_ARGV(0, entity);
1962 string cmd_name = M_ARGV(1, string);
1963 int cmd_argc = M_ARGV(2, int);
1965 if ( cmd_name == "ons_spawn" )
1967 vector pos = player.origin;
1969 pos_x = stof(argv(1));
1971 pos_y = stof(argv(2));
1973 pos_z = stof(argv(3));
1975 if ( IS_PLAYER(player) )
1977 if ( !STAT(FROZEN, player) )
1979 entity source_point = ons_Nearest_ControlPoint(player, player.origin, autocvar_g_onslaught_teleport_radius);
1981 if ( !source_point && player.health > 0 )
1983 sprint(player, "\nYou need to be next to a control point\n");
1988 entity closest_target = ons_Nearest_ControlPoint_2D(player, pos, autocvar_g_onslaught_click_radius);
1990 if ( closest_target == NULL )
1992 sprint(player, "\nNo control point found\n");
1996 if ( player.health <= 0 )
1998 player.ons_spawn_by = closest_target;
1999 player.respawn_flags = player.respawn_flags | RESPAWN_FORCE;
2003 if ( source_point == closest_target )
2005 sprint(player, "\nTeleporting to the same point\n");
2009 if ( !ons_Teleport(player,closest_target,autocvar_g_onslaught_teleport_radius,true) )
2010 sprint(player, "\nUnable to teleport there\n");
2016 sprint(player, "\nNo teleportation for you\n");
2024 MUTATOR_HOOKFUNCTION(ons, PlayerUseKey)
2026 if(MUTATOR_RETURNVALUE || game_stopped) return false;
2028 entity player = M_ARGV(0, entity);
2030 if((time > player.teleport_antispam) && (!IS_DEAD(player)) && !player.vehicle)
2032 entity source_point = ons_Nearest_ControlPoint(player, player.origin, autocvar_g_onslaught_teleport_radius);
2035 stuffcmd(player, "qc_cmd_cl hud clickradar\n");
2041 MUTATOR_HOOKFUNCTION(ons, PlayHitsound)
2043 entity frag_victim = M_ARGV(0, entity);
2045 return (frag_victim.classname == "onslaught_generator" && !frag_victim.isshielded)
2046 || (frag_victim.classname == "onslaught_controlpoint_icon" && !frag_victim.owner.isshielded);
2049 MUTATOR_HOOKFUNCTION(ons, SendWaypoint)
2051 entity wp = M_ARGV(0, entity);
2052 entity to = M_ARGV(1, entity);
2053 int sf = M_ARGV(2, int);
2054 int wp_flag = M_ARGV(3, int);
2058 if(wp.owner.classname == "onslaught_controlpoint")
2060 entity wp_owner = wp.owner;
2061 entity e = WaypointSprite_getviewentity(to);
2062 if(SAME_TEAM(e, wp_owner) && wp_owner.goalentity.health >= wp_owner.goalentity.max_health) { wp_flag |= 2; }
2063 if(!ons_ControlPoint_Attackable(wp_owner, e.team)) { wp_flag |= 2; }
2065 if(wp.owner.classname == "onslaught_generator")
2067 entity wp_owner = wp.owner;
2068 if(wp_owner.isshielded && wp_owner.health >= wp_owner.max_health) { wp_flag |= 2; }
2069 if(wp_owner.health <= 0) { wp_flag |= 2; }
2073 M_ARGV(3, int) = wp_flag;
2076 MUTATOR_HOOKFUNCTION(ons, TurretValidateTarget)
2078 entity turret_target = M_ARGV(1, entity);
2080 if(substring(turret_target.classname, 0, 10) == "onslaught_") // don't attack onslaught targets, that's the player's job!
2082 M_ARGV(3, float) = -3;
2089 MUTATOR_HOOKFUNCTION(ons, TurretThink)
2091 entity turret = M_ARGV(0, entity);
2093 // ONS uses somewhat backwards linking.
2096 entity e = find(NULL, targetname, turret.target);
2098 turret.team = e.team;
2101 if(turret.team != turret.tur_head.team)
2102 turret_respawn(turret);
2110 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
2111 Link between control points.
2113 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.
2116 "target" - first control point.
2117 "target2" - second control point.
2119 spawnfunc(onslaught_link)
2121 if(!g_onslaught) { delete(this); return; }
2123 if (this.target == "" || this.target2 == "")
2124 objerror(this, "target and target2 must be set\n");
2126 this.ons_worldlinknext = ons_worldlinklist; // link into ons_worldlinklist
2127 ons_worldlinklist = this;
2129 InitializeEntity(this, ons_DelayedLinkSetup, INITPRIO_FINDTARGET);
2130 Net_LinkEntity(this, false, 0, ons_Link_Send);
2133 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
2134 Control point. Be sure to give this enough clearance so that the shootable part has room to exist
2136 This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
2139 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2140 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
2141 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
2144 spawnfunc(onslaught_controlpoint)
2146 if(!g_onslaught) { delete(this); return; }
2148 ons_ControlPoint_Setup(this);
2151 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
2154 spawnfunc_onslaught_link entities can target this.
2157 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
2158 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2160 spawnfunc(onslaught_generator)
2162 if(!g_onslaught) { delete(this); return; }
2163 if(!this.team) { objerror(this, "team must be set"); }
2165 ons_GeneratorSetup(this);
2169 void ons_ScoreRules()
2171 CheckAllowedTeams(NULL);
2173 if(c1 >= 0) teams |= BIT(0);
2174 if(c2 >= 0) teams |= BIT(1);
2175 if(c3 >= 0) teams |= BIT(2);
2176 if(c4 >= 0) teams |= BIT(3);
2177 GameRules_scoring(teams, SFL_SORT_PRIO_PRIMARY, 0, {
2178 field_team(ST_ONS_CAPS, "destroyed", SFL_SORT_PRIO_PRIMARY);
2179 field(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
2180 field(SP_ONS_TAKES, "takes", 0);
2184 void ons_DelayedInit(entity this) // Do this check with a delay so we can wait for teams to be set up
2188 round_handler_Spawn(Onslaught_CheckPlayers, Onslaught_CheckWinner, Onslaught_RoundStart);
2189 round_handler_Init(5, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
2192 void ons_Initialize()
2195 ons_captureshield_force = autocvar_g_onslaught_shield_force;
2197 cam = new(objective_camera);
2199 InitializeEntity(NULL, ons_DelayedInit, INITPRIO_GAMETYPE);