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
This commit is contained in:
Monster Iestyn 2017-01-21 23:49:18 +00:00
parent 930527a3d6
commit e3ded1671c
3 changed files with 24 additions and 7 deletions

View file

@ -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

View file

@ -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:

View file

@ -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;