IEnumerable <Order> ClearBlockersOrders(World world, CPos topLeft) { var allTiles = FootprintUtils.Tiles(world.Map.Rules, building, buildingInfo, topLeft).ToArray(); var neightborTiles = Util.ExpandFootprint(allTiles, true).Except(allTiles) .Where(world.Map.Contains).ToList(); var blockers = allTiles.SelectMany(world.ActorMap.GetActorsAt) .Where(a => a.Owner == producer.Owner && a.IsIdle) .Select(a => new TraitPair <Mobile> { Actor = a, Trait = a.TraitOrDefault <Mobile>() }); foreach (var blocker in blockers.Where(x => x.Trait != null)) { var availableCells = neightborTiles.Where(t => blocker.Trait.CanEnterCell(t)).ToList(); if (availableCells.Count == 0) { continue; } yield return(new Order("Move", blocker.Actor, false) { TargetLocation = blocker.Actor.ClosestCell(availableCells) }); } }
public static IEnumerable <CPos> AdjacentCells(Target target) { var cells = target.IsActor ? target.Actor.OccupiesSpace.OccupiedCells().Select(c => c.First).ToArray() : new CPos[] {}; if (cells.Length == 0) { cells = new CPos[] { target.CenterLocation.ToCPos() } } ; return(Util.ExpandFootprint(cells, true)); }
public static IEnumerable <CPos> AdjacentCells(Target target) { var cells = target.Positions.Select(p => p.ToCPos()).Distinct(); return(Util.ExpandFootprint(cells, true)); }