From ea81fccfb5f30461081c1d6c067e98ee2cfee754 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Sun, 24 Aug 2025 21:39:24 -0400 Subject: [PATCH] Make friction stuff look nicer and add friction loss on waterrun --- src/k_kart.c | 52 ++++++++++++++++++++++++------------------------- src/k_terrain.c | 3 +-- src/p_local.h | 1 + src/p_map.c | 4 ++-- src/p_spec.c | 19 +++++++++++++++--- src/p_spec.h | 2 ++ 6 files changed, 47 insertions(+), 34 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 29fdff8a6..816ce8d2d 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -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 diff --git a/src/k_terrain.c b/src/k_terrain.c index 91837a81b..1816b1f03 100644 --- a/src/k_terrain.c +++ b/src/k_terrain.c @@ -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 diff --git a/src/p_local.h b/src/p_local.h index 1ff20a9ac..97154a8b1 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -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); diff --git a/src/p_map.c b/src/p_map.c index 4571ab989..e2d06ed34 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -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; } diff --git a/src/p_spec.c b/src/p_spec.c index d28fd23ed..cb4d1b8ce 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -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) { diff --git a/src/p_spec.h b/src/p_spec.h index a1d389598..af15e96de 100644 --- a/src/p_spec.h +++ b/src/p_spec.h @@ -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);