private List <Vector2Int> moveTowardsPosition(Vector2Int pos) { MoveMap <GameObject> mm = master.staticMap; int w = mm.getWidth(); int h = mm.getHeight(); Location[,] walkMap = new Location[w, h]; transposeMoveMapOntoWalkMap(ref mm, ref walkMap); transposeMoveMapOntoWalkMap(ref master.entityMap, ref walkMap); List <Location> nextToCheck = new List <Location>(); Location start = new Location(position); start.state = Location.State.Closed; nextToCheck.Add(start); nextToCheck.AddRange(getAdjacentWalkable(ref walkMap, ref start, pos)); nextToCheck.Sort((loc1, loc2) => loc1.f.CompareTo(loc2.f)); for (int i = 0; i < nextToCheck.Count; i++) { Location loc = nextToCheck[i]; if (loc.point == pos) { //TODO THIS RETURN ISN'T RETURNING A WHOLE LIST List <Vector2Int> path = new List <Vector2Int>(); Location curr = loc; while (curr.prev != null) { path.Add(curr.point); curr = curr.prev; } path.Reverse(); return(path); } else { if (search(ref walkMap, ref loc, pos)) { //TODO THIS RETURN ISN'T RETURNING A WHOLE LIST List <Vector2Int> path = new List <Vector2Int>(); Location curr = loc; while (curr.prev != null) { path.Add(curr.point); curr = curr.prev; } path.Reverse(); return(path); } } } return(null); }
private void transposeMoveMapOntoWalkMap(ref MoveMap <GameObject> mm, ref Location[,] walkMap) { for (int x = 0; x < mm.getWidth(); x++) { for (int y = 0; y < mm.getHeight(); y++) { if (mm[x, y] != null) { if (walkMap[x, y] == null) { walkMap[x, y] = new Location(x, y); } walkMap[x, y].state = Location.State.Closed; } } } }