]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mutators/mutator/dodging/sv_dodging.qc
Merge branch 'master' into Mario/invasion_types
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / dodging / sv_dodging.qc
index 88547f7bf4c2268e3dabd7507152aa100fa9d87d..d62aa42c4e529e8c64ff85798a8e4a85b98534b9 100644 (file)
@@ -12,7 +12,6 @@
 #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
-#define PHYS_DODGING_PRESSED_KEYS(s)           (s).pressedkeys
 
 // we ran out of stats slots! TODO: re-enable this when prediction is available for dodging
 #if 0
 #ifdef CSQC
        #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)
        #define PHYS_DODGING_FRAMETIME                          sys_frametime
-       #define PHYS_DODGING_TIMEOUT(s)                         s.cvar_cl_dodging_timeout
+       #define PHYS_DODGING_TIMEOUT(s)                         CS(s).cvar_cl_dodging_timeout
+       #define PHYS_DODGING_PRESSED_KEYS(s)            CS(s).pressedkeys
 #endif
 
 #ifdef SVQC
@@ -51,7 +52,7 @@ bool autocvar_sv_dodging_sound;
 #include <common/animdecide.qh>
 #include <common/physics/player.qh>
 
-.float cvar_cl_dodging_timeout = _STAT(DODGING_TIMEOUT);
+.float cvar_cl_dodging_timeout;
 
 REGISTER_MUTATOR(dodging, cvar("g_dodging"))
 {
@@ -156,9 +157,10 @@ bool PM_dodging_checkpressedkeys(entity this)
        float tap_direction_x = 0;
        float tap_direction_y = 0;
        bool dodge_detected = false;
+       vector mymovement = PHYS_CS(this).movement;
 
        #define X(COND,BTN,RESULT)                                                                                                                      \
-       if (this.movement_##COND)                                                                                               \
+       if (mymovement_##COND)                                                                                          \
                /* is this a state change? */                                                                                                   \
                if(!(PHYS_DODGING_PRESSED_KEYS(this) & KEY_##BTN) || frozen_no_doubletap) {             \
                                tap_direction_##RESULT;                                                                                                 \
@@ -236,7 +238,7 @@ void PM_dodging(entity this)
        if (this.dodging_action == 1)
        {
                //disable jump key during dodge accel phase
-               if(this.movement_z > 0) { this.movement_z = 0; }
+               if(PHYS_CS(this).movement.z > 0) { PHYS_CS(this).movement_z = 0; }
 
                this.velocity += ((this.dodging_direction_y * velocity_difference) * v_right)
                                        + ((this.dodging_direction_x * velocity_difference) * v_forward);
@@ -279,10 +281,10 @@ void PM_dodging_GetPressedKeys(entity this)
        PM_dodging_checkpressedkeys(this);
 
        int keys = this.pressedkeys;
-       keys = BITSET(keys, KEY_FORWARD,        this.movement.x > 0);
-       keys = BITSET(keys, KEY_BACKWARD,       this.movement.x < 0);
-       keys = BITSET(keys, KEY_RIGHT,          this.movement.y > 0);
-       keys = BITSET(keys, KEY_LEFT,           this.movement.y < 0);
+       keys = BITSET(keys, KEY_FORWARD,        PHYS_CS(this).movement.x > 0);
+       keys = BITSET(keys, KEY_BACKWARD,       PHYS_CS(this).movement.x < 0);
+       keys = BITSET(keys, KEY_RIGHT,          PHYS_CS(this).movement.y > 0);
+       keys = BITSET(keys, KEY_LEFT,           PHYS_CS(this).movement.y < 0);
 
        keys = BITSET(keys, KEY_JUMP,           PHYS_INPUT_BUTTON_JUMP(this));
        keys = BITSET(keys, KEY_CROUCH,         PHYS_INPUT_BUTTON_CROUCH(this));
@@ -305,6 +307,13 @@ MUTATOR_HOOKFUNCTION(dodging, PlayerPhysics)
 
 REPLICATE(cvar_cl_dodging_timeout, float, "cl_dodging_timeout");
 
+MUTATOR_HOOKFUNCTION(dodging, PlayerPreThink)
+{
+       entity player = M_ARGV(0, entity);
+
+       STAT(DODGING_TIMEOUT, player) = CS(player).cvar_cl_dodging_timeout;
+}
+
 MUTATOR_HOOKFUNCTION(dodging, GetPressedKeys)
 {
        entity player = M_ARGV(0, entity);