]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/mutators/mutator/dodging/sv_dodging.qc
Merge branch 'master' into Mario/qc_camstuff
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / mutators / mutator / dodging / sv_dodging.qc
index c8182cdd88e5985789ca50a52f390bad2f8b96b2..66d18ac671e8ad9c5ce074c8f74eee7e494fb9f5 100644 (file)
 #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
@@ -56,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.
@@ -113,20 +113,20 @@ REGISTER_MUTATOR(dodging, true);
                return true;
 
 // returns true if the player is close to a wall
-bool is_close_to_wall(entity this, float threshold)
+bool is_close_to_wall(entity this, float threshold, vector forward, vector right)
 {
-       X(v_right);
-       X(-v_right);
-       X(v_forward);
-       X(-v_forward);
+       X(right);
+       X(-right);
+       X(forward);
+       X(-forward);
 
        return false;
 }
 
-bool is_close_to_ground(entity this, float threshold)
+bool is_close_to_ground(entity this, float threshold, vector up)
 {
        if (IS_ONGROUND(this)) return true;
-       X(-v_up); // necessary for dodging down a slope using doubletap (using `+dodge` works anyway)
+       X(-up); // necessary for dodging down a slope using doubletap (using `+dodge` works anyway)
 
        return false;
 }
@@ -156,10 +156,8 @@ bool PM_dodging_checkpressedkeys(entity this)
        if (mymovement_##COND) {                                                                                                                                                                \
                /* is this a state change? */                                                                                                                                           \
                if(!(PHYS_DODGING_PRESSED_KEYS(this) & KEY_##BTN) || frozen_no_doubletap) {                                                     \
-                       /*LOG_INFOF("key press %f - %s\n", time, #BTN);*/                                                                                                       \
                        tap_direction_##RESULT;                                                                                                                                                 \
                        if ((time - this.last_##BTN##_KEY_time) < PHYS_DODGING_TIMEOUT(this) || frozen_no_doubletap) {  \
-                               /*LOG_INFOF("dodge repress %f (%s)\n", time - this.last_##BTN##_KEY_time, this.netname);*/              \
                                dodge_detected = true;                                                                                                                                          \
                        } else if(PHYS_INPUT_BUTTON_DODGE(this)) {                                                                                                              \
                                dodge_detected = true;                                                                                                                                          \
@@ -174,7 +172,6 @@ bool PM_dodging_checkpressedkeys(entity this)
        #undef X
 
        if (!dodge_detected) return false;
-       //LOG_INFOF("dodge keys detected %f - delay %f - %s\n", time, time - this.last_dodging_time, this.netname);
 
        // this check has to be after checking keys:
        // the first key press of the double tap is allowed to be before dodging delay,
@@ -183,10 +180,11 @@ bool PM_dodging_checkpressedkeys(entity this)
        if ((time - this.last_dodging_time) < PHYS_DODGING_DELAY)
                return false;
 
-       makevectors(this.angles);
+       vector forward, right, up;
+       MAKE_VECTORS(this.angles, forward, right, up);
 
-       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_dodge = (is_close_to_ground(this, PHYS_DODGING_HEIGHT_THRESHOLD, up) && (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, forward, right));
        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;
 
@@ -197,7 +195,6 @@ bool PM_dodging_checkpressedkeys(entity this)
 
        this.dodging_force_total = determine_force(this);
        this.dodging_force_remaining = this.dodging_force_total;
-       //LOG_INFOF("speed %d -> %f\n", vlen(vec2(this.velocity)), this.dodging_force_total);
 
        this.dodging_direction.x = tap_direction_x;
        this.dodging_direction.y = tap_direction_y;
@@ -225,11 +222,11 @@ void PM_dodging(entity this)
                return;
        }
 
-       // make sure v_up, v_right and v_forward are sane
+       vector forward, right, up;
        if(PHYS_DODGING_AIR)
-               makevectors(this.v_angle);
+               MAKE_VECTORS(this.v_angle, forward, right, up);
        else
-               makevectors(this.angles);
+               MAKE_VECTORS(this.angles, forward, right, up);
 
        // fraction of the force to apply each frame
        // if we have e.g. 0.5 sec ramptime and a frametime of 0.25, then the ramp code
@@ -241,16 +238,15 @@ void PM_dodging(entity this)
 
        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;
+       this.velocity += this.dodging_direction.x * velocity_increase * forward
+                      + this.dodging_direction.y * velocity_increase * right;
 
        // the up part of the dodge is a single shot action
        if (this.dodging_single_action == 1)
        {
                UNSET_ONGROUND(this);
 
-               this.velocity += PHYS_DODGING_UP_SPEED * v_up;
+               this.velocity += PHYS_DODGING_UP_SPEED * up;
 
 #ifdef SVQC
                if (autocvar_sv_dodging_sound)
@@ -293,7 +289,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);
@@ -308,7 +303,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);
 }