From f80d95dd6933df5248ec60c9153cffef42d311ff Mon Sep 17 00:00:00 2001 From: OBilo <54061981+Keshash@users.noreply.github.com> Date: Tue, 13 Jan 2026 13:59:19 +0200 Subject: [PATCH 1/7] Add cover mod extension --- .../CombatExtended/Defs/ModExtensionCover.cs | 7 ++++ .../CombatExtended/Compatibility/Trenches.cs | 35 +++++++++++++++---- 2 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 Source/CombatExtended/CombatExtended/Defs/ModExtensionCover.cs diff --git a/Source/CombatExtended/CombatExtended/Defs/ModExtensionCover.cs b/Source/CombatExtended/CombatExtended/Defs/ModExtensionCover.cs new file mode 100644 index 0000000000..02d65ca552 --- /dev/null +++ b/Source/CombatExtended/CombatExtended/Defs/ModExtensionCover.cs @@ -0,0 +1,7 @@ +using Verse; + +namespace CombatExtended; +public class ModExtensionCover : DefModExtension +{ + public float heightOffset = 0f; +} diff --git a/Source/CombatExtended/Compatibility/Trenches.cs b/Source/CombatExtended/Compatibility/Trenches.cs index 8275b29df0..18183459ec 100755 --- a/Source/CombatExtended/Compatibility/Trenches.cs +++ b/Source/CombatExtended/Compatibility/Trenches.cs @@ -39,6 +39,25 @@ private static bool checkVFE(IntVec3 cell, Map map, out float heightAdjust) return false; } + private static bool CheckTrench(IntVec3 cell, Map map, out float heightAdjust) + { + heightAdjust = 0f; + List thingList = cell.GetThingList(map); + foreach (Thing thing in thingList) + { + ModExtensionCover modExtProperties = thing.def.GetModExtension(); + if (modExtProperties == null) + { + continue; + } + + heightAdjust = modExtProperties.heightOffset; + return true; + } + + return false; + } + public static float GetHeightAdjust(IntVec3 cell, Map map) { if (cell == null || map == null) @@ -46,14 +65,18 @@ public static float GetHeightAdjust(IntVec3 cell, Map map) return 0; } - if (vfeInstalled) + float heightAdjust = 0; + + if (vfeInstalled && checkVFE(cell, map, out heightAdjust)) { - float heightAdjust = 0; - if (checkVFE(cell, map, out heightAdjust)) - { - return heightAdjust; - } + return heightAdjust; } + + if (CheckTrench(cell, map, out heightAdjust)) + { + return heightAdjust; + } + return 0f; } } From c3e3eb80740c1651eba09b0b6971304ab5205a4d Mon Sep 17 00:00:00 2001 From: OBilo <54061981+Keshash@users.noreply.github.com> Date: Tue, 13 Jan 2026 17:49:03 +0200 Subject: [PATCH 2/7] Make trenches hide legs --- Source/CombatExtended/CombatExtended/CollisionVertical.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/CombatExtended/CombatExtended/CollisionVertical.cs b/Source/CombatExtended/CombatExtended/CollisionVertical.cs index 2e2fc4221f..a0fdb0c73f 100755 --- a/Source/CombatExtended/CombatExtended/CollisionVertical.cs +++ b/Source/CombatExtended/CombatExtended/CollisionVertical.cs @@ -22,8 +22,8 @@ public struct CollisionVertical public FloatRange HeightRange => new FloatRange(heightRange.min, heightRange.max); public float Min => heightRange.min; public float Max => heightRange.max; - public float BottomHeight => Max * BodyRegionBottomHeight; - public float MiddleHeight => Max * BodyRegionMiddleHeight; + public float BottomHeight => Max - (heightRange.Span * (1 - BodyRegionBottomHeight)); + public float MiddleHeight => Max - (heightRange.Span * (1 - BodyRegionMiddleHeight)); public CollisionVertical(Thing thing) { From 30ab96b465638da3f2f93e1d3532231ad143e5ce Mon Sep 17 00:00:00 2001 From: OBilo <54061981+Keshash@users.noreply.github.com> Date: Sat, 24 Jan 2026 18:56:49 +0200 Subject: [PATCH 3/7] submerge pawns into water bodies for height calc --- Source/CombatExtended/Compatibility/Trenches.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Source/CombatExtended/Compatibility/Trenches.cs b/Source/CombatExtended/Compatibility/Trenches.cs index 18183459ec..36523ee5a2 100755 --- a/Source/CombatExtended/Compatibility/Trenches.cs +++ b/Source/CombatExtended/Compatibility/Trenches.cs @@ -42,6 +42,16 @@ private static bool checkVFE(IntVec3 cell, Map map, out float heightAdjust) private static bool CheckTrench(IntVec3 cell, Map map, out float heightAdjust) { heightAdjust = 0f; + + //consider swimming pawns to be in a trench + TerrainDef terrain = cell.GetTerrain(map); + if (terrain != null && terrain.IsWater) + { + heightAdjust = terrain.passability == Traversability.Impassable ? -0.75f : -0.5f; + return true; + } + + //find trench building List thingList = cell.GetThingList(map); foreach (Thing thing in thingList) { From 775d911f2af177804513d6ba4536fc3e029412db Mon Sep 17 00:00:00 2001 From: OBilo <54061981+Keshash@users.noreply.github.com> Date: Sun, 1 Feb 2026 01:56:43 +0200 Subject: [PATCH 4/7] Make sure entrenched pawns are always shootable --- Source/CombatExtended/CombatExtended/CollisionVertical.cs | 7 ++++--- Source/CombatExtended/Compatibility/Trenches.cs | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/Source/CombatExtended/CombatExtended/CollisionVertical.cs b/Source/CombatExtended/CombatExtended/CollisionVertical.cs index a0fdb0c73f..a109c2f178 100755 --- a/Source/CombatExtended/CombatExtended/CollisionVertical.cs +++ b/Source/CombatExtended/CombatExtended/CollisionVertical.cs @@ -19,7 +19,7 @@ public struct CollisionVertical private readonly FloatRange heightRange; public readonly float shotHeight; - public FloatRange HeightRange => new FloatRange(heightRange.min, heightRange.max); + public FloatRange HeightRange => new FloatRange(Mathf.Max(0, heightRange.min), Mathf.Max(0.1f, heightRange.max)); public float Min => heightRange.min; public float Max => heightRange.max; public float BottomHeight => Max - (heightRange.Span * (1 - BodyRegionBottomHeight)); @@ -126,8 +126,9 @@ private static void CalculateHeightRange(Thing thing, out FloatRange heightRange } } float fillPercent2 = collisionHeight; - heightRange = new FloatRange(Mathf.Min(edificeHeight, edificeHeight + fillPercent2) + heightAdjust, Mathf.Max(edificeHeight, edificeHeight + fillPercent2) + heightAdjust); - shotHeight = heightRange.max - shotHeightOffset; + heightRange = new FloatRange( + Mathf.Min(edificeHeight, edificeHeight + fillPercent2) + heightAdjust, + Mathf.Max(0.1f, Mathf.Max(edificeHeight, edificeHeight + fillPercent2) + heightAdjust)); } /// diff --git a/Source/CombatExtended/Compatibility/Trenches.cs b/Source/CombatExtended/Compatibility/Trenches.cs index 36523ee5a2..16c294c56f 100755 --- a/Source/CombatExtended/Compatibility/Trenches.cs +++ b/Source/CombatExtended/Compatibility/Trenches.cs @@ -56,7 +56,7 @@ private static bool CheckTrench(IntVec3 cell, Map map, out float heightAdjust) foreach (Thing thing in thingList) { ModExtensionCover modExtProperties = thing.def.GetModExtension(); - if (modExtProperties == null) + if (modExtProperties == null || modExtProperties.heightOffset == 0f) { continue; } From 04b7d64d6a58874c11ab03e892a81d5d47897b4d Mon Sep 17 00:00:00 2001 From: OBilo <54061981+Keshash@users.noreply.github.com> Date: Sun, 1 Feb 2026 01:57:16 +0200 Subject: [PATCH 5/7] stop pawns shooting from below the ground and hitting ground --- Source/CombatExtended/CombatExtended/CollisionVertical.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Source/CombatExtended/CombatExtended/CollisionVertical.cs b/Source/CombatExtended/CombatExtended/CollisionVertical.cs index a109c2f178..7490ac92c8 100755 --- a/Source/CombatExtended/CombatExtended/CollisionVertical.cs +++ b/Source/CombatExtended/CombatExtended/CollisionVertical.cs @@ -129,6 +129,7 @@ private static void CalculateHeightRange(Thing thing, out FloatRange heightRange heightRange = new FloatRange( Mathf.Min(edificeHeight, edificeHeight + fillPercent2) + heightAdjust, Mathf.Max(0.1f, Mathf.Max(edificeHeight, edificeHeight + fillPercent2) + heightAdjust)); + shotHeight = Mathf.Max(0.1f, heightRange.max - shotHeightOffset); } /// From e2952fca018ed9661845d051cd7dffa08abb334f Mon Sep 17 00:00:00 2001 From: OBilo <54061981+Keshash@users.noreply.github.com> Date: Sun, 1 Feb 2026 01:59:05 +0200 Subject: [PATCH 6/7] remove outdated VE Security references --- .../CombatExtended/Compatibility/Trenches.cs | 35 +------------------ 1 file changed, 1 insertion(+), 34 deletions(-) diff --git a/Source/CombatExtended/Compatibility/Trenches.cs b/Source/CombatExtended/Compatibility/Trenches.cs index 16c294c56f..c048e38aea 100755 --- a/Source/CombatExtended/Compatibility/Trenches.cs +++ b/Source/CombatExtended/Compatibility/Trenches.cs @@ -11,34 +11,6 @@ namespace CombatExtended.Compatibility; [StaticConstructorOnStartup] public class CETrenches { - private static bool vfeInstalled; - private const string VFES_ModName = "Vanilla Furniture Expanded - Security"; - static CETrenches() - { - vfeInstalled = ModLister.HasActiveModWithName(VFES_ModName); - } - - private static bool checkVFE(IntVec3 cell, Map map, out float heightAdjust) - { - heightAdjust = 0f; - List thingList = GridsUtility.GetThingList(cell, map); - foreach (Thing thing in thingList) - { - CompProperties_TerrainSetter compProperties = thing.def.GetCompProperties(); - if (compProperties == null) - { - return false; - } - - TerrainDef terrainDef = compProperties.terrainDef; - TerrainDefExtension terrainDefExtension = TerrainDefExtension.Get(terrainDef); - heightAdjust = -terrainDefExtension.coverEffectiveness * CollisionVertical.WallCollisionHeight; - return true; - - } - return false; - } - private static bool CheckTrench(IntVec3 cell, Map map, out float heightAdjust) { heightAdjust = 0f; @@ -76,12 +48,7 @@ public static float GetHeightAdjust(IntVec3 cell, Map map) } float heightAdjust = 0; - - if (vfeInstalled && checkVFE(cell, map, out heightAdjust)) - { - return heightAdjust; - } - + if (CheckTrench(cell, map, out heightAdjust)) { return heightAdjust; From 12951282b40e5b0b1a118bfb3d0c91b736f6f39d Mon Sep 17 00:00:00 2001 From: OBilo <54061981+Keshash@users.noreply.github.com> Date: Wed, 4 Feb 2026 16:51:19 +0200 Subject: [PATCH 7/7] Restore checking for trenches on collision --- Source/CombatExtended/CombatExtended/CollisionVertical.cs | 2 +- .../CombatExtended/CombatExtended/Defs/ModExtensionCover.cs | 2 +- Source/CombatExtended/Compatibility/Trenches.cs | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Source/CombatExtended/CombatExtended/CollisionVertical.cs b/Source/CombatExtended/CombatExtended/CollisionVertical.cs index fca309e426..5d7bdc4795 100755 --- a/Source/CombatExtended/CombatExtended/CollisionVertical.cs +++ b/Source/CombatExtended/CombatExtended/CollisionVertical.cs @@ -73,7 +73,7 @@ private static void CalculateHeightRange(Thing thing, out FloatRange heightRange } float collisionHeight = 0f; float shotHeightOffset = 0; - float heightAdjust = 0; + float heightAdjust = CETrenches.GetHeightAdjust(thing.Position, thing.Map); var pawn = thing as Pawn; if (pawn != null) diff --git a/Source/CombatExtended/CombatExtended/Defs/ModExtensionCover.cs b/Source/CombatExtended/CombatExtended/Defs/ModExtensionCover.cs index 02d65ca552..6c7bb0f3f7 100644 --- a/Source/CombatExtended/CombatExtended/Defs/ModExtensionCover.cs +++ b/Source/CombatExtended/CombatExtended/Defs/ModExtensionCover.cs @@ -3,5 +3,5 @@ namespace CombatExtended; public class ModExtensionCover : DefModExtension { - public float heightOffset = 0f; + public float heightOffset = 0f; } diff --git a/Source/CombatExtended/Compatibility/Trenches.cs b/Source/CombatExtended/Compatibility/Trenches.cs index c048e38aea..e34af4c629 100755 --- a/Source/CombatExtended/Compatibility/Trenches.cs +++ b/Source/CombatExtended/Compatibility/Trenches.cs @@ -15,11 +15,11 @@ private static bool CheckTrench(IntVec3 cell, Map map, out float heightAdjust) { heightAdjust = 0f; - //consider swimming pawns to be in a trench + //consider swimming pawns to be partially underground TerrainDef terrain = cell.GetTerrain(map); if (terrain != null && terrain.IsWater) { - heightAdjust = terrain.passability == Traversability.Impassable ? -0.75f : -0.5f; + heightAdjust = terrain.passability == Traversability.Impassable ? -0.5f : -0.25f; return true; } @@ -48,7 +48,7 @@ public static float GetHeightAdjust(IntVec3 cell, Map map) } float heightAdjust = 0; - + if (CheckTrench(cell, map, out heightAdjust)) { return heightAdjust;