From e3ded1671c48906152c7ee29769b86880b49b61c Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Sat, 21 Jan 2017 23:49:18 +0000 Subject: [PATCH] Added MobjMoveBlocked Lua hook Also slightly edited P_XYMovement to properly check the mobj still exists before checking its eflags for MFE_SPRUNG, while I was at it --- src/lua_hook.h | 2 ++ src/lua_hooklib.c | 3 +++ src/p_mobj.c | 26 +++++++++++++++++++------- 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/src/lua_hook.h b/src/lua_hook.h index 7192a2979..88867db2b 100644 --- a/src/lua_hook.h +++ b/src/lua_hook.h @@ -45,6 +45,7 @@ enum hook { hook_PlayerSpawn, hook_ShieldSpawn, hook_ShieldSpecial, + hook_MobjMoveBlocked, hook_MAX // last hook }; @@ -81,5 +82,6 @@ boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source, UINT8 #define LUAh_PlayerSpawn(player) LUAh_PlayerHook(player, hook_PlayerSpawn) // Hook for G_SpawnPlayer #define LUAh_ShieldSpawn(player) LUAh_PlayerHook(player, hook_ShieldSpawn) // Hook for P_SpawnShieldOrb #define LUAh_ShieldSpecial(player) LUAh_PlayerHook(player, hook_ShieldSpecial) // Hook for shield abilities +#define LUAh_MobjMoveBlocked(mo) LUAh_MobjHook(mo, hook_MobjMoveBlocked) // Hook for P_XYMovement (when movement is blocked) #endif diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c index f7ea25224..dadc1861a 100644 --- a/src/lua_hooklib.c +++ b/src/lua_hooklib.c @@ -56,6 +56,7 @@ const char *const hookNames[hook_MAX+1] = { "PlayerSpawn", "ShieldSpawn", "ShieldSpecial", + "MobjMoveBlocked", NULL }; @@ -126,6 +127,7 @@ static int lib_addHook(lua_State *L) case hook_BossDeath: case hook_MobjRemoved: case hook_HurtMsg: + case hook_MobjMoveBlocked: hook.s.mt = MT_NULL; if (lua_isnumber(L, 2)) hook.s.mt = lua_tonumber(L, 2); @@ -184,6 +186,7 @@ static int lib_addHook(lua_State *L) case hook_MobjDeath: case hook_BossDeath: case hook_MobjRemoved: + case hook_MobjMoveBlocked: lastp = &mobjhooks[hook.s.mt]; break; case hook_JumpSpecial: diff --git a/src/p_mobj.c b/src/p_mobj.c index f1dfa94f5..f71dffeae 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -2122,17 +2122,31 @@ void P_XYMovement(mobj_t *mo) if (CheckForBustableBlocks && mo->flags & MF_PUSHABLE) P_PushableCheckBustables(mo); - if (!P_TryMove(mo, mo->x + xmove, mo->y + ymove, true) && !(mo->eflags & MFE_SPRUNG)) - { - // blocked move - moved = false; + moved = P_TryMove(mo, mo->x + xmove, mo->y + ymove, true); // Move! + if (P_MobjWasRemoved(mo)) // mobj was removed during P_TryMove? don't continue + return; + if (mo->eflags & MFE_SPRUNG) // touching a spring counts as moved + moved = true; + + if (!moved) // blocked move + { if (player) { if (player->bot) B_MoveBlocked(player); } - if (mo->flags & MF_BOUNCE) +#ifdef HAVE_BLUA + if (LUAh_MobjMoveBlocked(mo)) + { + if (P_MobjWasRemoved(mo)) + return; + } + else +#endif + if (P_MobjWasRemoved(mo)) + return; + else if (mo->flags & MF_BOUNCE) { P_BounceMove(mo); xmove = ymove = 0; @@ -2232,8 +2246,6 @@ void P_XYMovement(mobj_t *mo) else mo->momx = mo->momy = 0; } - else - moved = true; if (P_MobjWasRemoved(mo)) // MF_SPECIAL touched a player! O_o;; return;