3 #include "../controlpoint.qh"
4 #include "../generator.qh"
6 void FixSize(entity e);
8 // =======================
9 // CaptureShield Functions
10 // =======================
12 bool ons_CaptureShield_Customize()
14 entity e = WaypointSprite_getviewentity(other);
16 if(!self.enemy.isshielded && (ons_ControlPoint_Attackable(self.enemy, e.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return false; }
17 if(SAME_TEAM(self, e)) { return false; }
22 void ons_CaptureShield_Touch()
24 if(!self.enemy.isshielded && (ons_ControlPoint_Attackable(self.enemy, other.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return; }
25 if(!IS_PLAYER(other)) { return; }
26 if(SAME_TEAM(other, self)) { return; }
28 vector mymid = (self.absmin + self.absmax) * 0.5;
29 vector othermid = (other.absmin + other.absmax) * 0.5;
31 Damage(other, self, self, 0, DEATH_HURTTRIGGER.m_id, mymid, normalize(othermid - mymid) * ons_captureshield_force);
33 if(IS_REAL_CLIENT(other))
35 play2(other, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
37 if(self.enemy.classname == "onslaught_generator")
38 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_GENERATOR_SHIELDED);
40 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_CONTROLPOINT_SHIELDED);
44 void ons_CaptureShield_Reset()
46 self.colormap = self.enemy.colormap;
47 self.team = self.enemy.team;
50 void ons_CaptureShield_Spawn(entity generator, bool is_generator)
52 entity shield = spawn();
54 shield.enemy = generator;
55 shield.team = generator.team;
56 shield.colormap = generator.colormap;
57 shield.reset = ons_CaptureShield_Reset;
58 shield.touch = ons_CaptureShield_Touch;
59 shield.customizeentityforclient = ons_CaptureShield_Customize;
60 shield.classname = "ons_captureshield";
61 shield.effects = EF_ADDITIVE;
62 shield.movetype = MOVETYPE_NOCLIP;
63 shield.solid = SOLID_TRIGGER;
64 shield.avelocity = '7 0 11';
66 shield.model = ((is_generator) ? "models/onslaught/generator_shield.md3" : "models/onslaught/controlpoint_shield.md3");
68 precache_model(shield.model);
69 setorigin(shield, generator.origin);
70 _setmodel(shield, shield.model);
71 setsize(shield, shield.scale * shield.mins, shield.scale * shield.maxs);
79 void ons_debug(string input)
81 switch(autocvar_g_onslaught_debug)
83 case 1: LOG_TRACE(input); break;
84 case 2: LOG_INFO(input); break;
88 void setmodel_fixsize(entity e, Model m)
94 void onslaught_updatelinks()
97 // first check if the game has ended
98 ons_debug("--- updatelinks ---\n");
99 // mark generators as being shielded and networked
100 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
103 ons_debug(strcat(etos(l), " (generator) belongs to team ", ftos(l.team), "\n"));
105 ons_debug(strcat(etos(l), " (generator) is destroyed\n"));
106 l.islinked = l.iscaptured;
107 l.isshielded = l.iscaptured;
108 l.sprite.SendFlags |= 16;
110 // mark points as shielded and not networked
111 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
116 for(i = 0; i < 17; ++i) { l.isgenneighbor[i] = false; l.iscpneighbor[i] = false; }
117 ons_debug(strcat(etos(l), " (point) belongs to team ", ftos(l.team), "\n"));
118 l.sprite.SendFlags |= 16;
120 // flow power outward from the generators through the network
125 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
127 // if both points are captured by the same team, and only one of
128 // them is powered, mark the other one as powered as well
129 if (l.enemy.iscaptured && l.goalentity.iscaptured)
130 if (l.enemy.islinked != l.goalentity.islinked)
131 if(SAME_TEAM(l.enemy, l.goalentity))
133 if (!l.goalentity.islinked)
136 l.goalentity.islinked = true;
137 ons_debug(strcat(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)\n"));
139 else if (!l.enemy.islinked)
142 l.enemy.islinked = true;
143 ons_debug(strcat(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)\n"));
148 // now that we know which points are powered we can mark their neighbors
149 // as unshielded if team differs
150 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
152 if (l.goalentity.islinked)
154 if(DIFF_TEAM(l.goalentity, l.enemy))
156 ons_debug(strcat(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)\n"));
157 l.enemy.isshielded = false;
159 if(l.goalentity.classname == "onslaught_generator")
160 l.enemy.isgenneighbor[l.goalentity.team] = true;
162 l.enemy.iscpneighbor[l.goalentity.team] = true;
164 if (l.enemy.islinked)
166 if(DIFF_TEAM(l.goalentity, l.enemy))
168 ons_debug(strcat(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)\n"));
169 l.goalentity.isshielded = false;
171 if(l.enemy.classname == "onslaught_generator")
172 l.goalentity.isgenneighbor[l.enemy.team] = true;
174 l.goalentity.iscpneighbor[l.enemy.team] = true;
177 // now update the generators
178 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
182 ons_debug(strcat(etos(l), " (generator) is shielded\n"));
183 l.takedamage = DAMAGE_NO;
184 l.bot_attack = false;
188 ons_debug(strcat(etos(l), " (generator) is not shielded\n"));
189 l.takedamage = DAMAGE_AIM;
193 ons_Generator_UpdateSprite(l);
195 // now update the takedamage and alpha variables on control point icons
196 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
200 ons_debug(strcat(etos(l), " (point) is shielded\n"));
203 l.goalentity.takedamage = DAMAGE_NO;
204 l.goalentity.bot_attack = false;
209 ons_debug(strcat(etos(l), " (point) is not shielded\n"));
212 l.goalentity.takedamage = DAMAGE_AIM;
213 l.goalentity.bot_attack = true;
216 ons_ControlPoint_UpdateSprite(l);
218 l = findchain(classname, "ons_captureshield");
221 l.team = l.enemy.team;
222 l.colormap = l.enemy.colormap;
228 // ===================
229 // Main Link Functions
230 // ===================
232 bool ons_Link_Send(entity this, entity to, int sendflags)
234 WriteByte(MSG_ENTITY, ENT_CLIENT_RADARLINK);
235 WriteByte(MSG_ENTITY, sendflags);
238 WriteCoord(MSG_ENTITY, self.goalentity.origin_x);
239 WriteCoord(MSG_ENTITY, self.goalentity.origin_y);
240 WriteCoord(MSG_ENTITY, self.goalentity.origin_z);
244 WriteCoord(MSG_ENTITY, self.enemy.origin_x);
245 WriteCoord(MSG_ENTITY, self.enemy.origin_y);
246 WriteCoord(MSG_ENTITY, self.enemy.origin_z);
250 WriteByte(MSG_ENTITY, self.clientcolors); // which is goalentity's color + enemy's color * 16
255 void ons_Link_CheckUpdate()
257 // TODO check if the two sides have moved (currently they won't move anyway)
258 float cc = 0, cc1 = 0, cc2 = 0;
260 if(self.goalentity.islinked || self.goalentity.iscaptured) { cc1 = (self.goalentity.team - 1) * 0x01; }
261 if(self.enemy.islinked || self.enemy.iscaptured) { cc2 = (self.enemy.team - 1) * 0x10; }
265 if(cc != self.clientcolors)
267 self.clientcolors = cc;
271 self.nextthink = time;
274 void ons_DelayedLinkSetup()
276 self.goalentity = find(world, targetname, self.target);
277 self.enemy = find(world, targetname, self.target2);
278 if(!self.goalentity) { objerror("can not find target\n"); }
279 if(!self.enemy) { objerror("can not find target2\n"); }
281 ons_debug(strcat(etos(self.goalentity), " linked with ", etos(self.enemy), "\n"));
283 self.think = ons_Link_CheckUpdate;
284 self.nextthink = time;
288 // =============================
289 // Main Control Point Functions
290 // =============================
292 int ons_ControlPoint_CanBeLinked(entity cp, int teamnumber)
294 if(cp.isgenneighbor[teamnumber]) { return 2; }
295 if(cp.iscpneighbor[teamnumber]) { return 1; }
300 int ons_ControlPoint_Attackable(entity cp, int teamnumber)
301 // -2: SAME TEAM, attackable by enemy!
306 // 3: attack it (HIGH PRIO)
307 // 4: touch it (HIGH PRIO)
315 else if(cp.goalentity)
317 // if there's already an icon built, nothing happens
318 if(cp.team == teamnumber)
320 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
321 if(a) // attackable by enemy?
322 return -2; // EMERGENCY!
325 // we know it can be linked, so no need to check
327 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
328 if(a == 2) // near our generator?
329 return 3; // EMERGENCY!
335 if(ons_ControlPoint_CanBeLinked(cp, teamnumber))
337 a = ons_ControlPoint_CanBeLinked(cp, teamnumber); // why was this here NUM_TEAM_1 + NUM_TEAM_2 - t
339 return 4; // GET THIS ONE NOW!
341 return 2; // TOUCH ME
347 void ons_ControlPoint_Icon_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
349 if(damage <= 0) { return; }
351 if (self.owner.isshielded)
353 // this is protected by a shield, so ignore the damage
354 if (time > self.pain_finished)
355 if (IS_PLAYER(attacker))
357 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
358 self.pain_finished = time + 1;
359 attacker.typehitsound += 1; // play both sounds (shield is way too quiet)
365 if(IS_PLAYER(attacker))
366 if(time - ons_notification_time[self.team] > 10)
368 play2team(self.team, SND(ONS_CONTROLPOINT_UNDERATTACK));
369 ons_notification_time[self.team] = time;
372 self.health = self.health - damage;
373 if(self.owner.iscaptured)
374 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
376 WaypointSprite_UpdateBuildFinished(self.owner.sprite, time + (self.max_health - self.health) / (self.count / ONS_CP_THINKRATE));
377 self.pain_finished = time + 1;
378 // particles on every hit
379 pointparticles(particleeffectnum(EFFECT_SPARKS), hitloc, force*-1, 1);
382 sound(self, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE+0.3, ATTEN_NORM);
384 sound(self, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE+0.3, ATTEN_NORM);
388 sound(self, CH_TRIGGER, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
389 pointparticles(particleeffectnum(EFFECT_ROCKET_EXPLODE), self.origin, '0 0 0', 1);
390 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_CPDESTROYED_), self.owner.message, attacker.netname);
392 PlayerScore_Add(attacker, SP_ONS_TAKES, 1);
393 PlayerScore_Add(attacker, SP_SCORE, 10);
395 self.owner.goalentity = world;
396 self.owner.islinked = false;
397 self.owner.iscaptured = false;
399 self.owner.colormap = 1024;
401 WaypointSprite_UpdateMaxHealth(self.owner.sprite, 0);
403 onslaught_updatelinks();
405 // Use targets now (somebody make sure this is in the right place..)
411 self.owner.waslinked = self.owner.islinked;
412 if(self.owner.model != "models/onslaught/controlpoint_pad.md3")
413 setmodel_fixsize(self.owner, MDL_ONS_CP_PAD1);
414 //setsize(self, '-32 -32 0', '32 32 8');
419 self.SendFlags |= CPSF_STATUS;
422 void ons_ControlPoint_Icon_Think()
424 self.nextthink = time + ONS_CP_THINKRATE;
426 if(autocvar_g_onslaught_cp_proxydecap)
428 int _enemy_count = 0;
429 int _friendly_count = 0;
433 FOR_EACH_PLAYER(_player)
435 if(!_player.deadflag)
437 _dist = vlen(_player.origin - self.origin);
438 if(_dist < autocvar_g_onslaught_cp_proxydecap_distance)
440 if(SAME_TEAM(_player, self))
448 _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
449 _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
451 self.health = bound(0, self.health + (_friendly_count - _enemy_count), self.max_health);
452 self.SendFlags |= CPSF_STATUS;
455 ons_ControlPoint_Icon_Damage(self, self, 1, 0, self.origin, '0 0 0');
460 if (time > self.pain_finished + 5)
462 if(self.health < self.max_health)
464 self.health = self.health + self.count;
465 if (self.health >= self.max_health)
466 self.health = self.max_health;
467 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
471 if(self.owner.islinked != self.owner.waslinked)
473 // unteam the spawnpoint if needed
474 int t = self.owner.team;
475 if(!self.owner.islinked)
485 self.owner.waslinked = self.owner.islinked;
489 if(random() < 0.6 - self.health / self.max_health)
491 Send_Effect(EFFECT_ELECTRIC_SPARKS, self.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
494 sound(self, CH_PAIN, SND_ONS_SPARK1, VOL_BASE, ATTEN_NORM);
495 else if (random() > 0.5)
496 sound(self, CH_PAIN, SND_ONS_SPARK2, VOL_BASE, ATTEN_NORM);
500 void ons_ControlPoint_Icon_BuildThink()
504 self.nextthink = time + ONS_CP_THINKRATE;
506 // only do this if there is power
507 a = ons_ControlPoint_CanBeLinked(self.owner, self.owner.team);
511 self.health = self.health + self.count;
513 self.SendFlags |= CPSF_STATUS;
515 if (self.health >= self.max_health)
517 self.health = self.max_health;
518 self.count = autocvar_g_onslaught_cp_regen * ONS_CP_THINKRATE; // slow repair rate from now on
519 self.think = ons_ControlPoint_Icon_Think;
520 sound(self, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILT, VOL_BASE, ATTEN_NORM);
521 self.owner.iscaptured = true;
522 self.solid = SOLID_BBOX;
524 Send_Effect(EFFECT_CAP(self.owner.team), self.owner.origin, '0 0 0', 1);
526 WaypointSprite_UpdateMaxHealth(self.owner.sprite, self.max_health);
527 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
529 if(IS_PLAYER(self.owner.ons_toucher))
531 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ONSLAUGHT_CAPTURE, self.owner.ons_toucher.netname, self.owner.message);
532 Send_Notification(NOTIF_ALL_EXCEPT, self.owner.ons_toucher, MSG_CENTER, APP_TEAM_ENT_4(self.owner.ons_toucher, CENTER_ONS_CAPTURE_), self.owner.message);
533 Send_Notification(NOTIF_ONE, self.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE, self.owner.message);
534 PlayerScore_Add(self.owner.ons_toucher, SP_ONS_CAPS, 1);
535 PlayerTeamScore_AddScore(self.owner.ons_toucher, 10);
538 self.owner.ons_toucher = world;
540 onslaught_updatelinks();
542 // Use targets now (somebody make sure this is in the right place..)
548 self.SendFlags |= CPSF_SETUP;
550 if(self.owner.model != MDL_ONS_CP_PAD2.model_str())
551 setmodel_fixsize(self.owner, MDL_ONS_CP_PAD2);
553 if(random() < 0.9 - self.health / self.max_health)
554 Send_Effect(EFFECT_RAGE, self.origin + 10 * randomvec(), '0 0 -1', 1);
557 void onslaught_controlpoint_icon_link(entity e, void() spawnproc);
559 void ons_ControlPoint_Icon_Spawn(entity cp, entity player)
563 setsize(e, CPICON_MIN, CPICON_MAX);
564 setorigin(e, cp.origin + CPICON_OFFSET);
566 e.classname = "onslaught_controlpoint_icon";
568 e.max_health = autocvar_g_onslaught_cp_health;
569 e.health = autocvar_g_onslaught_cp_buildhealth;
571 e.takedamage = DAMAGE_AIM;
573 e.event_damage = ons_ControlPoint_Icon_Damage;
574 e.team = player.team;
575 e.colormap = 1024 + (e.team - 1) * 17;
576 e.count = (e.max_health - e.health) * ONS_CP_THINKRATE / autocvar_g_onslaught_cp_buildtime; // how long it takes to build
578 sound(e, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILD, VOL_BASE, ATTEN_NORM);
582 cp.colormap = e.colormap;
584 Send_Effect(EFFECT_FLAG_TOUCH(player.team), e.origin, '0 0 0', 1);
586 WaypointSprite_UpdateBuildFinished(cp.sprite, time + (e.max_health - e.health) / (e.count / ONS_CP_THINKRATE));
587 WaypointSprite_UpdateRule(cp.sprite,cp.team,SPRITERULE_TEAMPLAY);
588 cp.sprite.SendFlags |= 16;
590 onslaught_controlpoint_icon_link(e, ons_ControlPoint_Icon_BuildThink);
593 entity ons_ControlPoint_Waypoint(entity e)
597 int a = ons_ControlPoint_Attackable(e, e.team);
599 if(a == -2) { return WP_OnsCPDefend; } // defend now
600 if(a == -1 || a == 1 || a == 2) { return WP_OnsCP; } // touch
601 if(a == 3 || a == 4) { return WP_OnsCPAttack; } // attack
609 void ons_ControlPoint_UpdateSprite(entity e)
611 entity s1 = ons_ControlPoint_Waypoint(e);
612 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
615 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));
617 if(e.lastteam != e.team + 2 || e.lastshielded != sh || e.iscaptured != e.lastcaptured)
619 if(e.iscaptured) // don't mess up build bars!
623 WaypointSprite_UpdateMaxHealth(e.sprite, 0);
627 WaypointSprite_UpdateMaxHealth(e.sprite, e.goalentity.max_health);
628 WaypointSprite_UpdateHealth(e.sprite, e.goalentity.health);
634 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, false));
636 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
641 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, false));
643 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
645 WaypointSprite_Ping(e.sprite);
647 e.lastteam = e.team + 2;
649 e.lastcaptured = e.iscaptured;
653 void ons_ControlPoint_Touch()
655 entity toucher = other;
658 if(IS_VEHICLE(toucher) && toucher.owner)
659 if(autocvar_g_onslaught_allow_vehicle_touch)
660 toucher = toucher.owner;
664 if(!IS_PLAYER(toucher)) { return; }
665 if(toucher.frozen) { return; }
666 if(toucher.deadflag != DEAD_NO) { return; }
668 if ( SAME_TEAM(self,toucher) )
669 if ( self.iscaptured )
671 if(time <= toucher.teleport_antispam)
672 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT_ANTISPAM, rint(toucher.teleport_antispam - time));
674 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
677 attackable = ons_ControlPoint_Attackable(self, toucher.team);
678 if(attackable != 2 && attackable != 4)
680 // we've verified that this player has a legitimate claim to this point,
681 // so start building the captured point icon (which only captures this
682 // point if it successfully builds without being destroyed first)
683 ons_ControlPoint_Icon_Spawn(self, toucher);
685 self.ons_toucher = toucher;
687 onslaught_updatelinks();
690 void ons_ControlPoint_Think()
692 self.nextthink = time + ONS_CP_THINKRATE;
693 CSQCMODEL_AUTOUPDATE(self);
696 void ons_ControlPoint_Reset()
699 remove(self.goalentity);
701 self.goalentity = world;
703 self.colormap = 1024;
704 self.iscaptured = false;
705 self.islinked = false;
706 self.isshielded = true;
707 self.think = ons_ControlPoint_Think;
708 self.ons_toucher = world;
709 self.nextthink = time + ONS_CP_THINKRATE;
710 setmodel_fixsize(self, MDL_ONS_CP_PAD1);
712 WaypointSprite_UpdateMaxHealth(self.sprite, 0);
713 WaypointSprite_UpdateRule(self.sprite,self.team,SPRITERULE_TEAMPLAY);
715 onslaught_updatelinks();
718 SUB_UseTargets(); // to reset the structures, playerspawns etc.
720 CSQCMODEL_AUTOUPDATE(self);
723 void ons_DelayedControlPoint_Setup(void)
725 onslaught_updatelinks();
727 // captureshield setup
728 ons_CaptureShield_Spawn(self, false);
730 CSQCMODEL_AUTOINIT(self);
733 void ons_ControlPoint_Setup(entity cp)
736 setself(cp); // for later usage with droptofloor()
739 cp.ons_worldcpnext = ons_worldcplist; // link control point into ons_worldcplist
740 ons_worldcplist = cp;
742 cp.netname = "Control point";
744 cp.solid = SOLID_BBOX;
745 cp.movetype = MOVETYPE_NONE;
746 cp.touch = ons_ControlPoint_Touch;
747 cp.think = ons_ControlPoint_Think;
748 cp.nextthink = time + ONS_CP_THINKRATE;
749 cp.reset = ons_ControlPoint_Reset;
751 cp.iscaptured = false;
753 cp.isshielded = true;
755 if(cp.message == "") { cp.message = "a"; }
758 setmodel_fixsize(cp, MDL_ONS_CP_PAD1);
760 // control point placement
761 if((cp.spawnflags & 1) || cp.noalign) // don't drop to floor, just stay at fixed location
764 cp.movetype = MOVETYPE_NONE;
766 else // drop to floor, automatically find a platform and set that as spawn origin
768 setorigin(cp, cp.origin + '0 0 20');
772 cp.movetype = MOVETYPE_TOSS;
776 WaypointSprite_SpawnFixed(WP_Null, self.origin + CPGEN_WAYPOINT_OFFSET, self, sprite, RADARICON_NONE);
777 WaypointSprite_UpdateRule(self.sprite, self.team, SPRITERULE_TEAMPLAY);
779 InitializeEntity(cp, ons_DelayedControlPoint_Setup, INITPRIO_SETLOCATION);
783 // =========================
784 // Main Generator Functions
785 // =========================
787 entity ons_Generator_Waypoint(entity e)
790 return WP_OnsGenShielded;
794 void ons_Generator_UpdateSprite(entity e)
796 entity s1 = ons_Generator_Waypoint(e);
797 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
799 if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
801 e.lastteam = e.team + 2;
802 e.lastshielded = e.isshielded;
806 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, false));
808 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
813 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, false));
815 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
817 WaypointSprite_Ping(e.sprite);
821 void ons_GeneratorDamage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
823 if(damage <= 0) { return; }
824 if(warmup_stage || gameover) { return; }
825 if(!round_handler_IsRoundStarted()) { return; }
827 if (attacker != self)
831 // this is protected by a shield, so ignore the damage
832 if (time > self.pain_finished)
833 if (IS_PLAYER(attacker))
835 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
836 attacker.typehitsound += 1;
837 self.pain_finished = time + 1;
841 if (time > self.pain_finished)
843 self.pain_finished = time + 10;
845 FOR_EACH_REALPLAYER(head) if(SAME_TEAM(head, self)) { Send_Notification(NOTIF_ONE, head, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK); }
846 play2team(self.team, SND(ONS_GENERATOR_UNDERATTACK));
849 self.health = self.health - damage;
850 WaypointSprite_UpdateHealth(self.sprite, self.health);
851 // choose an animation frame based on health
852 self.frame = 10 * bound(0, (1 - self.health / self.max_health), 1);
853 // see if the generator is still functional, or dying
856 self.lasthealth = self.health;
860 if (attacker == self)
861 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME_));
864 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_GENDESTROYED_));
865 PlayerScore_Add(attacker, SP_SCORE, 100);
867 self.iscaptured = false;
868 self.islinked = false;
869 self.isshielded = false;
870 self.takedamage = DAMAGE_NO; // can't be hurt anymore
871 self.event_damage = func_null; // won't do anything if hurt
872 self.count = 0; // reset counter
873 self.think = func_null;
875 //self.think(); // do the first explosion now
877 WaypointSprite_UpdateMaxHealth(self.sprite, 0);
878 WaypointSprite_Ping(self.sprite);
879 //WaypointSprite_Kill(self.sprite); // can't do this yet, code too poor
881 onslaught_updatelinks();
884 // Throw some flaming gibs on damage, more damage = more chance for gib
885 if(random() < damage/220)
887 sound(self, CH_TRIGGER, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
891 // particles on every hit
892 Send_Effect(EFFECT_SPARKS, hitloc, force * -1, 1);
896 sound(self, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE, ATTEN_NORM);
898 sound(self, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE, ATTEN_NORM);
901 self.SendFlags |= GSF_STATUS;
904 void ons_GeneratorThink()
907 self.nextthink = time + GEN_THINKRATE;
910 if(!self.isshielded && self.wait < time)
912 self.wait = time + 5;
913 FOR_EACH_REALPLAYER(e)
915 if(SAME_TEAM(e, self))
917 Send_Notification(NOTIF_ONE, e, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM);
918 soundto(MSG_ONE, e, CHAN_AUTO, SND(KH_ALARM), VOL_BASE, ATTEN_NONE); // FIXME: unique sound?
921 Send_Notification(NOTIF_ONE, e, MSG_CENTER, APP_TEAM_NUM_4(self.team, CENTER_ONS_NOTSHIELDED_));
927 void ons_GeneratorReset()
929 self.team = self.team_saved;
930 self.lasthealth = self.max_health = self.health = autocvar_g_onslaught_gen_health;
931 self.takedamage = DAMAGE_AIM;
932 self.bot_attack = true;
933 self.iscaptured = true;
934 self.islinked = true;
935 self.isshielded = true;
936 self.event_damage = ons_GeneratorDamage;
937 self.think = ons_GeneratorThink;
938 self.nextthink = time + GEN_THINKRATE;
940 Net_LinkEntity(self, false, 0, generator_send);
942 self.SendFlags = GSF_SETUP; // just incase
943 self.SendFlags |= GSF_STATUS;
945 WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
946 WaypointSprite_UpdateHealth(self.sprite, self.health);
947 WaypointSprite_UpdateRule(self.sprite,self.team,SPRITERULE_TEAMPLAY);
949 onslaught_updatelinks();
952 void ons_DelayedGeneratorSetup()
955 waypoint_spawnforitem_force(self, self.origin);
956 self.nearestwaypointtimeout = 0; // activate waypointing again
957 self.bot_basewaypoint = self.nearestwaypoint;
959 // captureshield setup
960 ons_CaptureShield_Spawn(self, true);
962 onslaught_updatelinks();
964 Net_LinkEntity(self, false, 0, generator_send);
968 void onslaught_generator_touch()
970 if ( IS_PLAYER(other) )
971 if ( SAME_TEAM(self,other) )
972 if ( self.iscaptured )
974 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_TELEPORT);
978 void ons_GeneratorSetup(entity gen) // called when spawning a generator entity on the map as a spawnfunc
981 int teamnumber = gen.team;
982 setself(gen); // for later usage with droptofloor()
985 gen.ons_worldgeneratornext = ons_worldgeneratorlist; // link generator into ons_worldgeneratorlist
986 ons_worldgeneratorlist = gen;
988 gen.netname = sprintf("%s generator", Team_ColoredFullName(teamnumber));
989 gen.classname = "onslaught_generator";
990 gen.solid = SOLID_BBOX;
991 gen.team_saved = teamnumber;
992 gen.movetype = MOVETYPE_NONE;
993 gen.lasthealth = gen.max_health = gen.health = autocvar_g_onslaught_gen_health;
994 gen.takedamage = DAMAGE_AIM;
995 gen.bot_attack = true;
996 gen.event_damage = ons_GeneratorDamage;
997 gen.reset = ons_GeneratorReset;
998 gen.think = ons_GeneratorThink;
999 gen.nextthink = time + GEN_THINKRATE;
1000 gen.iscaptured = true;
1001 gen.islinked = true;
1002 gen.isshielded = true;
1003 gen.touch = onslaught_generator_touch;
1006 // model handled by CSQC
1007 setsize(gen, GENERATOR_MIN, GENERATOR_MAX);
1008 setorigin(gen, (gen.origin + CPGEN_SPAWN_OFFSET));
1009 gen.colormap = 1024 + (teamnumber - 1) * 17;
1011 // generator placement
1016 WaypointSprite_SpawnFixed(WP_Null, self.origin + CPGEN_WAYPOINT_OFFSET, self, sprite, RADARICON_NONE);
1017 WaypointSprite_UpdateRule(self.sprite, self.team, SPRITERULE_TEAMPLAY);
1018 WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
1019 WaypointSprite_UpdateHealth(self.sprite, self.health);
1021 InitializeEntity(gen, ons_DelayedGeneratorSetup, INITPRIO_SETLOCATION);
1029 int total_generators;
1030 void Onslaught_count_generators()
1033 total_generators = redowned = blueowned = yellowowned = pinkowned = 0;
1034 for(e = ons_worldgeneratorlist; e; e = e.ons_worldgeneratornext)
1037 redowned += (e.team == NUM_TEAM_1 && e.health > 0);
1038 blueowned += (e.team == NUM_TEAM_2 && e.health > 0);
1039 yellowowned += (e.team == NUM_TEAM_3 && e.health > 0);
1040 pinkowned += (e.team == NUM_TEAM_4 && e.health > 0);
1044 int Onslaught_GetWinnerTeam()
1046 int winner_team = 0;
1048 winner_team = NUM_TEAM_1;
1051 if(winner_team) return 0;
1052 winner_team = NUM_TEAM_2;
1056 if(winner_team) return 0;
1057 winner_team = NUM_TEAM_3;
1061 if(winner_team) return 0;
1062 winner_team = NUM_TEAM_4;
1066 return -1; // no generators left?
1069 #define ONS_OWNED_GENERATORS() ((redowned > 0) + (blueowned > 0) + (yellowowned > 0) + (pinkowned > 0))
1070 #define ONS_OWNED_GENERATORS_OK() (ONS_OWNED_GENERATORS() > 1)
1071 bool Onslaught_CheckWinner()
1075 if ((autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60) || (round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0))
1077 ons_stalemate = true;
1079 if (!wpforenemy_announced)
1081 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT);
1082 sound(world, CH_INFO, SND_ONS_GENERATOR_DECAY, VOL_BASE, ATTEN_NONE);
1084 wpforenemy_announced = true;
1087 entity tmp_entity; // temporary entity
1089 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext) if(time >= tmp_entity.ons_overtime_damagedelay)
1091 // tmp_entity.max_health / 300 gives 5 minutes of overtime.
1092 // control points reduce the overtime duration.
1094 for(e = ons_worldcplist; e; e = e.ons_worldcpnext)
1096 if(DIFF_TEAM(e, tmp_entity))
1101 if(autocvar_g_campaign && autocvar__campaign_testrun)
1102 d = d * tmp_entity.max_health;
1104 d = d * tmp_entity.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
1106 Damage(tmp_entity, tmp_entity, tmp_entity, d, DEATH_HURTTRIGGER.m_id, tmp_entity.origin, '0 0 0');
1108 tmp_entity.sprite.SendFlags |= 16;
1110 tmp_entity.ons_overtime_damagedelay = time + 1;
1113 else { wpforenemy_announced = false; ons_stalemate = false; }
1115 Onslaught_count_generators();
1117 if(ONS_OWNED_GENERATORS_OK())
1120 int winner_team = Onslaught_GetWinnerTeam();
1124 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
1125 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
1126 TeamScore_AddToTeam(winner_team, ST_ONS_CAPS, +1);
1128 else if(winner_team == -1)
1130 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
1131 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
1134 ons_stalemate = false;
1136 play2all(SND(CTF_CAPTURE(winner_team)));
1138 round_handler_Init(7, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
1142 e.ons_roundlost = true;
1143 e.player_blocked = true;
1151 bool Onslaught_CheckPlayers()
1156 void Onslaught_RoundStart()
1159 FOR_EACH_PLAYER(tmp_entity) { tmp_entity.player_blocked = false; }
1161 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1162 tmp_entity.sprite.SendFlags |= 16;
1164 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1165 tmp_entity.sprite.SendFlags |= 16;
1173 // NOTE: LEGACY CODE, needs to be re-written!
1175 void havocbot_goalrating_ons_offenseitems(float ratingscale, vector org, float sradius)
1180 bool needarmor = false, needweapons = false;
1182 // Needs armor/health?
1188 for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
1191 if(self.weapons & WepSet_FromWeapon(i))
1199 if(!needweapons && !needarmor)
1202 ons_debug(strcat(self.netname, " needs weapons ", ftos(needweapons) , "\n"));
1203 ons_debug(strcat(self.netname, " needs armor ", ftos(needarmor) , "\n"));
1205 // See what is around
1206 head = findchainfloat(bot_pickup, true);
1209 // gather health and armor only
1211 if ( ((head.health || head.armorvalue) && needarmor) || (head.weapons && needweapons ) )
1212 if (vlen(head.origin - org) < sradius)
1214 t = head.bot_pickupevalfunc(self, head);
1216 navigation_routerating(head, t * ratingscale, 500);
1222 void havocbot_role_ons_setrole(entity bot, int role)
1224 ons_debug(strcat(bot.netname," switched to "));
1227 case HAVOCBOT_ONS_ROLE_DEFENSE:
1228 ons_debug("defense");
1229 bot.havocbot_role = havocbot_role_ons_defense;
1230 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE;
1231 bot.havocbot_role_timeout = 0;
1233 case HAVOCBOT_ONS_ROLE_ASSISTANT:
1234 ons_debug("assistant");
1235 bot.havocbot_role = havocbot_role_ons_assistant;
1236 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT;
1237 bot.havocbot_role_timeout = 0;
1239 case HAVOCBOT_ONS_ROLE_OFFENSE:
1240 ons_debug("offense");
1241 bot.havocbot_role = havocbot_role_ons_offense;
1242 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE;
1243 bot.havocbot_role_timeout = 0;
1249 int havocbot_ons_teamcount(entity bot, int role)
1254 FOR_EACH_PLAYER(head)
1255 if(SAME_TEAM(head, self))
1256 if(head.havocbot_role_flags & role)
1262 void havocbot_goalrating_ons_controlpoints_attack(float ratingscale)
1264 entity cp, cp1, cp2, best, pl, wp;
1265 float radius, bestvalue;
1269 // Filter control points
1270 for(cp2 = ons_worldcplist; cp2; cp2 = cp2.ons_worldcpnext)
1273 cp2.wpconsidered = false;
1278 // Ignore owned controlpoints
1279 if(!(cp2.isgenneighbor[self.team] || cp2.iscpneighbor[self.team]))
1282 // Count team mates interested in this control point
1283 // (easier and cleaner than keeping counters per cp and teams)
1285 if(SAME_TEAM(pl, self))
1286 if(pl.havocbot_role_flags & HAVOCBOT_ONS_ROLE_OFFENSE)
1287 if(pl.havocbot_ons_target==cp2)
1290 // NOTE: probably decrease the cost of attackable control points
1292 cp2.wpconsidered = true;
1295 // We'll consider only the best case
1296 bestvalue = 99999999999;
1298 for(cp1 = ons_worldcplist; cp1; cp1 = cp1.ons_worldcpnext)
1300 if (!cp1.wpconsidered)
1303 if(cp1.wpcost<bestvalue)
1305 bestvalue = cp1.wpcost;
1307 self.havocbot_ons_target = cp1;
1314 ons_debug(strcat(self.netname, " chose cp ranked ", ftos(bestvalue), "\n"));
1318 // Should be attacked
1319 // Rate waypoints near it
1322 bestvalue = 99999999999;
1323 for(radius=0; radius<1000 && !found; radius+=500)
1325 for(wp=findradius(cp.origin,radius); wp; wp=wp.chain)
1327 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
1328 if(wp.classname=="waypoint")
1329 if(checkpvs(wp.origin,cp))
1332 if(wp.cnt<bestvalue)
1343 navigation_routerating(best, ratingscale, 10000);
1346 self.havocbot_attack_time = 0;
1347 if(checkpvs(self.view_ofs,cp))
1348 if(checkpvs(self.view_ofs,best))
1349 self.havocbot_attack_time = time + 2;
1353 navigation_routerating(cp, ratingscale, 10000);
1355 ons_debug(strcat(self.netname, " found an attackable controlpoint at ", vtos(cp.origin) ,"\n"));
1359 // Should be touched
1360 ons_debug(strcat(self.netname, " found a touchable controlpoint at ", vtos(cp.origin) ,"\n"));
1363 // Look for auto generated waypoint
1364 if (!bot_waypoints_for_items)
1365 for (wp = findradius(cp.origin,100); wp; wp = wp.chain)
1367 if(wp.classname=="waypoint")
1369 navigation_routerating(wp, ratingscale, 10000);
1374 // Nothing found, rate the controlpoint itself
1376 navigation_routerating(cp, ratingscale, 10000);
1380 bool havocbot_goalrating_ons_generator_attack(float ratingscale)
1382 entity g, wp, bestwp;
1386 for(g = ons_worldgeneratorlist; g; g = g.ons_worldgeneratornext)
1388 if(SAME_TEAM(g, self) || g.isshielded)
1391 // Should be attacked
1392 // Rate waypoints near it
1397 for(wp=findradius(g.origin,400); wp; wp=wp.chain)
1399 if(wp.classname=="waypoint")
1400 if(checkpvs(wp.origin,g))
1413 ons_debug("waypoints found around generator\n");
1414 navigation_routerating(bestwp, ratingscale, 10000);
1417 self.havocbot_attack_time = 0;
1418 if(checkpvs(self.view_ofs,g))
1419 if(checkpvs(self.view_ofs,bestwp))
1420 self.havocbot_attack_time = time + 5;
1426 ons_debug("generator found without waypoints around\n");
1427 // if there aren't waypoints near the generator go straight to it
1428 navigation_routerating(g, ratingscale, 10000);
1429 self.havocbot_attack_time = 0;
1436 void havocbot_role_ons_offense()
1438 if(self.deadflag != DEAD_NO)
1440 self.havocbot_attack_time = 0;
1441 havocbot_ons_reset_role(self);
1445 // Set the role timeout if necessary
1446 if (!self.havocbot_role_timeout)
1447 self.havocbot_role_timeout = time + 120;
1449 if (time > self.havocbot_role_timeout)
1451 havocbot_ons_reset_role(self);
1455 if(self.havocbot_attack_time>time)
1458 if (self.bot_strategytime < time)
1460 navigation_goalrating_start();
1461 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
1462 if(!havocbot_goalrating_ons_generator_attack(20000))
1463 havocbot_goalrating_ons_controlpoints_attack(20000);
1464 havocbot_goalrating_ons_offenseitems(10000, self.origin, 10000);
1465 navigation_goalrating_end();
1467 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
1471 void havocbot_role_ons_assistant()
1473 havocbot_ons_reset_role(self);
1476 void havocbot_role_ons_defense()
1478 havocbot_ons_reset_role(self);
1481 void havocbot_ons_reset_role(entity bot)
1486 if(self.deadflag != DEAD_NO)
1489 bot.havocbot_ons_target = world;
1491 // TODO: Defend control points or generator if necessary
1493 // if there is only me on the team switch to offense
1495 FOR_EACH_PLAYER(head)
1496 if(SAME_TEAM(head, self))
1501 havocbot_role_ons_setrole(bot, HAVOCBOT_ONS_ROLE_OFFENSE);
1505 havocbot_role_ons_setrole(bot, HAVOCBOT_ONS_ROLE_OFFENSE);
1510 * Find control point or generator owned by the same team self which is nearest to pos
1511 * if max_dist is positive, only control points within this range will be considered
1513 entity ons_Nearest_ControlPoint(vector pos, float max_dist)
1515 entity tmp_entity, closest_target = world;
1516 tmp_entity = findchain(classname, "onslaught_controlpoint");
1519 if(SAME_TEAM(tmp_entity, self))
1520 if(tmp_entity.iscaptured)
1521 if(max_dist <= 0 || vlen(tmp_entity.origin - pos) <= max_dist)
1522 if(vlen(tmp_entity.origin - pos) <= vlen(closest_target.origin - pos) || closest_target == world)
1523 closest_target = tmp_entity;
1524 tmp_entity = tmp_entity.chain;
1526 tmp_entity = findchain(classname, "onslaught_generator");
1529 if(SAME_TEAM(tmp_entity, self))
1530 if(max_dist <= 0 || vlen(tmp_entity.origin - pos) < max_dist)
1531 if(vlen(tmp_entity.origin - pos) <= vlen(closest_target.origin - pos) || closest_target == world)
1532 closest_target = tmp_entity;
1533 tmp_entity = tmp_entity.chain;
1536 return closest_target;
1540 * Find control point or generator owned by the same team self which is nearest to pos
1541 * if max_dist is positive, only control points within this range will be considered
1542 * This function only check distances on the XY plane, disregarding Z
1544 entity ons_Nearest_ControlPoint_2D(vector pos, float max_dist)
1546 entity tmp_entity, closest_target = world;
1548 float smallest_distance = 0, distance;
1550 tmp_entity = findchain(classname, "onslaught_controlpoint");
1553 delta = tmp_entity.origin - pos;
1555 distance = vlen(delta);
1557 if(SAME_TEAM(tmp_entity, self))
1558 if(tmp_entity.iscaptured)
1559 if(max_dist <= 0 || distance <= max_dist)
1560 if(closest_target == world || distance <= smallest_distance )
1562 closest_target = tmp_entity;
1563 smallest_distance = distance;
1566 tmp_entity = tmp_entity.chain;
1568 tmp_entity = findchain(classname, "onslaught_generator");
1571 delta = tmp_entity.origin - pos;
1573 distance = vlen(delta);
1575 if(SAME_TEAM(tmp_entity, self))
1576 if(max_dist <= 0 || distance <= max_dist)
1577 if(closest_target == world || distance <= smallest_distance )
1579 closest_target = tmp_entity;
1580 smallest_distance = distance;
1583 tmp_entity = tmp_entity.chain;
1586 return closest_target;
1589 * find the number of control points and generators in the same team as self
1591 int ons_Count_SelfControlPoints()
1594 tmp_entity = findchain(classname, "onslaught_controlpoint");
1598 if(SAME_TEAM(tmp_entity, self))
1599 if(tmp_entity.iscaptured)
1601 tmp_entity = tmp_entity.chain;
1603 tmp_entity = findchain(classname, "onslaught_generator");
1606 if(SAME_TEAM(tmp_entity, self))
1608 tmp_entity = tmp_entity.chain;
1614 * Teleport player to a random position near tele_target
1615 * if tele_effects is true, teleport sound+particles are created
1616 * return false on failure
1618 bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effects)
1626 for(i = 0; i < 16; ++i)
1628 theta = random() * 2 * M_PI;
1632 loc *= random() * range;
1634 loc += tele_target.origin + '0 0 128';
1636 tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, player);
1637 if(trace_fraction == 1.0 && !trace_startsolid)
1639 traceline(tele_target.origin, loc, MOVE_NOMONSTERS, tele_target); // double check to make sure we're not spawning outside the world
1640 if(trace_fraction == 1.0 && !trace_startsolid)
1644 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
1645 sound (player, CH_TRIGGER, SND_TELEPORT, VOL_BASE, ATTEN_NORM);
1647 setorigin(player, loc);
1648 player.angles = '0 1 0' * ( theta * RAD2DEG + 180 );
1649 makevectors(player.angles);
1650 player.fixangle = true;
1651 player.teleport_antispam = time + autocvar_g_onslaught_teleport_wait;
1654 Send_Effect(EFFECT_TELEPORT, player.origin + v_forward * 32, '0 0 0', 1);
1667 MUTATOR_HOOKFUNCTION(ons_ResetMap)
1672 e.ons_roundlost = false;
1673 e.ons_deathloc = '0 0 0';
1674 WITH(entity, self, e, PutClientInServer());
1679 MUTATOR_HOOKFUNCTION(ons_RemovePlayer)
1681 self.ons_deathloc = '0 0 0';
1685 MUTATOR_HOOKFUNCTION(ons_PlayerSpawn)
1687 if(!round_handler_IsRoundStarted())
1689 self.player_blocked = true;
1694 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1696 l.sprite.SendFlags |= 16;
1698 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1700 l.sprite.SendFlags |= 16;
1703 if(ons_stalemate) { Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); }
1705 if ( autocvar_g_onslaught_spawn_choose )
1706 if ( self.ons_spawn_by )
1707 if ( ons_Teleport(self,self.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) )
1709 self.ons_spawn_by = world;
1713 if(autocvar_g_onslaught_spawn_at_controlpoints)
1714 if(random() <= autocvar_g_onslaught_spawn_at_controlpoints_chance)
1716 float random_target = autocvar_g_onslaught_spawn_at_controlpoints_random;
1717 entity tmp_entity, closest_target = world;
1718 vector spawn_loc = self.ons_deathloc;
1720 // new joining player or round reset, don't bother checking
1721 if(spawn_loc == '0 0 0') { return false; }
1723 if(random_target) { RandomSelection_Init(); }
1725 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1727 if(SAME_TEAM(tmp_entity, self))
1729 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1730 else if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world)
1731 closest_target = tmp_entity;
1734 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1740 for(i = 0; i < 10; ++i)
1742 loc = closest_target.origin + '0 0 96';
1743 loc += ('0 1 0' * random()) * 128;
1744 tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, self);
1745 if(trace_fraction == 1.0 && !trace_startsolid)
1747 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
1748 if(trace_fraction == 1.0 && !trace_startsolid)
1750 setorigin(self, loc);
1751 self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1759 if(autocvar_g_onslaught_spawn_at_generator)
1760 if(random() <= autocvar_g_onslaught_spawn_at_generator_chance)
1762 float random_target = autocvar_g_onslaught_spawn_at_generator_random;
1763 entity tmp_entity, closest_target = world;
1764 vector spawn_loc = self.ons_deathloc;
1766 // new joining player or round reset, don't bother checking
1767 if(spawn_loc == '0 0 0') { return false; }
1769 if(random_target) { RandomSelection_Init(); }
1771 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1774 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1777 if(SAME_TEAM(tmp_entity, self))
1778 if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world)
1779 closest_target = tmp_entity;
1783 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1789 for(i = 0; i < 10; ++i)
1791 loc = closest_target.origin + '0 0 128';
1792 loc += ('0 1 0' * random()) * 256;
1793 tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, self);
1794 if(trace_fraction == 1.0 && !trace_startsolid)
1796 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
1797 if(trace_fraction == 1.0 && !trace_startsolid)
1799 setorigin(self, loc);
1800 self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1811 MUTATOR_HOOKFUNCTION(ons_PlayerDies)
1813 frag_target.ons_deathloc = frag_target.origin;
1815 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1817 l.sprite.SendFlags |= 16;
1819 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1821 l.sprite.SendFlags |= 16;
1824 if ( autocvar_g_onslaught_spawn_choose )
1825 if ( ons_Count_SelfControlPoints() > 1 )
1826 stuffcmd(self, "qc_cmd_cl hud clickradar\n");
1831 MUTATOR_HOOKFUNCTION(ons_MonsterThink)
1833 entity e = find(world, targetname, self.target);
1840 void ons_MonsterSpawn_Delayed()
1842 entity e, own = self.owner;
1844 if(!own) { remove(self); return; }
1848 e = find(world, target, own.targetname);
1861 MUTATOR_HOOKFUNCTION(ons_MonsterSpawn)
1865 InitializeEntity(e, ons_MonsterSpawn_Delayed, INITPRIO_FINDTARGET);
1870 void ons_TurretSpawn_Delayed()
1872 entity e, own = self.owner;
1874 if(!own) { remove(self); return; }
1878 e = find(world, target, own.targetname);
1882 own.active = ACTIVE_NOT;
1892 MUTATOR_HOOKFUNCTION(ons_TurretSpawn)
1896 InitializeEntity(e, ons_TurretSpawn_Delayed, INITPRIO_FINDTARGET);
1901 MUTATOR_HOOKFUNCTION(ons_BotRoles)
1903 havocbot_ons_reset_role(self);
1907 MUTATOR_HOOKFUNCTION(ons_GetTeamCount)
1909 // onslaught is special
1911 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1913 switch(tmp_entity.team)
1915 case NUM_TEAM_1: c1 = 0; break;
1916 case NUM_TEAM_2: c2 = 0; break;
1917 case NUM_TEAM_3: c3 = 0; break;
1918 case NUM_TEAM_4: c4 = 0; break;
1925 MUTATOR_HOOKFUNCTION(ons_SpectateCopy)
1927 self.ons_roundlost = other.ons_roundlost; // make spectators see it too
1931 MUTATOR_HOOKFUNCTION(ons_SV_ParseClientCommand)
1933 if(MUTATOR_RETURNVALUE) // command was already handled?
1936 if ( cmd_name == "ons_spawn" )
1938 vector pos = self.origin;
1940 pos_x = stof(argv(1));
1942 pos_y = stof(argv(2));
1944 pos_z = stof(argv(3));
1946 if ( IS_PLAYER(self) )
1950 entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
1952 if ( !source_point && self.health > 0 )
1954 sprint(self, "\nYou need to be next to a control point\n");
1959 entity closest_target = ons_Nearest_ControlPoint_2D(pos, autocvar_g_onslaught_click_radius);
1961 if ( closest_target == world )
1963 sprint(self, "\nNo control point found\n");
1967 if ( self.health <= 0 )
1969 self.ons_spawn_by = closest_target;
1970 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
1974 if ( source_point == closest_target )
1976 sprint(self, "\nTeleporting to the same point\n");
1980 if ( !ons_Teleport(self,closest_target,autocvar_g_onslaught_teleport_radius,true) )
1981 sprint(self, "\nUnable to teleport there\n");
1987 sprint(self, "\nNo teleportation for you\n");
1995 MUTATOR_HOOKFUNCTION(ons_PlayerUseKey)
1997 if(MUTATOR_RETURNVALUE || gameover) { return false; }
1999 if((time > self.teleport_antispam) && (self.deadflag == DEAD_NO) && !self.vehicle)
2001 entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
2004 stuffcmd(self, "qc_cmd_cl hud clickradar\n");
2012 MUTATOR_HOOKFUNCTION(ons_PlayHitsound)
2014 return (frag_victim.classname == "onslaught_generator" && !frag_victim.isshielded)
2015 || (frag_victim.classname == "onslaught_controlpoint_icon" && !frag_victim.owner.isshielded);
2022 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
2023 Link between control points.
2025 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.
2028 "target" - first control point.
2029 "target2" - second control point.
2031 spawnfunc(onslaught_link)
2033 if(!g_onslaught) { remove(self); return; }
2035 if (self.target == "" || self.target2 == "")
2036 objerror("target and target2 must be set\n");
2038 self.ons_worldlinknext = ons_worldlinklist; // link into ons_worldlinklist
2039 ons_worldlinklist = self;
2041 InitializeEntity(self, ons_DelayedLinkSetup, INITPRIO_FINDTARGET);
2042 Net_LinkEntity(self, false, 0, ons_Link_Send);
2045 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
2046 Control point. Be sure to give this enough clearance so that the shootable part has room to exist
2048 This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
2051 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2052 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
2053 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
2056 spawnfunc(onslaught_controlpoint)
2058 if(!g_onslaught) { remove(self); return; }
2060 ons_ControlPoint_Setup(self);
2063 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
2066 spawnfunc_onslaught_link entities can target this.
2069 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
2070 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2072 spawnfunc(onslaught_generator)
2074 if(!g_onslaught) { remove(self); return; }
2075 if(!self.team) { objerror("team must be set"); }
2077 ons_GeneratorSetup(self);
2081 void ons_ScoreRules()
2083 CheckAllowedTeams(world);
2084 ScoreRules_basics(((c4>=0) ? 4 : (c3>=0) ? 3 : 2), SFL_SORT_PRIO_PRIMARY, 0, true);
2085 ScoreInfo_SetLabel_TeamScore (ST_ONS_CAPS, "destroyed", SFL_SORT_PRIO_PRIMARY);
2086 ScoreInfo_SetLabel_PlayerScore(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
2087 ScoreInfo_SetLabel_PlayerScore(SP_ONS_TAKES, "takes", 0);
2088 ScoreRules_basics_end();
2091 void ons_DelayedInit() // Do this check with a delay so we can wait for teams to be set up
2095 round_handler_Spawn(Onslaught_CheckPlayers, Onslaught_CheckWinner, Onslaught_RoundStart);
2096 round_handler_Init(5, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
2099 void ons_Initialize()
2101 ons_captureshield_force = autocvar_g_onslaught_shield_force;
2103 addstat(STAT_ROUNDLOST, AS_INT, ons_roundlost);
2105 InitializeEntity(world, ons_DelayedInit, INITPRIO_GAMETYPE);
2108 MUTATOR_DEFINITION(gamemode_onslaught)
2110 MUTATOR_HOOK(reset_map_global, ons_ResetMap, CBC_ORDER_ANY);
2111 MUTATOR_HOOK(MakePlayerObserver, ons_RemovePlayer, CBC_ORDER_ANY);
2112 MUTATOR_HOOK(ClientDisconnect, ons_RemovePlayer, CBC_ORDER_ANY);
2113 MUTATOR_HOOK(PlayerSpawn, ons_PlayerSpawn, CBC_ORDER_ANY);
2114 MUTATOR_HOOK(PlayerDies, ons_PlayerDies, CBC_ORDER_ANY);
2115 MUTATOR_HOOK(MonsterMove, ons_MonsterThink, CBC_ORDER_ANY);
2116 MUTATOR_HOOK(MonsterSpawn, ons_MonsterSpawn, CBC_ORDER_ANY);
2117 MUTATOR_HOOK(TurretSpawn, ons_TurretSpawn, CBC_ORDER_ANY);
2118 MUTATOR_HOOK(HavocBot_ChooseRole, ons_BotRoles, CBC_ORDER_ANY);
2119 MUTATOR_HOOK(GetTeamCount, ons_GetTeamCount, CBC_ORDER_ANY);
2120 MUTATOR_HOOK(SpectateCopy, ons_SpectateCopy, CBC_ORDER_ANY);
2121 MUTATOR_HOOK(SV_ParseClientCommand, ons_SV_ParseClientCommand, CBC_ORDER_ANY);
2122 MUTATOR_HOOK(PlayerUseKey, ons_PlayerUseKey, CBC_ORDER_ANY);
2123 MUTATOR_HOOK(PlayHitsound, ons_PlayHitsound, CBC_ORDER_ANY);
2127 if(time > 1) // game loads at time 1
2128 error("This is a game type and it cannot be added at runtime.");
2132 MUTATOR_ONROLLBACK_OR_REMOVE
2134 // we actually cannot roll back ons_Initialize here
2135 // BUT: we don't need to! If this gets called, adding always
2141 LOG_INFO("This is a game type and it cannot be removed at runtime.");