From d2a43db7e3e17a3e32e7faaf5f610cdf42f31da8 Mon Sep 17 00:00:00 2001 From: Andrey Akhmichin <15944199+nekonomicon@users.noreply.github.com> Date: Sun, 28 Jan 2024 09:13:49 +0000 Subject: [PATCH] HL 25th anniversary pushable fix. (#427) --- dlls/func_break.cpp | 76 +++++++++++++++++++++++++++++++-------------- dlls/game.cpp | 4 +++ dlls/game.h | 1 + 3 files changed, 57 insertions(+), 24 deletions(-) diff --git a/dlls/func_break.cpp b/dlls/func_break.cpp index 0c5e0114..f1829d6c 100644 --- a/dlls/func_break.cpp +++ b/dlls/func_break.cpp @@ -928,22 +928,25 @@ void CPushable::Move( CBaseEntity *pOther, int push ) if( pOther->IsPlayer() ) { - // g-cont. fix pushable acceleration bug (now implemented as cvar) - if (pushablemode.value == 1) - { - // Allow player push when moving right, left and back too - if ( push && !(pevToucher->button & (IN_FORWARD|IN_MOVERIGHT|IN_MOVELEFT|IN_BACK)) ) - return; - // Require player walking back when applying '+use' on pushable - if ( !push && !(pevToucher->button & (IN_BACK)) ) - return; - } - else + if( pushablemode.value == -1 ) { // Don't push unless the player is pushing forward and NOT use (pull) - if( push && !( pevToucher->button & ( IN_FORWARD | IN_USE ) ) ) + if( push && !( pevToucher->button & ( IN_FORWARD | IN_USE ))) return; } + // g-cont. fix pushable acceleration bug (now implemented as cvar) + else if( pushablemode.value != 0 ) + { + // Allow player push when moving right, left and back too + if( push && !( pevToucher->button & ( IN_FORWARD | IN_MOVERIGHT | IN_MOVELEFT | IN_BACK ))) + return; + // Require player walking back when applying '+use' on pushable + if( !push && !( pevToucher->button & ( IN_BACK ))) + return; + } + // Don't push when +use pressed + else if( push && ( pevToucher->button & ( IN_USE ))) + return; playerTouch = 1; } @@ -964,30 +967,55 @@ void CPushable::Move( CBaseEntity *pOther, int push ) else factor = 0.25f; - // Spirit fix for pushable acceleration - if (pushablemode.value == 2) + if( pushablemode.value != 0 ) { - if (!push) - factor *= 0.5f; + pev->velocity.x += pevToucher->velocity.x * factor; + pev->velocity.y += pevToucher->velocity.y * factor; } + else + { + if( push ) + { + factor = 0.25f; + pev->velocity.x += pevToucher->velocity.x * factor; + pev->velocity.y += pevToucher->velocity.y * factor; + } + else + { + // fix for pushable acceleration + if( sv_pushable_fixed_tick_fudge.value >= 0 ) + factor *= ( sv_pushable_fixed_tick_fudge.value * gpGlobals->frametime ); - pev->velocity.x += pevToucher->velocity.x * factor; - pev->velocity.y += pevToucher->velocity.y * factor; + if( fabs( pev->velocity.x ) < fabs( pevToucher->velocity.x - pevToucher->velocity.x * factor )) + pev->velocity.x += pevToucher->velocity.x * factor; + if( fabs( pev->velocity.y ) < fabs( pevToucher->velocity.y - pevToucher->velocity.y * factor )) + pev->velocity.y += pevToucher->velocity.y * factor; + } + } float length = sqrt( pev->velocity.x * pev->velocity.x + pev->velocity.y * pev->velocity.y ); - if( push && ( length > MaxSpeed() ) ) + if( ( push && pushablemode.value != 0 ) + || pushablemode.value == 0 ) { - pev->velocity.x = (pev->velocity.x * MaxSpeed() / length ); - pev->velocity.y = (pev->velocity.y * MaxSpeed() / length ); + if( length > MaxSpeed()) + { + pev->velocity.x = ( pev->velocity.x * MaxSpeed() / length ); + pev->velocity.y = ( pev->velocity.y * MaxSpeed() / length ); + } } + if( playerTouch ) { - pevToucher->velocity.x = pev->velocity.x; - pevToucher->velocity.y = pev->velocity.y; + if( push || pushablemode.value != 0 ) + { + pevToucher->velocity.x = pev->velocity.x; + pevToucher->velocity.y = pev->velocity.y; + } + if( ( gpGlobals->time - m_soundTime ) > 0.7f ) { m_soundTime = gpGlobals->time; - if( length > 0 && FBitSet( pev->flags,FL_ONGROUND ) ) + if( length > 0 && FBitSet( pev->flags, FL_ONGROUND )) { m_lastSound = RANDOM_LONG( 0, 2 ); EMIT_SOUND( ENT( pev ), CHAN_WEAPON, m_soundNames[m_lastSound], 0.5f, ATTN_NORM ); diff --git a/dlls/game.cpp b/dlls/game.cpp index e64f0417..f2c74d6b 100644 --- a/dlls/game.cpp +++ b/dlls/game.cpp @@ -457,6 +457,8 @@ cvar_t sk_player_leg3 = { "sk_player_leg3","1" }; // END Cvars for Skill Level settings +cvar_t sv_pushable_fixed_tick_fudge = { "sv_pushable_fixed_tick_fudge", "15" }; + // Register your console variables here // This gets called one time when the game is initialied void GameDLLInit( void ) @@ -883,6 +885,8 @@ void GameDLLInit( void ) CVAR_REGISTER( &sk_player_leg3 ); // END REGISTER CVARS FOR SKILL LEVEL STUFF + CVAR_REGISTER( &sv_pushable_fixed_tick_fudge ); + SERVER_COMMAND( "exec skill.cfg\n" ); } diff --git a/dlls/game.h b/dlls/game.h index 5f7bee1c..069324bb 100644 --- a/dlls/game.h +++ b/dlls/game.h @@ -43,6 +43,7 @@ extern cvar_t teamoverride; extern cvar_t defaultteam; extern cvar_t allowmonsters; extern cvar_t bhopcap; +extern cvar_t sv_pushable_fixed_tick_fudge; // Engine Cvars extern cvar_t *g_psv_gravity;