diff --git a/OpenRA.Mods.Common/AI/HackyAI.cs b/OpenRA.Mods.Common/AI/HackyAI.cs index 5817c60151..c02bcf87cb 100644 --- a/OpenRA.Mods.Common/AI/HackyAI.cs +++ b/OpenRA.Mods.Common/AI/HackyAI.cs @@ -264,6 +264,7 @@ namespace OpenRA.Mods.Common.AI public Player Player { get; private set; } readonly DomainIndex domainIndex; + readonly ResourceLayer resLayer; readonly ResourceClaimLayer claimLayer; readonly IPathFinder pathfinder; @@ -311,6 +312,7 @@ namespace OpenRA.Mods.Common.AI return; domainIndex = World.WorldActor.Trait(); + resLayer = World.WorldActor.TraitOrDefault(); claimLayer = World.WorldActor.TraitOrDefault(); pathfinder = World.WorldActor.Trait(); @@ -667,7 +669,8 @@ namespace OpenRA.Mods.Common.AI if (--assignRolesTicks <= 0) { assignRolesTicks = Info.AssignRolesInterval; - GiveOrdersToIdleHarvesters(); + if (resLayer != null && !resLayer.IsResourceLayerEmpty) + GiveOrdersToIdleHarvesters(); FindNewUnits(self); FindAndDeployBackupMcv(self); } diff --git a/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs b/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs index 4d1c84ce07..4e4f923bf3 100644 --- a/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs +++ b/OpenRA.Mods.Common/Traits/World/ResourceLayer.cs @@ -36,7 +36,10 @@ namespace OpenRA.Mods.Common.Traits protected readonly CellLayer Content; protected readonly CellLayer RenderContent; + public bool IsResourceLayerEmpty { get { return resCells < 1; } } + bool disposed; + int resCells; public ResourceLayer(Actor self) { @@ -217,6 +220,7 @@ namespace OpenRA.Mods.Common.Traits CellContents CreateResourceCell(ResourceType t, CPos cell) { world.Map.CustomTerrain[cell] = world.Map.Rules.TileSet.GetTerrainIndex(t.Info.TerrainType); + ++resCells; return new CellContents { @@ -255,6 +259,7 @@ namespace OpenRA.Mods.Common.Traits { Content[cell] = EmptyCell; world.Map.CustomTerrain[cell] = byte.MaxValue; + --resCells; } else Content[cell] = c; @@ -270,6 +275,8 @@ namespace OpenRA.Mods.Common.Traits if (Content[cell].Type == null) return; + --resCells; + // Clear cell Content[cell] = EmptyCell; world.Map.CustomTerrain[cell] = byte.MaxValue;