1 #include "sv_onslaught.qh"
2 #include "sv_controlpoint.qh"
3 #include "sv_generator.qh"
7 float autocvar_g_onslaught_teleport_wait;
8 bool autocvar_g_onslaught_spawn_at_controlpoints;
9 bool autocvar_g_onslaught_spawn_at_generator;
10 float autocvar_g_onslaught_cp_proxydecap;
11 float autocvar_g_onslaught_cp_proxydecap_distance = 512;
12 float autocvar_g_onslaught_cp_proxydecap_dps = 100;
13 float autocvar_g_onslaught_spawn_at_controlpoints_chance = 0.5;
14 float autocvar_g_onslaught_spawn_at_controlpoints_random;
15 float autocvar_g_onslaught_spawn_at_generator_chance;
16 float autocvar_g_onslaught_spawn_at_generator_random;
17 float autocvar_g_onslaught_cp_buildhealth;
18 float autocvar_g_onslaught_cp_buildtime;
19 float autocvar_g_onslaught_cp_health;
20 float autocvar_g_onslaught_cp_regen;
21 float autocvar_g_onslaught_gen_health;
22 float autocvar_g_onslaught_shield_force = 100;
23 float autocvar_g_onslaught_allow_vehicle_touch;
24 float autocvar_g_onslaught_round_timelimit;
25 float autocvar_g_onslaught_warmup;
26 float autocvar_g_onslaught_teleport_radius;
27 float autocvar_g_onslaught_spawn_choose;
28 float autocvar_g_onslaught_click_radius;
30 void FixSize(entity e);
32 // =======================
33 // CaptureShield Functions
34 // =======================
36 bool ons_CaptureShield_Customize(entity this, entity client)
38 entity e = WaypointSprite_getviewentity(client);
40 if(!this.enemy.isshielded && (ons_ControlPoint_Attackable(this.enemy, e.team) > 0 || this.enemy.classname != "onslaught_controlpoint")) { return false; }
41 if(SAME_TEAM(this, e)) { return false; }
46 void ons_CaptureShield_Touch(entity this, entity toucher)
48 if(!this.enemy.isshielded && (ons_ControlPoint_Attackable(this.enemy, toucher.team) > 0 || this.enemy.classname != "onslaught_controlpoint")) { return; }
49 if(!IS_PLAYER(toucher)) { return; }
50 if(SAME_TEAM(toucher, this)) { return; }
52 vector mymid = (this.absmin + this.absmax) * 0.5;
53 vector theirmid = (toucher.absmin + toucher.absmax) * 0.5;
55 Damage(toucher, this, this, 0, DEATH_HURTTRIGGER.m_id, mymid, normalize(theirmid - mymid) * ons_captureshield_force);
57 if(IS_REAL_CLIENT(toucher))
59 play2(toucher, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
61 if(this.enemy.classname == "onslaught_generator")
62 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_GENERATOR_SHIELDED);
64 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_CONTROLPOINT_SHIELDED);
68 void ons_CaptureShield_Reset(entity this)
70 this.colormap = this.enemy.colormap;
71 this.team = this.enemy.team;
74 void ons_CaptureShield_Spawn(entity generator, bool is_generator)
76 entity shield = new(ons_captureshield);
77 IL_PUSH(g_onsshields, shield);
79 shield.enemy = generator;
80 shield.team = generator.team;
81 shield.colormap = generator.colormap;
82 shield.reset = ons_CaptureShield_Reset;
83 settouch(shield, ons_CaptureShield_Touch);
84 setcefc(shield, ons_CaptureShield_Customize);
85 shield.effects = EF_ADDITIVE;
86 set_movetype(shield, MOVETYPE_NOCLIP);
87 shield.solid = SOLID_TRIGGER;
88 shield.avelocity = '7 0 11';
90 shield.model = ((is_generator) ? "models/onslaught/generator_shield.md3" : "models/onslaught/controlpoint_shield.md3");
92 precache_model(shield.model);
93 setorigin(shield, generator.origin);
94 _setmodel(shield, shield.model);
95 setsize(shield, shield.scale * shield.mins, shield.scale * shield.maxs);
103 void setmodel_fixsize(entity e, Model m)
109 void onslaught_updatelinks()
112 // first check if the game has ended
113 LOG_DEBUG("--- updatelinks ---");
114 // mark generators as being shielded and networked
115 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
118 LOG_DEBUG(etos(l), " (generator) belongs to team ", ftos(l.team));
120 LOG_DEBUG(etos(l), " (generator) is destroyed");
121 l.islinked = l.iscaptured;
122 l.isshielded = l.iscaptured;
123 l.sprite.SendFlags |= 16;
125 // mark points as shielded and not networked
126 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
131 for(i = 0; i < 17; ++i) { l.isgenneighbor[i] = false; l.iscpneighbor[i] = false; }
132 LOG_DEBUG(etos(l), " (point) belongs to team ", ftos(l.team));
133 l.sprite.SendFlags |= 16;
135 // flow power outward from the generators through the network
140 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
142 // if both points are captured by the same team, and only one of
143 // them is powered, mark the other one as powered as well
144 if (l.enemy.iscaptured && l.goalentity.iscaptured)
145 if (l.enemy.islinked != l.goalentity.islinked)
146 if(SAME_TEAM(l.enemy, l.goalentity))
148 if (!l.goalentity.islinked)
151 l.goalentity.islinked = true;
152 LOG_DEBUG(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)");
154 else if (!l.enemy.islinked)
157 l.enemy.islinked = true;
158 LOG_DEBUG(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)");
163 // now that we know which points are powered we can mark their neighbors
164 // as unshielded if team differs
165 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
167 if (l.goalentity.islinked)
169 if(DIFF_TEAM(l.goalentity, l.enemy))
171 LOG_DEBUG(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)");
172 l.enemy.isshielded = false;
174 if(l.goalentity.classname == "onslaught_generator")
175 l.enemy.isgenneighbor[l.goalentity.team] = true;
177 l.enemy.iscpneighbor[l.goalentity.team] = true;
179 if (l.enemy.islinked)
181 if(DIFF_TEAM(l.goalentity, l.enemy))
183 LOG_DEBUG(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)");
184 l.goalentity.isshielded = false;
186 if(l.enemy.classname == "onslaught_generator")
187 l.goalentity.isgenneighbor[l.enemy.team] = true;
189 l.goalentity.iscpneighbor[l.enemy.team] = true;
192 // now update the generators
193 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
197 LOG_DEBUG(etos(l), " (generator) is shielded");
198 l.takedamage = DAMAGE_NO;
199 l.bot_attack = false;
203 LOG_DEBUG(etos(l), " (generator) is not shielded");
204 l.takedamage = DAMAGE_AIM;
208 ons_Generator_UpdateSprite(l);
210 // now update the takedamage and alpha variables on control point icons
211 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
215 LOG_DEBUG(etos(l), " (point) is shielded");
218 l.goalentity.takedamage = DAMAGE_NO;
219 l.goalentity.bot_attack = false;
224 LOG_DEBUG(etos(l), " (point) is not shielded");
227 l.goalentity.takedamage = DAMAGE_AIM;
228 l.goalentity.bot_attack = true;
231 ons_ControlPoint_UpdateSprite(l);
233 IL_EACH(g_onsshields, true,
235 it.team = it.enemy.team;
236 it.colormap = it.enemy.colormap;
241 // ===================
242 // Main Link Functions
243 // ===================
245 bool ons_Link_Send(entity this, entity to, int sendflags)
247 WriteHeader(MSG_ENTITY, ENT_CLIENT_RADARLINK);
248 WriteByte(MSG_ENTITY, sendflags);
251 WriteCoord(MSG_ENTITY, this.goalentity.origin_x);
252 WriteCoord(MSG_ENTITY, this.goalentity.origin_y);
253 WriteCoord(MSG_ENTITY, this.goalentity.origin_z);
257 WriteCoord(MSG_ENTITY, this.enemy.origin_x);
258 WriteCoord(MSG_ENTITY, this.enemy.origin_y);
259 WriteCoord(MSG_ENTITY, this.enemy.origin_z);
263 WriteByte(MSG_ENTITY, this.clientcolors); // which is goalentity's color + enemy's color * 16
268 void ons_Link_CheckUpdate(entity this)
270 // TODO check if the two sides have moved (currently they won't move anyway)
271 float cc = 0, cc1 = 0, cc2 = 0;
273 if(this.goalentity.islinked || this.goalentity.iscaptured) { cc1 = (this.goalentity.team - 1) * 0x01; }
274 if(this.enemy.islinked || this.enemy.iscaptured) { cc2 = (this.enemy.team - 1) * 0x10; }
278 if(cc != this.clientcolors)
280 this.clientcolors = cc;
284 this.nextthink = time;
287 void ons_DelayedLinkSetup(entity this)
289 this.goalentity = find(NULL, targetname, this.target);
290 this.enemy = find(NULL, targetname, this.target2);
291 if(!this.goalentity) { objerror(this, "can not find target\n"); }
292 if(!this.enemy) { objerror(this, "can not find target2\n"); }
294 LOG_DEBUG(etos(this.goalentity), " linked with ", etos(this.enemy));
296 setthink(this, ons_Link_CheckUpdate);
297 this.nextthink = time;
301 // =============================
302 // Main Control Point Functions
303 // =============================
305 int ons_ControlPoint_CanBeLinked(entity cp, int teamnumber)
307 if(cp.isgenneighbor[teamnumber]) { return 2; }
308 if(cp.iscpneighbor[teamnumber]) { return 1; }
313 int ons_ControlPoint_Attackable(entity cp, int teamnumber)
314 // -2: SAME TEAM, attackable by enemy!
319 // 3: attack it (HIGH PRIO)
320 // 4: touch it (HIGH PRIO)
328 else if(cp.goalentity)
330 // if there's already an icon built, nothing happens
331 if(cp.team == teamnumber)
333 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
334 if(a) // attackable by enemy?
335 return -2; // EMERGENCY!
338 // we know it can be linked, so no need to check
340 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
341 if(a == 2) // near our generator?
342 return 3; // EMERGENCY!
348 if(ons_ControlPoint_CanBeLinked(cp, teamnumber))
350 a = ons_ControlPoint_CanBeLinked(cp, teamnumber); // why was this here NUM_TEAM_1 + NUM_TEAM_2 - t
352 return 4; // GET THIS ONE NOW!
354 return 2; // TOUCH ME
360 void ons_ControlPoint_Icon_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
362 if(damage <= 0) { return; }
364 if (this.owner.isshielded)
366 // this is protected by a shield, so ignore the damage
367 if (time > this.pain_finished)
368 if (IS_PLAYER(attacker))
370 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
371 this.pain_finished = time + 1;
372 attacker.typehitsound += 1; // play both sounds (shield is way too quiet)
378 if(IS_PLAYER(attacker))
379 if(time - ons_notification_time[this.team] > 10)
381 play2team(this.team, SND(ONS_CONTROLPOINT_UNDERATTACK));
382 ons_notification_time[this.team] = time;
385 this.health = this.health - damage;
386 if(this.owner.iscaptured)
387 WaypointSprite_UpdateHealth(this.owner.sprite, this.health);
389 WaypointSprite_UpdateBuildFinished(this.owner.sprite, time + (this.max_health - this.health) / (this.count / ONS_CP_THINKRATE));
390 this.pain_finished = time + 1;
391 // particles on every hit
392 pointparticles(EFFECT_SPARKS, hitloc, force*-1, 1);
395 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE+0.3, ATTEN_NORM);
397 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE+0.3, ATTEN_NORM);
401 sound(this, CH_TRIGGER, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
402 pointparticles(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
403 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_CPDESTROYED), this.owner.message, attacker.netname);
405 PlayerScore_Add(attacker, SP_ONS_TAKES, 1);
406 PlayerScore_Add(attacker, SP_SCORE, 10);
408 this.owner.goalentity = NULL;
409 this.owner.islinked = false;
410 this.owner.iscaptured = false;
412 this.owner.colormap = 1024;
414 WaypointSprite_UpdateMaxHealth(this.owner.sprite, 0);
416 onslaught_updatelinks();
418 // Use targets now (somebody make sure this is in the right place..)
419 SUB_UseTargets(this.owner, this, NULL);
421 this.owner.waslinked = this.owner.islinked;
422 if(this.owner.model != "models/onslaught/controlpoint_pad.md3")
423 setmodel_fixsize(this.owner, MDL_ONS_CP_PAD1);
424 //setsize(this, '-32 -32 0', '32 32 8');
429 this.SendFlags |= CPSF_STATUS;
432 void ons_ControlPoint_Icon_Think(entity this)
434 this.nextthink = time + ONS_CP_THINKRATE;
436 if(autocvar_g_onslaught_cp_proxydecap)
438 int _enemy_count = 0;
439 int _friendly_count = 0;
441 FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it), {
442 if(vdist(it.origin - this.origin, <, autocvar_g_onslaught_cp_proxydecap_distance))
444 if(SAME_TEAM(it, this))
451 _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
452 _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
454 this.health = bound(0, this.health + (_friendly_count - _enemy_count), this.max_health);
455 this.SendFlags |= CPSF_STATUS;
458 ons_ControlPoint_Icon_Damage(this, this, this, 1, 0, this.origin, '0 0 0');
463 if (time > this.pain_finished + 5)
465 if(this.health < this.max_health)
467 this.health = this.health + this.count;
468 if (this.health >= this.max_health)
469 this.health = this.max_health;
470 WaypointSprite_UpdateHealth(this.owner.sprite, this.health);
474 if(this.owner.islinked != this.owner.waslinked)
476 // unteam the spawnpoint if needed
477 int t = this.owner.team;
478 if(!this.owner.islinked)
481 SUB_UseTargets(this.owner, this, NULL);
485 this.owner.waslinked = this.owner.islinked;
489 if(random() < 0.6 - this.health / this.max_health)
491 Send_Effect(EFFECT_ELECTRIC_SPARKS, this.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
494 sound(this, CH_PAIN, SND_ONS_SPARK1, VOL_BASE, ATTEN_NORM);
495 else if (random() > 0.5)
496 sound(this, CH_PAIN, SND_ONS_SPARK2, VOL_BASE, ATTEN_NORM);
500 void ons_ControlPoint_Icon_BuildThink(entity this)
504 this.nextthink = time + ONS_CP_THINKRATE;
506 // only do this if there is power
507 a = ons_ControlPoint_CanBeLinked(this.owner, this.owner.team);
511 this.health = this.health + this.count;
513 this.SendFlags |= CPSF_STATUS;
515 if (this.health >= this.max_health)
517 this.health = this.max_health;
518 this.count = autocvar_g_onslaught_cp_regen * ONS_CP_THINKRATE; // slow repair rate from now on
519 setthink(this, ons_ControlPoint_Icon_Think);
520 sound(this, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILT, VOL_BASE, ATTEN_NORM);
521 this.owner.iscaptured = true;
522 this.solid = SOLID_BBOX;
524 Send_Effect(EFFECT_CAP(this.owner.team), this.owner.origin, '0 0 0', 1);
526 WaypointSprite_UpdateMaxHealth(this.owner.sprite, this.max_health);
527 WaypointSprite_UpdateHealth(this.owner.sprite, this.health);
529 if(IS_PLAYER(this.owner.ons_toucher))
531 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ONSLAUGHT_CAPTURE, this.owner.ons_toucher.netname, this.owner.message);
532 Send_Notification(NOTIF_ALL_EXCEPT, this.owner.ons_toucher, MSG_CENTER, APP_TEAM_NUM(this.owner.ons_toucher.team, CENTER_ONS_CAPTURE), this.owner.message);
533 Send_Notification(NOTIF_ONE, this.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE, this.owner.message);
534 PlayerScore_Add(this.owner.ons_toucher, SP_ONS_CAPS, 1);
535 PlayerTeamScore_AddScore(this.owner.ons_toucher, 10);
538 this.owner.ons_toucher = NULL;
540 onslaught_updatelinks();
542 // Use targets now (somebody make sure this is in the right place..)
543 SUB_UseTargets(this.owner, this, NULL);
545 this.SendFlags |= CPSF_SETUP;
547 if(this.owner.model != MDL_ONS_CP_PAD2.model_str())
548 setmodel_fixsize(this.owner, MDL_ONS_CP_PAD2);
550 if(random() < 0.9 - this.health / this.max_health)
551 Send_Effect(EFFECT_RAGE, this.origin + 10 * randomvec(), '0 0 -1', 1);
554 void onslaught_controlpoint_icon_link(entity e, void(entity this) spawnproc);
556 void ons_ControlPoint_Icon_Spawn(entity cp, entity player)
558 entity e = new(onslaught_controlpoint_icon);
560 setsize(e, CPICON_MIN, CPICON_MAX);
561 setorigin(e, cp.origin + CPICON_OFFSET);
564 e.max_health = autocvar_g_onslaught_cp_health;
565 e.health = autocvar_g_onslaught_cp_buildhealth;
567 e.takedamage = DAMAGE_AIM;
569 e.event_damage = ons_ControlPoint_Icon_Damage;
570 e.team = player.team;
571 e.colormap = 1024 + (e.team - 1) * 17;
572 e.count = (e.max_health - e.health) * ONS_CP_THINKRATE / autocvar_g_onslaught_cp_buildtime; // how long it takes to build
574 sound(e, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILD, VOL_BASE, ATTEN_NORM);
578 cp.colormap = e.colormap;
580 Send_Effect(EFFECT_FLAG_TOUCH(player.team), e.origin, '0 0 0', 1);
582 WaypointSprite_UpdateBuildFinished(cp.sprite, time + (e.max_health - e.health) / (e.count / ONS_CP_THINKRATE));
583 WaypointSprite_UpdateRule(cp.sprite,cp.team,SPRITERULE_TEAMPLAY);
584 cp.sprite.SendFlags |= 16;
586 onslaught_controlpoint_icon_link(e, ons_ControlPoint_Icon_BuildThink);
589 entity ons_ControlPoint_Waypoint(entity e)
593 int a = ons_ControlPoint_Attackable(e, e.team);
595 if(a == -2) { return WP_OnsCPDefend; } // defend now
596 if(a == -1 || a == 1 || a == 2) { return WP_OnsCP; } // touch
597 if(a == 3 || a == 4) { return WP_OnsCPAttack; } // attack
605 void ons_ControlPoint_UpdateSprite(entity e)
607 entity s1 = ons_ControlPoint_Waypoint(e);
608 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
611 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));
613 if(e.lastteam != e.team + 2 || e.lastshielded != sh || e.iscaptured != e.lastcaptured)
615 if(e.iscaptured) // don't mess up build bars!
619 WaypointSprite_UpdateMaxHealth(e.sprite, 0);
623 WaypointSprite_UpdateMaxHealth(e.sprite, e.goalentity.max_health);
624 WaypointSprite_UpdateHealth(e.sprite, e.goalentity.health);
630 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, false));
632 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
637 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, false));
639 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
641 WaypointSprite_Ping(e.sprite);
643 e.lastteam = e.team + 2;
645 e.lastcaptured = e.iscaptured;
649 void ons_ControlPoint_Touch(entity this, entity toucher)
653 if(IS_VEHICLE(toucher) && toucher.owner)
654 if(autocvar_g_onslaught_allow_vehicle_touch)
655 toucher = toucher.owner;
659 if(!IS_PLAYER(toucher)) { return; }
660 if(STAT(FROZEN, toucher)) { return; }
661 if(IS_DEAD(toucher)) { return; }
663 if ( SAME_TEAM(this,toucher) )
664 if ( this.iscaptured )
666 if(time <= toucher.teleport_antispam)
667 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT_ANTISPAM, rint(toucher.teleport_antispam - time));
669 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
672 attackable = ons_ControlPoint_Attackable(this, toucher.team);
673 if(attackable != 2 && attackable != 4)
675 // we've verified that this player has a legitimate claim to this point,
676 // so start building the captured point icon (which only captures this
677 // point if it successfully builds without being destroyed first)
678 ons_ControlPoint_Icon_Spawn(this, toucher);
680 this.ons_toucher = toucher;
682 onslaught_updatelinks();
685 void ons_ControlPoint_Think(entity this)
687 this.nextthink = time + ONS_CP_THINKRATE;
688 CSQCMODEL_AUTOUPDATE(this);
691 void ons_ControlPoint_Reset(entity this)
694 delete(this.goalentity);
696 this.goalentity = NULL;
698 this.colormap = 1024;
699 this.iscaptured = false;
700 this.islinked = false;
701 this.isshielded = true;
702 setthink(this, ons_ControlPoint_Think);
703 this.ons_toucher = NULL;
704 this.nextthink = time + ONS_CP_THINKRATE;
705 setmodel_fixsize(this, MDL_ONS_CP_PAD1);
707 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
708 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
710 onslaught_updatelinks();
712 SUB_UseTargets(this, this, NULL); // to reset the structures, playerspawns etc.
714 CSQCMODEL_AUTOUPDATE(this);
717 void ons_DelayedControlPoint_Setup(entity this)
719 onslaught_updatelinks();
721 // captureshield setup
722 ons_CaptureShield_Spawn(this, false);
724 CSQCMODEL_AUTOINIT(this);
727 void ons_ControlPoint_Setup(entity cp)
730 cp.ons_worldcpnext = ons_worldcplist; // link control point into ons_worldcplist
731 ons_worldcplist = cp;
733 cp.netname = "Control point";
735 cp.solid = SOLID_BBOX;
736 set_movetype(cp, MOVETYPE_NONE);
737 settouch(cp, ons_ControlPoint_Touch);
738 setthink(cp, ons_ControlPoint_Think);
739 cp.nextthink = time + ONS_CP_THINKRATE;
740 cp.reset = ons_ControlPoint_Reset;
742 cp.iscaptured = false;
744 cp.isshielded = true;
746 if(cp.message == "") { cp.message = "a"; }
749 setmodel_fixsize(cp, MDL_ONS_CP_PAD1);
751 // control point placement
752 if((cp.spawnflags & 1) || cp.noalign) // don't drop to floor, just stay at fixed location
755 set_movetype(cp, MOVETYPE_NONE);
757 else // drop to floor, automatically find a platform and set that as spawn origin
759 setorigin(cp, cp.origin + '0 0 20');
762 set_movetype(cp, MOVETYPE_TOSS);
766 WaypointSprite_SpawnFixed(WP_Null, cp.origin + CPGEN_WAYPOINT_OFFSET, cp, sprite, RADARICON_NONE);
767 WaypointSprite_UpdateRule(cp.sprite, cp.team, SPRITERULE_TEAMPLAY);
769 InitializeEntity(cp, ons_DelayedControlPoint_Setup, INITPRIO_SETLOCATION);
773 // =========================
774 // Main Generator Functions
775 // =========================
777 entity ons_Generator_Waypoint(entity e)
780 return WP_OnsGenShielded;
784 void ons_Generator_UpdateSprite(entity e)
786 entity s1 = ons_Generator_Waypoint(e);
787 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
789 if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
791 e.lastteam = e.team + 2;
792 e.lastshielded = e.isshielded;
796 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, false));
798 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
803 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, false));
805 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
807 WaypointSprite_Ping(e.sprite);
811 void ons_GeneratorDamage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
813 if(damage <= 0) { return; }
814 if(warmup_stage || gameover) { return; }
815 if(!round_handler_IsRoundStarted()) { return; }
817 if (attacker != this)
821 // this is protected by a shield, so ignore the damage
822 if (time > this.pain_finished)
823 if (IS_PLAYER(attacker))
825 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
826 attacker.typehitsound += 1;
827 this.pain_finished = time + 1;
831 if (time > this.pain_finished)
833 this.pain_finished = time + 10;
834 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && SAME_TEAM(it, this), Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK));
835 play2team(this.team, SND(ONS_GENERATOR_UNDERATTACK));
838 this.health = this.health - damage;
839 WaypointSprite_UpdateHealth(this.sprite, this.health);
840 // choose an animation frame based on health
841 this.frame = 10 * bound(0, (1 - this.health / this.max_health), 1);
842 // see if the generator is still functional, or dying
845 this.lasthealth = this.health;
849 if (attacker == this)
850 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME));
853 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED));
854 PlayerScore_Add(attacker, SP_SCORE, 100);
856 this.iscaptured = false;
857 this.islinked = false;
858 this.isshielded = false;
859 this.takedamage = DAMAGE_NO; // can't be hurt anymore
860 this.event_damage = func_null; // won't do anything if hurt
861 this.count = 0; // reset counter
862 setthink(this, func_null);
864 //this.think(); // do the first explosion now
866 WaypointSprite_UpdateMaxHealth(this.sprite, 0);
867 WaypointSprite_Ping(this.sprite);
868 //WaypointSprite_Kill(this.sprite); // can't do this yet, code too poor
870 onslaught_updatelinks();
873 // Throw some flaming gibs on damage, more damage = more chance for gib
874 if(random() < damage/220)
876 sound(this, CH_TRIGGER, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
880 // particles on every hit
881 Send_Effect(EFFECT_SPARKS, hitloc, force * -1, 1);
885 sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE, ATTEN_NORM);
887 sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE, ATTEN_NORM);
890 this.SendFlags |= GSF_STATUS;
893 void ons_GeneratorThink(entity this)
895 this.nextthink = time + GEN_THINKRATE;
898 if(!this.isshielded && this.wait < time)
900 this.wait = time + 5;
901 FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
902 if(SAME_TEAM(it, this))
904 Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM);
905 soundto(MSG_ONE, it, CHAN_AUTO, SND(KH_ALARM), VOL_BASE, ATTEN_NONE); // FIXME: unique sound?
908 Send_Notification(NOTIF_ONE, it, MSG_CENTER, APP_TEAM_NUM(this.team, CENTER_ONS_NOTSHIELDED));
914 void ons_GeneratorReset(entity this)
916 this.team = this.team_saved;
917 this.lasthealth = this.max_health = this.health = autocvar_g_onslaught_gen_health;
918 this.takedamage = DAMAGE_AIM;
919 this.bot_attack = true;
920 this.iscaptured = true;
921 this.islinked = true;
922 this.isshielded = true;
923 this.event_damage = ons_GeneratorDamage;
924 setthink(this, ons_GeneratorThink);
925 this.nextthink = time + GEN_THINKRATE;
927 Net_LinkEntity(this, false, 0, generator_send);
929 this.SendFlags = GSF_SETUP; // just incase
930 this.SendFlags |= GSF_STATUS;
932 WaypointSprite_UpdateMaxHealth(this.sprite, this.max_health);
933 WaypointSprite_UpdateHealth(this.sprite, this.health);
934 WaypointSprite_UpdateRule(this.sprite,this.team,SPRITERULE_TEAMPLAY);
936 onslaught_updatelinks();
939 void ons_DelayedGeneratorSetup(entity this)
942 waypoint_spawnforitem_force(this, this.origin);
943 this.nearestwaypointtimeout = 0; // activate waypointing again
944 this.bot_basewaypoint = this.nearestwaypoint;
946 // captureshield setup
947 ons_CaptureShield_Spawn(this, true);
949 onslaught_updatelinks();
951 Net_LinkEntity(this, false, 0, generator_send);
955 void onslaught_generator_touch(entity this, entity toucher)
957 if ( IS_PLAYER(toucher) )
958 if ( SAME_TEAM(this,toucher) )
959 if ( this.iscaptured )
961 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
965 void ons_GeneratorSetup(entity gen) // called when spawning a generator entity on the map as a spawnfunc
968 int teamnumber = gen.team;
971 gen.ons_worldgeneratornext = ons_worldgeneratorlist; // link generator into ons_worldgeneratorlist
972 ons_worldgeneratorlist = gen;
974 gen.netname = sprintf("%s generator", Team_ColoredFullName(teamnumber));
975 gen.classname = "onslaught_generator";
976 gen.solid = SOLID_BBOX;
977 gen.team_saved = teamnumber;
978 set_movetype(gen, MOVETYPE_NONE);
979 gen.lasthealth = gen.max_health = gen.health = autocvar_g_onslaught_gen_health;
980 gen.takedamage = DAMAGE_AIM;
981 gen.bot_attack = true;
982 gen.event_damage = ons_GeneratorDamage;
983 gen.reset = ons_GeneratorReset;
984 setthink(gen, ons_GeneratorThink);
985 gen.nextthink = time + GEN_THINKRATE;
986 gen.iscaptured = true;
988 gen.isshielded = true;
989 settouch(gen, onslaught_generator_touch);
992 // model handled by CSQC
993 setsize(gen, GENERATOR_MIN, GENERATOR_MAX);
994 setorigin(gen, (gen.origin + CPGEN_SPAWN_OFFSET));
995 gen.colormap = 1024 + (teamnumber - 1) * 17;
997 // generator placement
1001 WaypointSprite_SpawnFixed(WP_Null, gen.origin + CPGEN_WAYPOINT_OFFSET, gen, sprite, RADARICON_NONE);
1002 WaypointSprite_UpdateRule(gen.sprite, gen.team, SPRITERULE_TEAMPLAY);
1003 WaypointSprite_UpdateMaxHealth(gen.sprite, gen.max_health);
1004 WaypointSprite_UpdateHealth(gen.sprite, gen.health);
1006 InitializeEntity(gen, ons_DelayedGeneratorSetup, INITPRIO_SETLOCATION);
1014 int total_generators;
1015 void Onslaught_count_generators()
1018 total_generators = redowned = blueowned = yellowowned = pinkowned = 0;
1019 for(e = ons_worldgeneratorlist; e; e = e.ons_worldgeneratornext)
1022 redowned += (e.team == NUM_TEAM_1 && e.health > 0);
1023 blueowned += (e.team == NUM_TEAM_2 && e.health > 0);
1024 yellowowned += (e.team == NUM_TEAM_3 && e.health > 0);
1025 pinkowned += (e.team == NUM_TEAM_4 && e.health > 0);
1029 int Onslaught_GetWinnerTeam()
1031 int winner_team = 0;
1033 winner_team = NUM_TEAM_1;
1036 if(winner_team) return 0;
1037 winner_team = NUM_TEAM_2;
1041 if(winner_team) return 0;
1042 winner_team = NUM_TEAM_3;
1046 if(winner_team) return 0;
1047 winner_team = NUM_TEAM_4;
1051 return -1; // no generators left?
1054 void nades_Clear(entity e);
1056 #define ONS_OWNED_GENERATORS() ((redowned > 0) + (blueowned > 0) + (yellowowned > 0) + (pinkowned > 0))
1057 #define ONS_OWNED_GENERATORS_OK() (ONS_OWNED_GENERATORS() > 1)
1058 bool Onslaught_CheckWinner()
1060 if ((autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60) || (round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0))
1062 ons_stalemate = true;
1064 if (!wpforenemy_announced)
1066 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT);
1067 sound(NULL, CH_INFO, SND_ONS_GENERATOR_DECAY, VOL_BASE, ATTEN_NONE);
1069 wpforenemy_announced = true;
1072 entity tmp_entity; // temporary entity
1074 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext) if(time >= tmp_entity.ons_overtime_damagedelay)
1076 // tmp_entity.max_health / 300 gives 5 minutes of overtime.
1077 // control points reduce the overtime duration.
1080 for(e = ons_worldcplist; e; e = e.ons_worldcpnext)
1082 if(DIFF_TEAM(e, tmp_entity))
1087 if(autocvar_g_campaign && autocvar__campaign_testrun)
1088 d = d * tmp_entity.max_health;
1090 d = d * tmp_entity.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
1092 Damage(tmp_entity, tmp_entity, tmp_entity, d, DEATH_HURTTRIGGER.m_id, tmp_entity.origin, '0 0 0');
1094 tmp_entity.sprite.SendFlags |= 16;
1096 tmp_entity.ons_overtime_damagedelay = time + 1;
1099 else { wpforenemy_announced = false; ons_stalemate = false; }
1101 Onslaught_count_generators();
1103 if(ONS_OWNED_GENERATORS_OK())
1106 int winner_team = Onslaught_GetWinnerTeam();
1110 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
1111 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
1112 TeamScore_AddToTeam(winner_team, ST_ONS_CAPS, +1);
1114 else if(winner_team == -1)
1116 Send_Notification(NOTIF_ALL, NULL, MSG_CENTER, CENTER_ROUND_TIED);
1117 Send_Notification(NOTIF_ALL, NULL, MSG_INFO, INFO_ROUND_TIED);
1120 ons_stalemate = false;
1122 play2all(SND(CTF_CAPTURE(winner_team)));
1124 round_handler_Init(7, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
1126 FOREACH_CLIENT(IS_PLAYER(it), {
1127 STAT(ROUNDLOST, it) = true;
1128 it.player_blocked = true;
1136 bool Onslaught_CheckPlayers()
1141 void Onslaught_RoundStart()
1144 FOREACH_CLIENT(IS_PLAYER(it), it.player_blocked = false);
1146 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1147 tmp_entity.sprite.SendFlags |= 16;
1149 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1150 tmp_entity.sprite.SendFlags |= 16;
1158 // NOTE: LEGACY CODE, needs to be re-written!
1160 void havocbot_goalrating_ons_offenseitems(entity this, float ratingscale, vector org, float sradius)
1162 bool needarmor = false, needweapons = false;
1164 // Needs armor/health?
1170 FOREACH(Weapons, it != WEP_Null, {
1171 if(this.weapons & (it.m_wepset))
1179 if(!needweapons && !needarmor)
1182 LOG_DEBUG(this.netname, " needs weapons ", ftos(needweapons));
1183 LOG_DEBUG(this.netname, " needs armor ", ftos(needarmor));
1185 // See what is around
1186 IL_EACH(g_items, it.bot_pickup,
1188 // gather health and armor only
1190 if ( ((it.health || it.armorvalue) && needarmor) || (it.weapons && needweapons ) )
1191 if (vdist(it.origin - org, <, sradius))
1193 int t = it.bot_pickupevalfunc(this, it);
1195 navigation_routerating(this, it, t * ratingscale, 500);
1200 void havocbot_role_ons_setrole(entity this, int role)
1202 LOG_DEBUG(this.netname," switched to ");
1205 case HAVOCBOT_ONS_ROLE_DEFENSE:
1206 LOG_DEBUG("defense");
1207 this.havocbot_role = havocbot_role_ons_defense;
1208 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE;
1209 this.havocbot_role_timeout = 0;
1211 case HAVOCBOT_ONS_ROLE_ASSISTANT:
1212 LOG_DEBUG("assistant");
1213 this.havocbot_role = havocbot_role_ons_assistant;
1214 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT;
1215 this.havocbot_role_timeout = 0;
1217 case HAVOCBOT_ONS_ROLE_OFFENSE:
1218 LOG_DEBUG("offense");
1219 this.havocbot_role = havocbot_role_ons_offense;
1220 this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE;
1221 this.havocbot_role_timeout = 0;
1227 void havocbot_goalrating_ons_controlpoints_attack(entity this, float ratingscale)
1229 entity cp, cp1, cp2, best, wp;
1230 float radius, bestvalue;
1234 // Filter control points
1235 for(cp2 = ons_worldcplist; cp2; cp2 = cp2.ons_worldcpnext)
1238 cp2.wpconsidered = false;
1243 // Ignore owned controlpoints
1244 if(!(cp2.isgenneighbor[this.team] || cp2.iscpneighbor[this.team]))
1247 // Count team mates interested in this control point
1248 // (easier and cleaner than keeping counters per cp and teams)
1249 FOREACH_CLIENT(IS_PLAYER(it), {
1250 if(SAME_TEAM(it, this))
1251 if(it.havocbot_role_flags & HAVOCBOT_ONS_ROLE_OFFENSE)
1252 if(it.havocbot_ons_target == cp2)
1256 // NOTE: probably decrease the cost of attackable control points
1258 cp2.wpconsidered = true;
1261 // We'll consider only the best case
1262 bestvalue = 99999999999;
1264 for(cp1 = ons_worldcplist; cp1; cp1 = cp1.ons_worldcpnext)
1266 if (!cp1.wpconsidered)
1269 if(cp1.wpcost<bestvalue)
1271 bestvalue = cp1.wpcost;
1273 this.havocbot_ons_target = cp1;
1280 LOG_DEBUG(this.netname, " chose cp ranked ", ftos(bestvalue));
1284 // Should be attacked
1285 // Rate waypoints near it
1288 bestvalue = 99999999999;
1289 for(radius=0; radius<1000 && !found; radius+=500)
1291 for(wp=findradius(cp.origin,radius); wp; wp=wp.chain)
1293 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
1294 if(wp.classname=="waypoint")
1295 if(checkpvs(wp.origin,cp))
1298 if(wp.cnt<bestvalue)
1309 navigation_routerating(this, best, ratingscale, 10000);
1312 this.havocbot_attack_time = 0;
1313 if(checkpvs(this.view_ofs,cp))
1314 if(checkpvs(this.view_ofs,best))
1315 this.havocbot_attack_time = time + 2;
1319 navigation_routerating(this, cp, ratingscale, 10000);
1321 LOG_DEBUG(this.netname, " found an attackable controlpoint at ", vtos(cp.origin));
1325 // Should be touched
1326 LOG_DEBUG(this.netname, " found a touchable controlpoint at ", vtos(cp.origin));
1329 // Look for auto generated waypoint
1330 if (!bot_waypoints_for_items)
1331 for (wp = findradius(cp.origin,100); wp; wp = wp.chain)
1333 if(wp.classname=="waypoint")
1335 navigation_routerating(this, wp, ratingscale, 10000);
1340 // Nothing found, rate the controlpoint itself
1342 navigation_routerating(this, cp, ratingscale, 10000);
1346 bool havocbot_goalrating_ons_generator_attack(entity this, float ratingscale)
1348 entity g, wp, bestwp;
1352 for(g = ons_worldgeneratorlist; g; g = g.ons_worldgeneratornext)
1354 if(SAME_TEAM(g, this) || g.isshielded)
1357 // Should be attacked
1358 // Rate waypoints near it
1363 for(wp=findradius(g.origin,400); wp; wp=wp.chain)
1365 if(wp.classname=="waypoint")
1366 if(checkpvs(wp.origin,g))
1379 LOG_DEBUG("waypoints found around generator");
1380 navigation_routerating(this, bestwp, ratingscale, 10000);
1383 this.havocbot_attack_time = 0;
1384 if(checkpvs(this.view_ofs,g))
1385 if(checkpvs(this.view_ofs,bestwp))
1386 this.havocbot_attack_time = time + 5;
1392 LOG_DEBUG("generator found without waypoints around");
1393 // if there aren't waypoints near the generator go straight to it
1394 navigation_routerating(this, g, ratingscale, 10000);
1395 this.havocbot_attack_time = 0;
1402 void havocbot_role_ons_offense(entity this)
1406 this.havocbot_attack_time = 0;
1407 havocbot_ons_reset_role(this);
1411 // Set the role timeout if necessary
1412 if (!this.havocbot_role_timeout)
1413 this.havocbot_role_timeout = time + 120;
1415 if (time > this.havocbot_role_timeout)
1417 havocbot_ons_reset_role(this);
1421 if(this.havocbot_attack_time>time)
1424 if (this.bot_strategytime < time)
1426 navigation_goalrating_start(this);
1427 havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
1428 if(!havocbot_goalrating_ons_generator_attack(this, 20000))
1429 havocbot_goalrating_ons_controlpoints_attack(this, 20000);
1430 havocbot_goalrating_ons_offenseitems(this, 10000, this.origin, 10000);
1431 navigation_goalrating_end(this);
1433 this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
1437 void havocbot_role_ons_assistant(entity this)
1439 havocbot_ons_reset_role(this);
1442 void havocbot_role_ons_defense(entity this)
1444 havocbot_ons_reset_role(this);
1447 void havocbot_ons_reset_role(entity this)
1452 this.havocbot_ons_target = NULL;
1454 // TODO: Defend control points or generator if necessary
1456 havocbot_role_ons_setrole(this, HAVOCBOT_ONS_ROLE_OFFENSE);
1461 * Find control point or generator owned by the same team self which is nearest to pos
1462 * if max_dist is positive, only control points within this range will be considered
1464 entity ons_Nearest_ControlPoint(entity this, vector pos, float max_dist)
1466 entity closest_target = NULL;
1467 for(entity cp = ons_worldcplist; cp; cp = cp.ons_worldcpnext)
1469 if(SAME_TEAM(cp, this))
1471 if(max_dist <= 0 || vdist(cp.origin - pos, <=, max_dist))
1472 if(vlen2(cp.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
1473 closest_target = cp;
1475 for(entity gen = ons_worldgeneratorlist; gen; gen = gen.ons_worldgeneratornext)
1477 if(SAME_TEAM(gen, this))
1478 if(max_dist <= 0 || vdist(gen.origin - pos, <, max_dist))
1479 if(vlen2(gen.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == NULL)
1480 closest_target = gen;
1483 return closest_target;
1487 * Find control point or generator owned by the same team self which is nearest to pos
1488 * if max_dist is positive, only control points within this range will be considered
1489 * This function only check distances on the XY plane, disregarding Z
1491 entity ons_Nearest_ControlPoint_2D(entity this, vector pos, float max_dist)
1493 entity closest_target = NULL;
1495 float smallest_distance = 0, distance;
1497 for(entity cp = ons_worldcplist; cp; cp = cp.ons_worldcpnext)
1499 delta = cp.origin - pos;
1501 distance = vlen(delta);
1503 if(SAME_TEAM(cp, this))
1505 if(max_dist <= 0 || distance <= max_dist)
1506 if(closest_target == NULL || distance <= smallest_distance )
1508 closest_target = cp;
1509 smallest_distance = distance;
1512 for(entity gen = ons_worldgeneratorlist; gen; gen = gen.ons_worldgeneratornext)
1514 delta = gen.origin - pos;
1516 distance = vlen(delta);
1518 if(SAME_TEAM(gen, this))
1519 if(max_dist <= 0 || distance <= max_dist)
1520 if(closest_target == NULL || distance <= smallest_distance )
1522 closest_target = gen;
1523 smallest_distance = distance;
1527 return closest_target;
1530 * find the number of control points and generators in the same team as this
1532 int ons_Count_SelfControlPoints(entity this)
1535 for(entity cp = ons_worldcplist; cp; cp = cp.ons_worldcpnext)
1537 if(SAME_TEAM(cp, this))
1541 for(entity gen = ons_worldgeneratorlist; gen; gen = gen.ons_worldgeneratornext)
1543 if(SAME_TEAM(gen, this))
1550 * Teleport player to a random position near tele_target
1551 * if tele_effects is true, teleport sound+particles are created
1552 * return false on failure
1554 bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effects)
1562 // narrow the range for each iteration to increase chances that a spawnpoint
1563 // can be found even if there's little room around the control point
1564 float iteration_scale = 1;
1565 for(i = 0; i < 16; ++i)
1567 iteration_scale -= i / 16;
1568 theta = random() * 2 * M_PI;
1572 loc *= random() * range * iteration_scale;
1574 loc += tele_target.origin + '0 0 128' * iteration_scale;
1576 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
1577 if(trace_fraction == 1.0 && !trace_startsolid)
1579 traceline(tele_target.origin, loc, MOVE_NOMONSTERS, tele_target); // double check to make sure we're not spawning outside the NULL
1580 if(trace_fraction == 1.0 && !trace_startsolid)
1584 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
1585 sound (player, CH_TRIGGER, SND_TELEPORT, VOL_BASE, ATTEN_NORM);
1587 setorigin(player, loc);
1588 player.angles = '0 1 0' * ( theta * RAD2DEG + 180 );
1589 makevectors(player.angles);
1590 player.fixangle = true;
1591 player.teleport_antispam = time + autocvar_g_onslaught_teleport_wait;
1594 Send_Effect(EFFECT_TELEPORT, player.origin + v_forward * 32, '0 0 0', 1);
1607 MUTATOR_HOOKFUNCTION(ons, reset_map_global)
1609 FOREACH_CLIENT(IS_PLAYER(it), {
1610 STAT(ROUNDLOST, it) = false;
1611 it.ons_deathloc = '0 0 0';
1612 PutClientInServer(it);
1617 MUTATOR_HOOKFUNCTION(ons, ClientDisconnect)
1619 entity player = M_ARGV(0, entity);
1621 player.ons_deathloc = '0 0 0';
1624 MUTATOR_HOOKFUNCTION(ons, MakePlayerObserver)
1626 entity player = M_ARGV(0, entity);
1628 player.ons_deathloc = '0 0 0';
1631 MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
1633 entity player = M_ARGV(0, entity);
1635 if(!round_handler_IsRoundStarted())
1637 player.player_blocked = true;
1642 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1644 l.sprite.SendFlags |= 16;
1646 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1648 l.sprite.SendFlags |= 16;
1651 if(ons_stalemate) { Send_Notification(NOTIF_ONE, player, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); }
1653 if ( autocvar_g_onslaught_spawn_choose )
1654 if ( player.ons_spawn_by )
1655 if ( ons_Teleport(player,player.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) )
1657 player.ons_spawn_by = NULL;
1661 if(autocvar_g_onslaught_spawn_at_controlpoints)
1662 if(random() <= autocvar_g_onslaught_spawn_at_controlpoints_chance)
1664 float random_target = autocvar_g_onslaught_spawn_at_controlpoints_random;
1665 entity tmp_entity, closest_target = NULL;
1666 vector spawn_loc = player.ons_deathloc;
1668 // new joining player or round reset, don't bother checking
1669 if(spawn_loc == '0 0 0') { return false; }
1671 if(random_target) { RandomSelection_Init(); }
1673 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1675 if(SAME_TEAM(tmp_entity, player))
1677 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1678 else if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL)
1679 closest_target = tmp_entity;
1682 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1688 float iteration_scale = 1;
1689 for(i = 0; i < 10; ++i)
1691 iteration_scale -= i / 10;
1692 loc = closest_target.origin + '0 0 96' * iteration_scale;
1693 loc += ('0 1 0' * random()) * 128 * iteration_scale;
1694 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
1695 if(trace_fraction == 1.0 && !trace_startsolid)
1697 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL
1698 if(trace_fraction == 1.0 && !trace_startsolid)
1700 setorigin(player, loc);
1701 player.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1709 if(autocvar_g_onslaught_spawn_at_generator)
1710 if(random() <= autocvar_g_onslaught_spawn_at_generator_chance)
1712 float random_target = autocvar_g_onslaught_spawn_at_generator_random;
1713 entity tmp_entity, closest_target = NULL;
1714 vector spawn_loc = player.ons_deathloc;
1716 // new joining player or round reset, don't bother checking
1717 if(spawn_loc == '0 0 0') { return false; }
1719 if(random_target) { RandomSelection_Init(); }
1721 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1724 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1727 if(SAME_TEAM(tmp_entity, player))
1728 if(vlen2(tmp_entity.origin - spawn_loc) <= vlen2(closest_target.origin - spawn_loc) || closest_target == NULL)
1729 closest_target = tmp_entity;
1733 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1739 float iteration_scale = 1;
1740 for(i = 0; i < 10; ++i)
1742 iteration_scale -= i / 10;
1743 loc = closest_target.origin + '0 0 128' * iteration_scale;
1744 loc += ('0 1 0' * random()) * 256 * iteration_scale;
1745 tracebox(loc, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), loc, MOVE_NORMAL, player);
1746 if(trace_fraction == 1.0 && !trace_startsolid)
1748 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the NULL
1749 if(trace_fraction == 1.0 && !trace_startsolid)
1751 setorigin(player, loc);
1752 player.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1763 MUTATOR_HOOKFUNCTION(ons, PlayerDies)
1765 entity frag_target = M_ARGV(2, entity);
1767 frag_target.ons_deathloc = frag_target.origin;
1769 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1771 l.sprite.SendFlags |= 16;
1773 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1775 l.sprite.SendFlags |= 16;
1778 if ( autocvar_g_onslaught_spawn_choose )
1779 if ( ons_Count_SelfControlPoints(frag_target) > 1 )
1780 stuffcmd(frag_target, "qc_cmd_cl hud clickradar\n");
1785 MUTATOR_HOOKFUNCTION(ons, MonsterMove)
1787 entity mon = M_ARGV(0, entity);
1789 entity e = find(NULL, targetname, mon.target);
1794 void ons_MonsterSpawn_Delayed(entity this)
1796 entity own = this.owner;
1798 if(!own) { delete(this); return; }
1802 entity e = find(NULL, target, own.targetname);
1807 own.use(own, e, NULL);
1814 MUTATOR_HOOKFUNCTION(ons, MonsterSpawn)
1816 entity mon = M_ARGV(0, entity);
1820 InitializeEntity(e, ons_MonsterSpawn_Delayed, INITPRIO_FINDTARGET);
1823 void ons_TurretSpawn_Delayed(entity this)
1825 entity own = this.owner;
1827 if(!own) { delete(this); return; }
1831 entity e = find(NULL, target, own.targetname);
1835 own.active = ACTIVE_NOT;
1837 own.use(own, e, NULL);
1844 MUTATOR_HOOKFUNCTION(ons, TurretSpawn)
1846 entity turret = M_ARGV(0, entity);
1850 InitializeEntity(e, ons_TurretSpawn_Delayed, INITPRIO_FINDTARGET);
1855 MUTATOR_HOOKFUNCTION(ons, HavocBot_ChooseRole)
1857 entity bot = M_ARGV(0, entity);
1859 havocbot_ons_reset_role(bot);
1863 MUTATOR_HOOKFUNCTION(ons, GetTeamCount)
1865 // onslaught is special
1866 for(entity tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1868 switch(tmp_entity.team)
1870 case NUM_TEAM_1: c1 = 0; break;
1871 case NUM_TEAM_2: c2 = 0; break;
1872 case NUM_TEAM_3: c3 = 0; break;
1873 case NUM_TEAM_4: c4 = 0; break;
1880 MUTATOR_HOOKFUNCTION(ons, SpectateCopy)
1882 entity spectatee = M_ARGV(0, entity);
1883 entity client = M_ARGV(1, entity);
1885 STAT(ROUNDLOST, client) = STAT(ROUNDLOST, spectatee); // make spectators see it too
1888 MUTATOR_HOOKFUNCTION(ons, SV_ParseClientCommand)
1890 if(MUTATOR_RETURNVALUE) // command was already handled?
1893 entity player = M_ARGV(0, entity);
1894 string cmd_name = M_ARGV(1, string);
1895 int cmd_argc = M_ARGV(2, int);
1897 if ( cmd_name == "ons_spawn" )
1899 vector pos = player.origin;
1901 pos_x = stof(argv(1));
1903 pos_y = stof(argv(2));
1905 pos_z = stof(argv(3));
1907 if ( IS_PLAYER(player) )
1909 if ( !STAT(FROZEN, player) )
1911 entity source_point = ons_Nearest_ControlPoint(player, player.origin, autocvar_g_onslaught_teleport_radius);
1913 if ( !source_point && player.health > 0 )
1915 sprint(player, "\nYou need to be next to a control point\n");
1920 entity closest_target = ons_Nearest_ControlPoint_2D(player, pos, autocvar_g_onslaught_click_radius);
1922 if ( closest_target == NULL )
1924 sprint(player, "\nNo control point found\n");
1928 if ( player.health <= 0 )
1930 player.ons_spawn_by = closest_target;
1931 player.respawn_flags = player.respawn_flags | RESPAWN_FORCE;
1935 if ( source_point == closest_target )
1937 sprint(player, "\nTeleporting to the same point\n");
1941 if ( !ons_Teleport(player,closest_target,autocvar_g_onslaught_teleport_radius,true) )
1942 sprint(player, "\nUnable to teleport there\n");
1948 sprint(player, "\nNo teleportation for you\n");
1956 MUTATOR_HOOKFUNCTION(ons, PlayerUseKey)
1958 if(MUTATOR_RETURNVALUE || gameover) { return false; }
1960 entity player = M_ARGV(0, entity);
1962 if((time > player.teleport_antispam) && (!IS_DEAD(player)) && !player.vehicle)
1964 entity source_point = ons_Nearest_ControlPoint(player, player.origin, autocvar_g_onslaught_teleport_radius);
1967 stuffcmd(player, "qc_cmd_cl hud clickradar\n");
1973 MUTATOR_HOOKFUNCTION(ons, PlayHitsound)
1975 entity frag_victim = M_ARGV(0, entity);
1977 return (frag_victim.classname == "onslaught_generator" && !frag_victim.isshielded)
1978 || (frag_victim.classname == "onslaught_controlpoint_icon" && !frag_victim.owner.isshielded);
1981 MUTATOR_HOOKFUNCTION(ons, SendWaypoint)
1983 entity wp = M_ARGV(0, entity);
1984 entity to = M_ARGV(1, entity);
1985 int sf = M_ARGV(2, int);
1986 int wp_flag = M_ARGV(3, int);
1990 if(wp.owner.classname == "onslaught_controlpoint")
1992 entity wp_owner = wp.owner;
1993 entity e = WaypointSprite_getviewentity(to);
1994 if(SAME_TEAM(e, wp_owner) && wp_owner.goalentity.health >= wp_owner.goalentity.max_health) { wp_flag |= 2; }
1995 if(!ons_ControlPoint_Attackable(wp_owner, e.team)) { wp_flag |= 2; }
1997 if(wp.owner.classname == "onslaught_generator")
1999 entity wp_owner = wp.owner;
2000 if(wp_owner.isshielded && wp_owner.health >= wp_owner.max_health) { wp_flag |= 2; }
2001 if(wp_owner.health <= 0) { wp_flag |= 2; }
2005 M_ARGV(3, int) = wp_flag;
2008 MUTATOR_HOOKFUNCTION(ons, TurretValidateTarget)
2010 entity turret_target = M_ARGV(1, entity);
2012 if(substring(turret_target.classname, 0, 10) == "onslaught_") // don't attack onslaught targets, that's the player's job!
2014 M_ARGV(3, float) = -3;
2021 MUTATOR_HOOKFUNCTION(ons, TurretThink)
2023 entity turret = M_ARGV(0, entity);
2025 // ONS uses somewhat backwards linking.
2028 entity e = find(NULL, targetname, turret.target);
2030 turret.team = e.team;
2033 if(turret.team != turret.tur_head.team)
2034 turret_respawn(turret);
2042 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
2043 Link between control points.
2045 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.
2048 "target" - first control point.
2049 "target2" - second control point.
2051 spawnfunc(onslaught_link)
2053 if(!g_onslaught) { delete(this); return; }
2055 if (this.target == "" || this.target2 == "")
2056 objerror(this, "target and target2 must be set\n");
2058 this.ons_worldlinknext = ons_worldlinklist; // link into ons_worldlinklist
2059 ons_worldlinklist = this;
2061 InitializeEntity(this, ons_DelayedLinkSetup, INITPRIO_FINDTARGET);
2062 Net_LinkEntity(this, false, 0, ons_Link_Send);
2065 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
2066 Control point. Be sure to give this enough clearance so that the shootable part has room to exist
2068 This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
2071 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2072 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
2073 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
2076 spawnfunc(onslaught_controlpoint)
2078 if(!g_onslaught) { delete(this); return; }
2080 ons_ControlPoint_Setup(this);
2083 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
2086 spawnfunc_onslaught_link entities can target this.
2089 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
2090 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2092 spawnfunc(onslaught_generator)
2094 if(!g_onslaught) { delete(this); return; }
2095 if(!this.team) { objerror(this, "team must be set"); }
2097 ons_GeneratorSetup(this);
2101 void ons_ScoreRules()
2103 CheckAllowedTeams(NULL);
2105 if(c1 >= 0) teams |= BIT(0);
2106 if(c2 >= 0) teams |= BIT(1);
2107 if(c3 >= 0) teams |= BIT(2);
2108 if(c4 >= 0) teams |= BIT(3);
2109 ScoreRules_basics(teams, SFL_SORT_PRIO_PRIMARY, 0, true);
2110 ScoreInfo_SetLabel_TeamScore (ST_ONS_CAPS, "destroyed", SFL_SORT_PRIO_PRIMARY);
2111 ScoreInfo_SetLabel_PlayerScore(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
2112 ScoreInfo_SetLabel_PlayerScore(SP_ONS_TAKES, "takes", 0);
2113 ScoreRules_basics_end();
2116 void ons_DelayedInit(entity this) // Do this check with a delay so we can wait for teams to be set up
2120 round_handler_Spawn(Onslaught_CheckPlayers, Onslaught_CheckWinner, Onslaught_RoundStart);
2121 round_handler_Init(5, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
2124 void ons_Initialize()
2127 ons_captureshield_force = autocvar_g_onslaught_shield_force;
2129 InitializeEntity(NULL, ons_DelayedInit, INITPRIO_GAMETYPE);