]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/physics.qc
Revert "Merge branch 'TimePath/bot_api' into 'master'\r"
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / physics.qc
index ad5bc16c1888ccf092590191a91dcfa929130288..1a799c8de79c903edef70a5db80115bc103d657b 100644 (file)
@@ -1,13 +1,67 @@
 #include "physics.qh"
 #include "triggers/trigger/swamp.qh"
 #include "triggers/trigger/jumppads.qh"
+#include "viewloc.qh"
 
 #ifdef SVQC
 
 #include "../server/miscfunctions.qh"
+#include "triggers/trigger/viewloc.qh"
+
+// 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;
+}
+
+float Physics_ClientOption(entity pl, string option)
+{
+       if(Physics_Valid(pl.cvar_cl_physics))
+       {
+               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 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));
+}
 
 void Physics_AddStats()
 {
+       // static view offset and hitbox vectors
+       // networked for all you bandwidth pigs out there
+       addstat(STAT_PL_VIEW_OFS1, AS_FLOAT, stat_pl_view_ofs_x);
+       addstat(STAT_PL_VIEW_OFS2, AS_FLOAT, stat_pl_view_ofs_y);
+       addstat(STAT_PL_VIEW_OFS3, AS_FLOAT, stat_pl_view_ofs_z);
+       addstat(STAT_PL_CROUCH_VIEW_OFS1, AS_FLOAT, stat_pl_crouch_view_ofs_x);
+       addstat(STAT_PL_CROUCH_VIEW_OFS2, AS_FLOAT, stat_pl_crouch_view_ofs_y);
+       addstat(STAT_PL_CROUCH_VIEW_OFS3, AS_FLOAT, stat_pl_crouch_view_ofs_z);
+
+       addstat(STAT_PL_MIN1, AS_FLOAT, stat_pl_min_x);
+       addstat(STAT_PL_MIN2, AS_FLOAT, stat_pl_min_y);
+       addstat(STAT_PL_MIN3, AS_FLOAT, stat_pl_min_z);
+       addstat(STAT_PL_MAX1, AS_FLOAT, stat_pl_max_x);
+       addstat(STAT_PL_MAX2, AS_FLOAT, stat_pl_max_y);
+       addstat(STAT_PL_MAX3, AS_FLOAT, stat_pl_max_z);
+       addstat(STAT_PL_CROUCH_MIN1, AS_FLOAT, stat_pl_crouch_min_x);
+       addstat(STAT_PL_CROUCH_MIN2, AS_FLOAT, stat_pl_crouch_min_y);
+       addstat(STAT_PL_CROUCH_MIN3, AS_FLOAT, stat_pl_crouch_min_z);
+       addstat(STAT_PL_CROUCH_MAX1, AS_FLOAT, stat_pl_crouch_max_x);
+       addstat(STAT_PL_CROUCH_MAX2, AS_FLOAT, stat_pl_crouch_max_y);
+       addstat(STAT_PL_CROUCH_MAX3, AS_FLOAT, stat_pl_crouch_max_z);
+
        // g_movementspeed hack
        addstat(STAT_MOVEVARS_AIRSPEEDLIMIT_NONQW, AS_FLOAT, stat_sv_airspeedlimit_nonqw);
        addstat(STAT_MOVEVARS_MAXSPEED, AS_FLOAT, stat_sv_maxspeed);
@@ -30,25 +84,56 @@ void Physics_AddStats()
        addstat(STAT_DOUBLEJUMP, AS_INT, stat_doublejump);
 
        // jump speed caps
-       addstat(STAT_MOVEVARS_JUMPSPEEDCAP_MIN, AS_FLOAT, stat_jumpspeedcap_min);
-       addstat(STAT_MOVEVARS_JUMPSPEEDCAP_MIN, AS_FLOAT, stat_jumpspeedcap_min);
        addstat(STAT_MOVEVARS_JUMPSPEEDCAP_DISABLE_ONRAMPS, AS_INT, stat_jumpspeedcap_disable_onramps);
 
        // hacks
        addstat(STAT_MOVEVARS_FRICTION_ONLAND, AS_FLOAT, stat_sv_friction_on_land);
        addstat(STAT_MOVEVARS_FRICTION_SLICK, AS_FLOAT, stat_sv_friction_slick);
        addstat(STAT_GAMEPLAYFIX_EASIERWATERJUMP, AS_INT, stat_gameplayfix_easierwaterjump);
+
+       // new properties
+       addstat(STAT_MOVEVARS_JUMPVELOCITY, AS_FLOAT, stat_sv_jumpvelocity);
+       addstat(STAT_MOVEVARS_AIRACCEL_QW_STRETCHFACTOR, AS_FLOAT, stat_sv_airaccel_qw_stretchfactor);
+       addstat(STAT_MOVEVARS_MAXAIRSTRAFESPEED, AS_FLOAT, stat_sv_maxairstrafespeed);
+       addstat(STAT_MOVEVARS_MAXAIRSPEED, AS_FLOAT, stat_sv_maxairspeed);
+       addstat(STAT_MOVEVARS_AIRSTRAFEACCELERATE, AS_FLOAT, stat_sv_airstrafeaccelerate);
+       addstat(STAT_MOVEVARS_WARSOWBUNNY_TURNACCEL, AS_FLOAT, stat_sv_warsowbunny_turnaccel);
+       addstat(STAT_MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION, AS_FLOAT, stat_sv_airaccel_sideways_friction);
+       addstat(STAT_MOVEVARS_AIRCONTROL, AS_FLOAT, stat_sv_aircontrol);
+       addstat(STAT_MOVEVARS_AIRCONTROL_POWER, AS_FLOAT, stat_sv_aircontrol_power);
+       addstat(STAT_MOVEVARS_AIRCONTROL_PENALTY, AS_FLOAT, stat_sv_aircontrol_penalty);
+       addstat(STAT_MOVEVARS_WARSOWBUNNY_AIRFORWARDACCEL, AS_FLOAT, stat_sv_warsowbunny_airforwardaccel);
+       addstat(STAT_MOVEVARS_WARSOWBUNNY_TOPSPEED, AS_FLOAT, stat_sv_warsowbunny_topspeed);
+       addstat(STAT_MOVEVARS_WARSOWBUNNY_ACCEL, AS_FLOAT, stat_sv_warsowbunny_accel);
+       addstat(STAT_MOVEVARS_WARSOWBUNNY_BACKTOSIDERATIO, AS_FLOAT, stat_sv_warsowbunny_backtosideratio);
+       addstat(STAT_MOVEVARS_FRICTION, AS_FLOAT, stat_sv_friction);
+       addstat(STAT_MOVEVARS_ACCELERATE, AS_FLOAT, stat_sv_accelerate);
+       addstat(STAT_MOVEVARS_STOPSPEED, AS_FLOAT, stat_sv_stopspeed);
+       addstat(STAT_MOVEVARS_AIRACCELERATE, AS_FLOAT, stat_sv_airaccelerate);
+       addstat(STAT_MOVEVARS_AIRSTOPACCELERATE, AS_FLOAT, stat_sv_airstopaccelerate);
+
+       addstat(STAT_GAMEPLAYFIX_UPVELOCITYCLEARSONGROUND, AS_INT, stat_gameplayfix_upvelocityclearsonground);
 }
 
 void Physics_UpdateStats(float maxspd_mod)
-{
-       self.stat_sv_airaccel_qw = AdjustAirAccelQW(autocvar_sv_airaccel_qw, maxspd_mod);
-       if (autocvar_sv_airstrafeaccel_qw)
-               self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(autocvar_sv_airstrafeaccel_qw, maxspd_mod);
+{SELFPARAM();
+       // blah
+       self.stat_pl_view_ofs = PL_VIEW_OFS;
+       self.stat_pl_crouch_view_ofs = PL_CROUCH_VIEW_OFS;
+
+       self.stat_pl_min = PL_MIN;
+       self.stat_pl_max = PL_MAX;
+       self.stat_pl_crouch_min = PL_CROUCH_MIN;
+       self.stat_pl_crouch_max = PL_CROUCH_MAX;
+
+
+       self.stat_sv_airaccel_qw = AdjustAirAccelQW(Physics_ClientOption(self, "airaccel_qw"), maxspd_mod);
+       if(Physics_ClientOption(self, "airstrafeaccel_qw"))
+               self.stat_sv_airstrafeaccel_qw = AdjustAirAccelQW(Physics_ClientOption(self, "airstrafeaccel_qw"), maxspd_mod);
        else
                self.stat_sv_airstrafeaccel_qw = 0;
-       self.stat_sv_airspeedlimit_nonqw = autocvar_sv_airspeedlimit_nonqw * maxspd_mod;
-       self.stat_sv_maxspeed = autocvar_sv_maxspeed * maxspd_mod; // also slow walking
+       self.stat_sv_airspeedlimit_nonqw = Physics_ClientOption(self, "airspeedlimit_nonqw") * 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;
@@ -60,24 +145,47 @@ void Physics_UpdateStats(float maxspd_mod)
        self.stat_jetpack_maxspeed_up = PHYS_JETPACK_MAXSPEED_UP;
        self.stat_jetpack_fuel = PHYS_JETPACK_FUEL;
 
-       self.stat_jumpspeedcap_min = PHYS_JUMPSPEEDCAP_MIN;
-       self.stat_jumpspeedcap_max = PHYS_JUMPSPEEDCAP_MAX;
        self.stat_jumpspeedcap_disable_onramps = PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS;
 
        self.stat_sv_friction_on_land = PHYS_FRICTION_ONLAND;
        self.stat_sv_friction_slick = PHYS_FRICTION_SLICK;
 
        self.stat_gameplayfix_easierwaterjump = GAMEPLAYFIX_EASIERWATERJUMP;
+
+
+       // old stats
+       // fix some new settings
+       self.stat_sv_airaccel_qw_stretchfactor = Physics_ClientOption(self, "airaccel_qw_stretchfactor");
+       self.stat_sv_maxairstrafespeed = Physics_ClientOption(self, "maxairstrafespeed");
+       self.stat_sv_maxairspeed = Physics_ClientOption(self, "maxairspeed");
+       self.stat_sv_airstrafeaccelerate = Physics_ClientOption(self, "airstrafeaccelerate");
+       self.stat_sv_warsowbunny_turnaccel = Physics_ClientOption(self, "warsowbunny_turnaccel");
+       self.stat_sv_airaccel_sideways_friction = Physics_ClientOption(self, "airaccel_sideways_friction");
+       self.stat_sv_aircontrol = Physics_ClientOption(self, "aircontrol");
+       self.stat_sv_aircontrol_power = Physics_ClientOption(self, "aircontrol_power");
+       self.stat_sv_aircontrol_penalty = Physics_ClientOption(self, "aircontrol_penalty");
+       self.stat_sv_warsowbunny_airforwardaccel = Physics_ClientOption(self, "warsowbunny_airforwardaccel");
+       self.stat_sv_warsowbunny_topspeed = Physics_ClientOption(self, "warsowbunny_topspeed");
+       self.stat_sv_warsowbunny_accel = Physics_ClientOption(self, "warsowbunny_accel");
+       self.stat_sv_warsowbunny_backtosideratio = Physics_ClientOption(self, "warsowbunny_backtosideratio");
+       self.stat_sv_friction = Physics_ClientOption(self, "friction");
+       self.stat_sv_accelerate = Physics_ClientOption(self, "accelerate");
+       self.stat_sv_stopspeed = Physics_ClientOption(self, "stopspeed");
+       self.stat_sv_airaccelerate = Physics_ClientOption(self, "airaccelerate");
+       self.stat_sv_airstopaccelerate = Physics_ClientOption(self, "airstopaccelerate");
+       self.stat_sv_jumpvelocity = Physics_ClientOption(self, "jumpvelocity");
+
+       self.stat_gameplayfix_upvelocityclearsonground = UPWARD_VELOCITY_CLEARS_ONGROUND;
 }
 #endif
 
-float IsMoveInDirection(vector mv, float angle) // key mix factor
+float IsMoveInDirection(vector mv, float ang) // key mix factor
 {
        if (mv_x == 0 && mv_y == 0)
                return 0; // avoid division by zero
-       angle -= RAD2DEG * atan2(mv_y, mv_x);
-       angle = remainder(angle, 360) / 45;
-       return angle > 1 ? 0 : angle < -1 ? 0 : 1 - fabs(angle);
+       ang -= RAD2DEG * atan2(mv_y, mv_x);
+       ang = remainder(ang, 360) / 45;
+       return ang > 1 ? 0 : ang < -1 ? 0 : 1 - fabs(ang);
 }
 
 float GeomLerp(float a, float lerp, float b)
@@ -114,7 +222,7 @@ vector unstick_offsets[unstick_count] =
 };
 
 void PM_ClientMovement_Unstick()
-{
+{SELFPARAM();
        float i;
        for (i = 0; i < unstick_count; i++)
        {
@@ -129,7 +237,7 @@ void PM_ClientMovement_Unstick()
 }
 
 void PM_ClientMovement_UpdateStatus(bool ground)
-{
+{SELFPARAM();
        // make sure player is not stuck
        PM_ClientMovement_Unstick();
 
@@ -176,17 +284,21 @@ void PM_ClientMovement_UpdateStatus(bool ground)
        origin1_z += self.mins_z + 1;
        self.waterlevel = WATERLEVEL_NONE;
 
-       self.watertype = (pointcontents(origin1) == CONTENT_WATER);
+       int thepoint = pointcontents(origin1);
+
+       self.watertype = (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME);
 
        if(self.watertype)
        {
                self.waterlevel = WATERLEVEL_WETFEET;
                origin1_z = self.origin_z + (self.mins_z + self.maxs_z) * 0.5;
-               if(pointcontents(origin1) == CONTENT_WATER)
+               thepoint = pointcontents(origin1);
+               if(thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME)
                {
                        self.waterlevel = WATERLEVEL_SWIMMING;
                        origin1_z = self.origin_z + 22;
-                       if(pointcontents(origin1) == CONTENT_WATER)
+                       thepoint = pointcontents(origin1);
+                       if(thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME)
                                self.waterlevel = WATERLEVEL_SUBMERGED;
                }
        }
@@ -196,85 +308,101 @@ void PM_ClientMovement_UpdateStatus(bool ground)
 }
 
 void PM_ClientMovement_Move()
-{
+{SELFPARAM();
 #ifdef CSQC
-       float t = PHYS_INPUT_TIMELENGTH;
-       vector primalvelocity = self.velocity;
+       int bump;
+       float t;
+       float f;
+       vector neworigin;
+       vector currentorigin2;
+       vector neworigin2;
+       vector primalvelocity;
+
+       vector trace1_endpos = '0 0 0';
+       vector trace2_endpos = '0 0 0';
+       vector trace3_endpos = '0 0 0';
+       float trace1_fraction = 0;
+       float trace2_fraction = 0;
+       float trace3_fraction = 0;
+       vector trace1_plane_normal = '0 0 0';
+       vector trace2_plane_normal = '0 0 0';
+       vector trace3_plane_normal = '0 0 0';
+
+
        PM_ClientMovement_UpdateStatus(false);
-       float bump = 0;
-       for (bump = 0; bump < MAX_CLIP_PLANES && (self.velocity * self.velocity) > 0; bump++)
+       primalvelocity = self.velocity;
+       for(bump = 0, t = PHYS_INPUT_TIMELENGTH; bump < 8 && (self.velocity * self.velocity) > 0; bump++)
        {
-               vector neworigin = self.origin + t * self.velocity;
+               neworigin = self.origin + t * self.velocity;
                tracebox(self.origin, self.mins, self.maxs, neworigin, MOVE_NORMAL, self);
-               float old_trace1_fraction = trace_fraction;
-               vector old_trace1_endpos = trace_endpos;
-               vector old_trace1_plane_normal = trace_plane_normal;
-               if (trace_fraction < 1 && trace_plane_normal_z == 0)
+               trace1_endpos = trace_endpos;
+               trace1_fraction = trace_fraction;
+               trace1_plane_normal = trace_plane_normal;
+               if(trace1_fraction < 1 && trace1_plane_normal_z == 0)
                {
                        // may be a step or wall, try stepping up
                        // first move forward at a higher level
-                       vector currentorigin2 = self.origin;
+                       currentorigin2 = self.origin;
                        currentorigin2_z += PHYS_STEPHEIGHT;
-                       vector neworigin2 = neworigin;
-                       neworigin2_z = self.origin_z + PHYS_STEPHEIGHT;
+                       neworigin2 = neworigin;
+                       neworigin2_z += PHYS_STEPHEIGHT;
                        tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self);
-                       if (!trace_startsolid)
+                       trace2_endpos = trace_endpos;
+                       trace2_fraction = trace_fraction;
+                       trace2_plane_normal = trace_plane_normal;
+                       if(!trace_startsolid)
                        {
                                // then move down from there
-                               currentorigin2 = trace_endpos;
-                               neworigin2 = trace_endpos;
+                               currentorigin2 = trace2_endpos;
+                               neworigin2 = trace2_endpos;
                                neworigin2_z = self.origin_z;
-                               float old_trace2_fraction = trace_fraction;
-                               vector old_trace2_plane_normal = trace_plane_normal;
                                tracebox(currentorigin2, self.mins, self.maxs, neworigin2, MOVE_NORMAL, self);
+                               trace3_endpos = trace_endpos;
+                               trace3_fraction = trace_fraction;
+                               trace3_plane_normal = trace_plane_normal;
                                // accept the new trace if it made some progress
-                               if (fabs(trace_endpos_x - old_trace1_endpos_x) >= 0.03125 || fabs(trace_endpos_y - old_trace1_endpos_y) >= 0.03125)
-                               {
-                                       trace_fraction = old_trace2_fraction;
-                                       trace_endpos = trace_endpos;
-                                       trace_plane_normal = old_trace2_plane_normal;
-                               }
-                               else
+                               if(fabs(trace3_endpos_x - trace1_endpos_x) >= 0.03125 || fabs(trace3_endpos_y - trace1_endpos_y) >= 0.03125)
                                {
-                                       trace_fraction = old_trace1_fraction;
-                                       trace_endpos = old_trace1_endpos;
-                                       trace_plane_normal = old_trace1_plane_normal;
+                                       trace1_endpos = trace2_endpos;
+                                       trace1_fraction = trace2_fraction;
+                                       trace1_plane_normal = trace2_plane_normal;
+                                       trace1_endpos = trace3_endpos;
                                }
                        }
                }
 
                // check if it moved at all
-               if (trace_fraction >= 0.001)
-                       setorigin(self, trace_endpos);
+               if(trace1_fraction >= 0.001)
+                       setorigin(self, trace1_endpos);
 
                // check if it moved all the way
-               if (trace_fraction == 1)
+               if(trace1_fraction == 1)
                        break;
 
                // this is only really needed for nogravityonground combined with gravityunaffectedbyticrate
                // <LordHavoc> I'm pretty sure I commented it out solely because it seemed redundant
                // 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 (trace_plane_normal_z > 0.7)
+               // 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);
 
-               t -= t * trace_fraction;
+               t -= t * trace1_fraction;
 
-               float f = self.velocity * trace_plane_normal;
-               self.velocity -= f * trace_plane_normal;
+               f = (self.velocity * trace1_plane_normal);
+               self.velocity = self.velocity + -f * trace1_plane_normal;
        }
-       if (pmove_waterjumptime > 0)
+       if(pmove_waterjumptime > 0)
                self.velocity = primalvelocity;
 #endif
 }
 
 void CPM_PM_Aircontrol(vector wishdir, float wishspeed)
-{
-       float k = 32 * (2 * IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), 0) - 1);
+{SELFPARAM();
+       float k = 32 * (2 * IsMoveInDirection(self.movement, 0) - 1);
        if (k <= 0)
                return;
 
-       k *= bound(0, wishspeed / PHYS_MAXAIRSPEED, 1);
+       k *= bound(0, wishspeed / PHYS_MAXAIRSPEED(self), 1);
 
        float zspeed = self.velocity_z;
        self.velocity_z = 0;
@@ -306,7 +434,7 @@ float AdjustAirAccelQW(float accelqw, float factor)
 //   prvm_globalset server speedclamp_mode 1
 //     (or 2)
 void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float accel, float accelqw, float stretchfactor, float sidefric, float speedlimit)
-{
+{SELFPARAM();
        float speedclamp = stretchfactor > 0 ? stretchfactor
        : accelqw < 0 ? 1 // full clamping, no stretch
        : -1; // no clamping
@@ -370,7 +498,7 @@ void PM_Accelerate(vector wishdir, float wishspeed, float wishspeed0, float acce
 }
 
 void PM_AirAccelerate(vector wishdir, float wishspeed)
-{
+{SELFPARAM();
        if (wishspeed == 0)
                return;
 
@@ -412,8 +540,8 @@ When you press the jump key
 returns true if handled
 =============
 */
-float PlayerJump (void)
-{
+bool PlayerJump (void)
+{SELFPARAM();
        if (PHYS_FROZEN(self))
                return true; // no jumping in freezetag when frozen
 
@@ -422,17 +550,18 @@ float PlayerJump (void)
                return true; // no jumping while blocked
 #endif
 
-       float doublejump = false;
+       bool doublejump = false;
        float mjumpheight = PHYS_JUMPVELOCITY;
-
+#ifdef CSQC
        player_multijump = doublejump;
        player_jumpheight = mjumpheight;
-#ifdef SVQC
-       if (MUTATOR_CALLHOOK(PlayerJump))
-#elif defined(CSQC)
-       if(PM_multijump_checkjump())
 #endif
-               return true;
+
+       if (MUTATOR_CALLHOOK(PlayerJump, doublejump, mjumpheight)
+#ifdef CSQC
+               || PM_multijump_checkjump()
+#endif
+               ) { return true; }
 
        doublejump = player_multijump;
        mjumpheight = player_jumpheight;
@@ -470,22 +599,22 @@ float PlayerJump (void)
        // velocity bounds.  Final velocity is bound between (jumpheight *
        // min + jumpheight) and (jumpheight * max + jumpheight);
 
-       if(PHYS_JUMPSPEEDCAP_MIN)
+       if(PHYS_JUMPSPEEDCAP_MIN != "")
        {
-               float minjumpspeed = mjumpheight * PHYS_JUMPSPEEDCAP_MIN;
+               float minjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MIN);
 
                if (self.velocity_z < minjumpspeed)
                        mjumpheight += minjumpspeed - self.velocity_z;
        }
 
-       if(PHYS_JUMPSPEEDCAP_MAX)
+       if(PHYS_JUMPSPEEDCAP_MAX != "")
        {
                // don't do jump speedcaps on ramps to preserve old xonotic ramjump style
                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.98 && PHYS_JUMPSPEEDCAP_DISABLE_ONRAMPS))
                {
-                       float maxjumpspeed = mjumpheight * PHYS_JUMPSPEEDCAP_MAX;
+                       float maxjumpspeed = mjumpheight * stof(PHYS_JUMPSPEEDCAP_MAX);
 
                        if (self.velocity_z > maxjumpspeed)
                                mjumpheight -= self.velocity_z - maxjumpspeed;
@@ -494,16 +623,20 @@ float PlayerJump (void)
 
        if (!WAS_ONGROUND(self))
        {
+#ifdef SVQC
                if(autocvar_speedmeter)
-                       dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
+                       LOG_TRACE(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
+#endif
                if(self.lastground < time - 0.3)
                {
                        self.velocity_x *= (1 - PHYS_FRICTION_ONLAND);
                        self.velocity_y *= (1 - PHYS_FRICTION_ONLAND);
                }
+#ifdef SVQC
                if(self.jumppadcount > 1)
-                       dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
+                       LOG_TRACE(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
                self.jumppadcount = 0;
+#endif
        }
 
        self.velocity_z += mjumpheight;
@@ -524,9 +657,9 @@ float PlayerJump (void)
 }
 
 void CheckWaterJump()
-{
+{SELFPARAM();
 // check for a jump-out-of-water
-       makevectors(PHYS_INPUT_ANGLES(self));
+       makevectors(self.v_angle);
        vector start = self.origin;
        start_z += 8;
        v_forward_z = 0;
@@ -542,10 +675,12 @@ void CheckWaterJump()
                if (trace_fraction == 1)
                {       // open at eye level
                        self.velocity_z = 225;
-#ifdef SVQC
                        self.flags |= FL_WATERJUMP;
                        SET_JUMP_HELD(self);
+#ifdef SVQC
                        self.teleport_time = time + 2;  // safety net
+#elif defined(CSQC)
+                       pmove_waterjumptime = time + 2;
 #endif
                }
        }
@@ -562,26 +697,20 @@ void CheckWaterJump()
 // Hack: shouldn't need to know about this
 .float multijump_count;
 void CheckPlayerJump()
-{
+{SELFPARAM();
 #ifdef SVQC
-       float was_flying = ITEMS(self) & IT_USING_JETPACK;
+       float was_flying = ITEMS_STAT(self) & IT_USING_JETPACK;
 #endif
        if (JETPACK_JUMP(self) < 2)
-#ifdef SVQC
-               ITEMS(self) &= ~IT_USING_JETPACK;
-#endif
+               ITEMS_STAT(self) &= ~IT_USING_JETPACK;
 
        if(PHYS_INPUT_BUTTON_JUMP(self) || PHYS_INPUT_BUTTON_JETPACK(self))
        {
-#ifdef SVQC
                float air_jump = !PlayerJump() || self.multijump_count > 0; // 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 = !autocvar_g_jetpack_fuel || self.ammo_fuel || ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO;
-#else
-               PlayerJump(); // Client only
-               float has_fuel = true; // TODO
-#endif
-               if (!(ITEMS(self) & IT_JETPACK)) { }
+               float has_fuel = !PHYS_JETPACK_FUEL || PHYS_AMMO_FUEL(self) || ITEMS_STAT(self) & IT_UNLIMITED_WEAPON_AMMO;
+
+               if (!(ITEMS_STAT(self) & ITEM_Jetpack.m_itemid)) { }
                else if (self.jetpack_stopped) { }
                else if (!has_fuel)
                {
@@ -592,21 +721,15 @@ void CheckPlayerJump()
                                Send_Notification(NOTIF_ONE, self, MSG_INFO, INFO_JETPACK_NOFUEL);
 #endif
                        self.jetpack_stopped = true;
-#ifdef SVQC
-                       ITEMS(self) &= ~IT_USING_JETPACK;
-#endif
+                       ITEMS_STAT(self) &= ~IT_USING_JETPACK;
                }
-#ifdef SVQC
                else if (activate && !PHYS_FROZEN(self))
-                       ITEMS(self) |= IT_USING_JETPACK;
-#endif
+                       ITEMS_STAT(self) |= IT_USING_JETPACK;
        }
        else
        {
                self.jetpack_stopped = false;
-#ifdef SVQC
-               ITEMS(self) &= ~IT_USING_JETPACK;
-#endif
+               ITEMS_STAT(self) &= ~IT_USING_JETPACK;
        }
        if (!PHYS_INPUT_BUTTON_JUMP(self))
                UNSET_JUMP_HELD(self);
@@ -634,7 +757,7 @@ float racecar_angle(float forward, float down)
 }
 
 void RaceCarPhysics()
-{
+{SELFPARAM();
 #ifdef SVQC
        // using this move type for "big rigs"
        // the engine does not push the entity!
@@ -642,8 +765,8 @@ void RaceCarPhysics()
        vector rigvel;
 
        vector angles_save = self.angles;
-       float accel = bound(-1, PHYS_INPUT_MOVEVALUES(self).x / PHYS_MAXSPEED(self), 1);
-       float steer = bound(-1, PHYS_INPUT_MOVEVALUES(self).y / PHYS_MAXSPEED(self), 1);
+       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)
        {
@@ -848,22 +971,13 @@ void SpecialCommand()
        TetrisImpulse();
 #else
        if (!CheatImpulse(99))
-               print("A hollow voice says \"Plugh\".\n");
+               LOG_INFO("A hollow voice says \"Plugh\".\n");
 #endif
 #endif
 }
 
-float PM_check_keepaway(void)
-{
-#ifdef SVQC
-       return (self.ballcarried && g_keepaway) ? autocvar_g_keepaway_ballcarrier_highspeed : 1;
-#else
-       return 1;
-#endif
-}
-
 void PM_check_race_movetime(void)
-{
+{SELFPARAM();
 #ifdef SVQC
        self.race_movetime_frac += PHYS_INPUT_TIMELENGTH;
        float f = floor(self.race_movetime_frac);
@@ -874,7 +988,7 @@ void PM_check_race_movetime(void)
 }
 
 float PM_check_specialcommand(float buttons)
-{
+{SELFPARAM();
 #ifdef SVQC
        string c;
        if (!buttons)
@@ -911,20 +1025,20 @@ float PM_check_specialcommand(float buttons)
 }
 
 void PM_check_nickspam(void)
-{
+{SELFPARAM();
 #ifdef SVQC
        if (time >= self.nickspamtime)
                return;
        if (self.nickspamcount >= autocvar_g_nick_flood_penalty_yellow)
        {
                // slight annoyance for nick change scripts
-               PHYS_INPUT_MOVEVALUES(self) = -1 * PHYS_INPUT_MOVEVALUES(self);
+               self.movement = -1 * self.movement;
                self.BUTTON_ATCK = self.BUTTON_JUMP = self.BUTTON_ATCK2 = self.BUTTON_ZOOM = self.BUTTON_CROUCH = self.BUTTON_HOOK = self.BUTTON_USE = 0;
 
                if (self.nickspamcount >= autocvar_g_nick_flood_penalty_red) // if you are persistent and the slight annoyance above does not stop you, I'll show you!
                {
-                       PHYS_INPUT_ANGLES(self)_x = random() * 360;
-                       PHYS_INPUT_ANGLES(self)_y = random() * 360;
+                       self.v_angle_x = random() * 360;
+                       self.v_angle_y = random() * 360;
                        // at least I'm not forcing retardedview by also assigning to angles_z
                        self.fixangle = true;
                }
@@ -933,7 +1047,7 @@ void PM_check_nickspam(void)
 }
 
 void PM_check_punch()
-{
+{SELFPARAM();
 #ifdef SVQC
        if (self.punchangle != '0 0 0')
        {
@@ -956,18 +1070,20 @@ void PM_check_punch()
 }
 
 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
-       self.stat_sv_airspeedlimit_nonqw *= 0.5;
+       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)
-{
+{SELFPARAM();
        if (!PHYS_FROZEN(self))
                return;
        if (PHYS_DODGING_FROZEN
@@ -976,12 +1092,12 @@ void PM_check_frozen(void)
 #endif
        )
        {
-               PHYS_INPUT_MOVEVALUES(self)_x = bound(-5, PHYS_INPUT_MOVEVALUES(self).x, 5);
-               PHYS_INPUT_MOVEVALUES(self)_y = bound(-5, PHYS_INPUT_MOVEVALUES(self).y, 5);
-               PHYS_INPUT_MOVEVALUES(self)_z = bound(-5, PHYS_INPUT_MOVEVALUES(self).z, 5);
+               self.movement_x = bound(-5, self.movement.x, 5);
+               self.movement_y = bound(-5, self.movement.y, 5);
+               self.movement_z = bound(-5, self.movement.z, 5);
        }
        else
-               PHYS_INPUT_MOVEVALUES(self) = '0 0 0';
+               self.movement = '0 0 0';
 
        vector midpoint = ((self.absmin + self.absmax) * 0.5);
        if (pointcontents(midpoint) == CONTENT_WATER)
@@ -994,7 +1110,7 @@ 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
@@ -1021,11 +1137,11 @@ void PM_check_hitground()
 }
 
 void PM_check_blocked(void)
-{
+{SELFPARAM();
 #ifdef SVQC
        if (!self.player_blocked)
                return;
-       PHYS_INPUT_MOVEVALUES(self) = '0 0 0';
+       self.movement = '0 0 0';
        self.disableclientprediction = 1;
 #endif
 }
@@ -1035,7 +1151,7 @@ float speedaward_lastsent;
 float speedaward_lastupdate;
 #endif
 void PM_check_race(void)
-{
+{SELFPARAM();
 #ifdef SVQC
        if(!(g_cts || g_race))
                return;
@@ -1065,11 +1181,11 @@ void PM_check_race(void)
 }
 
 void PM_check_vortex(void)
-{
+{SELFPARAM();
 #ifdef SVQC
        // WEAPONTODO
        float xyspeed = vlen(vec2(self.velocity));
-       if (self.weapon == WEP_VORTEX && WEP_CVAR(vortex, charge) && WEP_CVAR(vortex, charge_velocity_rate) && xyspeed > WEP_CVAR(vortex, charge_minspeed))
+       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));
@@ -1081,25 +1197,28 @@ void PM_check_vortex(void)
 }
 
 void PM_fly(float maxspd_mod)
-{
+{SELFPARAM();
        // noclipping or flying
        UNSET_ONGROUND(self);
 
        self.velocity = self.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION);
-       makevectors(PHYS_INPUT_ANGLES(self));
-       //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
-       vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
-                                       + v_right * PHYS_INPUT_MOVEVALUES(self).y
-                                       + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z;
+       makevectors(self.v_angle);
+       //wishvel = v_forward * self.movement.x + v_right * self.movement.y + v_up * self.movement.z;
+       vector wishvel = v_forward * self.movement.x
+                                       + v_right * self.movement.y
+                                       + '0 0 1' * self.movement.z;
        // acceleration
        vector wishdir = normalize(wishvel);
        float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod);
+#ifdef SVQC
        if (time >= self.teleport_time)
+#endif
                PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0);
+       PM_ClientMovement_Move();
 }
 
 void PM_swim(float maxspd_mod)
-{
+{SELFPARAM();
        // swimming
        UNSET_ONGROUND(self);
 
@@ -1108,7 +1227,7 @@ void PM_swim(float maxspd_mod)
        // this mimics quakeworld code
        if (jump && self.waterlevel == WATERLEVEL_SWIMMING && self.velocity_z >= -180)
        {
-               vector yawangles = '0 1 0' * PHYS_INPUT_ANGLES(self).y;
+               vector yawangles = '0 1 0' * self.v_angle.y;
                makevectors(yawangles);
                vector forward = v_forward;
                vector spot = self.origin + 24 * forward;
@@ -1128,11 +1247,11 @@ void PM_swim(float maxspd_mod)
                        }
                }
        }
-       makevectors(PHYS_INPUT_ANGLES(self));
-       //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
-       vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
-                                       + v_right * PHYS_INPUT_MOVEVALUES(self).y
-                                       + '0 0 1' * PHYS_INPUT_MOVEVALUES(self).z;
+       makevectors(self.v_angle);
+       //wishvel = v_forward * self.movement.x + v_right * self.movement.y + v_up * self.movement.z;
+       vector wishvel = v_forward * self.movement.x
+                                       + v_right * self.movement.y
+                                       + '0 0 1' * self.movement.z;
        if (wishvel == '0 0 0')
                wishvel = '0 0 -60'; // drift towards bottom
 
@@ -1176,13 +1295,13 @@ void PM_swim(float maxspd_mod)
 #endif
                }
        }
-       PM_ClientMovement_Move();
        // water acceleration
        PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE * maxspd_mod, 1, 0, 0, 0);
+       PM_ClientMovement_Move();
 }
 
 void PM_ladder(float maxspd_mod)
-{
+{SELFPARAM();
        // on a spawnfunc_func_ladder or swimming in spawnfunc_func_water
        UNSET_ONGROUND(self);
 
@@ -1197,11 +1316,11 @@ void PM_ladder(float maxspd_mod)
        }
 
        self.velocity = self.velocity * (1 - PHYS_INPUT_TIMELENGTH * PHYS_FRICTION);
-       makevectors(PHYS_INPUT_ANGLES(self));
-       //wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x + v_right * PHYS_INPUT_MOVEVALUES(self).y + v_up * PHYS_INPUT_MOVEVALUES(self).z;
-       vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self)_x
-                                       + v_right * PHYS_INPUT_MOVEVALUES(self)_y
-                                       + '0 0 1' * PHYS_INPUT_MOVEVALUES(self)_z;
+       makevectors(self.v_angle);
+       //wishvel = v_forward * self.movement.x + v_right * self.movement.y + v_up * self.movement.z;
+       vector wishvel = v_forward * self.movement_x
+                                       + v_right * self.movement_y
+                                       + '0 0 1' * self.movement_z;
        self.velocity_z += g;
        if (self.ladder_entity.classname == "func_water")
        {
@@ -1226,22 +1345,22 @@ void PM_ladder(float maxspd_mod)
        // acceleration
        vector wishdir = normalize(wishvel);
        float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(self) * maxspd_mod);
-       PM_ClientMovement_Move();
 #ifdef SVQC
        if (time >= self.teleport_time)
 #endif
                // water acceleration
                PM_Accelerate(wishdir, wishspeed, wishspeed, PHYS_ACCELERATE*maxspd_mod, 1, 0, 0, 0);
+       PM_ClientMovement_Move();
 }
 
 void PM_jetpack(float maxspd_mod)
-{
-       //makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
-       makevectors(PHYS_INPUT_ANGLES(self));
-       vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self)_x
-                                       + v_right * PHYS_INPUT_MOVEVALUES(self)_y;
+{SELFPARAM();
+       //makevectors(self.v_angle.y * '0 1 0');
+       makevectors(self.v_angle);
+       vector wishvel = v_forward * self.movement_x
+                                       + v_right * self.movement_y;
        // add remaining speed as Z component
-       float maxairspd = PHYS_MAXAIRSPEED * max(1, maxspd_mod);
+       float maxairspd = PHYS_MAXAIRSPEED(self) * max(1, maxspd_mod);
        // fix speedhacks :P
        wishvel = normalize(wishvel) * min(1, vlen(wishvel) / maxairspd);
        // add the unused velocity as up component
@@ -1314,7 +1433,7 @@ void PM_jetpack(float maxspd_mod)
        wishvel_z = (wishvel_z - PHYS_GRAVITY) * fz + PHYS_GRAVITY;
 
        fvel = min(1, vlen(wishvel) / best);
-       if (PHYS_JETPACK_FUEL && !(ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO))
+       if (PHYS_JETPACK_FUEL && !(ITEMS_STAT(self) & IT_UNLIMITED_WEAPON_AMMO))
                f = min(1, PHYS_AMMO_FUEL(self) / (PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel));
        else
                f = 1;
@@ -1327,10 +1446,10 @@ void PM_jetpack(float maxspd_mod)
                UNSET_ONGROUND(self);
 
 #ifdef SVQC
-               if (!(ITEMS(self) & IT_UNLIMITED_WEAPON_AMMO))
+               if (!(ITEMS_STAT(self) & IT_UNLIMITED_WEAPON_AMMO))
                        self.ammo_fuel -= PHYS_JETPACK_FUEL * PHYS_INPUT_TIMELENGTH * fvel * f;
 
-               ITEMS(self) |= IT_USING_JETPACK;
+               ITEMS_STAT(self) |= IT_USING_JETPACK;
 
                // jetpack also inhibits health regeneration, but only for 1 second
                self.pauseregen_finished = max(self.pauseregen_finished, time + autocvar_g_balance_pause_fuel_regen);
@@ -1349,200 +1468,28 @@ void PM_jetpack(float maxspd_mod)
                        self.velocity_z -= g * 0.5;
 #endif
 }
-#ifdef SVQC
-void SV_WalkMove ()
-{
-       // if PHYS_INPUT_TIMELENGTH is 0 (due to client sending the same timestamp twice),
-       // don't move
-       if (PHYS_INPUT_TIMELENGTH <= 0)
-               return;
-
-//     if (autocvar_sv_gameplayfix_unstickplayers)
-//             SV_CheckStuck (self);
-
-//     applygravity = !SV_CheckWater(self) && self.movetype == MOVETYPE_WALK && !(self.flags & FL_WATERJUMP);
-
-//     hitsupercontentsmask = SV_GenericHitSuperContentsMask(self);
-
-//     SV_CheckVelocity(self);
-
-       // do a regular slide move unless it looks like you ran into a step
-//     float oldonground = self.flags & FL_ONGROUND;
-
-       vector start_origin = self.origin;
-       vector start_velocity = self.velocity;
-
-       float clip = 0;
-//     clip = SV_FlyMove (self, PHYS_INPUT_TIMELENGTH, applygravity, NULL, hitsupercontentsmask, sv_gameplayfix_stepmultipletimes.integer ? sv_stepheight.value : 0);
-
-//     if(sv_gameplayfix_downtracesupportsongroundflag.integer)
-//     if(!(clip & 1))
-       {
-               // only try this if there was no floor in the way in the trace (no,
-               // this check seems to be not REALLY necessary, because if clip & 1,
-               // our trace will hit that thing too)
-               vector upmove = self.origin;
-               upmove_z++;
-               vector downmove = self.origin;
-               upmove_z--;
-               float type;
-               if (self.movetype == MOVETYPE_FLYMISSILE)
-                       type = MOVE_MISSILE;
-               else if (self.movetype == MOVETYPE_FLY_WORLDONLY)
-                       type = MOVE_WORLDONLY;
-               else if (self.solid == SOLID_TRIGGER || self.solid == SOLID_NOT)
-                       type = MOVE_NOMONSTERS; // only clip against bmodels
-               else
-                       type = MOVE_NORMAL;
-               vector entmins = self.mins;
-               vector entmaxs = self.maxs;
-               tracebox(upmove, entmins, entmaxs, downmove, type, self);
-               if(trace_fraction < 1 && trace_plane_normal_z > 0.7)
-                       clip |= 1; // but we HAVE found a floor
-       }
-
-       // if the move did not hit the ground at any point, we're not on ground
-//     if(!(clip & 1))
-//             self.flags = self.flags & ~FL_ONGROUND;
-
-//     SV_CheckVelocity(self);
-//     SV_LinkEdict(self);
-//     SV_LinkEdict_TouchAreaGrid(self);
-
-       if(clip & 8) // teleport
-               return;
-
-       if (self.flags & FL_WATERJUMP)
-               return;
-
-//     if (autocvar_sv_nostep)
-//             return;
-
-       vector originalmove_origin = self.origin;
-       vector originalmove_velocity = self.velocity;
-       float originalmove_flags = self.flags;
-       entity originalmove_groundentity = self.groundentity;
-
-       // if move didn't block on a step, return
-       if (clip & 2)
-       {
-               // if move was not trying to move into the step, return
-               if (fabs(start_velocity_x) < 0.03125 && fabs(start_velocity_y) < 0.03125)
-                       return;
-
-               if (self.movetype != MOVETYPE_FLY)
-               {
-                       // return if gibbed by a trigger
-                       if (self.movetype != MOVETYPE_WALK)
-                               return;
-
-                       // return if attempting to jump while airborn (unless sv_jumpstep)
-//                     if (!autocvar_sv_jumpstep)
-//                             if (!oldonground && PRVM_serveredictfloat(self, waterlevel) == 0)
-//                                     return;
-               }
-
-               // try moving up and forward to go up a step
-               // back to start pos
-               setorigin(self, start_origin);
-               self.velocity = start_velocity;
-
-               // move up
-               vector upmove = '0 0 0';
-               upmove_z = autocvar_sv_stepheight;
-//             if(!SV_PushEntity(&trace, self, upmove, true))
-//             {
-//                     // we got teleported when upstepping... must abort the move
-//                     return;
-//             }
-
-               // move forward
-               self.velocity_z = 0;
-//             clip = SV_FlyMove (self, PHYS_INPUT_TIMELENGTH, applygravity, stepnormal, hitsupercontentsmask, 0);
-               self.velocity_z += start_velocity_z;
-//             if(clip & 8)
-//             {
-//                     // we got teleported when upstepping... must abort the move
-//                     // note that z velocity handling may not be what QC expects here, but we cannot help it
-//                     return;
-//             }
-
-//             SV_CheckVelocity(self);
-//             SV_LinkEdict(self);
-//             SV_LinkEdict_TouchAreaGrid(self);
-
-               // check for stuckness, possibly due to the limited precision of floats
-               // in the clipping hulls
-               if (clip
-                && fabs(originalmove_origin_y - self.origin_y < 0.03125)
-                && fabs(originalmove_origin_x - self.origin_x < 0.03125))
-               {
-                       //Con_Printf("wall\n");
-                       // stepping up didn't make any progress, revert to original move
-                       setorigin(self, originalmove_origin);
-                       self.velocity = originalmove_velocity;
-                       self.flags = originalmove_flags;
-                       self.groundentity = originalmove_groundentity;
-                       return;
-               }
-
-               //Con_Printf("step - ");
-
-               // extra friction based on view angle
-//             if (clip & 2 && sv_wallfriction.integer)
-//                     SV_WallFriction (self, stepnormal);
-       }
-       // don't do the down move if stepdown is disabled, moving upward, not in water, or the move started offground or ended onground
-//     else if (!autocvar_sv_gameplayfix_stepdown || self.waterlevel >= 3 || start_velocity_z >= (1.0 / 32.0) || !oldonground || (self.flags & FL_ONGROUND))
-//             return;
-
-       // move down
-       vector downmove = '0 0 0';
-       downmove_z = -autocvar_sv_stepheight + start_velocity_z*PHYS_INPUT_TIMELENGTH;
-//     if(!SV_PushEntity (&downtrace, self, downmove, true))
-//     {
-//             // we got teleported when downstepping... must abort the move
-//             return;
-//     }
-
-       if (trace_fraction < 1 && trace_plane_normal_z > 0.7)
-       {
-               // this has been disabled so that you can't jump when you are stepping
-               // up while already jumping (also known as the Quake2 double jump bug)
-       }
-       else
-       {
-               //Con_Printf("slope\n");
-               // if the push down didn't end up on good ground, use the move without
-               // the step up.  This happens near wall / slope combinations, and can
-               // cause the player to hop up higher on a slope too steep to climb
-               setorigin(self, originalmove_origin);
-               self.velocity = originalmove_velocity;
-               self.flags = originalmove_flags;
-               self.groundentity = originalmove_groundentity;
-       }
 
-//     SV_CheckVelocity(self);
-//     SV_LinkEdict(self);
-//     SV_LinkEdict_TouchAreaGrid(self);
-}
-#endif
 void PM_walk(float buttons_prev, float maxspd_mod)
-{
+{SELFPARAM();
        if (!WAS_ONGROUND(self))
        {
+#ifdef SVQC
                if (autocvar_speedmeter)
-                       dprint(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
+                       LOG_TRACE(strcat("landing velocity: ", vtos(self.velocity), " (abs: ", ftos(vlen(self.velocity)), ")\n"));
+#endif
                if (self.lastground < time - 0.3)
                        self.velocity *= (1 - PHYS_FRICTION_ONLAND);
+#ifdef SVQC
                if (self.jumppadcount > 1)
-                       dprint(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
+                       LOG_TRACE(strcat(ftos(self.jumppadcount), "x jumppad combo\n"));
                self.jumppadcount = 0;
+#endif
        }
+
        // walking
-       makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
-       vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
-                                       + v_right * PHYS_INPUT_MOVEVALUES(self).y;
+       makevectors(self.v_angle.y * '0 1 0');
+       vector wishvel = v_forward * self.movement.x
+                                       + v_right * self.movement.y;
        // acceleration
        vector wishdir = normalize(wishvel);
        float wishspeed = vlen(wishvel);
@@ -1608,10 +1555,10 @@ void PM_walk(float buttons_prev, float maxspd_mod)
 }
 
 void PM_air(float buttons_prev, float maxspd_mod)
-{
-       makevectors(PHYS_INPUT_ANGLES(self).y * '0 1 0');
-       vector wishvel = v_forward * PHYS_INPUT_MOVEVALUES(self).x
-                                       + v_right * PHYS_INPUT_MOVEVALUES(self).y;
+{SELFPARAM();
+       makevectors(self.v_angle.y * '0 1 0');
+       vector wishvel = v_forward * self.movement.x
+                                       + v_right * self.movement.y;
        // acceleration
        vector wishdir = normalize(wishvel);
        float wishspeed = vlen(wishvel);
@@ -1622,7 +1569,7 @@ void PM_air(float buttons_prev, float maxspd_mod)
        if (pmove_waterjumptime <= 0)
 #endif
        {
-               float maxairspd = PHYS_MAXAIRSPEED * min(maxspd_mod, 1);
+               float maxairspd = PHYS_MAXAIRSPEED(self) * min(maxspd_mod, 1);
 
                // apply air speed limit
                float airaccelqw = PHYS_AIRACCEL_QW(self);
@@ -1649,11 +1596,11 @@ void PM_air(float buttons_prev, float maxspd_mod)
                // dv/dt = accel * maxspeed * (1 - accelqw) (when fast)
                // log dv/dt = logaccel + logmaxspeed (when slow)
                // log dv/dt = logaccel + logmaxspeed + log(1 - accelqw) (when fast)
-               float strafity = IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), -90) + IsMoveInDirection(PHYS_INPUT_MOVEVALUES(self), +90); // if one is nonzero, other is always zero
+               float strafity = IsMoveInDirection(self.movement, -90) + IsMoveInDirection(self.movement, +90); // if one is nonzero, other is always zero
                if (PHYS_MAXAIRSTRAFESPEED)
-                       wishspeed = min(wishspeed, GeomLerp(PHYS_MAXAIRSPEED*maxspd_mod, strafity, PHYS_MAXAIRSTRAFESPEED*maxspd_mod));
-               if (PHYS_AIRSTRAFEACCELERATE)
-                       airaccel = GeomLerp(airaccel, strafity, PHYS_AIRSTRAFEACCELERATE*maxspd_mod);
+                       wishspeed = min(wishspeed, GeomLerp(PHYS_MAXAIRSPEED(self)*maxspd_mod, strafity, PHYS_MAXAIRSTRAFESPEED*maxspd_mod));
+               if (PHYS_AIRSTRAFEACCELERATE(self))
+                       airaccel = GeomLerp(airaccel, strafity, PHYS_AIRSTRAFEACCELERATE(self)*maxspd_mod);
                if (PHYS_AIRSTRAFEACCEL_QW(self))
                        airaccelqw =
                (((strafity > 0.5 ? PHYS_AIRSTRAFEACCEL_QW(self) : PHYS_AIRACCEL_QW(self)) >= 0) ? +1 : -1)
@@ -1661,7 +1608,7 @@ void PM_air(float buttons_prev, float maxspd_mod)
                (1 - GeomLerp(1 - fabs(PHYS_AIRACCEL_QW(self)), strafity, 1 - fabs(PHYS_AIRSTRAFEACCEL_QW(self))));
                // !CPM
 
-               if (PHYS_WARSOWBUNNY_TURNACCEL && accelerating && PHYS_INPUT_MOVEVALUES(self).y == 0 && PHYS_INPUT_MOVEVALUES(self).x != 0)
+               if (PHYS_WARSOWBUNNY_TURNACCEL && accelerating && self.movement.y == 0 && self.movement.x != 0)
                        PM_AirAccelerate(wishdir, wishspeed2);
                else
                        PM_Accelerate(wishdir, wishspeed, wishspeed0, airaccel, airaccelqw, PHYS_AIRACCEL_QW_STRETCHFACTOR(self), PHYS_AIRACCEL_SIDEWAYS_FRICTION / maxairspd, PHYS_AIRSPEEDLIMIT_NONQW(self));
@@ -1694,9 +1641,18 @@ bool IsFlying(entity a)
 }
 
 void PM_Main()
-{
-       float buttons = PHYS_INPUT_BUTTON_MASK(self);
+{SELFPARAM();
+       int buttons = PHYS_INPUT_BUTTON_MASK(self);
 #ifdef CSQC
+       self.items = getstati(STAT_ITEMS, 0, 24);
+
+       self.movement = PHYS_INPUT_MOVEVALUES(self);
+
+       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);
+
        self.team = myteam + 1; // is this correct?
        if (!(PHYS_INPUT_BUTTON_JUMP(self))) // !jump
                UNSET_JUMP_HELD(self); // canjump = true
@@ -1704,13 +1660,12 @@ void PM_Main()
 
        PM_ClientMovement_UpdateStatus(true);
 #endif
-       
+
 
 #ifdef SVQC
        WarpZone_PlayerPhysics_FixVAngle();
 #endif
        float maxspeed_mod = 1;
-       maxspeed_mod *= PM_check_keepaway();
        maxspeed_mod *= PHYS_HIGHSPEED;
 
 #ifdef SVQC
@@ -1731,14 +1686,14 @@ void PM_Main()
 #ifdef SVQC
        if (sv_maxidle > 0)
        {
-               if (buttons != self.buttons_old || PHYS_INPUT_MOVEVALUES(self) != self.movement_old || PHYS_INPUT_ANGLES(self) != self.v_angle_old)
+               if (buttons != self.buttons_old || self.movement != self.movement_old || self.v_angle != self.v_angle_old)
                        self.parm_idlesince = time;
        }
 #endif
-       float buttons_prev = self.buttons_old;
+       int buttons_prev = self.buttons_old;
        self.buttons_old = buttons;
-       self.movement_old = PHYS_INPUT_MOVEVALUES(self);
-       self.v_angle_old = PHYS_INPUT_ANGLES(self);
+       self.movement_old = self.movement;
+       self.v_angle_old = self.v_angle;
 
        PM_check_nickspam();
 
@@ -1760,14 +1715,14 @@ void PM_Main()
                                self.race_penalty = 0;
 #endif
 
-               float not_allowed_to_move = 0;
+               bool not_allowed_to_move = false;
 #ifdef SVQC
                if (self.race_penalty)
-                       not_allowed_to_move = 1;
+                       not_allowed_to_move = true;
 #endif
 #ifdef SVQC
                if (time < game_starttime)
-                       not_allowed_to_move = 1;
+                       not_allowed_to_move = true;
 #endif
 
                if (not_allowed_to_move)
@@ -1796,6 +1751,8 @@ void PM_Main()
        self.disableclientprediction = 0;
 #endif
 
+       viewloc_PlayerPhysics();
+
        PM_check_spider();
 
        PM_check_frozen();
@@ -1831,7 +1788,7 @@ void PM_Main()
 #ifdef SVQC
        if (!IS_PLAYER(self))
        {
-               maxspeed_mod *= autocvar_sv_spectator_speed_multiplier;
+               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))
@@ -1849,16 +1806,50 @@ void PM_Main()
                        } // otherwise just clear
                        self.impulse = 0;
                }
-               maxspeed_mod *= self.spectatorspeed;
+               maxspeed_mod = self.spectatorspeed;
+       }
+
+       float spd = max(PHYS_MAXSPEED(self), PHYS_MAXAIRSPEED(self)) * maxspeed_mod;
+       if(self.speed != spd)
+       {
+               self.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"));
+       }
+
+       if(self.stat_jumpspeedcap_min != PHYS_JUMPSPEEDCAP_MIN)
+       {
+               self.stat_jumpspeedcap_min = PHYS_JUMPSPEEDCAP_MIN;
+               stuffcmd(self, strcat("cl_jumpspeedcap_min ", PHYS_JUMPSPEEDCAP_MIN, "\n"));
+       }
+       if(self.stat_jumpspeedcap_max != PHYS_JUMPSPEEDCAP_MAX)
+       {
+               self.stat_jumpspeedcap_min = PHYS_JUMPSPEEDCAP_MAX;
+               stuffcmd(self, strcat("cl_jumpspeedcap_max ", PHYS_JUMPSPEEDCAP_MAX, "\n"));
        }
 #endif
 
        if(PHYS_DEAD(self))
+       {
+               // handle water here
+               vector midpoint = ((self.absmin + self.absmax) * 0.5);
+               if(pointcontents(midpoint) == CONTENT_WATER)
+               {
+                       self.velocity = self.velocity * 0.5;
+
+                       // do we want this?
+                       //if(pointcontents(midpoint + '0 0 2') == CONTENT_WATER)
+                               //{ self.velocity_z = 70; }
+               }
                goto end;
+       }
 
 #ifdef SVQC
        if (!self.fixangle && !g_bugrigs)
-               self.angles = '0 1 0' * PHYS_INPUT_ANGLES(self).y;
+               self.angles = '0 1 0' * self.v_angle.y;
 #endif
 
        PM_check_hitground();
@@ -1869,13 +1860,13 @@ void PM_Main()
        if (IS_PLAYER(self))
                CheckPlayerJump();
 
-       if (self.flags & /* FL_WATERJUMP */ 2048)
+       if (self.flags & FL_WATERJUMP)
        {
                self.velocity_x = self.movedir_x;
                self.velocity_y = self.movedir_y;
                if (time > self.teleport_time || self.waterlevel == WATERLEVEL_NONE)
                {
-                       self.flags &= ~/* FL_WATERJUMP */ 2048;
+                       self.flags &= ~FL_WATERJUMP;
                        self.teleport_time = 0;
                }
        }
@@ -1885,7 +1876,7 @@ void PM_Main()
                RaceCarPhysics();
 #endif
 
-       else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_FLY_WORLDONLY)
+       else if (self.movetype == MOVETYPE_NOCLIP || self.movetype == MOVETYPE_FLY || self.movetype == MOVETYPE_FLY_WORLDONLY || (BUFFS_STAT(self) & BUFF_FLIGHT.m_itemid))
                PM_fly(maxspeed_mod);
 
        else if (self.waterlevel >= WATERLEVEL_SWIMMING)
@@ -1894,7 +1885,7 @@ void PM_Main()
        else if (time < self.ladder_time)
                PM_ladder(maxspeed_mod);
 
-       else if (ITEMS(self) & IT_USING_JETPACK)
+       else if (ITEMS_STAT(self) & IT_USING_JETPACK)
                PM_jetpack(maxspeed_mod);
 
        else if (IS_ONGROUND(self))
@@ -1917,9 +1908,14 @@ void PM_Main()
        if(self.conveyor.state)
                self.velocity += self.conveyor.movedir;
 
-       self.lastflags = FLAGS(self);
+       self.lastflags = self.flags;
 
        self.lastclassname = self.classname;
+
+#ifdef CSQC
+       self.v_angle = oldv_angle;
+       self.angles = oldangles;
+#endif
 }
 
 #ifdef SVQC
@@ -1927,10 +1923,13 @@ void SV_PlayerPhysics(void)
 #elif defined(CSQC)
 void CSQC_ClientMovement_PlayerMove_Frame(void)
 #endif
-{
+{SELFPARAM();
        PM_Main();
 
 #ifdef CSQC
-       self.pmove_flags = self.pm_flags;
+       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);
 #endif
 }