From 6f8580dc5709394d3764cba7212119356908cfb7 Mon Sep 17 00:00:00 2001 From: Mario Date: Thu, 13 Oct 2016 03:05:52 +1000 Subject: [PATCH] Add an option to apply gravity on slick surfaces (so one slides down slopes) --- defaultXonotic.cfg | 2 ++ qcsrc/common/physics/movetypes/movetypes.qh | 5 +++++ qcsrc/common/physics/player.qc | 23 +++++++++++++++++++-- qcsrc/common/physics/player.qh | 3 +++ qcsrc/common/stats.qh | 5 +++++ qcsrc/ecs/systems/physics.qc | 2 ++ 6 files changed, 38 insertions(+), 2 deletions(-) diff --git a/defaultXonotic.cfg b/defaultXonotic.cfg index fe07038e7..8eaf852e7 100644 --- a/defaultXonotic.cfg +++ b/defaultXonotic.cfg @@ -289,6 +289,8 @@ set sv_gibhealth 100 "Minus health a dead body must have in order to get gibbed" set sv_friction_on_land 0 set sv_friction_slick 0.5 +set sv_slick_applygravity 0 + set sv_aircontrol_backwards 0 "apply forward aircontrol options to backward movement" set sv_player_viewoffset "0 0 35" "view offset of the player model" diff --git a/qcsrc/common/physics/movetypes/movetypes.qh b/qcsrc/common/physics/movetypes/movetypes.qh index db5d29cef..46e80fbc3 100644 --- a/qcsrc/common/physics/movetypes/movetypes.qh +++ b/qcsrc/common/physics/movetypes/movetypes.qh @@ -3,6 +3,9 @@ #define IS_ONGROUND(s) boolean((s).flags & FL_ONGROUND) #define SET_ONGROUND(s) ((s).flags |= FL_ONGROUND) #define UNSET_ONGROUND(s) ((s).flags &= ~FL_ONGROUND) +#define IS_ONSLICK(s) boolean((s).flags & FL_ONSLICK) +#define SET_ONSLICK(s) ((s).flags |= FL_ONSLICK) +#define UNSET_ONSLICK(s) ((s).flags &= ~FL_ONSLICK) #ifdef CSQC .float bouncestop; @@ -79,6 +82,8 @@ const int MOVETYPE_ANGLENOCLIP = 1; const int MOVETYPE_ANGLECLIP = 2; #endif +const int FL_ONSLICK = BIT(20); + const int MOVETYPE_FAKEPUSH = 13; const int MOVEFLAG_VALID = BIT(23); diff --git a/qcsrc/common/physics/player.qc b/qcsrc/common/physics/player.qc index 09882c02d..cbfbaaaca 100644 --- a/qcsrc/common/physics/player.qc +++ b/qcsrc/common/physics/player.qc @@ -307,7 +307,7 @@ bool PlayerJump(entity this) } if (!doublejump) - if (!IS_ONGROUND(this)) + if (!IS_ONGROUND(this) && !IS_ONSLICK(this)) return IS_JUMP_HELD(this); bool track_jump = PHYS_CL_TRACK_CANJUMP(this); @@ -344,7 +344,7 @@ bool PlayerJump(entity this) } } - if (!WAS_ONGROUND(this)) + if (!WAS_ONGROUND(this) && !WAS_ONSLICK(this)) { #ifdef SVQC if(autocvar_speedmeter) @@ -366,6 +366,7 @@ bool PlayerJump(entity this) this.velocity_z += mjumpheight; UNSET_ONGROUND(this); + UNSET_ONSLICK(this); SET_JUMP_HELD(this); #ifdef SVQC @@ -641,6 +642,24 @@ void PM_Footsteps(entity this) #endif } +void PM_check_slick(entity this) +{ + if(!IS_ONGROUND(this)) + return; + + if(!PHYS_SLICK_APPLYGRAVITY(this)) + return; + + tracebox(this.origin, this.mins, this.maxs, this.origin - '0 0 1', MOVE_NOMONSTERS, this); + if (trace_dphitq3surfaceflags & Q3SURFACEFLAG_SLICK) + { + UNSET_ONGROUND(this); + SET_ONSLICK(this); + } + else + UNSET_ONSLICK(this); +} + void PM_check_blocked(entity this) { #ifdef SVQC diff --git a/qcsrc/common/physics/player.qh b/qcsrc/common/physics/player.qh index 1899b1f60..5c0b10417 100644 --- a/qcsrc/common/physics/player.qh +++ b/qcsrc/common/physics/player.qh @@ -97,6 +97,8 @@ bool IsFlying(entity a); #define UPWARD_VELOCITY_CLEARS_ONGROUND(s) STAT(GAMEPLAYFIX_UPVELOCITYCLEARSONGROUND, s) +#define PHYS_SLICK_APPLYGRAVITY(s) STAT(SLICK_APPLYGRAVITY, s) + #define PHYS_INPUT_BUTTON_ATCK(s) PHYS_INPUT_BUTTON_BUTTON1(s) #define PHYS_INPUT_BUTTON_JUMP(s) PHYS_INPUT_BUTTON_BUTTON2(s) #define PHYS_INPUT_BUTTON_ATCK2(s) PHYS_INPUT_BUTTON_BUTTON3(s) @@ -156,6 +158,7 @@ STATIC_INIT(PHYS_INPUT_BUTTON_JETPACK) #define UNSET_JUMP_HELD(s) ((s).flags |= FL_JUMPRELEASED) #define WAS_ONGROUND(s) boolean((s).lastflags & FL_ONGROUND) +#define WAS_ONSLICK(s) boolean((s).lastflags & FL_ONSLICK) #define ITEMS_STAT(s) ((s).items) diff --git a/qcsrc/common/stats.qh b/qcsrc/common/stats.qh index e6cc5530c..09921c6f8 100644 --- a/qcsrc/common/stats.qh +++ b/qcsrc/common/stats.qh @@ -263,6 +263,11 @@ REGISTER_STAT(CAMERA_SPECTATOR, int) REGISTER_STAT(SPECTATORSPEED, float) +#ifdef SVQC +bool autocvar_sv_slick_applygravity; +#endif +REGISTER_STAT(SLICK_APPLYGRAVITY, bool, autocvar_sv_slick_applygravity) + #ifdef SVQC #include "physics/movetypes/movetypes.qh" #endif diff --git a/qcsrc/ecs/systems/physics.qc b/qcsrc/ecs/systems/physics.qc index c0a47e39b..a08422dcf 100644 --- a/qcsrc/ecs/systems/physics.qc +++ b/qcsrc/ecs/systems/physics.qc @@ -62,6 +62,8 @@ void sys_phys_update(entity this, float dt) goto end; } + PM_check_slick(this); + if (IS_SVQC && !PHYS_FIXANGLE(this)) { this.angles = '0 1 0' * this.v_angle.y; } if (IS_PLAYER(this)) { if (IS_ONGROUND(this)) { -- 2.39.2