public void Execute(SmartFarmer i) { i.lastSpotted = EntityManager.Instance.GetPlayer().Position; i.FollowingPath = false; Vector2 force = i.Seek(i.lastSpotted); if (!AStarGame.ApproximatelyZero(force)) i.Velocity += force; else i.Velocity = Vector2.Zero; }
public void Execute(SmartFarmer i) { if (!i.doneSearching) { bool reachedBush = AStarGame.ApproximatelyEqual(i.Position, bushes[nextBush]); if (reachedBush) { nextBush++; i.FollowingPath = false; if (nextBush >= bushes.Count) { i.doneSearching = true; return; } } if (!i.FollowingPath) { if (!AStarGame.GameMap.WallsBetween(i.Position, bushes[nextBush])) { Vector2 force = i.Seek(bushes[nextBush]); i.Velocity += force; } else { bushSearch = new AStarSearch( AStarGame.GameMap.NavigationGraph, AStarGame.GameMap.ClosestNodeIndex(i.Position), AStarGame.GameMap.ClosestNodeIndex(bushes[nextBush]), AStarHeuristics.Distance); bushSearch.PathToTarget(out bushSearchNodes); bushSearchPos = AStarGame.GameMap.getWorldfromNodes(bushSearchNodes); i.FollowPath(bushSearchPos, false); } } } }