Skip to content

Commit

Permalink
Merge pull request #1222 from CombatExtended-Continued/VFETrenches
Browse files Browse the repository at this point in the history
Add support for VFE Trenches
  • Loading branch information
N7Huntsman authored Dec 20, 2021
2 parents 962395e + 8c768f5 commit 1f09107
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 4 deletions.
11 changes: 7 additions & 4 deletions Source/CombatExtended/CombatExtended/CollisionVertical.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RimWorld;
using Verse;
using UnityEngine;
using CombatExtended.Compatibility;

namespace CombatExtended
{
Expand Down Expand Up @@ -69,10 +70,12 @@ private static void CalculateHeightRange(Thing thing, out FloatRange heightRange

float collisionHeight = 0f;
float shotHeightOffset = 0;
float heightAdjust = CETrenches.GetHeightAdjust(thing.Position, thing.Map);

var pawn = thing as Pawn;
if (pawn != null)
{
collisionHeight = CE_Utility.GetCollisionBodyFactors(pawn).y;
collisionHeight = CE_Utility.GetCollisionBodyFactors(pawn).y;

shotHeightOffset = collisionHeight * (1 - BodyRegionMiddleHeight);

Expand All @@ -90,7 +93,7 @@ private static void CalculateHeightRange(Thing thing, out FloatRange heightRange
Thing cover = curCell.GetCover(map);
if (cover != null && cover.def.Fillage == FillCategory.Partial && !cover.IsPlant())
{
var coverHeight = new CollisionVertical(cover).Max;
var coverHeight = new CollisionVertical(cover).Max - heightAdjust;
if (coverHeight > crouchHeight) crouchHeight = coverHeight;
}
}
Expand All @@ -112,7 +115,7 @@ private static void CalculateHeightRange(Thing thing, out FloatRange heightRange
}
}
float fillPercent2 = collisionHeight;
heightRange = new FloatRange(Mathf.Min(edificeHeight, edificeHeight + fillPercent2), Mathf.Max(edificeHeight, edificeHeight + fillPercent2));
heightRange = new FloatRange(Mathf.Min(edificeHeight, edificeHeight + fillPercent2) + heightAdjust, Mathf.Max(edificeHeight, edificeHeight + fillPercent2) + heightAdjust);
shotHeight = heightRange.max - shotHeightOffset;
}

Expand Down
48 changes: 48 additions & 0 deletions Source/CombatExtended/Compatibility/Trenches.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using CombatExtended.CombatExtended.LoggerUtils;
using UnityEngine;
using Verse;
using VFESecurity;

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);
}
public static float GetHeightAdjust(IntVec3 cell, Map map)
{
if (cell == null || map == null)
{
return 0;
}

if (vfeInstalled)
{
List<Thing> thingList = GridsUtility.GetThingList(cell, map);
foreach (Thing thing in thingList)
{
CompProperties_TerrainSetter compProperties = thing.def.GetCompProperties<CompProperties_TerrainSetter>();
if (compProperties == null)
{
return 0f;
}

TerrainDef terrainDef = compProperties.terrainDef;
TerrainDefExtension terrainDefExtension = TerrainDefExtension.Get(terrainDef);
return -terrainDefExtension.coverEffectiveness * CollisionVertical.WallCollisionHeight;

}
}
return 0f;
}
}
}

0 comments on commit 1f09107

Please sign in to comment.