From 184561a230107b1f0a4f561559bae349218b0b5c Mon Sep 17 00:00:00 2001
From: SSNTails <spaddlewit@gmail.com>
Date: Tue, 20 Feb 2024 10:38:50 -0500
Subject: [PATCH] 'highest' in P_MobjCeilingZ fixes. Function should now do
 what it says on the tin

---
 src/p_local.h | 6 +++---
 src/p_mobj.c  | 8 ++++----
 2 files changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/p_local.h b/src/p_local.h
index 2f56602559..96c71ed8ac 100644
--- a/src/p_local.h
+++ b/src/p_local.h
@@ -310,11 +310,11 @@ void P_SceneryThinker(mobj_t *mobj);
 fixed_t P_MobjFloorZ(sector_t *sector, sector_t *boundsec, fixed_t x, fixed_t y, fixed_t radius, line_t *line, boolean lowest, boolean perfect);
 fixed_t P_MobjCeilingZ(sector_t *sector, sector_t *boundsec, fixed_t x, fixed_t y, fixed_t radius, line_t *line, boolean highest, boolean perfect);
 #define P_GetFloorZ(mobj, sector, x, y, line) P_MobjFloorZ(sector, NULL, x, y, mobj->radius, line, false, false)
-#define P_GetCeilingZ(mobj, sector, x, y, line) P_MobjCeilingZ(sector, NULL, x, y, mobj->radius, line, true, false)
-#define P_GetFOFTopZ(mobj, sector, fof, x, y, line) P_MobjCeilingZ(sectors + fof->secnum, sector, x, y, mobj->radius, line, false, false)
+#define P_GetCeilingZ(mobj, sector, x, y, line) P_MobjCeilingZ(sector, NULL, x, y, mobj->radius, line, false, false)
+#define P_GetFOFTopZ(mobj, sector, fof, x, y, line) P_MobjCeilingZ(sectors + fof->secnum, sector, x, y, mobj->radius, line, true, false)
 #define P_GetFOFBottomZ(mobj, sector, fof, x, y, line) P_MobjFloorZ(sectors + fof->secnum, sector, x, y, mobj->radius, line, true, false)
 #define P_GetSpecialBottomZ(mobj, src, bound) P_MobjFloorZ(src, bound, mobj->x, mobj->y, mobj->radius, NULL, src != bound, true)
-#define P_GetSpecialTopZ(mobj, src, bound) P_MobjCeilingZ(src, bound, mobj->x, mobj->y, mobj->radius, NULL, src == bound, true)
+#define P_GetSpecialTopZ(mobj, src, bound) P_MobjCeilingZ(src, bound, mobj->x, mobj->y, mobj->radius, NULL, src != bound, true)
 
 boolean P_InsideANonSolidFFloor(mobj_t *mobj, ffloor_t *rover);
 boolean P_CheckDeathPitCollide(mobj_t *mo);
diff --git a/src/p_mobj.c b/src/p_mobj.c
index 60f6020eba..01a49c810d 100644
--- a/src/p_mobj.c
+++ b/src/p_mobj.c
@@ -1207,9 +1207,9 @@ fixed_t P_MobjCeilingZ(sector_t *sector, sector_t *boundsec, fixed_t x, fixed_t
 			fixed_t finalheight;
 
 			if (highest)
-				finalheight = INT32_MAX;
-			else
 				finalheight = INT32_MIN;
+			else
+				finalheight = INT32_MAX;
 
 			bbox[BOXLEFT] = x-radius;
 			bbox[BOXRIGHT] = x+radius;
@@ -1226,9 +1226,9 @@ fixed_t P_MobjCeilingZ(sector_t *sector, sector_t *boundsec, fixed_t x, fixed_t
 					continue;
 
 				if (highest)
-					finalheight = min(finalheight, HighestOnLine(radius, x, y, ld, slope, true));
-				else
 					finalheight = max(finalheight, HighestOnLine(radius, x, y, ld, slope, false));
+				else
+					finalheight = min(finalheight, HighestOnLine(radius, x, y, ld, slope, true));
 			}
 
 			return finalheight;
-- 
GitLab