]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Merge branch 'master' into Mario/ons_updates
authorMario <zacjardine@y7mail.com>
Tue, 3 Feb 2015 05:27:17 +0000 (16:27 +1100)
committerMario <zacjardine@y7mail.com>
Tue, 3 Feb 2015 05:27:17 +0000 (16:27 +1100)
Conflicts:
qcsrc/client/autocvars.qh
qcsrc/client/hud.qh
qcsrc/client/mapvoting.qc
qcsrc/client/progs.src
qcsrc/client/view.qc
qcsrc/client/waypointsprites.qc
qcsrc/client/waypointsprites.qh
qcsrc/common/constants.qh
qcsrc/common/mapinfo.qh
qcsrc/common/stats.qh
qcsrc/server/autocvars.qh
qcsrc/server/miscfunctions.qc
qcsrc/server/mutators/gamemode_onslaught.qc
qcsrc/server/progs.src

40 files changed:
defaultXonotic.cfg
gamemodes.cfg
gfx/teamradar_icon_glow.tga [new file with mode: 0644]
qcsrc/client/autocvars.qh
qcsrc/client/command/cl_cmd.qc
qcsrc/client/controlpoint.qc [new file with mode: 0644]
qcsrc/client/controlpoint.qh [new file with mode: 0644]
qcsrc/client/generator.qc [new file with mode: 0644]
qcsrc/client/generator.qh [new file with mode: 0644]
qcsrc/client/hud.qc
qcsrc/client/hud.qh
qcsrc/client/main.qc
qcsrc/client/main.qh
qcsrc/client/progs.src
qcsrc/client/scoreboard.qc
qcsrc/client/teamradar.qc
qcsrc/client/teamradar.qh
qcsrc/client/view.qc
qcsrc/client/waypointsprites.qc
qcsrc/client/waypointsprites.qh
qcsrc/common/constants.qh
qcsrc/common/mapinfo.qh
qcsrc/common/notifications.qh
qcsrc/common/stats.qh
qcsrc/server/autocvars.qh
qcsrc/server/bot/havocbot/havocbot.qc
qcsrc/server/bot/havocbot/roles.qc
qcsrc/server/controlpoint.qc [new file with mode: 0644]
qcsrc/server/controlpoint.qh [new file with mode: 0644]
qcsrc/server/g_damage.qc
qcsrc/server/g_world.qc
qcsrc/server/generator.qc [new file with mode: 0644]
qcsrc/server/generator.qh [new file with mode: 0644]
qcsrc/server/miscfunctions.qc
qcsrc/server/mutators/gamemode_onslaught.qc
qcsrc/server/mutators/gamemode_onslaught.qh [new file with mode: 0644]
qcsrc/server/mutators/mutators_include.qh
qcsrc/server/progs.src
qcsrc/server/teamplay.qc
qcsrc/server/waypointsprites.qc

index 034b3bb32d9df4fe1f3139dad707e1742af9c2c7..a765d46488182ca634efd1fc89ea395b90df696b 100644 (file)
@@ -234,10 +234,12 @@ seta cl_hitsound_nom_damage 25 "damage amount at which hitsound bases pitch off"
 seta cl_eventchase_death 1 "camera goes into 3rd person mode when the player is dead; set to 2 to active the effect only when the corpse doesn't move anymore"
 seta cl_eventchase_nexball 1 "camera goes into 3rd person mode when in nexball game-mode"
 seta cl_eventchase_distance 140 "final camera distance"
+seta cl_eventchase_distance 400 "final camera distance while viewing generator explosion"
 seta cl_eventchase_speed 1.3 "how fast the camera slides back, 0 is instant"
 seta cl_eventchase_maxs "12 12 8" "max size of eventchase camera bbox"
 seta cl_eventchase_mins "-12 -12 -8" "min size of eventchase camera bbox"
 seta cl_eventchase_viewoffset "0 0 20" "viewoffset of eventchase camera"
+seta cl_eventchase_generator_viewoffset "0 0 80" "viewoffset of eventchase camera while viewing generator explosion"
 
 //nifreks lockonrestart feature, used in team-based game modes, if set to 1 and all players readied up no other player can then join the game anymore, useful to block spectators from joining
 set teamplay_lockonrestart 0 "it set to 1 in a team-based game, the teams are locked once all players readied up and the game restarted (no new players can join after restart unless using the server-command unlockteams)"
index b6cbe92cfcba116c79de77e667e30d35d2c6601a..f05ff5238cc61c2a3218dafc9149dac1668107fc 100644 (file)
@@ -479,7 +479,17 @@ seta g_nexball_tackling 1 "Allow ball theft?"
 //  onslaught
 // ===========
 set g_onslaught 0 "Onslaught: take control points towards the enemy generator and then destroy it"
+set g_onslaught_point_limit 1 "Onslaught point limit overriding the mapinfo specified one (use 0 to play without limit, and -1 to use the mapinfo's limit)"
+set g_onslaught_warmup 5
+set g_onslaught_round_timelimit 280
+set g_onslaught_debug 0 "show debug prints in onslaught"
+set g_onslaught_teleport_radius 200 "Allows teleporting from a control point to another"
+set g_onslaught_teleport_wait 5 "Time before player can teleport again"
+set g_onslaught_spawn_choose 1 "Allow players to choose the control point to be spawned at"
+set g_onslaught_click_radius 500 "When choosing from the map, this level of precision is required"
+
 set g_onslaught_gen_health 2500
+set g_onslaught_allow_vehicle_touch 0
 set g_onslaught_cp_health 1000
 set g_onslaught_cp_buildhealth 100
 set g_onslaught_cp_buildtime 5
@@ -487,8 +497,13 @@ set g_onslaught_cp_regen 20
 set g_onslaught_cp_proxydecap 0 "de-capture controlpoints by standing close to them"
 set g_onslaught_cp_proxydecap_distance 512
 set g_onslaught_cp_proxydecap_dps 100
+set g_onslaught_shield_force 100
 set g_onslaught_spawn_at_controlpoints 0
+set g_onslaught_spawn_at_controlpoints_chance 0.5
+set g_onslaught_spawn_at_controlpoints_random 0
 set g_onslaught_spawn_at_generator 0
+set g_onslaught_spawn_at_generator_chance 0
+set g_onslaught_spawn_at_generator_random 0
 
 
 // ======
diff --git a/gfx/teamradar_icon_glow.tga b/gfx/teamradar_icon_glow.tga
new file mode 100644 (file)
index 0000000..4272d34
Binary files /dev/null and b/gfx/teamradar_icon_glow.tga differ
index e35bf82dd2759122afc2cf11d46707ef5fc1177b..c51edbd80076ab9912e1f021dd6f1414b573d86e 100644 (file)
@@ -431,6 +431,8 @@ float autocvar_cl_hitsound_nom_damage = 25;
 float autocvar_cl_hitsound_antispam_time;
 int autocvar_cl_eventchase_death = 1;
 int autocvar_cl_eventchase_nexball = 1;
+vector autocvar_cl_eventchase_generator_viewoffset = '0 0 80';
+float autocvar_cl_eventchase_generator_distance = 400;
 float autocvar_cl_eventchase_distance = 140;
 float autocvar_cl_eventchase_speed = 1.3;
 vector autocvar_cl_eventchase_maxs = '12 12 8';
index 7b74d2dd7fa56752889ee75f6abb3cdbb1e08115..8d5e45615a7e8ff8565dec1ef4844089ebc96d19 100644 (file)
@@ -268,9 +268,15 @@ void LocalCommand_hud(int request, int argc)
                                case "radar":
                                {
                                        if(argv(2))
-                                               hud_panel_radar_maximized = InterpretBoolean(argv(2));
+                                               HUD_Radar_Show_Maximized(InterpretBoolean(argv(2)),0);
                                        else
-                                               hud_panel_radar_maximized = !hud_panel_radar_maximized;
+                                               HUD_Radar_Show_Maximized(!hud_panel_radar_maximized,0);
+                                       return;
+                               }
+                               
+                               case "clickradar":
+                               {
+                                       HUD_Radar_Show_Maximized(!hud_panel_radar_mouse,1);
                                        return;
                                }
                        }
diff --git a/qcsrc/client/controlpoint.qc b/qcsrc/client/controlpoint.qc
new file mode 100644 (file)
index 0000000..0eb4989
--- /dev/null
@@ -0,0 +1,212 @@
+#include "controlpoint.qh"
+#include "gibs.qh"
+#include "teamradar.qh"
+
+bool cpicon_precached;
+.int count;
+.float pain_finished;
+
+.bool iscaptured;
+
+.vector cp_origin, cp_bob_origin;
+.float cp_bob_spd;
+
+.vector cp_bob_dmg;
+
+.vector punchangle;
+
+.float max_health;
+
+.entity icon_realmodel;
+
+void cpicon_precache()
+{
+       if(cpicon_precached)
+               return; // already precached
+
+       precache_model("models/onslaught/controlpoint_icon_dmg3.md3");
+       precache_model("models/onslaught/controlpoint_icon_dmg2.md3");
+       precache_model("models/onslaught/controlpoint_icon_dmg1.md3");
+       precache_model("models/onslaught/controlpoint_icon.md3");
+
+       cpicon_precached = true;
+}
+
+void cpicon_draw()
+{
+       if(time < self.move_time) { return; }
+
+       if(self.cp_bob_dmg_z > 0)
+               self.cp_bob_dmg_z = self.cp_bob_dmg_z - 3 * frametime;
+       else
+               self.cp_bob_dmg_z = 0;
+       self.cp_bob_origin_z = 4 * PI * (1 - cos(self.cp_bob_spd));
+       self.cp_bob_spd = self.cp_bob_spd + 1.875 * frametime;
+       self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));
+       
+       if(!self.iscaptured) self.alpha = self.health / self.max_health;
+       
+       if(self.iscaptured)
+       {
+               if (self.punchangle_x > 0)
+               {
+                       self.punchangle_x = self.punchangle_x - 60 * frametime;
+                       if (self.punchangle_x < 0)
+                               self.punchangle_x = 0;
+               }
+               else if (self.punchangle_x < 0)
+               {
+                       self.punchangle_x = self.punchangle_x + 60 * frametime;
+                       if (self.punchangle_x > 0)
+                               self.punchangle_x = 0;
+               }
+
+               if (self.punchangle_y > 0)
+               {
+                       self.punchangle_y = self.punchangle_y - 60 * frametime;
+                       if (self.punchangle_y < 0)
+                               self.punchangle_y = 0;
+               }
+               else if (self.punchangle_y < 0)
+               {
+                       self.punchangle_y = self.punchangle_y + 60 * frametime;
+                       if (self.punchangle_y > 0)
+                               self.punchangle_y = 0;
+               }
+
+               if (self.punchangle_z > 0)
+               {
+                       self.punchangle_z = self.punchangle_z - 60 * frametime;
+                       if (self.punchangle_z < 0)
+                               self.punchangle_z = 0;
+               }
+               else if (self.punchangle_z < 0)
+               {
+                       self.punchangle_z = self.punchangle_z + 60 * frametime;
+                       if (self.punchangle_z > 0)
+                               self.punchangle_z = 0;
+               }
+
+               self.angles_x = self.punchangle_x;
+               self.angles_y = self.punchangle_y + self.move_angles_y;
+               self.angles_z = self.punchangle_z;
+               self.move_angles_y = self.move_angles_y + 45 * frametime;
+       }
+       
+       setorigin(self, self.cp_origin + self.cp_bob_origin + self.cp_bob_dmg);
+}
+
+void cpicon_damage(float hp)
+{
+       if(!self.iscaptured) { return; }
+
+       if(hp < self.max_health * 0.25)
+               setmodel(self, "models/onslaught/controlpoint_icon_dmg3.md3");
+       else if(hp < self.max_health * 0.50)
+               setmodel(self, "models/onslaught/controlpoint_icon_dmg2.md3");
+       else if(hp < self.max_health * 0.75)
+               setmodel(self, "models/onslaught/controlpoint_icon_dmg1.md3");
+       else if(hp <= self.max_health || hp >= self.max_health)
+               setmodel(self, "models/onslaught/controlpoint_icon.md3");
+               
+       self.punchangle = (2 * randomvec() - '1 1 1') * 45;
+
+       self.cp_bob_dmg_z = (2 * random() - 1) * 15;
+       self.pain_finished = time + 1;
+       self.colormod = '2 2 2';
+
+       setsize(self, CPICON_MIN, CPICON_MAX);
+}
+
+void cpicon_construct()
+{
+       self.netname = "Control Point Icon";
+
+       setmodel(self, "models/onslaught/controlpoint_icon.md3");
+       setsize(self, CPICON_MIN, CPICON_MAX);
+       
+       if(self.icon_realmodel == world)
+       {
+               self.icon_realmodel = spawn();
+               setmodel(self.icon_realmodel, "null");
+               setorigin(self.icon_realmodel, self.origin);
+               setsize(self.icon_realmodel, CPICON_MIN, CPICON_MAX);
+               self.icon_realmodel.movetype = MOVETYPE_NOCLIP;
+               self.icon_realmodel.solid = SOLID_NOT;
+               self.icon_realmodel.move_origin = self.icon_realmodel.origin;
+       }
+       
+       if(self.iscaptured) { self.icon_realmodel.solid = SOLID_BBOX; }
+
+       self.move_movetype      = MOVETYPE_NOCLIP;
+       self.solid                      = SOLID_NOT;
+       self.movetype           = MOVETYPE_NOCLIP;
+       self.move_origin        = self.origin;
+       self.move_time          = time;
+       self.drawmask           = MASK_NORMAL;
+       self.alpha                      = 1;
+       self.draw                       = cpicon_draw;
+       self.cp_origin          = self.origin;
+       self.cp_bob_origin      = '0 0 0.1';
+       self.cp_bob_spd         = 0;
+}
+
+.vector glowmod;
+void cpicon_changeteam()
+{
+       if(self.team)
+       {
+               self.glowmod = Team_ColorRGB(self.team - 1);
+               self.teamradar_color = Team_ColorRGB(self.team - 1);
+               self.colormap = 1024 + (self.team - 1) * 17;
+       }
+       else
+       {
+               self.colormap = 1024;
+               self.glowmod = '1 1 0';
+               self.teamradar_color = '1 1 0';
+       }
+}
+
+void ent_cpicon()
+{
+       int sf = ReadByte();
+
+       if(sf & CPSF_SETUP)
+       {
+               self.origin_x = ReadCoord();
+               self.origin_y = ReadCoord();
+               self.origin_z = ReadCoord();
+               setorigin(self, self.origin);
+
+               self.health = ReadByte();
+               self.max_health = ReadByte();
+               self.count = ReadByte();
+               self.team = ReadByte();
+               self.iscaptured = ReadByte();
+
+               if(!self.count)
+                       self.count = (self.health - self.max_health) * frametime;
+
+               cpicon_changeteam();
+               cpicon_precache();
+               cpicon_construct();
+       }
+
+       if(sf & CPSF_STATUS)
+       {
+               int _tmp = ReadByte();
+               if(_tmp != self.team)
+               {
+                       self.team = _tmp;
+                       cpicon_changeteam();
+               }
+
+               _tmp = ReadByte();
+
+               if(_tmp != self.health)
+                       cpicon_damage(_tmp);
+
+               self.health = _tmp;
+       }
+}
diff --git a/qcsrc/client/controlpoint.qh b/qcsrc/client/controlpoint.qh
new file mode 100644 (file)
index 0000000..8469b52
--- /dev/null
@@ -0,0 +1,13 @@
+#ifndef CONTROLPOINT_H
+#define CONTROLPOINT_H
+
+const vector CPICON_MIN = '-32 -32 -9';
+const vector CPICON_MAX = '32 32 25';
+
+const int CPSF_STATUS = 4;
+const int CPSF_SETUP = 8;
+
+void ent_cpicon();
+void cpicon_precache();
+
+#endif
diff --git a/qcsrc/client/generator.qc b/qcsrc/client/generator.qc
new file mode 100644 (file)
index 0000000..fe19cc6
--- /dev/null
@@ -0,0 +1,261 @@
+#include "generator.qh"
+
+bool generator_precached;
+.int count;
+.float max_health;
+
+vector randompos(vector m1, vector m2)
+{
+       vector v;
+       m2 = m2 - m1;
+       v_x = m2_x * random() + m1_x;
+       v_y = m2_y * random() + m1_y;
+       v_z = m2_z * random() + m1_z;
+       return  v;
+}
+
+void generator_precache()
+{
+       if(generator_precached)
+               return; // already precached
+
+       precache_model("models/onslaught/generator.md3");
+       precache_model("models/onslaught/generator_dead.md3");
+       precache_model("models/onslaught/generator_dmg1.md3");
+       precache_model("models/onslaught/generator_dmg2.md3");
+       precache_model("models/onslaught/generator_dmg3.md3");
+       precache_model("models/onslaught/generator_dmg4.md3");
+       precache_model("models/onslaught/generator_dmg5.md3");
+       precache_model("models/onslaught/generator_dmg6.md3");
+       precache_model("models/onslaught/generator_dmg7.md3");
+       precache_model("models/onslaught/generator_dmg8.md3");
+       precache_model("models/onslaught/generator_dmg9.md3");
+       precache_model("models/onslaught/generator_dead.md3");
+
+       precache_model("models/onslaught/ons_ray.md3");
+       precache_sound("onslaught/shockwave.wav");
+       precache_sound("weapons/grenade_impact.wav");
+       precache_sound("weapons/rocket_impact.wav");
+       precache_sound("onslaught/electricity_explode.wav");
+
+       generator_precached = true;
+}
+
+void ons_generator_ray_draw()
+{
+       if(time < self.move_time)
+               return;
+       
+       self.move_time = time + 0.05;
+
+       if(self.count > 10)
+       {
+               remove(self);
+               return;
+       }
+
+       if(self.count > 5)
+               self.alpha -= 0.1;
+       else
+               self.alpha += 0.1;
+
+       self.scale += 0.2;
+       self.count +=1;
+}
+
+void ons_generator_ray_spawn(vector org)
+{
+       entity e;
+       e = spawn();
+       e.classname = "ons_ray";
+       setmodel(e, "models/onslaught/ons_ray.md3");
+       setorigin(e, org);
+       e.angles = randomvec() * 360;
+       e.move_origin = org;
+       e.movetype = MOVETYPE_NONE;
+       e.alpha = 0;
+       e.scale = random() * 5 + 8;
+       e.move_time = time + 0.05;
+       e.drawmask = MASK_NORMAL;
+       e.draw = ons_generator_ray_draw;
+}
+
+void generator_draw()
+{
+       if(time < self.move_time)
+               return;
+
+       if(self.health > 0)
+       {
+               // damaged fx (less probable the more damaged is the generator)
+               if(random() < 0.9 - self.health / self.max_health)
+               if(random() < 0.01)
+               {
+                       pointparticles(particleeffectnum("electro_ballexplode"), self.origin + randompos('-50 -50 -20', '50 50 50'), '0 0 0', 1);
+                       sound(self, CH_TRIGGER, "onslaught/electricity_explode.wav", VOL_BASE, ATTEN_NORM);
+               }
+               else
+                       pointparticles(particleeffectnum("torch_small"), self.origin + randompos('-60 -60 -20', '60 60 60'), '0 0 0', 1);
+       
+               self.move_time = time + 0.1;
+               
+               return;
+       }
+
+       if(self.count <= 0)
+               return;
+
+       vector org;
+       int i;
+
+       // White shockwave
+       if(self.count==40||self.count==20)
+       {
+               sound(self, CH_TRIGGER, "onslaught/shockwave.wav", VOL_BASE, ATTEN_NORM);
+               pointparticles(particleeffectnum("electro_combo"), self.origin, '0 0 0', 6);
+       }
+       
+       // rays
+       if(random() > 0.25)
+       {
+               ons_generator_ray_spawn(self.origin);
+       }
+
+       // Spawn fire balls
+       for(i=0;i < 10;++i)
+       {
+               org = self.origin + randompos('-30 -30 -30' * i + '0 0 -20', '30 30 30' * i + '0 0 20');
+               pointparticles(particleeffectnum("onslaught_generator_gib_explode"), org, '0 0 0', 1);
+       }
+
+       // Short explosion sound + small explosion
+       if(random() < 0.25)
+       {
+               te_explosion(self.origin);
+               sound(self, CH_TRIGGER, "weapons/grenade_impact.wav", VOL_BASE, ATTEN_NORM);
+       }
+
+       // Particles
+       org = self.origin + randompos(self.mins + '8 8 8', self.maxs + '-8 -8 -8');
+       pointparticles(particleeffectnum("onslaught_generator_smallexplosion"), org, '0 0 0', 1);
+
+       // Final explosion
+       if(self.count==1)
+       {
+               org = self.origin;
+               te_explosion(org);
+               pointparticles(particleeffectnum("onslaught_generator_finalexplosion"), org, '0 0 0', 1);
+               sound(self, CH_TRIGGER, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
+       }
+
+       self.move_time = time + 0.05;
+
+       self.count -= 1;
+}
+
+void generator_damage(float hp)
+{
+       if(hp <= 0)
+               setmodel(self, "models/onslaught/generator_dead.md3");
+       else if(hp < self.max_health * 0.10)
+               setmodel(self, "models/onslaught/generator_dmg9.md3");
+       else if(hp < self.max_health * 0.20)
+               setmodel(self, "models/onslaught/generator_dmg8.md3");
+       else if(hp < self.max_health * 0.30)
+               setmodel(self, "models/onslaught/generator_dmg7.md3");
+       else if(hp < self.max_health * 0.40)
+               setmodel(self, "models/onslaught/generator_dmg6.md3");
+       else if(hp < self.max_health * 0.50)
+               setmodel(self, "models/onslaught/generator_dmg5.md3");
+       else if(hp < self.max_health * 0.60)
+               setmodel(self, "models/onslaught/generator_dmg4.md3");
+       else if(hp < self.max_health * 0.70)
+               setmodel(self, "models/onslaught/generator_dmg3.md3");
+       else if(hp < self.max_health * 0.80)
+               setmodel(self, "models/onslaught/generator_dmg2.md3");
+       else if(hp < self.max_health * 0.90)
+               setmodel(self, "models/onslaught/generator_dmg1.md3");
+       else if(hp <= self.max_health || hp >= self.max_health)
+               setmodel(self, "models/onslaught/generator.md3");
+
+       setsize(self, GENERATOR_MIN, GENERATOR_MAX);
+}
+
+void generator_construct()
+{
+       self.netname = "Generator";
+       self.classname = "onslaught_generator";
+
+       setorigin(self, self.origin);
+       setmodel(self, "models/onslaught/generator.md3");
+       setsize(self, GENERATOR_MIN, GENERATOR_MAX);
+
+       self.move_movetype      = MOVETYPE_NOCLIP;
+       self.solid                      = SOLID_BBOX;
+       self.movetype           = MOVETYPE_NOCLIP;
+       self.move_origin        = self.origin;
+       self.move_time          = time;
+       self.drawmask           = MASK_NORMAL;
+       self.alpha                      = 1;
+       self.draw                       = generator_draw;
+}
+
+.vector glowmod;
+void generator_changeteam()
+{
+       if(self.team)
+       {
+               self.glowmod = Team_ColorRGB(self.team - 1);
+               self.teamradar_color = Team_ColorRGB(self.team - 1);
+               self.colormap = 1024 + (self.team - 1) * 17;
+       }
+       else
+       {
+               self.colormap = 1024;
+               self.glowmod = '1 1 0';
+               self.teamradar_color = '1 1 0';
+       }
+}
+
+void ent_generator()
+{
+       int sf = ReadByte();
+
+       if(sf & GSF_SETUP)
+       {
+               self.origin_x = ReadCoord();
+               self.origin_y = ReadCoord();
+               self.origin_z = ReadCoord();
+               setorigin(self, self.origin);
+
+               self.health = ReadByte();
+               self.max_health = ReadByte();
+               self.count = ReadByte();
+               self.team = ReadByte();
+
+               if(!self.count)
+                       self.count = 40;
+
+               generator_changeteam();
+               generator_precache();
+               generator_construct();
+       }
+
+       if(sf & GSF_STATUS)
+       {
+               int _tmp;
+               _tmp = ReadByte();
+               if(_tmp != self.team)
+               {
+                       self.team = _tmp;
+                       generator_changeteam();
+               }
+
+               _tmp = ReadByte();
+
+               if(_tmp != self.health)
+                       generator_damage(_tmp);
+
+               self.health = _tmp;
+       }
+}
diff --git a/qcsrc/client/generator.qh b/qcsrc/client/generator.qh
new file mode 100644 (file)
index 0000000..e4e1611
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef GENERATOR_H
+#define GENERATOR_H
+const vector GENERATOR_MIN = '-52 -52 -14';
+const vector GENERATOR_MAX = '52 52 75';
+
+const int GSF_STATUS = 4;
+const int GSF_SETUP = 8;
+
+void ent_generator();
+void generator_precache();
+#endif
index 024a0761e4b51ed5ae5fecb8ae6b80f5b818f829..ff8cb727e30577136003ec228aa35bf616394e0b 100644 (file)
@@ -1,3 +1,4 @@
+#include "mapvoting.qh"
 #include "scoreboard.qh"
 #include "teamradar.qh"
 #include "../common/buffs.qh"
@@ -1875,6 +1876,167 @@ void HUD_Timer(void)
 
 // Radar (#6)
 //
+
+float HUD_Radar_Clickable()
+{
+       return hud_panel_radar_mouse && !hud_panel_radar_temp_hidden;
+}
+
+void HUD_Radar_Show_Maximized(float show,float clickable)
+{
+       hud_panel_radar_maximized = show;
+       hud_panel_radar_temp_hidden = 0;
+       
+       if ( show )
+       {
+               if (clickable)
+               {
+                       if(autocvar_hud_cursormode)
+                               setcursormode(1);
+                       hud_panel_radar_mouse = 1; 
+               }
+       }
+       else if ( hud_panel_radar_mouse )
+       {
+               hud_panel_radar_mouse = 0;
+               mouseClicked = 0;
+               if(autocvar_hud_cursormode)
+               if(!mv_active)
+                       setcursormode(0);
+       }
+}
+void HUD_Radar_Hide_Maximized()
+{
+       HUD_Radar_Show_Maximized(false,false);
+}
+
+
+float HUD_Radar_InputEvent(float bInputType, float nPrimary, float nSecondary)
+{
+       if(!hud_panel_radar_maximized || !hud_panel_radar_mouse || 
+               autocvar__hud_configure || mv_active)
+               return false;
+
+       if(bInputType == 3)
+       {
+               mousepos_x = nPrimary;
+               mousepos_y = nSecondary;
+               return true;
+       }
+
+       if(nPrimary == K_MOUSE1)
+       {
+               if(bInputType == 0) // key pressed
+                       mouseClicked |= S_MOUSE1;
+               else if(bInputType == 1) // key released
+                       mouseClicked -= (mouseClicked & S_MOUSE1);
+       }
+       else if(nPrimary == K_MOUSE2)
+       {
+               if(bInputType == 0) // key pressed
+                       mouseClicked |= S_MOUSE2;
+               else if(bInputType == 1) // key released
+                       mouseClicked -= (mouseClicked & S_MOUSE2);
+       }
+       else if ( nPrimary == K_ESCAPE && bInputType == 0 )
+       {
+               HUD_Radar_Hide_Maximized();
+       }
+       else
+       {
+               // allow console/use binds to work without hiding the map
+               string con_keys;
+               float keys;
+               float i;
+               con_keys = strcat(findkeysforcommand("toggleconsole", 0)," ",findkeysforcommand("+use", 0)) ;
+               keys = tokenize(con_keys); // findkeysforcommand returns data for this
+               for (i = 0; i < keys; ++i)
+               {
+                       if(nPrimary == stof(argv(i)))
+                               return false;
+               }
+               
+               if ( getstati(STAT_HEALTH) <= 0 )
+               {
+                       // Show scoreboard
+                       if ( bInputType < 2 )
+                       {
+                               con_keys = findkeysforcommand("+showscores", 0);
+                               keys = tokenize(con_keys);
+                               for (i = 0; i < keys; ++i)
+                               {
+                                       if ( nPrimary == stof(argv(i)) )
+                                       {
+                                               hud_panel_radar_temp_hidden = bInputType == 0;
+                                               return false;
+                                       }
+                               }
+                       }
+               }
+               else if ( bInputType == 0 )
+                       HUD_Radar_Hide_Maximized();
+               
+               return false;
+       }
+
+       return true;
+}
+
+void HUD_Radar_Mouse()
+{
+       if ( !hud_panel_radar_mouse ) return;
+       if(mv_active) return;
+       
+       if ( intermission )
+       {
+               HUD_Radar_Hide_Maximized();
+               return;
+       }
+       
+       if(mouseClicked & S_MOUSE2)
+       {
+               HUD_Radar_Hide_Maximized();
+               return;
+       }
+       
+       if(!autocvar_hud_cursormode)
+       {
+               mousepos = mousepos + getmousepos() * autocvar_menu_mouse_speed;
+
+               mousepos_x = bound(0, mousepos_x, vid_conwidth);
+               mousepos_y = bound(0, mousepos_y, vid_conheight);
+       }
+
+       HUD_Panel_UpdateCvars();
+       
+       
+       panel_size = autocvar_hud_panel_radar_maximized_size;
+       panel_size_x = bound(0.2, panel_size_x, 1) * vid_conwidth;
+       panel_size_y = bound(0.2, panel_size_y, 1) * vid_conheight;
+       panel_pos_x = (vid_conwidth - panel_size_x) / 2;
+       panel_pos_y = (vid_conheight - panel_size_y) / 2;
+               
+       if(mouseClicked & S_MOUSE1)
+       {
+               // click outside
+               if ( mousepos_x < panel_pos_x || mousepos_x > panel_pos_x + panel_size_x ||
+                        mousepos_y < panel_pos_y || mousepos_y > panel_pos_y + panel_size_y )
+               {
+                       HUD_Radar_Hide_Maximized();
+                       return;
+               }
+               vector pos = teamradar_texcoord_to_3dcoord(teamradar_2dcoord_to_texcoord(mousepos),view_origin_z);
+               localcmd(sprintf("cmd ons_spawn %f %f %f",pos_x,pos_y,pos_z));
+               
+               HUD_Radar_Hide_Maximized();
+               return;
+       }
+       
+
+       const vector cursor_size = '32 32 0';
+       drawpic(mousepos-'8 4 0', strcat("gfx/menu/", autocvar_menu_skin, "/cursor.tga"), cursor_size, '1 1 1', 0.8, DRAWFLAG_NORMAL);
+}
+
 void HUD_Radar(void)
 {
        if (!autocvar__hud_configure)
@@ -1894,6 +2056,9 @@ void HUD_Radar(void)
                        }
                }
        }
+       
+       if ( hud_panel_radar_temp_hidden )
+               return;
 
        HUD_Panel_UpdateCvars();
 
@@ -2048,8 +2213,27 @@ void HUD_Radar(void)
 
        for(tm = world; (tm = find(tm, classname, "radarlink")); )
                draw_teamradar_link(tm.origin, tm.velocity, tm.team);
+       
+       vector coord;
+       vector brightcolor;
        for(tm = world; (tm = findflags(tm, teamradar_icon, 0xFFFFFF)); )
+       {
+               if ( hud_panel_radar_mouse )
+               if ( tm.health > 0 )
+               if ( tm.team == myteam+1 )
+               {
+                       coord = teamradar_texcoord_to_2dcoord(teamradar_3dcoord_to_texcoord(tm.origin));
+                       if ( vlen(mousepos-coord) < 8 )
+                       {
+                               brightcolor_x = min(1,tm.teamradar_color_x*1.5);
+                               brightcolor_y = min(1,tm.teamradar_color_y*1.5);
+                               brightcolor_z = min(1,tm.teamradar_color_z*1.5);
+                               drawpic(coord - '8 8 0', "gfx/teamradar_icon_glow", '16 16 0', brightcolor, panel_fg_alpha, 0);
+                       }
+               }
+               
                draw_teamradar_icon(tm.origin, tm.teamradar_icon, tm, tm.teamradar_color, panel_fg_alpha);
+       }
        for(tm = world; (tm = find(tm, classname, "entcs_receiver")); )
        {
                color2 = GetPlayerColor(tm.sv_entnum);
@@ -2059,6 +2243,21 @@ void HUD_Radar(void)
        draw_teamradar_player(view_origin, view_angles, '1 1 1');
 
        drawresetcliparea();
+       
+       if ( hud_panel_radar_mouse )
+       {                       
+               string message = "Click to select teleport destination";
+               
+               if ( getstati(STAT_HEALTH) <= 0 )
+               {
+                       message = "Click to select spawn location";
+               }
+               
+               drawcolorcodedstring(pos + '0.5 0 0' * (mySize_x - stringwidth(message, true, hud_fontsize)) - '0 1 0' * hud_fontsize_y * 2,
+                                                        message, hud_fontsize, hud_panel_radar_foreground_alpha, DRAWFLAG_NORMAL);
+               
+               hud_panel_radar_bottom = pos_y + mySize_y + hud_fontsize_y;
+       }
 }
 
 // Score (#7)
@@ -4211,8 +4410,16 @@ void HUD_CenterPrint (void)
                hud_fade_alpha = 1 - autocvar__menu_alpha;
        }
        HUD_Panel_UpdateCvars();
-
-       if(scoreboard_fade_alpha)
+       
+       if ( HUD_Radar_Clickable() )
+       {
+               if (hud_panel_radar_bottom >= 0.96 * vid_conheight)
+                       return;
+               
+               panel_pos = eY * hud_panel_radar_bottom + eX * 0.5 * (vid_conwidth - panel_size_x);
+               panel_size_y = min(panel_size_y, vid_conheight - hud_panel_radar_bottom);
+       }
+       else if(scoreboard_fade_alpha)
        {
                hud_fade_alpha = hud_fade_alpha_save;
 
index 16a7645fd991819a55fd1b8de4349d318ee15f30..251e9f23be853b51ba2fdea86e525035cd1785d6 100644 (file)
@@ -12,10 +12,15 @@ int HUD_PANEL_LAST;
 int panel_order[HUD_PANEL_MAX];
 string hud_panelorder_prev;
 
-float hud_draw_maximized;
-float hud_panel_radar_maximized;
-float chat_panel_modified;
-float radar_panel_modified;
+bool hud_draw_maximized;
+bool hud_panel_radar_maximized;
+bool hud_panel_radar_mouse;
+float hud_panel_radar_bottom;
+bool hud_panel_radar_temp_hidden;
+bool chat_panel_modified;
+bool radar_panel_modified;
+
+void HUD_Radar_Hide_Maximized();
 
 vector mousepos;
 vector panel_click_distance; // mouse cursor distance from the top left corner of the panel (saved only upon a click)
index 13f9545faab60a7c944d4d45b192dc6e16ca8a46..d0a0a418cbcdf50743c9862ecf9b6d235adf8247 100644 (file)
@@ -1,3 +1,5 @@
+#include "controlpoint.qh"
+#include "generator.qh"
 #include "mapvoting.qh"
 #include "modeleffects.qh"
 #include "particles.qh"
@@ -122,6 +124,7 @@ void CSQC_Init(void)
        precache_sound("misc/hit.wav");
        precache_sound("misc/typehit.wav");
 
+       generator_precache();
        Projectile_Precache();
        Hook_Precache();
        GibSplash_Precache();
@@ -335,6 +338,9 @@ float CSQC_InputEvent(float bInputType, float nPrimary, float nSecondary)
        if (HUD_Panel_InputEvent(bInputType, nPrimary, nSecondary))
                return true;
 
+       if ( HUD_Radar_InputEvent(bInputType, nPrimary, nSecondary) )
+               return true;
+
        if (MapVote_InputEvent(bInputType, nPrimary, nSecondary))
                return true;
 
@@ -749,7 +755,7 @@ void Ent_ReadSpawnEvent(float is_new)
                        button_zoom = false;
                }
        }
-
+       HUD_Radar_Hide_Maximized();
        //printf("Ent_ReadSpawnEvent(is_new = %d); origin = %s, entnum = %d, localentnum = %d\n", is_new, vtos(self.origin), entnum, player_localentnum);
 }
 
@@ -835,6 +841,8 @@ void CSQC_Ent_Update(float bIsNewEntity)
                case ENT_CLIENT_ACCURACY: Ent_ReadAccuracy(); break;
                case ENT_CLIENT_AUXILIARYXHAIR: Net_AuXair2(bIsNewEntity); break;
                case ENT_CLIENT_TURRET: ent_turret(); break;
+               case ENT_CLIENT_GENERATOR: ent_generator(); break;
+               case ENT_CLIENT_CONTROLPOINT_ICON: ent_cpicon(); break;
                case ENT_CLIENT_MODEL: CSQCModel_Read(bIsNewEntity); break;
                case ENT_CLIENT_ITEM: ItemRead(bIsNewEntity); break;
                case ENT_CLIENT_BUMBLE_RAYGUN: bumble_raygun_read(bIsNewEntity); break;
index b8823e6296d4de67aed98f1f2da417aa00ff0381..5689d24284dc027cd3da2490121f323e10199c9d 100644 (file)
@@ -149,4 +149,6 @@ entity entcs_receiver[255]; // 255 is the engine limit on maxclients
 float hud;
 float view_quality;
 int framecount;
+.float health;
+
 #endif
index f80da18d67309ace7482be0dd4ac37ac784cd1c0..81d349ff6bcdad35f39de3d8434203a829b4fecf 100644 (file)
@@ -6,9 +6,11 @@
 announcer.qc
 bgmscript.qc
 casings.qc
+controlpoint.qc
 csqcmodel_hooks.qc
 damage.qc
 effects.qc
+generator.qc
 gibs.qc
 hook.qc
 hud_config.qc
index c6d871807f2e7c190af068a4ff192b760d3de57b..d86956b4d730818a75822f9a85a6983ea544e503 100644 (file)
@@ -291,7 +291,7 @@ void Cmd_HUD_Help()
 #define HUD_DefaultColumnLayout() \
 "ping pl name | " \
 "-teams,race,lms/kills +ft,tdm/kills -teams,lms/deaths +ft,tdm/deaths -teams,lms,race,ka/suicides +ft,tdm/suicides -race,dm,tdm,ka,ft/frags " /* tdm already has this in "score" */ \
-"+ctf/caps +ctf/pickups +ctf/fckills +ctf/returns " \
+"+ctf/caps +ctf/pickups +ctf/fckills +ctf/returns +ons/caps +ons/takes " \
 "+lms/lives +lms/rank " \
 "+kh/caps +kh/pushes +kh/destroyed " \
 "?+race/laps ?+race/time ?+race/fastest " \
@@ -953,6 +953,8 @@ vector HUD_Scoreboard_MakeTable(vector pos, entity tm, vector rgb, vector bg_siz
 float HUD_WouldDrawScoreboard() {
        if (autocvar__hud_configure)
                return 0;
+       else if (HUD_Radar_Clickable())
+               return 0;
        else if (scoreboard_showscores)
                return 1;
        else if (intermission == 1)
index 1822acb5e467a2934b7c60aa80353d5c7d019636..088ba60d9bad2e89467e90096fe3fc21f80d4fd6 100644 (file)
@@ -43,6 +43,34 @@ vector teamradar_texcoord_to_2dcoord(vector in)
        return out;
 }
 
+
+vector teamradar_2dcoord_to_texcoord(vector in)
+{
+       vector out;
+       out = in;
+       
+       out -= teamradar_origin2d;
+       if(v_flipped)
+               out_x = -out_x;
+       out = out / teamradar_size;
+       
+       out_y = - out_y; // screen space is reversed
+       out = rotate(out, -teamradar_angle * DEG2RAD);
+       
+       out += teamradar_origin3d_in_texcoord;
+
+       return out;
+}
+
+vector teamradar_texcoord_to_3dcoord(vector in,float z)
+{
+       vector out;
+       out_x = in_x * (mi_picmax_x - mi_picmin_x) + mi_picmin_x;
+       out_y = in_y * (mi_picmax_y - mi_picmin_y) + mi_picmin_y;
+       out_z = z;
+       return out;
+}
+
 vector yinvert(vector v)
 {
        v.y = 1 - v.y;
index 31defc8efbd6c3b3bb8f78d03eaf71fa7ee07da6..da99652feef5dec0f3833e26e6eb0ad175c8e688 100644 (file)
@@ -32,10 +32,14 @@ float vlen_maxnorm2d(vector v);
 
 float vlen_minnorm2d(vector v);
 
+vector teamradar_2dcoord_to_texcoord(vector in);
+
 vector teamradar_3dcoord_to_texcoord(vector in);
 
 vector teamradar_texcoord_to_2dcoord(vector in);
 
+vector teamradar_texcoord_to_3dcoord(vector in,float z);
+
 vector yinvert(vector v);
 
 void draw_teamradar_background(float fg);
index ee8ef320ae4643740f8bb275f848b9436914462f..0224b35f2164ffb9b39a0f3f27449bb8dd14f61a 100644 (file)
@@ -1081,18 +1081,39 @@ void CSQC_UpdateView(float w, float h)
        // event chase camera
        if(autocvar_chase_active <= 0) // greater than 0 means it's enabled manually, and this code is skipped
        {
-               if(WantEventchase())
+               float ons_roundlost = (gametype == MAPINFO_TYPE_ONSLAUGHT && getstati(STAT_ROUNDLOST));
+               entity gen = world;
+               
+               if(ons_roundlost)
+               {
+                       entity e;
+                       for(e = world; (e = find(e, classname, "onslaught_generator")); )
+                       {
+                               if(e.health <= 0)
+                               {
+                                       gen = e;
+                                       break;
+                               }
+                       }
+                       if(!gen)
+                               ons_roundlost = FALSE; // don't enforce the 3rd person camera if there is no dead generator to show
+               }
+               if(WantEventchase() || (!autocvar_cl_orthoview && ons_roundlost))
                {
                        eventchase_running = true;
 
                        // make special vector since we can't use view_origin (It is one frame old as of this code, it gets set later with the results this code makes.)
                        vector current_view_origin = (csqcplayer ? csqcplayer.origin : pmove_org);
+                       if(ons_roundlost) { current_view_origin = gen.origin; }
 
                        // detect maximum viewoffset and use it
-                       if(autocvar_cl_eventchase_viewoffset)
+                       vector view_offset = autocvar_cl_eventchase_viewoffset;
+                       if(ons_roundlost) { view_offset = autocvar_cl_eventchase_generator_viewoffset; }
+
+                       if(view_offset)
                        {
-                               WarpZone_TraceLine(current_view_origin, current_view_origin + autocvar_cl_eventchase_viewoffset + ('0 0 1' * autocvar_cl_eventchase_maxs.z), MOVE_WORLDONLY, self);
-                               if(trace_fraction == 1) { current_view_origin += autocvar_cl_eventchase_viewoffset; }
+                               WarpZone_TraceLine(current_view_origin, current_view_origin + view_offset + ('0 0 1' * autocvar_cl_eventchase_maxs.z), MOVE_WORLDONLY, self);
+                               if(trace_fraction == 1) { current_view_origin += view_offset; }
                                else { current_view_origin.z += max(0, (trace_endpos.z - current_view_origin.z) - autocvar_cl_eventchase_maxs.z); }
                        }
 
@@ -1102,10 +1123,13 @@ void CSQC_UpdateView(float w, float h)
                        if(!autocvar_chase_active) { cvar_set("chase_active", "-1"); }
 
                        // make the camera smooth back
-                       if(autocvar_cl_eventchase_speed && eventchase_current_distance < autocvar_cl_eventchase_distance)
-                               eventchase_current_distance += autocvar_cl_eventchase_speed * (autocvar_cl_eventchase_distance - eventchase_current_distance) * frametime; // slow down the further we get
-                       else if(eventchase_current_distance != autocvar_cl_eventchase_distance)
-                               eventchase_current_distance = autocvar_cl_eventchase_distance;
+                       float chase_distance = autocvar_cl_eventchase_distance;
+                       if(ons_roundlost) { chase_distance = autocvar_cl_eventchase_generator_distance; }
+
+                       if(autocvar_cl_eventchase_speed && eventchase_current_distance < chase_distance)
+                               eventchase_current_distance += autocvar_cl_eventchase_speed * (chase_distance - eventchase_current_distance) * frametime; // slow down the further we get
+                       else if(eventchase_current_distance != chase_distance)
+                               eventchase_current_distance = chase_distance;
 
                        makevectors(view_angles);
 
@@ -1774,6 +1798,8 @@ void CSQC_UpdateView(float w, float h)
 
        if(autocvar__hud_configure)
                HUD_Panel_Mouse();
+       else 
+               HUD_Radar_Mouse();
 
     if(hud && !intermission)
     {
index 788dd871eed84f74e2050375211ef9eca122ee20..d20f8a896958de3200f81bacf48fa02e0420469f 100644 (file)
@@ -152,11 +152,8 @@ float spritelookupblinkvalue(string s)
 {
        switch(s)
        {
-               case "ons-cp-atck-neut": return 2;
-               case "ons-cp-atck-red":  return 2;
-               case "ons-cp-atck-blue": return 2;
-               case "ons-cp-dfnd-red":  return 0.5;
-               case "ons-cp-dfnd-blue": return 0.5;
+               case "ons-cp-atck":      return 2;
+               case "ons-cp-dfnd":      return 0.5;
                case "item-invis":       return 2;
                case "item-extralife":   return 2;
                case "item-speed":       return 2;
@@ -205,17 +202,11 @@ string spritelookuptext(string s)
                case "keycarrier-yellow": return _("Key carrier");
                case "redbase": return _("Red base");
                case "waypoint": return _("Waypoint");
-               case "ons-gen-red": return _("Generator");
-               case "ons-gen-blue": return _("Generator");
+               case "ons-gen": return _("Generator");
                case "ons-gen-shielded": return _("Generator");
-               case "ons-cp-neut": return _("Control point");
-               case "ons-cp-red": return _("Control point");
-               case "ons-cp-blue": return _("Control point");
-               case "ons-cp-atck-neut": return _("Control point");
-               case "ons-cp-atck-red": return _("Control point");
-               case "ons-cp-atck-blue": return _("Control point");
-               case "ons-cp-dfnd-red": return _("Control point");
-               case "ons-cp-dfnd-blue": return _("Control point");
+               case "ons-cp": return _("Control point");
+               case "ons-cp-atck": return _("Control point");
+               case "ons-cp-dfnd": return _("Control point");
                case "race-checkpoint": return _("Checkpoint");
                case "race-finish": return _("Finish");
                case "race-start": return _("Start");
index 3822793da1d0ef2b34260a07a850af138e9ab601..56fcd8e5f70874b4ff503fb3f9ae512d5bd1957d 100644 (file)
@@ -77,6 +77,7 @@ void Draw_WaypointSprite();
 // they are drawn using a .draw function
 
 void Ent_RemoveWaypointSprite();
+
 void Ent_WaypointSprite();
 
 void WaypointSprite_Load_Frames(string ext);
index 45a65abbe96bd904bae1c3e93007637ba5d8b581..df4f4ffc756462c27cfb6ae2d38176a3c9b57460 100644 (file)
@@ -78,6 +78,8 @@ const int ENT_CLIENT_ELIMINATEDPLAYERS = 39;
 const int ENT_CLIENT_TURRET = 40;
 const int ENT_CLIENT_AUXILIARYXHAIR = 50;
 const int ENT_CLIENT_VEHICLE = 60;
+const int ENT_CLIENT_GENERATOR = 61;
+const int ENT_CLIENT_CONTROLPOINT_ICON = 62;
 
 const int ENT_CLIENT_HEALING_ORB = 80;
 
index 6083350fa92028cf2be820c251875847a0927e9e..88f03c998b1febfd60454fb3e5ae57908c37a06c 100644 (file)
@@ -70,7 +70,7 @@ REGISTER_GAMETYPE(_("Key Hunt"),kh,g_keyhunt,KEYHUNT,true,"timelimit=20 pointlim
 REGISTER_GAMETYPE(_("Assault"),as,g_assault,ASSAULT,true,"timelimit=20",_("Destroy obstacles to find and destroy the enemy power core before time runs out"));
 #define g_assault IS_GAMETYPE(ASSAULT)
 
-REGISTER_GAMETYPE(_("Onslaught"),ons,g_onslaught,ONSLAUGHT,true,"timelimit=20",_("Capture control points to reach and destroy the enemy generator"));
+REGISTER_GAMETYPE(_("Onslaught"),ons,g_onslaught,ONSLAUGHT,true,"pointlimit=1 timelimit=20",_("Capture control points to reach and destroy the enemy generator"));
 #define g_onslaught IS_GAMETYPE(ONSLAUGHT)
 
 REGISTER_GAMETYPE(_("Nexball"),nb,g_nexball,NEXBALL,true,"timelimit=20 pointlimit=5 leadlimit=0",_("XonSports"));
index 1cb1adf51f368e9e97ad2d3b5afebc2cbb8595ee..95e13c137e511ed8b3552a8e79b2d2d9174aef9b 100644 (file)
@@ -483,6 +483,10 @@ void Send_Notification_WOCOVA(
     MSG_INFO_NOTIF(1, INFO_LMS_FORFEIT,                    1, 0, "s1", "",                          "",                     _("^BG%s^F3 forfeited"), "") \
     MSG_INFO_NOTIF(1, INFO_LMS_NOLIVES,                    1, 0, "s1", "",                          "",                     _("^BG%s^F3 has no more lives left"), "") \
     MSG_INFO_NOTIF(1, INFO_MONSTERS_DISABLED,              0, 0, "", "",                            "",                     _("^BGMonsters are currently disabled"), "") \
+    MSG_INFO_NOTIF(1, INFO_ONSLAUGHT_CAPTURE,              2, 0, "s1 s2", "",                       "",                     _("^BG%s^BG captured %s^BG control point"), "") \
+    MULTITEAM_INFO(1, INFO_ONSLAUGHT_CPDESTROYED_, 4,      2, 0, "s1 s2", "",                       "",                     _("^TC^TT^BG team %s^BG control point has been destroyed by %s"), "") \
+    MULTITEAM_INFO(1, INFO_ONSLAUGHT_GENDESTROYED_, 4,     0, 0, "", "",                            "",                     _("^TC^TT^BG generator has been destroyed"), "") \
+    MULTITEAM_INFO(1, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME_, 4,  0, 0, "", "",                      "",                     _("^TC^TT^BG generator spontaneously combusted due to overtime!"), "") \
     MSG_INFO_NOTIF(1, INFO_POWERUP_INVISIBILITY,           1, 0, "s1", "s1",                        "strength",             _("^BG%s^K1 picked up Invisibility"), "") \
     MSG_INFO_NOTIF(1, INFO_POWERUP_SHIELD,                 1, 0, "s1", "s1",                        "shield",               _("^BG%s^K1 picked up Shield"), "") \
     MSG_INFO_NOTIF(1, INFO_POWERUP_SPEED,                  1, 0, "s1", "s1",                        "shield",               _("^BG%s^K1 picked up Speed"), "") \
@@ -669,6 +673,7 @@ void Send_Notification_WOCOVA(
     MSG_CENTER_NOTIF(1, CENTER_FREEZETAG_REVIVE_SELF,       0, 0, "",             NO_CPID,             "0 0", _("^K3You revived yourself"), "") \
     MSG_CENTER_NOTIF(1, CENTER_FREEZETAG_REVIVED,           1, 0, "s1",           NO_CPID,             "0 0", _("^K3You were revived by ^BG%s"), "") \
     MSG_CENTER_NOTIF(1, CENTER_FREEZETAG_AUTO_REVIVED,      0, 1, "f1",           NO_CPID,             "0 0", _("^K3You were automatically revived after %s second(s)"), "") \
+    MSG_CENTER_NOTIF(1, CENTER_GENERATOR_UNDERATTACK,       0, 0, "",             NO_CPID,             "0 0", _("^BGThe generator is under attack!"), "") \
     MULTITEAM_CENTER(1, CENTER_ROUND_TEAM_WIN_, 4,          0, 0, "",             CPID_ROUND,          "0 0", _("^TC^TT^BG team wins the round"), "") \
     MSG_CENTER_NOTIF(1, CENTER_ROUND_PLAYER_WIN,            1, 0, "s1",           CPID_ROUND,          "0 0", _("^BG%s^BG wins the round"), "") \
     MSG_CENTER_NOTIF(1, CENTER_FREEZETAG_SELF,              0, 0, "",             NO_CPID,             "0 0", _("^K1You froze yourself"), "") \
@@ -705,7 +710,14 @@ void Send_Notification_WOCOVA(
     MSG_CENTER_NOTIF(1, CENTER_NIX_COUNTDOWN,               0, 2, "item_wepname",  CPID_NIX,              "1 f2", _("^F2^COUNT^BG until weapon change...\nNext weapon: ^F1%s"), "") \
     MSG_CENTER_NOTIF(1, CENTER_NIX_NEWWEAPON,               0, 1, "item_wepname",  CPID_NIX,              "0 0", _("^F2Active weapon: ^F1%s"), "") \
     MSG_CENTER_NOTIF(1, CENTER_NADE,                        0, 0, "",              NO_CPID,               "0 0", _("^BGPress ^F2DROPWEAPON^BG again to toss the grenade!"), "") \
-    MSG_CENTER_NOTIF(1, CENTER_ONS_NOTSHIELDED,             0, 0, "",              CPID_ONSLAUGHT,        "0 0", _("^K1Your generator is NOT shielded!\n^BGRe-capture controlpoints to shield it!"), "") \
+    MSG_CENTER_NOTIF(1, CENTER_ONS_CAPTURE,                 1, 0, "s1",            CPID_ONSLAUGHT,        "0 0", _("^BGYou captured %s^BG control point"), "") \
+    MULTITEAM_CENTER(1, CENTER_ONS_CAPTURE_, 4,             1, 0, "s1",            CPID_ONSLAUGHT,        "0 0", _("^TC^TT^BG team captured %s^BG control point"), "") \
+    MSG_CENTER_NOTIF(1, CENTER_ONS_CONTROLPOINT_SHIELDED,   0, 0, "",              CPID_ONS_CAPSHIELD,    "0 0", _("^BGThis control point currently cannot be captured"), "") \
+    MSG_CENTER_NOTIF(1, CENTER_ONS_GENERATOR_SHIELDED,      0, 0, "",              CPID_ONS_CAPSHIELD,    "0 0", _("^BGThe enemy generator cannot be destroyed yet\n^F2Capture some control points to unshield it"), "") \
+    MULTITEAM_CENTER(1, CENTER_ONS_NOTSHIELDED_, 4,         0, 0, "",              CPID_ONSLAUGHT,        "0 0", _("^BGThe ^TCenemy^BG generator is no longer shielded!"), "") \
+    MSG_CENTER_NOTIF(1, CENTER_ONS_NOTSHIELDED_TEAM,        0, 0, "",              CPID_ONSLAUGHT,        "0 0", _("^K1Your generator is NOT shielded!\n^BGRe-capture control points to shield it!"), "") \
+    MSG_CENTER_NOTIF(1, CENTER_ONS_TELEPORT,                0, 0, "pass_key",      CPID_ONSLAUGHT,        "0 0", _("^BGPress ^F2DROPFLAG%s^BG to teleport"), "") \
+    MSG_CENTER_NOTIF(1, CENTER_ONS_TELEPORT_ANTISPAM,       0, 1, "f1secs",        CPID_ONSLAUGHT,        "0 0", _("^BGTeleporting disabled for %s"), "") \
     MSG_CENTER_NOTIF(1, CENTER_OVERTIME_FRAG,               0, 0, "",              CPID_OVERTIME,         "0 0", _("^F2Now playing ^F4OVERTIME^F2!\nKeep fragging until we have a winner!"), _("^F2Now playing ^F4OVERTIME^F2!\nKeep scoring until we have a winner!")) \
     MSG_CENTER_NOTIF(1, CENTER_OVERTIME_CONTROLPOINT,       0, 0, "",              CPID_OVERTIME,         "5 0", _("^F2Now playing ^F4OVERTIME^F2!\n\nGenerators are now decaying.\nThe more control points your team holds,\nthe faster the enemy generator decays"), "") \
     MSG_CENTER_NOTIF(1, CENTER_OVERTIME_TIME,               0, 1, "f1time",        CPID_OVERTIME,         "0 0", _("^F2Now playing ^F4OVERTIME^F2!\n^BGAdded ^F4%s^BG to the game!"), "") \
@@ -1301,6 +1313,7 @@ enum {
 ,   CPID_MOTD
 ,   CPID_NIX
 ,   CPID_ONSLAUGHT
+,   CPID_ONS_CAPSHIELD
 ,   CPID_OVERTIME
 ,   CPID_POWERUP
 ,   CPID_RACE_FINISHLAP
index 481713cc9cb8f17df86aad4be260f8fd6f5ba76a..cbb0d7ba9c162252cdc6ca332a489f09f22ba18f 100644 (file)
@@ -92,7 +92,7 @@ const int STAT_HEALING_ORB_ALPHA      = 83;
 const int STAT_PLASMA                 = 84;
 const int STAT_OK_AMMO_CHARGE         = 85;
 const int STAT_OK_AMMO_CHARGEPOOL     = 86;
-// 87 empty?
+const int STAT_ROUNDLOST              = 87;
 // 88 empty?
 // 89 empty?
 // 90 empty?
index bcb9d28d70240e779e942a25b3c5764e7252298a..6ca5e760ef8beb3a5ede1a065d0ac6ed9dc047d3 100644 (file)
@@ -434,11 +434,6 @@ float autocvar_g_nix_with_powerups;
 float autocvar_g_nodepthtestitems;
 float autocvar_g_nodepthtestplayers;
 float autocvar_g_norecoil;
-float autocvar_g_onslaught_cp_buildhealth;
-float autocvar_g_onslaught_cp_buildtime;
-float autocvar_g_onslaught_cp_health;
-float autocvar_g_onslaught_cp_regen;
-float autocvar_g_onslaught_gen_health;
 float autocvar_g_pickup_cells_max;
 float autocvar_g_pickup_plasma_max;
 float autocvar_g_pickup_fuel_max;
@@ -853,6 +848,30 @@ float autocvar_g_spawn_near_teammate_ignore_spawnpoint_delay;
 float autocvar_g_spawn_near_teammate_ignore_spawnpoint_delay_death;
 float autocvar_g_spawn_near_teammate_ignore_spawnpoint_check_health;
 float autocvar_g_spawn_near_teammate_ignore_spawnpoint_closetodeath;
+float autocvar_g_onslaught_debug;
+float autocvar_g_onslaught_teleport_wait;
+float autocvar_g_onslaught_spawn_at_controlpoints;
+var float autocvar_g_onslaught_spawn_at_controlpoints_chance = 0.5;
+float autocvar_g_onslaught_spawn_at_controlpoints_random;
+float autocvar_g_onslaught_spawn_at_generator;
+float autocvar_g_onslaught_spawn_at_generator_chance;
+float autocvar_g_onslaught_spawn_at_generator_random;
+float autocvar_g_onslaught_cp_proxydecap;
+var float autocvar_g_onslaught_cp_proxydecap_distance = 512;
+var float autocvar_g_onslaught_cp_proxydecap_dps = 100;
+float autocvar_g_onslaught_cp_buildhealth;
+float autocvar_g_onslaught_cp_buildtime;
+float autocvar_g_onslaught_cp_health;
+float autocvar_g_onslaught_cp_regen;
+float autocvar_g_onslaught_gen_health;
+var float autocvar_g_onslaught_shield_force = 100;
+float autocvar_g_onslaught_allow_vehicle_touch;
+float autocvar_g_onslaught_round_timelimit;
+float autocvar_g_onslaught_point_limit;
+float autocvar_g_onslaught_warmup;
+float autocvar_g_onslaught_teleport_radius;
+float autocvar_g_onslaught_spawn_choose;
+float autocvar_g_onslaught_click_radius;
 float autocvar_g_buffs_waypoint_distance;
 float autocvar_g_buffs_randomize;
 float autocvar_g_buffs_random_lifetime;
@@ -882,4 +901,5 @@ float autocvar_g_buffs_vampire_damage_steal;
 float autocvar_g_buffs_invisible_alpha;
 float autocvar_g_buffs_flight_gravity;
 float autocvar_g_buffs_jump_height;
+
 #endif
index 0ecafaf1e87c7aa62fda4892d2c38ef300e05683..9991f5e0aa965c704a576147ace5e5b37b4c5f5e 100644 (file)
@@ -1,5 +1,4 @@
 #include "havocbot.qh"
-#include "role_onslaught.qc"
 #include "role_keyhunt.qc"
 #include "roles.qc"
 
index af219b8ec730272f85f334402ea9c8cc4dc229f4..9b62088deb4d21f04af6a26f35317e28d687915f 100644 (file)
@@ -238,8 +238,6 @@ void havocbot_chooserole()
                return;
        else if (g_keyhunt)
                havocbot_chooserole_kh();
-       else if (g_onslaught)
-               havocbot_chooserole_ons();
        else // assume anything else is deathmatch
                havocbot_chooserole_dm();
 }
diff --git a/qcsrc/server/controlpoint.qc b/qcsrc/server/controlpoint.qc
new file mode 100644 (file)
index 0000000..7cf81d7
--- /dev/null
@@ -0,0 +1,38 @@
+#include "controlpoint.qh"
+
+bool cpicon_send(entity to, int sf)
+{
+       WriteByte(MSG_ENTITY, ENT_CLIENT_CONTROLPOINT_ICON);
+       WriteByte(MSG_ENTITY, sf);
+       if(sf & CPSF_SETUP)
+       {
+               WriteCoord(MSG_ENTITY, self.origin_x);
+               WriteCoord(MSG_ENTITY, self.origin_y);
+               WriteCoord(MSG_ENTITY, self.origin_z);
+
+               WriteByte(MSG_ENTITY, self.health);
+               WriteByte(MSG_ENTITY, self.max_health);
+               WriteByte(MSG_ENTITY, self.count);
+               WriteByte(MSG_ENTITY, self.team);
+               WriteByte(MSG_ENTITY, self.owner.iscaptured);
+       }
+
+       if(sf & CPSF_STATUS)
+       {
+               WriteByte(MSG_ENTITY, self.team);
+
+               if(self.health <= 0)
+                       WriteByte(MSG_ENTITY, 0);
+               else
+                       WriteByte(MSG_ENTITY, ceil((self.health / self.max_health) * 255));
+       }
+
+       return true;
+}
+
+void onslaught_controlpoint_icon_link(entity e, void() spawnproc)
+{
+       Net_LinkEntity(e, true, 0, cpicon_send);
+       e.think         = spawnproc;
+       e.nextthink     = time * sys_frametime;
+}
diff --git a/qcsrc/server/controlpoint.qh b/qcsrc/server/controlpoint.qh
new file mode 100644 (file)
index 0000000..d76f0ea
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef CONTROLPOINT_H
+#define CONTROLPOINT_H
+
+const vector CPICON_MIN = '-32 -32 -9';
+const vector CPICON_MAX = '32 32 25';
+
+const int CPSF_STATUS = 4;
+const int CPSF_SETUP = 8;
+
+#endif
index d170cf4c020db0b7e229777a858fb5c55afb6825..446c4cf4e15ba1e7b38c435b2a3506a5da8c022e 100644 (file)
@@ -865,7 +865,7 @@ void Damage (entity targ, entity inflictor, entity attacker, float damage, float
                        else
                                victim = targ;
 
-                       if(IS_PLAYER(victim) || (victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET) || (victim.flags & FL_MONSTER))
+                       if(IS_PLAYER(victim) || (victim.turrcaps_flags & TFL_TURRCAPS_ISTURRET) || (victim.flags & FL_MONSTER) || victim.classname == "func_assault_destructible" || (victim.classname == "onslaught_generator" && !victim.isshielded) || (victim.classname == "onslaught_controlpoint_icon" && !victim.owner.isshielded))
                        {
                                if(DIFF_TEAM(victim, attacker) && !victim.frozen)
                                {
index 0a2708340dd007993e0e4f409615a3748c14276a..cc28f032fdceff893bbc0b2a06d199ad9ee4aa4a 100644 (file)
@@ -1664,48 +1664,6 @@ void ClearWinners(void)
                head.winning = 0;
 }
 
-// Onslaught winning condition:
-// game terminates if only one team has a working generator (or none)
-float WinningCondition_Onslaught()
-{
-       entity head;
-       float t1, t2, t3, t4;
-
-       WinningConditionHelper(); // set worldstatus
-
-       if(warmup_stage)
-               return WINNING_NO;
-
-       // first check if the game has ended
-       t1 = t2 = t3 = t4 = 0;
-       head = find(world, classname, "onslaught_generator");
-       while (head)
-       {
-               if (head.health > 0)
-               {
-                       if (head.team == NUM_TEAM_1) t1 = 1;
-                       if (head.team == NUM_TEAM_2) t2 = 1;
-                       if (head.team == NUM_TEAM_3) t3 = 1;
-                       if (head.team == NUM_TEAM_4) t4 = 1;
-               }
-               head = find(head, classname, "onslaught_generator");
-       }
-       if (t1 + t2 + t3 + t4 < 2)
-       {
-               // game over, only one team remains (or none)
-               ClearWinners();
-               if (t1) SetWinners(team, NUM_TEAM_1);
-               if (t2) SetWinners(team, NUM_TEAM_2);
-               if (t3) SetWinners(team, NUM_TEAM_3);
-               if (t4) SetWinners(team, NUM_TEAM_4);
-               dprint("Have a winner, ending game.\n");
-               return WINNING_YES;
-       }
-
-       // Two or more teams remain
-       return WINNING_NO;
-}
-
 // Assault winning condition: If the attackers triggered a round end (by fulfilling all objectives)
 // they win. Otherwise the defending team wins once the timelimit passes.
 void assault_new_round();
@@ -2075,9 +2033,6 @@ void CheckRules_World()
                return;
        }
 
-       if(g_onslaught)
-               timelimit = 0; // ONS has its own overtime rule
-
        float wantovertime;
        wantovertime = 0;
 
@@ -2163,10 +2118,6 @@ void CheckRules_World()
        {
                checkrules_status = WinningCondition_LMS();
        }
-       else if (g_onslaught)
-       {
-               checkrules_status = WinningCondition_Onslaught(); // TODO remove this?
-       }
        else
        {
                checkrules_status = WinningCondition_Scores(fraglimit, leadlimit);
diff --git a/qcsrc/server/generator.qc b/qcsrc/server/generator.qc
new file mode 100644 (file)
index 0000000..3e0b517
--- /dev/null
@@ -0,0 +1,37 @@
+#include "generator.qh"
+
+bool generator_send(entity to, int sf)
+{
+       WriteByte(MSG_ENTITY, ENT_CLIENT_GENERATOR);
+       WriteByte(MSG_ENTITY, sf);
+       if(sf & GSF_SETUP)
+       {
+               WriteCoord(MSG_ENTITY, self.origin_x);
+               WriteCoord(MSG_ENTITY, self.origin_y);
+               WriteCoord(MSG_ENTITY, self.origin_z);
+
+               WriteByte(MSG_ENTITY, self.health);
+               WriteByte(MSG_ENTITY, self.max_health);
+               WriteByte(MSG_ENTITY, self.count);
+               WriteByte(MSG_ENTITY, self.team);
+       }
+
+       if(sf & GSF_STATUS)
+       {
+               WriteByte(MSG_ENTITY, self.team);
+
+               if(self.health <= 0)
+                       WriteByte(MSG_ENTITY, 0);
+               else
+                       WriteByte(MSG_ENTITY, ceil((self.health / self.max_health) * 255));
+       }
+
+       return true;
+}
+
+void generator_link(void() spawnproc)
+{
+       Net_LinkEntity(self, true, 0, generator_send);
+       self.think              = spawnproc;
+       self.nextthink  = time;
+}
diff --git a/qcsrc/server/generator.qh b/qcsrc/server/generator.qh
new file mode 100644 (file)
index 0000000..cbdb36e
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef GENERATOR_H
+#define GENERATOR_H
+const vector GENERATOR_MIN = '-52 -52 -14';
+const vector GENERATOR_MAX = '52 52 75';
+
+const int GSF_STATUS = 4;
+const int GSF_SETUP = 8;
+
+bool generator_send(entity to, int sf);
+#endif
index d998ea7999b836763b21472eedd131204983e1b2..c41c7b3b930f35c76b70396fdb46fff833116d4d 100644 (file)
@@ -507,16 +507,6 @@ string playername(entity p)
         return p.netname;
 }
 
-vector randompos(vector m1, vector m2)
-{
-    vector v;
-    m2 = m2 - m1;
-    v.x = m2_x * random() + m1_x;
-    v.y = m2_y * random() + m1_y;
-    v.z = m2_z * random() + m1_z;
-    return  v;
-}
-
 float want_weapon(entity weaponinfo, float allguns) // WEAPONTODO: what still needs done?
 {
        int i = weaponinfo.weapon;
index d1f20f7ee950e5e3af577fe9dcbc154302cda51a..a05e6c1376340a991bb8201d1f235d46db6c3104 100644 (file)
-float autocvar_g_onslaught_spawn_at_controlpoints;
-float autocvar_g_onslaught_spawn_at_generator;
-float autocvar_g_onslaught_cp_proxydecap;
-float autocvar_g_onslaught_cp_proxydecap_distance = 512;
-float autocvar_g_onslaught_cp_proxydecap_dps = 100;
+#include "../controlpoint.qh"
+#include "../generator.qh"
 
-void onslaught_generator_updatesprite(entity e);
-void onslaught_controlpoint_updatesprite(entity e);
-void onslaught_link_checkupdate();
+// =======================
+// CaptureShield Functions
+// =======================
 
-.entity sprite;
-.string target2;
-.float iscaptured;
-.float islinked;
-.float isgenneighbor_red;
-.float isgenneighbor_blue;
-.float iscpneighbor_red;
-.float iscpneighbor_blue;
-.float isshielded;
-.float lasthealth;
-.float lastteam;
-.float lastshielded;
-.float lastcaptured;
+bool ons_CaptureShield_Customize()
+{
+       entity e = WaypointSprite_getviewentity(other);
 
-entity ons_red_generator;
-entity ons_blue_generator;
+       if(!self.enemy.isshielded && (ons_ControlPoint_Attackable(self.enemy, e.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return false; }
+       if(SAME_TEAM(self, e)) { return false; }
 
-void ons_gib_damage (entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector vforce)
-{
-       self.velocity = self.velocity + vforce;
+       return true;
 }
 
-.float giblifetime;
-void ons_throwgib_think()
+void ons_CaptureShield_Touch()
 {
-       float d;
+       if(!self.enemy.isshielded && (ons_ControlPoint_Attackable(self.enemy, other.team) > 0 || self.enemy.classname != "onslaught_controlpoint")) { return; }
+       if(!IS_PLAYER(other)) { return; }
+       if(SAME_TEAM(other, self)) { return; }
 
-       self.nextthink = time + 0.05;
+       vector mymid = (self.absmin + self.absmax) * 0.5;
+       vector othermid = (other.absmin + other.absmax) * 0.5;
 
-       d = self.giblifetime - time;
+       Damage(other, self, self, 0, DEATH_HURTTRIGGER, mymid, normalize(othermid - mymid) * ons_captureshield_force);
 
-       if(d<0)
+       if(IS_REAL_CLIENT(other))
        {
-               self.think = SUB_Remove;
-               return;
+               play2(other, "onslaught/damageblockedbyshield.wav");
+
+               if(self.enemy.classname == "onslaught_generator")
+                       Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_GENERATOR_SHIELDED);
+               else
+                       Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_CONTROLPOINT_SHIELDED);
        }
-       if(d<1)
-               self.alpha = d;
+}
 
-       if(d>2)
-       if(random()<0.6)
-               pointparticles(particleeffectnum("onslaught_generator_gib_flame"), self.origin, '0 0 0', 1);
+void ons_CaptureShield_Reset()
+{
+       self.colormap = self.enemy.colormap;
+       self.team = self.enemy.team;
 }
 
-void ons_throwgib(vector v_from, vector v_to, string smodel, float f_lifetime, float b_burn)
+void ons_CaptureShield_Spawn(entity generator, bool is_generator)
 {
-       entity gib;
+       entity shield = spawn();
+
+       shield.enemy = generator;
+       shield.team = generator.team;
+       shield.colormap = generator.colormap;
+       shield.reset = ons_CaptureShield_Reset;
+       shield.touch = ons_CaptureShield_Touch;
+       shield.customizeentityforclient = ons_CaptureShield_Customize;
+       shield.classname = "ons_captureshield";
+       shield.effects = EF_ADDITIVE;
+       shield.movetype = MOVETYPE_NOCLIP;
+       shield.solid = SOLID_TRIGGER;
+       shield.avelocity = '7 0 11';
+       shield.scale = 1;
+       shield.model = ((is_generator) ? "models/onslaught/generator_shield.md3" : "models/onslaught/controlpoint_shield.md3");
+       
+       precache_model(shield.model);
+       setorigin(shield, generator.origin);
+       setmodel(shield, shield.model);
+       setsize(shield, shield.scale * shield.mins, shield.scale * shield.maxs);
+}
 
-       gib = spawn();
 
-       setmodel(gib, smodel);
-       setorigin(gib, v_from);
-       gib.solid = SOLID_BBOX;
-       gib.movetype = MOVETYPE_BOUNCE;
-       gib.takedamage = DAMAGE_YES;
-       gib.event_damage = ons_gib_damage;
-       gib.health = -1;
-       gib.effects = EF_LOWPRECISION;
-       gib.flags = FL_NOTARGET;
-       gib.velocity = v_to;
-       gib.giblifetime = time + f_lifetime;
+// ==========
+// Junk Pile
+// ==========
 
-       if (b_burn)
+void ons_debug(string input)
+{
+       switch(autocvar_g_onslaught_debug)
        {
-               gib.think = ons_throwgib_think;
-               gib.nextthink = time + 0.05;
+               case 1: dprint(input); break;
+               case 2: print(input); break;
        }
-       else
-               SUB_SetFade(gib, gib.giblifetime, 2);
+}
+
+void FixSize(entity e)
+{
+       e.mins_x = rint(e.mins_x);
+       e.mins_y = rint(e.mins_y);
+       e.mins_z = rint(e.mins_z);
+       
+       e.maxs_x = rint(e.maxs_x);
+       e.maxs_y = rint(e.maxs_y);
+       e.maxs_z = rint(e.maxs_z);
+}
+
+vector randompos(vector m1, vector m2)
+{
+       vector v;
+       m2 = m2 - m1;
+       v_x = m2_x * random() + m1_x;
+       v_y = m2_y * random() + m1_y;
+       v_z = m2_z * random() + m1_z;
+       return  v;
+}
+
+void setmodel_fixsize(entity e, string m)
+{
+       setmodel(e, m);
+       FixSize(e);
 }
 
 void onslaught_updatelinks()
 {
-       entity l, links;
-       float stop, t1, t2, t3, t4;
+       entity l;
        // first check if the game has ended
-       dprint("--- updatelinks ---\n");
-       links = findchain(classname, "onslaught_link");
+       ons_debug("--- updatelinks ---\n");
        // mark generators as being shielded and networked
-       l = findchain(classname, "onslaught_generator");
-       while (l)
+       for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
        {
                if (l.iscaptured)
-                       dprint(etos(l), " (generator) belongs to team ", ftos(l.team), "\n");
+                       ons_debug(strcat(etos(l), " (generator) belongs to team ", ftos(l.team), "\n"));
                else
-                       dprint(etos(l), " (generator) is destroyed\n");
+                       ons_debug(strcat(etos(l), " (generator) is destroyed\n"));
                l.islinked = l.iscaptured;
                l.isshielded = l.iscaptured;
-               l = l.chain;
+               l.sprite.SendFlags |= 16;
        }
        // mark points as shielded and not networked
-       l = findchain(classname, "onslaught_controlpoint");
-       while (l)
+       for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
        {
                l.islinked = false;
                l.isshielded = true;
-               l.isgenneighbor_red = false;
-               l.isgenneighbor_blue = false;
-               l.iscpneighbor_red = false;
-               l.iscpneighbor_blue = false;
-               dprint(etos(l), " (point) belongs to team ", ftos(l.team), "\n");
-               l = l.chain;
+               int i;
+               for(i = 0; i < 17; ++i) { l.isgenneighbor[i] = false; l.iscpneighbor[i] = false; }
+               ons_debug(strcat(etos(l), " (point) belongs to team ", ftos(l.team), "\n"));
+               l.sprite.SendFlags |= 16;
        }
        // flow power outward from the generators through the network
-       l = links;
-       while (l)
-       {
-               dprint(etos(l), " (link) connects ", etos(l.goalentity), " with ", etos(l.enemy), "\n");
-               l = l.chain;
-       }
-       stop = false;
+       bool stop = false;
        while (!stop)
        {
                stop = true;
-               l = links;
-               while (l)
+               for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
                {
                        // if both points are captured by the same team, and only one of
                        // them is powered, mark the other one as powered as well
                        if (l.enemy.iscaptured && l.goalentity.iscaptured)
                                if (l.enemy.islinked != l.goalentity.islinked)
-                                       if (l.enemy.team == l.goalentity.team)
+                                       if(SAME_TEAM(l.enemy, l.goalentity))
                                        {
                                                if (!l.goalentity.islinked)
                                                {
                                                        stop = false;
                                                        l.goalentity.islinked = true;
-                                                       dprint(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)\n");
+                                                       ons_debug(strcat(etos(l), " (link) is marking ", etos(l.goalentity), " (point) because its team matches ", etos(l.enemy), " (point)\n"));
                                                }
                                                else if (!l.enemy.islinked)
                                                {
                                                        stop = false;
                                                        l.enemy.islinked = true;
-                                                       dprint(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)\n");
+                                                       ons_debug(strcat(etos(l), " (link) is marking ", etos(l.enemy), " (point) because its team matches ", etos(l.goalentity), " (point)\n"));
                                                }
                                        }
-                       l = l.chain;
                }
        }
        // now that we know which points are powered we can mark their neighbors
        // as unshielded if team differs
-       l = links;
-       while (l)
+       for(l = ons_worldlinklist; l; l = l.ons_worldlinknext)
        {
                if (l.goalentity.islinked)
                {
-                       if (l.goalentity.team != l.enemy.team)
+                       if(DIFF_TEAM(l.goalentity, l.enemy))
                        {
-                               dprint(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)\n");
+                               ons_debug(strcat(etos(l), " (link) is unshielding ", etos(l.enemy), " (point) because its team does not match ", etos(l.goalentity), " (point)\n"));
                                l.enemy.isshielded = false;
                        }
                        if(l.goalentity.classname == "onslaught_generator")
-                       {
-                               if(l.goalentity.team == NUM_TEAM_1)
-                                       l.enemy.isgenneighbor_red = true;
-                               else if(l.goalentity.team == NUM_TEAM_2)
-                                       l.enemy.isgenneighbor_blue = true;
-                       }
+                               l.enemy.isgenneighbor[l.goalentity.team] = true;
                        else
-                       {
-                               if(l.goalentity.team == NUM_TEAM_1)
-                                       l.enemy.iscpneighbor_red = true;
-                               else if(l.goalentity.team == NUM_TEAM_2)
-                                       l.enemy.iscpneighbor_blue = true;
-                       }
+                               l.enemy.iscpneighbor[l.goalentity.team] = true;
                }
                if (l.enemy.islinked)
                {
-                       if (l.goalentity.team != l.enemy.team)
+                       if(DIFF_TEAM(l.goalentity, l.enemy))
                        {
-                               dprint(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)\n");
+                               ons_debug(strcat(etos(l), " (link) is unshielding ", etos(l.goalentity), " (point) because its team does not match ", etos(l.enemy), " (point)\n"));
                                l.goalentity.isshielded = false;
                        }
                        if(l.enemy.classname == "onslaught_generator")
-                       {
-                               if(l.enemy.team == NUM_TEAM_1)
-                                       l.goalentity.isgenneighbor_red = true;
-                               else if(l.enemy.team == NUM_TEAM_2)
-                                       l.goalentity.isgenneighbor_blue = true;
-                       }
+                               l.goalentity.isgenneighbor[l.enemy.team] = true;
                        else
-                       {
-                               if(l.enemy.team == NUM_TEAM_1)
-                                       l.goalentity.iscpneighbor_red = true;
-                               else if(l.enemy.team == NUM_TEAM_2)
-                                       l.goalentity.iscpneighbor_blue = true;
-                       }
+                               l.goalentity.iscpneighbor[l.enemy.team] = true;
                }
-               l = l.chain;
        }
-       // now update the takedamage and alpha variables on generator shields
-       l = findchain(classname, "onslaught_generator");
-       while (l)
+       // now update the generators
+       for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
        {
                if (l.isshielded)
                {
-                       dprint(etos(l), " (generator) is shielded\n");
-                       l.enemy.alpha = 1;
+                       ons_debug(strcat(etos(l), " (generator) is shielded\n"));
                        l.takedamage = DAMAGE_NO;
                        l.bot_attack = false;
                }
                else
                {
-                       dprint(etos(l), " (generator) is not shielded\n");
-                       l.enemy.alpha = -1;
+                       ons_debug(strcat(etos(l), " (generator) is not shielded\n"));
                        l.takedamage = DAMAGE_AIM;
                        l.bot_attack = true;
                }
-               l = l.chain;
+
+               ons_Generator_UpdateSprite(l);
        }
        // now update the takedamage and alpha variables on control point icons
-       l = findchain(classname, "onslaught_controlpoint");
-       while (l)
+       for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
        {
                if (l.isshielded)
                {
-                       dprint(etos(l), " (point) is shielded\n");
-                       l.enemy.alpha = 1;
+                       ons_debug(strcat(etos(l), " (point) is shielded\n"));
                        if (l.goalentity)
                        {
                                l.goalentity.takedamage = DAMAGE_NO;
@@ -234,105 +223,98 @@ void onslaught_updatelinks()
                }
                else
                {
-                       dprint(etos(l), " (point) is not shielded\n");
-                       l.enemy.alpha = -1;
+                       ons_debug(strcat(etos(l), " (point) is not shielded\n"));
                        if (l.goalentity)
                        {
                                l.goalentity.takedamage = DAMAGE_AIM;
                                l.goalentity.bot_attack = true;
                        }
                }
-               onslaught_controlpoint_updatesprite(l);
-               l = l.chain;
+               ons_ControlPoint_UpdateSprite(l);
        }
-       // count generators owned by each team
-       t1 = t2 = t3 = t4 = 0;
-       l = findchain(classname, "onslaught_generator");
-       while (l)
+       l = findchain(classname, "ons_captureshield");
+       while(l)
        {
-               if (l.iscaptured)
-               {
-                       if (l.team == NUM_TEAM_1) t1 = 1;
-                       if (l.team == NUM_TEAM_2) t2 = 1;
-                       if (l.team == NUM_TEAM_3) t3 = 1;
-                       if (l.team == NUM_TEAM_4) t4 = 1;
-               }
-               onslaught_generator_updatesprite(l);
+               l.team = l.enemy.team;
+               l.colormap = l.enemy.colormap;
                l = l.chain;
        }
-       // see if multiple teams remain (if not, it's game over)
-       if (t1 + t2 + t3 + t4 < 2)
-               dprint("--- game over ---\n");
-       else
-               dprint("--- done updating links ---\n");
 }
 
-float onslaught_controlpoint_can_be_linked(entity cp, float t)
+
+// ===================
+// Main Link Functions
+// ===================
+
+bool ons_Link_Send(entity to, int sendflags)
 {
-       if(t == NUM_TEAM_1)
+       WriteByte(MSG_ENTITY, ENT_CLIENT_RADARLINK);
+       WriteByte(MSG_ENTITY, sendflags);
+       if(sendflags & 1)
        {
-               if(cp.isgenneighbor_red)
-                       return 2;
-               if(cp.iscpneighbor_red)
-                       return 1;
+               WriteCoord(MSG_ENTITY, self.goalentity.origin_x);
+               WriteCoord(MSG_ENTITY, self.goalentity.origin_y);
+               WriteCoord(MSG_ENTITY, self.goalentity.origin_z);
        }
-       else if(t == NUM_TEAM_2)
+       if(sendflags & 2)
        {
-               if(cp.isgenneighbor_blue)
-                       return 2;
-               if(cp.iscpneighbor_blue)
-                       return 1;
+               WriteCoord(MSG_ENTITY, self.enemy.origin_x);
+               WriteCoord(MSG_ENTITY, self.enemy.origin_y);
+               WriteCoord(MSG_ENTITY, self.enemy.origin_z);
        }
-       return 0;
-       /*
-          entity e;
-       // check to see if this player has a legitimate claim to capture this
-       // control point - more specifically that there is a captured path of
-       // points leading back to the team generator
-       e = findchain(classname, "onslaught_link");
-       while (e)
-       {
-       if (e.goalentity == cp)
-       {
-       dprint(etos(e), " (link) connects to ", etos(e.enemy), " (point)");
-       if (e.enemy.islinked)
-       {
-       dprint(" which is linked");
-       if (e.enemy.team == t)
+       if(sendflags & 4)
        {
-       dprint(" and has the correct team!\n");
-       return 1;
-       }
-       else
-       dprint(" but has the wrong team\n");
-       }
-       else
-       dprint("\n");
+               WriteByte(MSG_ENTITY, self.clientcolors); // which is goalentity's color + enemy's color * 16
        }
-       else if (e.enemy == cp)
-       {
-       dprint(etos(e), " (link) connects to ", etos(e.goalentity), " (point)");
-       if (e.goalentity.islinked)
-       {
-       dprint(" which is linked");
-       if (e.goalentity.team == t)
+       return true;
+}
+
+void ons_Link_CheckUpdate()
+{
+       // TODO check if the two sides have moved (currently they won't move anyway)
+       float cc = 0, cc1 = 0, cc2 = 0;
+       
+       if(self.goalentity.islinked || self.goalentity.iscaptured) { cc1 = (self.goalentity.team - 1) * 0x01; }
+       if(self.enemy.islinked || self.enemy.iscaptured) { cc2 = (self.enemy.team - 1) * 0x10; }
+       
+       cc = cc1 + cc2;
+
+       if(cc != self.clientcolors)
        {
-       dprint(" and has a team!\n");
-       return 1;
-       }
-       else
-       dprint(" but has the wrong team\n");
-       }
-       else
-       dprint("\n");
-       }
-       e = e.chain;
+               self.clientcolors = cc;
+               self.SendFlags |= 4;
        }
+
+       self.nextthink = time;
+}
+
+void ons_DelayedLinkSetup()
+{
+       self.goalentity = find(world, targetname, self.target);
+       self.enemy = find(world, targetname, self.target2);
+       if(!self.goalentity) { objerror("can not find target\n"); }
+       if(!self.enemy) { objerror("can not find target2\n"); }
+
+       ons_debug(strcat(etos(self.goalentity), " linked with ", etos(self.enemy), "\n"));
+       self.SendFlags |= 3;
+       self.think = ons_Link_CheckUpdate;
+       self.nextthink = time;
+}
+
+
+// =============================
+// Main Control Point Functions
+// =============================
+
+int ons_ControlPoint_CanBeLinked(entity cp, int teamnumber)
+{
+       if(cp.isgenneighbor[teamnumber]) { return 2; }
+       if(cp.iscpneighbor[teamnumber]) { return 1; }
+
        return 0;
-        */
 }
 
-float onslaught_controlpoint_attackable(entity cp, float t)
+int ons_ControlPoint_Attackable(entity cp, int teamnumber)
        // -2: SAME TEAM, attackable by enemy!
        // -1: SAME TEAM!
        // 0: off limits
@@ -341,7 +323,7 @@ float onslaught_controlpoint_attackable(entity cp, float t)
        // 3: attack it (HIGH PRIO)
        // 4: touch it (HIGH PRIO)
 {
-       float a;
+       int a;
 
        if(cp.isshielded)
        {
@@ -350,16 +332,16 @@ float onslaught_controlpoint_attackable(entity cp, float t)
        else if(cp.goalentity)
        {
                // if there's already an icon built, nothing happens
-               if(cp.team == t)
+               if(cp.team == teamnumber)
                {
-                       a = onslaught_controlpoint_can_be_linked(cp, NUM_TEAM_1 + NUM_TEAM_2 - t);
+                       a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
                        if(a) // attackable by enemy?
                                return -2; // EMERGENCY!
                        return -1;
                }
                // we know it can be linked, so no need to check
                // but...
-               a = onslaught_controlpoint_can_be_linked(cp, t);
+               a = ons_ControlPoint_CanBeLinked(cp, teamnumber);
                if(a == 2) // near our generator?
                        return 3; // EMERGENCY!
                return 1;
@@ -367,9 +349,9 @@ float onslaught_controlpoint_attackable(entity cp, float t)
        else
        {
                // free point
-               if(onslaught_controlpoint_can_be_linked(cp, t))
+               if(ons_ControlPoint_CanBeLinked(cp, teamnumber))
                {
-                       a = onslaught_controlpoint_can_be_linked(cp, NUM_TEAM_1 + NUM_TEAM_2 - t);
+                       a = ons_ControlPoint_CanBeLinked(cp, teamnumber); // why was this here NUM_TEAM_1 + NUM_TEAM_2 - t
                        if(a == 2)
                                return 4; // GET THIS ONE NOW!
                        else
@@ -379,428 +361,281 @@ float onslaught_controlpoint_attackable(entity cp, float t)
        return 0;
 }
 
-float overtime_msg_time;
-void onslaught_generator_think()
+void ons_ControlPoint_Icon_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
 {
-       float d;
-       entity e;
-       self.nextthink = ceil(time + 1);
-       if (!gameover)
+       entity oself;
+       
+       if(damage <= 0) { return; }
+
+       if (self.owner.isshielded)
        {
-               if (autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60)
-               {
-                       if (!overtime_msg_time)
-                       {
-                               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT);
-                               overtime_msg_time = time;
-                       }
-                       // self.max_health / 300 gives 5 minutes of overtime.
-                       // control points reduce the overtime duration.
-                       sound(self, CH_TRIGGER, "onslaught/generator_decay.wav", VOL_BASE, ATTEN_NORM);
-                       d = 1;
-                       e = findchain(classname, "onslaught_controlpoint");
-                       while (e)
+               // this is protected by a shield, so ignore the damage
+               if (time > self.pain_finished)
+                       if (IS_PLAYER(attacker))
                        {
-                               if (e.team != self.team)
-                                       if (e.islinked)
-                                               d = d + 1;
-                               e = e.chain;
+                               play2(attacker, "onslaught/damageblockedbyshield.wav");
+                               self.pain_finished = time + 1;
+                               attacker.typehitsound += 1; // play both sounds (shield is way too quiet)
                        }
 
-                       if(autocvar_g_campaign && autocvar__campaign_testrun)
-                               d = d * self.max_health;
-                       else
-                               d = d * self.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
-
-                       Damage(self, self, self, d, DEATH_HURTTRIGGER, self.origin, '0 0 0');
-               }
-               else if (overtime_msg_time)
-                       overtime_msg_time = 0;
-
-        if(!self.isshielded && self.wait < time)
-        {
-            self.wait = time + 5;
-            FOR_EACH_REALPLAYER(e)
-            {
-                               if(SAME_TEAM(e, self))
-                {
-                                       Send_Notification(NOTIF_ONE, e, MSG_CENTER, CENTER_ONS_NOTSHIELDED);
-                    soundto(MSG_ONE, e, CHAN_AUTO, "kh/alarm.wav", VOL_BASE, ATTEN_NONE);    // FIXME: Uniqe sound?
-                }
-            }
-        }
+               return;
        }
-}
-
-void onslaught_generator_ring_spawn(vector org)
-{
-       modeleffect_spawn("models/onslaught/shockwavetransring.md3", 0, 0, org, '0 0 0', '0 0 0', '0 0 0', 0, -16, 0.1, 1.25, 0.25);
-}
 
-void onslaught_generator_ray_think()
-{
-       self.nextthink = time + 0.05;
-       if(self.count > 10)
+       if(IS_PLAYER(attacker))
+       if(time - ons_notification_time[self.team] > 10)
        {
-               self.think = SUB_Remove;
-               return;
+               play2team(self.team, "onslaught/controlpoint_underattack.wav");
+               ons_notification_time[self.team] = time;
        }
 
-       if(self.count > 5)
-               self.alpha -= 0.1;
+       self.health = self.health - damage;
+       if(self.owner.iscaptured)
+               WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
+       else
+               WaypointSprite_UpdateBuildFinished(self.owner.sprite, time + (self.max_health - self.health) / (self.count / ONS_CP_THINKRATE));
+       self.pain_finished = time + 1;
+       // particles on every hit
+       pointparticles(particleeffectnum("sparks"), hitloc, force*-1, 1);
+       //sound on every hit
+       if (random() < 0.5)
+               sound(self, CH_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE+0.3, ATTEN_NORM);
        else
-               self.alpha += 0.1;
+               sound(self, CH_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE+0.3, ATTEN_NORM);
 
-       self.scale += 0.2;
-       self.count +=1;
-}
+       if (self.health < 0)
+       {
+               sound(self, CH_TRIGGER, "weapons/grenade_impact.wav", VOL_BASE, ATTEN_NORM);
+               pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
+               Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_CPDESTROYED_), self.owner.message, attacker.netname);
+               
+               PlayerScore_Add(attacker, SP_ONS_TAKES, 1);
+               PlayerScore_Add(attacker, SP_SCORE, 10);
+               
+               self.owner.goalentity = world;
+               self.owner.islinked = false;
+               self.owner.iscaptured = false;
+               self.owner.team = 0;
+               self.owner.colormap = 1024;
 
-void onslaught_generator_ray_spawn(vector org)
-{
-       entity e;
-       e = spawn();
-       setmodel(e, "models/onslaught/ons_ray.md3");
-       setorigin(e, org);
-       e.angles = randomvec() * 360;
-       e.alpha = 0;
-       e.scale = random() * 5 + 8;
-       e.think = onslaught_generator_ray_think;
-       e.nextthink = time + 0.05;
-}
+               WaypointSprite_UpdateMaxHealth(self.owner.sprite, 0);
 
-void onslaught_generator_shockwave_spawn(vector org)
-{
-       shockwave_spawn("models/onslaught/shockwave.md3", org, -64, 0.75, 0.5);
-}
+               onslaught_updatelinks();
 
-void onslaught_generator_damage_think()
-{
-       if(self.owner.health < 0)
-       {
-               self.think = SUB_Remove;
-               return;
-       }
-       self.nextthink = time+0.1;
+               // Use targets now (somebody make sure this is in the right place..)
+               oself = self;
+               self = self.owner;
+               activator = self;
+               SUB_UseTargets ();
+               self = oself;
 
-       // damaged fx (less probable the more damaged is the generator)
-       if(random() < 0.9 - self.owner.health / self.owner.max_health)
-               if(random() < 0.01)
-               {
-                       pointparticles(particleeffectnum("electro_ballexplode"), self.origin + randompos('-50 -50 -20', '50 50 50'), '0 0 0', 1);
-                       sound(self, CH_TRIGGER, "onslaught/electricity_explode.wav", VOL_BASE, ATTEN_NORM);
-               }
-               else
-                       pointparticles(particleeffectnum("torch_small"), self.origin + randompos('-60 -60 -20', '60 60 60'), '0 0 0', 1);
-}
+               self.owner.waslinked = self.owner.islinked;
+               if(self.owner.model != "models/onslaught/controlpoint_pad.md3")
+                       setmodel_fixsize(self.owner, "models/onslaught/controlpoint_pad.md3");
+               //setsize(self, '-32 -32 0', '32 32 8');
 
-void onslaught_generator_damage_spawn(entity gd_owner)
-{
-       entity e;
-       e = spawn();
-       e.owner = gd_owner;
-       e.health = self.owner.health;
-       setorigin(e, gd_owner.origin);
-       e.think = onslaught_generator_damage_think;
-       e.nextthink = time+1;
+               remove(self);
+       }
+       
+       self.SendFlags |= CPSF_STATUS;
 }
 
-void onslaught_generator_deaththink()
+void ons_ControlPoint_Icon_Think()
 {
-       vector org;
-       float i;
-
-       if (!self.count)
-               self.count = 40;
+       entity oself;
+       self.nextthink = time + ONS_CP_THINKRATE;
 
-       // White shockwave
-       if(self.count==40||self.count==20)
+       if(autocvar_g_onslaught_cp_proxydecap)
        {
-               onslaught_generator_ring_spawn(self.origin);
-               sound(self, CH_TRIGGER, "onslaught/shockwave.wav", VOL_BASE, ATTEN_NORM);
-       }
+        int _enemy_count = 0;
+        int _friendly_count = 0;
+        float _dist;
+        entity _player;
 
-       // Throw some gibs
-       if(random() < 0.3)
-       {
-               i = random();
-               if(i < 0.3)
-                       ons_throwgib(self.origin + '0 0 40', (100 * randomvec() - '1 1 1') * 11 + '0 0 20', "models/onslaught/gen_gib1.md3", 6, true);
-               else if(i > 0.7)
-                       ons_throwgib(self.origin + '0 0 40', (100 * randomvec() - '1 1 1') * 12 + '0 0 20', "models/onslaught/gen_gib2.md3", 6, true);
-               else
-                       ons_throwgib(self.origin + '0 0 40', (100 * randomvec() - '1 1 1') * 13 + '0 0 20', "models/onslaught/gen_gib3.md3", 6, true);
-       }
+        FOR_EACH_PLAYER(_player)
+        {
+            if(!_player.deadflag)
+            {
+                _dist = vlen(_player.origin - self.origin);
+                if(_dist < autocvar_g_onslaught_cp_proxydecap_distance)
+                {
+                                       if(SAME_TEAM(_player, self))
+                        ++_friendly_count;
+                    else
+                        ++_enemy_count;
+                }
+            }
+        }
+
+        _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
+        _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * ONS_CP_THINKRATE);
 
-       // Spawn fire balls
-       for(i=0;i < 10;++i)
+        self.health = bound(0, self.health + (_friendly_count - _enemy_count), self.max_health);
+               self.SendFlags |= CPSF_STATUS;
+        if(self.health <= 0)
+        {
+            ons_ControlPoint_Icon_Damage(self, self, 1, 0, self.origin, '0 0 0');
+            return;
+        }
+    }
+
+       if (time > self.pain_finished + 5)
        {
-               org = self.origin + randompos('-30 -30 -30' * i + '0 0 -20', '30 30 30' * i + '0 0 20');
-               pointparticles(particleeffectnum("onslaught_generator_gib_explode"), org, '0 0 0', 1);
+               if(self.health < self.max_health)
+               {
+                       self.health = self.health + self.count;
+                       if (self.health >= self.max_health)
+                               self.health = self.max_health;
+                       WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
+               }
        }
 
-       // Short explosion sound + small explosion
-       if(random() < 0.25)
+       if(self.owner.islinked != self.owner.waslinked)
        {
-               te_explosion(self.origin);
-               sound(self, CH_TRIGGER, "weapons/grenade_impact.wav", VOL_BASE, ATTEN_NORM);
-       }
+               // unteam the spawnpoint if needed
+               int t = self.owner.team;
+               if(!self.owner.islinked)
+                       self.owner.team = 0;
+
+               oself = self;
+               self = self.owner;
+               activator = self;
+               SUB_UseTargets ();
+               self = oself;
 
-       // Particles
-       org = self.origin + randompos(self.mins + '8 8 8', self.maxs + '-8 -8 -8');
-       pointparticles(particleeffectnum("onslaught_generator_smallexplosion"), org, '0 0 0', 1);
+               self.owner.team = t;
 
-       // rays
-       if(random() > 0.25 )
-       {
-               onslaught_generator_ray_spawn(self.origin);
+               self.owner.waslinked = self.owner.islinked;
        }
 
-       // Final explosion
-       if(self.count==1)
+       // damaged fx
+       if(random() < 0.6 - self.health / self.max_health)
        {
-               org = self.origin;
-               te_explosion(org);
-               onslaught_generator_shockwave_spawn(org);
-               pointparticles(particleeffectnum("onslaught_generator_finalexplosion"), org, '0 0 0', 1);
-               sound(self, CH_TRIGGER, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
-       }
-       else
-               self.nextthink = time + 0.05;
+               pointparticles(particleeffectnum("electricity_sparks"), self.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
 
-       self.count = self.count - 1;
+               if(random() > 0.8)
+                       sound(self, CH_PAIN, "onslaught/ons_spark1.wav", VOL_BASE, ATTEN_NORM);
+               else if (random() > 0.5)
+                       sound(self, CH_PAIN, "onslaught/ons_spark2.wav", VOL_BASE, ATTEN_NORM);
+       }
 }
 
-void onslaught_generator_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
+void ons_ControlPoint_Icon_BuildThink()
 {
-       float i;
-       if (damage <= 0)
-               return;
-       if(warmup_stage)
+       entity oself;
+       int a;
+
+       self.nextthink = time + ONS_CP_THINKRATE;
+
+       // only do this if there is power
+       a = ons_ControlPoint_CanBeLinked(self.owner, self.owner.team);
+       if(!a)
                return;
-       if (attacker != self)
+
+       self.health = self.health + self.count;
+       
+       self.SendFlags |= CPSF_STATUS;
+
+       if (self.health >= self.max_health)
        {
-               if (self.isshielded)
-               {
-                       // this is protected by a shield, so ignore the damage
-                       if (time > self.pain_finished)
-                               if (IS_PLAYER(attacker))
-                               {
-                                       play2(attacker, "onslaught/damageblockedbyshield.wav");
-                                       self.pain_finished = time + 1;
-                               }
-                       return;
-               }
-               if (time > self.pain_finished)
-               {
-                       self.pain_finished = time + 10;
-                       bprint(Team_ColoredFullName(self.team), " generator under attack!\n");
-                       play2team(self.team, "onslaught/generator_underattack.wav");
-               }
-       }
-       self.health = self.health - damage;
-       WaypointSprite_UpdateHealth(self.sprite, self.health);
-       // choose an animation frame based on health
-       self.frame = 10 * bound(0, (1 - self.health / self.max_health), 1);
-       // see if the generator is still functional, or dying
-       if (self.health > 0)
-       {
-#ifdef ONSLAUGHT_SPAM
-               float h, lh;
-               lh = ceil(self.lasthealth / 100) * 100;
-               h = ceil(self.health / 100) * 100;
-               if(lh != h)
-                       bprint(Team_ColoredFullName(self.team), " generator has less than ", ftos(h), " health remaining\n");
-#endif
-               self.lasthealth = self.health;
-       }
-       else if (!warmup_stage)
-       {
-               if (attacker == self)
-                       bprint(Team_ColoredFullName(self.team), " generator spontaneously exploded due to overtime!\n");
-               else
-               {
-                       string t;
-                       t = Team_ColoredFullName(attacker.team);
-                       bprint(Team_ColoredFullName(self.team), " generator destroyed by ", t, "!\n");
-               }
-               self.iscaptured = false;
-               self.islinked = false;
-               self.isshielded = false;
-               self.takedamage = DAMAGE_NO; // can't be hurt anymore
-               self.event_damage = func_null; // won't do anything if hurt
-               self.count = 0; // reset counter
-               self.think = onslaught_generator_deaththink; // explosion sequence
-               self.nextthink = time; // start exploding immediately
-               self.think(); // do the first explosion now
+               self.health = self.max_health;
+               self.count = autocvar_g_onslaught_cp_regen * ONS_CP_THINKRATE; // slow repair rate from now on
+               self.think = ons_ControlPoint_Icon_Think;
+               sound(self, CH_TRIGGER, "onslaught/controlpoint_built.wav", VOL_BASE, ATTEN_NORM);
+               self.owner.iscaptured = true;
+               self.solid = SOLID_BBOX;
 
-               WaypointSprite_UpdateMaxHealth(self.sprite, 0);
+               pointparticles(particleeffectnum(sprintf("%s_cap", Static_Team_ColorName_Lower(self.owner.team))), self.owner.origin, '0 0 0', 1);
 
-               onslaught_updatelinks();
-       }
+               WaypointSprite_UpdateMaxHealth(self.owner.sprite, self.max_health);
+               WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
 
-       if(self.health <= 0)
-               setmodel(self, "models/onslaught/generator_dead.md3");
-       else if(self.health < self.max_health * 0.10)
-               setmodel(self, "models/onslaught/generator_dmg9.md3");
-       else if(self.health < self.max_health * 0.20)
-               setmodel(self, "models/onslaught/generator_dmg8.md3");
-       else if(self.health < self.max_health * 0.30)
-               setmodel(self, "models/onslaught/generator_dmg7.md3");
-       else if(self.health < self.max_health * 0.40)
-               setmodel(self, "models/onslaught/generator_dmg6.md3");
-       else if(self.health < self.max_health * 0.50)
-               setmodel(self, "models/onslaught/generator_dmg5.md3");
-       else if(self.health < self.max_health * 0.60)
-               setmodel(self, "models/onslaught/generator_dmg4.md3");
-       else if(self.health < self.max_health * 0.70)
-               setmodel(self, "models/onslaught/generator_dmg3.md3");
-       else if(self.health < self.max_health * 0.80)
-               setmodel(self, "models/onslaught/generator_dmg2.md3");
-       else if(self.health < self.max_health * 0.90)
-               setmodel(self, "models/onslaught/generator_dmg1.md3");
-       setsize(self, '-52 -52 -14', '52 52 75');
+               if(IS_PLAYER(self.owner.ons_toucher))
+               {
+                       Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ONSLAUGHT_CAPTURE, self.owner.ons_toucher.netname, self.owner.message);
+                       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);
+                       Send_Notification(NOTIF_ONE, self.owner.ons_toucher, MSG_CENTER, CENTER_ONS_CAPTURE, self.owner.message);
+                       PlayerScore_Add(self.owner.ons_toucher, SP_ONS_CAPS, 1);
+                       PlayerTeamScore_AddScore(self.owner.ons_toucher, 10);
+               }
+               
+               self.owner.ons_toucher = world;
 
-       // Throw some flaming gibs on damage, more damage = more chance for gib
-       if(random() < damage/220)
-       {
-               sound(self, CH_TRIGGER, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
-               i = random();
-               if(i < 0.3)
-                       ons_throwgib(hitloc + '0 0 20', force * -1, "models/onslaught/gen_gib1.md3", 5, true);
-               else if(i > 0.7)
-                       ons_throwgib(hitloc + '0 0 20', force * -1, "models/onslaught/gen_gib2.md3", 5, true);
-               else
-                       ons_throwgib(hitloc + '0 0 20', force * -1, "models/onslaught/gen_gib3.md3", 5, true);
-       }
-       else
-       {
-               // particles on every hit
-               pointparticles(particleeffectnum("sparks"), hitloc, force * -1, 1);
+               onslaught_updatelinks();
 
-               //sound on every hit
-               if (random() < 0.5)
-                       sound(self, CH_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE, ATTEN_NORM);
-               else
-                       sound(self, CH_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM);
+               // Use targets now (somebody make sure this is in the right place..)
+               oself = self;
+               self = self.owner;
+               activator = self;
+               SUB_UseTargets ();
+               self = oself;
+               
+               self.SendFlags |= CPSF_SETUP;
        }
-
-       //throw some gibs on damage
-       if(random() < damage/200+0.2)
-               if(random() < 0.5)
-                       ons_throwgib(hitloc + '0 0 20', randomvec()*360, "models/onslaught/gen_gib1.md3", 5, false);
+       if(self.owner.model != "models/onslaught/controlpoint_pad2.md3")
+               setmodel_fixsize(self.owner, "models/onslaught/controlpoint_pad2.md3");
+               
+       if(random() < 0.9 - self.health / self.max_health)
+               pointparticles(particleeffectnum("rage"), self.origin + 10 * randomvec(), '0 0 -1', 1);
 }
 
-// update links after a delay
-void onslaught_generator_delayed()
+void ons_ControlPoint_Icon_Spawn(entity cp, entity player)
 {
-       onslaught_updatelinks();
-       // now begin normal thinking
-       self.think = onslaught_generator_think;
-       self.nextthink = time;
-}
+       entity e = spawn();
+       
+       setsize(e, CPICON_MIN, CPICON_MAX);
+       setorigin(e, cp.origin + CPICON_OFFSET);
+       
+       e.classname = "onslaught_controlpoint_icon";
+       e.owner = cp;
+       e.max_health = autocvar_g_onslaught_cp_health;
+       e.health = autocvar_g_onslaught_cp_buildhealth;
+       e.solid = SOLID_NOT;
+       e.takedamage = DAMAGE_AIM;
+       e.bot_attack = true;
+       e.event_damage = ons_ControlPoint_Icon_Damage;
+       e.team = player.team;
+       e.colormap = 1024 + (e.team - 1) * 17;
+       e.count = (e.max_health - e.health) * ONS_CP_THINKRATE / autocvar_g_onslaught_cp_buildtime; // how long it takes to build
+       
+       sound(e, CH_TRIGGER, "onslaught/controlpoint_build.wav", VOL_BASE, ATTEN_NORM);
+       
+       cp.goalentity = e;
+       cp.team = e.team;
+       cp.colormap = e.colormap;
 
-string onslaught_generator_waypointsprite_for_team(entity e, float t)
-{
-       if(t == e.team)
-       {
-               if(e.team == NUM_TEAM_1)
-                       return "ons-gen-red";
-               else if(e.team == NUM_TEAM_2)
-                       return "ons-gen-blue";
-       }
-       if(e.isshielded)
-               return "ons-gen-shielded";
-       if(e.team == NUM_TEAM_1)
-               return "ons-gen-red";
-       else if(e.team == NUM_TEAM_2)
-               return "ons-gen-blue";
-       return "";
-}
+       pointparticles(particleeffectnum(sprintf("%sflag_touch", Static_Team_ColorName_Lower(player.team))), e.origin, '0 0 0', 1);
 
-void onslaught_generator_updatesprite(entity e)
-{
-       string s1, s2, s3;
-       s1 = onslaught_generator_waypointsprite_for_team(e, NUM_TEAM_1);
-       s2 = onslaught_generator_waypointsprite_for_team(e, NUM_TEAM_2);
-       s3 = onslaught_generator_waypointsprite_for_team(e, -1);
-       WaypointSprite_UpdateSprites(e.sprite, s1, s2, s3);
+       WaypointSprite_UpdateBuildFinished(cp.sprite, time + (e.max_health - e.health) / (e.count / ONS_CP_THINKRATE));
+       WaypointSprite_UpdateRule(cp.sprite,cp.team,SPRITERULE_TEAMPLAY);
+       cp.sprite.SendFlags |= 16;
 
-       if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
-       {
-               e.lastteam = e.team + 2;
-               e.lastshielded = e.isshielded;
-               if(e.lastshielded)
-               {
-                       if(e.team == NUM_TEAM_1 || e.team == NUM_TEAM_2)
-                               WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, false));
-                       else
-                               WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
-               }
-               else
-               {
-                       if(e.team == NUM_TEAM_1 || e.team == NUM_TEAM_2)
-                               WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, false));
-                       else
-                               WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
-               }
-               WaypointSprite_Ping(e.sprite);
-       }
+       onslaught_controlpoint_icon_link(e, ons_ControlPoint_Icon_BuildThink);
 }
 
-string onslaught_controlpoint_waypointsprite_for_team(entity e, float t)
+string ons_ControlPoint_Waypoint(entity e)
 {
-       float a;
-       if(t != -1)
+       if(e.team)
        {
-               a = onslaught_controlpoint_attackable(e, t);
-               if(a == 3 || a == 4) // ATTACK/TOUCH THIS ONE NOW
-               {
-                       if(e.team == NUM_TEAM_1)
-                               return "ons-cp-atck-red";
-                       else if(e.team == NUM_TEAM_2)
-                               return "ons-cp-atck-blue";
-                       else
-                               return "ons-cp-atck-neut";
-               }
-               else if(a == -2) // DEFEND THIS ONE NOW
-               {
-                       if(e.team == NUM_TEAM_1)
-                               return "ons-cp-dfnd-red";
-                       else if(e.team == NUM_TEAM_2)
-                               return "ons-cp-dfnd-blue";
-               }
-               else if(e.team == t || a == -1 || a == 1) // own point, or fire at it
-               {
-                       if(e.team == NUM_TEAM_1)
-                               return "ons-cp-red";
-                       else if(e.team == NUM_TEAM_2)
-                               return "ons-cp-blue";
-               }
-               else if(a == 2) // touch it
-                       return "ons-cp-neut";
+               int a = ons_ControlPoint_Attackable(e, e.team);
+               
+               if(a == -2) { return "ons-cp-dfnd"; } // defend now
+               if(a == -1 || a == 1 || a == 2) { return "ons-cp"; } // touch
+               if(a == 3 || a == 4) { return "ons-cp-atck"; } // attack
        }
        else
-       {
-               if(e.team == NUM_TEAM_1)
-                       return "ons-cp-red";
-               else if(e.team == NUM_TEAM_2)
-                       return "ons-cp-blue";
-               else
-                       return "ons-cp-neut";
-       }
+               return "ons-cp";
+
        return "";
 }
 
-void onslaught_controlpoint_updatesprite(entity e)
+void ons_ControlPoint_UpdateSprite(entity e)
 {
-       string s1, s2, s3;
-       s1 = onslaught_controlpoint_waypointsprite_for_team(e, NUM_TEAM_1);
-       s2 = onslaught_controlpoint_waypointsprite_for_team(e, NUM_TEAM_2);
-       s3 = onslaught_controlpoint_waypointsprite_for_team(e, -1);
-       WaypointSprite_UpdateSprites(e.sprite, s1, s2, s3);
+       string s1;
+       s1 = ons_ControlPoint_Waypoint(e);
+       WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
 
-       float sh;
-       sh = !(onslaught_controlpoint_can_be_linked(e, NUM_TEAM_1) || onslaught_controlpoint_can_be_linked(e, NUM_TEAM_2));
+       bool sh;
+       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));
 
        if(e.lastteam != e.team + 2 || e.lastshielded != sh || e.iscaptured != e.lastcaptured)
        {
@@ -818,14 +653,14 @@ void onslaught_controlpoint_updatesprite(entity e)
                }
                if(e.lastshielded)
                {
-                       if(e.team == NUM_TEAM_1 || e.team == NUM_TEAM_2)
+                       if(e.team)
                                WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, 0.5 * colormapPaletteColor(e.team - 1, false));
                        else
                                WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.5 0.5 0.5');
                }
                else
                {
-                       if(e.team == NUM_TEAM_1 || e.team == NUM_TEAM_2)
+                       if(e.team)
                                WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, colormapPaletteColor(e.team - 1, false));
                        else
                                WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_CONTROLPOINT, '0.75 0.75 0.75');
@@ -838,870 +673,1521 @@ void onslaught_controlpoint_updatesprite(entity e)
        }
 }
 
-void onslaught_generator_reset()
+void ons_ControlPoint_Touch()
 {
-       self.team = self.team_saved;
-       self.lasthealth = self.max_health = self.health = autocvar_g_onslaught_gen_health;
-       self.takedamage = DAMAGE_AIM;
-       self.bot_attack = true;
-       self.iscaptured = true;
-       self.islinked = true;
-       self.isshielded = true;
-       self.enemy.solid = SOLID_NOT;
-       self.think = onslaught_generator_delayed;
-       self.nextthink = time + 0.2;
-       setmodel(self, "models/onslaught/generator.md3");
-       setsize(self, '-52 -52 -14', '52 52 75');
-
-       if(!self.noalign)
-       {
-               setorigin(self, self.origin + '0 0 20');
-               droptofloor();
+       entity toucher = other;
+       int attackable;
+       
+       if((toucher.vehicle_flags & VHF_ISVEHICLE) && toucher.owner)
+       if(autocvar_g_onslaught_allow_vehicle_touch)
+               toucher = toucher.owner;
+       else
+               return;
+               
+       if(!IS_PLAYER(toucher)) { return; }
+       if(toucher.frozen) { return; }
+       if(toucher.deadflag != DEAD_NO) { return; }
+       
+       if ( SAME_TEAM(self,toucher) )
+       if ( self.iscaptured )
+       {
+               if(time <= toucher.teleport_antispam)
+                       Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT_ANTISPAM, rint(toucher.teleport_antispam - time));
+               else
+                       Send_Notification(NOTIF_ONE, toucher, MSG_CENTER, CENTER_ONS_TELEPORT);
        }
+               
+       attackable = ons_ControlPoint_Attackable(self, toucher.team);
+       if(attackable != 2 && attackable != 4)
+               return;
+       // we've verified that this player has a legitimate claim to this point,
+       // so start building the captured point icon (which only captures this
+       // point if it successfully builds without being destroyed first)
+       ons_ControlPoint_Icon_Spawn(self, toucher);
+       
+       self.ons_toucher = toucher;
 
-       WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
-       WaypointSprite_UpdateHealth(self.sprite, self.health);
+       onslaught_updatelinks();
 }
 
-/*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
-  Base generator.
-
-  spawnfunc_onslaught_link entities can target this.
+void ons_ControlPoint_Think()
+{
+       self.nextthink = time + ONS_CP_THINKRATE;
+       CSQCMODEL_AUTOUPDATE();
+}
 
-keys:
-"team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
-"targetname" - name that spawnfunc_onslaught_link entities will use to target this.
- */
-void spawnfunc_onslaught_generator()
+void ons_ControlPoint_Reset()
 {
-       if (!g_onslaught)
-       {
-               remove(self);
-               return;
-       }
+       if(self.goalentity)
+               remove(self.goalentity);
 
-       //entity e;
-       precache_model("models/onslaught/generator.md3");
-       precache_model("models/onslaught/generator_shield.md3");
-       precache_model("models/onslaught/generator_dmg1.md3");
-       precache_model("models/onslaught/generator_dmg2.md3");
-       precache_model("models/onslaught/generator_dmg3.md3");
-       precache_model("models/onslaught/generator_dmg4.md3");
-       precache_model("models/onslaught/generator_dmg5.md3");
-       precache_model("models/onslaught/generator_dmg6.md3");
-       precache_model("models/onslaught/generator_dmg7.md3");
-       precache_model("models/onslaught/generator_dmg8.md3");
-       precache_model("models/onslaught/generator_dmg9.md3");
-       precache_model("models/onslaught/generator_dead.md3");
-       precache_model("models/onslaught/shockwave.md3");
-       precache_model("models/onslaught/shockwavetransring.md3");
-       precache_model("models/onslaught/gen_gib1.md3");
-       precache_model("models/onslaught/gen_gib2.md3");
-       precache_model("models/onslaught/gen_gib3.md3");
-       precache_model("models/onslaught/ons_ray.md3");
-       precache_sound("onslaught/generator_decay.wav");
-       precache_sound("weapons/grenade_impact.wav");
-       precache_sound("weapons/rocket_impact.wav");
-       precache_sound("onslaught/generator_underattack.wav");
-       precache_sound("onslaught/shockwave.wav");
-       precache_sound("onslaught/ons_hit1.wav");
-       precache_sound("onslaught/ons_hit2.wav");
-       precache_sound("onslaught/electricity_explode.wav");
-       if (!self.team)
-               objerror("team must be set");
+       self.goalentity = world;
+       self.team = 0;
+       self.colormap = 1024;
+       self.iscaptured = false;
+       self.islinked = false;
+       self.isshielded = true;
+       self.think = ons_ControlPoint_Think;
+       self.ons_toucher = world;
+       self.nextthink = time + ONS_CP_THINKRATE;
+       setmodel_fixsize(self, "models/onslaught/controlpoint_pad.md3");
 
-       if(self.team == NUM_TEAM_1)
-        ons_red_generator = self;
+       WaypointSprite_UpdateMaxHealth(self.sprite, 0);
+       WaypointSprite_UpdateRule(self.sprite,self.team,SPRITERULE_TEAMPLAY);
 
-       if(self.team == NUM_TEAM_2)
-        ons_blue_generator = self;
+       onslaught_updatelinks();
 
-       self.team_saved = self.team;
-       self.colormap = 1024 + (self.team - 1) * 17;
-       self.solid = SOLID_BBOX;
-       self.movetype = MOVETYPE_NONE;
-       self.lasthealth = self.max_health = self.health = autocvar_g_onslaught_gen_health;
-       setmodel(self, "models/onslaught/generator.md3");
-       setsize(self, '-52 -52 -14', '52 52 75');
-       setorigin(self, self.origin);
-       self.takedamage = DAMAGE_AIM;
-       self.bot_attack = true;
-       self.event_damage = onslaught_generator_damage;
-       self.iscaptured = true;
-       self.islinked = true;
-       self.isshielded = true;
-       // helper entity that create fx when generator is damaged
-       onslaught_generator_damage_spawn(self);
-       // spawn shield model which indicates whether this can be damaged
-       self.enemy = spawn();
-       setattachment(self.enemy , self, "");
-       self.enemy.classname = "onslaught_generator_shield";
-       self.enemy.solid = SOLID_NOT;
-       self.enemy.movetype = MOVETYPE_NONE;
-       self.enemy.effects = EF_ADDITIVE;
-       setmodel(self.enemy, "models/onslaught/generator_shield.md3");
-       //setorigin(e, self.origin);
-       self.enemy.colormap = self.colormap;
-       self.enemy.team = self.team;
-       //self.think = onslaught_generator_delayed;
-       //self.nextthink = time + 0.2;
-       InitializeEntity(self, onslaught_generator_delayed, INITPRIO_LAST);
-
-       WaypointSprite_SpawnFixed(string_null, self.origin + '0 0 128', self, sprite, RADARICON_NONE, '0 0 0');
-       WaypointSprite_UpdateRule(self.sprite, NUM_TEAM_2, SPRITERULE_TEAMPLAY);
-       WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
-       WaypointSprite_UpdateHealth(self.sprite, self.health);
+       activator = self;
+       SUB_UseTargets(); // to reset the structures, playerspawns etc.
 
-       waypoint_spawnforitem(self);
+       CSQCMODEL_AUTOUPDATE();
+}
 
+void ons_DelayedControlPoint_Setup(void)
+{
        onslaught_updatelinks();
+       
+       // captureshield setup
+       ons_CaptureShield_Spawn(self, false);
+
+       CSQCMODEL_AUTOINIT();
+}
 
-       self.reset = onslaught_generator_reset;
+void ons_ControlPoint_Setup(entity cp)
+{
+       // declarations
+       self = cp; // for later usage with droptofloor()
+       
+       // main setup
+       cp.ons_worldcpnext = ons_worldcplist; // link control point into ons_worldcplist
+       ons_worldcplist = cp;
+       
+       cp.netname = "Control point";
+       cp.team = 0;
+       cp.solid = SOLID_BBOX;
+       cp.movetype = MOVETYPE_NONE;
+       cp.touch = ons_ControlPoint_Touch;
+       cp.think = ons_ControlPoint_Think;
+       cp.nextthink = time + ONS_CP_THINKRATE;
+       cp.reset = ons_ControlPoint_Reset;
+       cp.colormap = 1024;
+       cp.iscaptured = false;
+       cp.islinked = false;
+       cp.isshielded = true;
+       
+       if(cp.message == "") { cp.message = "a"; }
+
+       // precache - TODO: clean up!
+       precache_model("models/onslaught/controlpoint_pad.md3");
+       precache_model("models/onslaught/controlpoint_pad2.md3");
+       precache_model("models/onslaught/controlpoint_shield.md3");
+       precache_model("models/onslaught/controlpoint_icon.md3");
+       precache_model("models/onslaught/controlpoint_icon_dmg1.md3");
+       precache_model("models/onslaught/controlpoint_icon_dmg2.md3");
+       precache_model("models/onslaught/controlpoint_icon_dmg3.md3");
+       precache_model("models/onslaught/controlpoint_icon_gib1.md3");
+       precache_model("models/onslaught/controlpoint_icon_gib2.md3");
+       precache_model("models/onslaught/controlpoint_icon_gib4.md3");
+       precache_sound("onslaught/controlpoint_build.wav");
+       precache_sound("onslaught/controlpoint_built.wav");
+       precache_sound("weapons/grenade_impact.wav");
+       precache_sound("onslaught/damageblockedbyshield.wav");
+       precache_sound("onslaught/controlpoint_underattack.wav");
+       precache_sound("onslaught/ons_spark1.wav");
+       precache_sound("onslaught/ons_spark2.wav");
+       
+       // appearence
+       setmodel_fixsize(cp, "models/onslaught/controlpoint_pad.md3");
+       
+       // control point placement
+       if((cp.spawnflags & 1) || cp.noalign) // don't drop to floor, just stay at fixed location
+       {
+               cp.noalign = true;
+               cp.movetype = MOVETYPE_NONE;
+       }
+       else // drop to floor, automatically find a platform and set that as spawn origin
+       {
+               setorigin(cp, cp.origin + '0 0 20');
+               cp.noalign = false;
+               self = cp;
+               droptofloor();
+               cp.movetype = MOVETYPE_TOSS;
+       }
+       
+       // waypointsprites
+       WaypointSprite_SpawnFixed(string_null, self.origin + CPGEN_WAYPOINT_OFFSET, self, sprite, RADARICON_NONE, '0 0 0');
+       WaypointSprite_UpdateRule(self.sprite, self.team, SPRITERULE_TEAMPLAY);
+       
+       InitializeEntity(cp, ons_DelayedControlPoint_Setup, INITPRIO_SETLOCATION);
 }
 
-.float waslinked;
-.float cp_bob_spd;
-.vector cp_origin, cp_bob_origin, cp_bob_dmg;
 
-float ons_notification_time_team1;
-float ons_notification_time_team2;
+// =========================
+// Main Generator Functions
+// =========================
 
-void onslaught_controlpoint_icon_damage(entity inflictor, entity attacker, float damage, float deathtype, vector hitloc, vector force)
+string ons_Generator_Waypoint(entity e)
 {
-       entity oself;
-       float nag;
+       if(e.isshielded)
+               return "ons-gen-shielded";
+       return "ons-gen";
+}
 
-       if (damage <= 0)
-               return;
-       if (self.owner.isshielded)
-       {
-               // this is protected by a shield, so ignore the damage
-               if (time > self.pain_finished)
-                       if (IS_PLAYER(attacker))
-                       {
-                               play2(attacker, "onslaught/damageblockedbyshield.wav");
-                               self.pain_finished = time + 1;
-                       }
-               return;
-       }
+void ons_Generator_UpdateSprite(entity e)
+{
+       string s1 = ons_Generator_Waypoint(e);
+       WaypointSprite_UpdateSprites(e.sprite, s1, s1, s1);
 
-       if (IS_PLAYER(attacker))
+       if(e.lastteam != e.team + 2 || e.lastshielded != e.isshielded)
        {
-               nag = false;
-               if(self.team == NUM_TEAM_1)
+               e.lastteam = e.team + 2;
+               e.lastshielded = e.isshielded;
+               if(e.lastshielded)
                {
-                       if(time - ons_notification_time_team1 > 10)
-                       {
-                               nag = true;
-                               ons_notification_time_team1 = time;
-                       }
+                       if(e.team)
+                               WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, 0.5 * colormapPaletteColor(e.team - 1, false));
+                       else
+                               WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.5 0.5 0.5');
                }
-               else if(self.team == NUM_TEAM_2)
+               else
                {
-                       if(time - ons_notification_time_team2 > 10)
-                       {
-                               nag = true;
-                               ons_notification_time_team2 = time;
-                       }
+                       if(e.team)
+                               WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, colormapPaletteColor(e.team - 1, false));
+                       else
+                               WaypointSprite_UpdateTeamRadar(e.sprite, RADARICON_GENERATOR, '0.75 0.75 0.75');
                }
-               else
-                       nag = true;
-
-               if(nag)
-                       play2team(self.team, "onslaught/controlpoint_underattack.wav");
+               WaypointSprite_Ping(e.sprite);
        }
+}
 
-       self.health = self.health - damage;
-       if(self.owner.iscaptured)
-               WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
-       else
-               WaypointSprite_UpdateBuildFinished(self.owner.sprite, time + (self.max_health - self.health) / (self.count / sys_frametime));
-       self.pain_finished = time + 1;
-       self.punchangle = (2 * randomvec() - '1 1 1') * 45;
-       self.cp_bob_dmg_z = (2 * random() - 1) * 15;
-       // colormod flash when shot
-       self.colormod = '2 2 2';
-       // particles on every hit
-       pointparticles(particleeffectnum("sparks"), hitloc, force*-1, 1);
-       //sound on every hit
-       if (random() < 0.5)
-               sound(self, CH_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE+0.3, ATTEN_NORM);
-       else
-               sound(self, CH_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE+0.3, ATTEN_NORM);
+void ons_GeneratorDamage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
+{
+       if(damage <= 0) { return; }
+       if(warmup_stage || gameover) { return; }
+       if(!round_handler_IsRoundStarted()) { return; }
 
-       if (self.health < 0)
+       if (attacker != self)
        {
-               sound(self, CH_TRIGGER, "weapons/grenade_impact.wav", VOL_BASE, ATTEN_NORM);
-               pointparticles(particleeffectnum("rocket_explode"), self.origin, '0 0 0', 1);
+               if (self.isshielded)
                {
-                       string t;
-                       t = Team_ColoredFullName(attacker.team);
-                       bprint(Team_ColoredFullName(self.team), " ", self.message, " control point destroyed by ", t, "\n");
-                       ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 25, "models/onslaught/controlpoint_icon_gib1.md3", 3, false);
-                       ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 45, "models/onslaught/controlpoint_icon_gib2.md3", 3, false);
-                       ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 45, "models/onslaught/controlpoint_icon_gib2.md3", 3, false);
-                       ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 3, false);
-                       ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 3, false);
-                       ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 3, false);
-                       ons_throwgib(self.origin, (2 * randomvec() - '1 1 1') * 75, "models/onslaught/controlpoint_icon_gib4.md3", 3, false);
+                       // this is protected by a shield, so ignore the damage
+                       if (time > self.pain_finished)
+                               if (IS_PLAYER(attacker))
+                               {
+                                       play2(attacker, "onslaught/damageblockedbyshield.wav");
+                                       attacker.typehitsound += 1;
+                                       self.pain_finished = time + 1;
+                               }
+                       return;
                }
-               self.owner.goalentity = world;
-               self.owner.islinked = false;
-               self.owner.iscaptured = false;
-               self.owner.team = 0;
-               self.owner.colormap = 1024;
+               if (time > self.pain_finished)
+               {
+                       self.pain_finished = time + 10;
+                       entity head;
+                       FOR_EACH_REALPLAYER(head) if(SAME_TEAM(head, self)) { Send_Notification(NOTIF_ONE, head, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK); }
+                       play2team(self.team, "onslaught/generator_underattack.wav");
+               }
+       }
+       self.health = self.health - damage;
+       WaypointSprite_UpdateHealth(self.sprite, self.health);
+       // choose an animation frame based on health
+       self.frame = 10 * bound(0, (1 - self.health / self.max_health), 1);
+       // see if the generator is still functional, or dying
+       if (self.health > 0)
+       {
+               self.lasthealth = self.health;
+       }
+       else
+       {
+               if (attacker == self)
+                       Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME_));
+               else
+               {
+                       Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_GENDESTROYED_));
+                       PlayerScore_Add(attacker, SP_SCORE, 100);
+               }
+               self.iscaptured = false;
+               self.islinked = false;
+               self.isshielded = false;
+               self.takedamage = DAMAGE_NO; // can't be hurt anymore
+               self.event_damage = func_null; // won't do anything if hurt
+               self.count = 0; // reset counter
+               self.think = func_null;
+               self.nextthink = 0;
+               //self.think(); // do the first explosion now
 
-               WaypointSprite_UpdateMaxHealth(self.owner.sprite, 0);
+               WaypointSprite_UpdateMaxHealth(self.sprite, 0);
+               WaypointSprite_Ping(self.sprite);
+               //WaypointSprite_Kill(self.sprite); // can't do this yet, code too poor
 
                onslaught_updatelinks();
+       }
 
-               // Use targets now (somebody make sure this is in the right place..)
-               oself = self;
-               self = self.owner;
-               activator = self;
-               SUB_UseTargets ();
-               self = oself;
-
-
-               self.owner.waslinked = self.owner.islinked;
-               if(self.owner.model != "models/onslaught/controlpoint_pad.md3")
-                       setmodel(self.owner, "models/onslaught/controlpoint_pad.md3");
-               //setsize(self, '-32 -32 0', '32 32 8');
+       // Throw some flaming gibs on damage, more damage = more chance for gib
+       if(random() < damage/220)
+       {
+               sound(self, CH_TRIGGER, "weapons/rocket_impact.wav", VOL_BASE, ATTEN_NORM);
+       }
+       else
+       {
+               // particles on every hit
+               pointparticles(particleeffectnum("sparks"), hitloc, force * -1, 1);
 
-               remove(self);
+               //sound on every hit
+               if (random() < 0.5)
+                       sound(self, CH_TRIGGER, "onslaught/ons_hit1.wav", VOL_BASE, ATTEN_NORM);
+               else
+                       sound(self, CH_TRIGGER, "onslaught/ons_hit2.wav", VOL_BASE, ATTEN_NORM);
        }
+
+       self.SendFlags |= GSF_STATUS;
 }
 
-void onslaught_controlpoint_icon_think()
+void ons_GeneratorThink()
 {
-       entity oself;
-       self.nextthink = time + sys_frametime;
-
-       if(autocvar_g_onslaught_cp_proxydecap)
+       entity e;
+       self.nextthink = time + GEN_THINKRATE;
+       if (!gameover)
        {
-        float _enemy_count = 0;
-        float _friendly_count = 0;
-        float _dist;
-        entity _player;
-
-        FOR_EACH_PLAYER(_player)
+        if(!self.isshielded && self.wait < time)
         {
-            if(!_player.deadflag)
+            self.wait = time + 5;
+            FOR_EACH_REALPLAYER(e)
             {
-                _dist = vlen(_player.origin - self.origin);
-                if(_dist < autocvar_g_onslaught_cp_proxydecap_distance)
-                {
-                    if(_player.team == self.team)
-                        ++_friendly_count;
-                    else
-                        ++_enemy_count;
+                               if(SAME_TEAM(e, self))
+                               {
+                                       Send_Notification(NOTIF_ONE, e, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM);
+                    soundto(MSG_ONE, e, CHAN_AUTO, "kh/alarm.wav", VOL_BASE, ATTEN_NONE);    // FIXME: unique sound?
                 }
+                               else
+                                       Send_Notification(NOTIF_ONE, e, MSG_CENTER, APP_TEAM_NUM_4(self.team, CENTER_ONS_NOTSHIELDED_));
             }
         }
+       }
+}
 
-        _friendly_count = _friendly_count * (autocvar_g_onslaught_cp_proxydecap_dps * sys_frametime);
-        _enemy_count = _enemy_count * (autocvar_g_onslaught_cp_proxydecap_dps * sys_frametime);
+void ons_GeneratorReset()
+{
+       self.team = self.team_saved;
+       self.lasthealth = self.max_health = self.health = autocvar_g_onslaught_gen_health;
+       self.takedamage = DAMAGE_AIM;
+       self.bot_attack = true;
+       self.iscaptured = true;
+       self.islinked = true;
+       self.isshielded = true;
+       self.event_damage = ons_GeneratorDamage;
+       self.think = ons_GeneratorThink;
+       self.nextthink = time + GEN_THINKRATE;
+       
+       Net_LinkEntity(self, false, 0, generator_send);
+       
+       self.SendFlags = GSF_SETUP; // just incase
+       self.SendFlags |= GSF_STATUS;
 
-        self.health = bound(0, self.health + (_friendly_count - _enemy_count), self.max_health);
-        if(self.health <= 0)
-        {
-            onslaught_controlpoint_icon_damage(self, self, 1, 0, self.origin, '0 0 0');
-            return;
-        }
-    }
+       WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
+       WaypointSprite_UpdateHealth(self.sprite, self.health);
+       WaypointSprite_UpdateRule(self.sprite,self.team,SPRITERULE_TEAMPLAY);
+       
+       onslaught_updatelinks();
+}
 
-       if (time > self.pain_finished + 5)
+void ons_DelayedGeneratorSetup()
+{
+       // bot waypoints
+       waypoint_spawnforitem_force(self, self.origin);
+       self.nearestwaypointtimeout = 0; // activate waypointing again
+       self.bot_basewaypoint = self.nearestwaypoint;
+
+       // captureshield setup
+       ons_CaptureShield_Spawn(self, true);
+       
+       onslaught_updatelinks();
+       
+       Net_LinkEntity(self, false, 0, generator_send);
+}
+
+
+void onslaught_generator_touch()
+{
+       if ( IS_PLAYER(other) )
+       if ( SAME_TEAM(self,other) )
+       if ( self.iscaptured )
        {
-               if(self.health < self.max_health)
-               {
-                       self.health = self.health + self.count;
-                       if (self.health >= self.max_health)
-                               self.health = self.max_health;
-                       WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
-               }
+               Send_Notification(NOTIF_ONE, other, MSG_CENTER, CENTER_ONS_TELEPORT);
        }
-       if (self.health < self.max_health * 0.25)
-               setmodel(self, "models/onslaught/controlpoint_icon_dmg3.md3");
-       else if (self.health < self.max_health * 0.50)
-               setmodel(self, "models/onslaught/controlpoint_icon_dmg2.md3");
-       else if (self.health < self.max_health * 0.75)
-               setmodel(self, "models/onslaught/controlpoint_icon_dmg1.md3");
-       else if (self.health < self.max_health * 0.90)
-               setmodel(self, "models/onslaught/controlpoint_icon.md3");
-       // colormod flash when shot
-       self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));
+}
 
-       if(self.owner.islinked != self.owner.waslinked)
-       {
-               // unteam the spawnpoint if needed
-               float t;
-               t = self.owner.team;
-               if(!self.owner.islinked)
-                       self.owner.team = 0;
+void ons_GeneratorSetup(entity gen) // called when spawning a generator entity on the map as a spawnfunc
+{
+       // declarations
+       int teamnumber = gen.team;
+       self = gen; // for later usage with droptofloor()
+       
+       // main setup
+       gen.ons_worldgeneratornext = ons_worldgeneratorlist; // link generator into ons_worldgeneratorlist
+       ons_worldgeneratorlist = gen;
+       
+       gen.netname = sprintf("%s generator", Team_ColoredFullName(teamnumber));
+       gen.classname = "onslaught_generator";
+       gen.solid = SOLID_BBOX;
+       gen.team_saved = teamnumber;
+       gen.movetype = MOVETYPE_NONE;
+       gen.lasthealth = gen.max_health = gen.health = autocvar_g_onslaught_gen_health;
+       gen.takedamage = DAMAGE_AIM;
+       gen.bot_attack = true;
+       gen.event_damage = ons_GeneratorDamage;
+       gen.reset = ons_GeneratorReset;
+       gen.think = ons_GeneratorThink;
+       gen.nextthink = time + GEN_THINKRATE;
+       gen.iscaptured = true;
+       gen.islinked = true;
+       gen.isshielded = true;
+       gen.touch = onslaught_generator_touch;
+       
+       // precache - TODO: clean up!
+       precache_model("models/onslaught/generator_shield.md3");
+       precache_model("models/onslaught/gen_gib1.md3");
+       precache_model("models/onslaught/gen_gib2.md3");
+       precache_model("models/onslaught/gen_gib3.md3");
+       precache_sound("onslaught/generator_decay.wav");
+       precache_sound("weapons/grenade_impact.wav");
+       precache_sound("weapons/rocket_impact.wav");
+       precache_sound("onslaught/generator_underattack.wav");
+       precache_sound("onslaught/shockwave.wav");
+       precache_sound("onslaught/ons_hit1.wav");
+       precache_sound("onslaught/ons_hit2.wav");
+       precache_sound("onslaught/generator_underattack.wav");
+       
+       // appearence
+       // model handled by CSQC
+       setsize(gen, GENERATOR_MIN, GENERATOR_MAX);
+       setorigin(gen, (gen.origin + CPGEN_SPAWN_OFFSET));
+       gen.colormap = 1024 + (teamnumber - 1) * 17;
+       
+       // generator placement
+       self = gen;
+       droptofloor();
+       
+       // waypointsprites
+       WaypointSprite_SpawnFixed(string_null, self.origin + CPGEN_WAYPOINT_OFFSET, self, sprite, RADARICON_NONE, '0 0 0');
+       WaypointSprite_UpdateRule(self.sprite, self.team, SPRITERULE_TEAMPLAY);
+       WaypointSprite_UpdateMaxHealth(self.sprite, self.max_health);
+       WaypointSprite_UpdateHealth(self.sprite, self.health);
+       
+       InitializeEntity(gen, ons_DelayedGeneratorSetup, INITPRIO_SETLOCATION);
+}
 
-               oself = self;
-               self = self.owner;
-               activator = self;
-               SUB_UseTargets ();
-               self = oself;
 
-               self.owner.team = t;
+// ===============
+//  Round Handler
+// ===============
 
-               self.owner.waslinked = self.owner.islinked;
+int total_generators;
+void Onslaught_count_generators()
+{
+       entity e;
+       total_generators = redowned = blueowned = yellowowned = pinkowned = 0;
+       for(e = ons_worldgeneratorlist; e; e = e.ons_worldgeneratornext)
+       {
+               ++total_generators;
+               redowned += (e.team == NUM_TEAM_1 && e.health > 0);
+               blueowned += (e.team == NUM_TEAM_2 && e.health > 0);
+               yellowowned += (e.team == NUM_TEAM_3 && e.health > 0);
+               pinkowned += (e.team == NUM_TEAM_4 && e.health > 0);
        }
+}
 
-       if (self.punchangle.x > 0)
+int Onslaught_GetWinnerTeam()
+{
+       int winner_team = 0;
+       if(redowned > 0)
+               winner_team = NUM_TEAM_1;
+       if(blueowned > 0)
        {
-               self.punchangle_x = self.punchangle.x - 60 * sys_frametime;
-               if (self.punchangle.x < 0)
-                       self.punchangle_x = 0;
+               if(winner_team) return 0;
+               winner_team = NUM_TEAM_2;
        }
-       else if (self.punchangle.x < 0)
+       if(yellowowned > 0)
        {
-               self.punchangle_x = self.punchangle.x + 60 * sys_frametime;
-               if (self.punchangle.x > 0)
-                       self.punchangle_x = 0;
+               if(winner_team) return 0;
+               winner_team = NUM_TEAM_3;
        }
-
-       if (self.punchangle.y > 0)
+       if(pinkowned > 0)
        {
-               self.punchangle_y = self.punchangle.y - 60 * sys_frametime;
-               if (self.punchangle.y < 0)
-                       self.punchangle_y = 0;
+               if(winner_team) return 0;
+               winner_team = NUM_TEAM_4;
        }
-       else if (self.punchangle.y < 0)
+       if(winner_team)
+               return winner_team;
+       return -1; // no generators left?
+}
+
+#define ONS_OWNED_GENERATORS() ((redowned > 0) + (blueowned > 0) + (yellowowned > 0) + (pinkowned > 0))
+#define ONS_OWNED_GENERATORS_OK() (ONS_OWNED_GENERATORS() > 1)
+bool Onslaught_CheckWinner()
+{
+       entity e;
+       
+       if ((autocvar_timelimit && time > game_starttime + autocvar_timelimit * 60) || (round_handler_GetEndTime() > 0 && round_handler_GetEndTime() - time <= 0))
        {
-               self.punchangle_y = self.punchangle.y + 60 * sys_frametime;
-               if (self.punchangle.y > 0)
-                       self.punchangle_y = 0;
+               ons_stalemate = true;
+
+               if (!wpforenemy_announced)
+               {
+                       Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT);
+                       sound(world, CH_INFO, "onslaught/generator_decay.wav", VOL_BASE, ATTEN_NONE);
+
+                       wpforenemy_announced = true;
+               }
+
+               entity tmp_entity; // temporary entity
+               float d;
+               for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext) if(time >= tmp_entity.ons_overtime_damagedelay)
+               {
+                       // tmp_entity.max_health / 300 gives 5 minutes of overtime.
+                       // control points reduce the overtime duration.
+                       d = 1;
+                       for(e = ons_worldcplist; e; e = e.ons_worldcpnext)
+                       {
+                               if(DIFF_TEAM(e, tmp_entity))
+                               if(e.islinked)
+                                       d = d + 1;
+                       }
+
+                       if(autocvar_g_campaign && autocvar__campaign_testrun)
+                               d = d * tmp_entity.max_health;
+                       else
+                               d = d * tmp_entity.max_health / max(30, 60 * autocvar_timelimit_suddendeath);
+
+                       Damage(tmp_entity, tmp_entity, tmp_entity, d, DEATH_HURTTRIGGER, tmp_entity.origin, '0 0 0');
+                       
+                       tmp_entity.sprite.SendFlags |= 16;
+
+                       tmp_entity.ons_overtime_damagedelay = time + 1;
+               }
        }
+       else { wpforenemy_announced = false; ons_stalemate = false; }
+
+       Onslaught_count_generators();
+       
+       if(ONS_OWNED_GENERATORS_OK())
+               return 0;
+
+       int winner_team = Onslaught_GetWinnerTeam();
 
-       if (self.punchangle.z > 0)
+       if(winner_team > 0)
        {
-               self.punchangle_z = self.punchangle.z - 60 * sys_frametime;
-               if (self.punchangle.z < 0)
-                       self.punchangle_z = 0;
+               Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM_4(winner_team, CENTER_ROUND_TEAM_WIN_));
+               Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(winner_team, INFO_ROUND_TEAM_WIN_));
+               TeamScore_AddToTeam(winner_team, ST_ONS_CAPS, +1);
        }
-       else if (self.punchangle.z < 0)
+       else if(winner_team == -1)
        {
-               self.punchangle_z = self.punchangle.z + 60 * sys_frametime;
-               if (self.punchangle.z > 0)
-                       self.punchangle_z = 0;
+               Send_Notification(NOTIF_ALL, world, MSG_CENTER, CENTER_ROUND_TIED);
+               Send_Notification(NOTIF_ALL, world, MSG_INFO, INFO_ROUND_TIED);
        }
+       
+       ons_stalemate = false;
 
-       self.angles_x = self.punchangle.x;
-       self.angles_y = self.punchangle.y + self.mangle.y;
-       self.angles_z = self.punchangle.z;
-       self.mangle_y = self.mangle.y + 45 * sys_frametime;
-
-       self.cp_bob_origin_z = 4 * PI * (1 - cos(self.cp_bob_spd));
-       self.cp_bob_spd = self.cp_bob_spd + 1.875 * sys_frametime;
-       if(self.cp_bob_dmg.z > 0)
-               self.cp_bob_dmg_z = self.cp_bob_dmg.z - 3 * sys_frametime;
-       else
-               self.cp_bob_dmg_z = 0;
-       setorigin(self,self.cp_origin + self.cp_bob_origin + self.cp_bob_dmg);
-
-       // damaged fx
-       if(random() < 0.6 - self.health / self.max_health)
+       play2all(sprintf("ctf/%s_capture.wav", Static_Team_ColorName_Lower(winner_team)));
+       
+       round_handler_Init(7, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
+       
+       FOR_EACH_PLAYER(e)
        {
-               pointparticles(particleeffectnum("electricity_sparks"), self.origin + randompos('-10 -10 -20', '10 10 20'), '0 0 0', 1);
+               e.ons_roundlost = true;
+               e.player_blocked = true;
 
-               if(random() > 0.8)
-                       sound(self, CH_PAIN, "onslaught/ons_spark1.wav", VOL_BASE, ATTEN_NORM);
-               else if (random() > 0.5)
-                       sound(self, CH_PAIN, "onslaught/ons_spark2.wav", VOL_BASE, ATTEN_NORM);
+               nades_Clear(e);
        }
+
+       return 1;
 }
 
-void onslaught_controlpoint_icon_buildthink()
+bool Onslaught_CheckPlayers()
 {
-       entity oself;
-       float a;
+       return 1;
+}
 
-       self.nextthink = time + sys_frametime;
+void Onslaught_RoundStart()
+{
+       entity tmp_entity;
+       FOR_EACH_PLAYER(tmp_entity) { tmp_entity.player_blocked = false; }
 
-       // only do this if there is power
-       a = onslaught_controlpoint_can_be_linked(self.owner, self.owner.team);
-       if(!a)
-               return;
+       for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
+               tmp_entity.sprite.SendFlags |= 16;
 
-       self.health = self.health + self.count;
+       for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
+               tmp_entity.sprite.SendFlags |= 16;
+}
 
-       if (self.health >= self.max_health)
-       {
-               self.health = self.max_health;
-               self.count = autocvar_g_onslaught_cp_regen * sys_frametime; // slow repair rate from now on
-               self.think = onslaught_controlpoint_icon_think;
-               sound(self, CH_TRIGGER, "onslaught/controlpoint_built.wav", VOL_BASE, ATTEN_NORM);
-               bprint(Team_ColoredFullName(self.team), " captured ", self.owner.message, " control point\n");
-               self.owner.iscaptured = true;
 
-               WaypointSprite_UpdateMaxHealth(self.owner.sprite, self.max_health);
-               WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
+// ================
+// Bot player logic
+// ================
 
-               onslaught_updatelinks();
+// NOTE: LEGACY CODE, needs to be re-written!
 
-               // Use targets now (somebody make sure this is in the right place..)
-               oself = self;
-               self = self.owner;
-               activator = self;
-               SUB_UseTargets ();
-               self = oself;
-               self.cp_origin = self.origin;
-               self.cp_bob_origin = '0 0 0.1';
-               self.cp_bob_spd = 0;
+void havocbot_goalrating_ons_offenseitems(float ratingscale, vector org, float sradius)
+{
+       entity head;
+       float t, c;
+       int i;
+       bool needarmor = false, needweapons = false;
+
+       // Needs armor/health?
+       if(self.health<100)
+               needarmor = true;
+
+       // Needs weapons?
+       c = 0;
+       for(i = WEP_FIRST; i <= WEP_LAST ; ++i)
+       {
+               // Find weapon
+               if(self.weapons & WepSet_FromWeapon(i))
+               if(++c>=4)
+                       break;
        }
-       self.alpha = self.health / self.max_health;
-       // colormod flash when shot
-       self.colormod = '1 1 1' * (2 - bound(0, (self.pain_finished - time) / 10, 1));
-       if(self.owner.model != "models/onslaught/controlpoint_pad2.md3")
-               setmodel(self.owner, "models/onslaught/controlpoint_pad2.md3");
-       //setsize(self, '-32 -32 0', '32 32 8');
 
-       if(random() < 0.9 - self.health / self.max_health)
-               pointparticles(particleeffectnum("rage"), self.origin + 10 * randomvec(), '0 0 -1', 1);
-}
+       if(c<4)
+               needweapons = true;
 
+       if(!needweapons && !needarmor)
+               return;
 
+       ons_debug(strcat(self.netname, " needs weapons ", ftos(needweapons) , "\n"));
+       ons_debug(strcat(self.netname, " needs armor ", ftos(needarmor) , "\n"));
 
+       // See what is around
+       head = findchainfloat(bot_pickup, true);
+       while (head)
+       {
+               // gather health and armor only
+               if (head.solid)
+               if ( ((head.health || head.armorvalue) && needarmor) || (head.weapons && needweapons ) )
+               if (vlen(head.origin - org) < sradius)
+               {
+                       t = head.bot_pickupevalfunc(self, head);
+                       if (t > 0)
+                               navigation_routerating(head, t * ratingscale, 500);
+               }
+               head = head.chain;
+       }
+}
 
-void onslaught_controlpoint_touch()
+void havocbot_role_ons_setrole(entity bot, int role)
 {
-       entity e;
-       float a;
-       if (!IS_PLAYER(other))
-               return;
-       a = onslaught_controlpoint_attackable(self, other.team);
-       if(a != 2 && a != 4)
-               return;
-       // we've verified that this player has a legitimate claim to this point,
-       // so start building the captured point icon (which only captures this
-       // point if it successfully builds without being destroyed first)
-       self.goalentity = e = spawn();
-       e.classname = "onslaught_controlpoint_icon";
-       e.owner = self;
-       e.max_health = autocvar_g_onslaught_cp_health;
-       e.health = autocvar_g_onslaught_cp_buildhealth;
-       e.solid = SOLID_BBOX;
-       e.movetype = MOVETYPE_NONE;
-       setmodel(e, "models/onslaught/controlpoint_icon.md3");
-       setsize(e, '-32 -32 -32', '32 32 32');
-       setorigin(e, self.origin + '0 0 96');
-       e.takedamage = DAMAGE_AIM;
-       e.bot_attack = true;
-       e.event_damage = onslaught_controlpoint_icon_damage;
-       e.team = other.team;
-       e.colormap = 1024 + (e.team - 1) * 17;
-       e.think = onslaught_controlpoint_icon_buildthink;
-       e.nextthink = time + sys_frametime;
-       e.count = (e.max_health - e.health) * sys_frametime / autocvar_g_onslaught_cp_buildtime; // how long it takes to build
-       sound(e, CH_TRIGGER, "onslaught/controlpoint_build.wav", VOL_BASE, ATTEN_NORM);
-       self.team = e.team;
-       self.colormap = e.colormap;
-       WaypointSprite_UpdateBuildFinished(self.sprite, time + (e.max_health - e.health) / (e.count / sys_frametime));
-       onslaught_updatelinks();
+       ons_debug(strcat(bot.netname," switched to "));
+       switch(role)
+       {
+               case HAVOCBOT_ONS_ROLE_DEFENSE:
+                       ons_debug("defense");
+                       bot.havocbot_role = havocbot_role_ons_defense;
+                       bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE;
+                       bot.havocbot_role_timeout = 0;
+                       break;
+               case HAVOCBOT_ONS_ROLE_ASSISTANT:
+                       ons_debug("assistant");
+                       bot.havocbot_role = havocbot_role_ons_assistant;
+                       bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT;
+                       bot.havocbot_role_timeout = 0;
+                       break;
+               case HAVOCBOT_ONS_ROLE_OFFENSE:
+                       ons_debug("offense");
+                       bot.havocbot_role = havocbot_role_ons_offense;
+                       bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE;
+                       bot.havocbot_role_timeout = 0;
+                       break;
+       }
+       ons_debug("\n");
 }
 
-void onslaught_controlpoint_think()
+int havocbot_ons_teamcount(entity bot, int role)
 {
-       self.nextthink = time;
-       CSQCMODEL_AUTOUPDATE();
+       int c = 0;
+       entity head;
+
+       FOR_EACH_PLAYER(head)
+       if(SAME_TEAM(head, self))
+       if(head.havocbot_role_flags & role)
+               ++c;
+
+       return c;
 }
 
-void onslaught_controlpoint_reset()
+void havocbot_goalrating_ons_controlpoints_attack(float ratingscale)
 {
-       if(self.goalentity && self.goalentity != world)
-               remove(self.goalentity);
-       self.goalentity = world;
-       self.team = 0;
-       self.colormap = 1024;
-       self.iscaptured = false;
-       self.islinked = false;
-       self.isshielded = true;
-       self.enemy.solid = SOLID_NOT;
-       self.enemy.colormap = self.colormap;
-       self.think = onslaught_controlpoint_think;
-       self.enemy.think = func_null;
-       self.nextthink = time; // don't like func_null :P
-       setmodel(self, "models/onslaught/controlpoint_pad.md3");
-       //setsize(self, '-32 -32 0', '32 32 8');
+       entity cp, cp1, cp2, best, pl, wp;
+       float radius, bestvalue;
+       int c;
+       bool found;
 
-       WaypointSprite_UpdateMaxHealth(self.sprite, 0);
+       // Filter control points
+       for(cp2 = ons_worldcplist; cp2; cp2 = cp2.ons_worldcpnext)
+       {
+               cp2.wpcost = c = 0;
+               cp2.wpconsidered = false;
 
-       onslaught_updatelinks();
+               if(cp2.isshielded)
+                       continue;
 
-       activator = self;
-       SUB_UseTargets(); // to reset the structures, playerspawns etc.
+               // Ignore owned controlpoints
+               if(!(cp2.isgenneighbor[self.team] || cp2.iscpneighbor[self.team]))
+                       continue;
 
-       CSQCMODEL_AUTOUPDATE();
+               // Count team mates interested in this control point
+               // (easier and cleaner than keeping counters per cp and teams)
+               FOR_EACH_PLAYER(pl)
+               if(SAME_TEAM(pl, self))
+               if(pl.havocbot_role_flags & HAVOCBOT_ONS_ROLE_OFFENSE)
+               if(pl.havocbot_ons_target==cp2)
+                       ++c;
+
+               // NOTE: probably decrease the cost of attackable control points
+               cp2.wpcost = c;
+               cp2.wpconsidered = true;
+       }
+
+       // We'll consider only the best case
+       bestvalue = 99999999999;
+       cp = world;
+       for(cp1 = ons_worldcplist; cp1; cp1 = cp1.ons_worldcpnext)
+       {
+               if (!cp1.wpconsidered)
+                       continue;
+
+               if(cp1.wpcost<bestvalue)
+               {
+                       bestvalue = cp1.wpcost;
+                       cp = cp1;
+                       self.havocbot_ons_target = cp1;
+               }
+       }
+
+       if (!cp)
+               return;
+
+       ons_debug(strcat(self.netname, " chose cp ranked ", ftos(bestvalue), "\n"));
+
+       if(cp.goalentity)
+       {
+               // Should be attacked
+               // Rate waypoints near it
+               found = false;
+               best = world;
+               bestvalue = 99999999999;
+               for(radius=0; radius<1000 && !found; radius+=500)
+               {
+                       for(wp=findradius(cp.origin,radius); wp; wp=wp.chain)
+                       {
+                               if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
+                               if(wp.classname=="waypoint")
+                               if(checkpvs(wp.origin,cp))
+                               {
+                                       found = true;
+                                       if(wp.cnt<bestvalue)
+                                       {
+                                               best = wp;
+                                               bestvalue = wp.cnt;
+                                       }
+                               }
+                       }
+               }
+
+               if(best)
+               {
+                       navigation_routerating(best, ratingscale, 10000);
+                       best.cnt += 1;
+
+                       self.havocbot_attack_time = 0;
+                       if(checkpvs(self.view_ofs,cp))
+                       if(checkpvs(self.view_ofs,best))
+                               self.havocbot_attack_time = time + 2;
+               }
+               else
+               {
+                       navigation_routerating(cp, ratingscale, 10000);
+               }
+               ons_debug(strcat(self.netname, " found an attackable controlpoint at ", vtos(cp.origin) ,"\n"));
+       }
+       else
+       {
+               // Should be touched
+               ons_debug(strcat(self.netname, " found a touchable controlpoint at ", vtos(cp.origin) ,"\n"));
+               found = false;
+
+               // Look for auto generated waypoint
+               if (!bot_waypoints_for_items)
+               for (wp = findradius(cp.origin,100); wp; wp = wp.chain)
+               {
+                       if(wp.classname=="waypoint")
+                       {
+                               navigation_routerating(wp, ratingscale, 10000);
+                               found = true;
+                       }
+               }
+
+               // Nothing found, rate the controlpoint itself
+               if (!found)
+                       navigation_routerating(cp, ratingscale, 10000);
+       }
 }
 
-/*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
-  Control point. Be sure to give this enough clearance so that the shootable part has room to exist
+bool havocbot_goalrating_ons_generator_attack(float ratingscale)
+{
+       entity g, wp, bestwp;
+       bool found;
+       int best;
 
-  This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
+       for(g = ons_worldgeneratorlist; g; g = g.ons_worldgeneratornext)
+       {
+               if(SAME_TEAM(g, self) || g.isshielded)
+                       continue;
 
-keys:
-"targetname" - name that spawnfunc_onslaught_link entities will use to target this.
-"target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
-"message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
- */
+               // Should be attacked
+               // Rate waypoints near it
+               found = false;
+               bestwp = world;
+               best = 99999999999;
 
-void spawnfunc_onslaught_controlpoint()
+               for(wp=findradius(g.origin,400); wp; wp=wp.chain)
+               {
+                       if(wp.classname=="waypoint")
+                       if(checkpvs(wp.origin,g))
+                       {
+                               found = true;
+                               if(wp.cnt<best)
+                               {
+                                       bestwp = wp;
+                                       best = wp.cnt;
+                               }
+                       }
+               }
+
+               if(bestwp)
+               {
+                       ons_debug("waypoints found around generator\n");
+                       navigation_routerating(bestwp, ratingscale, 10000);
+                       bestwp.cnt += 1;
+
+                       self.havocbot_attack_time = 0;
+                       if(checkpvs(self.view_ofs,g))
+                       if(checkpvs(self.view_ofs,bestwp))
+                               self.havocbot_attack_time = time + 5;
+
+                       return true;
+               }
+               else
+               {
+                       ons_debug("generator found without waypoints around\n");
+                       // if there aren't waypoints near the generator go straight to it
+                       navigation_routerating(g, ratingscale, 10000);
+                       self.havocbot_attack_time = 0;
+                       return true;
+               }
+       }
+       return false;
+}
+
+void havocbot_role_ons_offense()
 {
-       //entity e;
-       if (!g_onslaught)
+       if(self.deadflag != DEAD_NO)
        {
-               remove(self);
+               self.havocbot_attack_time = 0;
+               havocbot_ons_reset_role(self);
                return;
        }
-       precache_model("models/onslaught/controlpoint_pad.md3");
-       precache_model("models/onslaught/controlpoint_pad2.md3");
-       precache_model("models/onslaught/controlpoint_shield.md3");
-       precache_model("models/onslaught/controlpoint_icon.md3");
-       precache_model("models/onslaught/controlpoint_icon_dmg1.md3");
-       precache_model("models/onslaught/controlpoint_icon_dmg2.md3");
-       precache_model("models/onslaught/controlpoint_icon_dmg3.md3");
-       precache_model("models/onslaught/controlpoint_icon_gib1.md3");
-       precache_model("models/onslaught/controlpoint_icon_gib2.md3");
-       precache_model("models/onslaught/controlpoint_icon_gib4.md3");
-       precache_sound("onslaught/controlpoint_build.wav");
-       precache_sound("onslaught/controlpoint_built.wav");
-       precache_sound("weapons/grenade_impact.wav");
-       precache_sound("onslaught/damageblockedbyshield.wav");
-       precache_sound("onslaught/controlpoint_underattack.wav");
-       precache_sound("onslaught/ons_spark1.wav");
-       precache_sound("onslaught/ons_spark2.wav");
 
-       self.solid = SOLID_BBOX;
-       self.movetype = MOVETYPE_NONE;
-       setmodel(self, "models/onslaught/controlpoint_pad.md3");
-       //setsize(self, '-32 -32 0', '32 32 8');
-       if(!self.noalign)
+       // Set the role timeout if necessary
+       if (!self.havocbot_role_timeout)
+               self.havocbot_role_timeout = time + 120;
+
+       if (time > self.havocbot_role_timeout)
        {
-               setorigin(self, self.origin + '0 0 20');
-               droptofloor();
+               havocbot_ons_reset_role(self);
+               return;
        }
-       self.touch = onslaught_controlpoint_touch;
-       self.team = 0;
-       self.colormap = 1024;
-       self.iscaptured = false;
-       self.islinked = false;
-       self.isshielded = true;
 
-       // spawn shield model which indicates whether this can be damaged
-       self.enemy = spawn();
-       self.enemy.classname = "onslaught_controlpoint_shield";
-       self.enemy.solid = SOLID_NOT;
-       self.enemy.movetype = MOVETYPE_NONE;
-       self.enemy.effects = EF_ADDITIVE;
-       setmodel(self.enemy , "models/onslaught/controlpoint_shield.md3");
+       if(self.havocbot_attack_time>time)
+               return;
+
+       if (self.bot_strategytime < time)
+       {
+               navigation_goalrating_start();
+               havocbot_goalrating_enemyplayers(20000, self.origin, 650);
+               if(!havocbot_goalrating_ons_generator_attack(20000))
+                       havocbot_goalrating_ons_controlpoints_attack(20000);
+               havocbot_goalrating_ons_offenseitems(10000, self.origin, 10000);
+               navigation_goalrating_end();
+
+               self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
+       }
+}
+
+void havocbot_role_ons_assistant()
+{
+       havocbot_ons_reset_role(self);
+}
+
+void havocbot_role_ons_defense()
+{
+       havocbot_ons_reset_role(self);
+}
 
-       setattachment(self.enemy , self, "");
-       //setsize(e, '-32 -32 0', '32 32 128');
+void havocbot_ons_reset_role(entity bot)
+{
+       entity head;
+       int c = 0;
 
-       //setorigin(e, self.origin);
-       self.enemy.colormap = self.colormap;
+       if(self.deadflag != DEAD_NO)
+               return;
 
-       waypoint_spawnforitem(self);
+       bot.havocbot_ons_target = world;
 
-       self.think = onslaught_controlpoint_think;
-       self.nextthink = time;
+       // TODO: Defend control points or generator if necessary
 
-       WaypointSprite_SpawnFixed(string_null, self.origin + '0 0 128', self, sprite, RADARICON_NONE, '0 0 0');
-       WaypointSprite_UpdateRule(self.sprite, NUM_TEAM_2, SPRITERULE_TEAMPLAY);
+       // if there is only me on the team switch to offense
+       c = 0;
+       FOR_EACH_PLAYER(head)
+       if(SAME_TEAM(head, self))
+               ++c;
 
-       onslaught_updatelinks();
+       if(c==1)
+       {
+               havocbot_role_ons_setrole(bot, HAVOCBOT_ONS_ROLE_OFFENSE);
+               return;
+       }
 
-       self.reset = onslaught_controlpoint_reset;
+       havocbot_role_ons_setrole(bot, HAVOCBOT_ONS_ROLE_OFFENSE);
+}
 
-       CSQCMODEL_AUTOINIT();
+
+/*
+ * Find control point or generator owned by the same team self which is nearest to pos
+ * if max_dist is positive, only control points within this range will be considered
+ */
+entity ons_Nearest_ControlPoint(vector pos, float max_dist)
+{
+       entity tmp_entity, closest_target = world;
+       tmp_entity = findchain(classname, "onslaught_controlpoint");
+       while(tmp_entity)
+       {
+               if(SAME_TEAM(tmp_entity, self))
+               if(tmp_entity.iscaptured)
+               if(max_dist <= 0 || vlen(tmp_entity.origin - pos) <= max_dist)
+               if(vlen(tmp_entity.origin - pos) <= vlen(closest_target.origin - pos) || closest_target == world)
+                       closest_target = tmp_entity;
+               tmp_entity = tmp_entity.chain;
+       }
+       tmp_entity = findchain(classname, "onslaught_generator");
+       while(tmp_entity)
+       {
+               if(SAME_TEAM(tmp_entity, self))
+               if(max_dist <= 0 || vlen(tmp_entity.origin - pos) < max_dist)
+               if(vlen(tmp_entity.origin - pos) <= vlen(closest_target.origin - pos) || closest_target == world)
+                       closest_target = tmp_entity;
+               tmp_entity = tmp_entity.chain;
+       }
+       
+       return closest_target;
 }
 
-float onslaught_link_send(entity to, float sendflags)
+/*
+ * Find control point or generator owned by the same team self which is nearest to pos
+ * if max_dist is positive, only control points within this range will be considered
+ * This function only check distances on the XY plane, disregarding Z
+ */
+entity ons_Nearest_ControlPoint_2D(vector pos, float max_dist)
 {
-       WriteByte(MSG_ENTITY, ENT_CLIENT_RADARLINK);
-       WriteByte(MSG_ENTITY, sendflags);
-       if(sendflags & 1)
+       entity tmp_entity, closest_target = world;
+       vector delta;
+       float smallest_distance = 0, distance;
+       
+       tmp_entity = findchain(classname, "onslaught_controlpoint");
+       while(tmp_entity)
+       {
+               delta = tmp_entity.origin - pos;
+               delta_z = 0;
+               distance = vlen(delta);
+               
+               if(SAME_TEAM(tmp_entity, self))
+               if(tmp_entity.iscaptured)
+               if(max_dist <= 0 || distance <= max_dist)
+               if(closest_target == world || distance <= smallest_distance )
+               {
+                       closest_target = tmp_entity;
+                       smallest_distance = distance;
+               }
+               
+               tmp_entity = tmp_entity.chain;
+       }
+       tmp_entity = findchain(classname, "onslaught_generator");
+       while(tmp_entity)
+       {
+               delta = tmp_entity.origin - pos;
+               delta_z = 0;
+               distance = vlen(delta);
+               
+               if(SAME_TEAM(tmp_entity, self))
+               if(max_dist <= 0 || distance <= max_dist)
+               if(closest_target == world || distance <= smallest_distance )
+               {
+                       closest_target = tmp_entity;
+                       smallest_distance = distance;
+               }
+               
+               tmp_entity = tmp_entity.chain;
+       }
+       
+       return closest_target;
+}
+/**
+ * find the number of control points and generators in the same team as self
+ */
+int ons_Count_SelfControlPoints()
+{
+       entity tmp_entity;
+       tmp_entity = findchain(classname, "onslaught_controlpoint");
+       int n = 0;
+       while(tmp_entity)
        {
-               WriteCoord(MSG_ENTITY, self.goalentity.origin.x);
-               WriteCoord(MSG_ENTITY, self.goalentity.origin.y);
-               WriteCoord(MSG_ENTITY, self.goalentity.origin.z);
+               if(SAME_TEAM(tmp_entity, self))
+               if(tmp_entity.iscaptured)
+                       n++;
+               tmp_entity = tmp_entity.chain;
        }
-       if(sendflags & 2)
+       tmp_entity = findchain(classname, "onslaught_generator");
+       while(tmp_entity)
        {
-               WriteCoord(MSG_ENTITY, self.enemy.origin.x);
-               WriteCoord(MSG_ENTITY, self.enemy.origin.y);
-               WriteCoord(MSG_ENTITY, self.enemy.origin.z);
+               if(SAME_TEAM(tmp_entity, self))
+                       n++;
+               tmp_entity = tmp_entity.chain;
        }
-       if(sendflags & 4)
+       return n;
+}
+
+/**
+ * Teleport player to a random position near tele_target
+ * if tele_effects is true, teleport sound+particles are created
+ * return false on failure
+ */
+bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effects)
+{
+       if ( !tele_target )
+               return false;
+       
+       int i;
+       vector loc;
+       float theta;
+       for(i = 0; i < 16; ++i)
+       {
+               theta = random() * 2 * M_PI;
+               loc_y = sin(theta);
+               loc_x = cos(theta);
+               loc_z = 0;
+               loc *= random() * range;
+               
+               loc += tele_target.origin + '0 0 128';
+               
+               tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, player);
+               if(trace_fraction == 1.0 && !trace_startsolid)
+               {
+                       traceline(tele_target.origin, loc, MOVE_NOMONSTERS, tele_target); // double check to make sure we're not spawning outside the world
+                       if(trace_fraction == 1.0 && !trace_startsolid)
+                       {
+                               if ( tele_effects )
+                               {
+                                       pointparticles(particleeffectnum("teleport"), player.origin, '0 0 0', 1);
+                                       sound (player, CH_TRIGGER, "misc/teleport.wav", VOL_BASE, ATTEN_NORM);
+                               }
+                               setorigin(player, loc);
+                               player.angles = '0 1 0' * ( theta * RAD2DEG + 180 );
+                               makevectors(player.angles);
+                               player.fixangle = true;
+                               player.teleport_antispam = time + autocvar_g_onslaught_teleport_wait;
+
+                               if ( tele_effects )
+                                       pointparticles(particleeffectnum("teleport"), player.origin + v_forward * 32, '0 0 0', 1);
+                               return true;
+                       }
+               }
+       }
+       
+       return false;
+}
+
+// ==============
+// Hook Functions
+// ==============
+
+MUTATOR_HOOKFUNCTION(ons_ResetMap)
+{
+       FOR_EACH_PLAYER(self)
        {
-               WriteByte(MSG_ENTITY, self.clientcolors); // which is goalentity's color + enemy's color * 16
+               self.ons_roundlost = false;
+               self.ons_deathloc = '0 0 0';
+               PutClientInServer();
        }
-       return true;
+       return false;
 }
 
-void onslaught_link_checkupdate()
+MUTATOR_HOOKFUNCTION(ons_RemovePlayer)
 {
-       // TODO check if the two sides have moved (currently they won't move anyway)
-       float redpower, bluepower;
+       self.ons_deathloc = '0 0 0';
+       return false;
+}
 
-       redpower = bluepower = 0;
-       if(self.goalentity.islinked)
+MUTATOR_HOOKFUNCTION(ons_PlayerSpawn)
+{
+       if(!round_handler_IsRoundStarted())
+       {
+               self.player_blocked = true;
+               return false;
+       }
+       
+       entity l;
+       for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
        {
-               if(self.goalentity.team == NUM_TEAM_1)
-                       redpower = 1;
-               else if(self.goalentity.team == NUM_TEAM_2)
-                       bluepower = 1;
+               l.sprite.SendFlags |= 16;
        }
-       if(self.enemy.islinked)
+       for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
        {
-               if(self.enemy.team == NUM_TEAM_1)
-                       redpower = 2;
-               else if(self.enemy.team == NUM_TEAM_2)
-                       bluepower = 2;
+               l.sprite.SendFlags |= 16;
        }
 
-       float cc;
-       if(redpower == 1 && bluepower == 2)
-               cc = (NUM_TEAM_1 - 1) * 0x01 + (NUM_TEAM_2 - 1) * 0x10;
-       else if(redpower == 2 && bluepower == 1)
-               cc = (NUM_TEAM_1 - 1) * 0x10 + (NUM_TEAM_2 - 1) * 0x01;
-       else if(redpower)
-               cc = (NUM_TEAM_1 - 1) * 0x11;
-       else if(bluepower)
-               cc = (NUM_TEAM_2 - 1) * 0x11;
-       else
-               cc = 0;
+       if(ons_stalemate) { Send_Notification(NOTIF_ONE, self, MSG_CENTER, CENTER_OVERTIME_CONTROLPOINT); }
 
-       //print(etos(self), " rp=", ftos(redpower), " bp=", ftos(bluepower), " ");
-       //print("cc=", ftos(cc), "\n");
+       if ( autocvar_g_onslaught_spawn_choose )
+       if ( self.ons_spawn_by )
+       if ( ons_Teleport(self,self.ons_spawn_by,autocvar_g_onslaught_teleport_radius,false) )
+       {
+               self.ons_spawn_by = world;
+               return false;
+       }
+       
+       if(autocvar_g_onslaught_spawn_at_controlpoints)
+       if(random() <= autocvar_g_onslaught_spawn_at_controlpoints_chance)
+       {
+               float random_target = autocvar_g_onslaught_spawn_at_controlpoints_random;
+               entity tmp_entity, closest_target = world;
+               vector spawn_loc = self.ons_deathloc;
+               
+               // new joining player or round reset, don't bother checking
+               if(spawn_loc == '0 0 0') { return false; }
 
-       if(cc != self.clientcolors)
+               if(random_target) { RandomSelection_Init(); }
+
+               for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
+               {
+                       if(SAME_TEAM(tmp_entity, self))
+                       if(random_target)
+                               RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
+                       else if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world)
+                               closest_target = tmp_entity;
+               }
+               
+               if(random_target) { closest_target = RandomSelection_chosen_ent; }
+               
+               if(closest_target)
+               {
+                       float i;
+                       vector loc;
+                       for(i = 0; i < 10; ++i)
+                       {
+                               loc = closest_target.origin + '0 0 96';
+                               loc += ('0 1 0' * random()) * 128;
+                               tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, self);
+                               if(trace_fraction == 1.0 && !trace_startsolid)
+                               {
+                                       traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
+                                       if(trace_fraction == 1.0 && !trace_startsolid)
+                                       {
+                                               setorigin(self, loc);
+                                               self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
+                                               return false;
+                                       }
+                               }
+                       }
+               }
+       }
+       
+       if(autocvar_g_onslaught_spawn_at_generator)
+       if(random() <= autocvar_g_onslaught_spawn_at_generator_chance)
        {
-               self.clientcolors = cc;
-               self.SendFlags |= 4;
+               float random_target = autocvar_g_onslaught_spawn_at_generator_random;
+               entity tmp_entity, closest_target = world;
+               vector spawn_loc = self.ons_deathloc;
+               
+               // new joining player or round reset, don't bother checking
+               if(spawn_loc == '0 0 0') { return false; }
+               
+               if(random_target) { RandomSelection_Init(); }
+
+               for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
+               {
+                       if(random_target)
+                               RandomSelection_Add(tmp_entity, 0, string_null, 1, 1);
+                       else
+                       {
+                               if(SAME_TEAM(tmp_entity, self))
+                               if(vlen(tmp_entity.origin - spawn_loc) <= vlen(closest_target.origin - spawn_loc) || closest_target == world)
+                                       closest_target = tmp_entity;
+                       }
+               }
+               
+               if(random_target) { closest_target = RandomSelection_chosen_ent; }
+               
+               if(closest_target)
+               {
+                       float i;
+                       vector loc;
+                       for(i = 0; i < 10; ++i)
+                       {
+                               loc = closest_target.origin + '0 0 128';
+                               loc += ('0 1 0' * random()) * 256;
+                               tracebox(loc, PL_MIN, PL_MAX, loc, MOVE_NORMAL, self);
+                               if(trace_fraction == 1.0 && !trace_startsolid)
+                               {
+                                       traceline(closest_target.origin, loc, MOVE_NOMONSTERS, closest_target); // double check to make sure we're not spawning outside the world
+                                       if(trace_fraction == 1.0 && !trace_startsolid)
+                                       {
+                                               setorigin(self, loc);
+                                               self.angles = normalize(loc - closest_target.origin) * RAD2DEG;
+                                               return false;
+                                       }
+                               }
+                       }
+               }
        }
 
-       self.nextthink = time;
+    return false;
 }
 
-void onslaught_link_delayed()
+MUTATOR_HOOKFUNCTION(ons_PlayerDies)
 {
-       self.goalentity = find(world, targetname, self.target);
-       self.enemy = find(world, targetname, self.target2);
-       if (!self.goalentity)
-               objerror("can not find target\n");
-       if (!self.enemy)
-               objerror("can not find target2\n");
-       dprint(etos(self.goalentity), " linked with ", etos(self.enemy), "\n");
-       self.SendFlags |= 3;
-       self.think = onslaught_link_checkupdate;
-       self.nextthink = time;
+       frag_target.ons_deathloc = frag_target.origin;
+       entity l;
+       for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
+       {
+               l.sprite.SendFlags |= 16;
+       }
+       for(l = ons_worldcplist; l; l = l.ons_worldcpnext)
+       {
+               l.sprite.SendFlags |= 16;
+       }
+       
+       if ( autocvar_g_onslaught_spawn_choose )
+       if ( ons_Count_SelfControlPoints() > 1 )
+               stuffcmd(self, "qc_cmd_cl hud clickradar\n");
+       
+       return false;
 }
 
-/*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
-  Link between control points.
+MUTATOR_HOOKFUNCTION(ons_MonsterThink)
+{
+       entity e = find(world, targetname, self.target);
+       if (e != world)
+               self.team = e.team;
 
-  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.
+       return false;
+}
 
-keys:
-"target" - first control point.
-"target2" - second control point.
- */
-void spawnfunc_onslaught_link()
+void ons_MonsterSpawn_Delayed()
 {
-       if (!g_onslaught)
+       entity e, own = self.owner;
+       
+       if(!own) { remove(self); return; }
+       
+       if(own.targetname)
        {
-               remove(self);
-               return;
+               e = find(world, target, own.targetname);
+               if(e != world)
+               {
+                       own.team = e.team;
+                       
+                       activator = e;
+                       own.use();
+               }
        }
-       if (self.target == "" || self.target2 == "")
-               objerror("target and target2 must be set\n");
-       InitializeEntity(self, onslaught_link_delayed, INITPRIO_FINDTARGET);
-       Net_LinkEntity(self, false, 0, onslaught_link_send);
+       
+       remove(self);
 }
 
-MUTATOR_HOOKFUNCTION(ons_BuildMutatorsString)
+MUTATOR_HOOKFUNCTION(ons_MonsterSpawn)
 {
-       ret_string = strcat(ret_string, ":ONS");
-       return 0;
+       entity e = spawn();
+       e.owner = self;
+       InitializeEntity(e, ons_MonsterSpawn_Delayed, INITPRIO_FINDTARGET);
+
+       return false;
 }
 
-MUTATOR_HOOKFUNCTION(ons_BuildMutatorsPrettyString)
+void ons_TurretSpawn_Delayed()
 {
-       ret_string = strcat(ret_string, ", Onslaught");
-       return 0;
+       entity e, own = self.owner;
+
+       if(!own) { remove(self); return; }
+
+       if(own.targetname)
+       {
+               e = find(world, target, own.targetname);
+               if(e != world)
+               {
+                       own.team = e.team;
+                       own.active = ACTIVE_NOT;
+                       
+                       activator = e;
+                       own.use();
+               }
+       }
+
+       remove(self);
 }
 
-MUTATOR_HOOKFUNCTION(ons_Spawn_Score)
+MUTATOR_HOOKFUNCTION(ons_TurretSpawn)
 {
+       entity e = spawn();
+       e.owner = self;
+       InitializeEntity(e, ons_TurretSpawn_Delayed, INITPRIO_FINDTARGET);
 
-    /*
-    float _neer_home = (random() > 0.5 ? true : false);
+       return false;
+}
 
-       RandomSelection_Init();
+MUTATOR_HOOKFUNCTION(ons_BotRoles)
+{
+       havocbot_ons_reset_role(self);
+       return true;
+}
 
-       if(self.team == NUM_TEAM_1)
-        RandomSelection_Add(ons_red_generator, 0, string_null, 1, 1);
+MUTATOR_HOOKFUNCTION(ons_GetTeamCount)
+{
+       // onslaught is special
+       entity tmp_entity;
+       for(tmp_entity = ons_worldgeneratorlist; tmp_entity; tmp_entity = tmp_entity.ons_worldgeneratornext)
+       {
+               switch(tmp_entity.team)
+               {
+                       case NUM_TEAM_1: c1 = 0; break;
+                       case NUM_TEAM_2: c2 = 0; break;
+                       case NUM_TEAM_3: c3 = 0; break;
+                       case NUM_TEAM_4: c4 = 0; break;
+               }
+       }
 
-       if(self.team == NUM_TEAM_2)
-        RandomSelection_Add(ons_blue_generator, 0, string_null, 1, 1);
+       return true;
+}
 
-       entity _cp = findchain(classname, "onslaught_controlpoint"):
-       while _cp;
-       {
-           if(_cp.team == self.team)
-            RandomSelection_Add(_cp, 0, string_null, 1, 1);
+MUTATOR_HOOKFUNCTION(ons_SpectateCopy)
+{
+       self.ons_roundlost = other.ons_roundlost; // make spectators see it too
+       return false;
+}
 
-               _cp = _cp.chain;
+MUTATOR_HOOKFUNCTION(ons_SV_ParseClientCommand)
+{
+       if(MUTATOR_RETURNVALUE) // command was already handled?
+               return false;
+
+       if ( cmd_name == "ons_spawn" )
+       {
+               vector pos = self.origin;
+               if(cmd_argc > 1)
+                       pos_x = stof(argv(1));
+               if(cmd_argc > 2)
+                       pos_y = stof(argv(2));
+               if(cmd_argc > 3)
+                       pos_z = stof(argv(3));
+               
+               if ( IS_PLAYER(self) )
+               {
+                       if ( !self.frozen )
+                       {
+                               entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
+                               
+                               if ( !source_point && self.health > 0 )
+                               {
+                                       sprint(self, "\nYou need to be next to a control point\n");
+                                       return 1;
+                               }
+                               
+                               
+                               entity closest_target = ons_Nearest_ControlPoint_2D(pos, autocvar_g_onslaught_click_radius);
+                       
+                               if ( closest_target == world )
+                               {
+                                       sprint(self, "\nNo control point found\n");
+                                       return 1;
+                               }
+                               
+                               if ( self.health <= 0 )
+                               {
+                                       self.ons_spawn_by = closest_target;
+                                       self.respawn_flags = self.respawn_flags | RESPAWN_FORCE;
+                               }
+                               else
+                               {
+                                       if ( source_point == closest_target )
+                                       {
+                                               sprint(self, "\nTeleporting to the same point\n");
+                                               return 1;
+                                       }
+                                       
+                                       if ( !ons_Teleport(self,closest_target,autocvar_g_onslaught_teleport_radius,true) )
+                                               sprint(self, "\nUnable to teleport there\n");
+                               }
+                               
+                               return 1;
+                       }
+                       
+                       sprint(self, "\nNo teleportation for you\n");
+               }
+               
+               return 1;
        }
+       return 0;
+}
 
-       if(RandomSelection_chosen_ent)
+MUTATOR_HOOKFUNCTION(ons_PlayerUseKey)
+{
+       if(MUTATOR_RETURNVALUE || gameover) { return false; }
+       
+       if((time > self.teleport_antispam) && (self.deadflag == DEAD_NO) && !self.vehicle)
        {
-               self.tur_head = RandomSelection_chosen_ent;
-               spawn_score_x += SPAWN_PRIO_NEAR_TEAMMATE_FOUND;
+               entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
+               if ( source_point )
+               {
+                       stuffcmd(self, "qc_cmd_cl hud clickradar\n");
+                       return true;
+               }
        }
-       else if(self.team == spawn_spot.team)
-               spawn_score_x += SPAWN_PRIO_NEAR_TEAMMATE_SAMETEAM; // prefer same team, if we can't find a spawn near teammate
+       
+       return false;
+}
 
-    */
+// ==========
+// Spawnfuncs
+// ==========
 
-       return 0;
-}
+/*QUAKED spawnfunc_onslaught_link (0 .5 .8) (-16 -16 -16) (16 16 16)
+  Link between control points.
 
-MUTATOR_HOOKFUNCTION(ons_PlayerSpawn)
+  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.
+
+keys:
+"target" - first control point.
+"target2" - second control point.
+ */
+void spawnfunc_onslaught_link()
 {
-    if(!autocvar_g_onslaught_spawn_at_controlpoints)
-        return 0;
+       if(!g_onslaught) { remove(self); return; }
+
+       if (self.target == "" || self.target2 == "")
+               objerror("target and target2 must be set\n");
 
-    if(random() < 0.5)  // 50/50 chane to use default spawnsystem.
-        return 0;
+       self.ons_worldlinknext = ons_worldlinklist; // link into ons_worldlinklist
+       ons_worldlinklist = self;
 
-    float _close_to_home = ((random() > 0.5) ? true : false);
-    entity _best = world, _trg_gen = world;
-    float _score, _best_score = MAX_SHOT_DISTANCE;
+       InitializeEntity(self, ons_DelayedLinkSetup, INITPRIO_FINDTARGET);
+       Net_LinkEntity(self, false, 0, ons_Link_Send);
+}
 
-       RandomSelection_Init();
+/*QUAKED spawnfunc_onslaught_controlpoint (0 .5 .8) (-32 -32 0) (32 32 128)
+  Control point. Be sure to give this enough clearance so that the shootable part has room to exist
 
-       if(self.team == NUM_TEAM_1)
-       {
-           if(!_close_to_home)
-            _trg_gen = ons_blue_generator;
-        else
-            _trg_gen  = ons_red_generator;
-       }
+  This should link to an spawnfunc_onslaught_controlpoint entity or spawnfunc_onslaught_generator entity.
 
-       if(self.team == NUM_TEAM_2)
-       {
-           if(_close_to_home)
-            _trg_gen = ons_blue_generator;
-        else
-            _trg_gen  = ons_red_generator;
-       }
+keys:
+"targetname" - name that spawnfunc_onslaught_link entities will use to target this.
+"target" - target any entities that are tied to this control point, such as vehicles and buildable structure entities.
+"message" - name of this control point (should reflect the location in the map, such as "center bridge", "north tower", etc)
+ */
 
-       entity _cp = findchain(classname, "onslaught_controlpoint");
-       while(_cp)
-       {
-           if(_cp.team == self.team)
-        {
-            _score = vlen(_trg_gen.origin - _cp.origin);
-            if(_score < _best_score)
-            {
-                _best = _cp;
-                _best_score = _score;
-            }
-        }
-               _cp = _cp.chain;
-       }
+void spawnfunc_onslaught_controlpoint()
+{
+       if(!g_onslaught) { remove(self); return; }
+       
+       ons_ControlPoint_Setup(self);
+}
 
-    vector _loc;
-    float i;
-    if(_best)
-    {
-        for(i = 0; i < 10; ++i)
-        {
-            _loc = _best.origin + '0 0 96';
-            _loc += ('0 1 0' * random()) * 128;
-            tracebox(_loc, PL_MIN, PL_MAX, _loc, MOVE_NORMAL, self);
-            if(trace_fraction == 1.0 && !trace_startsolid)
-            {
-                setorigin(self, _loc);
-                self.angles = normalize(_loc - _best.origin) * RAD2DEG;
-                return 0;
-            }
-        }
-    }
-    else
-    {
-        if(!autocvar_g_onslaught_spawn_at_generator)
-            return 0;
+/*QUAKED spawnfunc_onslaught_generator (0 .5 .8) (-32 -32 -24) (32 32 64)
+  Base generator.
 
-        _trg_gen = ((self.team == NUM_TEAM_1) ? ons_red_generator : ons_blue_generator);
+  spawnfunc_onslaught_link entities can target this.
 
-        for(i = 0; i < 10; ++i)
-        {
-            _loc = _trg_gen.origin + '0 0 96';
-            _loc += ('0 1 0' * random()) * 128;
-            tracebox(_loc, PL_MIN, PL_MAX, _loc, MOVE_NORMAL, self);
-            if(trace_fraction == 1.0 && !trace_startsolid)
-            {
-                setorigin(self, _loc);
-                self.angles = normalize(_loc - _trg_gen.origin) * RAD2DEG;
-                return 0;
-            }
-        }
-    }
+keys:
+"team" - team that owns this generator (5 = red, 14 = blue, etc), MUST BE SET.
+"targetname" - name that spawnfunc_onslaught_link entities will use to target this.
+ */
+void spawnfunc_onslaught_generator()
+{
+       if(!g_onslaught) { remove(self); return; }
+       if(!self.team) { objerror("team must be set"); }
 
-    return 0;
+       ons_GeneratorSetup(self);
 }
 
-MUTATOR_HOOKFUNCTION(ons_MonsterThink)
+
+// scoreboard setup
+void ons_ScoreRules()
 {
-       entity e = find(world, targetname, self.target);
-       if (e != world)
-               self.team = e.team;
+       CheckAllowedTeams(world);
+       ScoreRules_basics(((c4>=0) ? 4 : (c3>=0) ? 3 : 2), SFL_SORT_PRIO_PRIMARY, 0, true);
+       ScoreInfo_SetLabel_TeamScore  (ST_ONS_CAPS,     "destroyed", SFL_SORT_PRIO_PRIMARY);
+       ScoreInfo_SetLabel_PlayerScore(SP_ONS_CAPS,     "caps",      SFL_SORT_PRIO_SECONDARY);
+       ScoreInfo_SetLabel_PlayerScore(SP_ONS_TAKES,    "takes",     0);
+       ScoreRules_basics_end();
+}
 
-       return false;
+void ons_DelayedInit() // Do this check with a delay so we can wait for teams to be set up
+{
+       ons_ScoreRules();
+       
+       round_handler_Spawn(Onslaught_CheckPlayers, Onslaught_CheckWinner, Onslaught_RoundStart);
+       round_handler_Init(5, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
 }
 
-MUTATOR_HOOKFUNCTION(ons_MonsterSpawn)
+void ons_Initialize()
 {
-       entity e, ee = world;
+       precache_sound("ctf/red_capture.wav");
+       precache_sound("ctf/blue_capture.wav");
+       precache_sound("ctf/yellow_capture.wav");
+       precache_sound("ctf/pink_capture.wav");
 
-       if(self.targetname)
-       {
-               e = find(world,target,self.targetname);
-               if(e != world)
-               {
-                       self.team = e.team;
-                       ee = e;
-               }
-       }
+       ons_captureshield_force = autocvar_g_onslaught_shield_force;
 
-       if(ee)
-       {
-        activator = ee;
-        self.use();
-    }
+       addstat(STAT_ROUNDLOST, AS_INT, ons_roundlost);
 
-       return false;
+       InitializeEntity(world, ons_DelayedInit, INITPRIO_GAMETYPE);
 }
 
 MUTATOR_DEFINITION(gamemode_onslaught)
 {
-       MUTATOR_HOOK(BuildMutatorsPrettyString, ons_BuildMutatorsPrettyString, CBC_ORDER_ANY);
-       MUTATOR_HOOK(BuildMutatorsString, ons_BuildMutatorsString, CBC_ORDER_ANY);
+       MUTATOR_HOOK(reset_map_global, ons_ResetMap, CBC_ORDER_ANY);
+       MUTATOR_HOOK(MakePlayerObserver, ons_RemovePlayer, CBC_ORDER_ANY);
+       MUTATOR_HOOK(ClientDisconnect, ons_RemovePlayer, CBC_ORDER_ANY);
        MUTATOR_HOOK(PlayerSpawn, ons_PlayerSpawn, CBC_ORDER_ANY);
+       MUTATOR_HOOK(PlayerDies, ons_PlayerDies, CBC_ORDER_ANY);
        MUTATOR_HOOK(MonsterMove, ons_MonsterThink, CBC_ORDER_ANY);
        MUTATOR_HOOK(MonsterSpawn, ons_MonsterSpawn, CBC_ORDER_ANY);
-       //MUTATOR_HOOK(Spawn_Score, ons_Spawn_Score, CBC_ORDER_ANY);
+       MUTATOR_HOOK(TurretSpawn, ons_TurretSpawn, CBC_ORDER_ANY);
+       MUTATOR_HOOK(HavocBot_ChooseRole, ons_BotRoles, CBC_ORDER_ANY);
+       MUTATOR_HOOK(GetTeamCount, ons_GetTeamCount, CBC_ORDER_ANY);
+       MUTATOR_HOOK(SpectateCopy, ons_SpectateCopy, CBC_ORDER_ANY);
+       MUTATOR_HOOK(SV_ParseClientCommand, ons_SV_ParseClientCommand, CBC_ORDER_ANY);
+       MUTATOR_HOOK(PlayerUseKey, ons_PlayerUseKey, CBC_ORDER_ANY);
 
        MUTATOR_ONADD
        {
                if(time > 1) // game loads at time 1
                        error("This is a game type and it cannot be added at runtime.");
+               ons_Initialize();
+       }
+
+       MUTATOR_ONROLLBACK_OR_REMOVE
+       {
+               // we actually cannot roll back ons_Initialize here
+               // BUT: we don't need to! If this gets called, adding always
+               // succeeds.
        }
 
        MUTATOR_ONREMOVE
@@ -1710,5 +2196,5 @@ MUTATOR_DEFINITION(gamemode_onslaught)
                return -1;
        }
 
-       return 0;
+       return false;
 }
diff --git a/qcsrc/server/mutators/gamemode_onslaught.qh b/qcsrc/server/mutators/gamemode_onslaught.qh
new file mode 100644 (file)
index 0000000..7cebb17
--- /dev/null
@@ -0,0 +1,93 @@
+// these are needed since mutators are compiled last
+
+#ifdef SVQC
+
+.entity ons_toucher; // player who touched the control point
+
+// control point / generator constants
+const float ONS_CP_THINKRATE = 0.2;
+const float GEN_THINKRATE = 1;
+#define CPGEN_SPAWN_OFFSET ('0 0 1' * (PL_MAX_z - 13))
+const vector CPGEN_WAYPOINT_OFFSET = ('0 0 128');
+const vector CPICON_OFFSET = ('0 0 96');
+
+// list of generators on the map
+entity ons_worldgeneratorlist;
+.entity ons_worldgeneratornext;
+.entity ons_stalegeneratornext;
+
+// list of control points on the map
+entity ons_worldcplist;
+.entity ons_worldcpnext;
+.entity ons_stalecpnext;
+
+// list of links on the map
+entity ons_worldlinklist;
+.entity ons_worldlinknext;
+.entity ons_stalelinknext;
+
+// definitions
+.entity sprite;
+.string target2;
+.int iscaptured;
+.int islinked;
+.int isshielded;
+.float lasthealth;
+.int lastteam;
+.int lastshielded;
+.int lastcaptured;
+
+.bool waslinked;
+
+bool ons_stalemate;
+
+.float teleport_antispam;
+
+.bool ons_roundlost;
+
+// waypoint sprites
+.entity bot_basewaypoint; // generator waypointsprite
+
+.bool isgenneighbor[17];
+.bool iscpneighbor[17];
+float ons_notification_time[17];
+
+.float ons_overtime_damagedelay;
+
+.vector ons_deathloc;
+
+.entity ons_spawn_by;
+
+// declarations for functions used outside gamemode_onslaught.qc
+void ons_Generator_UpdateSprite(entity e);
+void ons_ControlPoint_UpdateSprite(entity e);
+bool ons_ControlPoint_Attackable(entity cp, int teamnumber);
+
+// CaptureShield: Prevent capturing or destroying control point/generator if it is not available yet
+float ons_captureshield_force; // push force of the shield
+
+// bot player logic
+const int HAVOCBOT_ONS_ROLE_NONE               = 0;
+const int HAVOCBOT_ONS_ROLE_DEFENSE    = 2;
+const int HAVOCBOT_ONS_ROLE_ASSISTANT  = 4;
+const int HAVOCBOT_ONS_ROLE_OFFENSE    = 8;
+
+.entity havocbot_ons_target;
+
+.int havocbot_role_flags;
+.float havocbot_attack_time;
+
+void havocbot_role_ons_defense();
+void havocbot_role_ons_offense();
+void havocbot_role_ons_assistant();
+
+void havocbot_ons_reset_role(entity bot);
+void havocbot_goalrating_items(float ratingscale, vector org, float sradius);
+void havocbot_goalrating_enemyplayers(float ratingscale, vector org, float sradius);
+
+// score rule declarations
+const int ST_ONS_CAPS = 1;
+const int SP_ONS_CAPS = 4;
+const int SP_ONS_TAKES = 6;
+
+#endif
index da723d927963bbfec2941394dd2dcbe736e9b07e..777c28e078bf5086e5042f03c3a55bfb5937a955 100644 (file)
@@ -14,6 +14,7 @@
 #include "gamemode_invasion.qh"
 #include "gamemode_race.qh"
 #include "gamemode_cts.qh"
+#include "gamemode_onslaught.qh"
 
 #include "mutator_dodging.qh"
 #include "mutator_overkill.qh"
index 85e75cda9e2fce18b2f2715b0bd1c10e8452b7bb..a496de32cb66d447fb3437504cb42efc9965528b 100644 (file)
@@ -15,6 +15,7 @@ cl_client.qc
 cl_impulse.qc
 cl_physics.qc
 cl_player.qc
+controlpoint.qc
 csqceffects.qc
 // ctf.qc
 // domination.qc
@@ -29,6 +30,7 @@ g_tetris.qc
 g_triggers.qc
 g_violence.qc
 g_world.qc
+generator.qc
 ipban.qc
 item_key.qc
 mapvoting.qc
index ba1b4e6eedacb91412044bd0529c472ac3ffb977..f2d88aa77c9535f5735db54336291c2f5b53a0cb 100644 (file)
@@ -146,6 +146,7 @@ void InitGameplayMode()
        if(g_onslaught)
        {
                ActivateTeamplay();
+               fraglimit_override = autocvar_g_onslaught_point_limit;
                have_team_spawns = -1; // request team spawns
                MUTATOR_ADD(gamemode_onslaught);
        }
index 02ebdec920562847fb780067d94da3a9c36267df..f0f27d3c9795b4f27dc0f0fa1d98e399de9cedf3 100644 (file)
@@ -307,12 +307,27 @@ float WaypointSprite_SendEntity(entity to, float sendflags)
                WriteCoord(MSG_ENTITY, self.fade_time);
                WriteCoord(MSG_ENTITY, self.teleport_time);
                WriteShort(MSG_ENTITY, self.fade_rate); // maxdist
-               float f;
-               f = 0;
+               float f = 0;
                if(self.currentammo)
                        f |= 1; // hideable
                if(self.exteriormodeltoclient == to)
                        f |= 2; // my own
+               if(g_onslaught)
+               {
+                       if(self.owner.classname == "onslaught_controlpoint")
+                       {
+                               entity wp_owner = self.owner;
+                               entity e = WaypointSprite_getviewentity(to);
+                               if(SAME_TEAM(e, wp_owner) && wp_owner.goalentity.health >= wp_owner.goalentity.max_health) { f |= 2; }
+                               if(!ons_ControlPoint_Attackable(wp_owner, e.team)) { f |= 2; }
+                       }
+                       if(self.owner.classname == "onslaught_generator")
+                       {
+                               entity wp_owner = self.owner;
+                               if(wp_owner.isshielded && wp_owner.health >= wp_owner.max_health) { f |= 2; }
+                               if(wp_owner.health <= 0) { f |= 2; }
+                       }
+               }
                WriteByte(MSG_ENTITY, f);
        }