]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/server/cl_physics.qc
erm, little "workaround" ;)
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / cl_physics.qc
index 3c830e6d2f1c7795d2fbf1b6cceed2b42ce5202d..c9de732051750e895e4cdb9f4b4141f800aedf53 100644 (file)
@@ -33,6 +33,13 @@ float sv_airspeedlimit_nonqw;
 .float wasFlying;
 .float spectatorspeed;
 
+.float multijump_count;
+.float multijump_ready;
+.float prevjumpbutton;
+
+.float prevtopspeed; // store the top speed during the last 0.25 seconds to make dodging at full speeds easier
+.float prevtopspeed_time;
+
 /*
 =============
 PlayerJump
@@ -66,9 +73,39 @@ void PlayerJump (void)
                return;
        }
 
-       if (!doublejump)
-       if (!(self.flags & FL_ONGROUND))
-               return;
+       if (cvar("g_multijump"))
+       {
+               if (self.prevjumpbutton == FALSE && !(self.flags & FL_ONGROUND)) // jump button pressed this frame and we are in midair
+                       self.multijump_ready = TRUE;  // this is necessary to check that we released the jump button and pressed it again
+               else
+                       self.multijump_ready = FALSE;
+       }
+
+       if(self.multijump_ready && self.multijump_count < cvar("g_multijump") && self.velocity_z > cvar("g_multijump_speed"))
+       {
+               if (cvar("g_multijump") > 0)
+               {
+                       if (cvar("g_multijump_add") == 0) // in this case we make the z velocity == jumpvelocity
+                               self.velocity_z = 0;
+
+                       float curspeed;
+                       curspeed = vlen(self.velocity);
+                       local vector wishvel, wishdir;
+                       makevectors(self.v_angle);
+                       wishvel = v_forward * self.movement_x + v_right * self.movement_y;
+                       wishdir = normalize(wishvel);
+                       if(wishdir_x != 0 && wishdir_y != 0) // don't remove all speed if player isnt pressing any movement keys
+                       {
+                               self.velocity_x = wishdir_x * max(curspeed, self.prevtopspeed); // allow "dodging" at a multijump
+                               self.velocity_y = wishdir_y * max(curspeed, self.prevtopspeed);
+                       }
+                       self.multijump_count += 1;
+               }
+               self.multijump_ready = FALSE; // require releasing and pressing the jump button again for the next jump
+       }
+       else if (!doublejump)
+               if (!(self.flags & FL_ONGROUND))
+                       return;
 
        if(!sv_pogostick)
                if (!(self.flags & FL_JUMPRELEASED))
@@ -652,7 +689,7 @@ void SV_PlayerPhysics()
        float buttons_prev;
        float not_allowed_to_move;
        string c;
-
+       
        // fix physics stats for g_movement_highspeed
        self.stat_sv_airaccel_qw = AdjustAirAccelQW(sv_airaccel_qw, autocvar_g_movement_highspeed);
        if(sv_airstrafeaccel_qw)
@@ -897,6 +934,20 @@ void SV_PlayerPhysics()
 
        if(self.classname == "player")
        {
+               if(self.flags & FL_ONGROUND)
+               {
+                       if (cvar("g_multijump") > 0)
+                               self.multijump_count = 0;
+                       else
+                               self.multijump_count = -2; // the cvar value for infinite jumps is -1, so this needs to be smaller
+               }
+
+               if(vlen(self.velocity) >= self.prevtopspeed || time - self.prevtopspeed_time > 0.25)
+               {
+                       self.prevtopspeed_time = time;
+                       self.prevtopspeed = vlen('1 0 0' * self.velocity_x + '0 1 0' * self.velocity_y);
+               }
+
                if (self.BUTTON_JUMP)
                        PlayerJump ();
                else
@@ -904,6 +955,7 @@ void SV_PlayerPhysics()
 
                if (self.waterlevel == WATERLEVEL_SWIMMING)
                        CheckWaterJump ();
+               self.prevjumpbutton = self.BUTTON_JUMP;
        }
 
        if (self.flags & FL_WATERJUMP )
@@ -1205,7 +1257,13 @@ void SV_PlayerPhysics()
 
                        // CPM
                        if(sv_airstopaccelerate)
-                               airaccel = airaccel + (sv_airstopaccelerate*maxspd_mod - airaccel) * max(0, -(self.velocity * wishdir));
+                       {
+                               vector curdir;
+                               curdir = self.velocity;
+                               curdir_z = 0;
+                               curdir = normalize(curdir);
+                               airaccel = airaccel + (sv_airstopaccelerate*maxspd_mod - airaccel) * max(0, -(curdir * wishdir));
+                       }
                        // note that for straight forward jumping:
                        // step = accel * frametime * wishspeed0;
                        // accel  = bound(0, wishspeed - vel_xy_current, step) * accelqw + step * (1 - accelqw);