4 #include "../controlpoint.qh"
5 #include "../generator.qh"
7 // =======================
8 // CaptureShield Functions
9 // =======================
11 bool ons_CaptureShield_Customize()
13 entity e = WaypointSprite_getviewentity(other);
15 if(!self.enemy.isshielded && (ons_ControlPoint_Attackable(self.enemy, e.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return false; }
16 if(SAME_TEAM(self, e)) { return false; }
21 void ons_CaptureShield_Touch()
23 if(!self.enemy.isshielded && (ons_ControlPoint_Attackable(self.enemy, other.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return; }
24 if(!IS_PLAYER(other)) { return; }
25 if(SAME_TEAM(other, self)) { return; }
27 vector mymid = (self.absmin + self.absmax) * 0.5;
28 vector othermid = (other.absmin + other.absmax) * 0.5;
30 Damage(other, self, self, 0, DEATH_HURTTRIGGER, mymid, normalize(othermid - mymid) * ons_captureshield_force);
32 if(IS_REAL_CLIENT(other))
34 play2(other, "onslaught/damageblockedbyshield.wav");
36 if(self.enemy.classname == "onslaught_generator")
37 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_GENERATOR_SHIELDED);
39 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_CONTROLPOINT_SHIELDED);
43 void ons_CaptureShield_Reset()
45 self.colormap = self.enemy.colormap;
46 self.team = self.enemy.team;
49 void ons_CaptureShield_Spawn(entity generator, bool is_generator)
51 entity shield = spawn();
53 shield.enemy = generator;
54 shield.team = generator.team;
55 shield.colormap = generator.colormap;
56 shield.reset = ons_CaptureShield_Reset;
57 shield.touch = ons_CaptureShield_Touch;
58 shield.customizeentityforclient = ons_CaptureShield_Customize;
59 shield.classname = "ons_captureshield";
60 shield.effects = EF_ADDITIVE;
61 shield.movetype = MOVETYPE_NOCLIP;
62 shield.solid = SOLID_TRIGGER;
63 shield.avelocity = '7 0 11';
65 shield.model = ((is_generator) ? "models/onslaught/generator_shield.md3" : "models/onslaught/controlpoint_shield.md3");
67 precache_model(shield.model);
68 setorigin(shield, generator.origin);
69 setmodel(shield, shield.model);
70 setsize(shield, shield.scale * shield.mins, shield.scale * shield.maxs);
78 void ons_debug(string input)
80 switch(autocvar_g_onslaught_debug)
82 case 1: LOG_TRACE(input); break;
83 case 2: LOG_INFO(input); break;
87 void setmodel_fixsize(entity e, string m)
93 void onslaught_updatelinks()
96 // first check if the game has ended
97 ons_debug("--- updatelinks ---\n");
98 // mark generators as being shielded and networked
99 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
102 ons_debug(strcat(etos(l), " (generator) belongs to team ", ftos(l.team), "\n"));
104 ons_debug(strcat(etos(l), " (generator) is destroyed\n"));
105 l.islinked = l.iscaptured;
106 l.isshielded = l.iscaptured;
107 l.sprite.SendFlags |= 16;
109 // mark points as shielded and not networked
110 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
115 for(i = 0; i < 17; ++i) { l.isgenneighbor[i] = false; l.iscpneighbor[i] = false; }
116 ons_debug(strcat(etos(l), " (point) belongs to team ", ftos(l.team), "\n"));
117 l.sprite.SendFlags |= 16;
119 // flow power outward from the generators through the network
124 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
126 // if both points are captured by the same team, and only one of
127 // them is powered, mark the other one as powered as well
128 if (l.enemy.iscaptured && l.goalentity.iscaptured)
129 if (l.enemy.islinked != l.goalentity.islinked)
130 if(SAME_TEAM(l.enemy, l.goalentity))
132 if (!l.goalentity.islinked)
135 l.goalentity.islinked = true;
136 ons_debug(strcat(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)\n"));
138 else if (!l.enemy.islinked)
141 l.enemy.islinked = true;
142 ons_debug(strcat(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)\n"));
147 // now that we know which points are powered we can mark their neighbors
148 // as unshielded if team differs
149 for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
151 if (l.goalentity.islinked)
153 if(DIFF_TEAM(l.goalentity, l.enemy))
155 ons_debug(strcat(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)\n"));
156 l.enemy.isshielded = false;
158 if(l.goalentity.classname == "onslaught_generator")
159 l.enemy.isgenneighbor[l.goalentity.team] = true;
161 l.enemy.iscpneighbor[l.goalentity.team] = true;
163 if (l.enemy.islinked)
165 if(DIFF_TEAM(l.goalentity, l.enemy))
167 ons_debug(strcat(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)\n"));
168 l.goalentity.isshielded = false;
170 if(l.enemy.classname == "onslaught_generator")
171 l.goalentity.isgenneighbor[l.enemy.team] = true;
173 l.goalentity.iscpneighbor[l.enemy.team] = true;
176 // now update the generators
177 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
181 ons_debug(strcat(etos(l), " (generator) is shielded\n"));
182 l.takedamage = DAMAGE_NO;
183 l.bot_attack = false;
187 ons_debug(strcat(etos(l), " (generator) is not shielded\n"));
188 l.takedamage = DAMAGE_AIM;
192 ons_Generator_UpdateSprite(l);
194 // now update the takedamage and alpha variables on control point icons
195 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
199 ons_debug(strcat(etos(l), " (point) is shielded\n"));
202 l.goalentity.takedamage = DAMAGE_NO;
203 l.goalentity.bot_attack = false;
208 ons_debug(strcat(etos(l), " (point) is not shielded\n"));
211 l.goalentity.takedamage = DAMAGE_AIM;
212 l.goalentity.bot_attack = true;
215 ons_ControlPoint_UpdateSprite(l);
217 l = findchain(classname, "ons_captureshield");
220 l.team = l.enemy.team;
221 l.colormap = l.enemy.colormap;
227 // ===================
228 // Main Link Functions
229 // ===================
231 bool ons_Link_Send(entity to, int sendflags)
233 WriteByte(MSG_ENTITY, ENT_CLIENT_RADARLINK);
234 WriteByte(MSG_ENTITY, sendflags);
237 WriteCoord(MSG_ENTITY, self.goalentity.origin_x);
238 WriteCoord(MSG_ENTITY, self.goalentity.origin_y);
239 WriteCoord(MSG_ENTITY, self.goalentity.origin_z);
243 WriteCoord(MSG_ENTITY, self.enemy.origin_x);
244 WriteCoord(MSG_ENTITY, self.enemy.origin_y);
245 WriteCoord(MSG_ENTITY, self.enemy.origin_z);
249 WriteByte(MSG_ENTITY, self.clientcolors); // which is goalentity's color + enemy's color * 16
254 void ons_Link_CheckUpdate()
256 // TODO check if the two sides have moved (currently they won't move anyway)
257 float cc = 0, cc1 = 0, cc2 = 0;
259 if(self.goalentity.islinked || self.goalentity.iscaptured) { cc1 = (self.goalentity.team - 1) * 0x01; }
260 if(self.enemy.islinked || self.enemy.iscaptured) { cc2 = (self.enemy.team - 1) * 0x10; }
264 if(cc != self.clientcolors)
266 self.clientcolors = cc;
270 self.nextthink = time;
273 void ons_DelayedLinkSetup()
275 self.goalentity = find(world, targetname, self.target);
276 self.enemy = find(world, targetname, self.target2);
277 if(!self.goalentity) { objerror("can not find target\n"); }
278 if(!self.enemy) { objerror("can not find target2\n"); }
280 ons_debug(strcat(etos(self.goalentity), " linked with ", etos(self.enemy), "\n"));
282 self.think = ons_Link_CheckUpdate;
283 self.nextthink = time;
287 // =============================
288 // Main Control Point Functions
289 // =============================
291 int ons_ControlPoint_CanBeLinked(entity cp, int teamnumber)
293 if(cp.isgenneighbor[teamnumber]) { return 2; }
294 if(cp.iscpneighbor[teamnumber]) { return 1; }
299 int ons_ControlPoint_Attackable(entity cp, int teamnumber)
300 // -2: SAME TEAM, attackable by enemy!
305 // 3: attack it (HIGH PRIO)
306 // 4: touch it (HIGH PRIO)
314 else if(cp.goalentity)
316 // if there's already an icon built, nothing happens
317 if(cp.team == teamnumber)
319 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
320 if(a) // attackable by enemy?
321 return -2; // EMERGENCY!
324 // we know it can be linked, so no need to check
326 a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
327 if(a == 2) // near our generator?
328 return 3; // EMERGENCY!
334 if(ons_ControlPoint_CanBeLinked(cp, teamnumber))
336 a = ons_ControlPoint_CanBeLinked(cp, teamnumber); // why was this here NUM_TEAM_1 + NUM_TEAM_2 - t
338 return 4; // GET THIS ONE NOW!
340 return 2; // TOUCH ME
346 void ons_ControlPoint_Icon_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
348 if(damage <= 0) { return; }
350 if (self.owner.isshielded)
352 // this is protected by a shield, so ignore the damage
353 if (time > self.pain_finished)
354 if (IS_PLAYER(attacker))
356 play2(attacker, "onslaught/damageblockedbyshield.wav");
357 self.pain_finished = time + 1;
358 attacker.typehitsound += 1; // play both sounds (shield is way too quiet)
364 if(IS_PLAYER(attacker))
365 if(time - ons_notification_time[self.team] > 10)
367 play2team(self.team, "onslaught/controlpoint_underattack.wav");
368 ons_notification_time[self.team] = time;
371 self.health = self.health - damage;
372 if(self.owner.iscaptured)
373 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
375 WaypointSprite_UpdateBuildFinished(self.owner.sprite, time + (self.max_health - self.health) / (self.count / ONS_CP_THINKRATE));
376 self.pain_finished = time + 1;
377 // particles on every hit
378 pointparticles(particleeffectnum(EFFECT_SPARKS), hitloc, force*-1, 1);
381 sound(self, CH_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE+0.3, ATTEN_NORM);
383 sound(self, CH_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE+0.3, ATTEN_NORM);
387 sound(self, CH_TRIGGER, W_Sound("grenade_impact"), VOL_BASE, ATTEN_NORM);
388 pointparticles(particleeffectnum(EFFECT_ROCKET_EXPLODE), self.origin, '0 0 0', 1);
389 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_CPDESTROYED_), self.owner.message, attacker.netname);
391 PlayerScore_Add(attacker, SP_ONS_TAKES, 1);
392 PlayerScore_Add(attacker, SP_SCORE, 10);
394 self.owner.goalentity = world;
395 self.owner.islinked = false;
396 self.owner.iscaptured = false;
398 self.owner.colormap = 1024;
400 WaypointSprite_UpdateMaxHealth(self.owner.sprite, 0);
402 onslaught_updatelinks();
404 // Use targets now (somebody make sure this is in the right place..)
410 self.owner.waslinked = self.owner.islinked;
411 if(self.owner.model != "models/onslaught/controlpoint_pad.md3")
412 setmodel_fixsize(self.owner, "models/onslaught/controlpoint_pad.md3");
413 //setsize(self, '-32 -32 0', '32 32 8');
418 self.SendFlags |= CPSF_STATUS;
421 void ons_ControlPoint_Icon_Think()
423 self.nextthink = time + ONS_CP_THINKRATE;
425 if(autocvar_g_onslaught_cp_proxydecap)
427 int _enemy_count = 0;
428 int _friendly_count = 0;
432 FOR_EACH_PLAYER(_player)
434 if(!_player.deadflag)
436 _dist = vlen(_player.origin - self.origin);
437 if(_dist < autocvar_g_onslaught_cp_proxydecap_distance)
439 if(SAME_TEAM(_player, self))
447 _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
448 _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
450 self.health = bound(0, self.health + (_friendly_count - _enemy_count), self.max_health);
451 self.SendFlags |= CPSF_STATUS;
454 ons_ControlPoint_Icon_Damage(self, self, 1, 0, self.origin, '0 0 0');
459 if (time > self.pain_finished + 5)
461 if(self.health < self.max_health)
463 self.health = self.health + self.count;
464 if (self.health >= self.max_health)
465 self.health = self.max_health;
466 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
470 if(self.owner.islinked != self.owner.waslinked)
472 // unteam the spawnpoint if needed
473 int t = self.owner.team;
474 if(!self.owner.islinked)
484 self.owner.waslinked = self.owner.islinked;
488 if(random() < 0.6 - self.health / self.max_health)
490 Send_Effect(EFFECT_ELECTRIC_SPARKS, self.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
493 sound(self, CH_PAIN, "onslaught/ons_spark1.wav", VOL_BASE, ATTEN_NORM);
494 else if (random() > 0.5)
495 sound(self, CH_PAIN, "onslaught/ons_spark2.wav", VOL_BASE, ATTEN_NORM);
499 void ons_ControlPoint_Icon_BuildThink()
503 self.nextthink = time + ONS_CP_THINKRATE;
505 // only do this if there is power
506 a = ons_ControlPoint_CanBeLinked(self.owner, self.owner.team);
510 self.health = self.health + self.count;
512 self.SendFlags |= CPSF_STATUS;
514 if (self.health >= self.max_health)
516 self.health = self.max_health;
517 self.count = autocvar_g_onslaught_cp_regen * ONS_CP_THINKRATE; // slow repair rate from now on
518 self.think = ons_ControlPoint_Icon_Think;
519 sound(self, CH_TRIGGER, "onslaught/controlpoint_built.wav", VOL_BASE, ATTEN_NORM);
520 self.owner.iscaptured = true;
521 self.solid = SOLID_BBOX;
523 Send_Effect_(sprintf("%s_cap", Static_Team_ColorName_Lower(self.owner.team)), self.owner.origin, '0 0 0', 1);
525 WaypointSprite_UpdateMaxHealth(self.owner.sprite, self.max_health);
526 WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
528 if(IS_PLAYER(self.owner.ons_toucher))
530 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ONSLAUGHT_CAPTURE, self.owner.ons_toucher.netname, self.owner.message);
531 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);
532 Send_Notification(NOTIF_ONE, self.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE, self.owner.message);
533 PlayerScore_Add(self.owner.ons_toucher, SP_ONS_CAPS, 1);
534 PlayerTeamScore_AddScore(self.owner.ons_toucher, 10);
537 self.owner.ons_toucher = world;
539 onslaught_updatelinks();
541 // Use targets now (somebody make sure this is in the right place..)
547 self.SendFlags |= CPSF_SETUP;
549 if(self.owner.model != "models/onslaught/controlpoint_pad2.md3")
550 setmodel_fixsize(self.owner, "models/onslaught/controlpoint_pad2.md3");
552 if(random() < 0.9 - self.health / self.max_health)
553 Send_Effect(EFFECT_RAGE, self.origin + 10 * randomvec(), '0 0 -1', 1);
556 void ons_ControlPoint_Icon_Spawn(entity cp, entity player)
560 setsize(e, CPICON_MIN, CPICON_MAX);
561 setorigin(e, cp.origin + CPICON_OFFSET);
563 e.classname = "onslaught_controlpoint_icon";
565 e.max_health = autocvar_g_onslaught_cp_health;
566 e.health = autocvar_g_onslaught_cp_buildhealth;
568 e.takedamage = DAMAGE_AIM;
570 e.event_damage = ons_ControlPoint_Icon_Damage;
571 e.team = player.team;
572 e.colormap = 1024 + (e.team - 1) * 17;
573 e.count = (e.max_health - e.health) * ONS_CP_THINKRATE / autocvar_g_onslaught_cp_buildtime; // how long it takes to build
575 sound(e, CH_TRIGGER, "onslaught/controlpoint_build.wav", VOL_BASE, ATTEN_NORM);
579 cp.colormap = e.colormap;
581 Send_Effect_(sprintf("%sflag_touch", Static_Team_ColorName_Lower(player.team)), e.origin, '0 0 0', 1);
583 WaypointSprite_UpdateBuildFinished(cp.sprite, time + (e.max_health - e.health) / (e.count / ONS_CP_THINKRATE));
584 WaypointSprite_UpdateRule(cp.sprite,cp.team,SPRITERULE_TEAMPLAY);
585 cp.sprite.SendFlags |= 16;
587 onslaught_controlpoint_icon_link(e, ons_ControlPoint_Icon_BuildThink);
590 entity ons_ControlPoint_Waypoint(entity e)
594 int a = ons_ControlPoint_Attackable(e, e.team);
596 if(a == -2) { return WP_OnsCPDefend; } // defend now
597 if(a == -1 || a == 1 || a == 2) { return WP_OnsCP; } // touch
598 if(a == 3 || a == 4) { return WP_OnsCPAttack; } // attack
606 void ons_ControlPoint_UpdateSprite(entity e)
608 entity s1 = ons_ControlPoint_Waypoint(e);
609 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
612 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));
614 if(e.lastteam != e.team + 2 || e.lastshielded != sh || e.iscaptured != e.lastcaptured)
616 if(e.iscaptured) // don't mess up build bars!
620 WaypointSprite_UpdateMaxHealth(e.sprite, 0);
624 WaypointSprite_UpdateMaxHealth(e.sprite, e.goalentity.max_health);
625 WaypointSprite_UpdateHealth(e.sprite, e.goalentity.health);
631 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, false));
633 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
638 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, false));
640 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
642 WaypointSprite_Ping(e.sprite);
644 e.lastteam = e.team + 2;
646 e.lastcaptured = e.iscaptured;
650 void ons_ControlPoint_Touch()
652 entity toucher = other;
655 if(IS_VEHICLE(toucher) && toucher.owner)
656 if(autocvar_g_onslaught_allow_vehicle_touch)
657 toucher = toucher.owner;
661 if(!IS_PLAYER(toucher)) { return; }
662 if(toucher.frozen) { return; }
663 if(toucher.deadflag != DEAD_NO) { return; }
665 if ( SAME_TEAM(self,toucher) )
666 if ( self.iscaptured )
668 if(time <= toucher.teleport_antispam)
669 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT_ANTISPAM, rint(toucher.teleport_antispam - time));
671 Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
674 attackable = ons_ControlPoint_Attackable(self, toucher.team);
675 if(attackable != 2 && attackable != 4)
677 // we've verified that this player has a legitimate claim to this point,
678 // so start building the captured point icon (which only captures this
679 // point if it successfully builds without being destroyed first)
680 ons_ControlPoint_Icon_Spawn(self, toucher);
682 self.ons_toucher = toucher;
684 onslaught_updatelinks();
687 void ons_ControlPoint_Think()
689 self.nextthink = time + ONS_CP_THINKRATE;
690 CSQCMODEL_AUTOUPDATE(self);
693 void ons_ControlPoint_Reset()
696 remove(self.goalentity);
698 self.goalentity = world;
700 self.colormap = 1024;
701 self.iscaptured = false;
702 self.islinked = false;
703 self.isshielded = true;
704 self.think = ons_ControlPoint_Think;
705 self.ons_toucher = world;
706 self.nextthink = time + ONS_CP_THINKRATE;
707 setmodel_fixsize(self, "models/onslaught/controlpoint_pad.md3");
709 WaypointSprite_UpdateMaxHealth(self.sprite, 0);
710 WaypointSprite_UpdateRule(self.sprite,self.team,SPRITERULE_TEAMPLAY);
712 onslaught_updatelinks();
715 SUB_UseTargets(); // to reset the structures, playerspawns etc.
717 CSQCMODEL_AUTOUPDATE(self);
720 void ons_DelayedControlPoint_Setup(void)
722 onslaught_updatelinks();
724 // captureshield setup
725 ons_CaptureShield_Spawn(self, false);
727 CSQCMODEL_AUTOINIT(self);
730 void ons_ControlPoint_Setup(entity cp)
733 setself(cp); // for later usage with droptofloor()
736 cp.ons_worldcpnext = ons_worldcplist; // link control point into ons_worldcplist
737 ons_worldcplist = cp;
739 cp.netname = "Control point";
741 cp.solid = SOLID_BBOX;
742 cp.movetype = MOVETYPE_NONE;
743 cp.touch = ons_ControlPoint_Touch;
744 cp.think = ons_ControlPoint_Think;
745 cp.nextthink = time + ONS_CP_THINKRATE;
746 cp.reset = ons_ControlPoint_Reset;
748 cp.iscaptured = false;
750 cp.isshielded = true;
752 if(cp.message == "") { cp.message = "a"; }
754 // precache - TODO: clean up!
755 precache_model("models/onslaught/controlpoint_pad.md3");
756 precache_model("models/onslaught/controlpoint_pad2.md3");
757 precache_model("models/onslaught/controlpoint_shield.md3");
758 precache_model("models/onslaught/controlpoint_icon.md3");
759 precache_model("models/onslaught/controlpoint_icon_dmg1.md3");
760 precache_model("models/onslaught/controlpoint_icon_dmg2.md3");
761 precache_model("models/onslaught/controlpoint_icon_dmg3.md3");
762 precache_model("models/onslaught/controlpoint_icon_gib1.md3");
763 precache_model("models/onslaught/controlpoint_icon_gib2.md3");
764 precache_model("models/onslaught/controlpoint_icon_gib4.md3");
765 precache_sound("onslaught/controlpoint_build.wav");
766 precache_sound("onslaught/controlpoint_built.wav");
767 precache_sound(W_Sound("grenade_impact"));
768 precache_sound("onslaught/damageblockedbyshield.wav");
769 precache_sound("onslaught/controlpoint_underattack.wav");
770 precache_sound("onslaught/ons_spark1.wav");
771 precache_sound("onslaught/ons_spark2.wav");
774 setmodel_fixsize(cp, "models/onslaught/controlpoint_pad.md3");
776 // control point placement
777 if((cp.spawnflags & 1) || cp.noalign) // don't drop to floor, just stay at fixed location
780 cp.movetype = MOVETYPE_NONE;
782 else // drop to floor, automatically find a platform and set that as spawn origin
784 setorigin(cp, cp.origin + '0 0 20');
788 cp.movetype = MOVETYPE_TOSS;
792 WaypointSprite_SpawnFixed(WP_Null, self.origin + CPGEN_WAYPOINT_OFFSET, self, sprite, RADARICON_NONE);
793 WaypointSprite_UpdateRule(self.sprite, self.team, SPRITERULE_TEAMPLAY);
795 InitializeEntity(cp, ons_DelayedControlPoint_Setup, INITPRIO_SETLOCATION);
799 // =========================
800 // Main Generator Functions
801 // =========================
803 entity ons_Generator_Waypoint(entity e)
806 return WP_OnsGenShielded;
810 void ons_Generator_UpdateSprite(entity e)
812 entity s1 = ons_Generator_Waypoint(e);
813 WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
815 if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
817 e.lastteam = e.team + 2;
818 e.lastshielded = e.isshielded;
822 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, false));
824 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
829 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, false));
831 WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
833 WaypointSprite_Ping(e.sprite);
837 void ons_GeneratorDamage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
839 if(damage <= 0) { return; }
840 if(warmup_stage || gameover) { return; }
841 if(!round_handler_IsRoundStarted()) { return; }
843 if (attacker != self)
847 // this is protected by a shield, so ignore the damage
848 if (time > self.pain_finished)
849 if (IS_PLAYER(attacker))
851 play2(attacker, "onslaught/damageblockedbyshield.wav");
852 attacker.typehitsound += 1;
853 self.pain_finished = time + 1;
857 if (time > self.pain_finished)
859 self.pain_finished = time + 10;
861 FOR_EACH_REALPLAYER(head) if(SAME_TEAM(head, self)) { Send_Notification(NOTIF_ONE, head, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK); }
862 play2team(self.team, "onslaught/generator_underattack.wav");
865 self.health = self.health - damage;
866 WaypointSprite_UpdateHealth(self.sprite, self.health);
867 // choose an animation frame based on health
868 self.frame = 10 * bound(0, (1 - self.health / self.max_health), 1);
869 // see if the generator is still functional, or dying
872 self.lasthealth = self.health;
876 if (attacker == self)
877 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME_));
880 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_GENDESTROYED_));
881 PlayerScore_Add(attacker, SP_SCORE, 100);
883 self.iscaptured = false;
884 self.islinked = false;
885 self.isshielded = false;
886 self.takedamage = DAMAGE_NO; // can't be hurt anymore
887 self.event_damage = func_null; // won't do anything if hurt
888 self.count = 0; // reset counter
889 self.think = func_null;
891 //self.think(); // do the first explosion now
893 WaypointSprite_UpdateMaxHealth(self.sprite, 0);
894 WaypointSprite_Ping(self.sprite);
895 //WaypointSprite_Kill(self.sprite); // can't do this yet, code too poor
897 onslaught_updatelinks();
900 // Throw some flaming gibs on damage, more damage = more chance for gib
901 if(random() < damage/220)
903 sound(self, CH_TRIGGER, W_Sound("rocket_impact"), VOL_BASE, ATTEN_NORM);
907 // particles on every hit
908 Send_Effect(EFFECT_SPARKS, hitloc, force * -1, 1);
912 sound(self, CH_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE, ATTEN_NORM);
914 sound(self, CH_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM);
917 self.SendFlags |= GSF_STATUS;
920 void ons_GeneratorThink()
923 self.nextthink = time + GEN_THINKRATE;
926 if(!self.isshielded && self.wait < time)
928 self.wait = time + 5;
929 FOR_EACH_REALPLAYER(e)
931 if(SAME_TEAM(e, self))
933 Send_Notification(NOTIF_ONE, e, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM);
934 soundto(MSG_ONE, e, CHAN_AUTO, "kh/alarm.wav", VOL_BASE, ATTEN_NONE); // FIXME: unique sound?
937 Send_Notification(NOTIF_ONE, e, MSG_CENTER, APP_TEAM_NUM_4(self.team, CENTER_ONS_NOTSHIELDED_));
943 void ons_GeneratorReset()
945 self.team = self.team_saved;
946 self.lasthealth = self.max_health = self.health = autocvar_g_onslaught_gen_health;
947 self.takedamage = DAMAGE_AIM;
948 self.bot_attack = true;
949 self.iscaptured = true;
950 self.islinked = true;
951 self.isshielded = true;
952 self.event_damage = ons_GeneratorDamage;
953 self.think = ons_GeneratorThink;
954 self.nextthink = time + GEN_THINKRATE;
956 Net_LinkEntity(self, false, 0, generator_send);
958 self.SendFlags = GSF_SETUP; // just incase
959 self.SendFlags |= GSF_STATUS;
961 WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
962 WaypointSprite_UpdateHealth(self.sprite, self.health);
963 WaypointSprite_UpdateRule(self.sprite,self.team,SPRITERULE_TEAMPLAY);
965 onslaught_updatelinks();
968 void ons_DelayedGeneratorSetup()
971 waypoint_spawnforitem_force(self, self.origin);
972 self.nearestwaypointtimeout = 0; // activate waypointing again
973 self.bot_basewaypoint = self.nearestwaypoint;
975 // captureshield setup
976 ons_CaptureShield_Spawn(self, true);
978 onslaught_updatelinks();
980 Net_LinkEntity(self, false, 0, generator_send);
984 void onslaught_generator_touch()
986 if ( IS_PLAYER(other) )
987 if ( SAME_TEAM(self,other) )
988 if ( self.iscaptured )
990 Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_TELEPORT);
994 void ons_GeneratorSetup(entity gen) // called when spawning a generator entity on the map as a spawnfunc
997 int teamnumber = gen.team;
998 setself(gen); // for later usage with droptofloor()
1001 gen.ons_worldgeneratornext = ons_worldgeneratorlist; // link generator into ons_worldgeneratorlist
1002 ons_worldgeneratorlist = gen;
1004 gen.netname = sprintf("%s generator", Team_ColoredFullName(teamnumber));
1005 gen.classname = "onslaught_generator";
1006 gen.solid = SOLID_BBOX;
1007 gen.team_saved = teamnumber;
1008 gen.movetype = MOVETYPE_NONE;
1009 gen.lasthealth = gen.max_health = gen.health = autocvar_g_onslaught_gen_health;
1010 gen.takedamage = DAMAGE_AIM;
1011 gen.bot_attack = true;
1012 gen.event_damage = ons_GeneratorDamage;
1013 gen.reset = ons_GeneratorReset;
1014 gen.think = ons_GeneratorThink;
1015 gen.nextthink = time + GEN_THINKRATE;
1016 gen.iscaptured = true;
1017 gen.islinked = true;
1018 gen.isshielded = true;
1019 gen.touch = onslaught_generator_touch;
1021 // precache - TODO: clean up!
1022 precache_model("models/onslaught/generator_shield.md3");
1023 precache_model("models/onslaught/gen_gib1.md3");
1024 precache_model("models/onslaught/gen_gib2.md3");
1025 precache_model("models/onslaught/gen_gib3.md3");
1026 precache_sound("onslaught/generator_decay.wav");
1027 precache_sound(W_Sound("grenade_impact"));
1028 precache_sound(W_Sound("rocket_impact"));
1029 precache_sound("onslaught/generator_underattack.wav");
1030 precache_sound("onslaught/shockwave.wav");
1031 precache_sound("onslaught/ons_hit1.wav");
1032 precache_sound("onslaught/ons_hit2.wav");
1033 precache_sound("onslaught/generator_underattack.wav");
1036 // model handled by CSQC
1037 setsize(gen, GENERATOR_MIN, GENERATOR_MAX);
1038 setorigin(gen, (gen.origin + CPGEN_SPAWN_OFFSET));
1039 gen.colormap = 1024 + (teamnumber - 1) * 17;
1041 // generator placement
1046 WaypointSprite_SpawnFixed(WP_Null, self.origin + CPGEN_WAYPOINT_OFFSET, self, sprite, RADARICON_NONE);
1047 WaypointSprite_UpdateRule(self.sprite, self.team, SPRITERULE_TEAMPLAY);
1048 WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
1049 WaypointSprite_UpdateHealth(self.sprite, self.health);
1051 InitializeEntity(gen, ons_DelayedGeneratorSetup, INITPRIO_SETLOCATION);
1059 int total_generators;
1060 void Onslaught_count_generators()
1063 total_generators = redowned = blueowned = yellowowned = pinkowned = 0;
1064 for(e = ons_worldgeneratorlist; e; e = e.ons_worldgeneratornext)
1067 redowned += (e.team == NUM_TEAM_1 && e.health > 0);
1068 blueowned += (e.team == NUM_TEAM_2 && e.health > 0);
1069 yellowowned += (e.team == NUM_TEAM_3 && e.health > 0);
1070 pinkowned += (e.team == NUM_TEAM_4 && e.health > 0);
1074 int Onslaught_GetWinnerTeam()
1076 int winner_team = 0;
1078 winner_team = NUM_TEAM_1;
1081 if(winner_team) return 0;
1082 winner_team = NUM_TEAM_2;
1086 if(winner_team) return 0;
1087 winner_team = NUM_TEAM_3;
1091 if(winner_team) return 0;
1092 winner_team = NUM_TEAM_4;
1096 return -1; // no generators left?
1099 #define ONS_OWNED_GENERATORS() ((redowned > 0) + (blueowned > 0) + (yellowowned > 0) + (pinkowned > 0))
1100 #define ONS_OWNED_GENERATORS_OK() (ONS_OWNED_GENERATORS() > 1)
1101 bool Onslaught_CheckWinner()
1105 if ((autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60) || (round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0))
1107 ons_stalemate = true;
1109 if (!wpforenemy_announced)
1111 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT);
1112 sound(world, CH_INFO, "onslaught/generator_decay.wav", VOL_BASE, ATTEN_NONE);
1114 wpforenemy_announced = true;
1117 entity tmp_entity; // temporary entity
1119 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext) if(time >= tmp_entity.ons_overtime_damagedelay)
1121 // tmp_entity.max_health / 300 gives 5 minutes of overtime.
1122 // control points reduce the overtime duration.
1124 for(e = ons_worldcplist; e; e = e.ons_worldcpnext)
1126 if(DIFF_TEAM(e, tmp_entity))
1131 if(autocvar_g_campaign && autocvar__campaign_testrun)
1132 d = d * tmp_entity.max_health;
1134 d = d * tmp_entity.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
1136 Damage(tmp_entity, tmp_entity, tmp_entity, d, DEATH_HURTTRIGGER, tmp_entity.origin, '0 0 0');
1138 tmp_entity.sprite.SendFlags |= 16;
1140 tmp_entity.ons_overtime_damagedelay = time + 1;
1143 else { wpforenemy_announced = false; ons_stalemate = false; }
1145 Onslaught_count_generators();
1147 if(ONS_OWNED_GENERATORS_OK())
1150 int winner_team = Onslaught_GetWinnerTeam();
1154 Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
1155 Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
1156 TeamScore_AddToTeam(winner_team, ST_ONS_CAPS, +1);
1158 else if(winner_team == -1)
1160 Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
1161 Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
1164 ons_stalemate = false;
1166 play2all(sprintf("ctf/%s_capture.wav", Static_Team_ColorName_Lower(winner_team)));
1168 round_handler_Init(7, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
1172 e.ons_roundlost = true;
1173 e.player_blocked = true;
1181 bool Onslaught_CheckPlayers()
1186 void Onslaught_RoundStart()
1189 FOR_EACH_PLAYER(tmp_entity) { tmp_entity.player_blocked = false; }
1191 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1192 tmp_entity.sprite.SendFlags |= 16;
1194 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1195 tmp_entity.sprite.SendFlags |= 16;
1203 // NOTE: LEGACY CODE, needs to be re-written!
1205 void havocbot_goalrating_ons_offenseitems(float ratingscale, vector org, float sradius)
1210 bool needarmor = false, needweapons = false;
1212 // Needs armor/health?
1218 for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
1221 if(self.weapons & WepSet_FromWeapon(i))
1229 if(!needweapons && !needarmor)
1232 ons_debug(strcat(self.netname, " needs weapons ", ftos(needweapons) , "\n"));
1233 ons_debug(strcat(self.netname, " needs armor ", ftos(needarmor) , "\n"));
1235 // See what is around
1236 head = findchainfloat(bot_pickup, true);
1239 // gather health and armor only
1241 if ( ((head.health || head.armorvalue) && needarmor) || (head.weapons && needweapons ) )
1242 if (vlen(head.origin - org) < sradius)
1244 t = head.bot_pickupevalfunc(self, head);
1246 navigation_routerating(head, t * ratingscale, 500);
1252 void havocbot_role_ons_setrole(entity bot, int role)
1254 ons_debug(strcat(bot.netname," switched to "));
1257 case HAVOCBOT_ONS_ROLE_DEFENSE:
1258 ons_debug("defense");
1259 bot.havocbot_role = havocbot_role_ons_defense;
1260 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE;
1261 bot.havocbot_role_timeout = 0;
1263 case HAVOCBOT_ONS_ROLE_ASSISTANT:
1264 ons_debug("assistant");
1265 bot.havocbot_role = havocbot_role_ons_assistant;
1266 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT;
1267 bot.havocbot_role_timeout = 0;
1269 case HAVOCBOT_ONS_ROLE_OFFENSE:
1270 ons_debug("offense");
1271 bot.havocbot_role = havocbot_role_ons_offense;
1272 bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE;
1273 bot.havocbot_role_timeout = 0;
1279 int havocbot_ons_teamcount(entity bot, int role)
1284 FOR_EACH_PLAYER(head)
1285 if(SAME_TEAM(head, self))
1286 if(head.havocbot_role_flags & role)
1292 void havocbot_goalrating_ons_controlpoints_attack(float ratingscale)
1294 entity cp, cp1, cp2, best, pl, wp;
1295 float radius, bestvalue;
1299 // Filter control points
1300 for(cp2 = ons_worldcplist; cp2; cp2 = cp2.ons_worldcpnext)
1303 cp2.wpconsidered = false;
1308 // Ignore owned controlpoints
1309 if(!(cp2.isgenneighbor[self.team] || cp2.iscpneighbor[self.team]))
1312 // Count team mates interested in this control point
1313 // (easier and cleaner than keeping counters per cp and teams)
1315 if(SAME_TEAM(pl, self))
1316 if(pl.havocbot_role_flags & HAVOCBOT_ONS_ROLE_OFFENSE)
1317 if(pl.havocbot_ons_target==cp2)
1320 // NOTE: probably decrease the cost of attackable control points
1322 cp2.wpconsidered = true;
1325 // We'll consider only the best case
1326 bestvalue = 99999999999;
1328 for(cp1 = ons_worldcplist; cp1; cp1 = cp1.ons_worldcpnext)
1330 if (!cp1.wpconsidered)
1333 if(cp1.wpcost<bestvalue)
1335 bestvalue = cp1.wpcost;
1337 self.havocbot_ons_target = cp1;
1344 ons_debug(strcat(self.netname, " chose cp ranked ", ftos(bestvalue), "\n"));
1348 // Should be attacked
1349 // Rate waypoints near it
1352 bestvalue = 99999999999;
1353 for(radius=0; radius<1000 && !found; radius+=500)
1355 for(wp=findradius(cp.origin,radius); wp; wp=wp.chain)
1357 if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
1358 if(wp.classname=="waypoint")
1359 if(checkpvs(wp.origin,cp))
1362 if(wp.cnt<bestvalue)
1373 navigation_routerating(best, ratingscale, 10000);
1376 self.havocbot_attack_time = 0;
1377 if(checkpvs(self.view_ofs,cp))
1378 if(checkpvs(self.view_ofs,best))
1379 self.havocbot_attack_time = time + 2;
1383 navigation_routerating(cp, ratingscale, 10000);
1385 ons_debug(strcat(self.netname, " found an attackable controlpoint at ", vtos(cp.origin) ,"\n"));
1389 // Should be touched
1390 ons_debug(strcat(self.netname, " found a touchable controlpoint at ", vtos(cp.origin) ,"\n"));
1393 // Look for auto generated waypoint
1394 if (!bot_waypoints_for_items)
1395 for (wp = findradius(cp.origin,100); wp; wp = wp.chain)
1397 if(wp.classname=="waypoint")
1399 navigation_routerating(wp, ratingscale, 10000);
1404 // Nothing found, rate the controlpoint itself
1406 navigation_routerating(cp, ratingscale, 10000);
1410 bool havocbot_goalrating_ons_generator_attack(float ratingscale)
1412 entity g, wp, bestwp;
1416 for(g = ons_worldgeneratorlist; g; g = g.ons_worldgeneratornext)
1418 if(SAME_TEAM(g, self) || g.isshielded)
1421 // Should be attacked
1422 // Rate waypoints near it
1427 for(wp=findradius(g.origin,400); wp; wp=wp.chain)
1429 if(wp.classname=="waypoint")
1430 if(checkpvs(wp.origin,g))
1443 ons_debug("waypoints found around generator\n");
1444 navigation_routerating(bestwp, ratingscale, 10000);
1447 self.havocbot_attack_time = 0;
1448 if(checkpvs(self.view_ofs,g))
1449 if(checkpvs(self.view_ofs,bestwp))
1450 self.havocbot_attack_time = time + 5;
1456 ons_debug("generator found without waypoints around\n");
1457 // if there aren't waypoints near the generator go straight to it
1458 navigation_routerating(g, ratingscale, 10000);
1459 self.havocbot_attack_time = 0;
1466 void havocbot_role_ons_offense()
1468 if(self.deadflag != DEAD_NO)
1470 self.havocbot_attack_time = 0;
1471 havocbot_ons_reset_role(self);
1475 // Set the role timeout if necessary
1476 if (!self.havocbot_role_timeout)
1477 self.havocbot_role_timeout = time + 120;
1479 if (time > self.havocbot_role_timeout)
1481 havocbot_ons_reset_role(self);
1485 if(self.havocbot_attack_time>time)
1488 if (self.bot_strategytime < time)
1490 navigation_goalrating_start();
1491 havocbot_goalrating_enemyplayers(20000, self.origin, 650);
1492 if(!havocbot_goalrating_ons_generator_attack(20000))
1493 havocbot_goalrating_ons_controlpoints_attack(20000);
1494 havocbot_goalrating_ons_offenseitems(10000, self.origin, 10000);
1495 navigation_goalrating_end();
1497 self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
1501 void havocbot_role_ons_assistant()
1503 havocbot_ons_reset_role(self);
1506 void havocbot_role_ons_defense()
1508 havocbot_ons_reset_role(self);
1511 void havocbot_ons_reset_role(entity bot)
1516 if(self.deadflag != DEAD_NO)
1519 bot.havocbot_ons_target = world;
1521 // TODO: Defend control points or generator if necessary
1523 // if there is only me on the team switch to offense
1525 FOR_EACH_PLAYER(head)
1526 if(SAME_TEAM(head, self))
1531 havocbot_role_ons_setrole(bot, HAVOCBOT_ONS_ROLE_OFFENSE);
1535 havocbot_role_ons_setrole(bot, HAVOCBOT_ONS_ROLE_OFFENSE);
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
1543 entity ons_Nearest_ControlPoint(vector pos, float max_dist)
1545 entity tmp_entity, closest_target = world;
1546 tmp_entity = findchain(classname, "onslaught_controlpoint");
1549 if(SAME_TEAM(tmp_entity, self))
1550 if(tmp_entity.iscaptured)
1551 if(max_dist <= 0 || vlen(tmp_entity.origin - pos) <= max_dist)
1552 if(vlen(tmp_entity.origin - pos) <= vlen(closest_target.origin - pos) || closest_target == world)
1553 closest_target = tmp_entity;
1554 tmp_entity = tmp_entity.chain;
1556 tmp_entity = findchain(classname, "onslaught_generator");
1559 if(SAME_TEAM(tmp_entity, self))
1560 if(max_dist <= 0 || vlen(tmp_entity.origin - pos) < max_dist)
1561 if(vlen(tmp_entity.origin - pos) <= vlen(closest_target.origin - pos) || closest_target == world)
1562 closest_target = tmp_entity;
1563 tmp_entity = tmp_entity.chain;
1566 return closest_target;
1570 * Find control point or generator owned by the same team self which is nearest to pos
1571 * if max_dist is positive, only control points within this range will be considered
1572 * This function only check distances on the XY plane, disregarding Z
1574 entity ons_Nearest_ControlPoint_2D(vector pos, float max_dist)
1576 entity tmp_entity, closest_target = world;
1578 float smallest_distance = 0, distance;
1580 tmp_entity = findchain(classname, "onslaught_controlpoint");
1583 delta = tmp_entity.origin - pos;
1585 distance = vlen(delta);
1587 if(SAME_TEAM(tmp_entity, self))
1588 if(tmp_entity.iscaptured)
1589 if(max_dist <= 0 || distance <= max_dist)
1590 if(closest_target == world || distance <= smallest_distance )
1592 closest_target = tmp_entity;
1593 smallest_distance = distance;
1596 tmp_entity = tmp_entity.chain;
1598 tmp_entity = findchain(classname, "onslaught_generator");
1601 delta = tmp_entity.origin - pos;
1603 distance = vlen(delta);
1605 if(SAME_TEAM(tmp_entity, self))
1606 if(max_dist <= 0 || distance <= max_dist)
1607 if(closest_target == world || distance <= smallest_distance )
1609 closest_target = tmp_entity;
1610 smallest_distance = distance;
1613 tmp_entity = tmp_entity.chain;
1616 return closest_target;
1619 * find the number of control points and generators in the same team as self
1621 int ons_Count_SelfControlPoints()
1624 tmp_entity = findchain(classname, "onslaught_controlpoint");
1628 if(SAME_TEAM(tmp_entity, self))
1629 if(tmp_entity.iscaptured)
1631 tmp_entity = tmp_entity.chain;
1633 tmp_entity = findchain(classname, "onslaught_generator");
1636 if(SAME_TEAM(tmp_entity, self))
1638 tmp_entity = tmp_entity.chain;
1644 * Teleport player to a random position near tele_target
1645 * if tele_effects is true, teleport sound+particles are created
1646 * return false on failure
1648 bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effects)
1656 for(i = 0; i < 16; ++i)
1658 theta = random() * 2 * M_PI;
1662 loc *= random() * range;
1664 loc += tele_target.origin + '0 0 128';
1666 tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, player);
1667 if(trace_fraction == 1.0 && !trace_startsolid)
1669 traceline(tele_target.origin, loc, MOVE_NOMONSTERS, tele_target); // double check to make sure we're not spawning outside the world
1670 if(trace_fraction == 1.0 && !trace_startsolid)
1674 Send_Effect(EFFECT_TELEPORT, player.origin, '0 0 0', 1);
1675 sound (player, CH_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTEN_NORM);
1677 setorigin(player, loc);
1678 player.angles = '0 1 0' * ( theta * RAD2DEG + 180 );
1679 makevectors(player.angles);
1680 player.fixangle = true;
1681 player.teleport_antispam = time + autocvar_g_onslaught_teleport_wait;
1684 Send_Effect(EFFECT_TELEPORT, player.origin + v_forward * 32, '0 0 0', 1);
1697 MUTATOR_HOOKFUNCTION(ons_ResetMap)
1702 e.ons_roundlost = false;
1703 e.ons_deathloc = '0 0 0';
1704 WITH(entity, self, e, PutClientInServer());
1709 MUTATOR_HOOKFUNCTION(ons_RemovePlayer)
1711 self.ons_deathloc = '0 0 0';
1715 MUTATOR_HOOKFUNCTION(ons_PlayerSpawn)
1717 if(!round_handler_IsRoundStarted())
1719 self.player_blocked = true;
1724 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1726 l.sprite.SendFlags |= 16;
1728 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1730 l.sprite.SendFlags |= 16;
1733 if(ons_stalemate) { Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); }
1735 if ( autocvar_g_onslaught_spawn_choose )
1736 if ( self.ons_spawn_by )
1737 if ( ons_Teleport(self,self.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) )
1739 self.ons_spawn_by = world;
1743 if(autocvar_g_onslaught_spawn_at_controlpoints)
1744 if(random() <= autocvar_g_onslaught_spawn_at_controlpoints_chance)
1746 float random_target = autocvar_g_onslaught_spawn_at_controlpoints_random;
1747 entity tmp_entity, closest_target = world;
1748 vector spawn_loc = self.ons_deathloc;
1750 // new joining player or round reset, don't bother checking
1751 if(spawn_loc == '0 0 0') { return false; }
1753 if(random_target) { RandomSelection_Init(); }
1755 for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
1757 if(SAME_TEAM(tmp_entity, self))
1759 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1760 else if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world)
1761 closest_target = tmp_entity;
1764 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1770 for(i = 0; i < 10; ++i)
1772 loc = closest_target.origin + '0 0 96';
1773 loc += ('0 1 0' * random()) * 128;
1774 tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, self);
1775 if(trace_fraction == 1.0 && !trace_startsolid)
1777 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
1778 if(trace_fraction == 1.0 && !trace_startsolid)
1780 setorigin(self, loc);
1781 self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1789 if(autocvar_g_onslaught_spawn_at_generator)
1790 if(random() <= autocvar_g_onslaught_spawn_at_generator_chance)
1792 float random_target = autocvar_g_onslaught_spawn_at_generator_random;
1793 entity tmp_entity, closest_target = world;
1794 vector spawn_loc = self.ons_deathloc;
1796 // new joining player or round reset, don't bother checking
1797 if(spawn_loc == '0 0 0') { return false; }
1799 if(random_target) { RandomSelection_Init(); }
1801 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1804 RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
1807 if(SAME_TEAM(tmp_entity, self))
1808 if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world)
1809 closest_target = tmp_entity;
1813 if(random_target) { closest_target = RandomSelection_chosen_ent; }
1819 for(i = 0; i < 10; ++i)
1821 loc = closest_target.origin + '0 0 128';
1822 loc += ('0 1 0' * random()) * 256;
1823 tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, self);
1824 if(trace_fraction == 1.0 && !trace_startsolid)
1826 traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
1827 if(trace_fraction == 1.0 && !trace_startsolid)
1829 setorigin(self, loc);
1830 self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
1841 MUTATOR_HOOKFUNCTION(ons_PlayerDies)
1843 frag_target.ons_deathloc = frag_target.origin;
1845 for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
1847 l.sprite.SendFlags |= 16;
1849 for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
1851 l.sprite.SendFlags |= 16;
1854 if ( autocvar_g_onslaught_spawn_choose )
1855 if ( ons_Count_SelfControlPoints() > 1 )
1856 stuffcmd(self, "qc_cmd_cl hud clickradar\n");
1861 MUTATOR_HOOKFUNCTION(ons_MonsterThink)
1863 entity e = find(world, targetname, self.target);
1870 void ons_MonsterSpawn_Delayed()
1872 entity e, own = self.owner;
1874 if(!own) { remove(self); return; }
1878 e = find(world, target, own.targetname);
1891 MUTATOR_HOOKFUNCTION(ons_MonsterSpawn)
1895 InitializeEntity(e, ons_MonsterSpawn_Delayed, INITPRIO_FINDTARGET);
1900 void ons_TurretSpawn_Delayed()
1902 entity e, own = self.owner;
1904 if(!own) { remove(self); return; }
1908 e = find(world, target, own.targetname);
1912 own.active = ACTIVE_NOT;
1922 MUTATOR_HOOKFUNCTION(ons_TurretSpawn)
1926 InitializeEntity(e, ons_TurretSpawn_Delayed, INITPRIO_FINDTARGET);
1931 MUTATOR_HOOKFUNCTION(ons_BotRoles)
1933 havocbot_ons_reset_role(self);
1937 MUTATOR_HOOKFUNCTION(ons_GetTeamCount)
1939 // onslaught is special
1941 for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
1943 switch(tmp_entity.team)
1945 case NUM_TEAM_1: c1 = 0; break;
1946 case NUM_TEAM_2: c2 = 0; break;
1947 case NUM_TEAM_3: c3 = 0; break;
1948 case NUM_TEAM_4: c4 = 0; break;
1955 MUTATOR_HOOKFUNCTION(ons_SpectateCopy)
1957 self.ons_roundlost = other.ons_roundlost; // make spectators see it too
1961 MUTATOR_HOOKFUNCTION(ons_SV_ParseClientCommand)
1963 if(MUTATOR_RETURNVALUE) // command was already handled?
1966 if ( cmd_name == "ons_spawn" )
1968 vector pos = self.origin;
1970 pos_x = stof(argv(1));
1972 pos_y = stof(argv(2));
1974 pos_z = stof(argv(3));
1976 if ( IS_PLAYER(self) )
1980 entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
1982 if ( !source_point && self.health > 0 )
1984 sprint(self, "\nYou need to be next to a control point\n");
1989 entity closest_target = ons_Nearest_ControlPoint_2D(pos, autocvar_g_onslaught_click_radius);
1991 if ( closest_target == world )
1993 sprint(self, "\nNo control point found\n");
1997 if ( self.health <= 0 )
1999 self.ons_spawn_by = closest_target;
2000 self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
2004 if ( source_point == closest_target )
2006 sprint(self, "\nTeleporting to the same point\n");
2010 if ( !ons_Teleport(self,closest_target,autocvar_g_onslaught_teleport_radius,true) )
2011 sprint(self, "\nUnable to teleport there\n");
2017 sprint(self, "\nNo teleportation for you\n");
2025 MUTATOR_HOOKFUNCTION(ons_PlayerUseKey)
2027 if(MUTATOR_RETURNVALUE || gameover) { return false; }
2029 if((time > self.teleport_antispam) && (self.deadflag == DEAD_NO) && !self.vehicle)
2031 entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
2034 stuffcmd(self, "qc_cmd_cl hud clickradar\n");
2042 MUTATOR_HOOKFUNCTION(ons_PlayHitsound)
2044 return (frag_victim.classname == "onslaught_generator" && !frag_victim.isshielded)
2045 || (frag_victim.classname == "onslaught_controlpoint_icon" && !frag_victim.owner.isshielded);
2052 /*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
2053 Link between control points.
2055 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.
2058 "target" - first control point.
2059 "target2" - second control point.
2061 void spawnfunc_onslaught_link()
2063 if(!g_onslaught) { remove(self); return; }
2065 if (self.target == "" || self.target2 == "")
2066 objerror("target and target2 must be set\n");
2068 self.ons_worldlinknext = ons_worldlinklist; // link into ons_worldlinklist
2069 ons_worldlinklist = self;
2071 InitializeEntity(self, ons_DelayedLinkSetup, INITPRIO_FINDTARGET);
2072 Net_LinkEntity(self, false, 0, ons_Link_Send);
2075 /*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
2076 Control point. Be sure to give this enough clearance so that the shootable part has room to exist
2078 This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
2081 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2082 "target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
2083 "message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
2086 void spawnfunc_onslaught_controlpoint()
2088 if(!g_onslaught) { remove(self); return; }
2090 ons_ControlPoint_Setup(self);
2093 /*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
2096 spawnfunc_onslaught_link entities can target this.
2099 "team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
2100 "targetname" - name that spawnfunc_onslaught_link entities will use to target this.
2102 void spawnfunc_onslaught_generator()
2104 if(!g_onslaught) { remove(self); return; }
2105 if(!self.team) { objerror("team must be set"); }
2107 ons_GeneratorSetup(self);
2111 void ons_ScoreRules()
2113 CheckAllowedTeams(world);
2114 ScoreRules_basics(((c4>=0) ? 4 : (c3>=0) ? 3 : 2), SFL_SORT_PRIO_PRIMARY, 0, true);
2115 ScoreInfo_SetLabel_TeamScore (ST_ONS_CAPS, "destroyed", SFL_SORT_PRIO_PRIMARY);
2116 ScoreInfo_SetLabel_PlayerScore(SP_ONS_CAPS, "caps", SFL_SORT_PRIO_SECONDARY);
2117 ScoreInfo_SetLabel_PlayerScore(SP_ONS_TAKES, "takes", 0);
2118 ScoreRules_basics_end();
2121 void ons_DelayedInit() // Do this check with a delay so we can wait for teams to be set up
2125 round_handler_Spawn(Onslaught_CheckPlayers, Onslaught_CheckWinner, Onslaught_RoundStart);
2126 round_handler_Init(5, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
2129 void ons_Initialize()
2131 precache_sound("ctf/red_capture.wav");
2132 precache_sound("ctf/blue_capture.wav");
2133 precache_sound("ctf/yellow_capture.wav");
2134 precache_sound("ctf/pink_capture.wav");
2136 ons_captureshield_force = autocvar_g_onslaught_shield_force;
2138 addstat(STAT_ROUNDLOST, AS_INT, ons_roundlost);
2140 InitializeEntity(world, ons_DelayedInit, INITPRIO_GAMETYPE);
2143 MUTATOR_DEFINITION(gamemode_onslaught)
2145 MUTATOR_HOOK(reset_map_global, ons_ResetMap, CBC_ORDER_ANY);
2146 MUTATOR_HOOK(MakePlayerObserver, ons_RemovePlayer, CBC_ORDER_ANY);
2147 MUTATOR_HOOK(ClientDisconnect, ons_RemovePlayer, CBC_ORDER_ANY);
2148 MUTATOR_HOOK(PlayerSpawn, ons_PlayerSpawn, CBC_ORDER_ANY);
2149 MUTATOR_HOOK(PlayerDies, ons_PlayerDies, CBC_ORDER_ANY);
2150 MUTATOR_HOOK(MonsterMove, ons_MonsterThink, CBC_ORDER_ANY);
2151 MUTATOR_HOOK(MonsterSpawn, ons_MonsterSpawn, CBC_ORDER_ANY);
2152 MUTATOR_HOOK(TurretSpawn, ons_TurretSpawn, CBC_ORDER_ANY);
2153 MUTATOR_HOOK(HavocBot_ChooseRole, ons_BotRoles, CBC_ORDER_ANY);
2154 MUTATOR_HOOK(GetTeamCount, ons_GetTeamCount, CBC_ORDER_ANY);
2155 MUTATOR_HOOK(SpectateCopy, ons_SpectateCopy, CBC_ORDER_ANY);
2156 MUTATOR_HOOK(SV_ParseClientCommand, ons_SV_ParseClientCommand, CBC_ORDER_ANY);
2157 MUTATOR_HOOK(PlayerUseKey, ons_PlayerUseKey, CBC_ORDER_ANY);
2158 MUTATOR_HOOK(PlayHitsound, ons_PlayHitsound, CBC_ORDER_ANY);
2162 if(time > 1) // game loads at time 1
2163 error("This is a game type and it cannot be added at runtime.");
2167 MUTATOR_ONROLLBACK_OR_REMOVE
2169 // we actually cannot roll back ons_Initialize here
2170 // BUT: we don't need to! If this gets called, adding always
2176 LOG_INFO("This is a game type and it cannot be removed at runtime.");