Package net.sf.freecol.common.model
Class PathNode
- java.lang.Object
-
- net.sf.freecol.common.model.PathNode
-
public class PathNode extends java.lang.ObjectRepresents a singleLocationin a path. You will most likely be using:next,getDirection(),getTile()andgetTotalTurns(), when evaluating/following a path.
-
-
Field Summary
Fields Modifier and Type Field Description private LocationlocationThe location this node refers to.private intmovesLeftThe number of moves left at this node for the unit traversing this path.PathNodenextThe next node in the path.private booleanonCarrierWhether the unit traversing this path is on a carrier at this node.PathNodepreviousThe previous node in the path.private static intTURN_FACTORWeight turns much greater than moves.private intturnsThe number of turns used to get to this node by the unit traversing the path.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddTurns(int turns)Adds turns to the turns on this path.voidconvertToGoodsDeliveryPath()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.booleanembarkedThisTurn(int turns)Does this path include a non-carrier move within a given turn?voidensureDisembark()Ensure the last node of this path is no longer on the carrier.java.lang.StringfullPathToString()Another debug helper.PathNodegetCarrierMove()Gets the next carrier move on this path.intgetCost()Gets the cost of moving to thisPathNode.DirectiongetDirection()Gets the direction to move in order to get to this path node.PathNodegetFirstNode()Gets the first node of this path.PathNodegetLastNode()Gets the last node of this path.intgetLength()Get the length of the path.LocationgetLocation()Gets the location of this path.intgetMovesLeft()Gets the number of moves remaining at this point in the path.static intgetNodeCost(int turns, int movesLeft)Standard function to get the cost of moving to aPathNode.TilegetTile()Gets theTileof thisPathNode.intgetTotalTurns()Gets the number of turns it will take to move the entire path, from the startingPathNodeuntil the end.PathNodegetTransportDropNode()Gets the node where the unit using this path should leave its transport.intgetTransportDropTurns()Gets the number of turns it takes to reach thetransport node.intgetTurns()Gets the number of turns it will take to reach thisPathNode'sTilein the path.booleanisOnCarrier()Checks if the unit using this path is still onboard its transport.voidsetMovesLeft(int movesLeft)Sets the number of moves remaining at this point in the path.voidsetOnCarrier(boolean onCarrier)Sets if the unit using this path is still onboard its transport.voidsetTurns(int turns)Sets the number of turns it will take to reach thisPathNode'sTilein the path.java.lang.StringtoString()booleanusesCarrier()Does this path us a carrier at any point?
-
-
-
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 newPathNode.- Parameters:
location- TheLocationthisPathNoderepresents in the path.movesLeft- The number of moves remaining at this point in the path.turns- The number of turns it takes to reach thisPathNode'sTilefrom the start of the path.onCarrier- Whether the path is still using a carrier.previous- The previousPathNodein the path.next- The nextPathNodein the path.
-
-
Method Detail
-
getLocation
public Location getLocation()
Gets the location of this path.- Returns:
- The
Location.
-
getTile
public Tile getTile()
Gets theTileof thisPathNode.- Returns:
- The
TilethisPathNoderepresents 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.
-1is 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 thisPathNode'sTilein the path.- Returns:
- The number of turns, using zero for the first
move.
-1is 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 thisPathNode'sTilein 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:
trueif 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 totruein 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
Tilereturned by thisPathNode'sgetTile(), 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 startingPathNodeuntil 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 thetransport 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 aPathNode. 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 thisPathNode.- 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:
toStringin classjava.lang.Object
-
fullPathToString
public java.lang.String fullPathToString()
Another debug helper.- Returns:
- A string describing the whole path.
-
-