From ca88db00cdf77055615db7b6cd19e06ca401e3cf Mon Sep 17 00:00:00 2001 From: Snu Date: Wed, 30 Sep 2020 07:56:57 +0100 Subject: [PATCH 1/5] Create P_CeilingzAtPos function --- src/p_local.h | 1 + src/p_map.c | 46 +++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/p_local.h b/src/p_local.h index 9873a20af..525c1a3bd 100644 --- a/src/p_local.h +++ b/src/p_local.h @@ -424,6 +424,7 @@ void P_Initsecnode(void); void P_RadiusAttack(mobj_t *spot, mobj_t *source, fixed_t damagedist, UINT8 damagetype, boolean sightcheck); fixed_t P_FloorzAtPos(fixed_t x, fixed_t y, fixed_t z, fixed_t height); +fixed_t P_CeilingzAtPos(fixed_t x, fixed_t y, fixed_t z, fixed_t height); boolean PIT_PushableMoved(mobj_t *thing); boolean P_DoSpring(mobj_t *spring, mobj_t *object); diff --git a/src/p_map.c b/src/p_map.c index b7ad14808..d26b1707d 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -4953,7 +4953,7 @@ void P_MapEnd(void) } // P_FloorzAtPos -// Returns the floorz of the XYZ position // TODO: Need ceilingpos function too +// Returns the floorz of the XYZ position // Tails 05-26-2003 fixed_t P_FloorzAtPos(fixed_t x, fixed_t y, fixed_t z, fixed_t height) { @@ -4997,3 +4997,47 @@ fixed_t P_FloorzAtPos(fixed_t x, fixed_t y, fixed_t z, fixed_t height) return floorz; } + +// P_CeilingZAtPos +// Returns the ceilinz of the XYZ position +fixed_t P_CeilingzAtPos(fixed_t x, fixed_t y, fixed_t z, fixed_t height) +{ + sector_t *sec = R_PointInSubsector(x, y)->sector; + fixed_t ceilingz = P_GetSectorCeilingZAt(sec, x, y); + + if (sec->ffloors) + { + ffloor_t *rover; + fixed_t delta1, delta2, thingtop = z + height; + + for (rover = sec->ffloors; rover; rover = rover->next) + { + fixed_t topheight, bottomheight; + if (!(rover->flags & FF_EXISTS)) + continue; + + if ((!(rover->flags & FF_SOLID || rover->flags & FF_QUICKSAND) || (rover->flags & FF_SWIMMABLE))) + continue; + + topheight = P_GetFFloorTopZAt (rover, x, y); + bottomheight = P_GetFFloorBottomZAt(rover, x, y); + + if (rover->flags & FF_QUICKSAND) + { + if (z < topheight && bottomheight < thingtop) + { + if (ceilingz < z) + ceilingz = z; + } + continue; + } + + delta1 = z - (bottomheight + ((topheight - bottomheight)/2)); + delta2 = thingtop - (bottomheight + ((topheight - bottomheight)/2)); + if (bottomheight > ceilingz && abs(delta1) < abs(delta2)) + ceilingz = bottomheight; + } + } + + return ceilingz; +} \ No newline at end of file From feb011ee5222e81f21c1b816ea780106c2d54f1c Mon Sep 17 00:00:00 2001 From: Snu Date: Wed, 30 Sep 2020 07:58:41 +0100 Subject: [PATCH 2/5] Expose function to Lua --- src/lua_baselib.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index 775d9ec02..b3e423300 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -1601,6 +1601,18 @@ static int lib_pFloorzAtPos(lua_State *L) return 1; } +static int lib_pCeilingzAtPos(lua_State *L) +{ + fixed_t x = luaL_checkfixed(L, 1); + fixed_t y = luaL_checkfixed(L, 2); + fixed_t z = luaL_checkfixed(L, 3); + fixed_t height = luaL_checkfixed(L, 4); + //HUDSAFE + INLEVEL + lua_pushfixed(L, P_CeilingzAtPos(x, y, z, height)); + return 1; +} + static int lib_pDoSpring(lua_State *L) { mobj_t *spring = *((mobj_t **)luaL_checkudata(L, 1, META_MOBJ)); @@ -3316,7 +3328,8 @@ static luaL_Reg lib[] = { {"P_CheckSight", lib_pCheckSight}, {"P_CheckHoopPosition",lib_pCheckHoopPosition}, {"P_RadiusAttack",lib_pRadiusAttack}, - {"P_FloorzAtPos",lib_pFloorzAtPos}, + {"P_FloorzAtPos",lib_pCeilingzAtPos}, + {"P_CeilingzAtPos",lib_pFloorzAtPos}, {"P_DoSpring",lib_pDoSpring}, // p_inter From 82ceddb2bedebb4a3e12e6e7dbfaa7f2a3262f4d Mon Sep 17 00:00:00 2001 From: Snu Date: Wed, 30 Sep 2020 08:10:28 +0100 Subject: [PATCH 3/5] god damnit --- src/lua_baselib.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lua_baselib.c b/src/lua_baselib.c index b3e423300..e376fbea5 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -3328,8 +3328,8 @@ static luaL_Reg lib[] = { {"P_CheckSight", lib_pCheckSight}, {"P_CheckHoopPosition",lib_pCheckHoopPosition}, {"P_RadiusAttack",lib_pRadiusAttack}, - {"P_FloorzAtPos",lib_pCeilingzAtPos}, - {"P_CeilingzAtPos",lib_pFloorzAtPos}, + {"P_FloorzAtPos",lib_pFloorzAtPos}, + {"P_CeilingzAtPos",lib_pCeilingzAtPos}, {"P_DoSpring",lib_pDoSpring}, // p_inter From 8a00b47b38903a2f004f193853cba26684d0a098 Mon Sep 17 00:00:00 2001 From: Snu Date: Wed, 30 Sep 2020 08:40:21 +0100 Subject: [PATCH 4/5] Make the function ACTUALLY work --- src/p_map.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/p_map.c b/src/p_map.c index d26b1707d..c2e028472 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -5024,9 +5024,9 @@ fixed_t P_CeilingzAtPos(fixed_t x, fixed_t y, fixed_t z, fixed_t height) if (rover->flags & FF_QUICKSAND) { - if (z < topheight && bottomheight < thingtop) + if (thingtop > bottomheight && topheight > z) { - if (ceilingz < z) + if (ceilingz > z) ceilingz = z; } continue; @@ -5034,7 +5034,7 @@ fixed_t P_CeilingzAtPos(fixed_t x, fixed_t y, fixed_t z, fixed_t height) delta1 = z - (bottomheight + ((topheight - bottomheight)/2)); delta2 = thingtop - (bottomheight + ((topheight - bottomheight)/2)); - if (bottomheight > ceilingz && abs(delta1) < abs(delta2)) + if (bottomheight < ceilingz && abs(delta1) > abs(delta2)) ceilingz = bottomheight; } } From bfd8bd7564a81bd13c1737569e43d3c2870d74a2 Mon Sep 17 00:00:00 2001 From: Snu Date: Wed, 30 Sep 2020 08:44:43 +0100 Subject: [PATCH 5/5] comment typo --- src/p_map.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_map.c b/src/p_map.c index c2e028472..2851fa826 100644 --- a/src/p_map.c +++ b/src/p_map.c @@ -4999,7 +4999,7 @@ fixed_t P_FloorzAtPos(fixed_t x, fixed_t y, fixed_t z, fixed_t height) } // P_CeilingZAtPos -// Returns the ceilinz of the XYZ position +// Returns the ceilingz of the XYZ position fixed_t P_CeilingzAtPos(fixed_t x, fixed_t y, fixed_t z, fixed_t height) { sector_t *sec = R_PointInSubsector(x, y)->sector;