From 03c080c07bc2b75cbf41a2bfc2c256a1b389f2f7 Mon Sep 17 00:00:00 2001 From: Lactozilla Date: Mon, 14 Aug 2023 21:20:55 -0300 Subject: [PATCH] Add scale support to PlayerRespawn --- src/doomstat.h | 1 + src/lua_hooklib.c | 13 +++++++++---- src/p_mobj.c | 10 +++++++++- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/doomstat.h b/src/doomstat.h index 7111806fa..c0e56447b 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -641,6 +641,7 @@ typedef struct { fixed_t x, y, z; angle_t angle; + fixed_t scale; boolean spawn_on_ceiling; boolean spawn_flipped; } spawnpoint_t; diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index 8d887a51d..a1483bb4e 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -1190,8 +1190,11 @@ static void res_playerrespawn(Hook_State *hook) fixed_t height_offset = 0; boolean has_z = false; - spawnpoint_t spawnpoint; - memset(&spawnpoint, 0, sizeof(spawnpoint)); + spawnpoint_t spawnpoint = { + .x = 0, .y = 0, .z = 0, + .angle = 0, .scale = FRACUNIT, + .spawn_on_ceiling = false, .spawn_flipped = false + }; if (lua_istable(gL, -a)) { @@ -1239,8 +1242,9 @@ static void res_playerrespawn(Hook_State *hook) GETNUMBEROPT(spawnpoint.z, "z", has_z); GETNUMBER(height_offset, "height"); GETNUMBER(spawnpoint.angle, "angle"); - GETBOOLEAN(spawnpoint.spawn_on_ceiling, "spawn_on_ceiling"); GETBOOLEAN(spawnpoint.spawn_flipped, "spawn_flipped"); + GETBOOLEAN(spawnpoint.spawn_on_ceiling, "spawn_on_ceiling"); + GETNUMBER(spawnpoint.scale, "scale"); } #undef GETNUMBER @@ -1296,6 +1300,7 @@ static void res_playerrespawn(Hook_State *hook) GETBOOLEAN(spawnpoint.spawn_flipped, "spawn_flipped", -a + 4); GETBOOLEAN(spawnpoint.spawn_on_ceiling, "spawn_on_ceiling", -a + 5); GETBOOLEAN(height_is_relative, "height_is_relative", -a + 6); + GETNUMBER(spawnpoint.scale, "scale", -a + 7); if (!height_is_relative) spawnpoint.z = height_offset; @@ -1320,7 +1325,7 @@ spawnpoint_t *LUA_HookPlayerRespawn(player_t *player) if (prepare_hook(&hook, -1, HOOK(PlayerRespawn))) { LUA_PushUserdata(gL, player, META_PLAYER); - call_hooks(&hook, 7, res_playerrespawn); + call_hooks(&hook, 8, res_playerrespawn); } return (spawnpoint_t *)hook.status.type_void_pointer; } diff --git a/src/p_mobj.c b/src/p_mobj.c index 0928725c7..b6e431554 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -11730,6 +11730,7 @@ void P_MovePlayerToSpawn(INT32 playernum, spawnpoint_t *spawnpoint) { fixed_t x, y, z; angle_t angle; + fixed_t scale; player_t *p = &players[playernum]; mobj_t *mobj = p->mo; @@ -11740,6 +11741,7 @@ void P_MovePlayerToSpawn(INT32 playernum, spawnpoint_t *spawnpoint) x = spawnpoint->x; y = spawnpoint->y; angle = spawnpoint->angle; + scale = spawnpoint->scale; } else { @@ -11747,13 +11749,18 @@ void P_MovePlayerToSpawn(INT32 playernum, spawnpoint_t *spawnpoint) x = 0; y = 0; angle = 0; + scale = FRACUNIT; } + // Set scale + P_SetScale(mobj, scale); + mobj->destscale = scale; + // set Z height sector_t *sector = R_PointInSubsector(x, y)->sector; fixed_t floor = P_GetSectorFloorZAt(sector, x, y); fixed_t ceiling = P_GetSectorCeilingZAt(sector, x, y); - fixed_t ceilingspawn = ceiling - mobjinfo[MT_PLAYER].height; + fixed_t ceilingspawn = ceiling - FixedMul(mobjinfo[MT_PLAYER].height, scale); if (spawnpoint) { @@ -11858,6 +11865,7 @@ spawnpoint_t *P_MakeSpawnPointFromMapthing(mapthing_t *mthing) spawnpoint->x = mthing->x << FRACBITS; spawnpoint->y = mthing->y << FRACBITS; spawnpoint->angle = FixedAngle(mthing->angle<scale = FRACUNIT; // Setting the spawnpoint's args[0] will make the player start on the ceiling // Objectflip inverts