#include "sv_dodging.qh"
+#define PHYS_DODGING g_dodging
+#define PHYS_DODGING_DELAY autocvar_sv_dodging_delay
+#define PHYS_DODGING_DISTANCE_THRESHOLD autocvar_sv_dodging_wall_distance_threshold
+#define PHYS_DODGING_FROZEN_NODOUBLETAP autocvar_sv_dodging_frozen_doubletap
+#define PHYS_DODGING_HEIGHT_THRESHOLD autocvar_sv_dodging_height_threshold
+#define PHYS_DODGING_HORIZ_SPEED autocvar_sv_dodging_horiz_speed
+#define PHYS_DODGING_HORIZ_SPEED_FROZEN autocvar_sv_dodging_horiz_speed_frozen
+#define PHYS_DODGING_RAMP_TIME autocvar_sv_dodging_ramp_time
+#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
+
+// we ran out of stats slots! TODO: re-enable this when prediction is available for dodging
+#if 0
#define PHYS_DODGING STAT(DODGING, this)
#define PHYS_DODGING_DELAY STAT(DODGING_DELAY, this)
#define PHYS_DODGING_DISTANCE_THRESHOLD STAT(DODGING_DISTANCE_THRESHOLD, this)
#define PHYS_DODGING_UP_SPEED STAT(DODGING_UP_SPEED, this)
#define PHYS_DODGING_WALL STAT(DODGING_WALL, this)
#define PHYS_DODGING_AIR STAT(DODGING_AIR, this)
-#define PHYS_DODGING_PRESSED_KEYS(s) (s).pressedkeys
+#define PHYS_DODGING_MAXSPEED STAT(DODGING_MAXSPEED, this)
+#endif
#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_PRESSED_KEYS(s) CS(s).pressedkeys
#endif
#ifdef SVQC
makevectors(this.angles);
+ bool wall_dodge = false;
+
if(!PHYS_DODGING_AIR)
- if (check_close_to_ground(this, PHYS_DODGING_HEIGHT_THRESHOLD) != 1
- && check_close_to_wall(this, PHYS_DODGING_DISTANCE_THRESHOLD) != 1)
- return true;
+ if(!check_close_to_ground(this, PHYS_DODGING_HEIGHT_THRESHOLD))
+ {
+ wall_dodge = check_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 true;
+ }
+
+ if(!wall_dodge && PHYS_DODGING_MAXSPEED && vdist(this.velocity, >, PHYS_DODGING_MAXSPEED))
+ return false;
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; \
if (!PHYS_DODGING)
return;
- if (IS_DEAD(this))
- return;
-
- // when swimming, no dodging allowed..
- if (this.waterlevel >= WATERLEVEL_SWIMMING)
+ // when swimming or dead, no dodging allowed..
+ if (this.waterlevel >= WATERLEVEL_SWIMMING || IS_DEAD(this))
{
this.dodging_action = 0;
this.dodging_direction_x = 0;
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);
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));