Make friction stuff look nicer and add friction loss on waterrun

This commit is contained in:
NepDisk 2025-08-24 21:39:24 -04:00
parent 2ccaefd9b0
commit ea81fccfb5
6 changed files with 47 additions and 34 deletions

View file

@ -10603,6 +10603,24 @@ fixed_t K_PlayerBaseFriction(player_t *player, fixed_t original)
return frict;
}
static inline void K_RecalculateMovefactor(mobj_t *mobj)
{
if (mobj->friction > FRACUNIT)
mobj->friction = FRACUNIT;
if (mobj->friction < 0)
mobj->friction = 0;
mobj->movefactor = FixedDiv(ORIG_FRICTION, mobj->friction);
if (mobj->movefactor < FRACUNIT)
mobj->movefactor = 19*mobj->movefactor - 18*FRACUNIT;
else
mobj->movefactor = FRACUNIT;
if (mobj->movefactor < 32)
mobj->movefactor = 32;
}
//
static void K_AdjustPlayerFriction(player_t *player)
{
@ -10630,20 +10648,7 @@ static void K_AdjustPlayerFriction(player_t *player)
{
player->mo->friction += ((FRACUNIT - prevfriction) / greasetics) * player->tiregrease;
if (player->mo->friction > FRACUNIT)
player->mo->friction = FRACUNIT;
if (player->mo->friction < 0)
player->mo->friction = 0;
player->mo->movefactor = FixedDiv(ORIG_FRICTION, player->mo->friction);
if (player->mo->movefactor < FRACUNIT)
player->mo->movefactor = 19*player->mo->movefactor - 18*FRACUNIT;
else
player->mo->movefactor = FRACUNIT;
if (player->mo->movefactor < 32)
player->mo->movefactor = 32;
K_RecalculateMovefactor(player->mo);
}
// Friction
@ -10661,21 +10666,14 @@ static void K_AdjustPlayerFriction(player_t *player)
{
player->mo->friction += 1228;
if (player->mo->friction > FRACUNIT)
player->mo->friction = FRACUNIT;
if (player->mo->friction < 0)
player->mo->friction = 0;
K_RecalculateMovefactor(player->mo);
}
player->mo->movefactor = FixedDiv(ORIG_FRICTION, player->mo->friction);
if (P_WaterRunning(player->mo))
{
player->mo->friction += 614;
if (player->mo->movefactor < FRACUNIT)
player->mo->movefactor = 19*player->mo->movefactor - 18*FRACUNIT;
else
player->mo->movefactor = FRACUNIT;
if (player->mo->movefactor < 32)
player->mo->movefactor = 32;
K_RecalculateMovefactor(player->mo);
}
// Wipeout slowdown, or getting flipped over

View file

@ -494,8 +494,7 @@ static void K_SetTerrainFriction(mobj_t *mo)
terrain = mo->terrain;
if (isPlayer && !((terrain->flags & TRF_BYPASSBOOST)
|| (mo->player->invincibilitytimer == 0 && mo->player->hyudorotimer == 0
&& mo->player->sneakertimer == 0 && mo->player->growshrinktimer <= 0)))
|| P_AllowFriction(mo)))
{
// I want this to be consistent with sector friction
// so boosts bypass friction unless specficied otherwise

View file

@ -641,6 +641,7 @@ fixed_t P_GetMobjHead(const mobj_t *);
fixed_t P_GetMobjFeet(const mobj_t *);
fixed_t P_GetMobjGround(const mobj_t *);
fixed_t P_GetMobjZMovement(mobj_t *mo);
boolean P_WaterRunning(mobj_t *thing);
void P_InitTIDHash(void);
void P_AddThingTID(mobj_t *mo);

View file

@ -2478,7 +2478,7 @@ BlockItReturn_t PIT_PushableMoved(mobj_t *thing)
return BMIT_CONTINUE;
}
static boolean P_WaterRunning(mobj_t *thing)
boolean P_WaterRunning(mobj_t *thing)
{
ffloor_t *rover = thing->floorrover;
return rover && (rover->fofflags & FOF_SWIMMABLE) &&
@ -2502,7 +2502,7 @@ fixed_t P_GetThingStepUp(mobj_t *thing, fixed_t destX, fixed_t destY)
if (P_WaterStepUp(thing) == true)
{
// Add some extra stepmove when waterskipping
// Add some extra stepmove when waterrunning
maxstep += maxstepmove;
}

View file

@ -9197,6 +9197,21 @@ static void Add_Friction(INT32 friction, INT32 movefactor, INT32 affectee, INT32
P_AddThinker(THINK_MAIN, &f->thinker);
}
// Much cleaner looking way of detecting when to use friction.
boolean P_AllowFriction(mobj_t *mobj)
{
if (!mobj->player)
return false;
if (mobj->player->invincibilitytimer
|| mobj->player->hyudorotimer
|| mobj->player->sneakertimer
|| mobj->player->growshrinktimer > 0)
return false;
return true;
}
/** Applies friction to all things in a sector.
*
* \param f Friction thinker.
@ -9229,9 +9244,7 @@ void T_Friction(friction_t *f)
// apparently, all I had to do was comment out part of the next line and
// friction works for all mobj's
// (or at least MF_PUSHABLEs, which is all I care about anyway)
if ((!(thing->flags & (MF_NOGRAVITY | MF_NOCLIP)) && thing->z == thing->floorz) && (thing->player
&& (thing->player->invincibilitytimer == 0 && thing->player->hyudorotimer == 0
&& thing->player->sneakertimer == 0 && thing->player->growshrinktimer <= 0)))
if ((!(thing->flags & (MF_NOGRAVITY | MF_NOCLIP)) && thing->z == thing->floorz) && P_AllowFriction(thing))
{
if (f->roverfriction)
{

View file

@ -621,6 +621,8 @@ struct activator_t
boolean P_ProcessSpecial(activator_t *activator, INT16 special, INT32 *args, char **stringargs);
boolean P_CanActivateSpecial(INT16 special);
boolean P_AllowFriction(mobj_t *mobj);
void P_SetupSignExit(player_t *player);
boolean P_IsMobjTouchingSectorPlane(mobj_t *mo, sector_t *sec);