public override void Enter() { var pathFinder = new AStarFinder(Heuristic.Manhattan, npc.IsWalkable); pathFinder.FindPathAsync(npc.CurrentPosition, npc.HomePosition).ContinueWith(t => { var path = t.Result; if (path == null) { WriteLog("Path not found! (" + npc.CurrentPosition + " => " + npc.HomePosition + ")"); var f = new AStarFinder(Heuristic.Manhattan, (x, y) => true); path = f.FindPath(npc.CurrentPosition, npc.HomePosition); if (path == null) { WriteLog("Safe path not found! (" + npc.CurrentPosition + " => " + npc.HomePosition + ")"); } } _movement = new PathMovement(path); _movement.Start(npc); }); base.Enter(); }
//function that determines which loads are valid to keep and which are not private void KeepValidLoads(GridPos EndPoint) { int list_index = 0; bool removed; for (int i = 0; i < loadPos.Count; i++) { searchGrid.SetWalkableAt(loadPos[i], true); //assumes that all loads are walkable } //and only walls are in fact the only obstacles in the grid do { removed = false; jumpParam.Reset(loadPos[list_index], EndPoint); //tries to find path between each Load and the exit if (AStarFinder.FindPath(jumpParam, nud_weight.Value).Count == 0) //if no path is found { isLoad[loadPos[list_index].x, loadPos[list_index].y] = 2; //mark the corresponding load as NOT available loadPos.RemoveAt(list_index); //remove that load from the list removed = true; } if (!removed) { list_index++; } } while (list_index < loadPos.Count); //loop repeats untill all loads are checked if (loadPos.Count == 0) { mapHasLoads = false; } }