]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/gamemodes/gamemode/nexball/nexball.qc
Merge branch 'master' into Mario/wepent_experimental
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / gamemodes / gamemode / nexball / nexball.qc
index 426cab70e151aea46122fac85d0896113cf1319e..2cad55f166da384fd9c254179b028dc5079530a6 100644 (file)
@@ -1,6 +1,5 @@
 #include "nexball.qh"
 
-#ifdef IMPLEMENTATION
 #ifdef CSQC
 int autocvar_cl_eventchase_nexball = 1;
 
@@ -35,6 +34,7 @@ float autocvar_g_nexball_football_bouncestop;
 bool autocvar_g_nexball_radar_showallplayers;
 bool autocvar_g_nexball_sound_bounce;
 int autocvar_g_nexball_trail_color;
+bool autocvar_g_nexball_playerclip_collisions = true;
 
 float autocvar_g_nexball_safepass_turnrate;
 float autocvar_g_nexball_safepass_maxdist;
@@ -52,8 +52,8 @@ float autocvar_g_balance_nexball_secondary_lifetime;
 float autocvar_g_balance_nexball_secondary_refire;
 float autocvar_g_balance_nexball_secondary_speed;
 
-void basketball_touch(entity this);
-void football_touch(entity this);
+void basketball_touch(entity this, entity toucher);
+void football_touch(entity this, entity toucher);
 void ResetBall(entity this);
 const int NBM_NONE = 0;
 const int NBM_FOOTBALL = 2;
@@ -63,16 +63,14 @@ float nexball_mode;
 float OtherTeam(float t)  //works only if there are two teams on the map!
 {
        entity e;
-       e = find(world, classname, "nexball_team");
+       e = find(NULL, classname, "nexball_team");
        if(e.team == t)
                e = find(e, classname, "nexball_team");
        return e.team;
 }
 
 const float ST_NEXBALL_GOALS = 1;
-const float SP_NEXBALL_GOALS = 4;
-const float SP_NEXBALL_FAULTS = 5;
-void nb_ScoreRules(float teams)
+void nb_ScoreRules(int teams)
 {
        ScoreRules_basics(teams, 0, 0, true);
        ScoreInfo_SetLabel_TeamScore(   ST_NEXBALL_GOALS,  "goals", SFL_SORT_PRIO_PRIMARY);
@@ -87,7 +85,7 @@ void LogNB(string mode, entity actor)
        if(!autocvar_sv_eventlog)
                return;
        s = strcat(":nexball:", mode);
-       if(actor != world)
+       if(actor != NULL)
                s = strcat(s, ":", ftos(actor.playerid));
        GameLogEcho(s);
 }
@@ -106,10 +104,10 @@ void nexball_setstatus(entity this)
        {
                if(this.ballcarried.teamtime && (this.ballcarried.teamtime < time))
                {
-                       bprint("The ", Team_ColoredFullName(this.team), " held the ball for too long.\n");
-                       DropBall(this.ballcarried, this.ballcarried.owner.origin, '0 0 0');
+                       Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_NEXBALL_RETURN_HELD));
                        entity e = this.ballcarried;
-                       WITHSELF(e, ResetBall(e));
+                       DropBall(this.ballcarried, this.ballcarried.owner.origin, '0 0 0');
+                       ResetBall(e);
                }
                else
                        this.items |= IT_KEY1;
@@ -124,7 +122,7 @@ void relocate_nexball(entity this)
                vector o;
                o = this.origin;
                if(!move_out_of_solid(this))
-                       objerror("could not get out of solid at all!");
+                       objerror(this, "could not get out of solid at all!");
                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));
@@ -150,7 +148,7 @@ void GiveBall(entity plyr, entity ball)
        if(ownr)
        {
                ownr.effects &= ~autocvar_g_nexball_basketball_effects_default;
-               ownr.ballcarried = world;
+               ownr.ballcarried = NULL;
                if(ownr.metertime)
                {
                        ownr.metertime = 0;
@@ -170,6 +168,7 @@ void GiveBall(entity plyr, entity ball)
                ball.teamtime = time + autocvar_g_nexball_basketball_delay_hold_forteam;
 
        ball.owner = ball.pusher = plyr; //"owner" is set to the player carrying, "pusher" to the last player who touched it
+       ball.weaponentity_fld = weaponentity;
        ball.team = plyr.team;
        plyr.ballcarried = ball;
        ball.nb_dropper = plyr;
@@ -178,7 +177,7 @@ void GiveBall(entity plyr, entity ball)
        ball.effects &= ~autocvar_g_nexball_basketball_effects_default;
 
        ball.velocity = '0 0 0';
-       ball.movetype = MOVETYPE_NONE;
+       set_movetype(ball, MOVETYPE_NONE);
        settouch(ball, func_null);
        ball.effects |= EF_NOSHADOW;
        ball.scale = 1; // scale down.
@@ -193,12 +192,12 @@ void GiveBall(entity plyr, entity ball)
        }
 
        plyr.(weaponentity).weapons = plyr.weapons;
-       plyr.(weaponentity).m_switchweapon = PS(plyr).m_weapon;
+       plyr.m_switchweapon = plyr.(weaponentity).m_weapon;
        plyr.weapons = WEPSET(NEXBALL);
        Weapon w = WEP_NEXBALL;
-       WITHSELF(plyr, w.wr_resetplayer(w, plyr));
-       PS(plyr).m_switchweapon = WEP_NEXBALL;
-       WITHSELF(plyr, W_SwitchWeapon(plyr, WEP_NEXBALL));
+       w.wr_resetplayer(w, plyr);
+       plyr.(weaponentity).m_switchweapon = WEP_NEXBALL;
+       W_SwitchWeapon(plyr, WEP_NEXBALL, weaponentity);
 }
 
 void DropBall(entity ball, vector org, vector vel)
@@ -207,9 +206,9 @@ void DropBall(entity ball, vector org, vector vel)
        ball.effects &= ~EF_NOSHADOW;
        ball.owner.effects &= ~autocvar_g_nexball_basketball_effects_default;
 
-       setattachment(ball, world, "");
+       setattachment(ball, NULL, "");
        setorigin(ball, org);
-       ball.movetype = MOVETYPE_BOUNCE;
+       set_movetype(ball, MOVETYPE_BOUNCE);
        UNSET_ONGROUND(ball);
        ball.scale = ball_scale;
        ball.velocity = vel;
@@ -221,23 +220,23 @@ void DropBall(entity ball, vector org, vector vel)
        if(ball.owner.metertime)
        {
                ball.owner.metertime = 0;
-               .entity weaponentity = weaponentities[0]; // TODO: find ballstealer
+               .entity weaponentity = ball.weaponentity_fld;
                ball.owner.(weaponentity).state = WS_READY;
        }
 
        WaypointSprite_Kill(ball.owner.waypointsprite_attachedforcarrier);
-       WaypointSprite_Spawn(WP_NbBall, 0, 0, ball, '0 0 64', world, ball.team, ball, waypointsprite_attachedforcarrier, false, RADARICON_FLAGCARRIER); // no health bar please
+       WaypointSprite_Spawn(WP_NbBall, 0, 0, ball, '0 0 64', NULL, ball.team, ball, waypointsprite_attachedforcarrier, false, RADARICON_FLAGCARRIER); // no health bar please
        WaypointSprite_UpdateRule(ball.waypointsprite_attachedforcarrier, 0, SPRITERULE_DEFAULT);
 
-       ball.owner.ballcarried = world;
-       ball.owner = world;
+       ball.owner.ballcarried = NULL;
+       ball.owner = NULL;
 }
 
 void InitBall(entity this)
 {
        if(gameover) return;
        UNSET_ONGROUND(this);
-       this.movetype = MOVETYPE_BOUNCE;
+       set_movetype(this, MOVETYPE_BOUNCE);
        if(this.classname == "nexball_basketball")
                settouch(this, basketball_touch);
        else if(this.classname == "nexball_football")
@@ -246,11 +245,11 @@ void InitBall(entity this)
        setthink(this, ResetBall);
        this.nextthink = time + autocvar_g_nexball_delay_idle + 3;
        this.teamtime = 0;
-       this.pusher = world;
+       this.pusher = NULL;
        this.team = false;
        _sound(this, CH_TRIGGER, this.noise1, VOL_BASE, ATTEN_NORM);
        WaypointSprite_Ping(this.waypointsprite_attachedforcarrier);
-       LogNB("init", world);
+       LogNB("init", NULL);
 }
 
 void ResetBall(entity this)
@@ -258,13 +257,13 @@ void ResetBall(entity this)
        if(this.cnt < 2)        // step 1
        {
                if(time == this.teamtime)
-                       bprint("The ", Team_ColoredFullName(this.team), " held the ball for too long.\n");
+                       Send_Notification(NOTIF_ALL, NULL, MSG_INFO, APP_TEAM_NUM(this.team, INFO_NEXBALL_RETURN_HELD));
 
                settouch(this, func_null);
-               this.movetype = MOVETYPE_NOCLIP;
+               set_movetype(this, MOVETYPE_NOCLIP);
                this.velocity = '0 0 0'; // just in case?
                if(!this.cnt)
-                       LogNB("resetidle", world);
+                       LogNB("resetidle", NULL);
                this.cnt = 2;
                this.nextthink = time;
        }
@@ -278,105 +277,105 @@ void ResetBall(entity this)
        else     // step 4
        {
 //             dprint("Step 4: time: ", ftos(time), "\n");
-               if(vlen(this.origin - this.spawnorigin) > 10)  // should not happen anymore
+               if(vdist(this.origin - this.spawnorigin, >, 10)) // should not happen anymore
                        LOG_TRACE("The ball moved too far away from its spawn origin.\nOffset: ",
                                   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;
+               set_movetype(this, MOVETYPE_NONE);
                setthink(this, InitBall);
                this.nextthink = max(time, game_starttime) + autocvar_g_nexball_delay_start;
        }
 }
 
-void football_touch(entity this)
+void football_touch(entity this, entity toucher)
 {
-       if(other.solid == SOLID_BSP)
+       if(toucher.solid == SOLID_BSP)
        {
-               if(time > self.lastground + 0.1)
+               if(time > this.lastground + 0.1)
                {
-                       _sound(self, CH_TRIGGER, self.noise, VOL_BASE, ATTEN_NORM);
-                       self.lastground = time;
+                       _sound(this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
+                       this.lastground = time;
                }
-               if(vlen(self.velocity) && !self.cnt)
-                       self.nextthink = time + autocvar_g_nexball_delay_idle;
+               if(this.velocity && !this.cnt)
+                       this.nextthink = time + autocvar_g_nexball_delay_idle;
                return;
        }
-       if (!IS_PLAYER(other))
+       if (!IS_PLAYER(toucher))
                return;
-       if(other.health < 1)
+       if(toucher.health < 1)
                return;
-       if(!self.cnt)
-               self.nextthink = time + autocvar_g_nexball_delay_idle;
+       if(!this.cnt)
+               this.nextthink = time + autocvar_g_nexball_delay_idle;
 
-       self.pusher = other;
-       self.team = other.team;
+       this.pusher = toucher;
+       this.team = toucher.team;
 
        if(autocvar_g_nexball_football_physics == -1)   // MrBougo try 1, before decompiling Rev's original
        {
-               if(vlen(other.velocity))
-                       self.velocity = other.velocity * 1.5 + '0 0 1' * autocvar_g_nexball_football_boost_up;
+               if(toucher.velocity)
+                       this.velocity = toucher.velocity * 1.5 + '0 0 1' * autocvar_g_nexball_football_boost_up;
        }
        else if(autocvar_g_nexball_football_physics == 1)         // MrBougo's modded Rev style: partially independant of the height of the aiming point
        {
-               makevectors(other.v_angle);
-               self.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + '0 0 1' * autocvar_g_nexball_football_boost_up;
+               makevectors(toucher.v_angle);
+               this.velocity = toucher.velocity + v_forward * autocvar_g_nexball_football_boost_forward + '0 0 1' * autocvar_g_nexball_football_boost_up;
        }
        else if(autocvar_g_nexball_football_physics == 2)         // 2nd mod try: totally independant. Really playable!
        {
-               makevectors(other.v_angle.y * '0 1 0');
-               self.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
+               makevectors(toucher.v_angle.y * '0 1 0');
+               this.velocity = toucher.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
        }
        else     // Revenant's original style (from the original mod's disassembly, acknowledged by Revenant)
        {
-               makevectors(other.v_angle);
-               self.velocity = other.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
+               makevectors(toucher.v_angle);
+               this.velocity = toucher.velocity + v_forward * autocvar_g_nexball_football_boost_forward + v_up * autocvar_g_nexball_football_boost_up;
        }
-       self.avelocity = -250 * v_forward;  // maybe there is a way to make it look better?
+       this.avelocity = -250 * v_forward;  // maybe there is a way to make it look better?
 }
 
-void basketball_touch(entity this)
+void basketball_touch(entity this, entity toucher)
 {
-       if(other.ballcarried)
+       if(toucher.ballcarried)
        {
-               football_touch(this);
+               football_touch(this, toucher);
                return;
        }
-       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(!this.cnt && IS_PLAYER(toucher) && !STAT(FROZEN, toucher) && !IS_DEAD(toucher) && (toucher != this.nb_dropper || time > this.nb_droptime + autocvar_g_nexball_delay_collect))
        {
-               if(other.health <= 0)
+               if(toucher.health <= 0)
                        return;
-               LogNB("caught", other);
-               GiveBall(other, self);
+               LogNB("caught", toucher);
+               GiveBall(toucher, this);
        }
-       else if(other.solid == SOLID_BSP)
+       else if(toucher.solid == SOLID_BSP)
        {
-               _sound(self, CH_TRIGGER, self.noise, VOL_BASE, ATTEN_NORM);
-               if(vlen(self.velocity) && !self.cnt)
-                       self.nextthink = min(time + autocvar_g_nexball_delay_idle, self.teamtime);
+               _sound(this, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NORM);
+               if(this.velocity && !this.cnt)
+                       this.nextthink = min(time + autocvar_g_nexball_delay_idle, this.teamtime);
        }
 }
 
-void GoalTouch(entity this)
+void GoalTouch(entity this, entity toucher)
 {
        entity ball;
        float isclient, pscore, otherteam;
        string pname;
 
        if(gameover) return;
-       if((self.spawnflags & GOAL_TOUCHPLAYER) && other.ballcarried)
-               ball = other.ballcarried;
+       if((this.spawnflags & GOAL_TOUCHPLAYER) && toucher.ballcarried)
+               ball = toucher.ballcarried;
        else
-               ball = other;
+               ball = toucher;
        if(ball.classname != "nexball_basketball")
                if(ball.classname != "nexball_football")
                        return;
-       if((!ball.pusher && self.team != GOAL_OUT) || ball.cnt)
+       if((!ball.pusher && this.team != GOAL_OUT) || ball.cnt)
                return;
-       EXACTTRIGGER_TOUCH;
+       EXACTTRIGGER_TOUCH(this, toucher);
 
 
-       if(nb_teams == 2)
+       if(NumTeams(nb_teams) == 2)
                otherteam = OtherTeam(ball.team);
        else
                otherteam = 0;
@@ -386,25 +385,25 @@ void GoalTouch(entity this)
        else
                pname = "Someone (?)";
 
-       if(ball.team == self.team)               //owngoal (regular goals)
+       if(ball.team == this.team)               //owngoal (regular goals)
        {
                LogNB("owngoal", ball.pusher);
                bprint("Boo! ", pname, "^7 scored a goal against their own team!\n");
                pscore = -1;
        }
-       else if(self.team == GOAL_FAULT)
+       else if(this.team == GOAL_FAULT)
        {
                LogNB("fault", ball.pusher);
-               if(nb_teams == 2)
+               if(NumTeams(nb_teams) == 2)
                        bprint(Team_ColoredFullName(otherteam), " gets a point due to ", pname, "^7's silliness.\n");
                else
                        bprint(Team_ColoredFullName(ball.team), " loses a point due to ", pname, "^7's silliness.\n");
                pscore = -1;
        }
-       else if(self.team == GOAL_OUT)
+       else if(this.team == GOAL_OUT)
        {
                LogNB("out", ball.pusher);
-               if((self.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
+               if((this.spawnflags & GOAL_TOUCHPLAYER) && ball.owner)
                        bprint(pname, "^7 went out of bounds.\n");
                else
                        bprint("The ball was returned.\n");
@@ -412,16 +411,16 @@ void GoalTouch(entity this)
        }
        else                                                       //score
        {
-               LogNB(strcat("goal:", ftos(self.team)), ball.pusher);
+               LogNB(strcat("goal:", ftos(this.team)), ball.pusher);
                bprint("Goaaaaal! ", pname, "^7 scored a point for the ", Team_ColoredFullName(ball.team), ".\n");
                pscore = 1;
        }
 
-       _sound(ball, CH_TRIGGER, self.noise, VOL_BASE, ATTEN_NONE);
+       _sound(ball, CH_TRIGGER, this.noise, VOL_BASE, ATTEN_NONE);
 
        if(ball.team && pscore)
        {
-               if(nb_teams == 2 && pscore < 0)
+               if(NumTeams(nb_teams) == 2 && pscore < 0)
                        TeamScore_AddToTeam(otherteam, ST_NEXBALL_GOALS, -pscore);
                else
                        TeamScore_AddToTeam(ball.team, ST_NEXBALL_GOALS, pscore);
@@ -443,7 +442,7 @@ void GoalTouch(entity this)
        setthink(ball, ResetBall);
        if(ball.classname == "nexball_basketball")
                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);
+       ball.nextthink = time + autocvar_g_nexball_delay_goal * (this.team != GOAL_OUT);
 }
 
 //=======================//
@@ -453,7 +452,7 @@ spawnfunc(nexball_team)
 {
        if(!g_nexball)
        {
-               remove(this);
+               delete(this);
                return;
        }
        this.team = this.cnt + 1;
@@ -461,19 +460,19 @@ spawnfunc(nexball_team)
 
 void nb_spawnteam(string teamname, float teamcolor)
 {
-       LOG_TRACE("^2spawned team ", teamname, "\n");
+       LOG_TRACE("^2spawned team ", teamname);
        entity e = new(nexball_team);
        e.netname = teamname;
        e.cnt = teamcolor;
        e.team = e.cnt + 1;
-       nb_teams += 1;
+       //nb_teams += 1;
 }
 
 void nb_spawnteams()
 {
        bool t_red = false, t_blue = false, t_yellow = false, t_pink = false;
        entity e;
-       for(e = world; (e = find(e, classname, "nexball_goal"));)
+       for(e = NULL; (e = find(e, classname, "nexball_goal"));)
        {
                switch(e.team)
                {
@@ -481,6 +480,7 @@ void nb_spawnteams()
                        if(!t_red)
                        {
                                nb_spawnteam("Red", e.team-1)   ;
+                               nb_teams |= BIT(0);
                                t_red = true;
                        }
                        break;
@@ -489,6 +489,7 @@ void nb_spawnteams()
                        {
                                nb_spawnteam("Blue", e.team-1)  ;
                                t_blue = true;
+                               nb_teams |= BIT(1);
                        }
                        break;
                case NUM_TEAM_3:
@@ -496,6 +497,7 @@ void nb_spawnteams()
                        {
                                nb_spawnteam("Yellow", e.team-1);
                                t_yellow = true;
+                               nb_teams |= BIT(2);
                        }
                        break;
                case NUM_TEAM_4:
@@ -503,6 +505,7 @@ void nb_spawnteams()
                        {
                                nb_spawnteam("Pink", e.team-1)  ;
                                t_pink = true;
+                               nb_teams |= BIT(3);
                        }
                        break;
                }
@@ -511,7 +514,7 @@ void nb_spawnteams()
 
 void nb_delayedinit(entity this)
 {
-       if(find(world, classname, "nexball_team") == world)
+       if(find(NULL, classname, "nexball_team") == NULL)
                nb_spawnteams();
        nb_ScoreRules(nb_teams);
 }
@@ -523,7 +526,7 @@ void nb_delayedinit(entity this)
 
 void SpawnBall(entity this)
 {
-       if(!g_nexball) { remove(this); return; }
+       if(!g_nexball) { delete(this); return; }
 
 //     balls += 4; // using the remaining bits to count balls will leave more than the max edict count, so it's fine
 
@@ -549,7 +552,13 @@ void SpawnBall(entity this)
                this.glow_trail = true;
        }
 
-       this.movetype = MOVETYPE_FLY;
+       set_movetype(this, MOVETYPE_FLY);
+
+       if(autocvar_g_nexball_playerclip_collisions)
+       {
+               this.dphitcontentsmask = DPCONTENTS_BODY | DPCONTENTS_SOLID | DPCONTENTS_PLAYERCLIP;
+               this.dphitcontentsmask |= DPCONTENTS_PLAYERCLIP;
+       }
 
        if(!autocvar_g_nexball_sound_bounce)
                this.noise = "";
@@ -609,11 +618,10 @@ spawnfunc(nexball_football)
        SpawnBall(this);
 }
 
-float nb_Goal_Customize()
-{SELFPARAM();
-       entity e, wp_owner;
-       e = WaypointSprite_getviewentity(other);
-       wp_owner = self.owner;
+bool nb_Goal_Customize(entity this, entity client)
+{
+       entity e = WaypointSprite_getviewentity(client);
+       entity wp_owner = this.owner;
        if(SAME_TEAM(e, wp_owner)) { return false; }
 
        return true;
@@ -621,7 +629,7 @@ float nb_Goal_Customize()
 
 void SpawnGoal(entity this)
 {
-       if(!g_nexball) { remove(this); return; }
+       if(!g_nexball) { delete(this); return; }
 
        EXACTTRIGGER_INIT;
 
@@ -629,7 +637,7 @@ void SpawnGoal(entity this)
        {
                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;
+               setcefc(this.sprite, nb_Goal_Customize);
        }
 
        this.classname = "nexball_goal";
@@ -730,46 +738,46 @@ void W_Nexball_Think(entity this)
        this.nextthink = time;
 }
 
-void W_Nexball_Touch(entity this)
+void W_Nexball_Touch(entity this, entity toucher)
 {
        entity ball, attacker;
        attacker = this.owner;
        //this.think = func_null;
-       //this.enemy = world;
+       //this.enemy = NULL;
 
-       PROJECTILE_TOUCH(this);
-       if(attacker.team != other.team || autocvar_g_nexball_basketball_teamsteal)
-               if((ball = other.ballcarried) && !STAT(FROZEN, other) && !IS_DEAD(other) && (IS_PLAYER(attacker)))
+       PROJECTILE_TOUCH(this, toucher);
+       if(attacker.team != toucher.team || autocvar_g_nexball_basketball_teamsteal)
+               if((ball = toucher.ballcarried) && !STAT(FROZEN, toucher) && !IS_DEAD(toucher) && (IS_PLAYER(attacker)))
                {
-                       other.velocity = other.velocity + normalize(this.velocity) * other.damageforcescale * autocvar_g_balance_nexball_secondary_force;
-                       UNSET_ONGROUND(other);
+                       toucher.velocity = toucher.velocity + normalize(this.velocity) * toucher.damageforcescale * autocvar_g_balance_nexball_secondary_force;
+                       UNSET_ONGROUND(toucher);
                        if(!attacker.ballcarried)
                        {
                                LogNB("stole", attacker);
-                               _sound(other, CH_TRIGGER, ball.noise2, VOL_BASE, ATTEN_NORM);
+                               _sound(toucher, CH_TRIGGER, ball.noise2, VOL_BASE, ATTEN_NORM);
 
-                               if(SAME_TEAM(attacker, other) && time > attacker.teamkill_complain)
+                               if(SAME_TEAM(attacker, toucher) && time > attacker.teamkill_complain)
                                {
                                        attacker.teamkill_complain = time + 5;
                                        attacker.teamkill_soundtime = time + 0.4;
-                                       attacker.teamkill_soundsource = other;
+                                       attacker.teamkill_soundsource = toucher;
                                }
 
-                               GiveBall(attacker, other.ballcarried);
+                               GiveBall(attacker, toucher.ballcarried);
                        }
                }
-       remove(this);
+       delete(this);
 }
 
-void W_Nexball_Attack(entity actor, float t)
+void W_Nexball_Attack(entity actor, .entity weaponentity, float t)
 {
        entity ball;
        float mul, mi, ma;
        if(!(ball = actor.ballcarried))
                return;
 
-       W_SetupShot(actor, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0);
-       tracebox(w_shotorg, BALL_MINS, BALL_MAXS, w_shotorg, MOVE_WORLDONLY, world);
+       W_SetupShot(actor, weaponentity, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0);
+       tracebox(w_shotorg, BALL_MINS, BALL_MAXS, w_shotorg, MOVE_WORLDONLY, NULL);
        if(trace_startsolid)
        {
                if(actor.metertime)
@@ -791,7 +799,7 @@ void W_Nexball_Attack(entity actor, float t)
                mul = mi + (ma - mi) * mul; // range from the minimal power to the maximal power
        }
 
-       DropBall(ball, w_shotorg, W_CalculateProjectileVelocity(actor.velocity, w_shotdir * autocvar_g_balance_nexball_primary_speed * mul, false));
+       DropBall(ball, w_shotorg, W_CalculateProjectileVelocity(actor, actor.velocity, w_shotdir * autocvar_g_balance_nexball_primary_speed * mul, false));
 
 
        //TODO: use the speed_up cvar too ??
@@ -799,12 +807,12 @@ void W_Nexball_Attack(entity actor, float t)
 
 vector trigger_push_calculatevelocity(vector org, entity tgt, float ht);
 
-void W_Nexball_Attack2(entity actor)
+void W_Nexball_Attack2(entity actor, .entity weaponentity)
 {
        if(actor.ballcarried.enemy)
        {
                entity _ball = actor.ballcarried;
-               W_SetupShot(actor, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0);
+               W_SetupShot(actor, weaponentity, false, 4, SND_NB_SHOOT1, CH_WEAPON_A, 0);
                DropBall(_ball, w_shotorg, trigger_push_calculatevelocity(_ball.origin, _ball.enemy, 32));
                setthink(_ball, W_Nexball_Think);
                _ball.nextthink = time;
@@ -814,12 +822,12 @@ void W_Nexball_Attack2(entity actor)
        if(!autocvar_g_nexball_tackling)
                return;
 
-       W_SetupShot(actor, false, 2, SND_NB_SHOOT2, CH_WEAPON_A, 0);
+       W_SetupShot(actor, weaponentity, false, 2, SND_NB_SHOOT2, CH_WEAPON_A, 0);
        entity missile = new(ballstealer);
 
        missile.owner = actor;
 
-       missile.movetype = MOVETYPE_FLY;
+       set_movetype(missile, MOVETYPE_FLY);
        PROJECTILE_MAKETRIGGER(missile);
 
        //setmodel(missile, "models/elaser.mdl");  // precision set below
@@ -834,32 +842,34 @@ void W_Nexball_Attack2(entity actor)
 
        missile.effects = EF_BRIGHTFIELD | EF_LOWPRECISION;
        missile.flags = FL_PROJECTILE;
+       IL_PUSH(g_projectiles, missile);
+       IL_PUSH(g_bot_dodge, missile);
 
        CSQCProjectile(missile, true, PROJECTILE_ELECTRO, true);
 }
 
-float ball_customize()
-{SELFPARAM();
-       if(!self.owner)
+bool ball_customize(entity this, entity client)
+{
+       if(!this.owner)
        {
-               self.effects &= ~EF_FLAME;
-               self.scale = 1;
-               self.customizeentityforclient = func_null;
+               this.effects &= ~EF_FLAME;
+               this.scale = 1;
+               setcefc(this, func_null);
                return true;
        }
 
-       if(other == self.owner)
+       if(client == this.owner)
        {
-               self.scale = autocvar_g_nexball_viewmodel_scale;
-               if(self.enemy)
-                       self.effects |= EF_FLAME;
+               this.scale = autocvar_g_nexball_viewmodel_scale;
+               if(this.enemy)
+                       this.effects |= EF_FLAME;
                else
-                       self.effects &= ~EF_FLAME;
+                       this.effects &= ~EF_FLAME;
        }
        else
        {
-               self.effects &= ~EF_FLAME;
-               self.scale = 1;
+               this.effects &= ~EF_FLAME;
+               this.scale = 1;
        }
 
        return true;
@@ -879,37 +889,37 @@ METHOD(BallStealer, wr_think, void(BallStealer thiswep, entity actor, .entity we
             }
             else
             {
-                W_Nexball_Attack(actor, -1);
+                W_Nexball_Attack(actor, weaponentity, -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(actor);
+            W_Nexball_Attack2(actor, weaponentity);
             weapon_thinkf(actor, weaponentity, WFRAME_FIRE2, autocvar_g_balance_nexball_secondary_animtime, w_ready);
         }
 
     if(!(fire & 1) && actor.metertime && actor.ballcarried)
     {
-        W_Nexball_Attack(actor, time - actor.metertime);
+        W_Nexball_Attack(actor, weaponentity, time - actor.metertime);
         // DropBall or stealing will set metertime back to 0
         weapon_thinkf(actor, weaponentity, WFRAME_FIRE1, autocvar_g_balance_nexball_primary_animtime, w_ready);
     }
 }
 
-METHOD(BallStealer, wr_setup, void(BallStealer this, entity actor))
+METHOD(BallStealer, wr_setup, void(BallStealer this, entity actor, .entity weaponentity))
 {
     TC(BallStealer, this);
     //weapon_setup(WEP_PORTO.m_id);
 }
 
-METHOD(BallStealer, wr_checkammo1, bool(BallStealer this, entity actor))
+METHOD(BallStealer, wr_checkammo1, bool(BallStealer this, entity actor, .entity weaponentity))
 {
     TC(BallStealer, this);
     return true;
 }
 
-METHOD(BallStealer, wr_checkammo2, bool(BallStealer this, entity actor))
+METHOD(BallStealer, wr_checkammo2, bool(BallStealer this, entity actor, .entity weaponentity))
 {
     TC(BallStealer, this);
     return true;
@@ -922,63 +932,69 @@ void nb_DropBall(entity player)
 }
 
 MUTATOR_HOOKFUNCTION(nb, ClientDisconnect)
-{SELFPARAM();
-       nb_DropBall(self);
-       return false;
+{
+       entity player = M_ARGV(0, entity);
+
+       nb_DropBall(player);
 }
 
 MUTATOR_HOOKFUNCTION(nb, PlayerDies)
 {
+       entity frag_target = M_ARGV(2, entity);
+
        nb_DropBall(frag_target);
-       return false;
 }
 
 MUTATOR_HOOKFUNCTION(nb, MakePlayerObserver)
-{SELFPARAM();
-       nb_DropBall(self);
+{
+       entity player = M_ARGV(0, entity);
+
+       nb_DropBall(player);
        return false;
 }
 
 MUTATOR_HOOKFUNCTION(nb, PlayerPreThink)
-{SELFPARAM();
-       makevectors(self.v_angle);
+{
+       entity player = M_ARGV(0, entity);
+
+       makevectors(player.v_angle);
        if(nexball_mode & NBM_BASKETBALL)
        {
-               if(self.ballcarried)
+               if(player.ballcarried)
                {
                        // 'view ball'
-                       self.ballcarried.velocity = self.velocity;
-                       self.ballcarried.customizeentityforclient = ball_customize;
+                       player.ballcarried.velocity = player.velocity;
+                       setcefc(player.ballcarried, ball_customize);
 
-                       vector org = self.origin + self.view_ofs +
+                       vector org = player.origin + player.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;
-                       setorigin(self.ballcarried, org);
+                       setorigin(player.ballcarried, org);
 
                        // 'safe passing'
                        if(autocvar_g_nexball_safepass_maxdist)
                        {
-                               if(self.ballcarried.wait < time && self.ballcarried.enemy)
+                               if(player.ballcarried.wait < time && player.ballcarried.enemy)
                                {
-                                       //centerprint(self, sprintf("Lost lock on %s", self.ballcarried.enemy.netname));
-                                       self.ballcarried.enemy = world;
+                                       //centerprint(player, sprintf("Lost lock on %s", player.ballcarried.enemy.netname));
+                                       player.ballcarried.enemy = NULL;
                                }
 
 
-                               //tracebox(self.origin + self.view_ofs, '-2 -2 -2', '2 2 2', self.origin + self.view_ofs + v_forward * autocvar_g_nexball_safepass_maxdist);
-                               crosshair_trace(self);
+                               //tracebox(player.origin + player.view_ofs, '-2 -2 -2', '2 2 2', player.origin + player.view_ofs + v_forward * autocvar_g_nexball_safepass_maxdist);
+                               crosshair_trace(player);
                                if( trace_ent &&
                                        IS_CLIENT(trace_ent) &&
                                        !IS_DEAD(trace_ent) &&
-                                       trace_ent.team == self.team &&
-                                       vlen(trace_ent.origin - self.origin) <= autocvar_g_nexball_safepass_maxdist )
+                                       trace_ent.team == player.team &&
+                                       vdist(trace_ent.origin - player.origin, <=, autocvar_g_nexball_safepass_maxdist) )
                                {
 
-                                       //if(self.ballcarried.enemy != trace_ent)
-                                       //      centerprint(self, sprintf("Locked to %s", trace_ent.netname));
-                                       self.ballcarried.enemy = trace_ent;
-                                       self.ballcarried.wait = time + autocvar_g_nexball_safepass_holdtime;
+                                       //if(player.ballcarried.enemy != trace_ent)
+                                       //      centerprint(player, sprintf("Locked to %s", trace_ent.netname));
+                                       player.ballcarried.enemy = trace_ent;
+                                       player.ballcarried.wait = time + autocvar_g_nexball_safepass_holdtime;
 
 
                                }
@@ -986,43 +1002,51 @@ MUTATOR_HOOKFUNCTION(nb, PlayerPreThink)
                }
                else
                {
-                       .entity weaponentity = weaponentities[0]; // TODO
-                       if(self.(weaponentity).weapons)
+                       for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
                        {
-                               self.weapons = self.(weaponentity).weapons;
-                               Weapon w = WEP_NEXBALL;
-                               w.wr_resetplayer(w, self);
-                               PS(self).m_switchweapon = self.(weaponentity).m_switchweapon;
-                               W_SwitchWeapon(self, PS(self).m_switchweapon);
+                               .entity weaponentity = weaponentities[slot];
 
-                               self.(weaponentity).weapons = '0 0 0';
+                               if(player.(weaponentity).weapons)
+                               {
+                                       player.weapons = player.(weaponentity).weapons;
+                                       Weapon w = WEP_NEXBALL;
+                                       w.wr_resetplayer(w, player);
+                                       player.(weaponentity).m_switchweapon = player.m_switchweapon;
+                                       W_SwitchWeapon(player, player.(weaponentity).m_switchweapon, weaponentity);
+
+                                       player.(weaponentity).weapons = '0 0 0';
+                               }
                        }
                }
 
        }
 
-       nexball_setstatus(self);
-
-       return false;
+       nexball_setstatus(player);
 }
 
 MUTATOR_HOOKFUNCTION(nb, SpectateCopy)
 {
-       SELFPARAM();
-       this.metertime = other.metertime;
+       entity spectatee = M_ARGV(0, entity);
+       entity client = M_ARGV(1, entity);
+
+       client.metertime = spectatee.metertime;
 }
 
 MUTATOR_HOOKFUNCTION(nb, PlayerSpawn)
 {
-       SELFPARAM();
-       this.metertime = 0;
-       .entity weaponentity = weaponentities[0];
-       this.(weaponentity).weapons = '0 0 0';
+       entity player = M_ARGV(0, entity);
+
+       player.metertime = 0;
+       for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
+       {
+               .entity weaponentity = weaponentities[slot];
+               player.(weaponentity).weapons = '0 0 0';
+       }
 
        if (nexball_mode & NBM_BASKETBALL)
-               this.weapons |= WEPSET(NEXBALL);
+               player.weapons |= WEPSET(NEXBALL);
        else
-               this.weapons = '0 0 0';
+               player.weapons = '0 0 0';
 
        return false;
 }
@@ -1031,48 +1055,70 @@ MUTATOR_HOOKFUNCTION(nb, PlayerSpawn)
 .float stat_sv_maxspeed;
 
 MUTATOR_HOOKFUNCTION(nb, PlayerPhysics)
-{SELFPARAM();
-       if(self.ballcarried)
+{
+       entity player = M_ARGV(0, entity);
+
+       if(player.ballcarried)
        {
-               self.stat_sv_airspeedlimit_nonqw *= autocvar_g_nexball_basketball_carrier_highspeed;
-               self.stat_sv_maxspeed *= autocvar_g_nexball_basketball_carrier_highspeed;
+               player.stat_sv_airspeedlimit_nonqw *= autocvar_g_nexball_basketball_carrier_highspeed;
+               player.stat_sv_maxspeed *= autocvar_g_nexball_basketball_carrier_highspeed;
        }
-       return false;
 }
 
 MUTATOR_HOOKFUNCTION(nb, ForbidThrowCurrentWeapon)
-{SELFPARAM();
-       return PS(self).m_weapon == WEP_NEXBALL;
+{
+       //entity player = M_ARGV(0, entity);
+       entity wepent = M_ARGV(1, entity);
+
+       return wepent.m_weapon == WEP_NEXBALL;
 }
 
 MUTATOR_HOOKFUNCTION(nb, ForbidDropCurrentWeapon)
-{SELFPARAM();
-       return PS(self).m_weapon == WEP_MORTAR; // TODO: what is this for?
+{
+       //entity player = M_ARGV(0, entity);
+       int wep = M_ARGV(1, int);
+
+       return wep == WEP_MORTAR.m_id; // TODO: what is this for?
 }
 
 MUTATOR_HOOKFUNCTION(nb, FilterItem)
-{SELFPARAM();
-       if(self.classname == "droppedweapon")
-       if(self.weapon == WEP_NEXBALL.m_id)
+{
+       entity item = M_ARGV(0, entity);
+
+       if(item.classname == "droppedweapon")
+       if(item.weapon == WEP_NEXBALL.m_id)
                return true;
 
        return false;
 }
 
-MUTATOR_HOOKFUNCTION(nb, GetTeamCount)
+MUTATOR_HOOKFUNCTION(nb, ItemTouch)
+{
+       entity item = M_ARGV(0, entity);
+       entity toucher = M_ARGV(1, entity);
+
+       if(item.weapon && toucher.ballcarried)
+               return MUT_ITEMTOUCH_RETURN; // no new weapons for you, mister!
+
+       return MUT_ITEMTOUCH_CONTINUE;
+}
+
+MUTATOR_HOOKFUNCTION(nb, CheckAllowedTeams)
 {
-       ret_string = "nexball_team";
+       M_ARGV(1, string) = "nexball_team";
        return true;
 }
 
 MUTATOR_HOOKFUNCTION(nb, WantWeapon)
 {
-       ret_float = 0; // weapon is set a few lines later, apparently
+       M_ARGV(1, float) = 0; // weapon is set a few lines later, apparently
        return true;
 }
 
 MUTATOR_HOOKFUNCTION(nb, DropSpecialItems)
 {
+       entity frag_target = M_ARGV(0, entity);
+
        if(frag_target.ballcarried)
                DropBall(frag_target.ballcarried, frag_target.origin, frag_target.velocity);
 
@@ -1081,8 +1127,7 @@ MUTATOR_HOOKFUNCTION(nb, DropSpecialItems)
 
 MUTATOR_HOOKFUNCTION(nb, SendWaypoint)
 {
-       wp_sendflags &= ~0x80;
-       return false;
+       M_ARGV(2, int) &= ~0x80;
 }
 
 REGISTER_MUTATOR(nb, g_nexball)
@@ -1103,7 +1148,7 @@ REGISTER_MUTATOR(nb, g_nexball)
                */
                radar_showennemies = autocvar_g_nexball_radar_showallplayers;
 
-               InitializeEntity(world, nb_delayedinit, INITPRIO_GAMETYPE);
+               InitializeEntity(NULL, nb_delayedinit, INITPRIO_GAMETYPE);
                WEP_NEXBALL.spawnflags &= ~WEP_FLAG_MUTATORBLOCKED;
 
                ActivateTeamplay();
@@ -1129,4 +1174,3 @@ REGISTER_MUTATOR(nb, g_nexball)
 }
 
 #endif
-#endif