private void doTheAStar(Tile selected) { AStar astar = new AStar(); astar.FindPath(firstTile, selected, map); movement = astar.CellsFromPath(); movement.Remove(firstTile); RedrawLine(); }
public List <Vector3> FindPath(Vector3 origin, Vector3 goal) { //CreateBoard (); AStar pathFinder = new AStar(); pathFinder.FindPath(origin, goal, board, false); return(pathFinder.CellsFromPath()); }
public void HandleJob() { if (job != null) { if (job.gameObject.tag.Equals("Terrain")) { heading = job.GetComponent<Cell>(); //Debug.LogWarning("Handling Job: " + job.tag); } if (job.gameObject.tag.Equals("Harvestable")) { Debug.LogWarning("I have a new job"); AStar pathFinder = new AStar(); pathFinder.FindPath(cell, job.gameObject.GetComponent<Cell>(), cell.GetComponentInParent<Board>().board, false); List<Cell> path = pathFinder.CellsFromPath(); Debug.Log("Found path to harvestable : " + path.Count); switch(path.Count) { case 0: heading = cell; job = null; Debug.LogWarning("Job aborted impossible to reach"); break; case 1: board.RemoveCell(job.gameObject.GetComponent<Cell>()); heading = cell; job = null; Debug.LogWarning("Job complete"); break; default: heading = path[path.Count - 1]; break; } } } }
protected List<Cell> FindPath(Cell origin, Cell goal) { AStar pathFinder = new AStar(); pathFinder.FindPath(origin, goal, board, false); return pathFinder.CellsFromPath(); }
public void Move() { foreach(Transform pathingline in pathinglines) { Destroy(pathingline.gameObject); } pathinglines.Clear(); if (heading != null) { if (cell != heading) { AStar pathFinder = new AStar(); pathFinder.FindPath(cell, heading, cell.GetComponentInParent<Board>().board, false); List<Cell> path = pathFinder.CellsFromPath(); if (path.Count > 0) { pendingmove = path[0]; } else { Debug.LogWarning("Target location is unreachable"); // IF this is our job clear it if (job != null) { if (job.GetComponent<Cell>().Equals(heading)) { job = null; } } heading = cell; } } } if (pendingmove != null) { if (cell != pendingmove) { Debug.LogWarning("Pending move didn't match position"); cell = pendingmove; if (job != null) { if (job.GetComponent<Cell>().Equals(pendingmove)) { job = null; } } } } }
public List<GridPosition> FindPath(GridPosition origin, GridPosition goal) { AStar pathFinder = new AStar(); pathFinder.FindPath(origin, goal, points, true); return pathFinder.CellsFromPath(); }