Fix player Z snap to floor on moving platform ~FF_EXISTS

* Track player's old floorz by mo->floor_sectornum and floor_ffloornum
* Track tmfloorz by tmfloorrover, tmfloor_sectornum, tmfloor_rovernum
* Ceiling variants of the above
This commit is contained in:
mazmazz 2018-09-08 00:34:56 -04:00
parent ffde71c656
commit 76d7a54b2b
3 changed files with 108 additions and 9 deletions

View file

@ -52,6 +52,8 @@ fixed_t tmfloorz, tmceilingz;
static fixed_t tmdropoffz, tmdrpoffceilz; // drop-off floor/ceiling heights
mobj_t *tmfloorthing; // the thing corresponding to tmfloorz or NULL if tmfloorz is from a sector
mobj_t *tmhitthing; // the solid thing you bumped into (for collisions)
ffloor_t *tmfloorrover, *tmceilingrover;
size_t tmfloor_sectornum, tmfloor_rovernum, tmceiling_sectornum, tmceiling_rovernum;
#ifdef ESLOPE
pslope_t *tmfloorslope, *tmceilingslope;
#endif
@ -1417,6 +1419,8 @@ static boolean PIT_CheckThing(mobj_t *thing)
if (thing->z + thing->height > tmfloorz)
{
tmfloorz = thing->z + thing->height;
tmfloorrover = NULL;
tmfloor_sectornum = tmfloor_rovernum = 0;
#ifdef ESLOPE
tmfloorslope = NULL;
#endif
@ -1437,6 +1441,8 @@ static boolean PIT_CheckThing(mobj_t *thing)
return false;
tmfloorz = tmceilingz = topz; // block while in air
tmceilingrover = NULL;
tmceiling_sectornum = tmceiling_rovernum = 0;
#ifdef ESLOPE
tmceilingslope = NULL;
#endif
@ -1445,6 +1451,8 @@ static boolean PIT_CheckThing(mobj_t *thing)
else if (topz < tmceilingz && tmthing->z <= thing->z+thing->height)
{
tmceilingz = topz;
tmceilingrover = NULL;
tmceiling_sectornum = tmceiling_rovernum = 0;
#ifdef ESLOPE
tmceilingslope = NULL;
#endif
@ -1461,6 +1469,8 @@ static boolean PIT_CheckThing(mobj_t *thing)
if (thing->z < tmceilingz)
{
tmceilingz = thing->z;
tmceilingrover = NULL;
tmceiling_sectornum = tmceiling_rovernum = 0;
#ifdef ESLOPE
tmceilingslope = NULL;
#endif
@ -1481,6 +1491,8 @@ static boolean PIT_CheckThing(mobj_t *thing)
return false;
tmfloorz = tmceilingz = topz; // block while in air
tmfloorrover = NULL;
tmfloor_sectornum = tmfloor_rovernum = 0;
#ifdef ESLOPE
tmfloorslope = NULL;
#endif
@ -1489,6 +1501,8 @@ static boolean PIT_CheckThing(mobj_t *thing)
else if (topz > tmfloorz && tmthing->z+tmthing->height >= thing->z)
{
tmfloorz = topz;
tmfloorrover = NULL;
tmfloor_sectornum = tmfloor_rovernum = 0;
#ifdef ESLOPE
tmfloorslope = NULL;
#endif
@ -1640,6 +1654,8 @@ static boolean PIT_CheckLine(line_t *ld)
{
tmceilingz = opentop;
ceilingline = ld;
tmceilingrover = NULL;
tmceiling_sectornum = tmceiling_rovernum = 0;
#ifdef ESLOPE
tmceilingslope = opentopslope;
#endif
@ -1648,6 +1664,8 @@ static boolean PIT_CheckLine(line_t *ld)
if (openbottom > tmfloorz)
{
tmfloorz = openbottom;
tmfloorrover = NULL;
tmfloor_sectornum = tmfloor_rovernum = 0;
#ifdef ESLOPE
tmfloorslope = openbottomslope;
#endif
@ -1729,6 +1747,10 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y)
// will adjust them.
tmfloorz = tmdropoffz = P_GetFloorZ(thing, newsubsec->sector, x, y, NULL); //newsubsec->sector->floorheight;
tmceilingz = P_GetCeilingZ(thing, newsubsec->sector, x, y, NULL); //newsubsec->sector->ceilingheight;
tmfloorrover = NULL;
tmfloor_sectornum = tmfloor_rovernum = 0;
tmceilingrover = NULL;
tmceiling_sectornum = tmceiling_rovernum = 0;
#ifdef ESLOPE
tmfloorslope = newsubsec->sector->f_slope;
tmceilingslope = newsubsec->sector->c_slope;
@ -1738,6 +1760,7 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y)
if (newsubsec->sector->ffloors)
{
ffloor_t *rover;
size_t rovernum = 0;
fixed_t delta1, delta2;
INT32 thingtop = thing->z + thing->height;
@ -1746,7 +1769,10 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y)
fixed_t topheight, bottomheight;
if (!(rover->flags & FF_EXISTS))
{
rovernum++;
continue;
}
topheight = P_GetFOFTopZ(thing, newsubsec->sector, rover, x, y, NULL);
bottomheight = P_GetFOFBottomZ(thing, newsubsec->sector, rover, x, y, NULL);
@ -1772,6 +1798,9 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y)
{
if (tmfloorz < topheight - sinklevel) {
tmfloorz = topheight - sinklevel;
tmfloorrover = rover;
tmfloor_sectornum = newsubsec->sector - sectors;
tmfloor_rovernum = rovernum;
#ifdef ESLOPE
tmfloorslope = *rover->t_slope;
#endif
@ -1781,12 +1810,16 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y)
{
if (tmceilingz > bottomheight + sinklevel) {
tmceilingz = bottomheight + sinklevel;
tmceilingrover = rover;
tmceiling_sectornum = newsubsec->sector - sectors;
tmceiling_rovernum = rovernum;
#ifdef ESLOPE
tmceilingslope = *rover->b_slope;
#endif
}
}
}
rovernum++;
continue;
}
@ -1797,7 +1830,10 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y)
else if (!((rover->flags & FF_BLOCKPLAYER && thing->player)
|| (rover->flags & FF_BLOCKOTHERS && !thing->player)
|| rover->flags & FF_QUICKSAND))
{
rovernum++;
continue;
}
if (rover->flags & FF_QUICKSAND)
{
@ -1805,12 +1841,16 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y)
{
if (tmfloorz < thing->z) {
tmfloorz = thing->z;
tmfloorrover = rover;
tmfloor_sectornum = newsubsec->sector - sectors;
tmfloor_rovernum = rovernum;
#ifdef ESLOPE
tmfloorslope = NULL;
#endif
}
}
// Quicksand blocks never change heights otherwise.
rovernum++;
continue;
}
@ -1823,6 +1863,9 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y)
&& !(rover->flags & FF_REVERSEPLATFORM))
{
tmfloorz = tmdropoffz = topheight;
tmfloorrover = rover;
tmfloor_sectornum = newsubsec->sector - sectors;
tmfloor_rovernum = rovernum;
#ifdef ESLOPE
tmfloorslope = *rover->t_slope;
#endif
@ -1832,10 +1875,14 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y)
&& !(thing->type == MT_SKIM && (rover->flags & FF_SWIMMABLE)))
{
tmceilingz = tmdrpoffceilz = bottomheight;
tmceilingrover = rover;
tmceiling_sectornum = newsubsec->sector - sectors;
tmceiling_rovernum = rovernum;
#ifdef ESLOPE
tmceilingslope = *rover->b_slope;
#endif
}
rovernum++;
}
}
@ -2328,6 +2375,12 @@ boolean PIT_PushableMoved(mobj_t *thing)
mobj_t *oldthing = tmthing;
line_t *oldceilline = ceilingline;
line_t *oldblockline = blockingline;
ffloor_t *oldflrrover = tmfloorrover;
ffloor_t *oldceilrover = tmceilingrover;
size_t oldflrrover_sectornum = tmfloor_sectornum;
size_t oldflrrover_ffloornum = tmfloor_rovernum;
size_t oldceilrover_sectornum = tmceiling_sectornum;
size_t oldceilrover_ffloornum = tmceiling_rovernum;
#ifdef ESLOPE
pslope_t *oldfslope = tmfloorslope;
pslope_t *oldcslope = tmceilingslope;
@ -2344,6 +2397,12 @@ boolean PIT_PushableMoved(mobj_t *thing)
P_SetTarget(&tmthing, oldthing);
ceilingline = oldceilline;
blockingline = oldblockline;
tmfloorrover = oldflrrover;
tmceilingrover = oldceilrover;
tmfloor_sectornum = oldflrrover_sectornum;
tmfloor_rovernum = oldflrrover_ffloornum;
tmceiling_sectornum = oldceilrover_sectornum;
tmceiling_rovernum = oldceilrover_ffloornum;
#ifdef ESLOPE
tmfloorslope = oldfslope;
tmceilingslope = oldcslope;
@ -2663,7 +2722,9 @@ static boolean P_ThingHeightClip(mobj_t *thing)
{
boolean floormoved;
fixed_t oldfloorz = thing->floorz;
size_t oldfloor_sectornum = thing->floor_sectornum, oldfloor_rovernum = thing->floor_rovernum;
boolean onfloor = P_IsObjectOnGround(thing);//(thing->z <= thing->floorz);
ffloor_t *rover = NULL;
if (thing->flags & MF_NOCLIPHEIGHT)
return true;
@ -2678,6 +2739,10 @@ static boolean P_ThingHeightClip(mobj_t *thing)
thing->floorz = tmfloorz;
thing->ceilingz = tmceilingz;
thing->floor_sectornum = tmfloor_sectornum;
thing->floor_rovernum = tmfloor_rovernum;
thing->ceiling_sectornum = tmceiling_sectornum;
thing->ceiling_rovernum = tmceiling_rovernum;
// Ugly hack?!?! As long as just ceilingz is the lowest,
// you'll still get crushed, right?
@ -2686,16 +2751,33 @@ static boolean P_ThingHeightClip(mobj_t *thing)
if (onfloor && !(thing->flags & MF_NOGRAVITY) && floormoved)
{
if (thing->eflags & MFE_VERTICALFLIP)
thing->pmomz = thing->ceilingz - (thing->z + thing->height);
else
thing->pmomz = thing->floorz - thing->z;
thing->eflags |= MFE_APPLYPMOMZ;
// Find FOF referenced by floorz
if (oldfloor_sectornum)
{
size_t rovernum = 0;
for (rover = sectors[oldfloor_sectornum].ffloors; rover; rover = rover->next)
{
if (rovernum == oldfloor_rovernum)
break;
rovernum++;
}
}
if (thing->eflags & MFE_VERTICALFLIP)
thing->z = thing->ceilingz - thing->height;
else
thing->z = thing->floorz;
// Match the Thing's old floorz to an FOF and check for FF_EXISTS
// If ~FF_EXISTS, don't set mobj Z.
if (!rover || (rover->flags & FF_EXISTS))
{
if (thing->eflags & MFE_VERTICALFLIP)
thing->pmomz = thing->ceilingz - (thing->z + thing->height);
else
thing->pmomz = thing->floorz - thing->z;
thing->eflags |= MFE_APPLYPMOMZ;
if (thing->eflags & MFE_VERTICALFLIP)
thing->z = thing->ceilingz - thing->height;
else
thing->z = thing->floorz;
}
}
else if (!tmfloorthing)
{

View file

@ -282,6 +282,10 @@ typedef struct mobj_s
// The closest interval over all contacted sectors (or things).
fixed_t floorz; // Nearest floor below.
fixed_t ceilingz; // Nearest ceiling above.
size_t floor_sectornum; // FOF referred by floorz
size_t floor_rovernum; // FOF referred by floorz
size_t ceiling_sectornum; // FOF referred by ceilingz
size_t ceiling_rovernum; // FOF referred by ceilingz
// For movement checking.
fixed_t radius;

View file

@ -1192,6 +1192,10 @@ static void SaveMobjThinker(const thinker_t *th, const UINT8 type)
WRITEFIXED(save_p, mobj->z); // Force this so 3dfloor problems don't arise.
WRITEFIXED(save_p, mobj->floorz);
WRITEFIXED(save_p, mobj->ceilingz);
WRITEUINT32(save_p, (UINT32)mobj->floor_sectornum);
WRITEUINT32(save_p, (UINT32)mobj->floor_rovernum);
WRITEUINT32(save_p, (UINT32)mobj->ceiling_sectornum);
WRITEUINT32(save_p, (UINT32)mobj->ceiling_rovernum);
if (diff & MD_SPAWNPOINT)
{
@ -1989,6 +1993,7 @@ static void LoadMobjThinker(actionf_p1 thinker)
UINT16 diff2;
INT32 i;
fixed_t z, floorz, ceilingz;
size_t floor_sectornum, floor_rovernum, ceiling_sectornum, ceiling_rovernum;
diff = READUINT32(save_p);
if (diff & MD_MORE)
@ -2001,6 +2006,10 @@ static void LoadMobjThinker(actionf_p1 thinker)
z = READFIXED(save_p); // Force this so 3dfloor problems don't arise.
floorz = READFIXED(save_p);
ceilingz = READFIXED(save_p);
floor_sectornum = (size_t)READUINT32(save_p);
floor_rovernum = (size_t)READUINT32(save_p);
ceiling_sectornum = (size_t)READUINT32(save_p);
ceiling_rovernum = (size_t)READUINT32(save_p);
if (diff & MD_SPAWNPOINT)
{
@ -2026,6 +2035,10 @@ static void LoadMobjThinker(actionf_p1 thinker)
mobj->z = z;
mobj->floorz = floorz;
mobj->ceilingz = ceilingz;
mobj->floor_sectornum = floor_sectornum;
mobj->floor_rovernum = floor_rovernum;
mobj->ceiling_sectornum = ceiling_sectornum;
mobj->ceiling_rovernum = ceiling_rovernum;
if (diff & MD_TYPE)
mobj->type = READUINT32(save_p);