2 #include "../controlpoint.qh"
3 #include "../generator.qh"
7 float autocvar_g_onslaught_debug;
8 float autocvar_g_onslaught_teleport_wait;
9 bool autocvar_g_onslaught_spawn_at_controlpoints;
10 bool autocvar_g_onslaught_spawn_at_generator;
11 float autocvar_g_onslaught_cp_proxydecap;
12 float autocvar_g_onslaught_cp_proxydecap_distance = 512;
13 float autocvar_g_onslaught_cp_proxydecap_dps = 100;
14 float autocvar_g_onslaught_spawn_at_controlpoints_chance = 0.5;
15 float autocvar_g_onslaught_spawn_at_controlpoints_random;
16 float autocvar_g_onslaught_spawn_at_generator_chance;
17 float autocvar_g_onslaught_spawn_at_generator_random;
18 float autocvar_g_onslaught_cp_buildhealth;
19 float autocvar_g_onslaught_cp_buildtime;
20 float autocvar_g_onslaught_cp_health;
21 float autocvar_g_onslaught_cp_regen;
22 float autocvar_g_onslaught_gen_health;
23 float autocvar_g_onslaught_shield_force = 100;
24 float autocvar_g_onslaught_allow_vehicle_touch;
25 float autocvar_g_onslaught_round_timelimit;
26 float autocvar_g_onslaught_point_limit;
27 float autocvar_g_onslaught_warmup;
28 float autocvar_g_onslaught_teleport_radius;
29 float autocvar_g_onslaught_spawn_choose;
30 float autocvar_g_onslaught_click_radius;
32 void FixSize(entity e);
34 // =======================
35 // CaptureShield Functions
36 // =======================
38 bool ons_CaptureShield_Customize()
40 entity e = WaypointSprite_getviewentity(other);
42 if(!self.enemy.isshielded && (ons_ControlPoint_Attackable(self.enemy, e.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return false; }
43 if(SAME_TEAM(self, e)) { return false; }
48 void ons_CaptureShield_Touch()
50 if(!self.enemy.isshielded && (ons_ControlPoint_Attackable(self.enemy, other.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return; }
51 if(!IS_PLAYER(other)) { return; }
52 if(SAME_TEAM(other, self)) { return; }
54 vector mymid = (self.absmin + self.absmax) * 0.5;
55 vector othermid = (other.absmin + other.absmax) * 0.5;
57 Damage(other, self, self, 0, DEATH_HURTTRIGGER.m_id, mymid, normalize(othermid - mymid) * ons_captureshield_force);
59 if(IS_REAL_CLIENT(other))
61 play2(other, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
63 if(self.enemy.classname == "onslaught_generator")
64 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_GENERATOR_SHIELDED);
66 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_CONTROLPOINT_SHIELDED);
70 void ons_CaptureShield_Reset()
72 self.colormap = self.enemy.colormap;
73 self.team = self.enemy.team;
76 void ons_CaptureShield_Spawn(entity generator, bool is_generator)
78 entity shield = spawn();
80 shield.enemy = generator;
81 shield.team = generator.team;
82 shield.colormap = generator.colormap;
83 shield.reset = ons_CaptureShield_Reset;
84 shield.touch = ons_CaptureShield_Touch;
85 shield.customizeentityforclient = ons_CaptureShield_Customize;
86 shield.classname = "ons_captureshield";
87 shield.effects = EF_ADDITIVE;
88 shield.movetype = MOVETYPE_NOCLIP;
89 shield.solid = SOLID_TRIGGER;
90 shield.avelocity = '7 0 11';
92 shield.model = ((is_generator) ? "models/onslaught/generator_shield.md3" : "models/onslaught/controlpoint_shield.md3");
94 precache_model(shield.model);
95 setorigin(shield, generator.origin);
96 _setmodel(shield, shield.model);
97 setsize(shield, shield.scale * shield.mins, shield.scale * shield.maxs);
105 void ons_debug(string input)
107 switch(autocvar_g_onslaught_debug)
109 case 1: LOG_TRACE(input); break;
110 case 2: LOG_INFO(input); break;
114 void setmodel_fixsize(entity e, Model m)
120 void onslaught_updatelinks()
123 // first check if the game has ended
124 ons_debug("--- updatelinks ---\n");
125 // mark generators as being shielded and networked
126 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
129 ons_debug(strcat(etos(l), " (generator) belongs to team ", ftos(l.team), "\n"));
131 ons_debug(strcat(etos(l), " (generator) is destroyed\n"));
132 l.islinked = l.iscaptured;
133 l.isshielded = l.iscaptured;
134 l.sprite.SendFlags |= 16;
136 // mark points as shielded and not networked
137 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
142 for(i = 0; i < 17; ++i) { l.isgenneighbor[i] = false; l.iscpneighbor[i] = false; }
143 ons_debug(strcat(etos(l), " (point) belongs to team ", ftos(l.team), "\n"));
144 l.sprite.SendFlags |= 16;
146 // flow power outward from the generators through the network
151 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
153 // if both points are captured by the same team, and only one of
154 // them is powered, mark the other one as powered as well
155 if (l.enemy.iscaptured && l.goalentity.iscaptured)
156 if (l.enemy.islinked != l.goalentity.islinked)
157 if(SAME_TEAM(l.enemy, l.goalentity))
159 if (!l.goalentity.islinked)
162 l.goalentity.islinked = true;
163 ons_debug(strcat(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)\n"));
165 else if (!l.enemy.islinked)
168 l.enemy.islinked = true;
169 ons_debug(strcat(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)\n"));
174 // now that we know which points are powered we can mark their neighbors
175 // as unshielded if team differs
176 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
178 if (l.goalentity.islinked)
180 if(DIFF_TEAM(l.goalentity, l.enemy))
182 ons_debug(strcat(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)\n"));
183 l.enemy.isshielded = false;
185 if(l.goalentity.classname == "onslaught_generator")
186 l.enemy.isgenneighbor[l.goalentity.team] = true;
188 l.enemy.iscpneighbor[l.goalentity.team] = true;
190 if (l.enemy.islinked)
192 if(DIFF_TEAM(l.goalentity, l.enemy))
194 ons_debug(strcat(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)\n"));
195 l.goalentity.isshielded = false;
197 if(l.enemy.classname == "onslaught_generator")
198 l.goalentity.isgenneighbor[l.enemy.team] = true;
200 l.goalentity.iscpneighbor[l.enemy.team] = true;
203 // now update the generators
204 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
208 ons_debug(strcat(etos(l), " (generator) is shielded\n"));
209 l.takedamage = DAMAGE_NO;
210 l.bot_attack = false;
214 ons_debug(strcat(etos(l), " (generator) is not shielded\n"));
215 l.takedamage = DAMAGE_AIM;
219 ons_Generator_UpdateSprite(l);
221 // now update the takedamage and alpha variables on control point icons
222 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
226 ons_debug(strcat(etos(l), " (point) is shielded\n"));
229 l.goalentity.takedamage = DAMAGE_NO;
230 l.goalentity.bot_attack = false;
235 ons_debug(strcat(etos(l), " (point) is not shielded\n"));
238 l.goalentity.takedamage = DAMAGE_AIM;
239 l.goalentity.bot_attack = true;
242 ons_ControlPoint_UpdateSprite(l);
244 l = findchain(classname, "ons_captureshield");
247 l.team = l.enemy.team;
248 l.colormap = l.enemy.colormap;
254 // ===================
255 // Main Link Functions
256 // ===================
258 bool ons_Link_Send(entity this, entity to, int sendflags)
260 WriteByte(MSG_ENTITY, ENT_CLIENT_RADARLINK);
261 WriteByte(MSG_ENTITY, sendflags);
264 WriteCoord(MSG_ENTITY, self.goalentity.origin_x);
265 WriteCoord(MSG_ENTITY, self.goalentity.origin_y);
266 WriteCoord(MSG_ENTITY, self.goalentity.origin_z);
270 WriteCoord(MSG_ENTITY, self.enemy.origin_x);
271 WriteCoord(MSG_ENTITY, self.enemy.origin_y);
272 WriteCoord(MSG_ENTITY, self.enemy.origin_z);
276 WriteByte(MSG_ENTITY, self.clientcolors); // which is goalentity's color + enemy's color * 16
281 void ons_Link_CheckUpdate()
283 // TODO check if the two sides have moved (currently they won't move anyway)
284 float cc = 0, cc1 = 0, cc2 = 0;
286 if(self.goalentity.islinked || self.goalentity.iscaptured) { cc1 = (self.goalentity.team - 1) * 0x01; }
287 if(self.enemy.islinked || self.enemy.iscaptured) { cc2 = (self.enemy.team - 1) * 0x10; }
291 if(cc != self.clientcolors)
293 self.clientcolors = cc;
297 self.nextthink = time;
300 void ons_DelayedLinkSetup()
302 self.goalentity = find(world, targetname, self.target);
303 self.enemy = find(world, targetname, self.target2);
304 if(!self.goalentity) { objerror("can not find target\n"); }
305 if(!self.enemy) { objerror("can not find target2\n"); }
307 ons_debug(strcat(etos(self.goalentity), " linked with ", etos(self.enemy), "\n"));
309 self.think = ons_Link_CheckUpdate;
310 self.nextthink = time;
314 // =============================
315 // Main Control Point Functions
316 // =============================
318 int ons_ControlPoint_CanBeLinked(entity cp, int teamnumber)
320 if(cp.isgenneighbor[teamnumber]) { return 2; }
321 if(cp.iscpneighbor[teamnumber]) { return 1; }
326 int ons_ControlPoint_Attackable(entity cp, int teamnumber)
327 // -2: SAME TEAM, attackable by enemy!
332 // 3: attack it (HIGH PRIO)
333 // 4: touch it (HIGH PRIO)
341 else if(cp.goalentity)
343 // if there's already an icon built, nothing happens
344 if(cp.team == teamnumber)
346 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
347 if(a) // attackable by enemy?
348 return -2; // EMERGENCY!
351 // we know it can be linked, so no need to check
353 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
354 if(a == 2) // near our generator?
355 return 3; // EMERGENCY!
361 if(ons_ControlPoint_CanBeLinked(cp, teamnumber))
363 a = ons_ControlPoint_CanBeLinked(cp, teamnumber); // why was this here NUM_TEAM_1 + NUM_TEAM_2 - t
365 return 4; // GET THIS ONE NOW!
367 return 2; // TOUCH ME
373 void ons_ControlPoint_Icon_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
375 if(damage <= 0) { return; }
377 if (self.owner.isshielded)
379 // this is protected by a shield, so ignore the damage
380 if (time > self.pain_finished)
381 if (IS_PLAYER(attacker))
383 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
384 self.pain_finished = time + 1;
385 attacker.typehitsound += 1; // play both sounds (shield is way too quiet)
391 if(IS_PLAYER(attacker))
392 if(time - ons_notification_time[self.team] > 10)
394 play2team(self.team, SND(ONS_CONTROLPOINT_UNDERATTACK));
395 ons_notification_time[self.team] = time;
398 self.health = self.health - damage;
399 if(self.owner.iscaptured)
400 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
402 WaypointSprite_UpdateBuildFinished(self.owner.sprite, time + (self.max_health - self.health) / (self.count / ONS_CP_THINKRATE));
403 self.pain_finished = time + 1;
404 // particles on every hit
405 pointparticles(particleeffectnum(EFFECT_SPARKS), hitloc, force*-1, 1);
408 sound(self, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE+0.3, ATTEN_NORM);
410 sound(self, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE+0.3, ATTEN_NORM);
414 sound(self, CH_TRIGGER, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
415 pointparticles(particleeffectnum(EFFECT_ROCKET_EXPLODE), self.origin, '0 0 0', 1);
416 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_CPDESTROYED_), self.owner.message, attacker.netname);
418 PlayerScore_Add(attacker, SP_ONS_TAKES, 1);
419 PlayerScore_Add(attacker, SP_SCORE, 10);
421 self.owner.goalentity = world;
422 self.owner.islinked = false;
423 self.owner.iscaptured = false;
425 self.owner.colormap = 1024;
427 WaypointSprite_UpdateMaxHealth(self.owner.sprite, 0);
429 onslaught_updatelinks();
431 // Use targets now (somebody make sure this is in the right place..)
437 self.owner.waslinked = self.owner.islinked;
438 if(self.owner.model != "models/onslaught/controlpoint_pad.md3")
439 setmodel_fixsize(self.owner, MDL_ONS_CP_PAD1);
440 //setsize(self, '-32 -32 0', '32 32 8');
445 self.SendFlags |= CPSF_STATUS;
448 void ons_ControlPoint_Icon_Think()
450 self.nextthink = time + ONS_CP_THINKRATE;
452 if(autocvar_g_onslaught_cp_proxydecap)
454 int _enemy_count = 0;
455 int _friendly_count = 0;
459 FOR_EACH_PLAYER(_player)
461 if(!_player.deadflag)
463 _dist = vlen(_player.origin - self.origin);
464 if(_dist < autocvar_g_onslaught_cp_proxydecap_distance)
466 if(SAME_TEAM(_player, self))
474 _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
475 _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
477 self.health = bound(0, self.health + (_friendly_count - _enemy_count), self.max_health);
478 self.SendFlags |= CPSF_STATUS;
481 ons_ControlPoint_Icon_Damage(self, self, 1, 0, self.origin, '0 0 0');
486 if (time > self.pain_finished + 5)
488 if(self.health < self.max_health)
490 self.health = self.health + self.count;
491 if (self.health >= self.max_health)
492 self.health = self.max_health;
493 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
497 if(self.owner.islinked != self.owner.waslinked)
499 // unteam the spawnpoint if needed
500 int t = self.owner.team;
501 if(!self.owner.islinked)
511 self.owner.waslinked = self.owner.islinked;
515 if(random() < 0.6 - self.health / self.max_health)
517 Send_Effect(EFFECT_ELECTRIC_SPARKS, self.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
520 sound(self, CH_PAIN, SND_ONS_SPARK1, VOL_BASE, ATTEN_NORM);
521 else if (random() > 0.5)
522 sound(self, CH_PAIN, SND_ONS_SPARK2, VOL_BASE, ATTEN_NORM);
526 void ons_ControlPoint_Icon_BuildThink()
530 self.nextthink = time + ONS_CP_THINKRATE;
532 // only do this if there is power
533 a = ons_ControlPoint_CanBeLinked(self.owner, self.owner.team);
537 self.health = self.health + self.count;
539 self.SendFlags |= CPSF_STATUS;
541 if (self.health >= self.max_health)
543 self.health = self.max_health;
544 self.count = autocvar_g_onslaught_cp_regen * ONS_CP_THINKRATE; // slow repair rate from now on
545 self.think = ons_ControlPoint_Icon_Think;
546 sound(self, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILT, VOL_BASE, ATTEN_NORM);
547 self.owner.iscaptured = true;
548 self.solid = SOLID_BBOX;
550 Send_Effect(EFFECT_CAP(self.owner.team), self.owner.origin, '0 0 0', 1);
552 WaypointSprite_UpdateMaxHealth(self.owner.sprite, self.max_health);
553 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
555 if(IS_PLAYER(self.owner.ons_toucher))
557 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ONSLAUGHT_CAPTURE, self.owner.ons_toucher.netname, self.owner.message);
558 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);
559 Send_Notification(NOTIF_ONE, self.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE, self.owner.message);
560 PlayerScore_Add(self.owner.ons_toucher, SP_ONS_CAPS, 1);
561 PlayerTeamScore_AddScore(self.owner.ons_toucher, 10);
564 self.owner.ons_toucher = world;
566 onslaught_updatelinks();
568 // Use targets now (somebody make sure this is in the right place..)
574 self.SendFlags |= CPSF_SETUP;
576 if(self.owner.model != MDL_ONS_CP_PAD2.model_str())
577 setmodel_fixsize(self.owner, MDL_ONS_CP_PAD2);
579 if(random() < 0.9 - self.health / self.max_health)
580 Send_Effect(EFFECT_RAGE, self.origin + 10 * randomvec(), '0 0 -1', 1);
583 void onslaught_controlpoint_icon_link(entity e, void() spawnproc);
585 void ons_ControlPoint_Icon_Spawn(entity cp, entity player)
589 setsize(e, CPICON_MIN, CPICON_MAX);
590 setorigin(e, cp.origin + CPICON_OFFSET);
592 e.classname = "onslaught_controlpoint_icon";
594 e.max_health = autocvar_g_onslaught_cp_health;
595 e.health = autocvar_g_onslaught_cp_buildhealth;
597 e.takedamage = DAMAGE_AIM;
599 e.event_damage = ons_ControlPoint_Icon_Damage;
600 e.team = player.team;
601 e.colormap = 1024 + (e.team - 1) * 17;
602 e.count = (e.max_health - e.health) * ONS_CP_THINKRATE / autocvar_g_onslaught_cp_buildtime; // how long it takes to build
604 sound(e, CH_TRIGGER, SND_ONS_CONTROLPOINT_BUILD, VOL_BASE, ATTEN_NORM);
608 cp.colormap = e.colormap;
610 Send_Effect(EFFECT_FLAG_TOUCH(player.team), e.origin, '0 0 0', 1);
612 WaypointSprite_UpdateBuildFinished(cp.sprite, time + (e.max_health - e.health) / (e.count / ONS_CP_THINKRATE));
613 WaypointSprite_UpdateRule(cp.sprite,cp.team,SPRITERULE_TEAMPLAY);
614 cp.sprite.SendFlags |= 16;
616 onslaught_controlpoint_icon_link(e, ons_ControlPoint_Icon_BuildThink);
619 entity ons_ControlPoint_Waypoint(entity e)
623 int a = ons_ControlPoint_Attackable(e, e.team);
625 if(a == -2) { return WP_OnsCPDefend; } // defend now
626 if(a == -1 || a == 1 || a == 2) { return WP_OnsCP; } // touch
627 if(a == 3 || a == 4) { return WP_OnsCPAttack; } // attack
635 void ons_ControlPoint_UpdateSprite(entity e)
637 entity s1 = ons_ControlPoint_Waypoint(e);
638 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
641 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));
643 if(e.lastteam != e.team + 2 || e.lastshielded != sh || e.iscaptured != e.lastcaptured)
645 if(e.iscaptured) // don't mess up build bars!
649 WaypointSprite_UpdateMaxHealth(e.sprite, 0);
653 WaypointSprite_UpdateMaxHealth(e.sprite, e.goalentity.max_health);
654 WaypointSprite_UpdateHealth(e.sprite, e.goalentity.health);
660 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, false));
662 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
667 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, false));
669 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
671 WaypointSprite_Ping(e.sprite);
673 e.lastteam = e.team + 2;
675 e.lastcaptured = e.iscaptured;
679 void ons_ControlPoint_Touch()
681 entity toucher = other;
684 if(IS_VEHICLE(toucher) && toucher.owner)
685 if(autocvar_g_onslaught_allow_vehicle_touch)
686 toucher = toucher.owner;
690 if(!IS_PLAYER(toucher)) { return; }
691 if(toucher.frozen) { return; }
692 if(toucher.deadflag != DEAD_NO) { return; }
694 if ( SAME_TEAM(self,toucher) )
695 if ( self.iscaptured )
697 if(time <= toucher.teleport_antispam)
698 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT_ANTISPAM, rint(toucher.teleport_antispam - time));
700 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
703 attackable = ons_ControlPoint_Attackable(self, toucher.team);
704 if(attackable != 2 && attackable != 4)
706 // we've verified that this player has a legitimate claim to this point,
707 // so start building the captured point icon (which only captures this
708 // point if it successfully builds without being destroyed first)
709 ons_ControlPoint_Icon_Spawn(self, toucher);
711 self.ons_toucher = toucher;
713 onslaught_updatelinks();
716 void ons_ControlPoint_Think()
718 self.nextthink = time + ONS_CP_THINKRATE;
719 CSQCMODEL_AUTOUPDATE(self);
722 void ons_ControlPoint_Reset()
725 remove(self.goalentity);
727 self.goalentity = world;
729 self.colormap = 1024;
730 self.iscaptured = false;
731 self.islinked = false;
732 self.isshielded = true;
733 self.think = ons_ControlPoint_Think;
734 self.ons_toucher = world;
735 self.nextthink = time + ONS_CP_THINKRATE;
736 setmodel_fixsize(self, MDL_ONS_CP_PAD1);
738 WaypointSprite_UpdateMaxHealth(self.sprite, 0);
739 WaypointSprite_UpdateRule(self.sprite,self.team,SPRITERULE_TEAMPLAY);
741 onslaught_updatelinks();
744 SUB_UseTargets(); // to reset the structures, playerspawns etc.
746 CSQCMODEL_AUTOUPDATE(self);
749 void ons_DelayedControlPoint_Setup(void)
751 onslaught_updatelinks();
753 // captureshield setup
754 ons_CaptureShield_Spawn(self, false);
756 CSQCMODEL_AUTOINIT(self);
759 void ons_ControlPoint_Setup(entity cp)
762 setself(cp); // for later usage with droptofloor()
765 cp.ons_worldcpnext = ons_worldcplist; // link control point into ons_worldcplist
766 ons_worldcplist = cp;
768 cp.netname = "Control point";
770 cp.solid = SOLID_BBOX;
771 cp.movetype = MOVETYPE_NONE;
772 cp.touch = ons_ControlPoint_Touch;
773 cp.think = ons_ControlPoint_Think;
774 cp.nextthink = time + ONS_CP_THINKRATE;
775 cp.reset = ons_ControlPoint_Reset;
777 cp.iscaptured = false;
779 cp.isshielded = true;
781 if(cp.message == "") { cp.message = "a"; }
784 setmodel_fixsize(cp, MDL_ONS_CP_PAD1);
786 // control point placement
787 if((cp.spawnflags & 1) || cp.noalign) // don't drop to floor, just stay at fixed location
790 cp.movetype = MOVETYPE_NONE;
792 else // drop to floor, automatically find a platform and set that as spawn origin
794 setorigin(cp, cp.origin + '0 0 20');
798 cp.movetype = MOVETYPE_TOSS;
802 WaypointSprite_SpawnFixed(WP_Null, self.origin + CPGEN_WAYPOINT_OFFSET, self, sprite, RADARICON_NONE);
803 WaypointSprite_UpdateRule(self.sprite, self.team, SPRITERULE_TEAMPLAY);
805 InitializeEntity(cp, ons_DelayedControlPoint_Setup, INITPRIO_SETLOCATION);
809 // =========================
810 // Main Generator Functions
811 // =========================
813 entity ons_Generator_Waypoint(entity e)
816 return WP_OnsGenShielded;
820 void ons_Generator_UpdateSprite(entity e)
822 entity s1 = ons_Generator_Waypoint(e);
823 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
825 if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
827 e.lastteam = e.team + 2;
828 e.lastshielded = e.isshielded;
832 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, false));
834 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
839 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, false));
841 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
843 WaypointSprite_Ping(e.sprite);
847 void ons_GeneratorDamage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
849 if(damage <= 0) { return; }
850 if(warmup_stage || gameover) { return; }
851 if(!round_handler_IsRoundStarted()) { return; }
853 if (attacker != self)
857 // this is protected by a shield, so ignore the damage
858 if (time > self.pain_finished)
859 if (IS_PLAYER(attacker))
861 play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
862 attacker.typehitsound += 1;
863 self.pain_finished = time + 1;
867 if (time > self.pain_finished)
869 self.pain_finished = time + 10;
871 FOR_EACH_REALPLAYER(head) if(SAME_TEAM(head, self)) { Send_Notification(NOTIF_ONE, head, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK); }
872 play2team(self.team, SND(ONS_GENERATOR_UNDERATTACK));
875 self.health = self.health - damage;
876 WaypointSprite_UpdateHealth(self.sprite, self.health);
877 // choose an animation frame based on health
878 self.frame = 10 * bound(0, (1 - self.health / self.max_health), 1);
879 // see if the generator is still functional, or dying
882 self.lasthealth = self.health;
886 if (attacker == self)
887 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME_));
890 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_GENDESTROYED_));
891 PlayerScore_Add(attacker, SP_SCORE, 100);
893 self.iscaptured = false;
894 self.islinked = false;
895 self.isshielded = false;
896 self.takedamage = DAMAGE_NO; // can't be hurt anymore
897 self.event_damage = func_null; // won't do anything if hurt
898 self.count = 0; // reset counter
899 self.think = func_null;
901 //self.think(); // do the first explosion now
903 WaypointSprite_UpdateMaxHealth(self.sprite, 0);
904 WaypointSprite_Ping(self.sprite);
905 //WaypointSprite_Kill(self.sprite); // can't do this yet, code too poor
907 onslaught_updatelinks();
910 // Throw some flaming gibs on damage, more damage = more chance for gib
911 if(random() < damage/220)
913 sound(self, CH_TRIGGER, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
917 // particles on every hit
918 Send_Effect(EFFECT_SPARKS, hitloc, force * -1, 1);
922 sound(self, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE, ATTEN_NORM);
924 sound(self, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE, ATTEN_NORM);
927 self.SendFlags |= GSF_STATUS;
930 void ons_GeneratorThink()
933 self.nextthink = time + GEN_THINKRATE;
936 if(!self.isshielded && self.wait < time)
938 self.wait = time + 5;
939 FOR_EACH_REALPLAYER(e)
941 if(SAME_TEAM(e, self))
943 Send_Notification(NOTIF_ONE, e, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM);
944 soundto(MSG_ONE, e, CHAN_AUTO, SND(KH_ALARM), VOL_BASE, ATTEN_NONE); // FIXME: unique sound?
947 Send_Notification(NOTIF_ONE, e, MSG_CENTER, APP_TEAM_NUM_4(self.team, CENTER_ONS_NOTSHIELDED_));
953 void ons_GeneratorReset()
955 self.team = self.team_saved;
956 self.lasthealth = self.max_health = self.health = autocvar_g_onslaught_gen_health;
957 self.takedamage = DAMAGE_AIM;
958 self.bot_attack = true;
959 self.iscaptured = true;
960 self.islinked = true;
961 self.isshielded = true;
962 self.event_damage = ons_GeneratorDamage;
963 self.think = ons_GeneratorThink;
964 self.nextthink = time + GEN_THINKRATE;
966 Net_LinkEntity(self, false, 0, generator_send);
968 self.SendFlags = GSF_SETUP; // just incase
969 self.SendFlags |= GSF_STATUS;
971 WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
972 WaypointSprite_UpdateHealth(self.sprite, self.health);
973 WaypointSprite_UpdateRule(self.sprite,self.team,SPRITERULE_TEAMPLAY);
975 onslaught_updatelinks();
978 void ons_DelayedGeneratorSetup()
981 waypoint_spawnforitem_force(self, self.origin);
982 self.nearestwaypointtimeout = 0; // activate waypointing again
983 self.bot_basewaypoint = self.nearestwaypoint;
985 // captureshield setup
986 ons_CaptureShield_Spawn(self, true);
988 onslaught_updatelinks();
990 Net_LinkEntity(self, false, 0, generator_send);
994 void onslaught_generator_touch()
996 if ( IS_PLAYER(other) )
997 if ( SAME_TEAM(self,other) )
998 if ( self.iscaptured )
1000 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_TELEPORT);
1004 void ons_GeneratorSetup(entity gen) // called when spawning a generator entity on the map as a spawnfunc
1007 int teamnumber = gen.team;
1008 setself(gen); // for later usage with droptofloor()
1011 gen.ons_worldgeneratornext = ons_worldgeneratorlist; // link generator into ons_worldgeneratorlist
1012 ons_worldgeneratorlist = gen;
1014 gen.netname = sprintf("%s generator", Team_ColoredFullName(teamnumber));
1015 gen.classname = "onslaught_generator";
1016 gen.solid = SOLID_BBOX;
1017 gen.team_saved = teamnumber;
1018 gen.movetype = MOVETYPE_NONE;
1019 gen.lasthealth = gen.max_health = gen.health = autocvar_g_onslaught_gen_health;
1020 gen.takedamage = DAMAGE_AIM;
1021 gen.bot_attack = true;
1022 gen.event_damage = ons_GeneratorDamage;
1023 gen.reset = ons_GeneratorReset;
1024 gen.think = ons_GeneratorThink;
1025 gen.nextthink = time + GEN_THINKRATE;
1026 gen.iscaptured = true;
1027 gen.islinked = true;
1028 gen.isshielded = true;
1029 gen.touch = onslaught_generator_touch;
1032 // model handled by CSQC
1033 setsize(gen, GENERATOR_MIN, GENERATOR_MAX);
1034 setorigin(gen, (gen.origin + CPGEN_SPAWN_OFFSET));
1035 gen.colormap = 1024 + (teamnumber - 1) * 17;
1037 // generator placement
1042 WaypointSprite_SpawnFixed(WP_Null, self.origin + CPGEN_WAYPOINT_OFFSET, self, sprite, RADARICON_NONE);
1043 WaypointSprite_UpdateRule(self.sprite, self.team, SPRITERULE_TEAMPLAY);
1044 WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
1045 WaypointSprite_UpdateHealth(self.sprite, self.health);
1047 InitializeEntity(gen, ons_DelayedGeneratorSetup, INITPRIO_SETLOCATION);
1055 int total_generators;
1056 void Onslaught_count_generators()
1059 total_generators = redowned = blueowned = yellowowned = pinkowned = 0;
1060 for(e = ons_worldgeneratorlist; e; e = e.ons_worldgeneratornext)
1063 redowned += (e.team == NUM_TEAM_1 && e.health > 0);
1064 blueowned += (e.team == NUM_TEAM_2 && e.health > 0);
1065 yellowowned += (e.team == NUM_TEAM_3 && e.health > 0);
1066 pinkowned += (e.team == NUM_TEAM_4 && e.health > 0);
1070 int Onslaught_GetWinnerTeam()
1072 int winner_team = 0;
1074 winner_team = NUM_TEAM_1;
1077 if(winner_team) return 0;
1078 winner_team = NUM_TEAM_2;
1082 if(winner_team) return 0;
1083 winner_team = NUM_TEAM_3;
1087 if(winner_team) return 0;
1088 winner_team = NUM_TEAM_4;
1092 return -1; // no generators left?
1095 #define ONS_OWNED_GENERATORS() ((redowned > 0) + (blueowned > 0) + (yellowowned > 0) + (pinkowned > 0))
1096 #define ONS_OWNED_GENERATORS_OK() (ONS_OWNED_GENERATORS() > 1)
1097 bool Onslaught_CheckWinner()
1101 if ((autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60) || (round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0))
1103 ons_stalemate = true;
1105 if (!wpforenemy_announced)
1107 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT);
1108 sound(world, CH_INFO, SND_ONS_GENERATOR_DECAY, VOL_BASE, ATTEN_NONE);
1110 wpforenemy_announced = true;
1113 entity tmp_entity; // temporary entity
1115 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext) if(time >= tmp_entity.ons_overtime_damagedelay)
1117 // tmp_entity.max_health / 300 gives 5 minutes of overtime.
1118 // control points reduce the overtime duration.
1120 for(e = ons_worldcplist; e; e = e.ons_worldcpnext)
1122 if(DIFF_TEAM(e, tmp_entity))
1127 if(autocvar_g_campaign && autocvar__campaign_testrun)
1128 d = d * tmp_entity.max_health;
1130 d = d * tmp_entity.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
1132 Damage(tmp_entity, tmp_entity, tmp_entity, d, DEATH_HURTTRIGGER.m_id, tmp_entity.origin, '0 0 0');
1134 tmp_entity.sprite.SendFlags |= 16;
1136 tmp_entity.ons_overtime_damagedelay = time + 1;
1139 else { wpforenemy_announced = false; ons_stalemate = false; }
1141 Onslaught_count_generators();
1143 if(ONS_OWNED_GENERATORS_OK())
1146 int winner_team = Onslaught_GetWinnerTeam();
1150 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
1151 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
1152 TeamScore_AddToTeam(winner_team, ST_ONS_CAPS, +1);
1154 else if(winner_team == -1)
1156 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
1157 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
1160 ons_stalemate = false;
1162 play2all(SND(CTF_CAPTURE(winner_team)));
1164 round_handler_Init(7, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
1168 e.ons_roundlost = true;
1169 e.player_blocked = true;
1177 bool Onslaught_CheckPlayers()
1182 void Onslaught_RoundStart()
1185 FOR_EACH_PLAYER(tmp_entity) { tmp_entity.player_blocked = false; }
1187 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1188 tmp_entity.sprite.SendFlags |= 16;
1190 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1191 tmp_entity.sprite.SendFlags |= 16;
1199 // NOTE: LEGACY CODE, needs to be re-written!
1201 void havocbot_goalrating_ons_offenseitems(float ratingscale, vector org, float sradius)
1206 bool needarmor = false, needweapons = false;
1208 // Needs armor/health?
1214 for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
1217 if(self.weapons & WepSet_FromWeapon(i))
1225 if(!needweapons && !needarmor)
1228 ons_debug(strcat(self.netname, " needs weapons ", ftos(needweapons) , "\n"));
1229 ons_debug(strcat(self.netname, " needs armor ", ftos(needarmor) , "\n"));
1231 // See what is around
1232 head = findchainfloat(bot_pickup, true);
1235 // gather health and armor only
1237 if ( ((head.health || head.armorvalue) && needarmor) || (head.weapons && needweapons ) )
1238 if (vlen(head.origin - org) < sradius)
1240 t = head.bot_pickupevalfunc(self, head);
1242 navigation_routerating(head, t * ratingscale, 500);
1248 void havocbot_role_ons_setrole(entity bot, int role)
1250 ons_debug(strcat(bot.netname," switched to "));
1253 case HAVOCBOT_ONS_ROLE_DEFENSE:
1254 ons_debug("defense");
1255 bot.havocbot_role = havocbot_role_ons_defense;
1256 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE;
1257 bot.havocbot_role_timeout = 0;
1259 case HAVOCBOT_ONS_ROLE_ASSISTANT:
1260 ons_debug("assistant");
1261 bot.havocbot_role = havocbot_role_ons_assistant;
1262 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT;
1263 bot.havocbot_role_timeout = 0;
1265 case HAVOCBOT_ONS_ROLE_OFFENSE:
1266 ons_debug("offense");
1267 bot.havocbot_role = havocbot_role_ons_offense;
1268 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE;
1269 bot.havocbot_role_timeout = 0;
1275 int havocbot_ons_teamcount(entity bot, int role)
1280 FOR_EACH_PLAYER(head)
1281 if(SAME_TEAM(head, self))
1282 if(head.havocbot_role_flags & role)
1288 void havocbot_goalrating_ons_controlpoints_attack(float ratingscale)
1290 entity cp, cp1, cp2, best, pl, wp;
1291 float radius, bestvalue;
1295 // Filter control points
1296 for(cp2 = ons_worldcplist; cp2; cp2 = cp2.ons_worldcpnext)
1299 cp2.wpconsidered = false;
1304 // Ignore owned controlpoints
1305 if(!(cp2.isgenneighbor[self.team] || cp2.iscpneighbor[self.team]))
1308 // Count team mates interested in this control point
1309 // (easier and cleaner than keeping counters per cp and teams)
1311 if(SAME_TEAM(pl, self))
1312 if(pl.havocbot_role_flags & HAVOCBOT_ONS_ROLE_OFFENSE)
1313 if(pl.havocbot_ons_target==cp2)
1316 // NOTE: probably decrease the cost of attackable control points
1318 cp2.wpconsidered = true;
1321 // We'll consider only the best case
1322 bestvalue = 99999999999;
1324 for(cp1 = ons_worldcplist; cp1; cp1 = cp1.ons_worldcpnext)
1326 if (!cp1.wpconsidered)
1329 if(cp1.wpcost<bestvalue)
1331 bestvalue = cp1.wpcost;
1333 self.havocbot_ons_target = cp1;
1340 ons_debug(strcat(self.netname, " chose cp ranked ", ftos(bestvalue), "\n"));
1344 // Should be attacked
1345 // Rate waypoints near it
1348 bestvalue = 99999999999;
1349 for(radius=0; radius<1000 && !found; radius+=500)
1351 for(wp=findradius(cp.origin,radius); wp; wp=wp.chain)
1353 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
1354 if(wp.classname=="waypoint")
1355 if(checkpvs(wp.origin,cp))
1358 if(wp.cnt<bestvalue)
1369 navigation_routerating(best, ratingscale, 10000);
1372 self.havocbot_attack_time = 0;
1373 if(checkpvs(self.view_ofs,cp))
1374 if(checkpvs(self.view_ofs,best))
1375 self.havocbot_attack_time = time + 2;
1379 navigation_routerating(cp, ratingscale, 10000);
1381 ons_debug(strcat(self.netname, " found an attackable controlpoint at ", vtos(cp.origin) ,"\n"));
1385 // Should be touched
1386 ons_debug(strcat(self.netname, " found a touchable controlpoint at ", vtos(cp.origin) ,"\n"));
1389 // Look for auto generated waypoint
1390 if (!bot_waypoints_for_items)
1391 for (wp = findradius(cp.origin,100); wp; wp = wp.chain)
1393 if(wp.classname=="waypoint")
1395 navigation_routerating(wp, ratingscale, 10000);
1400 // Nothing found, rate the controlpoint itself
1402 navigation_routerating(cp, ratingscale, 10000);
1406 bool havocbot_goalrating_ons_generator_attack(float ratingscale)
1408 entity g, wp, bestwp;
1412 for(g = ons_worldgeneratorlist; g; g = g.ons_worldgeneratornext)
1414 if(SAME_TEAM(g, self) || g.isshielded)
1417 // Should be attacked
1418 // Rate waypoints near it
1423 for(wp=findradius(g.origin,400); wp; wp=wp.chain)
1425 if(wp.classname=="waypoint")
1426 if(checkpvs(wp.origin,g))
1439 ons_debug("waypoints found around generator\n");
1440 navigation_routerating(bestwp, ratingscale, 10000);
1443 self.havocbot_attack_time = 0;
1444 if(checkpvs(self.view_ofs,g))
1445 if(checkpvs(self.view_ofs,bestwp))
1446 self.havocbot_attack_time = time + 5;
1452 ons_debug("generator found without waypoints around\n");
1453 // if there aren't waypoints near the generator go straight to it
1454 navigation_routerating(g, ratingscale, 10000);
1455 self.havocbot_attack_time = 0;
1462 void havocbot_role_ons_offense()
1464 if(self.deadflag != DEAD_NO)
1466 self.havocbot_attack_time = 0;
1467 havocbot_ons_reset_role(self);
1471 // Set the role timeout if necessary
1472 if (!self.havocbot_role_timeout)
1473 self.havocbot_role_timeout = time + 120;
1475 if (time > self.havocbot_role_timeout)
1477 havocbot_ons_reset_role(self);
1481 if(self.havocbot_attack_time>time)
1484 if (self.bot_strategytime < time)
1486 navigation_goalrating_start();
1487 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
1488 if(!havocbot_goalrating_ons_generator_attack(20000))
1489 havocbot_goalrating_ons_controlpoints_attack(20000);
1490 havocbot_goalrating_ons_offenseitems(10000, self.origin, 10000);
1491 navigation_goalrating_end();
1493 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
1497 void havocbot_role_ons_assistant()
1499 havocbot_ons_reset_role(self);
1502 void havocbot_role_ons_defense()
1504 havocbot_ons_reset_role(self);
1507 void havocbot_ons_reset_role(entity bot)
1512 if(self.deadflag != DEAD_NO)
1515 bot.havocbot_ons_target = world;
1517 // TODO: Defend control points or generator if necessary
1519 // if there is only me on the team switch to offense
1521 FOR_EACH_PLAYER(head)
1522 if(SAME_TEAM(head, self))
1527 havocbot_role_ons_setrole(bot, HAVOCBOT_ONS_ROLE_OFFENSE);
1531 havocbot_role_ons_setrole(bot, HAVOCBOT_ONS_ROLE_OFFENSE);
1536 * Find control point or generator owned by the same team self which is nearest to pos
1537 * if max_dist is positive, only control points within this range will be considered
1539 entity ons_Nearest_ControlPoint(vector pos, float max_dist)
1541 entity tmp_entity, closest_target = world;
1542 tmp_entity = findchain(classname, "onslaught_controlpoint");
1545 if(SAME_TEAM(tmp_entity, self))
1546 if(tmp_entity.iscaptured)
1547 if(max_dist <= 0 || vlen(tmp_entity.origin - pos) <= max_dist)
1548 if(vlen(tmp_entity.origin - pos) <= vlen(closest_target.origin - pos) || closest_target == world)
1549 closest_target = tmp_entity;
1550 tmp_entity = tmp_entity.chain;
1552 tmp_entity = findchain(classname, "onslaught_generator");
1555 if(SAME_TEAM(tmp_entity, self))
1556 if(max_dist <= 0 || vlen(tmp_entity.origin - pos) < max_dist)
1557 if(vlen(tmp_entity.origin - pos) <= vlen(closest_target.origin - pos) || closest_target == world)
1558 closest_target = tmp_entity;
1559 tmp_entity = tmp_entity.chain;
1562 return closest_target;
1566 * Find control point or generator owned by the same team self which is nearest to pos
1567 * if max_dist is positive, only control points within this range will be considered
1568 * This function only check distances on the XY plane, disregarding Z
1570 entity ons_Nearest_ControlPoint_2D(vector pos, float max_dist)
1572 entity tmp_entity, closest_target = world;
1574 float smallest_distance = 0, distance;
1576 tmp_entity = findchain(classname, "onslaught_controlpoint");
1579 delta = tmp_entity.origin - pos;
1581 distance = vlen(delta);
1583 if(SAME_TEAM(tmp_entity, self))
1584 if(tmp_entity.iscaptured)
1585 if(max_dist <= 0 || distance <= max_dist)
1586 if(closest_target == world || distance <= smallest_distance )
1588 closest_target = tmp_entity;
1589 smallest_distance = distance;
1592 tmp_entity = tmp_entity.chain;
1594 tmp_entity = findchain(classname, "onslaught_generator");
1597 delta = tmp_entity.origin - pos;
1599 distance = vlen(delta);
1601 if(SAME_TEAM(tmp_entity, self))
1602 if(max_dist <= 0 || distance <= max_dist)
1603 if(closest_target == world || distance <= smallest_distance )
1605 closest_target = tmp_entity;
1606 smallest_distance = distance;
1609 tmp_entity = tmp_entity.chain;
1612 return closest_target;
1615 * find the number of control points and generators in the same team as self
1617 int ons_Count_SelfControlPoints()
1620 tmp_entity = findchain(classname, "onslaught_controlpoint");
1624 if(SAME_TEAM(tmp_entity, self))
1625 if(tmp_entity.iscaptured)
1627 tmp_entity = tmp_entity.chain;
1629 tmp_entity = findchain(classname, "onslaught_generator");
1632 if(SAME_TEAM(tmp_entity, self))
1634 tmp_entity = tmp_entity.chain;
1640 * Teleport player to a random position near tele_target
1641 * if tele_effects is true, teleport sound+particles are created
1642 * return false on failure
1644 bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effects)
1652 for(i = 0; i < 16; ++i)
1654 theta = random() * 2 * M_PI;
1658 loc *= random() * range;
1660 loc += tele_target.origin + '0 0 128';
1662 tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, player);
1663 if(trace_fraction == 1.0 && !trace_startsolid)
1665 traceline(tele_target.origin, loc, MOVE_NOMONSTERS, tele_target); // double check to make sure we're not spawning outside the world
1666 if(trace_fraction == 1.0 && !trace_startsolid)
1670 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
1671 sound (player, CH_TRIGGER, SND_TELEPORT, VOL_BASE, ATTEN_NORM);
1673 setorigin(player, loc);
1674 player.angles = '0 1 0' * ( theta * RAD2DEG + 180 );
1675 makevectors(player.angles);
1676 player.fixangle = true;
1677 player.teleport_antispam = time + autocvar_g_onslaught_teleport_wait;
1680 Send_Effect(EFFECT_TELEPORT, player.origin + v_forward * 32, '0 0 0', 1);
1693 MUTATOR_HOOKFUNCTION(ons, reset_map_global)
1698 e.ons_roundlost = false;
1699 e.ons_deathloc = '0 0 0';
1700 WITH(entity, self, e, PutClientInServer());
1705 MUTATOR_HOOKFUNCTION(ons, ClientDisconnect)
1707 self.ons_deathloc = '0 0 0';
1711 MUTATOR_HOOKFUNCTION(ons, MakePlayerObserver)
1713 self.ons_deathloc = '0 0 0';
1717 MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
1719 if(!round_handler_IsRoundStarted())
1721 self.player_blocked = true;
1726 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1728 l.sprite.SendFlags |= 16;
1730 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1732 l.sprite.SendFlags |= 16;
1735 if(ons_stalemate) { Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); }
1737 if ( autocvar_g_onslaught_spawn_choose )
1738 if ( self.ons_spawn_by )
1739 if ( ons_Teleport(self,self.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) )
1741 self.ons_spawn_by = world;
1745 if(autocvar_g_onslaught_spawn_at_controlpoints)
1746 if(random() <= autocvar_g_onslaught_spawn_at_controlpoints_chance)
1748 float random_target = autocvar_g_onslaught_spawn_at_controlpoints_random;
1749 entity tmp_entity, closest_target = world;
1750 vector spawn_loc = self.ons_deathloc;
1752 // new joining player or round reset, don't bother checking
1753 if(spawn_loc == '0 0 0') { return false; }
1755 if(random_target) { RandomSelection_Init(); }
1757 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1759 if(SAME_TEAM(tmp_entity, self))
1761 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1762 else if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world)
1763 closest_target = tmp_entity;
1766 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1772 for(i = 0; i < 10; ++i)
1774 loc = closest_target.origin + '0 0 96';
1775 loc += ('0 1 0' * random()) * 128;
1776 tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, self);
1777 if(trace_fraction == 1.0 && !trace_startsolid)
1779 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
1780 if(trace_fraction == 1.0 && !trace_startsolid)
1782 setorigin(self, loc);
1783 self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1791 if(autocvar_g_onslaught_spawn_at_generator)
1792 if(random() <= autocvar_g_onslaught_spawn_at_generator_chance)
1794 float random_target = autocvar_g_onslaught_spawn_at_generator_random;
1795 entity tmp_entity, closest_target = world;
1796 vector spawn_loc = self.ons_deathloc;
1798 // new joining player or round reset, don't bother checking
1799 if(spawn_loc == '0 0 0') { return false; }
1801 if(random_target) { RandomSelection_Init(); }
1803 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1806 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1809 if(SAME_TEAM(tmp_entity, self))
1810 if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world)
1811 closest_target = tmp_entity;
1815 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1821 for(i = 0; i < 10; ++i)
1823 loc = closest_target.origin + '0 0 128';
1824 loc += ('0 1 0' * random()) * 256;
1825 tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, self);
1826 if(trace_fraction == 1.0 && !trace_startsolid)
1828 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
1829 if(trace_fraction == 1.0 && !trace_startsolid)
1831 setorigin(self, loc);
1832 self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1843 MUTATOR_HOOKFUNCTION(ons, PlayerDies)
1845 frag_target.ons_deathloc = frag_target.origin;
1847 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1849 l.sprite.SendFlags |= 16;
1851 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1853 l.sprite.SendFlags |= 16;
1856 if ( autocvar_g_onslaught_spawn_choose )
1857 if ( ons_Count_SelfControlPoints() > 1 )
1858 stuffcmd(self, "qc_cmd_cl hud clickradar\n");
1863 MUTATOR_HOOKFUNCTION(ons, MonsterMove)
1865 entity e = find(world, targetname, self.target);
1872 void ons_MonsterSpawn_Delayed()
1874 entity e, own = self.owner;
1876 if(!own) { remove(self); return; }
1880 e = find(world, target, own.targetname);
1893 MUTATOR_HOOKFUNCTION(ons, MonsterSpawn)
1897 InitializeEntity(e, ons_MonsterSpawn_Delayed, INITPRIO_FINDTARGET);
1902 void ons_TurretSpawn_Delayed()
1904 entity e, own = self.owner;
1906 if(!own) { remove(self); return; }
1910 e = find(world, target, own.targetname);
1914 own.active = ACTIVE_NOT;
1924 MUTATOR_HOOKFUNCTION(ons, TurretSpawn)
1928 InitializeEntity(e, ons_TurretSpawn_Delayed, INITPRIO_FINDTARGET);
1933 MUTATOR_HOOKFUNCTION(ons, HavocBot_ChooseRole)
1935 havocbot_ons_reset_role(self);
1939 MUTATOR_HOOKFUNCTION(ons, GetTeamCount)
1941 // onslaught is special
1942 for(entity tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1944 switch(tmp_entity.team)
1946 case NUM_TEAM_1: c1 = 0; break;
1947 case NUM_TEAM_2: c2 = 0; break;
1948 case NUM_TEAM_3: c3 = 0; break;
1949 case NUM_TEAM_4: c4 = 0; break;
1956 MUTATOR_HOOKFUNCTION(ons, SpectateCopy)
1958 self.ons_roundlost = other.ons_roundlost; // make spectators see it too
1962 MUTATOR_HOOKFUNCTION(ons, SV_ParseClientCommand)
1964 if(MUTATOR_RETURNVALUE) // command was already handled?
1967 if ( cmd_name == "ons_spawn" )
1969 vector pos = self.origin;
1971 pos_x = stof(argv(1));
1973 pos_y = stof(argv(2));
1975 pos_z = stof(argv(3));
1977 if ( IS_PLAYER(self) )
1981 entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
1983 if ( !source_point && self.health > 0 )
1985 sprint(self, "\nYou need to be next to a control point\n");
1990 entity closest_target = ons_Nearest_ControlPoint_2D(pos, autocvar_g_onslaught_click_radius);
1992 if ( closest_target == world )
1994 sprint(self, "\nNo control point found\n");
1998 if ( self.health <= 0 )
2000 self.ons_spawn_by = closest_target;
2001 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
2005 if ( source_point == closest_target )
2007 sprint(self, "\nTeleporting to the same point\n");
2011 if ( !ons_Teleport(self,closest_target,autocvar_g_onslaught_teleport_radius,true) )
2012 sprint(self, "\nUnable to teleport there\n");
2018 sprint(self, "\nNo teleportation for you\n");
2026 MUTATOR_HOOKFUNCTION(ons, PlayerUseKey)
2028 if(MUTATOR_RETURNVALUE || gameover) { return false; }
2030 if((time > self.teleport_antispam) && (self.deadflag == DEAD_NO) && !self.vehicle)
2032 entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
2035 stuffcmd(self, "qc_cmd_cl hud clickradar\n");
2043 MUTATOR_HOOKFUNCTION(ons, PlayHitsound)
2045 return (frag_victim.classname == "onslaught_generator" && !frag_victim.isshielded)
2046 || (frag_victim.classname == "onslaught_controlpoint_icon" && !frag_victim.owner.isshielded);
2049 MUTATOR_HOOKFUNCTION(ons, SendWaypoint)
2051 if(wp_sendflags & 16)
2053 if(self.owner.classname == "onslaught_controlpoint")
2055 entity wp_owner = self.owner;
2056 entity e = WaypointSprite_getviewentity(wp_sendto);
2057 if(SAME_TEAM(e, wp_owner) && wp_owner.goalentity.health >= wp_owner.goalentity.max_health) { wp_flag |= 2; }
2058 if(!ons_ControlPoint_Attackable(wp_owner, e.team)) { wp_flag |= 2; }
2060 if(self.owner.classname == "onslaught_generator")
2062 entity wp_owner = self.owner;
2063 if(wp_owner.isshielded && wp_owner.health >= wp_owner.max_health) { wp_flag |= 2; }
2064 if(wp_owner.health <= 0) { wp_flag |= 2; }
2071 MUTATOR_HOOKFUNCTION(ons, TurretValidateTarget)
2073 if(substring(turret_target.classname, 0, 10) == "onslaught_") // don't attack onslaught targets, that's the player's job!
2082 MUTATOR_HOOKFUNCTION(ons, TurretThink)
2084 // ONS uses somewhat backwards linking.
2087 entity e = find(world, targetname, self.target);
2092 if(self.team != self.tur_head.team)
2103 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
2104 Link between control points.
2106 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.
2109 "target" - first control point.
2110 "target2" - second control point.
2112 spawnfunc(onslaught_link)
2114 if(!g_onslaught) { remove(self); return; }
2116 if (self.target == "" || self.target2 == "")
2117 objerror("target and target2 must be set\n");
2119 self.ons_worldlinknext = ons_worldlinklist; // link into ons_worldlinklist
2120 ons_worldlinklist = self;
2122 InitializeEntity(self, ons_DelayedLinkSetup, INITPRIO_FINDTARGET);
2123 Net_LinkEntity(self, false, 0, ons_Link_Send);
2126 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
2127 Control point. Be sure to give this enough clearance so that the shootable part has room to exist
2129 This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
2132 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2133 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
2134 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
2137 spawnfunc(onslaught_controlpoint)
2139 if(!g_onslaught) { remove(self); return; }
2141 ons_ControlPoint_Setup(self);
2144 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
2147 spawnfunc_onslaught_link entities can target this.
2150 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
2151 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2153 spawnfunc(onslaught_generator)
2155 if(!g_onslaught) { remove(self); return; }
2156 if(!self.team) { objerror("team must be set"); }
2158 ons_GeneratorSetup(self);
2162 void ons_ScoreRules()
2164 CheckAllowedTeams(world);
2165 ScoreRules_basics(((c4>=0) ? 4 : (c3>=0) ? 3 : 2), SFL_SORT_PRIO_PRIMARY, 0, true);
2166 ScoreInfo_SetLabel_TeamScore (ST_ONS_CAPS, "destroyed", SFL_SORT_PRIO_PRIMARY);
2167 ScoreInfo_SetLabel_PlayerScore(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
2168 ScoreInfo_SetLabel_PlayerScore(SP_ONS_TAKES, "takes", 0);
2169 ScoreRules_basics_end();
2172 void ons_DelayedInit() // Do this check with a delay so we can wait for teams to be set up
2176 round_handler_Spawn(Onslaught_CheckPlayers, Onslaught_CheckWinner, Onslaught_RoundStart);
2177 round_handler_Init(5, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
2180 void ons_Initialize()
2183 ons_captureshield_force = autocvar_g_onslaught_shield_force;
2185 addstat(STAT_ROUNDLOST, AS_INT, ons_roundlost);
2187 InitializeEntity(world, ons_DelayedInit, INITPRIO_GAMETYPE);
2190 REGISTER_MUTATOR(ons, IS_GAMETYPE(ONSLAUGHT))
2193 SetLimits(autocvar_g_onslaught_point_limit, -1, -1, -1);
2194 have_team_spawns = -1; // request team spawns
2198 if(time > 1) // game loads at time 1
2199 error("This is a game type and it cannot be added at runtime.");
2203 MUTATOR_ONROLLBACK_OR_REMOVE
2205 // we actually cannot roll back ons_Initialize here
2206 // BUT: we don't need to! If this gets called, adding always
2212 LOG_INFO("This is a game type and it cannot be removed at runtime.");