Class LocalPathFinder


  • public class LocalPathFinder
    extends PathFinder<Tile>
    The local pathfinder used for navigating within the local region

    This class generally doesn't need to be used if you're just trying to walk, see Walking.walk(Tile) instead

    For global pathfinding across regions, see WebFinder instead

    • Field Detail

      • sleepBetween

        public static int sleepBetween
    • Method Detail

      • getLocalPathFinder

        public static @NonNull LocalPathFinder getLocalPathFinder()
      • calculate

        public @Nullable LocalPath<Tile> calculate​(@NonNull Tile start,
                                                   @NonNull Tile end)
        Calculates and returns a valid path from the start tile to the end tile.

        If you're trying to walk somewhere, you'll generally not need to use this class or method directly, see Walking.walk(Tile) instead.

        Example usage:

         
         LocalPath path = LocalPathFinder.getLocalPathFinder().calculate(Players.getLocal().getTile(), new Tile(1234, 2345, 1));
        
         if (path != null && !path.isEmpty()) {
             Logger.log("We found a path: " + path);
             path.walk();
         } else {
             Logger.warn("No path found!");
         }
         
         
        Overrides:
        calculate in class PathFinder<Tile>
        Parameters:
        start - Start tile
        end - End tile
        Returns:
        null if either the start or end tiles are null, empty if we can't find a path, or the full path if it's valid
      • calculate

        public @NonNull LocalPath<Tile> calculate​(int sx,
                                                  int sy,
                                                  int tx,
                                                  int ty)
        Description copied from class: PathFinder
        Calculate a walkable abstract path from the start tile location (sx, sy) to the destination tile location (dx, dy), using data provided by the tile map. Assumes z coordinate is 0
        Overrides:
        calculate in class PathFinder<Tile>
        Parameters:
        sx - the starting grid X coordinate.
        sy - the starting grid Y coordinate.
        tx - the destination grid X coordinate.
        ty - the destination grid Y coordinate.
        Returns:
        the abstract path from the start to destination if a path is found, if unable to find path it will return null.
      • calculate

        public @NonNull LocalPath<Tile> calculate​(int sx,
                                                  int sy,
                                                  int sz,
                                                  int ex,
                                                  int ey,
                                                  int ez)
        Description copied from class: PathFinder
        Calculates an AbstractPath from the start location (x1,y1,z1) to the destination tile location (x2,y2,z2)
        Specified by:
        calculate in class PathFinder<Tile>
        Parameters:
        sx - the starting grid X coordinate.
        sy - the starting grid Y coordinate.
        sz - the starting grid Z coordinate.
        ex - the destination grid X coordinate.
        ey - the destination grid Y coordinate.
        ez - the destination grid Z coordinate
        Returns:
        AbstractPath
      • getOpen

        @Deprecated
        public static @NonNull java.util.List<PathNode> getOpen()
        Deprecated.
      • getClosed

        @Deprecated
        public static @NonNull java.util.List<PathNode> getClosed()
        Deprecated.
      • calculate

        public @NonNull LocalPath<Tile> calculate​(int sx,
                                                  int sy,
                                                  int tx,
                                                  int ty,
                                                  int z)
        Description copied from class: PathFinder
        Calculate a walkable abstract path from the start tile location (x1, y1,z) to the destination tile location (x2, y2,z), using data provided by the tile map.
        Overrides:
        calculate in class PathFinder<Tile>
        Parameters:
        sx - the starting grid X coordinate.
        sy - the starting grid Y coordinate.
        tx - the destination grid X coordinate.
        ty - the destination grid Y coordinate.
        z - the z coordinate
        Returns:
        the abstract path from the start to destination if a path is found, if unable to find path it will return null.
      • getCurrentDepth

        public int getCurrentDepth()
      • setCurrentDepth

        public void setCurrentDepth​(int currentDepth)
      • getHeuristicCost

        public float getHeuristicCost​(int x,
                                      int y,
                                      int tx,
                                      int ty)
        Get the heuristic cost for the given location. This determines in which order the locations are processed.
        Parameters:
        x - The x coordinate of the tile whose cost is being determined
        y - The y coordinate of the tile whose cost is being determined
        tx - The x coordinate of the target location
        ty - The y coordinate of the target location
        Returns:
        The heuristic cost assigned to the tile
      • getHeuristicCost

        public float getHeuristicCost​(int x,
                                      int y,
                                      int z,
                                      int tx,
                                      int ty,
                                      int tz)
      • getWalkingDistance

        public double getWalkingDistance​(@NonNull Tile startTile,
                                         @NonNull Tile endTile)
        Walking distance based on path finding between the provided tiles.
        Parameters:
        startTile - the start tile.
        endTile - the destination tile.
        Returns:
        return the path distance movement cost from the given tile as a double. If there isn't a path to the tile, it will return 3 times the crow flies distance. If either tile is null, it will return -1.