net.sf.freecol.common.model
Class Tile

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.model.FreeColGameObject
          extended by net.sf.freecol.common.model.UnitLocation
              extended by net.sf.freecol.common.model.Tile
All Implemented Interfaces:
Location, Named, Ownable

public final class Tile
extends UnitLocation
implements Named, Ownable

Represents a single tile on the Map.

See Also:
Map

Nested Class Summary
 
Nested classes/interfaces inherited from class net.sf.freecol.common.model.UnitLocation
UnitLocation.NoAddReason
 
Field Summary
private  boolean connected
          Whether this tile is connected to Europe.
private static java.util.logging.Logger logger
           
private  java.lang.Boolean moveToEurope
          Does this tile have an explicit moveToEurope state.
static int NEAR_RADIUS
          The maximum distance that will still be considered "near" when determining the location name.
private  Player owner
          The player that consider this tile to be their land.
private  Settlement owningSettlement
          Indicates which colony or Indian settlement that owns this tile ('null' indicates no owner).
private  java.util.Map<Player,PlayerExploredTile> playerExploredTiles
          Stores each player's image of this tile.
private  Region region
          Describe region here.
private  Settlement settlement
          A pointer to the settlement located on this tile or 'null' if there is no settlement on this tile.
private  int style
          The style of this Tile, as determined by adjacent tiles.
private  TileItemContainer tileItemContainer
          Stores all Improvements and Resources (if any)
private  TileType type
           
static java.lang.String UNIT_CHANGE
           
private  int x
           
private  int y
           
 
Fields inherited from class net.sf.freecol.common.model.FreeColGameObject
UNITS_TAG_NAME
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, INFINITY, NO_ID, PARTIAL_ATTRIBUTE, UNDEFINED, VALUE_TAG
 
Constructor Summary
Tile(Game game, java.lang.String id)
          Initiates a new Tile with the given ID.
Tile(Game game, TileType type, int locX, int locY)
          A constructor to use.
Tile(Game game, javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
 
Method Summary
 boolean add(Locatable locatable)
          Adds a Locatable to this Location.
 void addLostCityRumour(LostCityRumour rumour)
          Adds a lost city rumour to this tile.
 void addResource(Resource resource)
          Adds a Resource to this Tile.
private  void addTileItem(TileItem item)
          Adds a tile item to this tile.
 boolean canAdd(Locatable locatable)
          Checks whether or not the specified locatable may be added to this Location.
 boolean canGetRoad()
          Checks whether this Tile can have a road or not.
 boolean canMoveToEurope()
          Can a unit move to Europe from this tile?
 void changeOwnership(Player player, Settlement settlement)
          Change the tile ownership.
 void changeOwningSettlement(Settlement settlement)
          Changes the owning settlement for this tile.
 boolean contains(Locatable locatable)
          Checks if this Tile contains the specified Locatable.
 void dispose()
          Dispose of this UnitLocation.
 void disposeScratchTile()
          Special handling on dispose to avoid mutating the shared fields.
 Resource expendResource(GoodsType goodsType, UnitType unitType, Settlement settlement)
          This method is called only when a new turn is beginning.
 TileImprovement findTileImprovementType(TileImprovementType type)
          Finds the TileImprovement of a given Type, or null if there is no match.
 void fixup09x()
          Fixes visible pets where there is a settlement present but the tile is not owned correctly as ownership was not implemented in 0.9.x.
 Tile getAdjacentTile(Map.Direction direction)
          Gets the position adjacent Tile to a given Tile, in a given direction.
 Colony getColony()
          Gets the Colony located on this Tile.
 java.util.List<TileImprovement> getCompletedTileImprovements()
          Returns a List of completed TileImprovements.
 Unit getDefendingUnit(Unit attacker)
          Gets the Unit that is currently defending this Tile.
 Map.Direction getDirection(Tile tile)
          Gets the direction to a neighbouring tile from this one.
 Region getDiscoverableRegion()
          Return the discoverable Region of this Tile, or null if there is none.
 int getDistanceTo(Tile tile)
          Gets the distance in tiles between this Tile and the specified one.
 Unit getFirstUnit()
          Gets the first Unit on this tile.
 IndianSettlement getIndianSettlement()
          Gets the IndianSettlement located on this Tile.
 StringTemplate getLabel()
          Returns a description of the Tile, with the name of the tile and any improvements on it (road/plow/etc) from TileItemContainer.
 Unit getLastUnit()
          Gets the last Unit on this tile.
 StringTemplate getLocationName()
          Returns the name of this location.
 StringTemplate getLocationNameFor(Player player)
          Returns the name of this location for a particular player.
 LostCityRumour getLostCityRumour()
          Gets the lost city rumour on this Tile if any.
 Map getMap()
          Gets the Map in which this Tile belongs.
 int getMaximumPotential(GoodsType goodsType, UnitType unitType)
          Gets the maximum potential for producing the given type of goods.
 Unit getMovableUnit()
          Gets a Unit that can become active.
 java.lang.Boolean getMoveToEurope()
          Get the move-to-Europe state of the tile.
 java.lang.String getNameKey()
          Gets the name of this tile, or shows "unexplored" if not explored by player.
 Settlement getNearestSettlement(Player owner, int radius)
          Finds the nearest settlement to this tile.
 Tile getNeighbourOrNull(Map.Direction direction)
          Returns the neighbouring Tile of the given Tile in the given direction.
 Unit getOccupyingUnit()
          Returns the unit who is occupying the tile
 Player getOwner()
          The nation that consider this tile to be their property.
 Settlement getOwningSettlement()
          Gets the owning settlement for this tile.
 PlayerExploredTile getPlayerExploredTile(Player player)
          Gets the PlayerExploredTile for the given Player.
 Map.Position getPosition()
          Gets the Position of this Tile.
 java.util.Set<Modifier> getProductionBonus(GoodsType goodsType, UnitType unitType)
          Describe getProductionBonus method here.
 Region getRegion()
          Get the Region value.
 TileImprovement getRiver()
          Returns the river on this Tile if any
 int getRiverStyle()
          Returns the style of a river TileImprovement on this Tile.
 TileImprovement getRoad()
          Returns the road on this tile, if there is one, and null otherwise.
 Tile getSafeTile(Player player, java.util.Random random)
          Finds a safe tile to put a unit on, near to this one.
 Tile getScratchTile()
          Creates a temporary copy of this tile for planning purposes.
 Settlement getSettlement()
          Gets the Settlement located on this Tile.
 java.util.List<AbstractGoods> getSortedPotential()
          Sorts GoodsTypes according to potential based on TileType, TileItemContainer if any.
 java.util.List<AbstractGoods> getSortedPotential(Unit unit)
          Sorts GoodsTypes according to potential based on TileType, TileItemContainer if any.
 java.util.List<AbstractGoods> getSortedPotential(UnitType unitType, Player owner)
          Sorts GoodsTypes according to potential based on TileType, TileItemContainer if any.
 int getStyle()
          Get the Style value.
 java.lang.Iterable<Tile> getSurroundingTiles(int range)
          Returns all the tiles surrounding this tile within the given range.
 java.util.List<Tile> getSurroundingTiles(int rangeMin, int rangeMax)
          Returns all the tiles surrounding this tile within the given inclusive upper and lower bounds.
 Tile getTile()
          Gets the Tile where this Location is located or null if no Tile applies.
 java.util.List<TileImprovement> getTileImprovements()
          Returns a List of TileImprovements.
 TileItemContainer getTileItemContainer()
          Returns the TileItemContainer.
static int getTileTypePotential(TileType tileType, GoodsType goodsType, TileItemContainer tiContainer, UnitType unitType)
          Calculates the potential of a certain GoodsType.
 int getTotalUnitCount()
          Returns the total amount of Units at this Location.
 TileType getType()
          Returns the type of this Tile.
 int getWorkAmount(TileImprovementType workType)
          Returns the number of turns it takes for a non-expert pioneer to perform the given TileImprovementType.
 int getX()
          Returns the x-coordinate of this Tile.
static java.lang.String getXMLElementTagName()
          Returns the tag name of the root element representing this object.
 int getY()
          Returns the y-coordinate of this Tile.
 boolean hasImprovement(TileImprovementType type)
          Will check whether this tile has a completed improvement of the given type.
 boolean hasLostCityRumour()
          Returns true if this Tile has a lostCityRumour on it.
 boolean hasResource()
          Returns true if this Tile has a resource on it.
 boolean hasRiver()
          Returns true if this Tile has a River.
 boolean hasRoad()
          Returns true if this Tile has a road.
 boolean hasUnexploredAdjacent()
          Determine whether this tile has adjacent tiles that are unexplored.
 boolean isAdjacent(Tile tile)
          Determines whether this tile is adjacent to the specified tile.
 boolean isAdjacentToMapEdge()
          Checks if the given Tile is adjacent to the edge of the map.
 boolean isAdjacentToVerticalMapEdge()
          Checks if the given Tile is adjacent to the east or west edge of the map.
 boolean isCoast()
          Returns true if this tile has at least one adjacent land tile (if water), or at least one adjacent water tile (if land).
 boolean isConnected()
          Whether this tile is connected to Europe.
 boolean isExplored()
          Check if the tile has been explored.
 boolean isExploredBy(Player player)
          Checks if this Tile has been explored by the given Player.
 boolean isForested()
          Returns true if this Tile is forested.
 boolean isInUse()
          Is this tile under active use?
 boolean isLand()
          Returns true if this Tile is a land Tile, 'false' otherwise.
 boolean isOccupied()
          Checks whether there is a fortified enemy unit in the tile.
 boolean isPolar()
          Is this tile in the polar regions?
static boolean isSameTile(Location l1, Location l2)
          Are two locations non-null and either the same or at the same tile.
 boolean isViewShared()
           
 int potential(GoodsType goodsType, UnitType unitType)
          The potential of this tile to produce a certain type of goods.
protected  void readAttributes(javax.xml.stream.XMLStreamReader in)
          Reads the attributes of this object from an XML stream.
protected  void readChild(javax.xml.stream.XMLStreamReader in)
          Reads a single child object.
protected  void readChildren(javax.xml.stream.XMLStreamReader in)
          Reads the children of this object from an XML stream.
 boolean remove(Locatable locatable)
          Removes a Locatable from this Location.
 void removeLostCityRumour()
          Removes the lost city rumour from this Tile if there is one.
 void setConnected(boolean newConnected)
          Set the Connected value.
 void setExploredBy(Player player, boolean explored)
          Sets this Tile to be explored by the given Player.
 void setMoveToEurope(java.lang.Boolean moveToEurope)
          Set the move-to-Europe state of the tile.
 void setOwner(Player owner)
          Sets the nation that should consider this tile to be their property.
 void setOwningSettlement(Settlement owner)
          Sets the settlement that owns this tile.
 void setPosition(int x, int y)
           
 void setRegion(Region newRegion)
          Set the Region value.
 void setSettlement(Settlement s)
          Puts a Settlement on this Tile.
 void setStyle(int newStyle)
          Set the Style value.
 void setTileItemContainer(TileItemContainer newTileItemContainer)
          Sets the TileItemContainer.
 void setType(TileType t)
          Sets the type for this Tile.
 java.lang.String toString()
          Returns a String representation of this Tile.
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out, Player player, boolean showAll, boolean toSavedGame)
          This method writes an XML-representation of this object to the given stream.
 void toXMLMinimal(javax.xml.stream.XMLStreamWriter out)
          Write a minimal version of the tile.
 void updatePlayerExploredTile(Player player, boolean full)
          Updates the information about this Tile for the given Player.
 void updatePlayerExploredTiles()
          Updates the PlayerExploredTile for each player.
 void updatePlayerExploredTiles(Player oldPlayer)
          Updates the PlayerExploredTile for each player.
 
Methods inherited from class net.sf.freecol.common.model.UnitLocation
disposeList, getGoodsContainer, getNoAddReason, getSpaceTaken, getUnitCapacity, getUnitCount, getUnitIterator, getUnitList, isEmpty, isFull, writeAttributes, writeChildren
 
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
equals, equals, fundamentalDispose, getFreeColGameObject, getFreeColGameObject, getGame, getIntegerID, getSpecification, hashCode, isDisposed, isUninitialized, newLocation, readFromXML, readFromXMLPartialByClass, setDefaultId, setGame, setId, toXML, toXMLImpl, toXMLPartialByClass, updateFreeColGameObject
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, hasAbility, hasAttribute, hasListeners, readAttributes, readChild, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXMLElement, readFromXMLImpl, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setSpecification, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute, writeChildren
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.freecol.common.model.Location
getId
 

Field Detail

logger

private static final java.util.logging.Logger logger

UNIT_CHANGE

public static final java.lang.String UNIT_CHANGE
See Also:
Constant Field Values

NEAR_RADIUS

public static final int NEAR_RADIUS
The maximum distance that will still be considered "near" when determining the location name.

See Also:
getLocationName(), Constant Field Values

type

private TileType type

x

private int x

y

private int y

owner

private Player owner
The player that consider this tile to be their land.


settlement

private Settlement settlement
A pointer to the settlement located on this tile or 'null' if there is no settlement on this tile.


tileItemContainer

private TileItemContainer tileItemContainer
Stores all Improvements and Resources (if any)


owningSettlement

private Settlement owningSettlement
Indicates which colony or Indian settlement that owns this tile ('null' indicates no owner). A colony owns the tile it is located on, and every tile with a worker on it. Note that while units and settlements are owned by a player, a tile is owned by a settlement.


playerExploredTiles

private java.util.Map<Player,PlayerExploredTile> playerExploredTiles
Stores each player's image of this tile. Only initialized when needed.


region

private Region region
Describe region here.


connected

private boolean connected
Whether this tile is connected to Europe.


moveToEurope

private java.lang.Boolean moveToEurope
Does this tile have an explicit moveToEurope state. If null, just use the defaults (usually not, unless water and on map edge), otherwise use the explicit value provided here.


style

private int style
The style of this Tile, as determined by adjacent tiles.

Constructor Detail

Tile

public Tile(Game game,
            TileType type,
            int locX,
            int locY)
A constructor to use.

Parameters:
game - The Game this Tile belongs to.
type - The type.
locX - The x-position of this tile on the map.
locY - The y-position of this tile on the map.

Tile

public Tile(Game game,
            javax.xml.stream.XMLStreamReader in)
     throws javax.xml.stream.XMLStreamException
Initialize this object from an XML-representation of this object.

Parameters:
game - The Game this Tile should be created in.
in - The input stream containing the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

Tile

public Tile(Game game,
            java.lang.String id)
Initiates a new Tile with the given ID. The object should later be initialized by calling either FreeColGameObject.readFromXML(XMLStreamReader).

Parameters:
game - The Game in which this object belong.
id - The unique identifier for this object.
Method Detail

getScratchTile

public Tile getScratchTile()
Creates a temporary copy of this tile for planning purposes. The copy is identical except: - it is not present on the map - it has no owner, owning settlement or settlement The latter is not a problem as the main use of this routine is by Colony.getScratchColony() which needs to change these fields anyway. Note that the following fields are shared--- do not mutate them! + The tile item container. + The player explored tiles. Colony.getCorrespondingWorkLocation() depends on the tics being shared.

Returns:
A scratch version of this tile.

disposeScratchTile

public void disposeScratchTile()
Special handling on dispose to avoid mutating the shared fields.


isViewShared

public boolean isViewShared()

getRegion

public Region getRegion()
Get the Region value.

Returns:
a Region value

setRegion

public void setRegion(Region newRegion)
Set the Region value.

Parameters:
newRegion - The new Region value.

getDiscoverableRegion

public Region getDiscoverableRegion()
Return the discoverable Region of this Tile, or null if there is none.

Returns:
a Region value

getNameKey

public java.lang.String getNameKey()
Gets the name of this tile, or shows "unexplored" if not explored by player.

Specified by:
getNameKey in interface Named
Returns:
The name as a String.

getLabel

public StringTemplate getLabel()
Returns a description of the Tile, with the name of the tile and any improvements on it (road/plow/etc) from TileItemContainer.

Returns:
The description label for this tile

getLocationName

public StringTemplate getLocationName()
Returns the name of this location.

Specified by:
getLocationName in interface Location
Overrides:
getLocationName in class UnitLocation
Returns:
The name of this location.

getLocationNameFor

public StringTemplate getLocationNameFor(Player player)
Returns the name of this location for a particular player.

Specified by:
getLocationNameFor in interface Location
Overrides:
getLocationNameFor in class UnitLocation
Parameters:
player - The Player to prepare the location name for.
Returns:
The name of this location.

getStyle

public int getStyle()
Get the Style value.

Returns:
an int value

setStyle

public void setStyle(int newStyle)
Set the Style value.

Parameters:
newStyle - The new Style value.

isSameTile

public static boolean isSameTile(Location l1,
                                 Location l2)
Are two locations non-null and either the same or at the same tile.

Parameters:
l1 - The first Location.
l2 - The second Location.
Returns:
True if this location is the same or at the same tile.

getDistanceTo

public int getDistanceTo(Tile tile)
Gets the distance in tiles between this Tile and the specified one.

Parameters:
tile - The Tile to check the distance to.
Returns:
Distance

getDirection

public Map.Direction getDirection(Tile tile)
Gets the direction to a neighbouring tile from this one.

Parameters:
tile - The other Tile.
Returns:
The direction to the other tile, or null if not a neighbour.

getTileItemContainer

public TileItemContainer getTileItemContainer()
Returns the TileItemContainer.

Returns:
a TileItemContainer value

setTileItemContainer

public void setTileItemContainer(TileItemContainer newTileItemContainer)
Sets the TileItemContainer.

Parameters:
newTileItemContainer - a TileItemContainer value

getTileImprovements

public java.util.List<TileImprovement> getTileImprovements()
Returns a List of TileImprovements.

Returns:
a List of TileImprovements

getCompletedTileImprovements

public java.util.List<TileImprovement> getCompletedTileImprovements()
Returns a List of completed TileImprovements.

Returns:
a List of TileImprovements

getDefendingUnit

public Unit getDefendingUnit(Unit attacker)
Gets the Unit that is currently defending this Tile.

If this tile has a settlement, the units inside the settlement are also considered as potential defenders.

As this method is quite expensive, it should not be used to test for the presence of enemy units.

Parameters:
attacker - The target that would be attacking this tile.
Returns:
The Unit that has been chosen to defend this tile.

dispose

public void dispose()
Description copied from class: UnitLocation
Dispose of this UnitLocation.

Overrides:
dispose in class UnitLocation

getFirstUnit

public Unit getFirstUnit()
Gets the first Unit on this tile.

Returns:
The first Unit on this tile.

getLastUnit

public Unit getLastUnit()
Gets the last Unit on this tile.

Returns:
The last Unit on this tile.

getTotalUnitCount

public int getTotalUnitCount()
Returns the total amount of Units at this Location. This also includes units in a carrier

Returns:
The total amount of Units at this Location.

contains

public boolean contains(Locatable locatable)
Checks if this Tile contains the specified Locatable.

Specified by:
contains in interface Location
Overrides:
contains in class UnitLocation
Parameters:
locatable - The Locatable to test the presence of.
Returns:
  • true if the specified Locatable is on this Tile and
  • false otherwise.

getMap

public Map getMap()
Gets the Map in which this Tile belongs.

Returns:
The Map.

isConnected

public boolean isConnected()
Whether this tile is connected to Europe.

Returns:
a boolean value

setConnected

public void setConnected(boolean newConnected)
Set the Connected value.

Parameters:
newConnected - The new Connected value.

getMoveToEurope

public java.lang.Boolean getMoveToEurope()
Get the move-to-Europe state of the tile.

Returns:
The move-to-Europe state of the tile.

setMoveToEurope

public void setMoveToEurope(java.lang.Boolean moveToEurope)
Set the move-to-Europe state of the tile.

Parameters:
moveToEurope - The new move-to-Europe state for the tile.

canMoveToEurope

public boolean canMoveToEurope()
Can a unit move to Europe from this tile?

Returns:
True if a unit can move to Europe from this tile.

isExplored

public boolean isExplored()
Check if the tile has been explored.

Returns:
true if tile is known.

isPolar

public boolean isPolar()
Is this tile in the polar regions?

Returns:
True if the tile is polar.

isLand

public boolean isLand()
Returns true if this Tile is a land Tile, 'false' otherwise.

Returns:
true if this Tile is a land Tile, 'false' otherwise.

isForested

public boolean isForested()
Returns true if this Tile is forested.

Returns:
true if this Tile is forested.

hasRiver

public boolean hasRiver()
Returns true if this Tile has a River.

Returns:
true if this Tile has a River.

hasResource

public boolean hasResource()
Returns true if this Tile has a resource on it.

Returns:
true if this Tile has a resource on it.

hasLostCityRumour

public boolean hasLostCityRumour()
Returns true if this Tile has a lostCityRumour on it.

Returns:
true if this Tile has a lostCityRumour on it.

hasRoad

public boolean hasRoad()
Returns true if this Tile has a road.

Returns:
true if this Tile has a road.

getRoad

public TileImprovement getRoad()
Returns the road on this tile, if there is one, and null otherwise.

Returns:
a TileImprovement value

getType

public TileType getType()
Returns the type of this Tile. Returns UNKNOWN if the type of this Tile is unknown.

Returns:
The type of this Tile.

getOwner

public Player getOwner()
The nation that consider this tile to be their property.

Specified by:
getOwner in interface Ownable
Returns:
The player owning this tile.

setOwner

public void setOwner(Player owner)
Sets the nation that should consider this tile to be their property.

Specified by:
setOwner in interface Ownable
Parameters:
owner - The player, new owner of this tile.
See Also:
getOwner()

setSettlement

public void setSettlement(Settlement s)
Puts a Settlement on this Tile. A Tile can only have one Settlement located on it. The Settlement will also become the owner of this Tile.

Parameters:
s - The Settlement that shall be located on this Tile.
See Also:
getSettlement()

getSettlement

public Settlement getSettlement()
Gets the Settlement located on this Tile.

Specified by:
getSettlement in interface Location
Overrides:
getSettlement in class UnitLocation
Returns:
The Settlement that is located on this Tile or null if no Settlement apply.
See Also:
setSettlement(net.sf.freecol.common.model.Settlement)

getColony

public Colony getColony()
Gets the Colony located on this Tile. Only a convenience method for getSettlement() that makes sure that the settlement is a colony.

Specified by:
getColony in interface Location
Overrides:
getColony in class UnitLocation
Returns:
The Colony that is located on this Tile or null if none found.
See Also:
getSettlement()

getIndianSettlement

public IndianSettlement getIndianSettlement()
Gets the IndianSettlement located on this Tile. Only a convenience method for getSettlement() that makes sure that the settlement is a native settlement.

Returns:
The IndianSettlement that is located on this Tile or null if none found.
See Also:
getSettlement()

getOwningSettlement

public Settlement getOwningSettlement()
Gets the owning settlement for this tile.

Returns:
The Settlement that owns this tile.
See Also:
setOwner(net.sf.freecol.common.model.Player)

setOwningSettlement

public void setOwningSettlement(Settlement owner)
Sets the settlement that owns this tile.

Parameters:
owner - The Settlement to own this tile.
See Also:
getOwner()

changeOwningSettlement

public void changeOwningSettlement(Settlement settlement)
Changes the owning settlement for this tile.

Parameters:
settlement - The new owning Settlement for this tile.

changeOwnership

public void changeOwnership(Player player,
                            Settlement settlement)
Change the tile ownership. Also change the owning settlement as the two are commonly related.

Parameters:
player - The Player to own the tile.
settlement - The Settlement to own the tile.

isInUse

public boolean isInUse()
Is this tile under active use?

Returns:
True if a colony is using this tile.

addTileItem

private void addTileItem(TileItem item)
Adds a tile item to this tile.

Parameters:
item - The TileItem to add.

getLostCityRumour

public LostCityRumour getLostCityRumour()
Gets the lost city rumour on this Tile if any.

Returns:
The LostCityRumour on this tile, or null if none.

addLostCityRumour

public void addLostCityRumour(LostCityRumour rumour)
Adds a lost city rumour to this tile.

Parameters:
rumour - The LostCityRumour to add.

removeLostCityRumour

public void removeLostCityRumour()
Removes the lost city rumour from this Tile if there is one.


getRiver

public TileImprovement getRiver()
Returns the river on this Tile if any

Returns:
River TileImprovement

getRiverStyle

public int getRiverStyle()
Returns the style of a river TileImprovement on this Tile.

Returns:
an int value

getNeighbourOrNull

public Tile getNeighbourOrNull(Map.Direction direction)
Returns the neighbouring Tile of the given Tile in the given direction.

Parameters:
direction - The direction in which the neighbour tile is located.
Returns:
The neighbouring Tile of the given Tile in the given direction.

hasUnexploredAdjacent

public boolean hasUnexploredAdjacent()
Determine whether this tile has adjacent tiles that are unexplored.

Returns:
true if at least one neighbouring tiles is unexplored, otherwise false

isCoast

public boolean isCoast()
Returns true if this tile has at least one adjacent land tile (if water), or at least one adjacent water tile (if land).

Returns:
a boolean value

addResource

public void addResource(Resource resource)
Adds a Resource to this Tile.

Parameters:
resource - The Resource to add.

setType

public void setType(TileType t)
Sets the type for this Tile.

Parameters:
t - The new TileType for this Tile.

getX

public int getX()
Returns the x-coordinate of this Tile.

Returns:
The x-coordinate of this Tile.

getY

public int getY()
Returns the y-coordinate of this Tile.

Returns:
The y-coordinate of this Tile.

getPosition

public Map.Position getPosition()
Gets the Position of this Tile.

Returns:
The Position of this Tile.

setPosition

public void setPosition(int x,
                        int y)

getMovableUnit

public Unit getMovableUnit()
Gets a Unit that can become active. This is preferably a Unit not currently performing any work.

Returns:
A Unit with movesLeft > 0 or null if no such Unit is located on this Tile.

getTile

public Tile getTile()
Gets the Tile where this Location is located or null if no Tile applies.

Specified by:
getTile in interface Location
Overrides:
getTile in class UnitLocation
Returns:
This Tile.

add

public boolean add(Locatable locatable)
Adds a Locatable to this Location.

Specified by:
add in interface Location
Overrides:
add in class UnitLocation
Parameters:
locatable - The Locatable to add to this Location.

remove

public boolean remove(Locatable locatable)
Removes a Locatable from this Location.

Specified by:
remove in interface Location
Overrides:
remove in class UnitLocation
Parameters:
locatable - The Locatable to remove from this Location.

canAdd

public boolean canAdd(Locatable locatable)
Checks whether or not the specified locatable may be added to this Location.

Specified by:
canAdd in interface Location
Overrides:
canAdd in class UnitLocation
Parameters:
locatable - a Locatable value
Returns:
a boolean value

potential

public int potential(GoodsType goodsType,
                     UnitType unitType)
The potential of this tile to produce a certain type of goods.

Parameters:
goodsType - The type of goods to check the potential for.
unitType - an UnitType value
Returns:
The normal potential of this tile to produce that amount of goods.

getMaximumPotential

public int getMaximumPotential(GoodsType goodsType,
                               UnitType unitType)
Gets the maximum potential for producing the given type of goods. The maximum potential is the potential of a tile after the tile has been plowed/built road on.

Parameters:
goodsType - The type of goods.
unitType - an UnitType value
Returns:
The maximum potential.

getProductionBonus

public java.util.Set<Modifier> getProductionBonus(GoodsType goodsType,
                                                  UnitType unitType)
Describe getProductionBonus method here.

Parameters:
goodsType - a GoodsType value
Returns:
a Modifier value

canGetRoad

public boolean canGetRoad()
Checks whether this Tile can have a road or not. This method will return false if a road has already been built.

Returns:
The result.

findTileImprovementType

public TileImprovement findTileImprovementType(TileImprovementType type)
Finds the TileImprovement of a given Type, or null if there is no match.


hasImprovement

public boolean hasImprovement(TileImprovementType type)
Will check whether this tile has a completed improvement of the given type. Useful for checking whether the tile for instance has a road or is plowed.

Parameters:
type - The type to check for.
Returns:
Whether the tile has the improvement and the improvement is completed.

getTileTypePotential

public static int getTileTypePotential(TileType tileType,
                                       GoodsType goodsType,
                                       TileItemContainer tiContainer,
                                       UnitType unitType)
Calculates the potential of a certain GoodsType.

Parameters:
tileType - The TileType.
goodsType - The GoodsType to check the potential for.
tiContainer - The TileItemContainer with any TileItems to give bonuses.
unitType - an UnitType value The Bonus Fish to be considered if valid
Returns:
The amount of goods.

getSortedPotential

public java.util.List<AbstractGoods> getSortedPotential()
Sorts GoodsTypes according to potential based on TileType, TileItemContainer if any.

Returns:
The sorted GoodsTypes.

getSortedPotential

public java.util.List<AbstractGoods> getSortedPotential(Unit unit)
Sorts GoodsTypes according to potential based on TileType, TileItemContainer if any.

Parameters:
unit - the Unit to work on this Tile
Returns:
The sorted GoodsTypes.

getSortedPotential

public java.util.List<AbstractGoods> getSortedPotential(UnitType unitType,
                                                        Player owner)
Sorts GoodsTypes according to potential based on TileType, TileItemContainer if any.

Parameters:
unitType - the UnitType to work on this Tile
owner - the Player owning the unit
Returns:
The sorted GoodsTypes.

expendResource

public Resource expendResource(GoodsType goodsType,
                               UnitType unitType,
                               Settlement settlement)
This method is called only when a new turn is beginning. It will reduce the quantity of the bonus Resource that is on the tile, if any and if applicable.

Returns:
The resource if it is exhausted by this call (so it can be used in a message), otherwise null.
See Also:
ResourceType

updatePlayerExploredTiles

public void updatePlayerExploredTiles()
Updates the PlayerExploredTile for each player. This update will only be performed if the player can see this Tile.


updatePlayerExploredTiles

public void updatePlayerExploredTiles(Player oldPlayer)
Updates the PlayerExploredTile for each player. This update will only be performed if the player can see this Tile.

Parameters:
oldPlayer - The optional Player that formerly had visibility of this tile and should see the change.

getPlayerExploredTile

public PlayerExploredTile getPlayerExploredTile(Player player)
Gets the PlayerExploredTile for the given Player.

Parameters:
player - The Player.
See Also:
PlayerExploredTile

updatePlayerExploredTile

public void updatePlayerExploredTile(Player player,
                                     boolean full)
Updates the information about this Tile for the given Player.

Parameters:
player - The Player.
full - If true, also update any hidden information specific to a settlement present on the tile.

isExploredBy

public boolean isExploredBy(Player player)
Checks if this Tile has been explored by the given Player.

Parameters:
player - The Player.
Returns:
true if this Tile has been explored by the given Player and false otherwise.

setExploredBy

public void setExploredBy(Player player,
                          boolean explored)
Sets this Tile to be explored by the given Player.

Parameters:
player - The Player.
explored - true if this Tile should be explored by the given Player and false otherwise.

getWorkAmount

public int getWorkAmount(TileImprovementType workType)
Returns the number of turns it takes for a non-expert pioneer to perform the given TileImprovementType. It will check if it is valid for this TileType.

Parameters:
workType - The TileImprovementType
Returns:
The number of turns it should take a non-expert pioneer to finish the work.

getOccupyingUnit

public Unit getOccupyingUnit()
Returns the unit who is occupying the tile

Returns:
the unit who is occupying the tile
See Also:
isOccupied()

isOccupied

public boolean isOccupied()
Checks whether there is a fortified enemy unit in the tile. Units can't produce in occupied tiles

Returns:
true if an fortified enemy unit is in the tile

isAdjacent

public boolean isAdjacent(Tile tile)
Determines whether this tile is adjacent to the specified tile.

Parameters:
tile - A potentially adjacent Tile.
Returns:
true if the tile is adjacent to this tile

getAdjacentTile

public Tile getAdjacentTile(Map.Direction direction)
Gets the position adjacent Tile to a given Tile, in a given direction.

Parameters:
direction - The direction (N, NE, E, etc.)
Returns:
Adjacent tile

getSurroundingTiles

public java.lang.Iterable<Tile> getSurroundingTiles(int range)
Returns all the tiles surrounding this tile within the given range. This tile is not included.

Parameters:
range - How far away do we need to go starting from this.
Returns:
The tiles surrounding this tile.

getSurroundingTiles

public java.util.List<Tile> getSurroundingTiles(int rangeMin,
                                                int rangeMax)
Returns all the tiles surrounding this tile within the given inclusive upper and lower bounds. getSurroundingTiles(r) is equivalent to getSurroundingTiles(1, r), thus this tile is included if rangeMin is zero.

Parameters:
rangeMin - The inclusive minimum distance from this tile.
rangeMax - The inclusive maximum distance from this tile.
Returns:
A list of the tiles surrounding this tile.

isAdjacentToVerticalMapEdge

public boolean isAdjacentToVerticalMapEdge()
Checks if the given Tile is adjacent to the east or west edge of the map.

Returns:
true if the given tile is at the edge of the map.

isAdjacentToMapEdge

public boolean isAdjacentToMapEdge()
Checks if the given Tile is adjacent to the edge of the map.

Returns:
true if the given tile is at the edge of the map.

getNearestSettlement

public Settlement getNearestSettlement(Player owner,
                                       int radius)
Finds the nearest settlement to this tile.

Parameters:
owner - If non-null, the settlement should be owned by this player.
radius - The maximum radius of the search.
Returns:
The nearest settlement, or null if none.

getSafeTile

public Tile getSafeTile(Player player,
                        java.util.Random random)
Finds a safe tile to put a unit on, near to this one. Useful on return from Europe.

Parameters:
player - The owner of the unit to place (may be null).
random - An optional pseudo-random number source.
Returns:
A vacant tile near this one.

toXMLMinimal

public void toXMLMinimal(javax.xml.stream.XMLStreamWriter out)
                  throws javax.xml.stream.XMLStreamException
Write a minimal version of the tile. Useful if the player has not explored the tile.

Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException

toXMLImpl

protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out,
                         Player player,
                         boolean showAll,
                         boolean toSavedGame)
                  throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object to the given stream.

Only attributes visible to the given Player will be added to that representation if showAll is set to false.

Specified by:
toXMLImpl in class FreeColGameObject
Parameters:
out - The target stream.
player - The Player this XML-representation should be made for, or null if showAll == true.
showAll - Only attributes visible to player will be added to the representation if showAll is set to false.
toSavedGame - If true then information that is only needed when saving a game is added.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

readAttributes

protected void readAttributes(javax.xml.stream.XMLStreamReader in)
                       throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.

Overrides:
readAttributes in class FreeColObject
Parameters:
in - The XML input stream.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

readChildren

protected void readChildren(javax.xml.stream.XMLStreamReader in)
                     throws javax.xml.stream.XMLStreamException
Reads the children of this object from an XML stream.

Overrides:
readChildren in class UnitLocation
Parameters:
in - The XML input stream.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

readChild

protected void readChild(javax.xml.stream.XMLStreamReader in)
                  throws javax.xml.stream.XMLStreamException
Reads a single child object. This method does calls readChild with a null specification parameter.

Overrides:
readChild in class UnitLocation
Parameters:
in - The XML input stream.
Throws:
javax.xml.stream.XMLStreamException - if an error occurs

fixup09x

public void fixup09x()
Fixes visible pets where there is a settlement present but the tile is not owned correctly as ownership was not implemented in 0.9.x. Need to do this after reading the game so that canSee() is valid. TODO: remove when 0.9.x is not supported.


toString

public java.lang.String toString()
Returns a String representation of this Tile.

Overrides:
toString in class FreeColGameObject
Returns:
A String representation of this Tile.

getXMLElementTagName

public static java.lang.String getXMLElementTagName()
Returns the tag name of the root element representing this object.

Returns:
"tile".