net.sf.freecol.common.model
Class PathNode

java.lang.Object
  extended by net.sf.freecol.common.model.PathNode
All Implemented Interfaces:
java.lang.Comparable<PathNode>

public class PathNode
extends java.lang.Object
implements java.lang.Comparable<PathNode>

Represents a single Tile in a path.

You will most likely be using: next, getDirection(), getTile() and getTotalTurns(), when evaluating/following a path.


Field Summary
 PathNode next
          The next node in the path.
 PathNode previous
          The previous node in the path.
 
Constructor Summary
PathNode(Tile tile, int cost, int f, Map.Direction direction, int movesLeft, int turns)
          Creates a new PathNode.
 
Method Summary
 int compareTo(PathNode o)
          Compares this PathNode's f with the f of the given object.
 boolean equals(java.lang.Object o)
          Checks if this PathNode is equal to another object.
 int getCost()
          Returns the cost of moving to this PathNode's tile.
 Map.Direction getDirection()
          Returns the direction to move in order to get closer towards the goal.
 int getF()
          Returns the estimated cost of the path at this stage.
 PathNode getLastNode()
          Returns the last node of this path.
 int getMovesLeft()
          Returns the number of moves remaining at this point in the path.
 Tile getTile()
          Gets the Tile of this PathNode.
 int getTotalTurns()
          Returns the number of turns it will take to move the entire path, from the starting PathNode until the end.
 PathNode getTransportDropNode()
          Returns the node where the unit using this path should leave it's transport.
 int getTransportDropTurns()
          Returns the number of turns it takes to reach the transport node.
 int getTurns()
          Returns the number of turns it will take to reach this PathNode's Tile in the path.
 int hashCode()
          Returns the hashCode of this object.
 boolean isOnCarrier()
          Checks if the unit using this path is still onboard it's 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 it's transport.
 java.lang.String toString()
          Debug helper.
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

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(Tile tile,
                int cost,
                int f,
                Map.Direction direction,
                int movesLeft,
                int turns)
Creates a new PathNode.

Parameters:
tile - The Tile this PathNode represents in the path.
cost - The cost of moving to this PathNode's Tile, given in move points.
f - This is cost + heuristics. The latter one is an estimate for the cost from this tile and to the goal.
direction - The direction to move on the map in order to get to the next Tile 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.
Method Detail

getCost

public int getCost()
Returns the cost of moving to this PathNode's tile.

Returns:
The cost of moving to this PathNode's Tile, given in move points.

getTile

public Tile getTile()
Gets the Tile of this PathNode.

That is; the Tile you reach if you move in the direction given by getDirection() from the previous tile. Explained by code:

map.getNeighbourOrNull(getDirection(), previous.getTile()) == getTile()

Returns:
The Tile this PathNode represents in the path.

isOnCarrier

public boolean isOnCarrier()
Checks if the unit using this path is still onboard it's 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 it's 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()

getTransportDropTurns

public int getTransportDropTurns()
Returns 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.

getTransportDropNode

public PathNode getTransportDropNode()
Returns the node where the unit using this path should leave it's transport.

Returns:
The node where the unit leaves it's carrier.

getLastNode

public PathNode getLastNode()
Returns the last node of this path.

Returns:
The last PathNode.

getF

public int getF()
Returns the estimated cost of the path at this stage.

Returns:
The cost + heuristics. The latter one is an estimate for the cost from this tile and to the goal.

getDirection

public Map.Direction getDirection()
Returns the direction to move in order to get closer towards the goal.

Returns:
The direction to move on the map in order to get to the Tile returned by this PathNode's getTile() in the path.

getTurns

public int getTurns()
Returns 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.

getTotalTurns

public int getTotalTurns()
Returns 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.

getMovesLeft

public int getMovesLeft()
Returns 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.

compareTo

public int compareTo(PathNode o)
Compares this PathNode's f with the f of the given object.

Note: this class has a natural ordering that is inconsistent with equals.

Specified by:
compareTo in interface java.lang.Comparable<PathNode>
Parameters:
o - the object to be compared.
Returns:
a negative integer, zero or a positive integer as this object is less than, equal to, or greater than the specified object.
Throws:
java.lang.ClassCastException - if the given object is not a PathNode.

equals

public boolean equals(java.lang.Object o)
Checks if this PathNode is equal to another object.

Overrides:
equals in class java.lang.Object
Parameters:
o - The Object to compare with.
Returns:
true if the given object is a PathNode with the same tile as this one.

hashCode

public int hashCode()
Returns the hashCode of this object.

Overrides:
hashCode in class java.lang.Object

toString

public java.lang.String toString()
Debug helper.

Overrides:
toString in class java.lang.Object