diff --git a/TerraformingBZ/Properties/AssemblyInfo.cs b/TerraformingBZ/Properties/AssemblyInfo.cs index b1ca7cb..774aeff 100644 --- a/TerraformingBZ/Properties/AssemblyInfo.cs +++ b/TerraformingBZ/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.4.1.0")] -[assembly: AssemblyFileVersion("1.4.1.0")] +[assembly: AssemblyVersion("1.4.2.0")] +[assembly: AssemblyFileVersion("1.4.2.0")] diff --git a/TerraformingBZ/mod.json b/TerraformingBZ/mod.json index 722ecf9..7930ce3 100644 --- a/TerraformingBZ/mod.json +++ b/TerraformingBZ/mod.json @@ -2,7 +2,7 @@ "Id": "TerraformingBZ", "DisplayName": "Terraforming Ability for Below Zero", "Author": "repkins", - "Version": "1.4.1", + "Version": "1.4.2", "Dependencies": [ ], "VersionDependencies": { }, "LoadBefore": [ ], diff --git a/TerraformingShared/Tools/BuilderExtensions.cs b/TerraformingShared/Tools/BuilderExtensions.cs index 95fc43c..99e4358 100644 --- a/TerraformingShared/Tools/BuilderExtensions.cs +++ b/TerraformingShared/Tools/BuilderExtensions.cs @@ -9,10 +9,22 @@ internal static class BuilderExtensions { public static void ClearConstructionObstacles(List results) { - results.RemoveAll(IsObstacleOf); + results.RemoveAll(IsContructionObstacle); + } + + public static bool IsContructionObstacle(GameObject go) + { + if (IsObstacleOf(go)) + { + return true; + } #if !BelowZero - results.RemoveAll(IsObstacleOf); + if (IsObstacleOf(go)) + { + return true; + } #endif + return false; } static bool IsObstacleOf(GameObject go) diff --git a/TerraformingShared/Tools/BuilderToolPatches.cs b/TerraformingShared/Tools/BuilderToolPatches.cs index 1f4c7eb..5a85ea7 100644 --- a/TerraformingShared/Tools/BuilderToolPatches.cs +++ b/TerraformingShared/Tools/BuilderToolPatches.cs @@ -58,10 +58,7 @@ public static void UpdateObstacleSettings() { RestoreHighlightedObstacles(); - if (Config.Instance.destroyLargerObstaclesOnConstruction) - { - HighlightDestroyableObstacles(constructableBase); - } + HighlightDestroyableObstacles(constructableBase); } prevTarget = targetObject; @@ -105,28 +102,37 @@ public static void OnHolster_Postfix() static void HighlightDestroyableObstacles(ConstructableBase constructableBase) { - using (var orientedBoundsListPool = Pool>.Get()) + using (var constructableBoundsListPool = Pool>.Get()) using (var obstacleListPool = Pool>.Get()) + using (var overlappedObjectsPool = Pool>.Get()) { - var orientedBoundsList = orientedBoundsListPool.list; + var constructableBoundsList = constructableBoundsListPool.list; var obstacleList = obstacleListPool.list; + var overlappedObjects = overlappedObjectsPool.list; + + constructableBase.GetComponentsInChildren(true, constructableBoundsList); - Builder.CacheBounds(constructableBase.gameObject.transform, constructableBase.gameObject, orientedBoundsList, false); - BuilderExtensions.GetObstacles(constructableBase.transform.position, constructableBase.transform.rotation, orientedBoundsList, obstacleList); + var orientedBoundsList = constructableBoundsList.Select(constructableBounds => OrientedBounds.ToWorldBounds(constructableBounds.transform, constructableBounds.bounds)); + foreach (var orientedBounds in orientedBoundsList) + { + overlappedObjects.Clear(); + Builder.GetOverlappedObjects(orientedBounds.position, orientedBounds.rotation, orientedBounds.extents, overlappedObjects); + + obstacleList.AddRange(overlappedObjects); + } - Terraforming.Logger.Info($"obstacleList.Count = {obstacleList.Count}"); + Terraforming.Logger.Debug($"obstacleList.Count = {obstacleList.Count}"); if (obstacleList.Count > 0) { - using (var materialListPool = Pool>.Get()) using (var rendererListPool = Pool>.Get()) { - var materialList = materialListPool.list; var rendererList = rendererListPool.list; foreach (var obstacle in obstacleList) { - if (!(obstacle.GetComponent() != null) && Builder.CanDestroyObject(obstacle)) + if ((Config.Instance.destroyLargerObstaclesOnConstruction || !BuilderExtensions.IsContructionObstacle(obstacle)) + && obstacle.GetComponent() == null && Builder.CanDestroyObject(obstacle)) { obstacle.GetComponentsInChildren(rendererList);