Refactor P_CheckBouncySectors

This commit is contained in:
MascaraSnake 2020-05-03 10:01:58 +02:00
parent 452fd100b8
commit d0d25025e1

View file

@ -2729,17 +2729,19 @@ static void P_CheckBouncySectors(player_t *player)
for (node = player->mo->touching_sectorlist; node; node = node->m_sectorlist_next)
{
ffloor_t *rover;
if (!node->m_sector)
break;
if (node->m_sector->ffloors)
{
ffloor_t *rover;
boolean top = true;
fixed_t topheight, bottomheight;
if (!node->m_sector->ffloors)
continue;
for (rover = node->m_sector->ffloors; rover; rover = rover->next)
{
fixed_t bouncestrength;
fixed_t topheight, bottomheight;
if (!(rover->flags & FF_EXISTS))
continue; // FOFs should not be bouncy if they don't even "exist"
@ -2755,27 +2757,25 @@ static void P_CheckBouncySectors(player_t *player)
if (player->mo->z + player->mo->height < bottomheight)
continue;
bouncestrength = P_AproxDistance(rover->master->dx, rover->master->dy)/100;
if (oldz < P_GetFOFTopZ(player->mo, node->m_sector, rover, oldx, oldy, NULL)
&& oldz + player->mo->height > P_GetFOFBottomZ(player->mo, node->m_sector, rover, oldx, oldy, NULL))
top = false;
{
fixed_t linedist;
player->mo->momx = -FixedMul(player->mo->momx,bouncestrength);
player->mo->momy = -FixedMul(player->mo->momy,bouncestrength);
linedist = P_AproxDistance(rover->master->v1->x-rover->master->v2->x, rover->master->v1->y-rover->master->v2->y);
linedist = FixedDiv(linedist,100*FRACUNIT);
if (top)
if (player->pflags & PF_SPINNING)
{
player->pflags &= ~PF_SPINNING;
player->pflags |= P_GetJumpFlags(player);
player->pflags |= PF_THOKKED;
}
}
else
{
fixed_t newmom;
pslope_t *slope;
if (abs(oldz - topheight) < abs(oldz + player->mo->height - bottomheight)) { // Hit top
slope = *rover->t_slope;
} else { // Hit bottom
slope = *rover->b_slope;
}
pslope_t *slope = (abs(oldz - topheight) < abs(oldz + player->mo->height - bottomheight)) ? *rover->t_slope : *rover->b_slope;
momentum.x = player->mo->momx;
momentum.y = player->mo->momy;
@ -2784,12 +2784,10 @@ static void P_CheckBouncySectors(player_t *player)
if (slope)
P_ReverseQuantizeMomentumToSlope(&momentum, slope);
newmom = momentum.z = -FixedMul(momentum.z,linedist)/2;
newmom = momentum.z = -FixedMul(momentum.z,bouncestrength)/2;
if (abs(newmom) < (linedist*2))
{
if (abs(newmom) < (bouncestrength*2))
goto bouncydone;
}
if (!(rover->master->flags & ML_BOUNCY))
{
@ -2798,9 +2796,12 @@ static void P_CheckBouncySectors(player_t *player)
if (newmom < 8*FRACUNIT)
newmom = 8*FRACUNIT;
}
else if (newmom > -8*FRACUNIT && newmom != 0)
else if (newmom < 0)
{
if (newmom > -8*FRACUNIT)
newmom = -8*FRACUNIT;
}
}
if (newmom > P_GetPlayerHeight(player)/2)
newmom = P_GetPlayerHeight(player)/2;
@ -2823,18 +2824,6 @@ static void P_CheckBouncySectors(player_t *player)
player->pflags |= PF_THOKKED;
}
}
else
{
player->mo->momx = -FixedMul(player->mo->momx,linedist);
player->mo->momy = -FixedMul(player->mo->momy,linedist);
if (player->pflags & PF_SPINNING)
{
player->pflags &= ~PF_SPINNING;
player->pflags |= P_GetJumpFlags(player);
player->pflags |= PF_THOKKED;
}
}
if ((player->pflags & PF_SPINNING) && player->speed < FixedMul(1<<FRACBITS, player->mo->scale) && player->mo->momz)
{
@ -2845,8 +2834,6 @@ static void P_CheckBouncySectors(player_t *player)
goto bouncydone;
}
}
}
}
bouncydone:
P_UnsetThingPosition(player->mo);
player->mo->x = oldx;