Class PathNode

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private Location location
      The location this node refers to.
      private int movesLeft
      The number of moves left at this node for the unit traversing this path.
      PathNode next
      The next node in the path.
      private boolean onCarrier
      Whether the unit traversing this path is on a carrier at this node.
      PathNode previous
      The previous node in the path.
      private static int TURN_FACTOR
      Weight turns much greater than moves.
      private int turns
      The number of turns used to get to this node by the unit traversing the path.
    • Constructor Summary

      Constructors 
      Constructor Description
      PathNode​(Location location, int movesLeft, int turns, boolean onCarrier, PathNode previous, PathNode next)
      Creates a new PathNode.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addTurns​(int turns)
      Adds turns to the turns on this path.
      void convertToGoodsDeliveryPath()
      Convert this path to a delivery path for some goods, where every node is marked as on carrier, except for a duplicate of the last node.
      boolean embarkedThisTurn​(int turns)
      Does this path include a non-carrier move within a given turn?
      void ensureDisembark()
      Ensure the last node of this path is no longer on the carrier.
      java.lang.String fullPathToString()
      Another debug helper.
      PathNode getCarrierMove()
      Gets the next carrier move on this path.
      int getCost()
      Gets the cost of moving to this PathNode.
      Direction getDirection()
      Gets the direction to move in order to get to this path node.
      PathNode getFirstNode()
      Gets the first node of this path.
      PathNode getLastNode()
      Gets the last node of this path.
      int getLength()
      Get the length of the path.
      Location getLocation()
      Gets the location of this path.
      int getMovesLeft()
      Gets the number of moves remaining at this point in the path.
      static int getNodeCost​(int turns, int movesLeft)
      Standard function to get the cost of moving to a PathNode.
      Tile getTile()
      Gets the Tile of this PathNode.
      int getTotalTurns()
      Gets the number of turns it will take to move the entire path, from the starting PathNode until the end.
      PathNode getTransportDropNode()
      Gets the node where the unit using this path should leave its transport.
      int getTransportDropTurns()
      Gets the number of turns it takes to reach the transport node.
      int getTurns()
      Gets the number of turns it will take to reach this PathNode's Tile in the path.
      boolean isOnCarrier()
      Checks if the unit using this path is still onboard its transport.
      void setMovesLeft​(int movesLeft)
      Sets the number of moves remaining at this point in the path.
      void setOnCarrier​(boolean onCarrier)
      Sets if the unit using this path is still onboard its transport.
      void setTurns​(int turns)
      Sets the number of turns it will take to reach this PathNode's Tile in the path.
      java.lang.String toString()
      boolean usesCarrier()
      Does this path us a carrier at any point?
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • TURN_FACTOR

        private static final int TURN_FACTOR
        Weight turns much greater than moves.
        See Also:
        Constant Field Values
      • location

        private final Location location
        The location this node refers to. Usually a Tile.
      • movesLeft

        private int movesLeft
        The number of moves left at this node for the unit traversing this path.
      • turns

        private int turns
        The number of turns used to get to this node by the unit traversing the path.
      • onCarrier

        private boolean onCarrier
        Whether the unit traversing this path is on a carrier at this node.
      • next

        public PathNode next
        The next node in the path.
      • previous

        public PathNode previous
        The previous node in the path.
    • Constructor Detail

      • PathNode

        public PathNode​(Location location,
                        int movesLeft,
                        int turns,
                        boolean onCarrier,
                        PathNode previous,
                        PathNode next)
        Creates a new PathNode.
        Parameters:
        location - The Location this PathNode represents in the path.
        movesLeft - The number of moves remaining at this point in the path.
        turns - The number of turns it takes to reach this PathNode's Tile from the start of the path.
        onCarrier - Whether the path is still using a carrier.
        previous - The previous PathNode in the path.
        next - The next PathNode in the path.
    • Method Detail

      • getLocation

        public Location getLocation()
        Gets the location of this path.
        Returns:
        The Location.
      • getTile

        public Tile getTile()
        Gets the Tile of this PathNode.
        Returns:
        The Tile this PathNode represents in the path, if any.
      • getMovesLeft

        public int getMovesLeft()
        Gets the number of moves remaining at this point in the path.
        Returns:
        The number of moves remaining. -1 is returned if the number of moves left has not been calculated.
      • setMovesLeft

        public void setMovesLeft​(int movesLeft)
        Sets the number of moves remaining at this point in the path.
        Parameters:
        movesLeft - The number of moves remaining.
      • getTurns

        public int getTurns()
        Gets the number of turns it will take to reach this PathNode's Tile in the path.
        Returns:
        The number of turns, using zero for the first move. -1 is returned if the number of turns has not been calculated.
      • setTurns

        public void setTurns​(int turns)
        Sets the number of turns it will take to reach this PathNode's Tile in the path.
        Parameters:
        turns - The new number of turns.
      • addTurns

        public void addTurns​(int turns)
        Adds turns to the turns on this path.
        Parameters:
        turns - The number of turns to add.
      • isOnCarrier

        public boolean isOnCarrier()
        Checks if the unit using this path is still onboard its transport.
        Returns:
        true if the unit is still onboard a carrier when using this path.
        See Also:
        getTransportDropTurns()
      • setOnCarrier

        public void setOnCarrier​(boolean onCarrier)
        Sets if the unit using this path is still onboard its transport.
        Parameters:
        onCarrier - Should be set to true in order to indicate that the unit using this path is still onboard the carrier on this path node.
        See Also:
        getTransportDropTurns()
      • getLength

        public int getLength()
        Get the length of the path.
        Returns:
        The number of nodes in the path.
      • getDirection

        public Direction getDirection()
        Gets the direction to move in order to get to this path node.
        Returns:
        The direction to move on the map in order to get to the Tile returned by this PathNode's getTile(), or null if there is no previous node or either this or the previous node location is not on the map.
      • getTransportDropNode

        public PathNode getTransportDropNode()
        Gets the node where the unit using this path should leave its transport.
        Returns:
        The node where the unit leaves the carrier.
      • getFirstNode

        public PathNode getFirstNode()
        Gets the first node of this path.
        Returns:
        The first PathNode.
      • getLastNode

        public PathNode getLastNode()
        Gets the last node of this path.
        Returns:
        The last PathNode.
      • getTotalTurns

        public int getTotalTurns()
        Gets the number of turns it will take to move the entire path, from the starting PathNode until the end.
        Returns:
        The number of turns, using zero for the first move.
      • getTransportDropTurns

        public int getTransportDropTurns()
        Gets the number of turns it takes to reach the transport node.
        Returns:
        The number of turns in takes to get to the node where the unit using this path should leave it's transport.
      • getNodeCost

        public static int getNodeCost​(int turns,
                                      int movesLeft)
        Standard function to get the cost of moving to a PathNode. Static version provided for path calculation comparisons. Some care is taken to avoid overflow as test paths with infinite moves are created in the path planning process.
        Parameters:
        turns - The number of turns taken.
        movesLeft - The number of moves left for the moving unit.
        Returns:
        The cost of moving to a PathNode.
      • getCost

        public int getCost()
        Gets the cost of moving to this PathNode.
        Returns:
        The cost of moving to this PathNode.
      • getCarrierMove

        public PathNode getCarrierMove()
        Gets the next carrier move on this path.
        Returns:
        The first node along the path which is a carrier move, or null if the path does not use a carrier.
      • usesCarrier

        public boolean usesCarrier()
        Does this path us a carrier at any point?
        Returns:
        True if there is an onCarrier move in this path.
      • embarkedThisTurn

        public boolean embarkedThisTurn​(int turns)
        Does this path include a non-carrier move within a given turn?
        Parameters:
        turns - Paths with fewer turns than this are previous turns.
        Returns:
        True if there was a non-carrier move in the last turn.
      • convertToGoodsDeliveryPath

        public void convertToGoodsDeliveryPath()
        Convert this path to a delivery path for some goods, where every node is marked as on carrier, except for a duplicate of the last node.
      • ensureDisembark

        public void ensureDisembark()
        Ensure the last node of this path is no longer on the carrier.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • fullPathToString

        public java.lang.String fullPathToString()
        Another debug helper.
        Returns:
        A string describing the whole path.