bit more p_mobj cleanup

more unnesting stuffs
This commit is contained in:
alufolie91 committed 2026-07-21 15:31:11 +02:00
1 parent 6187ab4a24
commit 7511540a9b
1 file changed
+150 -116
+150 -116
View File
@@ -2866,13 +2866,11 @@ static boolean P_SceneryZMovement(mobj_t *mo)
}
// Fix for any silly pushables like the egg statues that are also scenery for some reason -- Monster Iestyn
if (P_CheckDeathPitCollide(mo))
if ((mo->flags & MF_PUSHABLE) &&
P_CheckDeathPitCollide(mo))
{
if (mo->flags & MF_PUSHABLE)
{
P_RemoveMobj(mo);
return false;
}
P_RemoveMobj(mo);
return false;
}
// clip movement
@@ -2996,7 +2994,10 @@ void P_MobjCheckWater(mobj_t *mobj)
fixed_t thingtop = mobj->z + mobj->height; // especially for players, infotable height does not neccessarily match actual height
sector_t *sector = mobj->subsector->sector;
ffloor_t *rover;
player_t *p = mobj->player; // Will just be null if not a player.
player_t *player = mobj->player; // Will just be null if not a player.
const fixed_t moheight = FixedMul(mobj->info->height, mobj->scale);
const fixed_t mohalfheight = FixedMul(mobj->info->height/2, mobj->scale);
// Default if no water exists.
mobj->watertop = mobj->waterbottom = mobj->z - 1000*FRACUNIT;
@@ -3010,19 +3011,19 @@ void P_MobjCheckWater(mobj_t *mobj)
fixed_t topcheck, bottomcheck;
if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_SWIMMABLE)
|| (((rover->flags & FF_BLOCKPLAYER) && mobj->player)
|| ((rover->flags & FF_BLOCKOTHERS) && !mobj->player)))
|| (((rover->flags & FF_BLOCKPLAYER) && player)
|| ((rover->flags & FF_BLOCKOTHERS) && !player)))
continue;
if (mobj->eflags & MFE_VERTICALFLIP)
{
topcheck = (thingtop - FixedMul(mobj->info->height/2, mobj->scale));
topcheck = (thingtop - mohalfheight);
bottomcheck = thingtop;
}
else
{
topcheck = mobj->z;
bottomcheck = (mobj->z + FixedMul(mobj->info->height/2, mobj->scale));
bottomcheck = (mobj->z + mohalfheight);
}
topheight = P_GetFFloorTopZAt(rover, mobj->x, mobj->y);
@@ -3040,16 +3041,17 @@ void P_MobjCheckWater(mobj_t *mobj)
mobj->waterbottom = bottomheight;
// Just touching the water?
if (((mobj->eflags & MFE_VERTICALFLIP) && thingtop - FixedMul(mobj->info->height, mobj->scale) < bottomheight)
|| (!(mobj->eflags & MFE_VERTICALFLIP) && mobj->z + FixedMul(mobj->info->height, mobj->scale) > topheight))
if (((mobj->eflags & MFE_VERTICALFLIP) && thingtop - moheight < bottomheight) ||
(!(mobj->eflags & MFE_VERTICALFLIP) && mobj->z + moheight > topheight))
{
mobj->eflags |= MFE_TOUCHWATER;
if (rover->flags & FF_GOOWATER && !(mobj->flags & MF_NOGRAVITY))
mobj->eflags |= MFE_GOOWATER;
}
// Actually in the water?
if (((mobj->eflags & MFE_VERTICALFLIP) && thingtop - FixedMul(mobj->info->height/2, mobj->scale) > bottomheight)
|| (!(mobj->eflags & MFE_VERTICALFLIP) && mobj->z + FixedMul(mobj->info->height/2, mobj->scale) < topheight))
if (((mobj->eflags & MFE_VERTICALFLIP) && thingtop - mohalfheight > bottomheight) ||
(!(mobj->eflags & MFE_VERTICALFLIP) && mobj->z + mohalfheight < topheight))
{
mobj->eflags |= MFE_UNDERWATER;
if (rover->flags & FF_GOOWATER && !(mobj->flags & MF_NOGRAVITY))
@@ -3058,21 +3060,22 @@ void P_MobjCheckWater(mobj_t *mobj)
}
// Specific things for underwater players
if (p && (mobj->eflags & MFE_UNDERWATER) == MFE_UNDERWATER)
if (player && (mobj->eflags & MFE_UNDERWATER) == MFE_UNDERWATER)
{
if (!((p->powers[pw_super]) || (p->powers[pw_invulnerability])))
if (!((player->powers[pw_super]) || (player->powers[pw_invulnerability])))
{
if ((p->powers[pw_shield] & SH_NOSTACK) == SH_ATTRACT)
if ((player->powers[pw_shield] & SH_NOSTACK) == SH_ATTRACT)
{ // Water removes attract shield.
p->powers[pw_shield] = p->powers[pw_shield] & SH_STACK;
P_FlashPal(p, PAL_WHITE, 1);
player->powers[pw_shield] = player->powers[pw_shield] & SH_STACK;
P_FlashPal(player, PAL_WHITE, 1);
}
}
// Can't drown.
p->powers[pw_underwater] = 0;
player->powers[pw_underwater] = 0;
}
if (p)
if (player)
K_SpawnWaterRunParticles(mobj);
// The rest of this code only executes on a water state change.
@@ -3080,20 +3083,20 @@ void P_MobjCheckWater(mobj_t *mobj)
return;
// Spectators and dead players also don't count.
if (p && (p->spectator || p->playerstate != PST_LIVE))
if (player && (player->spectator || player->playerstate != PST_LIVE))
return;
if ((p) // Players
if (player // Players
|| (mobj->flags & MF_PUSHABLE) // Pushables
|| ((mobj->info->flags & MF_PUSHABLE) && mobj->fuse) // Previously pushable, might be moving still
)
{
// Check to make sure you didn't just cross into a sector to jump out of
// that has shallower water than the block you were originally in.
if (!(mobj->eflags & MFE_VERTICALFLIP) && mobj->watertop-mobj->floorz <= FixedMul(mobj->info->height, mobj->scale)>>1)
if (!(mobj->eflags & MFE_VERTICALFLIP) && mobj->watertop-mobj->floorz <= moheight>>1)
return;
if ((mobj->eflags & MFE_VERTICALFLIP) && mobj->ceilingz-mobj->waterbottom <= FixedMul(mobj->info->height, mobj->scale)>>1)
if ((mobj->eflags & MFE_VERTICALFLIP) && mobj->ceilingz-mobj->waterbottom <= moheight>>1)
return;
if ((mobj->eflags & MFE_GOOWATER || wasingoo)) // Decide what happens to your momentum when you enter/leave goopy water.
@@ -3106,13 +3109,13 @@ void P_MobjCheckWater(mobj_t *mobj)
if (P_MobjFlip(mobj)*mobj->momz < 0)
{
if ((mobj->eflags & MFE_VERTICALFLIP && thingtop-(FixedMul(mobj->info->height, mobj->scale)>>1)-mobj->momz <= mobj->waterbottom)
|| (!(mobj->eflags & MFE_VERTICALFLIP) && mobj->z+(FixedMul(mobj->info->height, mobj->scale)>>1)-mobj->momz >= mobj->watertop))
if (((mobj->eflags & MFE_VERTICALFLIP) && thingtop-(moheight>>1)-mobj->momz <= mobj->waterbottom) ||
(!(mobj->eflags & MFE_VERTICALFLIP) && mobj->z+(moheight>>1)-mobj->momz >= mobj->watertop))
{
// Spawn a splash
mobj_t *splish;
if (mobj->eflags & MFE_VERTICALFLIP)
if ((mobj->eflags & MFE_VERTICALFLIP))
{
splish = P_SpawnMobj(mobj->x, mobj->y, mobj->waterbottom-FixedMul(mobjinfo[MT_SPLISH].height, mobj->scale), MT_SPLISH);
splish->flags2 |= MF2_OBJECTFLIP;
@@ -3126,9 +3129,9 @@ void P_MobjCheckWater(mobj_t *mobj)
}
// skipping stone!
if (p && p->kartstuff[k_waterskip] < 2
&& ((p->speed/3 > abs(mobj->momz)) // Going more forward than horizontal, so you can skip across the water.
|| (p->speed > K_GetKartSpeed(p,false)/3 && p->kartstuff[k_waterskip])) // Already skipped once, so you can skip once more!
if (player && player->kartstuff[k_waterskip] < 2
&& ((player->speed/3 > abs(mobj->momz)) // Going more forward than horizontal, so you can skip across the water.
|| (player->speed > K_GetKartSpeed(player, false)/3 && player->kartstuff[k_waterskip])) // Already skipped once, so you can skip once more!
&& ((!(mobj->eflags & MFE_VERTICALFLIP) && thingtop - mobj->momz > mobj->watertop)
|| ((mobj->eflags & MFE_VERTICALFLIP) && mobj->z - mobj->momz < mobj->waterbottom)))
{
@@ -3141,23 +3144,23 @@ void P_MobjCheckWater(mobj_t *mobj)
if (!(mobj->eflags & MFE_VERTICALFLIP) && mobj->momz < FixedMul(min, mobj->scale))
mobj->momz = FixedMul(min, mobj->scale);
else if (mobj->eflags & MFE_VERTICALFLIP && mobj->momz > FixedMul(-min, mobj->scale))
else if ((mobj->eflags & MFE_VERTICALFLIP) && mobj->momz > FixedMul(-min, mobj->scale))
mobj->momz = FixedMul(-min, mobj->scale);
p->kartstuff[k_waterskip]++;
player->kartstuff[k_waterskip]++;
}
}
else if (P_MobjFlip(mobj)*mobj->momz > 0)
{
if (((mobj->eflags & MFE_VERTICALFLIP && thingtop-(FixedMul(mobj->info->height, mobj->scale)>>1)-mobj->momz > mobj->waterbottom)
|| (!(mobj->eflags & MFE_VERTICALFLIP) && mobj->z+(FixedMul(mobj->info->height, mobj->scale)>>1)-mobj->momz < mobj->watertop))
if ((((mobj->eflags & MFE_VERTICALFLIP) && thingtop-(moheight>>1)-mobj->momz > mobj->waterbottom)
|| (!(mobj->eflags & MFE_VERTICALFLIP) && mobj->z+(moheight>>1)-mobj->momz < mobj->watertop))
&& !(mobj->eflags & MFE_UNDERWATER)) // underwater check to prevent splashes on opposite side
{
// Spawn a splash
mobj_t *splish;
if (mobj->eflags & MFE_VERTICALFLIP)
if ((mobj->eflags & MFE_VERTICALFLIP))
{
splish = P_SpawnMobj(mobj->x, mobj->y, mobj->waterbottom-FixedMul(mobjinfo[MT_SPLISH].height, mobj->scale), MT_SPLISH);
splish->flags2 |= MF2_OBJECTFLIP;
@@ -3511,13 +3514,117 @@ boolean P_CameraThinker(player_t *player, camera_t *thiscam, boolean resetcalled
return false;
}
static void P_CheckCrumblingPlatforms(mobj_t *mobj)
{
msecnode_t *node;
if (netgame && mobj->player->spectator)
return;
for (node = mobj->touching_sectorlist; node; node = node->m_sectorlist_next)
{
ffloor_t *rover;
for (rover = node->m_sector->ffloors; rover; rover = rover->next)
{
if (!(rover->flags & FF_EXISTS))
continue;
if (!(rover->flags & FF_CRUMBLE))
continue;
if (mobj->eflags & MFE_VERTICALFLIP)
{
if (P_GetSpecialBottomZ(mobj, sectors + rover->secnum, node->m_sector) != mobj->z + mobj->height) // You nut.
continue;
}
else
{
if (P_GetSpecialTopZ(mobj, sectors + rover->secnum, node->m_sector) != mobj->z)
continue;
}
EV_StartCrumble(rover->master->frontsector, rover, (rover->flags & FF_FLOATBOB), mobj->player, rover->alpha, !(rover->flags & FF_NORETURN));
}
}
}
static boolean P_MobjTouchesSectorWithWater(mobj_t *mobj)
{
msecnode_t *node;
for (node = mobj->touching_sectorlist; node; node = node->m_sectorlist_next)
{
ffloor_t *rover;
if (!node->m_sector->ffloors)
continue;
for (rover = node->m_sector->ffloors; rover; rover = rover->next)
{
if (!(rover->flags & FF_EXISTS))
continue;
if (!(rover->flags & FF_SWIMMABLE)) // Is there water?
continue;
return true;
}
}
return false;
}
// Check for floating water platforms and bounce them
static void P_CheckFloatbobPlatforms(mobj_t *mobj)
{
msecnode_t *node;
// Can't land on anything if you're not moving downwards
if (P_MobjFlip(mobj)*mobj->momz >= 0)
return;
if (!P_MobjTouchesSectorWithWater(mobj))
return;
for (node = mobj->touching_sectorlist; node; node = node->m_sectorlist_next)
{
ffloor_t *rover;
if (!node->m_sector->ffloors)
continue;
for (rover = node->m_sector->ffloors; rover; rover = rover->next)
{
if (!(rover->flags & FF_EXISTS))
continue;
if (!(rover->flags & FF_FLOATBOB))
continue;
if (mobj->eflags & MFE_VERTICALFLIP)
{
if (abs(*rover->bottomheight - (mobj->z + mobj->height)) > abs(mobj->momz))
continue;
}
else
{
if (abs(*rover->topheight - mobj->z) > abs(mobj->momz)) // The player is landing on the cheese!
continue;
}
// Initiate a 'bouncy' elevator function which slowly diminishes.
EV_BounceSector(rover->master->frontsector, -mobj->momz, rover->master);
}
} // Ugly ugly billions of braces! Argh!
}
//
// P_PlayerMobjThinker
//
static void P_PlayerMobjThinker(mobj_t *mobj)
{
msecnode_t *node;
I_Assert(mobj->player != NULL);
I_Assert(!P_MobjWasRemoved(mobj));
@@ -3564,84 +3671,11 @@ static void P_PlayerMobjThinker(mobj_t *mobj)
else
P_TryMove(mobj, mobj->x, mobj->y, true);
if (!(netgame && mobj->player->spectator))
{
// Crumbling platforms
for (node = mobj->touching_sectorlist; node; node = node->m_sectorlist_next)
{
ffloor_t *rover;
// Crumbling platforms
P_CheckCrumblingPlatforms(mobj);
for (rover = node->m_sector->ffloors; rover; rover = rover->next)
{
boolean oncrumble;
if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_CRUMBLE))
continue;
if (mobj->eflags & MFE_VERTICALFLIP)
{
oncrumble = P_GetSpecialBottomZ(mobj, sectors + rover->secnum, node->m_sector) == mobj->z + mobj->height; // You nut.
}
else
{
oncrumble = P_GetSpecialTopZ(mobj, sectors + rover->secnum, node->m_sector) == mobj->z;
}
if (oncrumble)
EV_StartCrumble(rover->master->frontsector, rover, (rover->flags & FF_FLOATBOB), mobj->player, rover->alpha, !(rover->flags & FF_NORETURN));
}
}
}
// Check for floating water platforms and bounce them
if (CheckForFloatBob && P_MobjFlip(mobj)*mobj->momz < 0)
{
boolean thereiswater = false;
for (node = mobj->touching_sectorlist; node; node = node->m_sectorlist_next)
{
if (!node->m_sector->ffloors)
continue;
ffloor_t *rover;
// Get water boundaries first
for (rover = node->m_sector->ffloors; rover; rover = rover->next)
{
if (!(rover->flags & FF_EXISTS))
continue;
if (rover->flags & FF_SWIMMABLE) // Is there water?
{
thereiswater = true;
break;
}
}
}
if (thereiswater)
{
for (node = mobj->touching_sectorlist; node; node = node->m_sectorlist_next)
{
if (!node->m_sector->ffloors)
continue;
ffloor_t *rover;
for (rover = node->m_sector->ffloors; rover; rover = rover->next)
{
if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_FLOATBOB))
continue;
if ((!(mobj->eflags & MFE_VERTICALFLIP) && abs(*rover->topheight-mobj->z) <= abs(mobj->momz)) // The player is landing on the cheese!
|| (mobj->eflags & MFE_VERTICALFLIP && abs(*rover->bottomheight-(mobj->z+mobj->height)) <= abs(mobj->momz)))
{
// Initiate a 'bouncy' elevator function
// which slowly diminishes.
EV_BounceSector(rover->master->frontsector, -mobj->momz, rover->master);
}
}
}
} // Ugly ugly billions of braces! Argh!
}
if (CheckForFloatBob)
P_CheckFloatbobPlatforms(mobj);
// always do the gravity bit now, that's simpler
// BUT CheckPosition only if wasn't done before.