]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mutators/mutator/dodging/sv_dodging.qc
Merge branch 't0uYK8Ne/set_slick_friction' into 'master'
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / dodging / sv_dodging.qc
index b3a938bcb4bf0bdfabae87ae2e76bf60fb17e2d1..c97308d58ab1f8cd8a7db8adcd738c277baa739e 100644 (file)
@@ -16,7 +16,8 @@
 #define PHYS_DODGING_UP_SPEED                          autocvar_sv_dodging_up_speed
 #define PHYS_DODGING_WALL                                      autocvar_sv_dodging_wall_dodging
 #define PHYS_DODGING_AIR                                       autocvar_sv_dodging_air_dodging
-#define PHYS_DODGING_MAXSPEED                          autocvar_sv_dodging_maxspeed // TODO separate max air speed, fix frozen dodging
+#define PHYS_DODGING_MAXSPEED                          autocvar_sv_dodging_maxspeed
+#define PHYS_DODGING_AIR_MAXSPEED                      autocvar_sv_dodging_air_maxspeed
 
 // we ran out of stats slots! TODO: re-enable this when prediction is available for dodging
 #if 0
 #define PHYS_DODGING_WALL                                      STAT(DODGING_WALL, this)
 #define PHYS_DODGING_AIR                                       STAT(DODGING_AIR, this)
 #define PHYS_DODGING_MAXSPEED                          STAT(DODGING_MAXSPEED, this)
+#define PHYS_DODGING_AIR_MAXSPEED                      STAT(DODGING_AIR_MAXSPEED, this)
 #endif
 
 #ifdef CSQC
+       float cvar_cl_dodging_timeout;
        #define PHYS_DODGING_FRAMETIME                          (1 / (frametime <= 0 ? 60 : frametime))
        #define PHYS_DODGING_TIMEOUT(s)                         STAT(DODGING_TIMEOUT)
        #define PHYS_DODGING_PRESSED_KEYS(s)            (s).pressedkeys
 #elif defined(SVQC)
+       .float cvar_cl_dodging_timeout;
        #define PHYS_DODGING_FRAMETIME                          sys_frametime
        #define PHYS_DODGING_TIMEOUT(s)                         CS(s).cvar_cl_dodging_timeout
        #define PHYS_DODGING_PRESSED_KEYS(s)            CS(s).pressedkeys
@@ -54,8 +58,6 @@ bool autocvar_sv_dodging_sound;
 #include <common/animdecide.qh>
 #include <common/physics/player.qh>
 
-.float cvar_cl_dodging_timeout;
-
 REGISTER_MUTATOR(dodging, cvar("g_dodging"))
 {
        // this just turns on the cvar.
@@ -142,10 +144,6 @@ float determine_force(entity player) {
 
 bool PM_dodging_checkpressedkeys(entity this)
 {
-       // first check if the last dodge is far enough back in time so we can dodge again
-       if ((time - this.last_dodging_time) < PHYS_DODGING_DELAY)
-               return false;
-
        bool frozen_dodging = (PHYS_FROZEN(this) && PHYS_DODGING_FROZEN(this));
        bool frozen_no_doubletap = (frozen_dodging && !PHYS_DODGING_FROZEN_DOUBLETAP);
 
@@ -154,17 +152,19 @@ bool PM_dodging_checkpressedkeys(entity this)
        bool dodge_detected = false;
        vector mymovement = PHYS_CS(this).movement;
 
-       #define X(COND,BTN,RESULT)                                                                                                                      \
-       if (mymovement_##COND)                                                                                          \
-               /* is this a state change? */                                                                                                   \
-               if(!(PHYS_DODGING_PRESSED_KEYS(this) & KEY_##BTN) || frozen_no_doubletap) {             \
-                       tap_direction_##RESULT;                                                                                                 \
-                       if ((time - this.last_##BTN##_KEY_time) < PHYS_DODGING_TIMEOUT(this) || frozen_no_doubletap)    \
-                               dodge_detected = true;                                                                                          \
-                       if(PHYS_INPUT_BUTTON_DODGE(this))                                                                               \
-                               dodge_detected = true;                                                                                          \
-                       this.last_##BTN##_KEY_time = time;                                                                              \
-               }
+       #define X(COND,BTN,RESULT)                                                                                                                                                              \
+       if (mymovement_##COND) {                                                                                                                                                                \
+               /* is this a state change? */                                                                                                                                           \
+               if(!(PHYS_DODGING_PRESSED_KEYS(this) & KEY_##BTN) || frozen_no_doubletap) {                                                     \
+                       tap_direction_##RESULT;                                                                                                                                                 \
+                       if ((time - this.last_##BTN##_KEY_time) < PHYS_DODGING_TIMEOUT(this) || frozen_no_doubletap) {  \
+                               dodge_detected = true;                                                                                                                                          \
+                       } else if(PHYS_INPUT_BUTTON_DODGE(this)) {                                                                                                              \
+                               dodge_detected = true;                                                                                                                                          \
+                       }                                                                                                                                                                                               \
+                       this.last_##BTN##_KEY_time = time;                                                                                                                              \
+               }                                                                                                                                                                                                       \
+       }
        X(x < 0, BACKWARD,      x--);
        X(x > 0, FORWARD,       x++);
        X(y < 0, LEFT,          y--);
@@ -173,20 +173,19 @@ bool PM_dodging_checkpressedkeys(entity this)
 
        if (!dodge_detected) return false;
 
-       makevectors(this.angles);
-
-       bool wall_dodge = false;
+       // this check has to be after checking keys:
+       // the first key press of the double tap is allowed to be before dodging delay,
+       // only the second has to be after, otherwise +dodge gives an advantage because typical repress time is 0.1 s
+       // or higher which means players using +dodge would be able to do it more often
+       if ((time - this.last_dodging_time) < PHYS_DODGING_DELAY)
+               return false;
 
-       if(!PHYS_DODGING_AIR)
-       if(!is_close_to_ground(this, PHYS_DODGING_HEIGHT_THRESHOLD)) // TODO first check wall wallldodging - this fails for sloped walls
-       {
-               wall_dodge = (PHYS_DODGING_WALL && is_close_to_wall(this, PHYS_DODGING_DISTANCE_THRESHOLD));
-               if(!wall_dodge) // we're not on the ground, and wall dodging isn't allowed, end it!
-                       return false;
-       }
+       makevectors(this.angles);
 
-       if(!wall_dodge && PHYS_DODGING_MAXSPEED && vdist(this.velocity, >, PHYS_DODGING_MAXSPEED))
-               return false;
+       bool can_dodge = (is_close_to_ground(this, PHYS_DODGING_HEIGHT_THRESHOLD) && (PHYS_DODGING_MAXSPEED == 0 || vdist(this.velocity, <, PHYS_DODGING_MAXSPEED)));
+       bool can_wall_dodge = (PHYS_DODGING_WALL && is_close_to_wall(this, PHYS_DODGING_DISTANCE_THRESHOLD));
+       bool can_air_dodge = (PHYS_DODGING_AIR && (PHYS_DODGING_AIR_MAXSPEED == 0 || vdist(this.velocity, <, PHYS_DODGING_AIR_MAXSPEED)));
+       if (!can_dodge && !can_wall_dodge && !can_air_dodge) return false;
 
        this.last_dodging_time = time;
 
@@ -233,14 +232,11 @@ void PM_dodging(entity this)
        // will be called ramp_time/frametime times = 2 times. so, we need to
        // add 0.5 * the total speed each frame until the dodge action is done..
        float common_factor = PHYS_DODGING_FRAMETIME / PHYS_DODGING_RAMP_TIME;
-       //common_factor /= 2; // FIXME this is WRONG but this function is called twice per frame!!!
-
-       // if ramp time is smaller than frametime we get problems ;D
-       common_factor = min(common_factor, 1); // TODO necessary with dodging_force_remaining?
+       // NOTE: depending on cl_netfps the client may (and probably will) send more input frames during each server frame
+       // but common_factor uses server frame rate so players with higher cl_netfps will ramp slightly faster
 
        float velocity_increase = min(common_factor * this.dodging_force_total, this.dodging_force_remaining);
        this.dodging_force_remaining -= velocity_increase;
-       LOG_INFOF("time %f velocity_increase: %f\n", time, velocity_increase);
        this.velocity += this.dodging_direction.x * velocity_increase * v_forward
                       + this.dodging_direction.y * velocity_increase * v_right;
 
@@ -292,7 +288,6 @@ void PM_dodging_GetPressedKeys(entity this)
 MUTATOR_HOOKFUNCTION(dodging, PlayerPhysics)
 {
        entity player = M_ARGV(0, entity);
-       //LOG_INFOF("player %s, physics %f\n", player.netname, time);
 
 #ifdef CSQC
        PM_dodging_GetPressedKeys(player);
@@ -307,7 +302,6 @@ REPLICATE(cvar_cl_dodging_timeout, float, "cl_dodging_timeout");
 MUTATOR_HOOKFUNCTION(dodging, GetPressedKeys)
 {
        entity player = M_ARGV(0, entity);
-       //LOG_INFOF("player %s, keys %f\n", player.netname, time);
 
        PM_dodging_checkpressedkeys(player);
 }