diff --git a/src/lua_blockmaplib.c b/src/lua_blockmaplib.c index 0b93766b8..2367673cd 100644 --- a/src/lua_blockmaplib.c +++ b/src/lua_blockmaplib.c @@ -53,10 +53,12 @@ static UINT8 lib_searchBlockmap_Objects(lua_State *L, INT32 x, INT32 y, mobj_t * CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1)); lua_pop(gL, 1); blockfuncerror = true; + P_SetTarget(&bnext, NULL); return 0; // *shrugs* } if (!lua_isnil(gL, -1)) { // if nil, continue + P_SetTarget(&bnext, NULL); if (lua_toboolean(gL, -1)) return 2; // stop whole search else @@ -256,4 +258,4 @@ int LUA_BlockmapLib(lua_State *L) { lua_register(L, "searchBlockmap", lib_searchBlockmap); return 0; -} \ No newline at end of file +} diff --git a/src/p_map.c b/src/p_map.c index 6051d5d1c..bcb2b6a73 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -1548,13 +1548,13 @@ static boolean PIT_CheckThing(mobj_t *thing) { tmfloorz = tmceilingz = topz; // block while in air tmceilingslope = NULL; - tmfloorthing = thing; // needed for side collision + P_SetTarget(&tmfloorthing, thing); // needed for side collision } else if (topz < tmceilingz && tmthing->z <= thing->z+thing->height) { tmceilingz = topz; tmceilingslope = NULL; - tmfloorthing = thing; // thing we may stand on + P_SetTarget(&tmfloorthing, thing); // thing we may stand on } } else @@ -1585,13 +1585,13 @@ static boolean PIT_CheckThing(mobj_t *thing) { tmfloorz = tmceilingz = topz; // block while in air tmfloorslope = NULL; - tmfloorthing = thing; // needed for side collision + P_SetTarget(&tmfloorthing, thing); // needed for side collision } else if (topz > tmfloorz && tmthing->z+tmthing->height >= thing->z) { tmfloorz = topz; tmfloorslope = NULL; - tmfloorthing = thing; // thing we may stand on + P_SetTarget(&tmfloorthing, thing); // thing we may stand on } } } @@ -1991,8 +1991,8 @@ boolean P_CheckPosition(mobj_t *thing, fixed_t x, fixed_t y) } // tmfloorthing is set when tmfloorz comes from a thing's top - tmfloorthing = NULL; - tmhitthing = NULL; + P_SetTarget(&tmfloorthing, NULL); + P_SetTarget(&tmhitthing, NULL); validcount++; @@ -2489,8 +2489,10 @@ boolean P_TryMove(mobj_t *thing, fixed_t x, fixed_t y, boolean allowdropoff) if (tmceilingz - tmfloorz < thing->height) { - if (tmfloorthing) - tmhitthing = tmfloorthing; + if (tmfloorthing != NULL) + { + P_SetTarget(&tmhitthing, tmfloorthing); + } return false; // doesn't fit } diff --git a/src/p_mobj.c b/src/p_mobj.c index 0423b00f3..b25a30065 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -6073,7 +6073,8 @@ void P_MobjThinker(mobj_t *mobj) mobj->flags2 &= ~MF2_PUSHED; mobj->eflags &= ~(MFE_SPRUNG|MFE_JUSTBOUNCEDWALL); - tmfloorthing = tmhitthing = NULL; + P_SetTarget(&tmfloorthing, NULL); + P_SetTarget(&tmhitthing, NULL); // 970 allows ANY mobj to trigger a linedef exec if (mobj->subsector && GETSECSPECIAL(mobj->subsector->sector->special, 2) == 8) @@ -10030,13 +10031,29 @@ void P_RemoveMobj(mobj_t *mobj) P_SetTarget(&mobj->target, NULL); P_SetTarget(&mobj->tracer, NULL); + // repair hnext chain + mobj_t *cachenext = mobj->hnext; + if (mobj->hnext && !P_MobjWasRemoved(mobj->hnext)) - P_SetTarget(&mobj->hnext->hprev, mobj->hprev); + { + if (mobj->hnext->hprev == mobj) + { + P_SetTarget(&mobj->hnext->hprev, mobj->hprev); + } + + P_SetTarget(&mobj->hnext, NULL); + } + if (mobj->hprev && !P_MobjWasRemoved(mobj->hprev)) - P_SetTarget(&mobj->hprev->hnext, mobj->hnext); - - P_SetTarget(&mobj->hnext, P_SetTarget(&mobj->hprev, NULL)); + { + if (mobj->hprev->hnext == mobj) + { + P_SetTarget(&mobj->hprev->hnext, cachenext); + } + P_SetTarget(&mobj->hprev, NULL); + } + // clear the reference from the mapthing if (mobj->spawnpoint) P_SetTarget(&mobj->spawnpoint->mobj, NULL);