diff --git a/src/k_kart.c b/src/k_kart.c index 96df5e0d3..528810383 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -3288,21 +3288,63 @@ boolean K_WaterRun(mobj_t *mobj) void K_SpawnWaterTrail(mobj_t *mobj) { - fixed_t topspeed = mobj->player ? K_GetKartSpeed(mobj->player, false, false) : K_GetKartSpeedFromStat(5); - fixed_t runspd = 14*mobj->scale; //srb2kart - runspd = FixedMul(runspd, mobj->movefactor); - fixed_t trailScale; + fixed_t topspeed = INT32_MAX; + fixed_t speed = INT32_MAX; + fixed_t runspd = 14 * mobj->scale; + fixed_t trailScale = FRACUNIT; + + if (mobj->momz != 0) + { + // Only while touching ground. + return; + } + + if (mobj->watertop == INT32_MAX || mobj->waterbottom == INT32_MIN) + { + // Invalid water plane. + return; + } + + if (!((!(mobj->eflags & MFE_VERTICALFLIP) && mobj->z + mobj->height >= mobj->watertop && mobj->z <= mobj->watertop) + || (mobj->eflags & MFE_VERTICALFLIP && mobj->z + mobj->height >= mobj->waterbottom && mobj->z <= mobj->waterbottom))) + { + // No valid watertop. + return; + } + + if (mobj->player != NULL) + { + if (mobj->player->spectator) + { + // Not as spectator. + return; + } + + if (mobj->player->carry == CR_SLIDING) + { + // Not in water slides. + return; + } + + topspeed = K_GetKartSpeed(mobj->player, false, false); + runspd = FixedMul(runspd, mobj->movefactor); + } + else + { + topspeed = FixedMul(mobj->scale, K_GetKartSpeedFromStat(5)); + } + + speed = P_AproxDistance(mobj->momx, mobj->momy); + + if (speed <= runspd) + { + // Not fast enough. + return; + } if (topspeed > runspd) { - if (mobj->player) - { - trailScale = FixedMul(FixedDiv(mobj->player->speed - runspd, topspeed - runspd), mapobjectscale); - } - else - { - trailScale = FixedMul(FixedDiv(R_PointToDist2(0, 0, mobj->momx, mobj->momy) - runspd, topspeed - runspd), mapobjectscale); - } + trailScale = FixedMul(FixedDiv(speed - runspd, topspeed - runspd), mapobjectscale); } else trailScale = mapobjectscale; // Scaling is based off difference between runspeed and top speed @@ -3382,6 +3424,13 @@ void K_SpawnWaterTrail(mobj_t *mobj) S_StartSoundAtVolume(mobj, sfx_s3kdbs, volume); } } + + // Little water sound while touching water - just a nicety. + if ((mobj->eflags & MFE_TOUCHWATER) && !(mobj->eflags & MFE_UNDERWATER)) + { + if (P_RandomChance(FRACUNIT/2) && leveltime % TICRATE == 0) + S_StartSound(mobj, sfx_floush); + } } static fixed_t K_FlameShieldDashVar(INT32 val) diff --git a/src/p_mobj.c b/src/p_mobj.c index 1b8978a74..9a9f99eca 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -3208,6 +3208,11 @@ void P_MobjCheckWater(mobj_t *mobj) return; } + if (mobj->flags & MF_APPLYTERRAIN) + { + K_SpawnWaterTrail(mobj); + } + // The rest of this code only executes on a water state change. if (!!(mobj->eflags & MFE_UNDERWATER) == wasinwater) return; @@ -8333,7 +8338,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) P_Thrust(mobj, mobj->angle, thrustamount); - if (R_PointToDist2(0, 0, mobj->momx, mobj->momy) < 8*FRACUNIT) + if (P_AproxDistance(mobj->momx, mobj->momy) <= 14*mobj->scale) { // Not moving fast enough to water run. mobj->flags2 &= ~MF2_WATERRUN; @@ -8351,6 +8356,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) if (leveltime % 6 == 0) S_StartSound(mobj, mobj->info->activesound); } + P_MobjCheckWater(mobj); break; } case MT_JAWZ: @@ -8405,7 +8411,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) K_DriftDustHandling(mobj); - if (R_PointToDist2(0, 0, mobj->momx, mobj->momy) < 8*FRACUNIT) + if (P_AproxDistance(mobj->momx, mobj->momy) <= 14*mobj->scale) { // Not moving fast enough to water run. mobj->flags2 &= ~MF2_WATERRUN; @@ -8417,6 +8423,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) && (mobj->subsector->sector->specialflags & (SSF_YELLOWPOGOSPRING|SSF_REDPOGOSPRING)))) K_DoPogoSpring(mobj, 0, 1); + P_MobjCheckWater(mobj); break; } case MT_JAWZ_DUD: @@ -8435,6 +8442,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) } else { + P_MobjCheckWater(mobj); P_SpawnGhostMobj(mobj); mobj->angle = R_PointToAngle2(0, 0, mobj->momx, mobj->momy); P_InstaThrust(mobj, mobj->angle, mobj->movefactor); @@ -8448,7 +8456,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) K_DoPogoSpring(mobj, 0, 1); } - if (R_PointToDist2(0, 0, mobj->momx, mobj->momy) < 8*FRACUNIT) + if (P_AproxDistance(mobj->momx, mobj->momy) <= 14*mobj->scale) { // Not moving fast enough to water run. mobj->flags2 &= ~MF2_WATERRUN; @@ -8459,14 +8467,17 @@ static boolean P_MobjRegularThink(mobj_t *mobj) if (leveltime % TICRATE == 0) S_StartSound(mobj, mobj->info->activesound); - } + + } + P_MobjCheckWater(mobj); break; } case MT_EGGMANITEM: /* FALLTHRU */ case MT_BANANA: mobj->friction = ORIG_FRICTION/4; + P_MobjCheckWater(mobj); if (mobj->momx || mobj->momy) { @@ -8488,6 +8499,8 @@ static boolean P_MobjRegularThink(mobj_t *mobj) if (mobj->threshold > 0) mobj->threshold--; + + P_MobjCheckWater(mobj); break; case MT_SPB: indirectitemcooldown = 20*TICRATE; @@ -8505,6 +8518,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) if (mobj->threshold > 0) mobj->threshold--; + P_MobjCheckWater(mobj); } break; case MT_SINK: @@ -8527,6 +8541,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) if (mobj->threshold > 0) mobj->threshold--; + P_MobjCheckWater(mobj); break; case MT_SSMINE: if (mobj->target && mobj->target->player) @@ -8559,6 +8574,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) if (mobj->threshold > 0) mobj->threshold--; + P_MobjCheckWater(mobj); break; case MT_LANDMINE: mobj->friction = ORIG_FRICTION/4; @@ -8578,6 +8594,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) if (mobj->threshold > 0) mobj->threshold--; + P_MobjCheckWater(mobj); break; case MT_DROPTARGET: if (mobj->reactiontime > 0) @@ -8615,7 +8632,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) mobj->renderflags = (mobj->renderflags|RF_FULLBRIGHT) ^ RF_FULLDARK; // the difference between semi and fullbright - if (R_PointToDist2(0, 0, mobj->momx, mobj->momy) < 8*FRACUNIT) + if (P_AproxDistance(mobj->momx, mobj->momy) <= 14*mobj->scale) { // Not moving fast enough to water run. mobj->flags2 &= ~MF2_WATERRUN; @@ -8623,6 +8640,7 @@ static boolean P_MobjRegularThink(mobj_t *mobj) if (mobj->threshold > 0) mobj->threshold--; + P_MobjCheckWater(mobj); break; case MT_SPBEXPLOSION: mobj->health--; diff --git a/src/p_user.c b/src/p_user.c index 468fd5090..b102c747d 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -2217,21 +2217,6 @@ void P_MovePlayer(player_t *player) //GAMEPLAY STUFF// ////////////////// - if (((!(player->mo->eflags & MFE_VERTICALFLIP) && player->mo->z + player->mo->height >= player->mo->watertop && player->mo->z <= player->mo->watertop) - || (player->mo->eflags & MFE_VERTICALFLIP && player->mo->z + player->mo->height >= player->mo->waterbottom && player->mo->z <= player->mo->waterbottom)) - && (player->speed > runspd) - && player->mo->momz == 0 && player->carry != CR_SLIDING && !player->spectator) - { - K_SpawnWaterTrail(player->mo); - } - - // Little water sound while touching water - just a nicety. - if ((player->mo->eflags & MFE_TOUCHWATER) && !(player->mo->eflags & MFE_UNDERWATER) && !player->spectator) - { - if (P_RandomChance(FRACUNIT/2) && leveltime % TICRATE == 0) - S_StartSound(player->mo, sfx_floush); - } - //////////////////////////// //SPINNING AND SPINDASHING// ////////////////////////////