]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/gamemodes/gamemode/onslaught/onslaught.qc
Merge branch 'terencehill/menu_fixes' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / onslaught / onslaught.qc
index c0f2eac21d16fd5017fc9f94d8b6162202fb2a60..bb302998f2e9c6c8daeb19e08562987126a11153 100644 (file)
@@ -13,7 +13,7 @@ REGISTER_MUTATOR(ons, false)
                ons_Initialize();
 
                ActivateTeamplay();
-               SetLimits(autocvar_g_onslaught_point_limit, -1, -1, -1);
+               SetLimits(autocvar_g_onslaught_point_limit, autocvar_leadlimit_override, autocvar_timelimit_override, -1);
                have_team_spawns = -1; // request team spawns
        }
 
@@ -110,13 +110,13 @@ const int HAVOCBOT_ONS_ROLE_OFFENSE       = 8;
 .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_role_ons_defense(entity this);
+void havocbot_role_ons_offense(entity this);
+void havocbot_role_ons_assistant(entity this);
 
-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);
+void havocbot_ons_reset_role(entity this);
+void havocbot_goalrating_items(entity this, float ratingscale, vector org, float sradius);
+void havocbot_goalrating_enemyplayers(entity this, float ratingscale, vector org, float sradius);
 
 // score rule declarations
 const int ST_ONS_CAPS = 1;
@@ -414,8 +414,8 @@ void ons_Link_CheckUpdate()
        self.nextthink = time;
 }
 
-void ons_DelayedLinkSetup()
-{SELFPARAM();
+void ons_DelayedLinkSetup(entity this)
+{
        self.goalentity = find(world, targetname, self.target);
        self.enemy = find(world, targetname, self.target2);
        if(!self.goalentity) { objerror("can not find target\n"); }
@@ -487,18 +487,18 @@ int ons_ControlPoint_Attackable(entity cp, int teamnumber)
        return 0;
 }
 
-void ons_ControlPoint_Icon_Damage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
-{SELFPARAM();
+void ons_ControlPoint_Icon_Damage(entity this, entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
+{
        if(damage <= 0) { return; }
 
-       if (self.owner.isshielded)
+       if (this.owner.isshielded)
        {
                // this is protected by a shield, so ignore the damage
-               if (time > self.pain_finished)
+               if (time > this.pain_finished)
                        if (IS_PLAYER(attacker))
                        {
                                play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
-                               self.pain_finished = time + 1;
+                               this.pain_finished = time + 1;
                                attacker.typehitsound += 1; // play both sounds (shield is way too quiet)
                        }
 
@@ -506,60 +506,57 @@ void ons_ControlPoint_Icon_Damage(entity inflictor, entity attacker, float damag
        }
 
        if(IS_PLAYER(attacker))
-       if(time - ons_notification_time[self.team] > 10)
+       if(time - ons_notification_time[this.team] > 10)
        {
-               play2team(self.team, SND(ONS_CONTROLPOINT_UNDERATTACK));
-               ons_notification_time[self.team] = time;
+               play2team(this.team, SND(ONS_CONTROLPOINT_UNDERATTACK));
+               ons_notification_time[this.team] = time;
        }
 
-       self.health = self.health - damage;
-       if(self.owner.iscaptured)
-               WaypointSprite_UpdateHealth(self.owner.sprite, self.health);
+       this.health = this.health - damage;
+       if(this.owner.iscaptured)
+               WaypointSprite_UpdateHealth(this.owner.sprite, this.health);
        else
-               WaypointSprite_UpdateBuildFinished(self.owner.sprite, time + (self.max_health - self.health) / (self.count / ONS_CP_THINKRATE));
-       self.pain_finished = time + 1;
+               WaypointSprite_UpdateBuildFinished(this.owner.sprite, time + (this.max_health - this.health) / (this.count / ONS_CP_THINKRATE));
+       this.pain_finished = time + 1;
        // particles on every hit
        pointparticles(EFFECT_SPARKS, hitloc, force*-1, 1);
        //sound on every hit
        if (random() < 0.5)
-               sound(self, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE+0.3, ATTEN_NORM);
+               sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE+0.3, ATTEN_NORM);
        else
-               sound(self, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE+0.3, ATTEN_NORM);
+               sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE+0.3, ATTEN_NORM);
 
-       if (self.health < 0)
+       if (this.health < 0)
        {
-               sound(self, CH_TRIGGER, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
-               pointparticles(EFFECT_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);
+               sound(this, CH_TRIGGER, SND_GRENADE_IMPACT, VOL_BASE, ATTEN_NORM);
+               pointparticles(EFFECT_ROCKET_EXPLODE, this.origin, '0 0 0', 1);
+               Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_CPDESTROYED), this.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;
+               this.owner.goalentity = world;
+               this.owner.islinked = false;
+               this.owner.iscaptured = false;
+               this.owner.team = 0;
+               this.owner.colormap = 1024;
 
-               WaypointSprite_UpdateMaxHealth(self.owner.sprite, 0);
+               WaypointSprite_UpdateMaxHealth(this.owner.sprite, 0);
 
                onslaught_updatelinks();
 
                // Use targets now (somebody make sure this is in the right place..)
-               setself(self.owner);
-               activator = self;
-               SUB_UseTargets ();
-               setself(this);
+               SUB_UseTargets(this.owner, this, NULL);
 
-               self.owner.waslinked = self.owner.islinked;
-               if(self.owner.model != "models/onslaught/controlpoint_pad.md3")
-                       setmodel_fixsize(self.owner, MDL_ONS_CP_PAD1);
-               //setsize(self, '-32 -32 0', '32 32 8');
+               this.owner.waslinked = this.owner.islinked;
+               if(this.owner.model != "models/onslaught/controlpoint_pad.md3")
+                       setmodel_fixsize(this.owner, MDL_ONS_CP_PAD1);
+               //setsize(this, '-32 -32 0', '32 32 8');
 
-               remove(self);
+               remove(this);
        }
 
-       self.SendFlags |= CPSF_STATUS;
+       this.SendFlags |= CPSF_STATUS;
 }
 
 void ons_ControlPoint_Icon_Think()
@@ -570,18 +567,16 @@ void ons_ControlPoint_Icon_Think()
        {
                int _enemy_count = 0;
                int _friendly_count = 0;
-               float _dist;
 
-               FOREACH_CLIENT(IS_PLAYER(it) && it.deadflag == DEAD_NO, LAMBDA(
-                       _dist = vlen(it.origin - self.origin);
-                       if(_dist < autocvar_g_onslaught_cp_proxydecap_distance)
+               FOREACH_CLIENT(IS_PLAYER(it) && !IS_DEAD(it), {
+                       if(vdist(it.origin - self.origin, <, autocvar_g_onslaught_cp_proxydecap_distance))
                        {
                                if(SAME_TEAM(it, 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);
@@ -590,7 +585,7 @@ void ons_ControlPoint_Icon_Think()
                self.SendFlags |= CPSF_STATUS;
                if(self.health <= 0)
                {
-                       ons_ControlPoint_Icon_Damage(self, self, 1, 0, self.origin, '0 0 0');
+                       ons_ControlPoint_Icon_Damage(self, self, self, 1, 0, self.origin, '0 0 0');
                        return;
                }
        }
@@ -613,10 +608,7 @@ void ons_ControlPoint_Icon_Think()
                if(!self.owner.islinked)
                        self.owner.team = 0;
 
-               setself(self.owner);
-               activator = self;
-               SUB_UseTargets ();
-               setself(this);
+               SUB_UseTargets(self.owner, self, NULL);
 
                self.owner.team = t;
 
@@ -667,7 +659,7 @@ void ons_ControlPoint_Icon_BuildThink()
                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_ALL_EXCEPT, self.owner.ons_toucher, MSG_CENTER, APP_TEAM_NUM(self.owner.ons_toucher.team, 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);
@@ -678,10 +670,7 @@ void ons_ControlPoint_Icon_BuildThink()
                onslaught_updatelinks();
 
                // Use targets now (somebody make sure this is in the right place..)
-               setself(self.owner);
-               activator = self;
-               SUB_UseTargets ();
-               setself(this);
+               SUB_UseTargets(self.owner, self, NULL);
 
                self.SendFlags |= CPSF_SETUP;
        }
@@ -799,8 +788,8 @@ void ons_ControlPoint_Touch()
                return;
 
        if(!IS_PLAYER(toucher)) { return; }
-       if(toucher.frozen) { return; }
-       if(toucher.deadflag != DEAD_NO) { return; }
+       if(STAT(FROZEN, toucher)) { return; }
+       if(IS_DEAD(toucher)) { return; }
 
        if ( SAME_TEAM(self,toucher) )
        if ( self.iscaptured )
@@ -851,14 +840,13 @@ void ons_ControlPoint_Reset(entity this)
 
        onslaught_updatelinks();
 
-       activator = this;
-       SUB_UseTargets(); // to reset the structures, playerspawns etc.
+       SUB_UseTargets(this, this, NULL); // to reset the structures, playerspawns etc.
 
        CSQCMODEL_AUTOUPDATE(this);
 }
 
-void ons_DelayedControlPoint_Setup()
-{SELFPARAM();
+void ons_DelayedControlPoint_Setup(entity this)
+{
        onslaught_updatelinks();
 
        // captureshield setup
@@ -955,64 +943,64 @@ void ons_Generator_UpdateSprite(entity e)
        }
 }
 
-void ons_GeneratorDamage(entity inflictor, entity attacker, float damage, int deathtype, vector hitloc, vector force)
-{SELFPARAM();
+void ons_GeneratorDamage(entity this, 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 (attacker != self)
+       if (attacker != this)
        {
-               if (self.isshielded)
+               if (this.isshielded)
                {
                        // this is protected by a shield, so ignore the damage
-                       if (time > self.pain_finished)
+                       if (time > this.pain_finished)
                                if (IS_PLAYER(attacker))
                                {
                                        play2(attacker, SND(ONS_DAMAGEBLOCKEDBYSHIELD));
                                        attacker.typehitsound += 1;
-                                       self.pain_finished = time + 1;
+                                       this.pain_finished = time + 1;
                                }
                        return;
                }
-               if (time > self.pain_finished)
+               if (time > this.pain_finished)
                {
-                       self.pain_finished = time + 10;
-                       FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && SAME_TEAM(it, self), LAMBDA(Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK)));
-                       play2team(self.team, SND(ONS_GENERATOR_UNDERATTACK));
+                       this.pain_finished = time + 10;
+                       FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it) && SAME_TEAM(it, this), Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_GENERATOR_UNDERATTACK));
+                       play2team(this.team, SND(ONS_GENERATOR_UNDERATTACK));
                }
        }
-       self.health = self.health - damage;
-       WaypointSprite_UpdateHealth(self.sprite, self.health);
+       this.health = this.health - damage;
+       WaypointSprite_UpdateHealth(this.sprite, this.health);
        // choose an animation frame based on health
-       self.frame = 10 * bound(0, (1 - self.health / self.max_health), 1);
+       this.frame = 10 * bound(0, (1 - this.health / this.max_health), 1);
        // see if the generator is still functional, or dying
-       if (self.health > 0)
+       if (this.health > 0)
        {
-               self.lasthealth = self.health;
+               this.lasthealth = this.health;
        }
        else
        {
-               if (attacker == self)
-                       Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME_));
+               if (attacker == this)
+                       Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM(this.team, INFO_ONSLAUGHT_GENDESTROYED_OVERTIME));
                else
                {
-                       Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM_4(self.team, INFO_ONSLAUGHT_GENDESTROYED_));
+                       Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM(this.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.sprite, 0);
-               WaypointSprite_Ping(self.sprite);
-               //WaypointSprite_Kill(self.sprite); // can't do this yet, code too poor
+               this.iscaptured = false;
+               this.islinked = false;
+               this.isshielded = false;
+               this.takedamage = DAMAGE_NO; // can't be hurt anymore
+               this.event_damage = func_null; // won't do anything if hurt
+               this.count = 0; // reset counter
+               this.think = func_null;
+               this.nextthink = 0;
+               //this.think(); // do the first explosion now
+
+               WaypointSprite_UpdateMaxHealth(this.sprite, 0);
+               WaypointSprite_Ping(this.sprite);
+               //WaypointSprite_Kill(this.sprite); // can't do this yet, code too poor
 
                onslaught_updatelinks();
        }
@@ -1020,7 +1008,7 @@ void ons_GeneratorDamage(entity inflictor, entity attacker, float damage, int de
        // Throw some flaming gibs on damage, more damage = more chance for gib
        if(random() < damage/220)
        {
-               sound(self, CH_TRIGGER, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
+               sound(this, CH_TRIGGER, SND_ROCKET_IMPACT, VOL_BASE, ATTEN_NORM);
        }
        else
        {
@@ -1029,12 +1017,12 @@ void ons_GeneratorDamage(entity inflictor, entity attacker, float damage, int de
 
                //sound on every hit
                if (random() < 0.5)
-                       sound(self, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE, ATTEN_NORM);
+                       sound(this, CH_TRIGGER, SND_ONS_HIT1, VOL_BASE, ATTEN_NORM);
                else
-                       sound(self, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE, ATTEN_NORM);
+                       sound(this, CH_TRIGGER, SND_ONS_HIT2, VOL_BASE, ATTEN_NORM);
        }
 
-       self.SendFlags |= GSF_STATUS;
+       this.SendFlags |= GSF_STATUS;
 }
 
 void ons_GeneratorThink()
@@ -1045,15 +1033,15 @@ void ons_GeneratorThink()
                if(!self.isshielded && self.wait < time)
                {
                        self.wait = time + 5;
-                       FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), LAMBDA(
+                       FOREACH_CLIENT(IS_PLAYER(it) && IS_REAL_CLIENT(it), {
                                if(SAME_TEAM(it, self))
                                {
                                        Send_Notification(NOTIF_ONE, it, MSG_CENTER, CENTER_ONS_NOTSHIELDED_TEAM);
                                        soundto(MSG_ONE, it, CHAN_AUTO, SND(KH_ALARM), VOL_BASE, ATTEN_NONE);    // FIXME: unique sound?
                                }
                                else
-                                       Send_Notification(NOTIF_ONE, it, MSG_CENTER, APP_TEAM_NUM_4(self.team, CENTER_ONS_NOTSHIELDED_));
-                       ));
+                                       Send_Notification(NOTIF_ONE, it, MSG_CENTER, APP_TEAM_NUM(self.team, CENTER_ONS_NOTSHIELDED));
+                       });
                }
        }
 }
@@ -1083,8 +1071,8 @@ void ons_GeneratorReset(entity this)
        onslaught_updatelinks();
 }
 
-void ons_DelayedGeneratorSetup()
-{SELFPARAM();
+void ons_DelayedGeneratorSetup(entity this)
+{
        // bot waypoints
        waypoint_spawnforitem_force(self, self.origin);
        self.nearestwaypointtimeout = 0; // activate waypointing again
@@ -1256,8 +1244,8 @@ bool Onslaught_CheckWinner()
 
        if(winner_team > 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_));
+               Send_Notification(NOTIF_ALL, world, MSG_CENTER, APP_TEAM_NUM(winner_team, CENTER_ROUND_TEAM_WIN));
+               Send_Notification(NOTIF_ALL, world, MSG_INFO, APP_TEAM_NUM(winner_team, INFO_ROUND_TEAM_WIN));
                TeamScore_AddToTeam(winner_team, ST_ONS_CAPS, +1);
        }
        else if(winner_team == -1)
@@ -1272,12 +1260,12 @@ bool Onslaught_CheckWinner()
 
        round_handler_Init(7, autocvar_g_onslaught_warmup, autocvar_g_onslaught_round_timelimit);
 
-       FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+       FOREACH_CLIENT(IS_PLAYER(it), {
                it.ons_roundlost = true;
                it.player_blocked = true;
 
                nades_Clear(it);
-       ));
+       });
 
        return 1;
 }
@@ -1290,7 +1278,7 @@ bool Onslaught_CheckPlayers()
 void Onslaught_RoundStart()
 {
        entity tmp_entity;
-       FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(it.player_blocked = false));
+       FOREACH_CLIENT(IS_PLAYER(it), it.player_blocked = false);
 
        for(tmp_entity = ons_worldcplist; tmp_entity; tmp_entity = tmp_entity.ons_worldcpnext)
                tmp_entity.sprite.SendFlags |= 16;
@@ -1306,23 +1294,23 @@ void Onslaught_RoundStart()
 
 // NOTE: LEGACY CODE, needs to be re-written!
 
-void havocbot_goalrating_ons_offenseitems(float ratingscale, vector org, float sradius)
-{SELFPARAM();
+void havocbot_goalrating_ons_offenseitems(entity this, float ratingscale, vector org, float sradius)
+{
        entity head;
        float t, c;
        bool needarmor = false, needweapons = false;
 
        // Needs armor/health?
-       if(self.health<100)
+       if(this.health<100)
                needarmor = true;
 
        // Needs weapons?
        c = 0;
-       FOREACH(Weapons, it != WEP_Null, LAMBDA(
-               if(self.weapons & (it.m_wepset))
+       FOREACH(Weapons, it != WEP_Null, {
+               if(this.weapons & (it.m_wepset))
                if(++c >= 4)
                        break;
-       ));
+       });
 
        if(c<4)
                needweapons = true;
@@ -1330,8 +1318,8 @@ void havocbot_goalrating_ons_offenseitems(float ratingscale, vector org, float s
        if(!needweapons && !needarmor)
                return;
 
-       LOG_DEBUG(strcat(self.netname, " needs weapons ", ftos(needweapons) , "\n"));
-       LOG_DEBUG(strcat(self.netname, " needs armor ", ftos(needarmor) , "\n"));
+       LOG_DEBUG(strcat(this.netname, " needs weapons ", ftos(needweapons) , "\n"));
+       LOG_DEBUG(strcat(this.netname, " needs armor ", ftos(needarmor) , "\n"));
 
        // See what is around
        head = findchainfloat(bot_pickup, true);
@@ -1342,43 +1330,43 @@ void havocbot_goalrating_ons_offenseitems(float ratingscale, vector org, float s
                if ( ((head.health || head.armorvalue) && needarmor) || (head.weapons && needweapons ) )
                if (vlen(head.origin - org) < sradius)
                {
-                       t = head.bot_pickupevalfunc(self, head);
+                       t = head.bot_pickupevalfunc(this, head);
                        if (t > 0)
-                               navigation_routerating(head, t * ratingscale, 500);
+                               navigation_routerating(this, head, t * ratingscale, 500);
                }
                head = head.chain;
        }
 }
 
-void havocbot_role_ons_setrole(entity bot, int role)
+void havocbot_role_ons_setrole(entity this, int role)
 {
-       LOG_DEBUG(strcat(bot.netname," switched to "));
+       LOG_DEBUG(strcat(this.netname," switched to "));
        switch(role)
        {
                case HAVOCBOT_ONS_ROLE_DEFENSE:
                        LOG_DEBUG("defense");
-                       bot.havocbot_role = havocbot_role_ons_defense;
-                       bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE;
-                       bot.havocbot_role_timeout = 0;
+                       this.havocbot_role = havocbot_role_ons_defense;
+                       this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE;
+                       this.havocbot_role_timeout = 0;
                        break;
                case HAVOCBOT_ONS_ROLE_ASSISTANT:
                        LOG_DEBUG("assistant");
-                       bot.havocbot_role = havocbot_role_ons_assistant;
-                       bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT;
-                       bot.havocbot_role_timeout = 0;
+                       this.havocbot_role = havocbot_role_ons_assistant;
+                       this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT;
+                       this.havocbot_role_timeout = 0;
                        break;
                case HAVOCBOT_ONS_ROLE_OFFENSE:
                        LOG_DEBUG("offense");
-                       bot.havocbot_role = havocbot_role_ons_offense;
-                       bot.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE;
-                       bot.havocbot_role_timeout = 0;
+                       this.havocbot_role = havocbot_role_ons_offense;
+                       this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE;
+                       this.havocbot_role_timeout = 0;
                        break;
        }
        LOG_DEBUG("\n");
 }
 
-void havocbot_goalrating_ons_controlpoints_attack(float ratingscale)
-{SELFPARAM();
+void havocbot_goalrating_ons_controlpoints_attack(entity this, float ratingscale)
+{
        entity cp, cp1, cp2, best, wp;
        float radius, bestvalue;
        int c;
@@ -1394,17 +1382,17 @@ void havocbot_goalrating_ons_controlpoints_attack(float ratingscale)
                        continue;
 
                // Ignore owned controlpoints
-               if(!(cp2.isgenneighbor[self.team] || cp2.iscpneighbor[self.team]))
+               if(!(cp2.isgenneighbor[this.team] || cp2.iscpneighbor[this.team]))
                        continue;
 
                // Count team mates interested in this control point
                // (easier and cleaner than keeping counters per cp and teams)
-               FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
-                       if(SAME_TEAM(it, self))
+               FOREACH_CLIENT(IS_PLAYER(it), {
+                       if(SAME_TEAM(it, this))
                        if(it.havocbot_role_flags & HAVOCBOT_ONS_ROLE_OFFENSE)
                        if(it.havocbot_ons_target == cp2)
                                ++c;
-               ));
+               });
 
                // NOTE: probably decrease the cost of attackable control points
                cp2.wpcost = c;
@@ -1423,14 +1411,14 @@ void havocbot_goalrating_ons_controlpoints_attack(float ratingscale)
                {
                        bestvalue = cp1.wpcost;
                        cp = cp1;
-                       self.havocbot_ons_target = cp1;
+                       this.havocbot_ons_target = cp1;
                }
        }
 
        if (!cp)
                return;
 
-       LOG_DEBUG(strcat(self.netname, " chose cp ranked ", ftos(bestvalue), "\n"));
+       LOG_DEBUG(strcat(this.netname, " chose cp ranked ", ftos(bestvalue), "\n"));
 
        if(cp.goalentity)
        {
@@ -1459,24 +1447,24 @@ void havocbot_goalrating_ons_controlpoints_attack(float ratingscale)
 
                if(best)
                {
-                       navigation_routerating(best, ratingscale, 10000);
+                       navigation_routerating(this, 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;
+                       this.havocbot_attack_time = 0;
+                       if(checkpvs(this.view_ofs,cp))
+                       if(checkpvs(this.view_ofs,best))
+                               this.havocbot_attack_time = time + 2;
                }
                else
                {
-                       navigation_routerating(cp, ratingscale, 10000);
+                       navigation_routerating(this, cp, ratingscale, 10000);
                }
-               LOG_DEBUG(strcat(self.netname, " found an attackable controlpoint at ", vtos(cp.origin) ,"\n"));
+               LOG_DEBUG(strcat(this.netname, " found an attackable controlpoint at ", vtos(cp.origin) ,"\n"));
        }
        else
        {
                // Should be touched
-               LOG_DEBUG(strcat(self.netname, " found a touchable controlpoint at ", vtos(cp.origin) ,"\n"));
+               LOG_DEBUG(strcat(this.netname, " found a touchable controlpoint at ", vtos(cp.origin) ,"\n"));
                found = false;
 
                // Look for auto generated waypoint
@@ -1485,26 +1473,26 @@ void havocbot_goalrating_ons_controlpoints_attack(float ratingscale)
                {
                        if(wp.classname=="waypoint")
                        {
-                               navigation_routerating(wp, ratingscale, 10000);
+                               navigation_routerating(this, wp, ratingscale, 10000);
                                found = true;
                        }
                }
 
                // Nothing found, rate the controlpoint itself
                if (!found)
-                       navigation_routerating(cp, ratingscale, 10000);
+                       navigation_routerating(this, cp, ratingscale, 10000);
        }
 }
 
-bool havocbot_goalrating_ons_generator_attack(float ratingscale)
-{SELFPARAM();
+bool havocbot_goalrating_ons_generator_attack(entity this, float ratingscale)
+{
        entity g, wp, bestwp;
        bool found;
        int best;
 
        for(g = ons_worldgeneratorlist; g; g = g.ons_worldgeneratornext)
        {
-               if(SAME_TEAM(g, self) || g.isshielded)
+               if(SAME_TEAM(g, this) || g.isshielded)
                        continue;
 
                // Should be attacked
@@ -1530,13 +1518,13 @@ bool havocbot_goalrating_ons_generator_attack(float ratingscale)
                if(bestwp)
                {
                        LOG_DEBUG("waypoints found around generator\n");
-                       navigation_routerating(bestwp, ratingscale, 10000);
+                       navigation_routerating(this, 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;
+                       this.havocbot_attack_time = 0;
+                       if(checkpvs(this.view_ofs,g))
+                       if(checkpvs(this.view_ofs,bestwp))
+                               this.havocbot_attack_time = time + 5;
 
                        return true;
                }
@@ -1544,69 +1532,69 @@ bool havocbot_goalrating_ons_generator_attack(float ratingscale)
                {
                        LOG_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;
+                       navigation_routerating(this, g, ratingscale, 10000);
+                       this.havocbot_attack_time = 0;
                        return true;
                }
        }
        return false;
 }
 
-void havocbot_role_ons_offense()
-{SELFPARAM();
-       if(self.deadflag != DEAD_NO)
+void havocbot_role_ons_offense(entity this)
+{
+       if(IS_DEAD(this))
        {
-               self.havocbot_attack_time = 0;
-               havocbot_ons_reset_role(self);
+               this.havocbot_attack_time = 0;
+               havocbot_ons_reset_role(this);
                return;
        }
 
        // Set the role timeout if necessary
-       if (!self.havocbot_role_timeout)
-               self.havocbot_role_timeout = time + 120;
+       if (!this.havocbot_role_timeout)
+               this.havocbot_role_timeout = time + 120;
 
-       if (time > self.havocbot_role_timeout)
+       if (time > this.havocbot_role_timeout)
        {
-               havocbot_ons_reset_role(self);
+               havocbot_ons_reset_role(this);
                return;
        }
 
-       if(self.havocbot_attack_time>time)
+       if(this.havocbot_attack_time>time)
                return;
 
-       if (self.bot_strategytime < time)
+       if (this.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();
+               navigation_goalrating_start(this);
+               havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
+               if(!havocbot_goalrating_ons_generator_attack(this, 20000))
+                       havocbot_goalrating_ons_controlpoints_attack(this, 20000);
+               havocbot_goalrating_ons_offenseitems(this, 10000, this.origin, 10000);
+               navigation_goalrating_end(this);
 
-               self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
+               this.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
        }
 }
 
-void havocbot_role_ons_assistant()
-{SELFPARAM();
-       havocbot_ons_reset_role(self);
+void havocbot_role_ons_assistant(entity this)
+{
+       havocbot_ons_reset_role(this);
 }
 
-void havocbot_role_ons_defense()
-{SELFPARAM();
-       havocbot_ons_reset_role(self);
+void havocbot_role_ons_defense(entity this)
+{
+       havocbot_ons_reset_role(this);
 }
 
-void havocbot_ons_reset_role(entity bot)
-{SELFPARAM();
-       if(self.deadflag != DEAD_NO)
+void havocbot_ons_reset_role(entity this)
+{
+       if(IS_DEAD(this))
                return;
 
-       bot.havocbot_ons_target = world;
+       this.havocbot_ons_target = world;
 
        // TODO: Defend control points or generator if necessary
 
-       havocbot_role_ons_setrole(bot, HAVOCBOT_ONS_ROLE_OFFENSE);
+       havocbot_role_ons_setrole(this, HAVOCBOT_ONS_ROLE_OFFENSE);
 }
 
 
@@ -1622,8 +1610,8 @@ entity ons_Nearest_ControlPoint(vector pos, float max_dist)
        {
                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)
+               if(max_dist <= 0 || vdist(tmp_entity.origin - pos, <=, max_dist))
+               if(vlen2(tmp_entity.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == world)
                        closest_target = tmp_entity;
                tmp_entity = tmp_entity.chain;
        }
@@ -1631,8 +1619,8 @@ entity ons_Nearest_ControlPoint(vector pos, float max_dist)
        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)
+               if(max_dist <= 0 || vdist(tmp_entity.origin - pos, <, max_dist))
+               if(vlen2(tmp_entity.origin - pos) <= vlen2(closest_target.origin - pos) || closest_target == world)
                        closest_target = tmp_entity;
                tmp_entity = tmp_entity.chain;
        }
@@ -1690,16 +1678,16 @@ entity ons_Nearest_ControlPoint_2D(vector pos, float max_dist)
        return closest_target;
 }
 /**
- * find the number of control points and generators in the same team as self
+ * find the number of control points and generators in the same team as this
  */
-int ons_Count_SelfControlPoints()
-{SELFPARAM();
+int ons_Count_SelfControlPoints(entity this)
+{
        entity tmp_entity;
        tmp_entity = findchain(classname, "onslaught_controlpoint");
        int n = 0;
        while(tmp_entity)
        {
-               if(SAME_TEAM(tmp_entity, self))
+               if(SAME_TEAM(tmp_entity, this))
                if(tmp_entity.iscaptured)
                        n++;
                tmp_entity = tmp_entity.chain;
@@ -1707,7 +1695,7 @@ int ons_Count_SelfControlPoints()
        tmp_entity = findchain(classname, "onslaught_generator");
        while(tmp_entity)
        {
-               if(SAME_TEAM(tmp_entity, self))
+               if(SAME_TEAM(tmp_entity, this))
                        n++;
                tmp_entity = tmp_entity.chain;
        }
@@ -1774,11 +1762,11 @@ bool ons_Teleport(entity player, entity tele_target, float range, bool tele_effe
 
 MUTATOR_HOOKFUNCTION(ons, reset_map_global)
 {SELFPARAM();
-       FOREACH_CLIENT(IS_PLAYER(it), LAMBDA(
+       FOREACH_CLIENT(IS_PLAYER(it), {
                it.ons_roundlost = false;
                it.ons_deathloc = '0 0 0';
-               WITH(entity, self, it, PutClientInServer());
-       ));
+               WITHSELF(it, PutClientInServer());
+       });
        return false;
 }
 
@@ -1925,7 +1913,7 @@ MUTATOR_HOOKFUNCTION(ons, PlayerSpawn)
 }
 
 MUTATOR_HOOKFUNCTION(ons, PlayerDies)
-{SELFPARAM();
+{
        frag_target.ons_deathloc = frag_target.origin;
        entity l;
        for(l = ons_worldgeneratorlist; l; l = l.ons_worldgeneratornext)
@@ -1938,8 +1926,8 @@ MUTATOR_HOOKFUNCTION(ons, PlayerDies)
        }
 
        if ( autocvar_g_onslaught_spawn_choose )
-       if ( ons_Count_SelfControlPoints() > 1 )
-               stuffcmd(self, "qc_cmd_cl hud clickradar\n");
+       if ( ons_Count_SelfControlPoints(frag_target) > 1 )
+               stuffcmd(frag_target, "qc_cmd_cl hud clickradar\n");
 
        return false;
 }
@@ -1953,25 +1941,24 @@ MUTATOR_HOOKFUNCTION(ons, MonsterMove)
        return false;
 }
 
-void ons_MonsterSpawn_Delayed()
-{SELFPARAM();
-       entity e, own = self.owner;
+void ons_MonsterSpawn_Delayed(entity this)
+{
+       entity own = self.owner;
 
-       if(!own) { remove(self); return; }
+       if(!own) { remove(this); return; }
 
        if(own.targetname)
        {
-               e = find(world, target, own.targetname);
+               entity e = find(world, target, own.targetname);
                if(e != world)
                {
                        own.team = e.team;
 
-                       activator = e;
-                       own.use();
+                       own.use(own, e, NULL);
                }
        }
 
-       remove(self);
+       remove(this);
 }
 
 MUTATOR_HOOKFUNCTION(ons, MonsterSpawn)
@@ -1983,22 +1970,21 @@ MUTATOR_HOOKFUNCTION(ons, MonsterSpawn)
        return false;
 }
 
-void ons_TurretSpawn_Delayed()
-{SELFPARAM();
-       entity e, own = self.owner;
+void ons_TurretSpawn_Delayed(entity this)
+{
+       entity own = self.owner;
 
        if(!own) { remove(self); return; }
 
        if(own.targetname)
        {
-               e = find(world, target, own.targetname);
+               entity e = find(world, target, own.targetname);
                if(e != world)
                {
                        own.team = e.team;
                        own.active = ACTIVE_NOT;
 
-                       activator = e;
-                       own.use();
+                       own.use(own, e, NULL);
                }
        }
 
@@ -2060,7 +2046,7 @@ MUTATOR_HOOKFUNCTION(ons, SV_ParseClientCommand)
 
                if ( IS_PLAYER(self) )
                {
-                       if ( !self.frozen )
+                       if ( !STAT(FROZEN, self) )
                        {
                                entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
 
@@ -2111,7 +2097,7 @@ MUTATOR_HOOKFUNCTION(ons, PlayerUseKey)
 {SELFPARAM();
        if(MUTATOR_RETURNVALUE || gameover) { return false; }
 
-       if((time > self.teleport_antispam) && (self.deadflag == DEAD_NO) && !self.vehicle)
+       if((time > self.teleport_antispam) && (!IS_DEAD(self)) && !self.vehicle)
        {
                entity source_point = ons_Nearest_ControlPoint(self.origin, autocvar_g_onslaught_teleport_radius);
                if ( source_point )
@@ -2132,6 +2118,7 @@ MUTATOR_HOOKFUNCTION(ons, PlayHitsound)
 
 MUTATOR_HOOKFUNCTION(ons, SendWaypoint)
 {
+    SELFPARAM();
        if(wp_sendflags & 16)
        {
                if(self.owner.classname == "onslaught_controlpoint")
@@ -2165,6 +2152,7 @@ MUTATOR_HOOKFUNCTION(ons, TurretValidateTarget)
 
 MUTATOR_HOOKFUNCTION(ons, TurretThink)
 {
+    SELFPARAM();
        // ONS uses somewhat backwards linking.
        if(self.target)
        {
@@ -2253,7 +2241,7 @@ void ons_ScoreRules()
        ScoreRules_basics_end();
 }
 
-void ons_DelayedInit() // Do this check with a delay so we can wait for teams to be set up
+void ons_DelayedInit(entity this) // Do this check with a delay so we can wait for teams to be set up
 {
        ons_ScoreRules();