From 073798166a497e75f327c6882c47d14ada29fb29 Mon Sep 17 00:00:00 2001
From: spherallic <spherallic@gmail.com>
Date: Sat, 10 Jun 2023 03:00:20 +0200
Subject: [PATCH] Implement absolutez flag for things

---
 Build/Configurations/Includes/SRB222_misc.cfg              | 2 ++
 Source/Core/Controls/ThingInfoPanel.cs                     | 2 +-
 Source/Core/Geometry/Tools.cs                              | 6 +++---
 Source/Plugins/BuilderModes/General/BuilderModesTools.cs   | 6 +++---
 Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs | 2 +-
 5 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/Build/Configurations/Includes/SRB222_misc.cfg b/Build/Configurations/Includes/SRB222_misc.cfg
index 61b79ae57..e274fece6 100644
--- a/Build/Configurations/Includes/SRB222_misc.cfg
+++ b/Build/Configurations/Includes/SRB222_misc.cfg
@@ -126,6 +126,7 @@ sectorflagscategories
 thingflags_udmf
 {
 	flip = "Flip";
+	absolutez = "Absolute Z height";
 }
 
 // Thing flags UDMF translation table
@@ -137,6 +138,7 @@ thingflagstranslation
 	2 = "flip";
 	4 = "special";
 	8 = "ambush";
+	16 = "absolutez";
 }
 
 // DEFAULT SECTOR BRIGHTNESS LEVELS
diff --git a/Source/Core/Controls/ThingInfoPanel.cs b/Source/Core/Controls/ThingInfoPanel.cs
index 6ec78d70e..cd426b1a0 100644
--- a/Source/Core/Controls/ThingInfoPanel.cs
+++ b/Source/Core/Controls/ThingInfoPanel.cs
@@ -87,7 +87,7 @@ namespace CodeImp.DoomBuilder.Controls
 			// Determine z info to show
 			t.DetermineSector();
 			string zinfo;
-			if(ti.AbsoluteZ || t.Sector == null)
+			if(ti.AbsoluteZ || t.IsFlagSet(General.Map.UDMF ? "absolutez" : "16") || t.Sector == null)
 			{
 				zinfo = t.Position.z.ToString(CultureInfo.InvariantCulture) + " (abs.)"; //mxd
 			}
diff --git a/Source/Core/Geometry/Tools.cs b/Source/Core/Geometry/Tools.cs
index 99caff567..f049175bc 100755
--- a/Source/Core/Geometry/Tools.cs
+++ b/Source/Core/Geometry/Tools.cs
@@ -2213,7 +2213,7 @@ namespace CodeImp.DoomBuilder.Geometry
 			if(initialSector != t.Sector && General.Map.FormatInterface.HasThingHeight) 
 			{
 				ThingTypeInfo ti = General.Map.Data.GetThingInfo(t.Type);
-				if(ti.AbsoluteZ) return;
+				if(ti.AbsoluteZ || t.IsFlagSet(General.Map.UDMF ? "absolutez" : "16")) return;
 
 				if(ti.Hangs && initialSector.CeilHeight != t.Sector.CeilHeight) 
 				{
@@ -2226,10 +2226,10 @@ namespace CodeImp.DoomBuilder.Geometry
 			}
 		}
 
-		public static int GetThingAbsoluteZ(Thing t, ThingTypeInfo ti) 
+		public static int GetThingAbsoluteZ(Thing t, ThingTypeInfo ti)
 		{
 			// Determine z info
-			if(ti.AbsoluteZ) return (int)t.Position.z;
+			if(ti.AbsoluteZ || t.IsFlagSet(General.Map.UDMF ? "absolutez" : "16")) return (int)t.Position.z;
 
 			if(t.Sector != null) 
 			{
diff --git a/Source/Plugins/BuilderModes/General/BuilderModesTools.cs b/Source/Plugins/BuilderModes/General/BuilderModesTools.cs
index a42bb1122..5d5d8e6ce 100755
--- a/Source/Plugins/BuilderModes/General/BuilderModesTools.cs
+++ b/Source/Plugins/BuilderModes/General/BuilderModesTools.cs
@@ -354,7 +354,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
 		{
 			Vector3D pos = thing.Thing.Position;
 			double thingheight = thing.Thing.Height;
-			bool absolute = thing.Info.AbsoluteZ;
+			bool absolute = thing.Info.AbsoluteZ || thing.Thing.IsFlagSet(General.Map.UDMF ? "absolutez" : "16");
 			bool hangs = thing.Info.Hangs;
 			
 			if(absolute && hangs)
@@ -450,7 +450,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
 		{
 			Vector3D pos = thing.Thing.Position;
 			double thingheight = thing.Thing.Height;
-			bool absolute = thing.Info.AbsoluteZ;
+			bool absolute = thing.Info.AbsoluteZ || thing.Thing.IsFlagSet(General.Map.UDMF ? "absolutez" : "16"); ;
 			bool hangs = thing.Info.Hangs;
 			
 			if(absolute && hangs)
@@ -577,7 +577,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
 			if(info != null)
 			{
 				if(info.AbsoluteZ && info.Hangs) return t.Position.z; // Not sure what to do here...
-				if(info.AbsoluteZ)
+				if(info.AbsoluteZ || t.IsFlagSet(General.Map.UDMF ? "absolutez" : "16"))
 				{
 					// Transform to floor-aligned position
 					SectorData nsd = mode.GetSectorData(t.Sector);
diff --git a/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs b/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs
index 28a294695..f9987579f 100755
--- a/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs
+++ b/Source/Plugins/BuilderModes/VisualModes/BaseVisualThing.cs
@@ -434,7 +434,7 @@ namespace CodeImp.DoomBuilder.BuilderModes
 					pos.z = (Thing.Args[0] == 0) ? sd.Floor.sector.FloorHeight + Thing.Position.z : Thing.Position.z;
 				}
 			}
-			else if(info.AbsoluteZ)
+			else if(info.AbsoluteZ || Thing.IsFlagSet(General.Map.UDMF ? "absolutez" : "16"))
 			{
 				// Absolute Z position
 				pos.z = Thing.Position.z;
-- 
GitLab