]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/physics.qc
Merge branch 'master' into TimePath/stats
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / physics.qc
index 63e7ae7e91dae4ee1caa28bf8d66ea993c1c2454..0526742b4a56c6c8ceef92c00b4db5e5ac07e959 100644 (file)
@@ -30,147 +30,37 @@ float Physics_ClientOption(entity pl, string option)
        return cvar(strcat("sv_", option));
 }
 
-void Physics_AddStats()
+void Physics_UpdateStats(entity this, float maxspd_mod)
 {
-       // 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);
-       addstat(STAT_MOVEVARS_AIRACCEL_QW, AS_FLOAT, stat_sv_airaccel_qw);
-       addstat(STAT_MOVEVARS_AIRSTRAFEACCEL_QW, AS_FLOAT, stat_sv_airstrafeaccel_qw);
-       addstat(STAT_MOVEVARS_HIGHSPEED, AS_FLOAT, stat_movement_highspeed);
-
-       // jet pack
-       addstat(STAT_JETPACK_ACCEL_SIDE, AS_FLOAT, stat_jetpack_accel_side);
-       addstat(STAT_JETPACK_ACCEL_UP, AS_FLOAT, stat_jetpack_accel_up);
-       addstat(STAT_JETPACK_ANTIGRAVITY, AS_FLOAT, stat_jetpack_antigravity);
-       addstat(STAT_JETPACK_FUEL, AS_FLOAT, stat_jetpack_fuel);
-       addstat(STAT_JETPACK_MAXSPEED_UP, AS_FLOAT, stat_jetpack_maxspeed_up);
-       addstat(STAT_JETPACK_MAXSPEED_SIDE, AS_FLOAT, stat_jetpack_maxspeed_side);
-
-       // hack to fix track_canjump
-       addstat(STAT_MOVEVARS_CL_TRACK_CANJUMP, AS_INT, cvar_cl_movement_track_canjump);
-       addstat(STAT_MOVEVARS_TRACK_CANJUMP, AS_INT, stat_sv_track_canjump);
-
-       // double jump
-       addstat(STAT_DOUBLEJUMP, AS_INT, stat_doublejump);
-
-       // jump speed caps
-       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)
-{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 = 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;
-
-       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;
-       self.stat_jetpack_maxspeed_side = PHYS_JETPACK_MAXSPEED_SIDE;
-       self.stat_jetpack_maxspeed_up = PHYS_JETPACK_MAXSPEED_UP;
-       self.stat_jetpack_fuel = PHYS_JETPACK_FUEL;
-
-       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;
-
+       STAT(MOVEVARS_AIRACCEL_QW, this) = AdjustAirAccelQW(Physics_ClientOption(this, "airaccel_qw"), maxspd_mod);
+       STAT(MOVEVARS_AIRSTRAFEACCEL_QW, this) = (Physics_ClientOption(this, "airstrafeaccel_qw"))
+               ? AdjustAirAccelQW(Physics_ClientOption(this, "airstrafeaccel_qw"), maxspd_mod)
+               : 0;
+       STAT(MOVEVARS_AIRSPEEDLIMIT_NONQW, this) = Physics_ClientOption(this, "airspeedlimit_nonqw") * maxspd_mod;
+       STAT(MOVEVARS_MAXSPEED, this) = Physics_ClientOption(this, "maxspeed") * maxspd_mod; // also slow walking
 
        // 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_sv_track_canjump = Physics_ClientOption(self, "track_canjump");
-
-       self.stat_gameplayfix_upvelocityclearsonground = UPWARD_VELOCITY_CLEARS_ONGROUND;
+       STAT(MOVEVARS_AIRACCEL_QW_STRETCHFACTOR, this) = Physics_ClientOption(this, "airaccel_qw_stretchfactor");
+       STAT(MOVEVARS_MAXAIRSTRAFESPEED, this) = Physics_ClientOption(this, "maxairstrafespeed");
+       STAT(MOVEVARS_MAXAIRSPEED, this) = Physics_ClientOption(this, "maxairspeed");
+       STAT(MOVEVARS_AIRSTRAFEACCELERATE, this) = Physics_ClientOption(this, "airstrafeaccelerate");
+       STAT(MOVEVARS_WARSOWBUNNY_TURNACCEL, this) = Physics_ClientOption(this, "warsowbunny_turnaccel");
+       STAT(MOVEVARS_AIRACCEL_SIDEWAYS_FRICTION, this) = Physics_ClientOption(this, "airaccel_sideways_friction");
+       STAT(MOVEVARS_AIRCONTROL, this) = Physics_ClientOption(this, "aircontrol");
+       STAT(MOVEVARS_AIRCONTROL_POWER, this) = Physics_ClientOption(this, "aircontrol_power");
+       STAT(MOVEVARS_AIRCONTROL_PENALTY, this) = Physics_ClientOption(this, "aircontrol_penalty");
+       STAT(MOVEVARS_WARSOWBUNNY_AIRFORWARDACCEL, this) = Physics_ClientOption(this, "warsowbunny_airforwardaccel");
+       STAT(MOVEVARS_WARSOWBUNNY_TOPSPEED, this) = Physics_ClientOption(this, "warsowbunny_topspeed");
+       STAT(MOVEVARS_WARSOWBUNNY_ACCEL, this) = Physics_ClientOption(this, "warsowbunny_accel");
+       STAT(MOVEVARS_WARSOWBUNNY_BACKTOSIDERATIO, this) = Physics_ClientOption(this, "warsowbunny_backtosideratio");
+       STAT(MOVEVARS_FRICTION, this) = Physics_ClientOption(this, "friction");
+       STAT(MOVEVARS_ACCELERATE, this) = Physics_ClientOption(this, "accelerate");
+       STAT(MOVEVARS_STOPSPEED, this) = Physics_ClientOption(this, "stopspeed");
+       STAT(MOVEVARS_AIRACCELERATE, this) = Physics_ClientOption(this, "airaccelerate");
+       STAT(MOVEVARS_AIRSTOPACCELERATE, this) = Physics_ClientOption(this, "airstopaccelerate");
+       STAT(MOVEVARS_JUMPVELOCITY, this) = Physics_ClientOption(this, "jumpvelocity");
+       STAT(MOVEVARS_TRACK_CANJUMP, this) = Physics_ClientOption(this, "track_canjump");
 }
 #endif
 
@@ -860,7 +750,7 @@ void RaceCarPhysics()
                vector rigvel_xy, neworigin, up;
                float mt;
 
-               rigvel_z -= PHYS_INPUT_TIMELENGTH * PHYS_GRAVITY; // 4x gravity plays better
+               rigvel_z -= PHYS_INPUT_TIMELENGTH * PHYS_GRAVITY(this); // 4x gravity plays better
                rigvel_xy = vec2(rigvel);
 
                if (g_bugrigs_planar_movement_car_jumping)
@@ -909,7 +799,7 @@ void RaceCarPhysics()
        }
        else
        {
-               rigvel_z -= PHYS_INPUT_TIMELENGTH * PHYS_GRAVITY; // 4x gravity plays better
+               rigvel_z -= PHYS_INPUT_TIMELENGTH * PHYS_GRAVITY(this); // 4x gravity plays better
                self.velocity = rigvel;
                self.movetype = MOVETYPE_FLY;
        }
@@ -1247,7 +1137,7 @@ void PM_ladder(float maxspd_mod)
        UNSET_ONGROUND(self);
 
        float g;
-       g = PHYS_GRAVITY * PHYS_INPUT_TIMELENGTH;
+       g = PHYS_GRAVITY(this) * PHYS_INPUT_TIMELENGTH;
        if (PHYS_ENTGRAVITY(self))
                g *= PHYS_ENTGRAVITY(self);
        if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
@@ -1313,7 +1203,7 @@ void PM_jetpack(float maxspd_mod)
        // it is now normalized, so...
        float a_side = PHYS_JETPACK_ACCEL_SIDE;
        float a_up = PHYS_JETPACK_ACCEL_UP;
-       float a_add = PHYS_JETPACK_ANTIGRAVITY * PHYS_GRAVITY;
+       float a_add = PHYS_JETPACK_ANTIGRAVITY * PHYS_GRAVITY(this);
 
        wishvel_x *= a_side;
        wishvel_y *= a_side;
@@ -1362,7 +1252,7 @@ void PM_jetpack(float maxspd_mod)
 
        float fxy, fz;
        fxy = bound(0, 1 - (self.velocity * normalize(wishvel_x * '1 0 0' + wishvel_y * '0 1 0')) / PHYS_JETPACK_MAXSPEED_SIDE, 1);
-       if (wishvel_z - PHYS_GRAVITY > 0)
+       if (wishvel_z - PHYS_GRAVITY(this) > 0)
                fz = bound(0, 1 - self.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1);
        else
                fz = bound(0, 1 + self.velocity_z / PHYS_JETPACK_MAXSPEED_UP, 1);
@@ -1371,7 +1261,7 @@ void PM_jetpack(float maxspd_mod)
        fvel = vlen(wishvel);
        wishvel_x *= fxy;
        wishvel_y *= fxy;
-       wishvel_z = (wishvel_z - PHYS_GRAVITY) * fz + PHYS_GRAVITY;
+       wishvel_z = (wishvel_z - PHYS_GRAVITY(this)) * fz + PHYS_GRAVITY(this);
 
        fvel = min(1, vlen(wishvel) / best);
        if (PHYS_JETPACK_FUEL && !(ITEMS_STAT(self) & IT_UNLIMITED_WEAPON_AMMO))
@@ -1398,7 +1288,7 @@ void PM_jetpack(float maxspd_mod)
        }
 
 #ifdef CSQC
-       float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
+       float g = PHYS_GRAVITY(this) * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
        if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
                self.velocity_z -= g * 0.5;
        else
@@ -1482,7 +1372,7 @@ void PM_walk(entity this, float maxspd_mod)
                const float accelspeed = min(PHYS_ACCELERATE * PHYS_INPUT_TIMELENGTH * wishspeed, addspeed);
                this.velocity += accelspeed * wishdir;
        }
-       const float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(this) * PHYS_INPUT_TIMELENGTH;
+       const float g = PHYS_GRAVITY(this) * PHYS_ENTGRAVITY(this) * PHYS_INPUT_TIMELENGTH;
        if (!(GAMEPLAYFIX_NOGRAVITYONGROUND))
                this.velocity_z -= g * (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE ? 0.5 : 1);
        if (vdist(this.velocity, >, 0))
@@ -1554,7 +1444,7 @@ void PM_air(float buttons_prev, float maxspd_mod)
                if (PHYS_AIRCONTROL)
                        CPM_PM_Aircontrol(wishdir, wishspeed2);
        }
-       float g = PHYS_GRAVITY * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
+       float g = PHYS_GRAVITY(this) * PHYS_ENTGRAVITY(self) * PHYS_INPUT_TIMELENGTH;
        if (GAMEPLAYFIX_GRAVITYUNAFFECTEDBYTICRATE)
                self.velocity_z -= g * 0.5;
        else
@@ -1607,7 +1497,7 @@ void PM_Main(entity this)
        maxspeed_mod *= PHYS_HIGHSPEED;
 
 #ifdef SVQC
-       Physics_UpdateStats(maxspeed_mod);
+       Physics_UpdateStats(this, maxspeed_mod);
 
        if (this.PlayerPhysplug)
                if (this.PlayerPhysplug())