Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fix AI jamming up its base by enforcing 1-cell gaps

  • Loading branch information...
commit bd0b3edccb01e60001aafa8f0c9fd6f0e4821151 1 parent d66439a
@chrisforbes chrisforbes authored
Showing with 27 additions and 1 deletion.
  1. +27 −1 OpenRA.Mods.RA/HackyAI.cs
View
28 OpenRA.Mods.RA/HackyAI.cs
@@ -169,6 +169,30 @@ ActorInfo ChooseDefenseToBuild(ProductionQueue queue)
return null;
}
+ IEnumerable<int2> 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<int2> ExpandFootprint(IEnumerable<int2> cells)
+ {
+ var result = new Dictionary<int2, bool>();
+ foreach (var c in cells.SelectMany(c => Neighbours(c)))
+ result[c] = true;
+ return result.Keys;
+ }
+
+ bool NoBuildingsUnder(IEnumerable<int2> cells)
+ {
+ var bi = world.WorldActor.Trait<BuildingInfluence>();
+ return cells.All(c => bi.GetBuildingAt(c) == null);
+ }
+
int2? ChooseBuildLocation(ProductionItem item)
{
var bi = Rules.Info[item.Item].Traits.Get<BuildingInfo>();
@@ -177,7 +201,9 @@ ActorInfo ChooseDefenseToBuild(ProductionQueue queue)
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.
}
Please sign in to comment.
Something went wrong with that request. Please try again.