Skip to content

Commit

Permalink
Highlight other destroyable overlapping objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
repkins committed Oct 29, 2022
1 parent 9000715 commit 9538548
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
4 changes: 2 additions & 2 deletions TerraformingBZ/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
2 changes: 1 addition & 1 deletion TerraformingBZ/mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [ ],
Expand Down
16 changes: 14 additions & 2 deletions TerraformingShared/Tools/BuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,22 @@ internal static class BuilderExtensions
{
public static void ClearConstructionObstacles(List<GameObject> results)
{
results.RemoveAll(IsObstacleOf<ConstructionObstacle>);
results.RemoveAll(IsContructionObstacle);
}

public static bool IsContructionObstacle(GameObject go)
{
if (IsObstacleOf<ConstructionObstacle>(go))
{
return true;
}
#if !BelowZero
results.RemoveAll(IsObstacleOf<ImmuneToPropulsioncannon>);
if (IsObstacleOf<ImmuneToPropulsioncannon>(go))
{
return true;
}
#endif
return false;
}

static bool IsObstacleOf<T>(GameObject go)
Expand Down
30 changes: 18 additions & 12 deletions TerraformingShared/Tools/BuilderToolPatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ public static void UpdateObstacleSettings()
{
RestoreHighlightedObstacles();

if (Config.Instance.destroyLargerObstaclesOnConstruction)
{
HighlightDestroyableObstacles(constructableBase);
}
HighlightDestroyableObstacles(constructableBase);
}

prevTarget = targetObject;
Expand Down Expand Up @@ -105,28 +102,37 @@ public static void OnHolster_Postfix()

static void HighlightDestroyableObstacles(ConstructableBase constructableBase)
{
using (var orientedBoundsListPool = Pool<ListPool<OrientedBounds>>.Get())
using (var constructableBoundsListPool = Pool<ListPool<ConstructableBounds>>.Get())
using (var obstacleListPool = Pool<ListPool<GameObject>>.Get())
using (var overlappedObjectsPool = Pool<ListPool<GameObject>>.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<ListPool<Material>>.Get())
using (var rendererListPool = Pool<ListPool<Renderer>>.Get())
{
var materialList = materialListPool.list;
var rendererList = rendererListPool.list;

foreach (var obstacle in obstacleList)
{
if (!(obstacle.GetComponent<BaseCell>() != null) && Builder.CanDestroyObject(obstacle))
if ((Config.Instance.destroyLargerObstaclesOnConstruction || !BuilderExtensions.IsContructionObstacle(obstacle))
&& obstacle.GetComponent<BaseCell>() == null && Builder.CanDestroyObject(obstacle))
{
obstacle.GetComponentsInChildren(rendererList);

Expand Down

0 comments on commit 9538548

Please sign in to comment.