]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/physics.qc
Kill the use of self in movetype code, to make it usable from the player physics...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / physics.qc
index b3db77143b375f4bdb315e22a1a3c0d057aecd38..aab87365408e9c139caf783d20b0b69fec6b6e7d 100644 (file)
@@ -1,6 +1,5 @@
 #include "physics.qh"
-#include "triggers/trigger/swamp.qh"
-#include "triggers/trigger/jumppads.qh"
+#include "triggers/include.qh"
 #include "viewloc.qh"
 
 #ifdef SVQC
 // client side physics
 bool Physics_Valid(string thecvar)
 {
-       if(!autocvar_g_physics_clientselect) { return false; }
-
-       string l = strcat(" ", autocvar_g_physics_clientselect_options, " ");
-
-       if(strstrofs(l, strcat(" ", thecvar, " "), 0) >= 0)
-               return true;
-
-       return false;
+       return autocvar_g_physics_clientselect && strhasword(autocvar_g_physics_clientselect_options, thecvar);
 }
 
 float Physics_ClientOption(entity pl, string option)
 {
        if(Physics_Valid(pl.cvar_cl_physics))
        {
-               string var = sprintf("g_physics_%s_%s", pl.cvar_cl_physics, option);
-               if(cvar_type(var) & CVAR_TYPEFLAG_EXISTS)
-                       return cvar(var);
+               string s = sprintf("g_physics_%s_%s", pl.cvar_cl_physics, option);
+               if(cvar_type(s) & CVAR_TYPEFLAG_EXISTS)
+                       return cvar(s);
        }
        if(autocvar_g_physics_clientselect && autocvar_g_physics_clientselect_default)
        {
-               string var = sprintf("g_physics_%s_%s", autocvar_g_physics_clientselect_default, option);
-               if(cvar_type(var) & CVAR_TYPEFLAG_EXISTS)
-                       return cvar(var);
+               string s = sprintf("g_physics_%s_%s", autocvar_g_physics_clientselect_default, option);
+               if(cvar_type(s) & CVAR_TYPEFLAG_EXISTS)
+                       return cvar(s);
        }
        return cvar(strcat("sv_", option));
 }
@@ -78,10 +70,8 @@ void Physics_AddStats()
        addstat(STAT_JETPACK_MAXSPEED_SIDE, AS_FLOAT, stat_jetpack_maxspeed_side);
 
        // hack to fix track_canjump
-       addstat(STAT_MOVEVARS_TRACK_CANJUMP, AS_INT, cvar_cl_movement_track_canjump);
-
-       // double jump
-       addstat(STAT_DOUBLEJUMP, AS_INT, stat_doublejump);
+       addstat(STAT_MOVEVARS_CL_TRACK_CANJUMP, AS_INT, cvar_cl_movement_track_canjump);
+       addstat(STAT_MOVEVARS_TRACK_CANJUMP, AS_INT, stat_sv_track_canjump);
 
        // jump speed caps
        addstat(STAT_MOVEVARS_JUMPSPEEDCAP_DISABLE_ONRAMPS, AS_INT, stat_jumpspeedcap_disable_onramps);
@@ -136,8 +126,6 @@ void Physics_UpdateStats(float maxspd_mod)
        self.stat_sv_maxspeed = Physics_ClientOption(self, "maxspeed") * maxspd_mod; // also slow walking
        self.stat_movement_highspeed = PHYS_HIGHSPEED; // TODO: remove this!
 
-       self.stat_doublejump = PHYS_DOUBLEJUMP;
-
        self.stat_jetpack_antigravity = PHYS_JETPACK_ANTIGRAVITY;
        self.stat_jetpack_accel_up = PHYS_JETPACK_ACCEL_UP;
        self.stat_jetpack_accel_side = PHYS_JETPACK_ACCEL_SIDE;
@@ -175,6 +163,8 @@ void Physics_UpdateStats(float maxspd_mod)
        self.stat_sv_airstopaccelerate = Physics_ClientOption(self, "airstopaccelerate");
        self.stat_sv_jumpvelocity = Physics_ClientOption(self, "jumpvelocity");
 
+       self.stat_sv_track_canjump = Physics_ClientOption(self, "track_canjump");
+
        self.stat_gameplayfix_upvelocityclearsonground = UPWARD_VELOCITY_CLEARS_ONGROUND;
 }
 #endif
@@ -197,119 +187,119 @@ float GeomLerp(float a, float lerp, float b)
 
 noref float pmove_waterjumptime;
 
-const float unstick_count = 27;
-vector unstick_offsets[unstick_count] =
+#define unstick_offsets(X) \
+/* 1 no nudge (just return the original if this test passes) */ \
+       X(' 0.000  0.000  0.000') \
+/* 6 simple nudges */ \
+       X(' 0.000  0.000  0.125') X('0.000  0.000 -0.125') \
+       X('-0.125  0.000  0.000') X('0.125  0.000  0.000') \
+       X(' 0.000 -0.125  0.000') X('0.000  0.125  0.000') \
+/* 4 diagonal flat nudges */ \
+       X('-0.125 -0.125  0.000') X('0.125 -0.125  0.000') \
+       X('-0.125  0.125  0.000') X('0.125  0.125  0.000') \
+/* 8 diagonal upward nudges */ \
+       X('-0.125  0.000  0.125') X('0.125  0.000  0.125') \
+       X(' 0.000 -0.125  0.125') X('0.000  0.125  0.125') \
+       X('-0.125 -0.125  0.125') X('0.125 -0.125  0.125') \
+       X('-0.125  0.125  0.125') X('0.125  0.125  0.125') \
+/* 8 diagonal downward nudges */ \
+       X('-0.125  0.000 -0.125') X('0.125  0.000 -0.125') \
+       X(' 0.000 -0.125 -0.125') X('0.000  0.125 -0.125') \
+       X('-0.125 -0.125 -0.125') X('0.125 -0.125 -0.125') \
+       X('-0.125  0.125 -0.125') X('0.125  0.125 -0.125') \
+/**/
+
+void PM_ClientMovement_Unstick(entity this)
 {
-// 1 no nudge (just return the original if this test passes)
-       '0.000   0.000  0.000',
-// 6 simple nudges
-       ' 0.000  0.000  0.125', '0.000  0.000 -0.125',
-       '-0.125  0.000  0.000', '0.125  0.000  0.000',
-       ' 0.000 -0.125  0.000', '0.000  0.125  0.000',
-// 4 diagonal flat nudges
-       '-0.125 -0.125  0.000', '0.125 -0.125  0.000',
-       '-0.125  0.125  0.000', '0.125  0.125  0.000',
-// 8 diagonal upward nudges
-       '-0.125  0.000  0.125', '0.125  0.000  0.125',
-       ' 0.000 -0.125  0.125', '0.000  0.125  0.125',
-       '-0.125 -0.125  0.125', '0.125 -0.125  0.125',
-       '-0.125  0.125  0.125', '0.125  0.125  0.125',
-// 8 diagonal downward nudges
-       '-0.125  0.000 -0.125', '0.125  0.000 -0.125',
-       ' 0.000 -0.125 -0.125', '0.000  0.125 -0.125',
-       '-0.125 -0.125 -0.125', '0.125 -0.125 -0.125',
-       '-0.125  0.125 -0.125', '0.125  0.125 -0.125',
-};
-
-void PM_ClientMovement_Unstick()
-{SELFPARAM();
-       float i;
-       for (i = 0; i < unstick_count; i++)
-       {
-               vector neworigin = unstick_offsets[i] + self.origin;
-               tracebox(neworigin, PL_CROUCH_MIN, PL_CROUCH_MAX, neworigin, MOVE_NORMAL, self);
-               if (!trace_startsolid)
-               {
-                       setorigin(self, neworigin);
-                       return;// true;
-               }
+       #define X(unstick_offset) \
+       { \
+               vector neworigin = unstick_offset + this.origin; \
+               tracebox(neworigin, PL_CROUCH_MIN, PL_CROUCH_MAX, neworigin, MOVE_NORMAL, this); \
+               if (!trace_startsolid) \
+               { \
+                       setorigin(this, neworigin); \
+                       return; \
+               } \
        }
+       unstick_offsets(X);
+       #undef X
 }
 
-void PM_ClientMovement_UpdateStatus(bool ground)
-{SELFPARAM();
+void PM_ClientMovement_UpdateStatus(entity this, bool ground)
+{
        // make sure player is not stuck
-       PM_ClientMovement_Unstick();
+       PM_ClientMovement_Unstick(this);
 
        // set crouched
-       if (PHYS_INPUT_BUTTON_CROUCH(self))
+       if (PHYS_INPUT_BUTTON_CROUCH(this))
        {
-               // wants to crouch, this always works..
-               if (!IS_DUCKED(self))
-                       SET_DUCKED(self);
+               // wants to crouch, this always works
+               if (!IS_DUCKED(this)) SET_DUCKED(this);
        }
        else
        {
-               // wants to stand, if currently crouching we need to check for a
-               // low ceiling first
-               if (IS_DUCKED(self))
+               // wants to stand, if currently crouching we need to check for a low ceiling first
+               if (IS_DUCKED(this))
                {
-                       tracebox(self.origin, PL_MIN, PL_MAX, self.origin, MOVE_NORMAL, self);
-                       if (!trace_startsolid)
-                               UNSET_DUCKED(self);
+                       tracebox(this.origin, PL_MIN, PL_MAX, this.origin, MOVE_NORMAL, this);
+                       if (!trace_startsolid) UNSET_DUCKED(this);
                }
        }
 
        // set onground
-       vector origin1 = self.origin + '0 0 1';
-       vector origin2 = self.origin - '0 0 1';
+       vector origin1 = this.origin + '0 0 1';
+       vector origin2 = this.origin - '0 0 1';
 
-       if(ground)
+       if (ground)
        {
-               tracebox(origin1, self.mins, self.maxs, origin2, MOVE_NORMAL, self);
-               if (trace_fraction < 1.0 && trace_plane_normal_z > 0.7)
+               tracebox(origin1, this.mins, this.maxs, origin2, MOVE_NORMAL, this);
+               if (trace_fraction < 1.0 && trace_plane_normal.z > 0.7)
                {
-                       SET_ONGROUND(self);
+                       SET_ONGROUND(this);
 
                        // this code actually "predicts" an impact; so let's clip velocity first
-                       float f = self.velocity * trace_plane_normal;
-                       self.velocity -= f * trace_plane_normal;
+                       this.velocity -= this.velocity * trace_plane_normal * trace_plane_normal;
                }
                else
-                       UNSET_ONGROUND(self);
+                       UNSET_ONGROUND(this);
        }
 
        // set watertype/waterlevel
-       origin1 = self.origin;
-       origin1_z += self.mins_z + 1;
-       self.waterlevel = WATERLEVEL_NONE;
+       origin1 = this.origin;
+       origin1.z += this.mins_z + 1;
+       this.waterlevel = WATERLEVEL_NONE;
 
        int thepoint = pointcontents(origin1);
 
-       self.watertype = (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME);
+       this.watertype = (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME);
 
-       if(self.watertype)
+       if (this.watertype)
        {
-               self.waterlevel = WATERLEVEL_WETFEET;
-               origin1_z = self.origin_z + (self.mins_z + self.maxs_z) * 0.5;
+               this.waterlevel = WATERLEVEL_WETFEET;
+               origin1.z = this.origin.z + (this.mins.z + this.maxs.z) * 0.5;
                thepoint = pointcontents(origin1);
-               if(thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME)
+               if (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME)
                {
-                       self.waterlevel = WATERLEVEL_SWIMMING;
-                       origin1_z = self.origin_z + 22;
+                       this.waterlevel = WATERLEVEL_SWIMMING;
+                       origin1.z = this.origin.z + 22;
                        thepoint = pointcontents(origin1);
-                       if(thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME)
-                               self.waterlevel = WATERLEVEL_SUBMERGED;
+                       if (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME)
+                               this.waterlevel = WATERLEVEL_SUBMERGED;
                }
        }
 
-       if(IS_ONGROUND(self) || self.velocity_z <= 0 || pmove_waterjumptime <= 0)
+       if (IS_ONGROUND(this) || this.velocity.z <= 0 || pmove_waterjumptime <= 0)
                pmove_waterjumptime = 0;
 }
 
-void PM_ClientMovement_Move()
-{SELFPARAM();
+void PM_ClientMovement_Move(entity this)
+{
 #ifdef CSQC
+
+       PM_ClientMovement_UpdateStatus(this, false);
+       if(autocvar_cl_movement == 3)
+               return;
+
        int bump;
        float t;
        float f;
@@ -328,13 +318,11 @@ void PM_ClientMovement_Move()
        vector trace2_plane_normal = '0 0 0';
        vector trace3_plane_normal = '0 0 0';
 
-
-       PM_ClientMovement_UpdateStatus(false);
-       primalvelocity = self.velocity;
-       for(bump = 0, t = PHYS_INPUT_TIMELENGTH; bump < 8 && (self.velocity * self.velocity) > 0; bump++)
+       primalvelocity = this.velocity;
+       for(bump = 0, t = PHYS_INPUT_TIMELENGTH; bump < 8 && (this.velocity * this.velocity) > 0; bump++)
        {
-               neworigin = self.origin + t * self.velocity;
-               tracebox(self.origin, self.mins, self.maxs, neworigin, MOVE_NORMAL, self);
+               neworigin = this.origin + t * this.velocity;
+               tracebox(this.origin, this.mins, this.maxs, neworigin, MOVE_NORMAL, this);
                trace1_endpos = trace_endpos;
                trace1_fraction = trace_fraction;
                trace1_plane_normal = trace_plane_normal;
@@ -342,11 +330,11 @@ void PM_ClientMovement_Move()
                {
                        // may be a step or wall, try stepping up
                        // first move forward at a higher level
-                       currentorigin2 = self.origin;
+                       currentorigin2 = this.origin;
                        currentorigin2_z += PHYS_STEPHEIGHT;
                        neworigin2 = neworigin;
                        neworigin2_z += PHYS_STEPHEIGHT;
-                       tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self);
+                       tracebox(currentorigin2, this.mins, this.maxs, neworigin2, MOVE_NORMAL, this);
                        trace2_endpos = trace_endpos;
                        trace2_fraction = trace_fraction;
                        trace2_plane_normal = trace_plane_normal;
@@ -355,8 +343,8 @@ void PM_ClientMovement_Move()
                                // then move down from there
                                currentorigin2 = trace2_endpos;
                                neworigin2 = trace2_endpos;
-                               neworigin2_z = self.origin_z;
-                               tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self);
+                               neworigin2_z = this.origin_z;
+                               tracebox(currentorigin2, this.mins, this.maxs, neworigin2, MOVE_NORMAL, this);
                                trace3_endpos = trace_endpos;
                                trace3_fraction = trace_fraction;
                                trace3_plane_normal = trace_plane_normal;
@@ -373,7 +361,7 @@ void PM_ClientMovement_Move()
 
                // check if it moved at all
                if(trace1_fraction >= 0.001)
-                       setorigin(self, trace1_endpos);
+                       setorigin(this, trace1_endpos);
 
                // check if it moved all the way
                if(trace1_fraction == 1)
@@ -384,15 +372,15 @@ void PM_ClientMovement_Move()
                // this got commented out in a change that supposedly makes the code match QW better
                // so if this is broken, maybe put it in an if(cls.protocol != PROTOCOL_QUAKEWORLD) block
                if(trace1_plane_normal_z > 0.7)
-                       SET_ONGROUND(self);
+                       SET_ONGROUND(this);
 
                t -= t * trace1_fraction;
 
-               f = (self.velocity * trace1_plane_normal);
-               self.velocity = self.velocity + -f * trace1_plane_normal;
+               f = (this.velocity * trace1_plane_normal);
+               this.velocity = this.velocity + -f * trace1_plane_normal;
        }
        if(pmove_waterjumptime > 0)
-               self.velocity = primalvelocity;
+               this.velocity = primalvelocity;
 #endif
 }
 
@@ -540,7 +528,7 @@ When you press the jump key
 returns true if handled
 =============
 */
-bool PlayerJump (void)
+bool PlayerJump ()
 {SELFPARAM();
        if (PHYS_FROZEN(self))
                return true; // no jumping in freezetag when frozen
@@ -552,35 +540,13 @@ bool PlayerJump (void)
 
        bool doublejump = false;
        float mjumpheight = PHYS_JUMPVELOCITY;
-#ifdef CSQC
-       player_multijump = doublejump;
-       player_jumpheight = mjumpheight;
-#endif
 
-       if (MUTATOR_CALLHOOK(PlayerJump, doublejump, mjumpheight)
-#ifdef CSQC
-               || PM_multijump_checkjump()
-#endif
-               ) { return true; }
+       if (MUTATOR_CALLHOOK(PlayerJump, doublejump, mjumpheight))
+               return true;
 
        doublejump = player_multijump;
        mjumpheight = player_jumpheight;
 
-       if (PHYS_DOUBLEJUMP)
-       {
-               tracebox(self.origin + '0 0 0.01', self.mins, self.maxs, self.origin - '0 0 0.01', MOVE_NORMAL, self);
-               if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
-               {
-                       doublejump = true;
-
-                       // we MUST clip velocity here!
-                       float f;
-                       f = self.velocity * trace_plane_normal;
-                       if (f < 0)
-                               self.velocity -= f * trace_plane_normal;
-               }
-       }
-
        if (self.waterlevel >= WATERLEVEL_SWIMMING)
        {
                self.velocity_z = PHYS_MAXSPEED(self) * 0.7;
@@ -591,7 +557,11 @@ bool PlayerJump (void)
                if (!IS_ONGROUND(self))
                        return IS_JUMP_HELD(self);
 
-       if (PHYS_TRACK_CANJUMP(self))
+       bool track_jump = PHYS_CL_TRACK_CANJUMP(self);
+       if(PHYS_TRACK_CANJUMP(self))
+               track_jump = true;
+
+       if (track_jump)
                if (IS_JUMP_HELD(self))
                        return true;
 
@@ -694,8 +664,6 @@ void CheckWaterJump()
        #define JETPACK_JUMP(s) autocvar_cl_jetpack_jump
 #endif
 .float jetpack_stopped;
-// Hack: shouldn't need to know about this
-.float multijump_count;
 void CheckPlayerJump()
 {SELFPARAM();
 #ifdef SVQC
@@ -706,7 +674,7 @@ void CheckPlayerJump()
 
        if(PHYS_INPUT_BUTTON_JUMP(self) || PHYS_INPUT_BUTTON_JETPACK(self))
        {
-               float air_jump = !PlayerJump() || self.multijump_count > 0; // PlayerJump() has important side effects
+               float air_jump = !PlayerJump() || player_multijump; // PlayerJump() has important side effects
                float activate = JETPACK_JUMP(self) && air_jump && PHYS_INPUT_BUTTON_JUMP(self) || PHYS_INPUT_BUTTON_JETPACK(self);
                float has_fuel = !PHYS_JETPACK_FUEL || PHYS_AMMO_FUEL(self) || ITEMS_STAT(self) & IT_UNLIMITED_WEAPON_AMMO;
 
@@ -756,235 +724,14 @@ float racecar_angle(float forward, float down)
                return ret * angle_mult;
 }
 
-void RaceCarPhysics()
-{SELFPARAM();
-#ifdef SVQC
-       // using this move type for "big rigs"
-       // the engine does not push the entity!
-
-       vector rigvel;
-
-       vector angles_save = self.angles;
-       float accel = bound(-1, self.movement.x / PHYS_MAXSPEED(self), 1);
-       float steer = bound(-1, self.movement.y / PHYS_MAXSPEED(self), 1);
-
-       if (g_bugrigs_reverse_speeding)
-       {
-               if (accel < 0)
-               {
-                       // back accel is DIGITAL
-                       // to prevent speedhack
-                       if (accel < -0.5)
-                               accel = -1;
-                       else
-                               accel = 0;
-               }
-       }
-
-       self.angles_x = 0;
-       self.angles_z = 0;
-       makevectors(self.angles); // new forward direction!
-
-       if (IS_ONGROUND(self) || g_bugrigs_air_steering)
-       {
-               float myspeed = self.velocity * v_forward;
-               float upspeed = self.velocity * v_up;
-
-               // responsiveness factor for steering and acceleration
-               float f = 1 / (1 + pow(max(-myspeed, myspeed) / g_bugrigs_speed_ref, g_bugrigs_speed_pow));
-               //MAXIMA: f(v) := 1 / (1 + (v / g_bugrigs_speed_ref) ^ g_bugrigs_speed_pow);
-
-               float steerfactor;
-               if (myspeed < 0 && g_bugrigs_reverse_spinning)
-                       steerfactor = -myspeed * g_bugrigs_steer;
-               else
-                       steerfactor = -myspeed * f * g_bugrigs_steer;
-
-               float accelfactor;
-               if (myspeed < 0 && g_bugrigs_reverse_speeding)
-                       accelfactor = g_bugrigs_accel;
-               else
-                       accelfactor = f * g_bugrigs_accel;
-               //MAXIMA: accel(v) := f(v) * g_bugrigs_accel;
-
-               if (accel < 0)
-               {
-                       if (myspeed > 0)
-                       {
-                               myspeed = max(0, myspeed - PHYS_INPUT_TIMELENGTH * (g_bugrigs_friction_floor - g_bugrigs_friction_brake * accel));
-                       }
-                       else
-                       {
-                               if (!g_bugrigs_reverse_speeding)
-                                       myspeed = min(0, myspeed + PHYS_INPUT_TIMELENGTH * g_bugrigs_friction_floor);
-                       }
-               }
-               else
-               {
-                       if (myspeed >= 0)
-                       {
-                               myspeed = max(0, myspeed - PHYS_INPUT_TIMELENGTH * g_bugrigs_friction_floor);
-                       }
-                       else
-                       {
-                               if (g_bugrigs_reverse_stopping)
-                                       myspeed = 0;
-                               else
-                                       myspeed = min(0, myspeed + PHYS_INPUT_TIMELENGTH * (g_bugrigs_friction_floor + g_bugrigs_friction_brake * accel));
-                       }
-               }
-               // terminal velocity = velocity at which 50 == accelfactor, that is, 1549 units/sec
-               //MAXIMA: friction(v) := g_bugrigs_friction_floor;
-
-               self.angles_y += steer * PHYS_INPUT_TIMELENGTH * steerfactor; // apply steering
-               makevectors(self.angles); // new forward direction!
-
-               myspeed += accel * accelfactor * PHYS_INPUT_TIMELENGTH;
-
-               rigvel = myspeed * v_forward + '0 0 1' * upspeed;
-       }
-       else
-       {
-               float myspeed = vlen(self.velocity);
-
-               // responsiveness factor for steering and acceleration
-               float f = 1 / (1 + pow(max(0, myspeed / g_bugrigs_speed_ref), g_bugrigs_speed_pow));
-               float steerfactor = -myspeed * f;
-               self.angles_y += steer * PHYS_INPUT_TIMELENGTH * steerfactor; // apply steering
-
-               rigvel = self.velocity;
-               makevectors(self.angles); // new forward direction!
-       }
-
-       rigvel *= max(0, 1 - vlen(rigvel) * g_bugrigs_friction_air * PHYS_INPUT_TIMELENGTH);
-       //MAXIMA: airfriction(v) := v * v * g_bugrigs_friction_air;
-       //MAXIMA: total_acceleration(v) := accel(v) - friction(v) - airfriction(v);
-       //MAXIMA: solve(total_acceleration(v) = 0, v);
-
-       if (g_bugrigs_planar_movement)
-       {
-               vector rigvel_xy, neworigin, up;
-               float mt;
-
-               rigvel_z -= PHYS_INPUT_TIMELENGTH * PHYS_GRAVITY; // 4x gravity plays better
-               rigvel_xy = vec2(rigvel);
-
-               if (g_bugrigs_planar_movement_car_jumping)
-                       mt = MOVE_NORMAL;
-               else
-                       mt = MOVE_NOMONSTERS;
-
-               tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 1024', mt, self);
-               up = trace_endpos - self.origin;
-
-               // BUG RIGS: align the move to the surface instead of doing collision testing
-               // can we move?
-               tracebox(trace_endpos, self.mins, self.maxs, trace_endpos + rigvel_xy * PHYS_INPUT_TIMELENGTH, mt, self);
-
-               // align to surface
-               tracebox(trace_endpos, self.mins, self.maxs, trace_endpos - up + '0 0 1' * rigvel_z * PHYS_INPUT_TIMELENGTH, mt, self);
-
-               if (trace_fraction < 0.5)
-               {
-                       trace_fraction = 1;
-                       neworigin = self.origin;
-               }
-               else
-                       neworigin = trace_endpos;
-
-               if (trace_fraction < 1)
-               {
-                       // now set angles_x so that the car points parallel to the surface
-                       self.angles = vectoangles(
-                                       '1 0 0' * v_forward_x * trace_plane_normal_z
-                                       +
-                                       '0 1 0' * v_forward_y * trace_plane_normal_z
-                                       +
-                                       '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y)
-                                       );
-                       SET_ONGROUND(self);
-               }
-               else
-               {
-                       // now set angles_x so that the car points forward, but is tilted in velocity direction
-                       UNSET_ONGROUND(self);
-               }
-
-               self.velocity = (neworigin - self.origin) * (1.0 / PHYS_INPUT_TIMELENGTH);
-               self.movetype = MOVETYPE_NOCLIP;
-       }
-       else
-       {
-               rigvel_z -= PHYS_INPUT_TIMELENGTH * PHYS_GRAVITY; // 4x gravity plays better
-               self.velocity = rigvel;
-               self.movetype = MOVETYPE_FLY;
-       }
-
-       trace_fraction = 1;
-       tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 4', MOVE_NORMAL, self);
-       if (trace_fraction != 1)
-       {
-               self.angles = vectoangles2(
-                               '1 0 0' * v_forward_x * trace_plane_normal_z
-                               +
-                               '0 1 0' * v_forward_y * trace_plane_normal_z
-                               +
-                               '0 0 1' * -(v_forward_x * trace_plane_normal_x + v_forward_y * trace_plane_normal_y),
-                               trace_plane_normal
-                               );
-       }
-       else
-       {
-               vector vel_local;
-
-               vel_local_x = v_forward * self.velocity;
-               vel_local_y = v_right * self.velocity;
-               vel_local_z = v_up * self.velocity;
-
-               self.angles_x = racecar_angle(vel_local_x, vel_local_z);
-               self.angles_z = racecar_angle(-vel_local_y, vel_local_z);
-       }
-
-       // smooth the angles
-       vector vf1, vu1, smoothangles;
-       makevectors(self.angles);
-       float f = bound(0, PHYS_INPUT_TIMELENGTH * g_bugrigs_angle_smoothing, 1);
-       if (f == 0)
-               f = 1;
-       vf1 = v_forward * f;
-       vu1 = v_up * f;
-       makevectors(angles_save);
-       vf1 = vf1 + v_forward * (1 - f);
-       vu1 = vu1 + v_up * (1 - f);
-       smoothangles = vectoangles2(vf1, vu1);
-       self.angles_x = -smoothangles_x;
-       self.angles_z =  smoothangles_z;
-#endif
-}
-
 string specialcommand = "xwxwxsxsxaxdxaxdx1x ";
 .float specialcommand_pos;
 void SpecialCommand()
 {
 #ifdef SVQC
-#ifdef TETRIS
-       TetrisImpulse();
-#else
        if (!CheatImpulse(99))
                LOG_INFO("A hollow voice says \"Plugh\".\n");
 #endif
-#endif
-}
-
-void PM_check_race_movetime(void)
-{SELFPARAM();
-#ifdef SVQC
-       self.race_movetime_frac += PHYS_INPUT_TIMELENGTH;
-       float f = floor(self.race_movetime_frac);
-       self.race_movetime_frac -= f;
-       self.race_movetime_count += f;
-       self.race_movetime = self.race_movetime_frac + self.race_movetime_count;
-#endif
 }
 
 float PM_check_specialcommand(float buttons)
@@ -1024,7 +771,7 @@ float PM_check_specialcommand(float buttons)
        return false;
 }
 
-void PM_check_nickspam(void)
+void PM_check_nickspam()
 {SELFPARAM();
 #ifdef SVQC
        if (time >= self.nickspamtime)
@@ -1069,20 +816,8 @@ void PM_check_punch()
 #endif
 }
 
-void PM_check_spider(void)
-{SELFPARAM();
-#ifdef SVQC
-       if (time >= self.spider_slowness)
-               return;
-       PHYS_MAXSPEED(self) *= 0.5; // half speed while slow from spider
-       PHYS_MAXAIRSPEED(self) *= 0.5;
-       PHYS_AIRSPEEDLIMIT_NONQW(self) *= 0.5;
-       PHYS_AIRSTRAFEACCELERATE(self) *= 0.5;
-#endif
-}
-
 // predict frozen movement, as frozen players CAN move in some cases
-void PM_check_frozen(void)
+void PM_check_frozen()
 {SELFPARAM();
        if (!PHYS_FROZEN(self))
                return;
@@ -1112,31 +847,23 @@ void PM_check_frozen(void)
 void PM_check_hitground()
 {SELFPARAM();
 #ifdef SVQC
-       if (IS_ONGROUND(self))
-       if (IS_PLAYER(self)) // no fall sounds for observers thank you very much
-       if (self.wasFlying)
-       {
-               self.wasFlying = 0;
-               if (self.waterlevel < WATERLEVEL_SWIMMING)
-               if (time >= self.ladder_time)
-               if (!self.hook)
-               {
-                       self.nextstep = time + 0.3 + random() * 0.1;
-                       trace_dphitq3surfaceflags = 0;
-                       tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
-                       if (!(trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS))
-                       {
-                               if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
-                                       GlobalSound(globalsound_metalfall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
-                               else
-                                       GlobalSound(globalsound_fall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
-                       }
-               }
-       }
+       if (!IS_PLAYER(this)) return; // no fall sounds for observers thank you very much
+       if (!IS_ONGROUND(this)) return;
+       if (!this.wasFlying) return;
+    this.wasFlying = false;
+    if (this.waterlevel >= WATERLEVEL_SWIMMING) return;
+    if (time < this.ladder_time) return;
+    if (this.hook) return;
+    this.nextstep = time + 0.3 + random() * 0.1;
+    trace_dphitq3surfaceflags = 0;
+    tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
+    if ((trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS)) return;
+    entity fall = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS) ? GS_FALL_METAL : GS_FALL;
+    GlobalSound(fall, CH_PLAYER, VOICETYPE_PLAYERSOUND);
 #endif
 }
 
-void PM_check_blocked(void)
+void PM_check_blocked()
 {SELFPARAM();
 #ifdef SVQC
        if (!self.player_blocked)
@@ -1146,56 +873,6 @@ void PM_check_blocked(void)
 #endif
 }
 
-#ifdef SVQC
-float speedaward_lastsent;
-float speedaward_lastupdate;
-#endif
-void PM_check_race(void)
-{SELFPARAM();
-#ifdef SVQC
-       if(!(g_cts || g_race))
-               return;
-       if (vlen(self.velocity - self.velocity_z * '0 0 1') > speedaward_speed)
-       {
-               speedaward_speed = vlen(self.velocity - self.velocity_z * '0 0 1');
-               speedaward_holder = self.netname;
-               speedaward_uid = self.crypto_idfp;
-               speedaward_lastupdate = time;
-       }
-       if (speedaward_speed > speedaward_lastsent && time - speedaward_lastupdate > 1)
-       {
-               string rr = (g_cts) ? CTS_RECORD : RACE_RECORD;
-               race_send_speedaward(MSG_ALL);
-               speedaward_lastsent = speedaward_speed;
-               if (speedaward_speed > speedaward_alltimebest && speedaward_uid != "")
-               {
-                       speedaward_alltimebest = speedaward_speed;
-                       speedaward_alltimebest_holder = speedaward_holder;
-                       speedaward_alltimebest_uid = speedaward_uid;
-                       db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/speed"), ftos(speedaward_alltimebest));
-                       db_put(ServerProgsDB, strcat(GetMapname(), rr, "speed/crypto_idfp"), speedaward_alltimebest_uid);
-                       race_send_speedaward_alltimebest(MSG_ALL);
-               }
-       }
-#endif
-}
-
-void PM_check_vortex(void)
-{SELFPARAM();
-#ifdef SVQC
-       // WEAPONTODO
-       float xyspeed = vlen(vec2(self.velocity));
-       if (self.weapon == WEP_VORTEX.m_id && WEP_CVAR(vortex, charge) && WEP_CVAR(vortex, charge_velocity_rate) && xyspeed > WEP_CVAR(vortex, charge_minspeed))
-       {
-               // add a maximum of charge_velocity_rate when going fast (f = 1), gradually increasing from minspeed (f = 0) to maxspeed
-               xyspeed = min(xyspeed, WEP_CVAR(vortex, charge_maxspeed));
-               float f = (xyspeed - WEP_CVAR(vortex, charge_minspeed)) / (WEP_CVAR(vortex, charge_maxspeed) - WEP_CVAR(vortex, charge_minspeed));
-               // add the extra charge
-               self.vortex_charge = min(1, self.vortex_charge + WEP_CVAR(vortex, charge_velocity_rate) * f * PHYS_INPUT_TIMELENGTH);
-       }
-#endif
-}
-
 void PM_fly(float maxspd_mod)
 {SELFPARAM();
        // noclipping or flying
@@ -1214,7 +891,7 @@ void PM_fly(float maxspd_mod)
        if (time >= self.teleport_time)
 #endif
                PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0);
-       PM_ClientMovement_Move();
+       PM_ClientMovement_Move(self);
 }
 
 void PM_swim(float maxspd_mod)
@@ -1297,7 +974,7 @@ void PM_swim(float maxspd_mod)
        }
        // water acceleration
        PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0);
-       PM_ClientMovement_Move();
+       PM_ClientMovement_Move(self);
 }
 
 void PM_ladder(float maxspd_mod)
@@ -1350,7 +1027,7 @@ void PM_ladder(float maxspd_mod)
 #endif
                // water acceleration
                PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE*maxspd_mod, 1, 0, 0, 0);
-       PM_ClientMovement_Move();
+       PM_ClientMovement_Move(self);
 }
 
 void PM_jetpack(float maxspd_mod)
@@ -1458,63 +1135,66 @@ void PM_jetpack(float maxspd_mod)
 
 #ifdef CSQC
        float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
-       if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
-               self.velocity_z -= g * 0.5;
-       else
-               self.velocity_z -= g;
-       PM_ClientMovement_Move();
-       if (!IS_ONGROUND(self) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
+       if(autocvar_cl_movement != 3)
+       {
                if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
                        self.velocity_z -= g * 0.5;
+               else
+                       self.velocity_z -= g;
+       }
+       PM_ClientMovement_Move(self);
+       if(autocvar_cl_movement != 3)
+       {
+               if (!IS_ONGROUND(self) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
+                       if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
+                               self.velocity_z -= g * 0.5;
+       }
 #endif
 }
 
-void PM_walk(float buttons_prev, float maxspd_mod)
-{SELFPARAM();
-       if (!WAS_ONGROUND(self))
+void PM_walk(entity this, float maxspd_mod)
+{
+       if (!WAS_ONGROUND(this))
        {
 #ifdef SVQC
                if (autocvar_speedmeter)
-                       LOG_TRACE(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
+                       LOG_TRACE(strcat("landing velocity: ", vtos(this.velocity), " (abs: ", ftos(vlen(this.velocity)), ")\n"));
 #endif
-               if (self.lastground < time - 0.3)
-                       self.velocity *= (1 - PHYS_FRICTION_ONLAND);
+               if (this.lastground < time - 0.3)
+                       this.velocity *= (1 - PHYS_FRICTION_ONLAND);
 #ifdef SVQC
-               if (self.jumppadcount > 1)
-                       LOG_TRACE(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
-               self.jumppadcount = 0;
+               if (this.jumppadcount > 1)
+                       LOG_TRACE(strcat(ftos(this.jumppadcount), "x jumppad combo\n"));
+               this.jumppadcount = 0;
 #endif
        }
 
        // walking
-       makevectors(self.v_angle.y * '0 1 0');
-       vector wishvel = v_forward * self.movement.x
-                                       + v_right * self.movement.y;
+       makevectors(this.v_angle.y * '0 1 0');
+       const vector wishvel = v_forward * this.movement.x
+                                               + v_right * this.movement.y;
        // acceleration
-       vector wishdir = normalize(wishvel);
+       const vector wishdir = normalize(wishvel);
        float wishspeed = vlen(wishvel);
-
-       wishspeed = min(wishspeed, PHYS_MAXSPEED(self) * maxspd_mod);
-       if (IS_DUCKED(self))
-               wishspeed *= 0.5;
+       wishspeed = min(wishspeed, PHYS_MAXSPEED(this) * maxspd_mod);
+       if (IS_DUCKED(this)) wishspeed *= 0.5;
 
        // apply edge friction
-       float f = vlen(vec2(self.velocity));
-       if (f > 0)
+       const float f2 = vlen2(vec2(this.velocity));
+       if (f2 > 0)
        {
-               float realfriction;
                trace_dphitq3surfaceflags = 0;
-               tracebox(self.origin, self.mins, self.maxs, self.origin - '0 0 1', MOVE_NOMONSTERS, self);
+               tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this);
                // TODO: apply edge friction
                // apply ground friction
-               if(trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK)
-                       realfriction = PHYS_FRICTION_SLICK;
-               else
-                       realfriction = PHYS_FRICTION;
+               const int realfriction = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK)
+                       ? PHYS_FRICTION_SLICK
+                       : PHYS_FRICTION;
 
+               float f = sqrt(f2);
                f = 1 - PHYS_INPUT_TIMELENGTH * realfriction * ((f < PHYS_STOPSPEED) ? (PHYS_STOPSPEED / f) : 1);
                f = max(0, f);
-               self.velocity *= f;
+               this.velocity *= f;
                /*
                   Mathematical analysis time!
 
@@ -1538,20 +1218,28 @@ void PM_walk(float buttons_prev, float maxspd_mod)
                        v >= PHYS_STOPSPEED * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION)
                 */
        }
-       float addspeed = wishspeed - self.velocity * wishdir;
+       const float addspeed = wishspeed - this.velocity * wishdir;
        if (addspeed > 0)
        {
-               float accelspeed = min(PHYS_ACCELERATE * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed);
-               self.velocity += accelspeed * wishdir;
+               const float accelspeed = min(PHYS_ACCELERATE * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed);
+               this.velocity += accelspeed * wishdir;
        }
-       float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
-       if (!(GAMEPLAYFIX_NOGRAVITYONGROUND))
-               self.velocity_z -= g * (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1);
-       if (self.velocity * self.velocity)
-               PM_ClientMovement_Move();
-       if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
-               if (!IS_ONGROUND(self) || !GAMEPLAYFIX_NOGRAVITYONGROUND)
-                       self.velocity_z -= g * 0.5;
+#ifdef CSQC
+       const float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(this) * PHYS_INPUT_TIMELENGTH;
+       if(autocvar_cl_movement != 3)
+       {
+               if (!(GAMEPLAYFIX_NOGRAVITYONGROUND))
+                       this.velocity_z -= g * (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1);
+       }
+       if (vdist(this.velocity, >, 0))
+               PM_ClientMovement_Move(self);
+       if(autocvar_cl_movement != 3)
+       {
+               if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
+                       if (!IS_ONGROUND(this) || !GAMEPLAYFIX_NOGRAVITYONGROUND)
+                               this.velocity_z -= g * 0.5;
+       }
+#endif
 }
 
 void PM_air(float buttons_prev, float maxspd_mod)
@@ -1616,15 +1304,21 @@ void PM_air(float buttons_prev, float maxspd_mod)
                if (PHYS_AIRCONTROL)
                        CPM_PM_Aircontrol(wishdir, wishspeed2);
        }
+#ifdef CSQC
        float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
+       if(autocvar_cl_movement != 3)
        if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
                self.velocity_z -= g * 0.5;
        else
                self.velocity_z -= g;
-       PM_ClientMovement_Move();
+#endif
+       PM_ClientMovement_Move(self);
+#ifdef CSQC
+       if(autocvar_cl_movement != 3)
        if (!IS_ONGROUND(self) || !(GAMEPLAYFIX_NOGRAVITYONGROUND))
                if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
                        self.velocity_z -= g * 0.5;
+#endif
 }
 
 // used for calculating airshots
@@ -1640,25 +1334,25 @@ bool IsFlying(entity a)
        return true;
 }
 
-void PM_Main()
-{SELFPARAM();
-       int buttons = PHYS_INPUT_BUTTON_MASK(self);
+void PM_Main(entity this)
+{
+       int buttons = PHYS_INPUT_BUTTON_MASK(this);
 #ifdef CSQC
-       self.items = getstati(STAT_ITEMS, 0, 24);
+       this.items = getstati(STAT_ITEMS, 0, 24);
 
-       self.movement = PHYS_INPUT_MOVEVALUES(self);
+       this.movement = PHYS_INPUT_MOVEVALUES(this);
 
-       vector oldv_angle = self.v_angle;
-       vector oldangles = self.angles; // we need to save these, as they're abused by other code
-       self.v_angle = PHYS_INPUT_ANGLES(self);
-       self.angles = PHYS_WORLD_ANGLES(self);
+       vector oldv_angle = this.v_angle;
+       vector oldangles = this.angles; // we need to save these, as they're abused by other code
+       this.v_angle = PHYS_INPUT_ANGLES(this);
+       this.angles = PHYS_WORLD_ANGLES(this);
 
-       self.team = myteam + 1; // is this correct?
-       if (!(PHYS_INPUT_BUTTON_JUMP(self))) // !jump
-               UNSET_JUMP_HELD(self); // canjump = true
+       this.team = myteam + 1; // is this correct?
+       if (!(PHYS_INPUT_BUTTON_JUMP(this))) // !jump
+               UNSET_JUMP_HELD(this); // canjump = true
        pmove_waterjumptime -= PHYS_INPUT_TIMELENGTH;
 
-       PM_ClientMovement_UpdateStatus(true);
+       PM_ClientMovement_UpdateStatus(this, true);
 #endif
 
 
@@ -1671,12 +1365,11 @@ void PM_Main()
 #ifdef SVQC
        Physics_UpdateStats(maxspeed_mod);
 
-       if (self.PlayerPhysplug)
-               if (self.PlayerPhysplug())
+       if (this.PlayerPhysplug)
+               if (this.PlayerPhysplug())
                        return;
 #endif
 
-       PM_check_race_movetime();
 #ifdef SVQC
        anticheat_physics();
 #endif
@@ -1686,250 +1379,210 @@ void PM_Main()
 #ifdef SVQC
        if (sv_maxidle > 0)
        {
-               if (buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
-                       self.parm_idlesince = time;
+               if (buttons != this.buttons_old || this.movement != this.movement_old || this.v_angle != this.v_angle_old)
+                       this.parm_idlesince = time;
        }
 #endif
-       int buttons_prev = self.buttons_old;
-       self.buttons_old = buttons;
-       self.movement_old = self.movement;
-       self.v_angle_old = self.v_angle;
+       int buttons_prev = this.buttons_old;
+       this.buttons_old = buttons;
+       this.movement_old = this.movement;
+       this.v_angle_old = this.v_angle;
 
        PM_check_nickspam();
 
        PM_check_punch();
 #ifdef SVQC
-       if (IS_BOT_CLIENT(self))
+       if (IS_BOT_CLIENT(this))
        {
                if (playerdemo_read())
                        return;
                bot_think();
        }
-
-       if (IS_PLAYER(self))
-#endif
-       {
-#ifdef SVQC
-               if (self.race_penalty)
-                       if (time > self.race_penalty)
-                               self.race_penalty = 0;
 #endif
 
-               bool not_allowed_to_move = false;
-#ifdef SVQC
-               if (self.race_penalty)
-                       not_allowed_to_move = true;
-#endif
 #ifdef SVQC
-               if (time < game_starttime)
-                       not_allowed_to_move = true;
-#endif
-
-               if (not_allowed_to_move)
+       if (IS_PLAYER(this))
+       {
+               const bool allowed_to_move = (time >= game_starttime);
+               if (!allowed_to_move)
                {
-                       self.velocity = '0 0 0';
-                       self.movetype = MOVETYPE_NONE;
-#ifdef SVQC
-                       self.disableclientprediction = 2;
-#endif
+                       this.velocity = '0 0 0';
+                       this.movetype = MOVETYPE_NONE;
+                       this.disableclientprediction = 2;
                }
-#ifdef SVQC
-               else if (self.disableclientprediction == 2)
+               else if (this.disableclientprediction == 2)
                {
-                       if (self.movetype == MOVETYPE_NONE)
-                               self.movetype = MOVETYPE_WALK;
-                       self.disableclientprediction = 0;
+                       if (this.movetype == MOVETYPE_NONE)
+                               this.movetype = MOVETYPE_WALK;
+                       this.disableclientprediction = 0;
                }
-#endif
        }
+#endif
 
 #ifdef SVQC
-       if (self.movetype == MOVETYPE_NONE)
+       if (this.movetype == MOVETYPE_NONE)
                return;
 
        // when we get here, disableclientprediction cannot be 2
-       self.disableclientprediction = 0;
+       this.disableclientprediction = 0;
 #endif
 
        viewloc_PlayerPhysics();
 
-       PM_check_spider();
-
        PM_check_frozen();
 
        PM_check_blocked();
 
        maxspeed_mod = 1;
 
-       if (self.in_swamp)
-               maxspeed_mod *= self.swamp_slowdown; //cvar("g_balance_swamp_moverate");
+       if (this.in_swamp)
+               maxspeed_mod *= this.swamp_slowdown; //cvar("g_balance_swamp_moverate");
 
        // conveyors: first fix velocity
-       if (self.conveyor.state)
-               self.velocity -= self.conveyor.movedir;
+       if (this.conveyor.state)
+               this.velocity -= this.conveyor.movedir;
 
-#ifdef SVQC
        MUTATOR_CALLHOOK(PlayerPhysics);
-#endif
-#ifdef CSQC
-       PM_multijump();
-#endif
-
-//     float forcedodge = 1;
-//     if(forcedodge) {
-//#ifdef CSQC
-//             PM_dodging_checkpressedkeys();
-//#endif
-//             PM_dodging();
-//             PM_ClientMovement_Move();
-//             return;
-//     }
 
 #ifdef SVQC
-       if (!IS_PLAYER(self))
+       if (!IS_PLAYER(this))
        {
                maxspeed_mod = autocvar_sv_spectator_speed_multiplier;
-               if (!self.spectatorspeed)
-                       self.spectatorspeed = maxspeed_mod;
-               if (self.impulse && self.impulse <= 19 || (self.impulse >= 200 && self.impulse <= 209) || (self.impulse >= 220 && self.impulse <= 229))
+               if (!this.spectatorspeed)
+                       this.spectatorspeed = maxspeed_mod;
+               if (this.impulse && this.impulse <= 19 || (this.impulse >= 200 && this.impulse <= 209) || (this.impulse >= 220 && this.impulse <= 229))
                {
-                       if (self.lastclassname != "player")
+                       if (this.lastclassname != "player")
                        {
-                               if (self.impulse == 10 || self.impulse == 15 || self.impulse == 18 || (self.impulse >= 200 && self.impulse <= 209))
-                                       self.spectatorspeed = bound(1, self.spectatorspeed + 0.5, 5);
-                               else if (self.impulse == 11)
-                                       self.spectatorspeed = maxspeed_mod;
-                               else if (self.impulse == 12 || self.impulse == 16  || self.impulse == 19 || (self.impulse >= 220 && self.impulse <= 229))
-                                       self.spectatorspeed = bound(1, self.spectatorspeed - 0.5, 5);
-                               else if (self.impulse >= 1 && self.impulse <= 9)
-                                       self.spectatorspeed = 1 + 0.5 * (self.impulse - 1);
+                               if (this.impulse == 10 || this.impulse == 15 || this.impulse == 18 || (this.impulse >= 200 && this.impulse <= 209))
+                                       this.spectatorspeed = bound(1, this.spectatorspeed + 0.5, 5);
+                               else if (this.impulse == 11)
+                                       this.spectatorspeed = maxspeed_mod;
+                               else if (this.impulse == 12 || this.impulse == 16  || this.impulse == 19 || (this.impulse >= 220 && this.impulse <= 229))
+                                       this.spectatorspeed = bound(1, this.spectatorspeed - 0.5, 5);
+                               else if (this.impulse >= 1 && this.impulse <= 9)
+                                       this.spectatorspeed = 1 + 0.5 * (this.impulse - 1);
                        } // otherwise just clear
-                       self.impulse = 0;
+                       this.impulse = 0;
                }
-               maxspeed_mod = self.spectatorspeed;
+               maxspeed_mod = this.spectatorspeed;
        }
 
-       float spd = max(PHYS_MAXSPEED(self), PHYS_MAXAIRSPEED(self)) * maxspeed_mod;
-       if(self.speed != spd)
+       float spd = max(PHYS_MAXSPEED(this), PHYS_MAXAIRSPEED(this)) * maxspeed_mod;
+       if(this.speed != spd)
        {
-               self.speed = spd;
+               this.speed = spd;
                string temps = ftos(spd);
-               stuffcmd(self, strcat("cl_forwardspeed ", temps, "\n"));
-               stuffcmd(self, strcat("cl_backspeed ", temps, "\n"));
-               stuffcmd(self, strcat("cl_sidespeed ", temps, "\n"));
-               stuffcmd(self, strcat("cl_upspeed ", temps, "\n"));
+               stuffcmd(this, strcat("cl_forwardspeed ", temps, "\n"));
+               stuffcmd(this, strcat("cl_backspeed ", temps, "\n"));
+               stuffcmd(this, strcat("cl_sidespeed ", temps, "\n"));
+               stuffcmd(this, strcat("cl_upspeed ", temps, "\n"));
        }
 
-       if(self.stat_jumpspeedcap_min != PHYS_JUMPSPEEDCAP_MIN)
+       if(this.stat_jumpspeedcap_min != PHYS_JUMPSPEEDCAP_MIN)
        {
-               self.stat_jumpspeedcap_min = PHYS_JUMPSPEEDCAP_MIN;
-               stuffcmd(self, strcat("cl_jumpspeedcap_min ", PHYS_JUMPSPEEDCAP_MIN, "\n"));
+               this.stat_jumpspeedcap_min = PHYS_JUMPSPEEDCAP_MIN;
+               stuffcmd(this, strcat("cl_jumpspeedcap_min ", PHYS_JUMPSPEEDCAP_MIN, "\n"));
        }
-       if(self.stat_jumpspeedcap_max != PHYS_JUMPSPEEDCAP_MAX)
+       if(this.stat_jumpspeedcap_max != PHYS_JUMPSPEEDCAP_MAX)
        {
-               self.stat_jumpspeedcap_min = PHYS_JUMPSPEEDCAP_MAX;
-               stuffcmd(self, strcat("cl_jumpspeedcap_max ", PHYS_JUMPSPEEDCAP_MAX, "\n"));
+               this.stat_jumpspeedcap_min = PHYS_JUMPSPEEDCAP_MAX;
+               stuffcmd(this, strcat("cl_jumpspeedcap_max ", PHYS_JUMPSPEEDCAP_MAX, "\n"));
        }
 #endif
 
-       if(PHYS_DEAD(self))
+       if(PHYS_DEAD(this))
        {
                // handle water here
-               vector midpoint = ((self.absmin + self.absmax) * 0.5);
+               vector midpoint = ((this.absmin + this.absmax) * 0.5);
                if(pointcontents(midpoint) == CONTENT_WATER)
                {
-                       self.velocity = self.velocity * 0.5;
+                       this.velocity = this.velocity * 0.5;
 
                        // do we want this?
                        //if(pointcontents(midpoint + '0 0 2') == CONTENT_WATER)
-                               //{ self.velocity_z = 70; }
+                               //{ this.velocity_z = 70; }
                }
                goto end;
        }
 
 #ifdef SVQC
-       if (!self.fixangle && !g_bugrigs)
-               self.angles = '0 1 0' * self.v_angle.y;
+       if (!this.fixangle)
+               this.angles = '0 1 0' * this.v_angle.y;
 #endif
 
        PM_check_hitground();
 
-       if(IsFlying(self))
-               self.wasFlying = 1;
+       if(IsFlying(this))
+               this.wasFlying = 1;
 
-       if (IS_PLAYER(self))
+       if (IS_PLAYER(this))
                CheckPlayerJump();
 
-       if (self.flags & FL_WATERJUMP)
+       if (this.flags & FL_WATERJUMP)
        {
-               self.velocity_x = self.movedir_x;
-               self.velocity_y = self.movedir_y;
-               if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
+               this.velocity_x = this.movedir.x;
+               this.velocity_y = this.movedir.y;
+               if (time > this.teleport_time || this.waterlevel == WATERLEVEL_NONE)
                {
-                       self.flags &= ~FL_WATERJUMP;
-                       self.teleport_time = 0;
+                       this.flags &= ~FL_WATERJUMP;
+                       this.teleport_time = 0;
                }
        }
 
-#ifdef SVQC
-       else if (g_bugrigs && IS_PLAYER(self))
-               RaceCarPhysics();
-#endif
+       else if (MUTATOR_CALLHOOK(PM_Physics, maxspeed_mod))
+               { }
 
-       else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_FLY_WORLDONLY || (BUFFS_STAT(self) & BUFF_FLIGHT.m_itemid))
+       else if (this.movetype == MOVETYPE_NOCLIP || this.movetype == MOVETYPE_FLY || this.movetype == MOVETYPE_FLY_WORLDONLY || MUTATOR_CALLHOOK(IsFlying, this))
                PM_fly(maxspeed_mod);
 
-       else if (self.waterlevel >= WATERLEVEL_SWIMMING)
+       else if (this.waterlevel >= WATERLEVEL_SWIMMING)
                PM_swim(maxspeed_mod);
 
-       else if (time < self.ladder_time)
+       else if (time < this.ladder_time)
                PM_ladder(maxspeed_mod);
 
-       else if (ITEMS_STAT(self) & IT_USING_JETPACK)
+       else if (ITEMS_STAT(this) & IT_USING_JETPACK)
                PM_jetpack(maxspeed_mod);
 
-       else if (IS_ONGROUND(self))
-               PM_walk(buttons_prev, maxspeed_mod);
+       else if (IS_ONGROUND(this))
+               PM_walk(this, maxspeed_mod);
 
        else
                PM_air(buttons_prev, maxspeed_mod);
 
-#ifdef SVQC
-       if (!IS_OBSERVER(self))
-               PM_check_race();
-#endif
-       PM_check_vortex();
-
 :end
-       if (IS_ONGROUND(self))
-               self.lastground = time;
+       if (IS_ONGROUND(this))
+               this.lastground = time;
 
        // conveyors: then break velocity again
-       if(self.conveyor.state)
-               self.velocity += self.conveyor.movedir;
+       if(this.conveyor.state)
+               this.velocity += this.conveyor.movedir;
 
-       self.lastflags = self.flags;
+       this.lastflags = this.flags;
 
-       self.lastclassname = self.classname;
+       this.lastclassname = this.classname;
 
 #ifdef CSQC
-       self.v_angle = oldv_angle;
-       self.angles = oldangles;
+       this.v_angle = oldv_angle;
+       this.angles = oldangles;
 #endif
 }
 
-#ifdef SVQC
-void SV_PlayerPhysics(void)
+#if defined(SVQC)
+void SV_PlayerPhysics()
 #elif defined(CSQC)
-void CSQC_ClientMovement_PlayerMove_Frame(void)
+void CSQC_ClientMovement_PlayerMove_Frame(entity this)
 #endif
-{SELFPARAM();
-       PM_Main();
-
+{
+#ifdef SVQC
+       SELFPARAM();
+#endif
+       PM_Main(this);
 #ifdef CSQC
-       self.pmove_flags =
-                       ((self.flags & FL_DUCKED) ? PMF_DUCKED : 0) |
-                       (!(self.flags & FL_JUMPRELEASED) ? 0 : PMF_JUMP_HELD) |
-                       ((self.flags & FL_ONGROUND) ? PMF_ONGROUND : 0);
+       this.pmove_flags =
+                       ((this.flags & FL_DUCKED) ? PMF_DUCKED : 0) |
+                       (!(this.flags & FL_JUMPRELEASED) ? PMF_JUMP_HELD : 0) |
+                       ((this.flags & FL_ONGROUND) ? PMF_ONGROUND : 0);
 #endif
 }