[HL25] Backport fixes to pushable

Including the "sv_pushable_fixed_tick_fudge" CVAR functionality.
This commit is contained in:
Joël Troch 2024-08-28 15:54:39 +02:00
parent b61c0beadf
commit 4f0d502e4e
3 changed files with 43 additions and 12 deletions

View file

@ -964,7 +964,11 @@ void CPushable::Move(CBaseEntity* pOther, bool push)
if (pOther->IsPlayer())
{
if (push && (pevToucher->button & (IN_FORWARD | IN_USE)) == 0) // Don't push unless the player is pushing forward and NOT use (pull)
// JoshA: Used to check for FORWARD too and logic was inverted
// from comment which seems wrong.
// Fixed to just check for USE being not set for PUSH.
// Should have the right effect.
if (push && !!(pevToucher->button & IN_USE)) // Don't push unless the player is not useing (pull)
return;
playerTouch = true;
}
@ -986,19 +990,39 @@ void CPushable::Move(CBaseEntity* pOther, bool push)
else
factor = 0.25;
pev->velocity.x += pevToucher->velocity.x * factor;
pev->velocity.y += pevToucher->velocity.y * factor;
// This used to be added every 'frame', but to be consistent at high fps,
// now act as if it's added at a constant rate with a fudge factor.
extern cvar_t sv_pushable_fixed_tick_fudge;
if (!push && sv_pushable_fixed_tick_fudge.value >= 0.0f)
{
factor *= gpGlobals->frametime * sv_pushable_fixed_tick_fudge.value;
}
// JoshA: Always apply this if pushing, or if under the player's velocity.
if (push || (abs(pev->velocity.x) < abs(pevToucher->velocity.x - pevToucher->velocity.x * factor)))
pev->velocity.x += pevToucher->velocity.x * factor;
if (push || (abs(pev->velocity.y) < abs(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 (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;
// JoshA: Match the player to our pushable's velocity.
// Previously this always happened, but it should only
// happen if the player is pushing (or rather, being pushed.)
// This either stops the player in their tracks or nudges them along.
if (push)
{
pevToucher->velocity.x = pev->velocity.x;
pevToucher->velocity.y = pev->velocity.y;
}
if ((gpGlobals->time - m_soundTime) > 0.7)
{
m_soundTime = gpGlobals->time;

View file

@ -454,6 +454,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"};
cvar_t sv_busters = {"sv_busters", "0", FCVAR_SERVER};
static bool SV_InitServer()
@ -927,6 +929,8 @@ void GameDLLInit()
CVAR_REGISTER(&sk_player_leg3);
// END REGISTER CVARS FOR SKILL LEVEL STUFF
CVAR_REGISTER(&sv_pushable_fixed_tick_fudge);
InitMapLoadingUtils();
SERVER_COMMAND("exec skill.cfg\n");

View file

@ -2940,6 +2940,15 @@ void PM_CheckParamters()
pmove->maxspeed = V_min(maxspeed, pmove->maxspeed);
}
// Slow down, I'm pulling it! (a box maybe) but only when I'm standing on ground
//
// JoshA: Moved this to CheckParamters rather than working on the velocity,
// as otherwise it affects every integration step incorrectly.
if ((pmove->onground != -1) && (pmove->cmd.buttons & IN_USE))
{
pmove->maxspeed *= 1.0f / 3.0f;
}
if ((spd != 0.0) &&
(spd > pmove->maxspeed))
{
@ -3111,12 +3120,6 @@ void PM_PlayerMove(qboolean server)
}
}
// Slow down, I'm pulling it! (a box maybe) but only when I'm standing on ground
if ((pmove->onground != -1) && (pmove->cmd.buttons & IN_USE) != 0)
{
VectorScale(pmove->velocity, 0.3, pmove->velocity);
}
// Handle movement
switch (pmove->movetype)
{