Class FixedPath

java.lang.Object
games.stendhal.server.core.pathfinder.FixedPath

public class FixedPath extends Object
A path using a fixed route.
  • Field Details

    • currentGoal

      protected Node currentGoal
      The current goal node.
    • loop

      protected boolean loop
      Whether to loop the path.
    • nodes

      protected List<Node> nodes
      The path nodes.
    • pos

      protected int pos
      The current position.
    • suspensions

      protected Map<Integer,​Pair<Integer,​Direction>> suspensions
      Positions in the entity's path where it will suspend for a determined amount of turns.
  • Constructor Details

    • FixedPath

      public FixedPath(List<Node> nodes, boolean loop)
      Create a fixed path from a list. NOTE: The list is not copied, and should not be modified afterward.
      Parameters:
      nodes - A list of nodes to follow.
      loop - Whether the path should loop.
  • Method Details

    • getCurrentGoal

      public Node getCurrentGoal()
      Get the current goal.
      Returns:
      The current goal to reach, or null.
    • getNodeList

      public List<Node> getNodeList()
      Get the list of nodes that make up the path. NOTE: The list is not copied, and should not be modified.
      Returns:
      The node list.
    • getNodes

      public Node[] getNodes()
      Get the array of nodes that make up the path.
      Returns:
      The nodes.
    • isLoop

      public boolean isLoop()
      Determine if the path is an infinite loop.
      Returns:
      true if the path loops when the last point is reached.
    • follow

      public boolean follow(ActiveEntity entity)
      Follow this path. This will face the entity into the proper direction to reach it's next path goal.
      Parameters:
      entity - The entity to direct along the path.
      Returns:
      true if something to follow, false if complete.
    • getDestination

      public Node getDestination()
      Get the final destination point.
      Returns:
      The destination node, or null if there is none (i.e. no path, or unbound/infinite movement).
    • isFinished

      public boolean isFinished()
      Determine if the path has finished.
      Returns:
      true if there is no more path to follow.
    • addSuspend

      public void addSuspend(int duration, Direction dir, int... pos)
      Add a suspension to the entity's path.
      Parameters:
      duration - Amount of time (in turns) the entity will be suspended.
      dir - Direction to face while suspended, or null if direction should not be changed.
      pos - The position(s) in the path where to add the suspension.
    • addSuspend

      public void addSuspend(int duration, int... pos)
      Add a suspension to the entity's path.
      Parameters:
      duration - Amount of time (in turns) the entity will be suspended.
      pos - The position(s) in the path where to add the suspension.
    • removeSuspend

      public void removeSuspend(int... pos)
      Removes suspension value from path position.
      Parameters:
      pos - The position(s) in the path from where to remove the suspension.
    • suspendAt

      public boolean suspendAt(int pos)
      Checks if the entity should be suspended at the given path position.
      Parameters:
      pos - Path position to check.
      Returns:
      true if the entity should suspend.
    • getSuspendValue

      public Integer getSuspendValue(int pos)
      Retrieves the duration of the suspension of the given path position.
      Parameters:
      pos - Path position to check.
      Returns:
      Duration (in turns) the entity should suspend or null.
    • getSuspendDirection

      public Direction getSuspendDirection(int pos)
      Retrieves the direction the entity should face while suspended.
      Parameters:
      pos - Path position to check.
      Returns:
      Direction to face or null.
    • toString

      public String toString()
      Get the string representation.
      Overrides:
      toString in class Object
      Returns:
      The string representation.