diff --git a/OpenRA.Mods.RA/HackyAI.cs b/OpenRA.Mods.RA/HackyAI.cs index ab17d58ea6..350830ec65 100644 --- a/OpenRA.Mods.RA/HackyAI.cs +++ b/OpenRA.Mods.RA/HackyAI.cs @@ -169,6 +169,30 @@ namespace OpenRA.Mods.RA return null; } + IEnumerable Neighbours(int2 c) + { + /* only return 4-neighbors for now, maybe add 8s later. */ + yield return c; + yield return new int2(c.X - 1, c.Y); + yield return new int2(c.X + 1, c.Y); + yield return new int2(c.X, c.Y - 1); + yield return new int2(c.X, c.Y + 1); + } + + IEnumerable ExpandFootprint(IEnumerable cells) + { + var result = new Dictionary(); + foreach (var c in cells.SelectMany(c => Neighbours(c))) + result[c] = true; + return result.Keys; + } + + bool NoBuildingsUnder(IEnumerable cells) + { + var bi = world.WorldActor.Trait(); + return cells.All(c => bi.GetBuildingAt(c) == null); + } + int2? ChooseBuildLocation(ProductionItem item) { var bi = Rules.Info[item.Item].Traits.Get(); @@ -177,7 +201,9 @@ namespace OpenRA.Mods.RA foreach (var t in world.FindTilesInCircle(baseCenter, k)) if (world.CanPlaceBuilding(item.Item, bi, t, null)) if (bi.IsCloseEnoughToBase(world, p, item.Item, t)) - return t; + if (NoBuildingsUnder(ExpandFootprint( + FootprintUtils.Tiles( item.Item, bi, t )))) + return t; return null; // i don't know where to put it. }