]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/physics.qc
Use a temporary hack to hide the jump sound issue
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / physics.qc
index 482135ed6168f9e98296f2cf475890d70ead207b..f7551e253a5341be8df131b048529c4a3f011f05 100644 (file)
@@ -80,8 +80,6 @@ float GeomLerp(float a, float lerp, float b)
                : a * pow(fabs(b / a), lerp);
 }
 
-noref float pmove_waterjumptime;
-
 #define unstick_offsets(X) \
 /* 1 no nudge (just return the original if this test passes) */ \
        X(' 0.000  0.000  0.000') \
@@ -122,8 +120,10 @@ void PM_ClientMovement_Unstick(entity this)
 
 void PM_ClientMovement_UpdateStatus(entity this, bool ground)
 {
+#ifdef CSQC
        // make sure player is not stuck
-       PM_ClientMovement_Unstick(this);
+       if(autocvar_cl_movement != 3)
+               PM_ClientMovement_Unstick(this);
 
        // set crouched
        if (PHYS_INPUT_BUTTON_CROUCH(this))
@@ -145,7 +145,7 @@ void PM_ClientMovement_UpdateStatus(entity this, bool ground)
        vector origin1 = this.origin + '0 0 1';
        vector origin2 = this.origin - '0 0 1';
 
-       if (ground)
+       if (ground && autocvar_cl_movement != 3)
        {
                tracebox(origin1, this.mins, this.maxs, origin2, MOVE_NORMAL, this);
                if (trace_fraction < 1.0 && trace_plane_normal.z > 0.7)
@@ -159,32 +159,36 @@ void PM_ClientMovement_UpdateStatus(entity this, bool ground)
                        UNSET_ONGROUND(this);
        }
 
-       // set watertype/waterlevel
-       origin1 = this.origin;
-       origin1.z += this.mins_z + 1;
-       this.waterlevel = WATERLEVEL_NONE;
+       if(autocvar_cl_movement != 3)
+       {
+               // set watertype/waterlevel
+               origin1 = this.origin;
+               origin1.z += this.mins_z + 1;
+               this.waterlevel = WATERLEVEL_NONE;
 
-       int thepoint = pointcontents(origin1);
+               int thepoint = pointcontents(origin1);
 
-       this.watertype = (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME);
+               this.watertype = (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME);
 
-       if (this.watertype)
-       {
-               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 (this.watertype)
                {
-                       this.waterlevel = WATERLEVEL_SWIMMING;
-                       origin1.z = this.origin.z + 22;
+                       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)
-                               this.waterlevel = WATERLEVEL_SUBMERGED;
+                       {
+                               this.waterlevel = WATERLEVEL_SWIMMING;
+                               origin1.z = this.origin.z + 22;
+                               thepoint = pointcontents(origin1);
+                               if (thepoint == CONTENT_WATER || thepoint == CONTENT_LAVA || thepoint == CONTENT_SLIME)
+                                       this.waterlevel = WATERLEVEL_SUBMERGED;
+                       }
                }
        }
 
        if (IS_ONGROUND(this) || this.velocity.z <= 0 || pmove_waterjumptime <= 0)
                pmove_waterjumptime = 0;
+#endif
 }
 
 void PM_ClientMovement_Move(entity this)
@@ -274,7 +278,7 @@ void PM_ClientMovement_Move(entity this)
                f = (this.velocity * trace1_plane_normal);
                this.velocity = this.velocity + -f * trace1_plane_normal;
        }
-       if(pmove_waterjumptime > 0)
+       if(PHYS_TELEPORT_TIME(this) > 0)
                this.velocity = primalvelocity;
 #endif
 }
@@ -516,7 +520,7 @@ bool PlayerJump(entity this)
        animdecide_setaction(this, ANIMACTION_JUMP, true);
 
        if (autocvar_g_jump_grunt)
-               WITH(entity, this, this, PlayerSound(playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND));
+               PlayerSound(this, playersound_jump, CH_PLAYER, VOICETYPE_PLAYERSOUND);
 #endif
        return true;
 }
@@ -542,11 +546,11 @@ void CheckWaterJump(entity this)
                        this.velocity_z = 225;
                        this.flags |= FL_WATERJUMP;
                        SET_JUMP_HELD(this);
-#ifdef SVQC
-                       this.teleport_time = time + 2;  // safety net
-#elif defined(CSQC)
+               #ifdef SVQC
+                       PHYS_TELEPORT_TIME(this) = time + 2;    // safety net
+               #elif defined(CSQC)
                        pmove_waterjumptime = time + 2;
-#endif
+               #endif
                }
        }
 }
@@ -742,8 +746,6 @@ void PM_check_frozen(entity this)
 void PM_check_hitground(entity this)
 {
 #ifdef SVQC
-       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;
@@ -752,9 +754,32 @@ void PM_check_hitground(entity this)
     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;
-    WITH(entity, self, this, GlobalSound(fall, CH_PLAYER, VOICETYPE_PLAYERSOUND));
+    if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_NOSTEPS) return;
+    entity gs = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
+       ? GS_FALL_METAL
+       : GS_FALL;
+    GlobalSound(this, gs, CH_PLAYER, VOICETYPE_PLAYERSOUND);
+#endif
+}
+
+void PM_Footsteps(entity this)
+{
+#ifdef SVQC
+       if (!g_footsteps) return;
+       if (IS_DUCKED(this)) return;
+       if (time >= this.lastground + 0.2) return;
+       if (vdist(this.velocity, <=, autocvar_sv_maxspeed * 0.6)) return;
+       if ((time > this.nextstep) || (time < (this.nextstep - 10.0)))
+       {
+               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 gs = (trace_dphitq3surfaceflags & Q3SURFACEFLAG_METALSTEPS)
+                       ? GS_STEP_METAL
+                       : GS_STEP;
+               GlobalSound(this, gs, CH_PLAYER, VOICETYPE_PLAYERSOUND);
+       }
 #endif
 }
 
@@ -783,7 +808,7 @@ void PM_fly(entity this, float maxspd_mod)
        vector wishdir = normalize(wishvel);
        float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod);
 #ifdef SVQC
-       if (time >= this.teleport_time)
+       if(time >= PHYS_TELEPORT_TIME(this))
 #endif
                PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this) * maxspd_mod, 1, 0, 0, 0);
        PM_ClientMovement_Move(this);
@@ -813,7 +838,9 @@ void PM_swim(entity this, float maxspd_mod)
                        {
                                this.velocity = forward * 50;
                                this.velocity_z = 310;
+                       #ifdef CSQC
                                pmove_waterjumptime = 2;
+                       #endif
                                UNSET_ONGROUND(this);
                                SET_JUMP_HELD(this);
                        }
@@ -917,9 +944,7 @@ void PM_ladder(entity this, float maxspd_mod)
        // acceleration
        vector wishdir = normalize(wishvel);
        float wishspeed = min(vlen(wishvel), PHYS_MAXSPEED(this) * maxspd_mod);
-#ifdef SVQC
-       if (time >= this.teleport_time)
-#endif
+       if(time >= PHYS_TELEPORT_TIME(this))
                // water acceleration
                PM_Accelerate(this, wishdir, wishspeed, wishspeed, PHYS_ACCELERATE(this)*maxspd_mod, 1, 0, 0, 0);
        PM_ClientMovement_Move(this);
@@ -1147,9 +1172,9 @@ void PM_air(entity this, float buttons_prev, float maxspd_mod)
        float wishspeed = vlen(wishvel);
 
 #ifdef SVQC
-       if (time >= this.teleport_time)
-#else
-       if (pmove_waterjumptime <= 0)
+       if(time >= PHYS_TELEPORT_TIME(this))
+#elif defined(CSQC)
+       if(pmove_waterjumptime <= 0)
 #endif
        {
                float maxairspd = PHYS_MAXAIRSPEED(this) * min(maxspd_mod, 1);
@@ -1374,15 +1399,15 @@ void PM_Main(entity this)
                stuffcmd(this, strcat("cl_upspeed ", temps, "\n"));
        }
 
-       if(this.stat_jumpspeedcap_min != PHYS_JUMPSPEEDCAP_MIN)
+       if(this.jumpspeedcap_min != autocvar_sv_jumpspeedcap_min)
        {
-               this.stat_jumpspeedcap_min = PHYS_JUMPSPEEDCAP_MIN;
-               stuffcmd(this, strcat("cl_jumpspeedcap_min ", PHYS_JUMPSPEEDCAP_MIN, "\n"));
+               this.jumpspeedcap_min = autocvar_sv_jumpspeedcap_min;
+               stuffcmd(this, sprintf("\ncl_jumpspeedcap_min \"%s\"\n", autocvar_sv_jumpspeedcap_min));
        }
-       if(this.stat_jumpspeedcap_max != PHYS_JUMPSPEEDCAP_MAX)
+       if(this.jumpspeedcap_max != autocvar_sv_jumpspeedcap_max)
        {
-               this.stat_jumpspeedcap_min = PHYS_JUMPSPEEDCAP_MAX;
-               stuffcmd(this, strcat("cl_jumpspeedcap_max ", PHYS_JUMPSPEEDCAP_MAX, "\n"));
+               this.jumpspeedcap_max = autocvar_sv_jumpspeedcap_max;
+               stuffcmd(this, sprintf("\ncl_jumpspeedcap_max \"%s\"\n", autocvar_sv_jumpspeedcap_max));
        }
 #endif
 
@@ -1406,7 +1431,11 @@ void PM_Main(entity this)
                this.angles = '0 1 0' * this.v_angle.y;
 #endif
 
-       PM_check_hitground(this);
+       if (IS_PLAYER(this) && IS_ONGROUND(this))
+       {
+               PM_check_hitground(this);
+               PM_Footsteps(this);
+       }
 
        if(IsFlying(this))
                this.wasFlying = 1;
@@ -1418,17 +1447,21 @@ void PM_Main(entity this)
        {
                this.velocity_x = this.movedir.x;
                this.velocity_y = this.movedir.y;
-               if (time > this.teleport_time || this.waterlevel == WATERLEVEL_NONE)
+               if (time > PHYS_TELEPORT_TIME(this) || this.waterlevel == WATERLEVEL_NONE)
                {
                        this.flags &= ~FL_WATERJUMP;
-                       this.teleport_time = 0;
+                       PHYS_TELEPORT_TIME(this) = 0;
                }
        }
 
        else if (MUTATOR_CALLHOOK(PM_Physics, this, maxspeed_mod))
                { }
 
+#ifdef SVQC
        else if (this.movetype == MOVETYPE_NOCLIP || this.movetype == MOVETYPE_FLY || this.movetype == MOVETYPE_FLY_WORLDONLY || MUTATOR_CALLHOOK(IsFlying, this))
+#elif defined(CSQC)
+       else if (this.move_movetype == MOVETYPE_NOCLIP || this.move_movetype == MOVETYPE_FLY || this.move_movetype == MOVETYPE_FLY_WORLDONLY || MUTATOR_CALLHOOK(IsFlying, this))
+#endif
                PM_fly(this, maxspeed_mod);
 
        else if (this.waterlevel >= WATERLEVEL_SWIMMING)
@@ -1474,10 +1507,4 @@ void CSQC_ClientMovement_PlayerMove_Frame(entity this)
        SELFPARAM();
 #endif
        PM_Main(this);
-#ifdef CSQC
-       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
 }