diff --git a/src/p_local.h b/src/p_local.h
index 2f56602559a439400d2ea960ec22a92352be62f6..96c71ed8ace16cd812aa8f34eda62993d26c8f88 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 60f6020eba4ec87d2297cee7ad7a633546a29380..01a49c810d4f810dd91aa91f4d9028754cc356a6 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;