From 0cf41dade0f860bc1b42b4056ef75f1204110578 Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 16 Feb 2021 03:55:37 -0800 Subject: [PATCH] Improve P_SpawnMobjFromMobj by factoring the scale from P_SpawnMobj in This will copy the parent object's scale to the child, but scale it by the child's original scale relative to the map scale. Also uses the child's actual height, instead of the mobjinfo version. Might be useful if either the scale or height was changed in P_SpawnMobj. Say, from a Lua hook. --- src/p_local.h | 1 + src/p_mobj.c | 18 +++++++++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/p_local.h b/src/p_local.h index c5eac863e..a6622b5c1 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -521,5 +521,6 @@ void P_Thrust(mobj_t *mo, angle_t angle, fixed_t move); void P_ExplodeMissile(mobj_t *mo); void P_CheckGravity(mobj_t *mo, boolean affect); void P_SetPitchRollFromSlope(mobj_t *mo, pslope_t *slope); +fixed_t P_ScaleFromMap(fixed_t, fixed_t scale); #endif // __P_LOCAL__ diff --git a/src/p_mobj.c b/src/p_mobj.c index 2bc6c620f..5975da344 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -12748,6 +12748,15 @@ void P_FlashPal(player_t *pl, UINT16 type, UINT16 duration) pl->flashpal = type; } +// +// P_ScaleFromMap +// Scales a number relative to the mapobjectscale. +// +fixed_t P_ScaleFromMap(fixed_t n, fixed_t scale) +{ + return FixedMul(n, FixedDiv(scale, mapobjectscale)); +} + // // P_SpawnMobjFromMobj // Spawns an object with offsets relative to the position of another object. @@ -12765,16 +12774,15 @@ mobj_t *P_SpawnMobjFromMobj(mobj_t *mobj, fixed_t xofs, fixed_t yofs, fixed_t zo if (!newmobj) return NULL; + newmobj->destscale = P_ScaleFromMap(mobj->destscale, newmobj->destscale); + P_SetScale(newmobj, P_ScaleFromMap(mobj->scale, newmobj->scale)); + if (mobj->eflags & MFE_VERTICALFLIP) { - fixed_t elementheight = FixedMul(newmobj->info->height, mobj->scale); - newmobj->eflags |= MFE_VERTICALFLIP; newmobj->flags2 |= MF2_OBJECTFLIP; - newmobj->z = mobj->z + mobj->height - zofs - elementheight; + newmobj->z = mobj->z + mobj->height - zofs - newmobj->height; } - newmobj->destscale = mobj->destscale; - P_SetScale(newmobj, mobj->scale); return newmobj; }