Add AnyBuildingAt method to BuildingInfluence.

This commit is contained in:
Paul Chote
2021-03-28 11:20:56 +01:00
committed by reaperrr
parent 19c7e14393
commit bc286b78bf
4 changed files with 10 additions and 6 deletions

View File

@@ -114,7 +114,7 @@ namespace OpenRA.Mods.Cnc.Traits
var blockedByNeighbours = Map.Ramp[cell] == 0 && !Common.Util.ExpandFootprint(cell, false) var blockedByNeighbours = Map.Ramp[cell] == 0 && !Common.Util.ExpandFootprint(cell, false)
.All(c => check(cell, c)); .All(c => check(cell, c));
return !blockedByNeighbours && (resourceType == info.VeinType || BuildingInfluence.GetBuildingAt(cell) == null); return !blockedByNeighbours && (resourceType == info.VeinType || !BuildingInfluence.AnyBuildingAt(cell));
} }
} }
} }

View File

@@ -50,5 +50,10 @@ namespace OpenRA.Mods.Common.Traits
{ {
return influence.Contains(cell) ? influence[cell] : null; return influence.Contains(cell) ? influence[cell] : null;
} }
public bool AnyBuildingAt(CPos cell)
{
return influence.Contains(cell) && influence[cell] != null;
}
} }
} }

View File

@@ -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 // Replacements are enabled and the cell contained at least one (not ignored) actor or building bib
var building = world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(cell); var foundBuilding = world.WorldActor.Trait<BuildingInfluence>().AnyBuildingAt(cell);
if (foundActors || building != null) if (foundActors || foundBuilding)
{ {
// The cell contains at least one actor, and none were replaceable // The cell contains at least one actor, and none were replaceable
if (acceptedReplacements == null) if (acceptedReplacements == null)
@@ -73,8 +73,7 @@ namespace OpenRA.Mods.Common.Traits
{ {
// HACK: To preserve legacy behaviour, AllowInvalidPlacement should display red placement indicators // HACK: To preserve legacy behaviour, AllowInvalidPlacement should display red placement indicators
// if (and only if) there is a building or bib in the cell // if (and only if) there is a building or bib in the cell
var building = world.WorldActor.Trait<BuildingInfluence>().GetBuildingAt(cell); if (world.WorldActor.Trait<BuildingInfluence>().AnyBuildingAt(cell))
if (building != null)
return false; return false;
} }

View File

@@ -178,7 +178,7 @@ namespace OpenRA.Mods.Common.Traits
if (!resourceInfo.AllowedTerrainTypes.Contains(Map.GetTerrainInfo(cell).Type)) if (!resourceInfo.AllowedTerrainTypes.Contains(Map.GetTerrainInfo(cell).Type))
return false; return false;
return BuildingInfluence.GetBuildingAt(cell) == null; return !BuildingInfluence.AnyBuildingAt(cell);
} }
ResourceLayerContents CreateResourceCell(string resourceType, CPos cell, int density) ResourceLayerContents CreateResourceCell(string resourceType, CPos cell, int density)