From bc286b78bf50a0ee05fb4994dd916382dc8d66bd Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sun, 28 Mar 2021 11:20:56 +0100 Subject: [PATCH] Add AnyBuildingAt method to BuildingInfluence. --- OpenRA.Mods.Cnc/Traits/World/TSResourceLayer.cs | 2 +- OpenRA.Mods.Common/Traits/Buildings/BuildingInfluence.cs | 5 +++++ OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs | 7 +++---- OpenRA.Mods.Common/Traits/World/ResourceLayer.cs | 2 +- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/OpenRA.Mods.Cnc/Traits/World/TSResourceLayer.cs b/OpenRA.Mods.Cnc/Traits/World/TSResourceLayer.cs index 9d9cbbd687..cf3a02297a 100644 --- a/OpenRA.Mods.Cnc/Traits/World/TSResourceLayer.cs +++ b/OpenRA.Mods.Cnc/Traits/World/TSResourceLayer.cs @@ -114,7 +114,7 @@ namespace OpenRA.Mods.Cnc.Traits var blockedByNeighbours = Map.Ramp[cell] == 0 && !Common.Util.ExpandFootprint(cell, false) .All(c => check(cell, c)); - return !blockedByNeighbours && (resourceType == info.VeinType || BuildingInfluence.GetBuildingAt(cell) == null); + return !blockedByNeighbours && (resourceType == info.VeinType || !BuildingInfluence.AnyBuildingAt(cell)); } } } diff --git a/OpenRA.Mods.Common/Traits/Buildings/BuildingInfluence.cs b/OpenRA.Mods.Common/Traits/Buildings/BuildingInfluence.cs index 22ad8fda18..7c630f6d16 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/BuildingInfluence.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/BuildingInfluence.cs @@ -50,5 +50,10 @@ namespace OpenRA.Mods.Common.Traits { return influence.Contains(cell) ? influence[cell] : null; } + + public bool AnyBuildingAt(CPos cell) + { + return influence.Contains(cell) && influence[cell] != null; + } } } diff --git a/OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs b/OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs index e4a0631cee..d47ecc4966 100644 --- a/OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs +++ b/OpenRA.Mods.Common/Traits/Buildings/BuildingUtils.cs @@ -54,8 +54,8 @@ namespace OpenRA.Mods.Common.Traits } // Replacements are enabled and the cell contained at least one (not ignored) actor or building bib - var building = world.WorldActor.Trait().GetBuildingAt(cell); - if (foundActors || building != null) + var foundBuilding = world.WorldActor.Trait().AnyBuildingAt(cell); + if (foundActors || foundBuilding) { // The cell contains at least one actor, and none were replaceable if (acceptedReplacements == null) @@ -73,8 +73,7 @@ namespace OpenRA.Mods.Common.Traits { // HACK: To preserve legacy behaviour, AllowInvalidPlacement should display red placement indicators // if (and only if) there is a building or bib in the cell - var building = world.WorldActor.Trait().GetBuildingAt(cell); - if (building != null) + if (world.WorldActor.Trait().AnyBuildingAt(cell)) return false; } diff --git a/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs b/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs index 07d4a81122..06fc0a1077 100644 --- a/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs @@ -178,7 +178,7 @@ namespace OpenRA.Mods.Common.Traits if (!resourceInfo.AllowedTerrainTypes.Contains(Map.GetTerrainInfo(cell).Type)) return false; - return BuildingInfluence.GetBuildingAt(cell) == null; + return !BuildingInfluence.AnyBuildingAt(cell); } ResourceLayerContents CreateResourceCell(string resourceType, CPos cell, int density)