]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/gamemodes/gamemode/nexball/nexball.qc
Remove weapon SELFPARAM
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / nexball / nexball.qc
index dc158a69a6d0b85078f2dd944fbe938639bd3178..afa6db93f0a31c84cd9a69bef59c3601e6004427 100644 (file)
@@ -2,11 +2,12 @@
 
 #ifdef IMPLEMENTATION
 #ifdef SVQC
-.float metertime;
+.float metertime = _STAT(NB_METERSTART);
 
 int autocvar_g_nexball_goalleadlimit;
 #define autocvar_g_nexball_goallimit cvar("g_nexball_goallimit")
 
+bool autocvar_g_nexball_basketball_jumppad = true;
 float autocvar_g_nexball_basketball_bouncefactor;
 float autocvar_g_nexball_basketball_bouncestop;
 float autocvar_g_nexball_basketball_carrier_highspeed;
@@ -16,6 +17,7 @@ float autocvar_g_nexball_basketball_meter_minpower;
 float autocvar_g_nexball_delay_collect;
 float autocvar_g_nexball_delay_goal;
 float autocvar_g_nexball_delay_start;
+bool autocvar_g_nexball_football_jumppad = true;
 float autocvar_g_nexball_football_bouncefactor;
 float autocvar_g_nexball_football_bouncestop;
 bool autocvar_g_nexball_radar_showallplayers;
@@ -38,9 +40,9 @@ float autocvar_g_balance_nexball_secondary_lifetime;
 float autocvar_g_balance_nexball_secondary_refire;
 float autocvar_g_balance_nexball_secondary_speed;
 
-void basketball_touch();
-void football_touch();
-void ResetBall();
+void basketball_touch(entity this);
+void football_touch(entity this);
+void ResetBall(entity this);
 const int NBM_NONE = 0;
 const int NBM_FOOTBALL = 2;
 const int NBM_BASKETBALL = 4;
@@ -78,61 +80,60 @@ void LogNB(string mode, entity actor)
        GameLogEcho(s);
 }
 
-void ball_restart(void)
-{SELFPARAM();
-       if(self.owner)
-               DropBall(self, self.owner.origin, '0 0 0');
-       ResetBall();
+void ball_restart(entity this)
+{
+       if(this.owner)
+               DropBall(this, this.owner.origin, '0 0 0');
+       ResetBall(this);
 }
 
-void nexball_setstatus(void)
+void nexball_setstatus()
 {SELFPARAM();
-       self.items &= ~IT_KEY1;
-       if(self.ballcarried)
+       this.items &= ~IT_KEY1;
+       if(this.ballcarried)
        {
-               if(self.ballcarried.teamtime && (self.ballcarried.teamtime < time))
+               if(this.ballcarried.teamtime && (this.ballcarried.teamtime < time))
                {
-                       bprint("The ", Team_ColoredFullName(self.team), " held the ball for too long.\n");
-                       setself(self.ballcarried);
-                       DropBall(self, self.owner.origin, '0 0 0');
-                       ResetBall();
-                       setself(this);
+                       bprint("The ", Team_ColoredFullName(this.team), " held the ball for too long.\n");
+                       DropBall(this.ballcarried, this.ballcarried.owner.origin, '0 0 0');
+                       entity e = this.ballcarried;
+                       WITHSELF(e, ResetBall(e));
                }
                else
-                       self.items |= IT_KEY1;
+                       this.items |= IT_KEY1;
        }
 }
 
-void relocate_nexball(void)
-{SELFPARAM();
-       tracebox(self.origin, BALL_MINS, BALL_MAXS, self.origin, true, self);
+void relocate_nexball(entity this)
+{
+       tracebox(this.origin, BALL_MINS, BALL_MAXS, this.origin, true, this);
        if(trace_startsolid)
        {
                vector o;
-               o = self.origin;
-               if(!move_out_of_solid(self))
+               o = this.origin;
+               if(!move_out_of_solid(this))
                        objerror("could not get out of solid at all!");
-               LOG_INFO("^1NOTE: this map needs FIXING. ", self.classname, " at ", vtos(o - '0 0 1'));
-               LOG_INFO(" needs to be moved out of solid, e.g. by '", ftos(self.origin.x - o.x));
-               LOG_INFO(" ", ftos(self.origin.y - o.y));
-               LOG_INFO(" ", ftos(self.origin.z - o.z), "'\n");
-               self.origin = o;
+               LOG_INFO("^1NOTE: this map needs FIXING. ", this.classname, " at ", vtos(o - '0 0 1'));
+               LOG_INFO(" needs to be moved out of solid, e.g. by '", ftos(this.origin.x - o.x));
+               LOG_INFO(" ", ftos(this.origin.y - o.y));
+               LOG_INFO(" ", ftos(this.origin.z - o.z), "'\n");
+               this.origin = o;
        }
 }
 
-void DropOwner(void)
-{SELFPARAM();
+void DropOwner(entity this)
+{
        entity ownr;
-       ownr = self.owner;
-       DropBall(self, ownr.origin, ownr.velocity);
+       ownr = this.owner;
+       DropBall(this, ownr.origin, ownr.velocity);
        makevectors(ownr.v_angle.y * '0 1 0');
        ownr.velocity += ('0 0 0.75' - v_forward) * 1000;
-       ownr.flags &= ~FL_ONGROUND;
+       UNSET_ONGROUND(ownr);
 }
 
 void GiveBall(entity plyr, entity ball)
-{SELFPARAM();
-       int slot = 0; // TODO: find ballstealer
+{
+       .entity weaponentity = weaponentities[0]; // TODO: find ballstealer
        entity ownr = ball.owner;
        if(ownr)
        {
@@ -141,7 +142,7 @@ void GiveBall(entity plyr, entity ball)
                if(ownr.metertime)
                {
                        ownr.metertime = 0;
-                       ownr.weaponentity[slot].state = WS_READY;
+                       ownr.(weaponentity).state = WS_READY;
                }
                WaypointSprite_Kill(ownr.waypointsprite_attachedforcarrier);
        }
@@ -166,7 +167,7 @@ void GiveBall(entity plyr, entity ball)
 
        ball.velocity = '0 0 0';
        ball.movetype = MOVETYPE_NONE;
-       ball.touch = func_null;
+       settouch(ball, func_null);
        ball.effects |= EF_NOSHADOW;
        ball.scale = 1; // scale down.
 
@@ -175,19 +176,17 @@ void GiveBall(entity plyr, entity ball)
 
        if(autocvar_g_nexball_basketball_delay_hold)
        {
-               ball.think = DropOwner;
+               setthink(ball, DropOwner);
                ball.nextthink = time + autocvar_g_nexball_basketball_delay_hold;
        }
 
-       plyr.weaponentity[slot].weapons = plyr.weapons;
-       plyr.weaponentity[slot].switchweapon = plyr.weapon;
+       plyr.(weaponentity).weapons = plyr.weapons;
+       plyr.(weaponentity).m_switchweapon = PS(plyr).m_weapon;
        plyr.weapons = WEPSET(NEXBALL);
-       setself(plyr);
        Weapon w = WEP_NEXBALL;
-       w.wr_resetplayer(w);
-       plyr.switchweapon = WEP_NEXBALL.m_id;
-       W_SwitchWeapon(WEP_NEXBALL.m_id);
-       setself(this);
+       WITHSELF(plyr, w.wr_resetplayer(w, plyr));
+       PS(plyr).m_switchweapon = WEP_NEXBALL;
+       WITHSELF(plyr, W_SwitchWeapon(plyr, WEP_NEXBALL));
 }
 
 void DropBall(entity ball, vector org, vector vel)
@@ -199,19 +198,19 @@ void DropBall(entity ball, vector org, vector vel)
        setattachment(ball, world, "");
        setorigin(ball, org);
        ball.movetype = MOVETYPE_BOUNCE;
-       ball.flags &= ~FL_ONGROUND;
+       UNSET_ONGROUND(ball);
        ball.scale = ball_scale;
        ball.velocity = vel;
        ball.nb_droptime = time;
-       ball.touch = basketball_touch;
-       ball.think = ResetBall;
+       settouch(ball, basketball_touch);
+       setthink(ball, ResetBall);
        ball.nextthink = min(time + autocvar_g_nexball_delay_idle, ball.teamtime);
 
        if(ball.owner.metertime)
        {
                ball.owner.metertime = 0;
-               int slot = 0; // TODO: find ballstealer
-               ball.owner.weaponentity[slot].state = WS_READY;
+               .entity weaponentity = weaponentities[0]; // TODO: find ballstealer
+               ball.owner.(weaponentity).state = WS_READY;
        }
 
        WaypointSprite_Kill(ball.owner.waypointsprite_attachedforcarrier);
@@ -222,64 +221,64 @@ void DropBall(entity ball, vector org, vector vel)
        ball.owner = world;
 }
 
-void InitBall(void)
-{SELFPARAM();
+void InitBall(entity this)
+{
        if(gameover) return;
-       self.flags &= ~FL_ONGROUND;
-       self.movetype = MOVETYPE_BOUNCE;
-       if(self.classname == "nexball_basketball")
-               self.touch = basketball_touch;
-       else if(self.classname == "nexball_football")
-               self.touch = football_touch;
-       self.cnt = 0;
-       self.think = ResetBall;
-       self.nextthink = time + autocvar_g_nexball_delay_idle + 3;
-       self.teamtime = 0;
-       self.pusher = world;
-       self.team = false;
-       _sound(self, CH_TRIGGER, self.noise1, VOL_BASE, ATTEN_NORM);
-       WaypointSprite_Ping(self.waypointsprite_attachedforcarrier);
+       UNSET_ONGROUND(this);
+       this.movetype = MOVETYPE_BOUNCE;
+       if(this.classname == "nexball_basketball")
+               settouch(this, basketball_touch);
+       else if(this.classname == "nexball_football")
+               settouch(this, football_touch);
+       this.cnt = 0;
+       setthink(this, ResetBall);
+       this.nextthink = time + autocvar_g_nexball_delay_idle + 3;
+       this.teamtime = 0;
+       this.pusher = world;
+       this.team = false;
+       _sound(this, CH_TRIGGER, this.noise1, VOL_BASE, ATTEN_NORM);
+       WaypointSprite_Ping(this.waypointsprite_attachedforcarrier);
        LogNB("init", world);
 }
 
-void ResetBall(void)
-{SELFPARAM();
-       if(self.cnt < 2)        // step 1
+void ResetBall(entity this)
+{
+       if(this.cnt < 2)        // step 1
        {
-               if(time == self.teamtime)
-                       bprint("The ", Team_ColoredFullName(self.team), " held the ball for too long.\n");
+               if(time == this.teamtime)
+                       bprint("The ", Team_ColoredFullName(this.team), " held the ball for too long.\n");
 
-               self.touch = func_null;
-               self.movetype = MOVETYPE_NOCLIP;
-               self.velocity = '0 0 0'; // just in case?
-               if(!self.cnt)
+               settouch(this, func_null);
+               this.movetype = MOVETYPE_NOCLIP;
+               this.velocity = '0 0 0'; // just in case?
+               if(!this.cnt)
                        LogNB("resetidle", world);
-               self.cnt = 2;
-               self.nextthink = time;
+               this.cnt = 2;
+               this.nextthink = time;
        }
-       else if(self.cnt < 4)     // step 2 and 3
+       else if(this.cnt < 4)     // step 2 and 3
        {
-//             dprint("Step ", ftos(self.cnt), ": Calculated velocity: ", vtos(self.spawnorigin - self.origin), ", time: ", ftos(time), "\n");
-               self.velocity = (self.spawnorigin - self.origin) * (self.cnt - 1); // 1 or 0.5 second movement
-               self.nextthink = time + 0.5;
-               self.cnt += 1;
+//             dprint("Step ", ftos(this.cnt), ": Calculated velocity: ", vtos(this.spawnorigin - this.origin), ", time: ", ftos(time), "\n");
+               this.velocity = (this.spawnorigin - this.origin) * (this.cnt - 1); // 1 or 0.5 second movement
+               this.nextthink = time + 0.5;
+               this.cnt += 1;
        }
        else     // step 4
        {
 //             dprint("Step 4: time: ", ftos(time), "\n");
-               if(vlen(self.origin - self.spawnorigin) > 10)  // should not happen anymore
+               if(vlen(this.origin - this.spawnorigin) > 10)  // should not happen anymore
                        LOG_TRACE("The ball moved too far away from its spawn origin.\nOffset: ",
-                                  vtos(self.origin - self.spawnorigin), " Velocity: ", vtos(self.velocity), "\n");
-               self.velocity = '0 0 0';
-               setorigin(self, self.spawnorigin); // make sure it's positioned correctly anyway
-               self.movetype = MOVETYPE_NONE;
-               self.think = InitBall;
-               self.nextthink = max(time, game_starttime) + autocvar_g_nexball_delay_start;
+                                  vtos(this.origin - this.spawnorigin), " Velocity: ", vtos(this.velocity), "\n");
+               this.velocity = '0 0 0';
+               setorigin(this, this.spawnorigin); // make sure it's positioned correctly anyway
+               this.movetype = MOVETYPE_NONE;
+               setthink(this, InitBall);
+               this.nextthink = max(time, game_starttime) + autocvar_g_nexball_delay_start;
        }
 }
 
-void football_touch(void)
-{SELFPARAM();
+void football_touch(entity this)
+{
        if(other.solid == SOLID_BSP)
        {
                if(time > self.lastground + 0.1)
@@ -324,14 +323,14 @@ void football_touch(void)
        self.avelocity = -250 * v_forward;  // maybe there is a way to make it look better?
 }
 
-void basketball_touch(void)
-{SELFPARAM();
+void basketball_touch(entity this)
+{
        if(other.ballcarried)
        {
-               football_touch();
+               football_touch(this);
                return;
        }
-       if(!self.cnt && IS_PLAYER(other) && !other.frozen && !other.deadflag && (other != self.nb_dropper || time > self.nb_droptime + autocvar_g_nexball_delay_collect))
+       if(!self.cnt && IS_PLAYER(other) && !STAT(FROZEN, other) && !IS_DEAD(other) && (other != self.nb_dropper || time > self.nb_droptime + autocvar_g_nexball_delay_collect))
        {
                if(other.health <= 0)
                        return;
@@ -346,8 +345,8 @@ void basketball_touch(void)
        }
 }
 
-void GoalTouch(void)
-{SELFPARAM();
+void GoalTouch(entity this)
+{
        entity ball;
        float isclient, pscore, otherteam;
        string pname;
@@ -429,9 +428,9 @@ void GoalTouch(void)
        WaypointSprite_Ping(ball.waypointsprite_attachedforcarrier);
 
        ball.cnt = 1;
-       ball.think = ResetBall;
+       setthink(ball, ResetBall);
        if(ball.classname == "nexball_basketball")
-               ball.touch = football_touch; // better than func_null: football control until the ball gets reset
+               settouch(ball, football_touch); // better than func_null: football control until the ball gets reset
        ball.nextthink = time + autocvar_g_nexball_delay_goal * (self.team != GOAL_OUT);
 }
 
@@ -442,10 +441,10 @@ spawnfunc(nexball_team)
 {
        if(!g_nexball)
        {
-               remove(self);
+               remove(this);
                return;
        }
-       self.team = self.cnt + 1;
+       this.team = this.cnt + 1;
 }
 
 void nb_spawnteam(string teamname, float teamcolor)
@@ -458,7 +457,7 @@ void nb_spawnteam(string teamname, float teamcolor)
        nb_teams += 1;
 }
 
-void nb_spawnteams(void)
+void nb_spawnteams()
 {
        bool t_red = false, t_blue = false, t_yellow = false, t_pink = false;
        entity e;
@@ -498,7 +497,7 @@ void nb_spawnteams(void)
        }
 }
 
-void nb_delayedinit(void)
+void nb_delayedinit(entity this)
 {
        if(find(world, classname, "nexball_team") == world)
                nb_spawnteams();
@@ -510,62 +509,62 @@ void nb_delayedinit(void)
 //       spawnfuncs       //
 //=======================//
 
-void SpawnBall(void)
-{SELFPARAM();
-       if(!g_nexball) { remove(self); return; }
+void SpawnBall(entity this)
+{
+       if(!g_nexball) { remove(this); return; }
 
 //     balls += 4; // using the remaining bits to count balls will leave more than the max edict count, so it's fine
 
-       if(self.model == "")
+       if(this.model == "")
        {
-               self.model = "models/nexball/ball.md3";
-               self.scale = 1.3;
+               this.model = "models/nexball/ball.md3";
+               this.scale = 1.3;
        }
 
-       precache_model(self.model);
-       _setmodel(self, self.model);
-       setsize(self, BALL_MINS, BALL_MAXS);
-       ball_scale = self.scale;
+       precache_model(this.model);
+       _setmodel(this, this.model);
+       setsize(this, BALL_MINS, BALL_MAXS);
+       ball_scale = this.scale;
 
-       relocate_nexball();
-       self.spawnorigin = self.origin;
+       relocate_nexball(this);
+       this.spawnorigin = this.origin;
 
-       self.effects = self.effects | EF_LOWPRECISION;
+       this.effects = this.effects | EF_LOWPRECISION;
 
-       if(cvar(strcat("g_", self.classname, "_trail")))  //nexball_basketball :p
+       if(cvar(strcat("g_", this.classname, "_trail")))  //nexball_basketball :p
        {
-               self.glow_color = autocvar_g_nexball_trail_color;
-               self.glow_trail = true;
+               this.glow_color = autocvar_g_nexball_trail_color;
+               this.glow_trail = true;
        }
 
-       self.movetype = MOVETYPE_FLY;
+       this.movetype = MOVETYPE_FLY;
 
        if(!autocvar_g_nexball_sound_bounce)
-               self.noise = "";
-       else if(self.noise == "")
-               self.noise = SND(NB_BOUNCE);
+               this.noise = "";
+       else if(this.noise == "")
+               this.noise = strzone(SND(NB_BOUNCE));
        //bounce sound placeholder (FIXME)
-       if(self.noise1 == "")
-               self.noise1 = SND(NB_DROP);
+       if(this.noise1 == "")
+               this.noise1 = strzone(SND(NB_DROP));
        //ball drop sound placeholder (FIXME)
-       if(self.noise2 == "")
-               self.noise2 = SND(NB_STEAL);
+       if(this.noise2 == "")
+               this.noise2 = strzone(SND(NB_STEAL));
        //stealing sound placeholder (FIXME)
-       if(self.noise) precache_sound(self.noise);
-       precache_sound(self.noise1);
-       precache_sound(self.noise2);
+       if(this.noise) precache_sound(this.noise);
+       precache_sound(this.noise1);
+       precache_sound(this.noise2);
 
-       WaypointSprite_AttachCarrier(WP_NbBall, self, RADARICON_FLAGCARRIER); // the ball's team is not set yet, no rule update needed
+       WaypointSprite_AttachCarrier(WP_NbBall, this, RADARICON_FLAGCARRIER); // the ball's team is not set yet, no rule update needed
 
-       self.reset = ball_restart;
-       self.think = InitBall;
-       self.nextthink = game_starttime + autocvar_g_nexball_delay_start;
+       this.reset = ball_restart;
+       setthink(this, InitBall);
+       this.nextthink = game_starttime + autocvar_g_nexball_delay_start;
 }
 
 spawnfunc(nexball_basketball)
 {
        nexball_mode |= NBM_BASKETBALL;
-       self.classname = "nexball_basketball";
+       this.classname = "nexball_basketball";
        if (!(balls & BALL_BASKET))
        {
                /*
@@ -576,24 +575,26 @@ spawnfunc(nexball_basketball)
                */
                autocvar_g_nexball_basketball_effects_default = autocvar_g_nexball_basketball_effects_default & BALL_EFFECTMASK;
        }
-       if(!self.effects)
-               self.effects = autocvar_g_nexball_basketball_effects_default;
-       self.solid = SOLID_TRIGGER;
+       if(!this.effects)
+               this.effects = autocvar_g_nexball_basketball_effects_default;
+       this.solid = SOLID_TRIGGER;
+       this.pushable = autocvar_g_nexball_basketball_jumppad;
        balls |= BALL_BASKET;
-       self.bouncefactor = autocvar_g_nexball_basketball_bouncefactor;
-       self.bouncestop = autocvar_g_nexball_basketball_bouncestop;
-       SpawnBall();
+       this.bouncefactor = autocvar_g_nexball_basketball_bouncefactor;
+       this.bouncestop = autocvar_g_nexball_basketball_bouncestop;
+       SpawnBall(this);
 }
 
 spawnfunc(nexball_football)
 {
        nexball_mode |= NBM_FOOTBALL;
-       self.classname = "nexball_football";
-       self.solid = SOLID_TRIGGER;
+       this.classname = "nexball_football";
+       this.solid = SOLID_TRIGGER;
        balls |= BALL_FOOT;
-       self.bouncefactor = autocvar_g_nexball_football_bouncefactor;
-       self.bouncestop = autocvar_g_nexball_football_bouncestop;
-       SpawnBall();
+       this.pushable = autocvar_g_nexball_football_jumppad;
+       this.bouncefactor = autocvar_g_nexball_football_bouncefactor;
+       this.bouncestop = autocvar_g_nexball_football_bouncestop;
+       SpawnBall(this);
 }
 
 float nb_Goal_Customize()
@@ -606,61 +607,61 @@ float nb_Goal_Customize()
        return true;
 }
 
-void SpawnGoal(void)
-{SELFPARAM();
-       if(!g_nexball) { remove(self); return; }
+void SpawnGoal(entity this)
+{
+       if(!g_nexball) { remove(this); return; }
 
        EXACTTRIGGER_INIT;
 
-       if(self.team != GOAL_OUT && Team_TeamToNumber(self.team) != -1)
+       if(this.team != GOAL_OUT && Team_TeamToNumber(this.team) != -1)
        {
-               entity wp = WaypointSprite_SpawnFixed(WP_NbGoal, (self.absmin + self.absmax) * 0.5, self, sprite, RADARICON_NONE);
-               wp.colormod = ((self.team) ? Team_ColorRGB(self.team) : '1 0.5 0');
-               self.sprite.customizeentityforclient = nb_Goal_Customize;
+               entity wp = WaypointSprite_SpawnFixed(WP_NbGoal, (this.absmin + this.absmax) * 0.5, this, sprite, RADARICON_NONE);
+               wp.colormod = ((this.team) ? Team_ColorRGB(this.team) : '1 0.5 0');
+               this.sprite.customizeentityforclient = nb_Goal_Customize;
        }
 
-       self.classname = "nexball_goal";
-       if(self.noise == "")
-               self.noise = "ctf/respawn.wav";
-       precache_sound(self.noise);
-       self.touch = GoalTouch;
+       this.classname = "nexball_goal";
+       if(this.noise == "")
+               this.noise = "ctf/respawn.wav";
+       precache_sound(this.noise);
+       settouch(this, GoalTouch);
 }
 
 spawnfunc(nexball_redgoal)
 {
-       self.team = NUM_TEAM_1;
-       SpawnGoal();
+       this.team = NUM_TEAM_1;
+       SpawnGoal(this);
 }
 spawnfunc(nexball_bluegoal)
 {
-       self.team = NUM_TEAM_2;
-       SpawnGoal();
+       this.team = NUM_TEAM_2;
+       SpawnGoal(this);
 }
 spawnfunc(nexball_yellowgoal)
 {
-       self.team = NUM_TEAM_3;
-       SpawnGoal();
+       this.team = NUM_TEAM_3;
+       SpawnGoal(this);
 }
 spawnfunc(nexball_pinkgoal)
 {
-       self.team = NUM_TEAM_4;
-       SpawnGoal();
+       this.team = NUM_TEAM_4;
+       SpawnGoal(this);
 }
 
 spawnfunc(nexball_fault)
 {
-       self.team = GOAL_FAULT;
-       if(self.noise == "")
-               self.noise = SND(TYPEHIT);
-       SpawnGoal();
+       this.team = GOAL_FAULT;
+       if(this.noise == "")
+               this.noise = strzone(SND(TYPEHIT));
+       SpawnGoal(this);
 }
 
 spawnfunc(nexball_out)
 {
-       self.team = GOAL_OUT;
-       if(self.noise == "")
-               self.noise = SND(TYPEHIT);
-       SpawnGoal();
+       this.team = GOAL_OUT;
+       if(this.noise == "")
+               this.noise = strzone(SND(TYPEHIT));
+       SpawnGoal(this);
 }
 
 //
@@ -702,23 +703,23 @@ spawnfunc(ball_bound)
 //=======================//
 
 
-void W_Nexball_Think()
-{SELFPARAM();
+void W_Nexball_Think(entity this)
+{
        //dprint("W_Nexball_Think\n");
-       //vector new_dir = steerlib_arrive(self.enemy.origin, 2500);
-       vector new_dir = normalize(self.enemy.origin + '0 0 50' - self.origin);
-       vector old_dir = normalize(self.velocity);
-       float _speed = vlen(self.velocity);
+       //vector new_dir = steerlib_arrive(this.enemy.origin, 2500);
+       vector new_dir = normalize(this.enemy.origin + '0 0 50' - this.origin);
+       vector old_dir = normalize(this.velocity);
+       float _speed = vlen(this.velocity);
        vector new_vel = normalize(old_dir + (new_dir * autocvar_g_nexball_safepass_turnrate)) * _speed;
        //vector new_vel = (new_dir * autocvar_g_nexball_safepass_turnrate
 
-       self.velocity = new_vel;
+       this.velocity = new_vel;
 
-       self.nextthink = time;
+       this.nextthink = time;
 }
 
-void W_Nexball_Touch(void)
-{SELFPARAM();
+void W_Nexball_Touch(entity this)
+{
        entity ball, attacker;
        attacker = self.owner;
        //self.think = func_null;
@@ -726,10 +727,10 @@ void W_Nexball_Touch(void)
 
        PROJECTILE_TOUCH;
        if(attacker.team != other.team || autocvar_g_nexball_basketball_teamsteal)
-               if((ball = other.ballcarried) && !other.frozen && !other.deadflag && (IS_PLAYER(attacker)))
+               if((ball = other.ballcarried) && !STAT(FROZEN, other) && !IS_DEAD(other) && (IS_PLAYER(attacker)))
                {
                        other.velocity = other.velocity + normalize(self.velocity) * other.damageforcescale * autocvar_g_balance_nexball_secondary_force;
-                       other.flags &= ~FL_ONGROUND;
+                       UNSET_ONGROUND(other);
                        if(!attacker.ballcarried)
                        {
                                LogNB("stole", attacker);
@@ -755,7 +756,7 @@ void W_Nexball_Attack(float t)
        if(!(ball = self.ballcarried))
                return;
 
-       W_SetupShot(self, false, 4, SND(NB_SHOOT1), CH_WEAPON_A, 0);
+       W_SetupShot(self, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0);
        tracebox(w_shotorg, BALL_MINS, BALL_MAXS, w_shotorg, MOVE_WORLDONLY, world);
        if(trace_startsolid)
        {
@@ -786,14 +787,14 @@ void W_Nexball_Attack(float t)
 
 vector trigger_push_calculatevelocity(vector org, entity tgt, float ht);
 
-void W_Nexball_Attack2(void)
+void W_Nexball_Attack2()
 {SELFPARAM();
        if(self.ballcarried.enemy)
        {
                entity _ball = self.ballcarried;
-               W_SetupShot(self, false, 4, SND(NB_SHOOT1), CH_WEAPON_A, 0);
+               W_SetupShot(self, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0);
                DropBall(_ball, w_shotorg, trigger_push_calculatevelocity(_ball.origin, _ball.enemy, 32));
-               _ball.think = W_Nexball_Think;
+               setthink(_ball, W_Nexball_Think);
                _ball.nextthink = time;
                return;
        }
@@ -801,7 +802,7 @@ void W_Nexball_Attack2(void)
        if(!autocvar_g_nexball_tackling)
                return;
 
-       W_SetupShot(self, false, 2, SND(NB_SHOOT2), CH_WEAPON_A, 0);
+       W_SetupShot(self, false, 2, SND_NB_SHOOT2, CH_WEAPON_A, 0);
        entity missile = new(ballstealer);
 
        missile.owner = self;
@@ -815,8 +816,8 @@ void W_Nexball_Attack2(void)
 
        W_SetupProjVelocity_Basic(missile, autocvar_g_balance_nexball_secondary_speed, 0);
        missile.angles = vectoangles(missile.velocity);
-       missile.touch = W_Nexball_Touch;
-       missile.think = SUB_Remove;
+       settouch(missile, W_Nexball_Touch);
+       setthink(missile, SUB_Remove);
        missile.nextthink = time + autocvar_g_balance_nexball_secondary_lifetime; //FIXME: use a distance instead?
 
        missile.effects = EF_BRIGHTFIELD | EF_LOWPRECISION;
@@ -852,48 +853,56 @@ float ball_customize()
        return true;
 }
 
-       METHOD(BallStealer, wr_think, void(BallStealer thiswep, entity actor, int slot, int fire))
-       {
-               if(fire & 1)
-                       if(weapon_prepareattack(thiswep, actor, slot, false, autocvar_g_balance_nexball_primary_refire))
-                               if(autocvar_g_nexball_basketball_meter)
-                               {
-                                       if(self.ballcarried && !self.metertime)
-                                               self.metertime = time;
-                                       else
-                                               weapon_thinkf(actor, slot, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
-                               }
-                               else
-                               {
-                                       W_Nexball_Attack(-1);
-                                       weapon_thinkf(actor, slot, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
-                               }
-               if(fire & 2)
-                       if(weapon_prepareattack(thiswep, actor, slot, true, autocvar_g_balance_nexball_secondary_refire))
-                       {
-                               W_Nexball_Attack2();
-                               weapon_thinkf(actor, slot, WFRAME_FIRE2, autocvar_g_balance_nexball_secondary_animtime, w_ready);
-                       }
+METHOD(BallStealer, wr_think, void(BallStealer thiswep, entity actor, .entity weaponentity, int fire))
+{
+    SELFPARAM();
+    TC(BallStealer, thiswep);
+    if(fire & 1)
+        if(weapon_prepareattack(thiswep, actor, weaponentity, false, autocvar_g_balance_nexball_primary_refire))
+            if(autocvar_g_nexball_basketball_meter)
+            {
+                if(self.ballcarried && !self.metertime)
+                    self.metertime = time;
+                else
+                    weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
+            }
+            else
+            {
+                W_Nexball_Attack(-1);
+                weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
+            }
+    if(fire & 2)
+        if(weapon_prepareattack(thiswep, actor, weaponentity, true, autocvar_g_balance_nexball_secondary_refire))
+        {
+            W_Nexball_Attack2();
+            weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, autocvar_g_balance_nexball_secondary_animtime, w_ready);
+        }
+
+    if(!(fire & 1) && self.metertime && self.ballcarried)
+    {
+        W_Nexball_Attack(time - self.metertime);
+        // DropBall or stealing will set metertime back to 0
+        weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
+    }
+}
 
-               if(!(fire & 1) && self.metertime && self.ballcarried)
-               {
-                       W_Nexball_Attack(time - self.metertime);
-                       // DropBall or stealing will set metertime back to 0
-                       weapon_thinkf(actor, slot, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
-               }
-       }
-       METHOD(BallStealer, wr_setup, void(BallStealer thiswep))
-       {
-               //weapon_setup(WEP_PORTO.m_id);
-       }
-       METHOD(BallStealer, wr_checkammo1, bool(BallStealer thiswep))
-       {
-               return true;
-       }
-       METHOD(BallStealer, wr_checkammo2, bool(BallStealer thiswep))
-       {
-               return true;
-       }
+METHOD(BallStealer, wr_setup, void(BallStealer this, entity actor))
+{
+    TC(BallStealer, this);
+    //weapon_setup(WEP_PORTO.m_id);
+}
+
+METHOD(BallStealer, wr_checkammo1, bool(BallStealer this, entity actor))
+{
+    TC(BallStealer, this);
+    return true;
+}
+
+METHOD(BallStealer, wr_checkammo2, bool(BallStealer this, entity actor))
+{
+    TC(BallStealer, this);
+    return true;
+}
 
 void nb_DropBall(entity player)
 {
@@ -908,8 +917,8 @@ MUTATOR_HOOKFUNCTION(nb, ClientDisconnect)
 }
 
 MUTATOR_HOOKFUNCTION(nb, PlayerDies)
-{SELFPARAM();
-       nb_DropBall(self);
+{
+       nb_DropBall(frag_target);
        return false;
 }
 
@@ -930,10 +939,11 @@ MUTATOR_HOOKFUNCTION(nb, PlayerPreThink)
                        self.ballcarried.velocity = self.velocity;
                        self.ballcarried.customizeentityforclient = ball_customize;
 
-                       setorigin(self.ballcarried, self.origin + self.view_ofs +
+                       vector org = self.origin + self.view_ofs +
                                          v_forward * autocvar_g_nexball_viewmodel_offset.x +
                                          v_right * autocvar_g_nexball_viewmodel_offset.y +
-                                         v_up * autocvar_g_nexball_viewmodel_offset.z);
+                                         v_up * autocvar_g_nexball_viewmodel_offset.z;
+                       setorigin(self.ballcarried, org);
 
                        // 'safe passing'
                        if(autocvar_g_nexball_safepass_maxdist)
@@ -949,7 +959,7 @@ MUTATOR_HOOKFUNCTION(nb, PlayerPreThink)
                                crosshair_trace(self);
                                if( trace_ent &&
                                        IS_CLIENT(trace_ent) &&
-                                       trace_ent.deadflag == DEAD_NO &&
+                                       !IS_DEAD(trace_ent) &&
                                        trace_ent.team == self.team &&
                                        vlen(trace_ent.origin - self.origin) <= autocvar_g_nexball_safepass_maxdist )
                                {
@@ -965,16 +975,16 @@ MUTATOR_HOOKFUNCTION(nb, PlayerPreThink)
                }
                else
                {
-                       int slot = 0; // TODO
-                       if(self.weaponentity[slot].weapons)
+                       .entity weaponentity = weaponentities[0]; // TODO
+                       if(self.(weaponentity).weapons)
                        {
-                               self.weapons = self.weaponentity[slot].weapons;
+                               self.weapons = self.(weaponentity).weapons;
                                Weapon w = WEP_NEXBALL;
-                               w.wr_resetplayer(w);
-                               self.switchweapon = self.weaponentity[slot].switchweapon;
-                               W_SwitchWeapon(self.switchweapon);
+                               w.wr_resetplayer(w, self);
+                               PS(self).m_switchweapon = self.(weaponentity).m_switchweapon;
+                               W_SwitchWeapon(self, PS(self).m_switchweapon);
 
-               self.weaponentity[slot].weapons = '0 0 0';
+                               self.(weaponentity).weapons = '0 0 0';
                        }
                }
 
@@ -995,8 +1005,8 @@ MUTATOR_HOOKFUNCTION(nb, PlayerSpawn)
 {
        SELFPARAM();
        this.metertime = 0;
-       int slot = 0;
-       this.weaponentity[slot].weapons = '0 0 0';
+       .entity weaponentity = weaponentities[0];
+       this.(weaponentity).weapons = '0 0 0';
 
        if (nexball_mode & NBM_BASKETBALL)
                this.weapons |= WEPSET(NEXBALL);
@@ -1021,12 +1031,12 @@ MUTATOR_HOOKFUNCTION(nb, PlayerPhysics)
 
 MUTATOR_HOOKFUNCTION(nb, ForbidThrowCurrentWeapon)
 {SELFPARAM();
-       return self.weapon == WEP_NEXBALL.m_id;
+       return PS(self).m_weapon == WEP_NEXBALL;
 }
 
 MUTATOR_HOOKFUNCTION(nb, ForbidDropCurrentWeapon)
 {SELFPARAM();
-       return self.weapon == WEP_MORTAR.m_id; // TODO: what is this for?
+       return PS(self).m_weapon == WEP_MORTAR; // TODO: what is this for?
 }
 
 MUTATOR_HOOKFUNCTION(nb, FilterItem)
@@ -1066,17 +1076,12 @@ MUTATOR_HOOKFUNCTION(nb, SendWaypoint)
 
 REGISTER_MUTATOR(nb, g_nexball)
 {
-       ActivateTeamplay();
-       SetLimits(autocvar_g_nexball_goallimit, autocvar_g_nexball_goalleadlimit, -1, -1);
-       have_team_spawns = -1; // request team spawns
-
        MUTATOR_ONADD
        {
                g_nexball_meter_period = autocvar_g_nexball_meter_period;
                if(g_nexball_meter_period <= 0)
                        g_nexball_meter_period = 2; // avoid division by zero etc. due to silly users
                g_nexball_meter_period = rint(g_nexball_meter_period * 32) / 32; //Round to 1/32ths to send as a byte multiplied by 32
-               addstat(STAT_NB_METERSTART, AS_FLOAT, metertime);
 
                // General settings
                /*
@@ -1089,6 +1094,10 @@ REGISTER_MUTATOR(nb, g_nexball)
 
                InitializeEntity(world, nb_delayedinit, INITPRIO_GAMETYPE);
                WEP_NEXBALL.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
+
+               ActivateTeamplay();
+               SetLimits(autocvar_g_nexball_goallimit, autocvar_g_nexball_goalleadlimit, autocvar_timelimit_override, -1);
+               have_team_spawns = -1; // request team spawns
        }
 
        MUTATOR_ONROLLBACK_OR_REMOVE