public static void MoveFarthestAndAttack(Droid attacker, BitArray targets) { if (attacker.AttacksLeft == 0) { return; } var liveTargets = targets.ToPoints().Where(p => Bb.DroidLookup[p].HealthLeft > 0); Func<Point, bool> patherPassable = p => IsPassable(p) || p.Equals(attacker.ToPoint()); var movementSearch = new Pather.Search(new Point[] { attacker.ToPoint() }, patherPassable, p => false, (p1, p2) => 1, attacker.MovementLeft); var walkables = movementSearch.GScore.Keys.Where(p => movementSearch.GScore[p] <= attacker.MovementLeft); var walkablesWithTargets = walkables.Where(p => liveTargets.Any(t => p.IsInRange(attacker.Range, t))); Console.WriteLine("MoveFarthestAndAttack " + attacker.ToPoint()); Console.WriteLine("Walkables: " + walkables.Count()); Console.WriteLine("WalkablesWithTargets: " + walkablesWithTargets.Count()); if (walkablesWithTargets.Any()) { var walkTo = walkablesWithTargets.MaxBy(p => movementSearch.GScore[p]); var path = Pather.ConstructPath(movementSearch.CameFrom, walkTo); foreach (var step in path.Skip(1)) { Console.WriteLine("Move {0} -> {1}", attacker.ToPoint(), step); attacker.move(step.x, step.y); } var target = liveTargets.First(t => attacker.IsInRange(t)); attacker.operate(target.x, target.y); } }
public static void MoveAndAttack(Droid droid, IEnumerable<Point> path) { var targetPoint = path.Last(); foreach (var point in path) { if (droid.MovementLeft == 0 || droid.IsInRange(targetPoint)) { break; } droid.move(point.x, point.y); } if (droid.IsInRange(targetPoint)) { droid.operate(targetPoint.x, targetPoint.y); var target = Bb.DroidLookup[targetPoint]; if ((Unit)target.Variant == Unit.HANGAR && target.HealthLeft <= 0) { Bb.KillHangerCountDown = 0; // Todo, release the kittens } } }