Package net.sf.freecol.common.model
Class Tile
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColGameObject
-
- net.sf.freecol.common.model.UnitLocation
-
- net.sf.freecol.common.model.Tile
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,Location
,Named
,Ownable
,ObjectWithId
public final class Tile extends UnitLocation implements Named, Ownable
Represents a single tile on theMap
.- See Also:
Map
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
Tile.IndianSettlementInternals
Information that is internal to the native settlements, and only updated on close contact.-
Nested classes/interfaces inherited from class net.sf.freecol.common.model.UnitLocation
UnitLocation.NoAddReason
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
CACHED_TILE_TAG
private java.util.Map<Player,Tile>
cachedTiles
A map of cached tiles for each European player, null in clients.private static java.lang.String
CONNECTED_TAG
private int
contiguity
An artificial contiguous-region number to identify connected parts of the map.private static java.lang.String
CONTIGUITY_TAG
private static java.lang.String
COPIED_TAG
static java.util.Comparator<Tile>
edgeDistanceComparator
Comparator to sort tiles by increasing distance from the edge.static int
FLAG_RECALCULATE
Flag to assign to the high seas count to flag that the high seas connectivity needs recalculation after reading in the map.static int
FOREST_ZINDEX
static java.util.Comparator<Tile>
highSeasComparator
Comparator to find the smallest high seas count.private int
highSeasCount
The number of tiles to traverse to get to the high seas.static java.util.function.Predicate<Tile>
isSeaTile
Predicate to identify ordinary sea tiles.private static java.util.logging.Logger
logger
private static int
LOW_PRODUCTION_WARNING_VALUE
Warn about colonies that can not produce this amount of a building material.private static java.lang.String
MOVE_TO_EUROPE_TAG
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.static java.lang.String
OLD_PLAYER_EXPLORED_TILE_TAG
static java.lang.String
OLD_TILE_ITEM_CONTAINER_TAG
static int
OVERLAY_ZINDEX
private Player
owner
The player that consider this tile to be their land.private static java.lang.String
OWNER_TAG
private static java.lang.String
OWNING_SETTLEMENT_TAG
private Settlement
owningSettlement
Indicates which settlement owns this tile (null indicates no owner).private static java.lang.String
PLAYER_TAG
private java.util.Map<Player,Tile.IndianSettlementInternals>
playerIndianSettlements
A cache of native settlement internals for each European player, null in clients.private Region
region
The region this tile is in.private static java.lang.String
REGION_TAG
static int
RESOURCE_ZINDEX
static int
RUMOUR_ZINDEX
private Settlement
settlement
The settlement located on this tile, if any.private int
style
The style of this Tile, as determined by adjacent tiles.private static java.lang.String
STYLE_TAG
static java.lang.String
TAG
private TileItemContainer
tileItemContainer
Stores all Improvements and Resources (if any).private TileType
type
The type of the tile.private static java.lang.String
TYPE_TAG
static java.lang.String
UNIT_CHANGE
This must be distinct from ColonyTile/Building.UNIT_CHANGE or the colony panel can get confused.private int
x
The tile coordinates in the enclosing map.private static java.lang.String
X_TAG
private int
y
The tile coordinates in the enclosing map.private static java.lang.String
Y_TAG
-
Fields inherited from class net.sf.freecol.common.model.FreeColGameObject
initialized
-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
Fields inherited from interface net.sf.freecol.common.model.Location
LOCATION_RANK_EUROPE, LOCATION_RANK_HIGHSEAS, LOCATION_RANK_NOWHERE
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
add(Locatable locatable)
Adds aLocatable
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.TileImprovement
addRiver(int magnitude, java.lang.String conns)
Adds a new river to this tile.TileImprovement
addRoad()
Adds a road to this tile.private boolean
addTileItem(TileItem item)
Adds a tile item to this tile.void
cacheUnseen()
A change is about to occur on this tile.void
cacheUnseen(Player player)
A change is about to occur on this tile.private void
cacheUnseen(Player player, Tile copied)
A change may have occured on this tile.void
cacheUnseen(Tile copied)
A change may have occured on this tile.boolean
canAdd(Locatable locatable)
Checks whether or not the specified locatable may be added to thisLocation
.boolean
canProduce(GoodsType goodsType, UnitType unitType)
Can this tile produce a given goods type? To produce goods either the tile type must have a suitable production type, or the tile item container contains suitable resource.void
changeOwnership(Player player, Settlement settlement)
Change the tile ownership.void
changeOwningSettlement(Settlement settlement)
Changes the owning settlement for this tile.void
changeType(TileType type)
Changes the type of this tile.Constants.IntegrityType
checkIntegrity(boolean fix, LogBuilder lb)
Checks the integrity of this game object.boolean
contains(Locatable locatable)
Checks if thisLocation
contains the specifiedLocatable
.<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.void
disposeResources()
Dispose of the resources of this object, and finally remove it from the game.java.util.stream.Stream<Ability>
getAbilities(java.lang.String id, FreeColSpecObjectType fcgot, Turn turn)
Gets the set of abilities with the given identifier from this object.java.util.List<Colony>
getAdjacentColonies()
Get the adjacent colonies.int
getAvailableAdjacentCount()
Get the number of tiles adjacent to this one that are of the same land/water type such as to be nominally accessible to a unit.int
getBaseProduction(ProductionType productionType, GoodsType goodsType, UnitType unitType)
Get the base production exclusive of any bonuses.Tile
getBestDisembarkTile(Player player)
Get the adjacent land tile with the best defence bonus.AbstractGoods
getBestFoodProduction()
Get the best food type to produce here.StringTemplate
getBuildColonyWarnings(Unit unit)
A colony is proposed to be built on this tile.private Tile
getCachedTile(Player player)
Get a players view of this tile.private java.util.Map<Player,Tile>
getCachedTiles()
Get the cached tile map.StringTemplate
getColonyTileLocationLabel(Colony colony)
Get a label for this tile assuming it is a colony tile of a given colony.java.util.List<TileItem>
getCompleteItems()
Get the completed tile items for this tile.java.util.List<TileImprovement>
getCompleteTileImprovements()
Gets a list of completedTileImprovements
.int
getContiguity()
Get the contiguity identifier for this tile.java.util.Set<Tile>
getContiguityAdjacent(int contiguity)
Get the adjacent tiles that have a given contiguity.int
getDefenceBonusPercentage()
Get the defence bonus as a percent.double
getDefenceValue()
Get the defence value for this tile type.Unit
getDefendingUnit(Unit attacker)
Gets the unit that is currently defending this tile.private StringTemplate
getDetailedLocationLabel()
Get a detailed label for this tile.private StringTemplate
getDetailedLocationLabelFor(Player player)
Get a detailed label for this tile for a given player.Direction
getDirection(Tile tile)
Gets the direction to a neighbouring tile from this one.java.util.stream.Stream<RandomChoice<Disaster>>
getDisasterChoices()
Gets a weighted list of natural disasters than can strike this tile.Region
getDiscoverableRegion()
Get the discoverable region of this tile.FreeColObject
getDisplayObject()
Get an object to display when showing the user messages for this object.int
getDistanceTo(Tile tile)
Gets the distance in tiles between this tile and the specified one.private int
getEdgeDistance()
Get the minimum distance in tiles from this tile to the map edge.int
getHighSeasCount()
Gets the high seas count.StringTemplate
getLabel()
Gets a description of theTile
, with the name of the tile and any improvements on it (road/plow/etc) fromTileItemContainer
.UnitType
getLearnableSkill(Player player)
FreeColGameObject
getLinkTarget(Player player)
Get a suitable game object to use as a clickable link in messages to a player.StringTemplate
getLocationLabel()
Get a label for this location.StringTemplate
getLocationLabelFor(Player player)
Get a label for this location for a particular player.LostCityRumour
getLostCityRumour()
Gets a lost city rumour on this tile.Map
getMap()
Get the map in which this tile belongs.int
getMaximumPotential(GoodsType goodsType, UnitType unitType)
Gets the maximum potential for producing the given type of goods.private int
getMaximumPotential(GoodsType goodsType, UnitType unitType, TileType tileType)
Gets the maximum potential for producing the given type of goods with a given unit if this tile is (perhaps changed to) a given tile type.java.lang.Boolean
getMoveToEurope()
Get the move-to-Europe state of the tile.java.lang.String
getNameKey()
Gets the name of this named object.Settlement
getNearestSettlement(Player owner, int radius, boolean same)
Finds the nearest settlement to this tile.private StringTemplate
getNearLocationLabel(Direction direction, StringTemplate location)
Get a label for a nearby location.Tile
getNeighbourOrNull(Direction direction)
Get the neighbouring tile in the given direction.Unit
getOccupyingUnit()
Gets the unit that is occupying the tile.Player
getOwner()
Gets the owner of thisOwnable
.Settlement
getOwningSettlement()
Gets the owning settlement for this tile.private Tile.IndianSettlementInternals
getPlayerIndianSettlement(Player player)
Gets theIndianSettlementInternals
for the given player.int
getPotentialProduction(GoodsType goodsType, UnitType unitType)
Get the potential production of this tile for a given goods type and optional worker type.java.util.stream.Stream<Modifier>
getProductionModifiers(GoodsType goodsType, UnitType unitType)
Get the production modifiers for this tile.int
getRank()
Get a integer for this location, for the benefit of location comparators.Region
getRegion()
Get the tile region.Resource
getResource()
Gets the resource on this tile.TileImprovement
getRiver()
Gets the river on this tile.TileImprovementStyle
getRiverStyle()
Gets the style of a river improvement on this tile.TileImprovement
getRoad()
Gets the road on this tile.java.util.List<Tile>
getSafeAnchoringTiles(Unit unit)
Get any safe sites for a naval transport unit to stop at to disembark a unit to this tile.java.util.List<Tile>
getSafestSurroundingLandTiles(Player player)
Get a list of surrounding land tiles, sorted with the most defensible first.Tile
getSafeTile(Player player, java.util.Random random)
Finds a safe tile to put a unit on, near to this one.Settlement
getSettlement()
Gets the settlement on this tile.StringTemplate
getSimpleLabel()
Get a simple label for this tile, with just its coordinates.java.util.List<AbstractGoods>
getSortedPotential()
Sort possible goods types according to potential.java.util.List<AbstractGoods>
getSortedPotential(Unit unit)
Sort possible goods types according to potential.java.util.List<AbstractGoods>
getSortedPotential(UnitType unitType, Player owner)
Sort possible goods types according to potential.int
getStyle()
Get the style value.java.lang.Iterable<Tile>
getSurroundingTiles(int range)
Gets all the tiles surrounding a tile within the given range.java.util.List<Tile>
getSurroundingTiles(int rangeMin, int rangeMax)
Gets all the tiles surrounding this tile within the given inclusive upper and lower bounds.Tile
getTile()
Gets the Tile associated with this Location.TileImprovement
getTileImprovement(TileImprovementType type)
Gets the TileImprovement of a given type, or null if there is no match.java.util.List<TileImprovement>
getTileImprovements()
Gets a list ofTileImprovements
.TileItemContainer
getTileItemContainer()
Gets this tilesTileItemContainer
.Tile
getTileToCache()
Get a copy of this tile suitable for caching (lacking units).TileType
getType()
Gets the type of this Tile.java.util.List<GoodsType>
getWantedGoods(Player player)
int
getWorkAmount(TileImprovementType workType)
Get the number of turns it takes for a non-expert pioneer to build the givenTileImprovementType
.int
getX()
Gets the x-coordinate of this tile.java.lang.String
getXMLTagName()
Get the serialization tag for this object.int
getY()
Gets the y-coordinate of this tile.boolean
hasLostCityRumour()
Does this tile have a LCR?boolean
hasResource()
Does this tile have a resource?boolean
hasRiver()
Does this tile have a river?boolean
hasRoad()
Does this tile have a road?boolean
hasSettlement()
Does this tile have a settlement.boolean
hasTileImprovement(TileImprovementType type)
Does this tile contain a completed improvement of the given type?boolean
hasUnexploredAdjacent()
Determine whether this tile has adjacent tiles that are unexplored.private void
internalToXML(FreeColXMLWriter xw, java.lang.String tag)
Fundamental (post-cache) version of toXML.boolean
isAdjacent(Tile tile)
Determines whether this tile is adjacent to the specified tile.boolean
isBlocked(Unit unit)
Quick test whether this tile is trivially blocked to moves from a unit.boolean
isCoastland()
Is this a land tile on the sea coast (lakes do not count).boolean
isConnectedTo(Tile other)
Is this tile connected to another across the same contiguous piece of land or water?boolean
isDangerousToShip(Unit ship)
Is this tile dangerous for a naval unit to enter? That is, is there an adjacent settlement that is likely to bombard it.boolean
isDirectlyHighSeasConnected()
Can a unit move to the high seas from this tile?boolean
isExplored()
Check if the tile has been explored.boolean
isExploredBy(Player player)
Checks if thisTile
has been explored by the givenPlayer
.boolean
isForested()
Is this a forested tile?boolean
isGoodHillTile()
Is this a good tile to put hills on? Used by the terrain generator.boolean
isGoodMountainTile(TileType mountains)
Is this a good tile to put mountains on? Used by the terrain generator.boolean
isGoodRiverTile(TileImprovementType riverType)
Is this a good tile to start a river on? Used by the terrain generator.boolean
isHighSeasConnected()
Gets whether this tile is connected to the high seas.boolean
isImprovementAllowed(TileImprovement tip)
Check if a given improvement is valid for this tile.boolean
isImprovementTypeAllowed(TileImprovementType type)
Check if a given improvement type is valid for this tile.boolean
isInUse()
Is this tile under active use?boolean
isLand()
Is this a land tile?boolean
isLandLocked()
Is this tile land locked?boolean
isOccupied()
Checks whether there is an enemy unit occupying this tile.boolean
isOnRiver()
Is this tile on or adjacent to a navigable river but not the ocean.boolean
isPolar()
Is this tile in the polar regions?boolean
isRiverCorner()
Is this tile on a river corner?boolean
isShore()
Is this a shoreline tile? The tile can be water or land, and the water can be ocean, river or an inland lake.protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.protected void
readChild(FreeColXMLReader xr)
Reads a single child object.protected void
readChildren(FreeColXMLReader xr)
Reads the children of this object from an XML stream.boolean
remove(Locatable locatable)
Removes aLocatable
from this Location.void
removeIndianSettlementInternals(Player player)
LostCityRumour
removeLostCityRumour()
Removes the lost city rumour from thisTile
if there is one.Resource
removeResource()
Removes a resource from this tile.void
removeRiver()
Removes a river from this tile.TileImprovement
removeRoad()
Removes a road from this tile.private <T extends TileItem>
TremoveTileItem(T item)
Removes a tile item from this tile.void
seeTile()
Set the players view of this tile to the tile itself if the player can see it.void
seeTile(Player player)
Set a players view of this tile to the tile itself.void
setCachedTile(Player player, Tile tile)
Set a players view of this tile.private void
setCachedTiles(java.util.Map<Player,Tile> cachedTiles)
Get the cached tile map.void
setContiguity(int contiguity)
Sets the contiguity identifier for this tile.void
setExplored(Player player, boolean reveal)
Explore/unexplore a tile for a player.void
setHighSeasCount(int count)
Set the high seas count.private void
setIndianSettlementInternals(Player player, UnitType skill, java.util.List<GoodsType> wanted)
Set native settlement information.void
setMoveToEurope(java.lang.Boolean moveToEurope)
Set the move-to-Europe state of the tile.void
setOwner(Player owner)
Sets the owner of thisOwnable
.void
setOwningSettlement(Settlement owner)
Sets the settlement that owns this tile.void
setRegion(Region newRegion)
Set the tile region.void
setSettlement(Settlement settlement)
Put a settlement onto this tile.void
setStyle(int newStyle)
Set the tile style.void
setTileItemContainer(TileItemContainer newTileItemContainer)
Sets theTileItemContainer
.void
setType(TileType t)
Sets the type for this Tile.java.lang.String
toShortString()
Get a short description of this location.java.lang.String
toString()
void
toXML(FreeColXMLWriter xw, java.lang.String tag)
This method writes an XML-representation of this object with a specified tag to the given stream.Location
up()
Promote this location to a more meaningful one if possible.private void
updateColonyTiles()
Update production after a change to this tile.void
updateIndianSettlement(Player player)
Updates the information about the native settlement on thisTile
for the givenPlayer
.protected void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.protected void
writeChildren(FreeColXMLWriter xw)
Write the children of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.UnitLocation
clearUnitList, equipForRole, getCarrierForUnit, getColony, getDisposables, getFirstUnit, getGoodsContainer, getIndianSettlement, getLastUnit, getNavalUnits, getNoAddReason, getSpaceTaken, getTotalUnitCount, getUnitCapacity, getUnitCount, getUnitList, getUnits, hasCarrierWithSpace, intern, isEmpty, isFull, moveToFront, priceGoods
-
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
dispose, equals, fundamentalDispose, getClassIndex, getGame, getSpecification, hashCode, internId, isDisposed, isInitialized, isInternable, readFromXML, setGame, setSpecification
-
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addAbility, addFeatures, addModifier, addPropertyChangeListener, addPropertyChangeListener, apply, apply, applyModifiers, applyModifiers, arrayKey, compareIds, compareTo, containsAbilityKey, containsModifierKey, copy, copy, copy, copy, copyInCast, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getDefenceModifiers, getFeatureContainer, getFreeColObjectClass, getFreeColObjectClassByName, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, hasAbility, hasAbility, hasAbility, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setId, toXML, toXMLPartial, toXMLPartial
-
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, getLocationImageKey
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
edgeDistanceComparator
public static final java.util.Comparator<Tile> edgeDistanceComparator
Comparator to sort tiles by increasing distance from the edge.
-
highSeasComparator
public static final java.util.Comparator<Tile> highSeasComparator
Comparator to find the smallest high seas count.
-
isSeaTile
public static final java.util.function.Predicate<Tile> isSeaTile
Predicate to identify ordinary sea tiles.
-
UNIT_CHANGE
public static final java.lang.String UNIT_CHANGE
This must be distinct from ColonyTile/Building.UNIT_CHANGE or the colony panel can get confused.- See Also:
- Constant Field Values
-
FLAG_RECALCULATE
public static final int FLAG_RECALCULATE
Flag to assign to the high seas count to flag that the high seas connectivity needs recalculation after reading in the map.- See Also:
- Constant Field Values
-
LOW_PRODUCTION_WARNING_VALUE
private static final int LOW_PRODUCTION_WARNING_VALUE
Warn about colonies that can not produce this amount of a building material.- 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:
getLocationLabel()
, Constant Field Values
-
OVERLAY_ZINDEX
public static final int OVERLAY_ZINDEX
- See Also:
- Constant Field Values
-
FOREST_ZINDEX
public static final int FOREST_ZINDEX
- See Also:
- Constant Field Values
-
RESOURCE_ZINDEX
public static final int RESOURCE_ZINDEX
- See Also:
- Constant Field Values
-
RUMOUR_ZINDEX
public static final int RUMOUR_ZINDEX
- See Also:
- Constant Field Values
-
type
private TileType type
The type of the tile. Beware: this may appear to be null in the client when the tile is unexplored.
-
x
private int x
The tile coordinates in the enclosing map.
-
y
private int y
The tile coordinates in the enclosing map.
-
owner
private Player owner
The player that consider this tile to be their land.
-
settlement
private Settlement settlement
The settlement located on this tile, if any.
-
owningSettlement
private Settlement owningSettlement
Indicates which settlement owns this tile (null indicates no owner). A colony owns the tile it is located on, and every tile it has claimed by successfully moving a worker on to it. Native settlements make more extensive and unpredictable claims. Note that while units and settlements are owned by a player, a tile is owned by a settlement.
-
tileItemContainer
private TileItemContainer tileItemContainer
Stores all Improvements and Resources (if any).
-
region
private Region region
The region this tile is in.
-
highSeasCount
private int highSeasCount
The number of tiles to traverse to get to the high seas.
-
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.
-
contiguity
private int contiguity
An artificial contiguous-region number to identify connected parts of the map. That is, all land tiles with the same contiguity number can be reached by a land unit on any of those tiles in the absence of extra-geographic blockages like settlements and other units. Similarly for water tiles/naval units. This is used to quickly scope out the sort of paths available to a unit attempting to reach some destination. It only needs serialization from server to client, as it is set by the TerrainGenerator on map import or creation.
-
cachedTiles
private final java.util.Map<Player,Tile> cachedTiles
A map of cached tiles for each European player, null in clients.
-
playerIndianSettlements
private final java.util.Map<Player,Tile.IndianSettlementInternals> playerIndianSettlements
A cache of native settlement internals for each European player, null in clients.
-
CACHED_TILE_TAG
private static final java.lang.String CACHED_TILE_TAG
- See Also:
- Constant Field Values
-
CONNECTED_TAG
private static final java.lang.String CONNECTED_TAG
- See Also:
- Constant Field Values
-
CONTIGUITY_TAG
private static final java.lang.String CONTIGUITY_TAG
- See Also:
- Constant Field Values
-
COPIED_TAG
private static final java.lang.String COPIED_TAG
- See Also:
- Constant Field Values
-
MOVE_TO_EUROPE_TAG
private static final java.lang.String MOVE_TO_EUROPE_TAG
- See Also:
- Constant Field Values
-
OWNER_TAG
private static final java.lang.String OWNER_TAG
- See Also:
- Constant Field Values
-
OWNING_SETTLEMENT_TAG
private static final java.lang.String OWNING_SETTLEMENT_TAG
- See Also:
- Constant Field Values
-
PLAYER_TAG
private static final java.lang.String PLAYER_TAG
- See Also:
- Constant Field Values
-
REGION_TAG
private static final java.lang.String REGION_TAG
- See Also:
- Constant Field Values
-
STYLE_TAG
private static final java.lang.String STYLE_TAG
- See Also:
- Constant Field Values
-
TYPE_TAG
private static final java.lang.String TYPE_TAG
- See Also:
- Constant Field Values
-
X_TAG
private static final java.lang.String X_TAG
- See Also:
- Constant Field Values
-
Y_TAG
private static final java.lang.String Y_TAG
- See Also:
- Constant Field Values
-
OLD_PLAYER_EXPLORED_TILE_TAG
public static final java.lang.String OLD_PLAYER_EXPLORED_TILE_TAG
- See Also:
- Constant Field Values
-
OLD_TILE_ITEM_CONTAINER_TAG
public static final java.lang.String OLD_TILE_ITEM_CONTAINER_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Tile
public Tile(Game game, TileType type, int locX, int locY)
The main tile constructor.- Parameters:
game
- The enclosingGame
.type
- TheTileType
.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, java.lang.String id)
Create a newTile
with the given identifier. The object should later be initialized by calling eitherFreeColGameObject.readFromXML(FreeColXMLReader)
.- Parameters:
game
- The enclosingGame
.id
- The object identifier.
-
-
Method Detail
-
getType
public TileType getType()
Gets the type of this Tile.- Returns:
- The
TileType
.
-
setType
public void setType(TileType t)
Sets the type for this Tile. -til: Changes appearance.- Parameters:
t
- The newTileType
for thisTile
.
-
isExplored
public boolean isExplored()
Check if the tile has been explored.- Returns:
- True if this is an explored
Tile
.
-
isLand
public boolean isLand()
Is this a land tile?- Returns:
- True if this a land
Tile
.
-
isForested
public boolean isForested()
Is this a forested tile?- Returns:
- True if this is a forested
Tile
.
-
getX
public int getX()
Gets the x-coordinate of this tile.- Returns:
- The x-coordinate of this
Tile
.
-
getY
public int getY()
Gets the y-coordinate of this tile.- Returns:
- The y-coordinate of this
Tile
.
-
getMap
public Map getMap()
Get the map in which this tile belongs.- Returns:
- The enclosing
Map
.
-
getSettlement
public Settlement getSettlement()
Gets the settlement on this tile.- Specified by:
getSettlement
in interfaceLocation
- Overrides:
getSettlement
in classUnitLocation
- Returns:
- The
Settlement
that is located on thisTile
, or null if none is present. - See Also:
setSettlement(net.sf.freecol.common.model.Settlement)
-
setSettlement
public void setSettlement(Settlement settlement)
Put a settlement onto this tile. A tile can only have one settlement located on it. The settlement will also become the owner of this tile. -til: Changes appearance.- Parameters:
settlement
- ASettlement
to put on thisTile
.- See Also:
getSettlement()
-
hasSettlement
public boolean hasSettlement()
Does this tile have a settlement.- Returns:
- True if there is a settlement present.
-
getOwningSettlement
public Settlement getOwningSettlement()
Gets the owning settlement for this tile.- Returns:
- The
Settlement
that owns thisTile
. - See Also:
setOwner(net.sf.freecol.common.model.Player)
-
setOwningSettlement
public void setOwningSettlement(Settlement owner)
Sets the settlement that owns this tile. -til: Changes appearance.- Parameters:
owner
- TheSettlement
to own thisTile
.- See Also:
getOwner()
-
getTileItemContainer
public TileItemContainer getTileItemContainer()
Gets this tilesTileItemContainer
.- Returns:
- The
TileItemContainer
.
-
setTileItemContainer
public void setTileItemContainer(TileItemContainer newTileItemContainer)
Sets theTileItemContainer
.- Parameters:
newTileItemContainer
- The newTileItemContainer
value.
-
getCompleteItems
public java.util.List<TileItem> getCompleteItems()
Get the completed tile items for this tile.- Returns:
- A list of completed
TileItem
s.
-
getRegion
public Region getRegion()
Get the tile region.- Returns:
- The tile
Region
.
-
setRegion
public void setRegion(Region newRegion)
Set the tile region. -til: Changes appearance.- Parameters:
newRegion
- The newRegion
value.
-
getDiscoverableRegion
public Region getDiscoverableRegion()
Get the discoverable region of this tile.- Returns:
- Any discoverable
Region
.
-
isHighSeasConnected
public boolean isHighSeasConnected()
Gets whether this tile is connected to the high seas.- Returns:
- True if this
Tile
is connected to the high seas.
-
getHighSeasCount
public int getHighSeasCount()
Gets the high seas count.- Returns:
- The high seas count value.
-
setHighSeasCount
public void setHighSeasCount(int count)
Set the high seas count.- Parameters:
count
- The new high seas count value.
-
isCoastland
public boolean isCoastland()
Is this a land tile on the sea coast (lakes do not count).- Returns:
- True if this is a coastland tile.
-
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 theTile
.
-
isDirectlyHighSeasConnected
public boolean isDirectlyHighSeasConnected()
Can a unit move to the high seas from this tile?- Returns:
- True if a unit can move to high seas from this tile.
-
isRiverCorner
public boolean isRiverCorner()
Is this tile on a river corner?- Returns:
- True if this is a river corner.
-
getEdgeDistance
private int getEdgeDistance()
Get the minimum distance in tiles from this tile to the map edge.- Returns:
- The distance to the edge.
-
getStyle
public int getStyle()
Get the style value.- Returns:
- The
Tile
style.
-
setStyle
public void setStyle(int newStyle)
Set the tile style. -til: Changes appearance.- Parameters:
newStyle
- The new style value.
-
getContiguity
public int getContiguity()
Get the contiguity identifier for this tile.- Returns:
- A contiguity number.
-
setContiguity
public void setContiguity(int contiguity)
Sets the contiguity identifier for this tile.- Parameters:
contiguity
- A contiguity number.
-
isConnectedTo
public boolean isConnectedTo(Tile other)
Is this tile connected to another across the same contiguous piece of land or water?- Parameters:
other
- The otherTile
to check.- Returns:
- True if the
Tile
s are connected.
-
getContiguityAdjacent
public java.util.Set<Tile> getContiguityAdjacent(int contiguity)
Get the adjacent tiles that have a given contiguity.- Parameters:
contiguity
- The contiguity to search for.- Returns:
- A set of
Tile
s with the required contiguity.
-
isOnRiver
public boolean isOnRiver()
Is this tile on or adjacent to a navigable river but not the ocean.- Returns:
- True if on a navigable river.
-
isBlocked
public boolean isBlocked(Unit unit)
Quick test whether this tile is trivially blocked to moves from a unit. This is a simplification, use getMoveType().isProgress() for the full details.- Parameters:
unit
- TheUnit
to test.- Returns:
- True if the unit can not move to this tile.
-
getPlayerIndianSettlement
private Tile.IndianSettlementInternals getPlayerIndianSettlement(Player player)
Gets theIndianSettlementInternals
for the given player.- Parameters:
player
- ThePlayer
to query.- Returns:
- The
IndianSettlementInternals
for the given player, or null if none present.
-
getTileImprovements
public java.util.List<TileImprovement> getTileImprovements()
Gets a list ofTileImprovements
.- Returns:
- A list of all the
TileImprovements
.
-
getCompleteTileImprovements
public java.util.List<TileImprovement> getCompleteTileImprovements()
Gets a list of completedTileImprovements
.- Returns:
- A list of all completed
TileImprovements
.
-
hasTileImprovement
public boolean hasTileImprovement(TileImprovementType type)
Does this tile contain a completed improvement of the given type?- Parameters:
type
- TheTileImprovementType
to look for.- Returns:
- True if there is a completed improvement present.
-
getTileImprovement
public TileImprovement getTileImprovement(TileImprovementType type)
Gets the TileImprovement of a given type, or null if there is no match.- Parameters:
type
- TheTileImprovementType
to look for.- Returns:
- The
TileImprovement
of the requested type found, or null if none.
-
hasLostCityRumour
public boolean hasLostCityRumour()
Does this tile have a LCR?- Returns:
- True if this
Tile
has aLostCityRumour
on it.
-
getLostCityRumour
public LostCityRumour getLostCityRumour()
Gets a lost city rumour on this tile.- Returns:
- The
LostCityRumour
on thisTile
, or null if none found.
-
hasResource
public boolean hasResource()
Does this tile have a resource?- Returns:
- True if this is a resource
Tile
.
-
hasRiver
public boolean hasRiver()
Does this tile have a river?- Returns:
- True if this is a river
Tile
.
-
getRiver
public TileImprovement getRiver()
Gets the river on this tile.- Returns:
- A river
TileImprovement
, or null if none present.
-
getRiverStyle
public TileImprovementStyle getRiverStyle()
Gets the style of a river improvement on this tile.- Returns:
- The river
TileImprovementStyle
.
-
hasRoad
public boolean hasRoad()
Does this tile have a road?- Returns:
- True if this
Tile
has a road.
-
getRoad
public TileImprovement getRoad()
Gets the road on this tile.- Returns:
- A road
TileImprovement
, or null if none present.
-
addTileItem
private boolean addTileItem(TileItem item)
Adds a tile item to this tile. -til: Changes appearance.- Parameters:
item
- TheTileItem
to add.- Returns:
- True if the item was added.
-
removeTileItem
private <T extends TileItem> T removeTileItem(T item)
Removes a tile item from this tile. -til: Changes appearance.- Type Parameters:
T
- The actualTileItem
type.- Parameters:
item
- TheTileItem
to remove.- Returns:
- The item removed, or null on failure.
-
addLostCityRumour
public void addLostCityRumour(LostCityRumour rumour)
Adds a lost city rumour to this tile. -til: Changes appearance.- Parameters:
rumour
- TheLostCityRumour
to add.
-
removeLostCityRumour
public LostCityRumour removeLostCityRumour()
Removes the lost city rumour from thisTile
if there is one. -til: Changes appearance.- Returns:
- The removed
LostCityRumour
.
-
addRiver
public TileImprovement addRiver(int magnitude, java.lang.String conns)
Adds a new river to this tile. -til: Changes appearance.- Parameters:
magnitude
- The magnitude of the river to be createdconns
- The encoded river size/connections.- Returns:
- The new river added, or null on failure.
-
removeRiver
public void removeRiver()
Removes a river from this tile. -til: Changes appearance.
-
addRoad
public TileImprovement addRoad()
Adds a road to this tile. It is not complete. -til: Changes appearance.- Returns:
- The new road added, or the existing one.
-
removeRoad
public TileImprovement removeRoad()
Removes a road from this tile. -til: Changes appearance.- Returns:
- The removed road.
-
getResource
public Resource getResource()
Gets the resource on this tile.- Returns:
- A
Resource
, or null if none present.
-
addResource
public void addResource(Resource resource)
Adds a resource to this tile. -til: Changes appearance.- Parameters:
resource
- TheResource
to add.
-
removeResource
public Resource removeResource()
Removes a resource from this tile. -til: Changes appearance.- Returns:
- The removed
Resource
.
-
getWorkAmount
public int getWorkAmount(TileImprovementType workType)
Get the number of turns it takes for a non-expert pioneer to build the givenTileImprovementType
. It will check if it is valid for thisTileType
.- Parameters:
workType
- TheTileImprovementType
to check.- Returns:
- The number of turns it should take a non-expert pioneer to finish the work.
-
isImprovementTypeAllowed
public boolean isImprovementTypeAllowed(TileImprovementType type)
Check if a given improvement type is valid for this tile.- Parameters:
type
- TheTileImprovementType
to check.- Returns:
- True if this tile can be improved with the improvement type.
-
isImprovementAllowed
public boolean isImprovementAllowed(TileImprovement tip)
Check if a given improvement is valid for this tile.- Parameters:
tip
- TheTileImprovement
to check.- Returns:
- True if this tile can be improved with the improvement.
-
getDisasterChoices
public java.util.stream.Stream<RandomChoice<Disaster>> getDisasterChoices()
Gets a weighted list of natural disasters than can strike this tile. This list comprises all natural disasters that can strike a tile of this type or a completed tile improvement present.- Returns:
- A stream of
Disaster
choices.
-
getLabel
public StringTemplate getLabel()
Gets a description of theTile
, with the name of the tile and any improvements on it (road/plow/etc) fromTileItemContainer
.- Returns:
- The description label for this
Tile
.
-
getSimpleLabel
public StringTemplate getSimpleLabel()
Get a simple label for this tile, with just its coordinates.- Returns:
- A simple
StringTemplate
label.
-
getNearLocationLabel
private StringTemplate getNearLocationLabel(Direction direction, StringTemplate location)
Get a label for a nearby location.- Parameters:
direction
- TheDirection
from this tile to the nearby location.location
- AStringTemplate
describing the location.- Returns:
- A
StringTemplate
stating that the location is nearby.
-
getDetailedLocationLabel
private StringTemplate getDetailedLocationLabel()
Get a detailed label for this tile.- Returns:
- A suitable
StringTemplate
.
-
getDetailedLocationLabelFor
private StringTemplate getDetailedLocationLabelFor(Player player)
Get a detailed label for this tile for a given player.- Parameters:
player
- ThePlayer
to produce a label for.- Returns:
- A suitable
StringTemplate
.
-
getColonyTileLocationLabel
public StringTemplate getColonyTileLocationLabel(Colony colony)
Get a label for this tile assuming it is a colony tile of a given colony.- Parameters:
colony
- TheColony
assumed to own this tile.- Returns:
- A suitable
StringTemplate
, or null if this tile is not close enough to the colony to be a colony tile.
-
getDistanceTo
public int getDistanceTo(Tile tile)
Gets the distance in tiles between this tile and the specified one.- Parameters:
tile
- TheTile
to check the distance to.- Returns:
- The distance.
-
getDirection
public Direction getDirection(Tile tile)
Gets the direction to a neighbouring tile from this one.- Parameters:
tile
- The otherTile
.- Returns:
- The direction to the other
Tile
, or null if the other tile is not a neighbour.
-
getNeighbourOrNull
public Tile getNeighbourOrNull(Direction direction)
Get the neighbouring tile in the given direction.- Parameters:
direction
- TheDirection
to check in.- Returns:
- The neighbouring
Tile
in the givenDirection
, or null if none present.
-
isAdjacent
public boolean isAdjacent(Tile tile)
Determines whether this tile is adjacent to the specified tile.- Parameters:
tile
- A potentially adjacentTile
.- Returns:
- True if the
Tile
is adjacent to thisTile
.
-
isPolar
public boolean isPolar()
Is this tile in the polar regions?- Returns:
- True if the
Tile
is polar.
-
isLandLocked
public boolean isLandLocked()
Is this tile land locked?- Returns:
- True if land locked.
-
isShore
public boolean isShore()
Is this a shoreline tile? The tile can be water or land, and the water can be ocean, river or an inland lake. If this is true for a land tile with a colony, the colony can build docks.- Returns:
- True if this
Tile
is on the shore.
-
isGoodHillTile
public boolean isGoodHillTile()
Is this a good tile to put hills on? Used by the terrain generator.- Returns:
- True if this is a good potential hill tile.
-
isGoodMountainTile
public boolean isGoodMountainTile(TileType mountains)
Is this a good tile to put mountains on? Used by the terrain generator.- Parameters:
mountains
- The mountain tile type.- Returns:
- True if this is a good potential elevated tile.
-
isGoodRiverTile
public boolean isGoodRiverTile(TileImprovementType riverType)
Is this a good tile to start a river on? Used by the terrain generator.- Parameters:
riverType
- The riverTileImprovementType
.- Returns:
- True if this is a good place to start a river.
-
getSurroundingTiles
public java.lang.Iterable<Tile> getSurroundingTiles(int range)
Gets all the tiles surrounding a tile within the given range. The center 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)
Gets 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 thisTile
.rangeMax
- The inclusive maximum distance from thisTile
.- Returns:
- A list of the tiles surrounding this
Tile
.
-
hasUnexploredAdjacent
public boolean hasUnexploredAdjacent()
Determine whether this tile has adjacent tiles that are unexplored.- Returns:
- True if at least one neighbouring
Tile
s is unexplored.
-
getAvailableAdjacentCount
public int getAvailableAdjacentCount()
Get the number of tiles adjacent to this one that are of the same land/water type such as to be nominally accessible to a unit.- Returns:
- The number of adjacent available tiles.
-
getAdjacentColonies
public java.util.List<Colony> getAdjacentColonies()
Get the adjacent colonies.- Returns:
- A list of adjacent
Colony
s.
-
getNearestSettlement
public Settlement getNearestSettlement(Player owner, int radius, boolean same)
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.same
- If true, require the settlement to be on the same land mass.- 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.
-
getDefenceValue
public double getDefenceValue()
Get the defence value for this tile type.- Returns:
- The defence value.
-
getDefenceBonusPercentage
public int getDefenceBonusPercentage()
Get the defence bonus as a percent.- Returns:
- The percentage defence bonus.
-
getSafestSurroundingLandTiles
public java.util.List<Tile> getSafestSurroundingLandTiles(Player player)
Get a list of surrounding land tiles, sorted with the most defensible first. Useful when planning an attack.- Parameters:
player
- APlayer
to use to check for tile access.- Returns:
- A list of land
Tile
s.
-
getBestDisembarkTile
public Tile getBestDisembarkTile(Player player)
Get the adjacent land tile with the best defence bonus. Useful for incoming attackers as a disembark site.- Parameters:
player
- APlayer
to use to check for tile access.- Returns:
- The most defensible adjacent land
Tile
.
-
isDangerousToShip
public boolean isDangerousToShip(Unit ship)
Is this tile dangerous for a naval unit to enter? That is, is there an adjacent settlement that is likely to bombard it.- Parameters:
ship
- The navalUnit
to check.- Returns:
- True if moving the ship to this tile exposes it to attack.
-
getSafeAnchoringTiles
public java.util.List<Tile> getSafeAnchoringTiles(Unit unit)
Get any safe sites for a naval transport unit to stop at to disembark a unit to this tile. To be safe, the tile must be adjacent to this one but not adjacent to a dangerous settlement.- Parameters:
unit
- The transportUnit
that needs a anchoring site.- Returns:
- A list of suitable
Tile
s.
-
changeType
public void changeType(TileType type)
Changes the type of this tile. The map generator et al should just use setType(), whereas this routine should be called for the special case of a change of an existing tile type (e.g. pioneer clearing forest). -til: Changes appearance.- Parameters:
type
- The newTileType
.
-
isInUse
public boolean isInUse()
Is this tile under active use?- Returns:
- True if a
Colony
is using thisTile
.
-
changeOwningSettlement
public void changeOwningSettlement(Settlement settlement)
Changes the owning settlement for this tile. -til: Changes appearance.- Parameters:
settlement
- The new owningSettlement
for thisTile
.
-
changeOwnership
public void changeOwnership(Player player, Settlement settlement)
Change the tile ownership. Also change the owning settlement as the two are commonly related. -til: Changes appearance.- Parameters:
player
- ThePlayer
to own the tile.settlement
- TheSettlement
to own theTile
.
-
getBuildColonyWarnings
public StringTemplate getBuildColonyWarnings(Unit unit)
A colony is proposed to be built on this tile. Collect warnings if this has disadvantages.- Parameters:
unit
- TheUnit
which is to build the colony.- Returns:
- A
StringTemplate
containing the warnings, or null if none.
-
canProduce
public boolean canProduce(GoodsType goodsType, UnitType unitType)
Can this tile produce a given goods type? To produce goods either the tile type must have a suitable production type, or the tile item container contains suitable resource.- Parameters:
goodsType
- TheGoodsType
to produce.unitType
- An optionalUnitType
to use.- Returns:
- True if the tile can produce the goods.
-
getBaseProduction
public int getBaseProduction(ProductionType productionType, GoodsType goodsType, UnitType unitType)
Get the base production exclusive of any bonuses.- Parameters:
productionType
- An optionalProductionType
to use, if null the best available one is used.goodsType
- TheGoodsType
to produce.unitType
- An optionalUnitType
to use.- Returns:
- The base production due to tile type and resources.
-
getPotentialProduction
public int getPotentialProduction(GoodsType goodsType, UnitType unitType)
Get the potential production of this tile for a given goods type and optional worker type.- Parameters:
goodsType
- TheGoodsType
to check the potential for.unitType
- An optionalUnitType
to do the work.- Returns:
- The potential production of this
Tile
to produce the givenGoodsType
.
-
getProductionModifiers
public java.util.stream.Stream<Modifier> getProductionModifiers(GoodsType goodsType, UnitType unitType)
Get the production modifiers for this tile.- Parameters:
goodsType
- TheGoodsType
to produce.unitType
- An optionalUnitType
to do the work.- Returns:
- A stream of production
Modifier
s.
-
getMaximumPotential
private int getMaximumPotential(GoodsType goodsType, UnitType unitType, TileType tileType)
Gets the maximum potential for producing the given type of goods with a given unit if this tile is (perhaps changed to) a given tile type.- Parameters:
goodsType
- TheGoodsType
to check.unitType
- AUnitType
to do the work.tileType
- ATileType
to change to.- Returns:
- The maximum potential.
-
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
- TheGoodsType
to check.unitType
- AUnitType
to do the work.- Returns:
- The maximum potential.
-
getSortedPotential
public java.util.List<AbstractGoods> getSortedPotential()
Sort possible goods types according to potential.- Returns:
- A list of goods, highest potential production first.
-
getSortedPotential
public java.util.List<AbstractGoods> getSortedPotential(Unit unit)
Sort possible goods types according to potential.- Parameters:
unit
- theUnit
to work on thisTile
- Returns:
- A list of goods, highest potential production first.
-
getSortedPotential
public java.util.List<AbstractGoods> getSortedPotential(UnitType unitType, Player owner)
Sort possible goods types according to potential.- Parameters:
unitType
- TheUnitType
to do the work.owner
- thePlayer
owning the unit.- Returns:
- A list of goods, highest potential production first.
-
getBestFoodProduction
public AbstractGoods getBestFoodProduction()
Get the best food type to produce here.- Returns:
- The
AbstractGoods
to produce.
-
updateColonyTiles
private void updateColonyTiles()
Update production after a change to this tile.
-
getCachedTiles
private java.util.Map<Player,Tile> getCachedTiles()
Get the cached tile map.- Returns:
- The map of cached tiles.
-
setCachedTiles
private void setCachedTiles(java.util.Map<Player,Tile> cachedTiles)
Get the cached tile map.- Parameters:
cachedTiles
- The new map of cachedTile
s.
-
getCachedTile
private Tile getCachedTile(Player player)
Get a players view of this tile.- Parameters:
player
- ThePlayer
who owns the view.- Returns:
- The view of this
Tile
.
-
setCachedTile
public void setCachedTile(Player player, Tile tile)
Set a players view of this tile.- Parameters:
player
- ThePlayer
who owns the view.tile
- The view of theTile
(either this tile, or an uninterned copy of it).
-
seeTile
public void seeTile()
Set the players view of this tile to the tile itself if the player can see it. Useful when the cache needs to be cleared forcibly such as when a native settlement is removed.
-
seeTile
public void seeTile(Player player)
Set a players view of this tile to the tile itself.- Parameters:
player
- ThePlayer
who owns the view.
-
getTileToCache
public Tile getTileToCache()
Get a copy of this tile suitable for caching (lacking units).- Returns:
- An uninterned copy of this
Tile
.
-
cacheUnseen
public void cacheUnseen()
A change is about to occur on this tile. Cache it if unseen.
-
cacheUnseen
public void cacheUnseen(Player player)
A change is about to occur on this tile. Cache it if unseen.- Parameters:
player
- APlayer
that currently may not be able to see the tile, but will as a result of the change, and so should not cache it.
-
cacheUnseen
public void cacheUnseen(Tile copied)
A change may have occured on this tile. Establish caches where needed. Use the copied tile if supplied (which should have been created previously withgetTileToCache()
,- Parameters:
copied
- An optionalTile
to cache.
-
cacheUnseen
private void cacheUnseen(Player player, Tile copied)
A change may have occured on this tile. Establish caches where needed. Use the copied tile if supplied (which should have been created previously withgetTileToCache()
.- Parameters:
player
- APlayer
that currently may not be able to see the tile, but will as a result of the change, and so should not cache it.copied
- An optionalTile
to cache.
-
updateIndianSettlement
public void updateIndianSettlement(Player player)
Updates the information about the native settlement on thisTile
for the givenPlayer
.- Parameters:
player
- ThePlayer
.
-
removeIndianSettlementInternals
public void removeIndianSettlementInternals(Player player)
-
setIndianSettlementInternals
private void setIndianSettlementInternals(Player player, UnitType skill, java.util.List<GoodsType> wanted)
Set native settlement information. Do not check the current map state as we might leak destruction information.- Parameters:
player
- ThePlayer
to pet belonged to.skill
- The skill taught by the settlement.wanted
- The goods wanted by the settlement.
-
isExploredBy
public boolean isExploredBy(Player player)
Checks if thisTile
has been explored by the givenPlayer
. If we are in the server, then the presence of a cached tile determines whether exploration has happened. In the client there are no cached tiles, but if the tile is explored the server will have updated the client with the tile type (checked by isExplored()).- Parameters:
player
- ThePlayer
.- Returns:
- True if this
Tile
has been explored by the givenPlayer
.
-
setExplored
public void setExplored(Player player, boolean reveal)
Explore/unexplore a tile for a player.- Parameters:
player
- ThePlayer
that is exploring.reveal
- The exploration state.
-
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
- TheUnit
that would be attacking thisTile
.- Returns:
- The
Unit
that has been chosen to defend thisTile
.
-
getOccupyingUnit
public Unit getOccupyingUnit()
Gets the unit that is occupying the tile.- Returns:
- The
Unit
that is occupying thisTile
. - See Also:
isOccupied()
-
isOccupied
public boolean isOccupied()
Checks whether there is an enemy unit occupying this tile. Units can not produce in occupied tiles.- Returns:
- True if an enemy unit is occupying this
Tile
.
-
getTile
public Tile getTile()
Gets the Tile associated with this Location.- Specified by:
getTile
in interfaceLocation
- Overrides:
getTile
in classUnitLocation
- Returns:
- The Tile associated with this Location, or null if none found.
-
getLocationLabel
public StringTemplate getLocationLabel()
Get a label for this location.- Specified by:
getLocationLabel
in interfaceLocation
- Overrides:
getLocationLabel
in classUnitLocation
- Returns:
- A label for this location.
-
getLocationLabelFor
public StringTemplate getLocationLabelFor(Player player)
Get a label for this location for a particular player.- Specified by:
getLocationLabelFor
in interfaceLocation
- Overrides:
getLocationLabelFor
in classUnitLocation
- Parameters:
player
- ThePlayer
to return the name for.- Returns:
- A label for this location.
-
add
public boolean add(Locatable locatable)
Adds aLocatable
to this Location. -til: Changes appearance with TileItems.- Specified by:
add
in interfaceLocation
- Overrides:
add
in classUnitLocation
- Parameters:
locatable
- TheLocatable
to add to this Location.- Returns:
- True if the locatable was added.
-
remove
public boolean remove(Locatable locatable)
Removes aLocatable
from this Location. -til: Changes appearance with TileItems.- Specified by:
remove
in interfaceLocation
- Overrides:
remove
in classUnitLocation
- Parameters:
locatable
- TheLocatable
to remove from this Location.- Returns:
- True if the locatable was removed.
-
contains
public boolean contains(Locatable locatable)
Checks if thisLocation
contains the specifiedLocatable
.- Specified by:
contains
in interfaceLocation
- Overrides:
contains
in classUnitLocation
- Parameters:
locatable
- TheLocatable
to test the presence of.- Returns:
- True if the locatable is present at this location.
-
canAdd
public boolean canAdd(Locatable locatable)
Checks whether or not the specified locatable may be added to thisLocation
.- Specified by:
canAdd
in interfaceLocation
- Overrides:
canAdd
in classUnitLocation
- Parameters:
locatable
- TheLocatable
to add.- Returns:
- True if the locatable can be added to this location.
-
up
public Location up()
Promote this location to a more meaningful one if possible. For example: a settlement is more meaningful than the tile it occupies.
-
getRank
public int getRank()
Get a integer for this location, for the benefit of location comparators.
-
toShortString
public java.lang.String toShortString()
Get a short description of this location.- Specified by:
toShortString
in interfaceLocation
- Returns:
- A short description.
-
getNameKey
public java.lang.String getNameKey()
Gets the name of this named object. Try to avoid using this directly except in i18n-related routines or to implement itself in more complext objects.- Specified by:
getNameKey
in interfaceNamed
- Returns:
- The name of the
Named
.
-
getOwner
public Player getOwner()
Gets the owner of thisOwnable
.
-
setOwner
public void setOwner(Player owner)
Sets the owner of thisOwnable
. -til: Changes appearance.
-
disposeResources
public void disposeResources()
Dispose of the resources of this object, and finally remove it from the game. To be extended by subclasses, but they must tail call up towards this.- Overrides:
disposeResources
in classUnitLocation
-
getLinkTarget
public FreeColGameObject getLinkTarget(Player player)
Get a suitable game object to use as a clickable link in messages to a player. Objects do not have links by default, hence the null return here. However, for example, a player's colony should return itself as a link target.- Overrides:
getLinkTarget
in classFreeColGameObject
- Parameters:
player
- ThePlayer
to make a link for.- Returns:
- A suitable link target if available, although usually null.
-
checkIntegrity
public Constants.IntegrityType checkIntegrity(boolean fix, LogBuilder lb)
Checks the integrity of this game object.- Overrides:
checkIntegrity
in classFreeColGameObject
- Parameters:
fix
- If true, fix problems if possible.lb
- ALogBuilder
to log to.- Returns:
- A suitable
IntegrityType
.
-
getAbilities
public java.util.stream.Stream<Ability> getAbilities(java.lang.String id, FreeColSpecObjectType fcgot, Turn turn)
Gets the set of abilities with the given identifier from this object. Subclasses with complex ability handling should override this as all prior routines are derived from it.- Overrides:
getAbilities
in classFreeColObject
- Parameters:
id
- The object identifier.fcgot
- An optionalFreeColSpecObjectType
the ability applies to.turn
- An optional applicableTurn
.- Returns:
- A set of abilities.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classUnitLocation
- Type Parameters:
T
- TheFreeColObject
subclass of the object to copy in.- Parameters:
other
- The other object.- Returns:
- True if the copy in is succesful.
-
getDisplayObject
public FreeColObject getDisplayObject()
Get an object to display when showing the user messages for this object. Example: If this object is a Building, the object to display will be the BuildingType.- Overrides:
getDisplayObject
in classFreeColObject
- Returns:
- A suitable
FreeColObject
to display, defaults to this.
-
toXML
public void toXML(FreeColXMLWriter xw, java.lang.String tag) throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object with a specified tag to the given stream. Almost all FreeColObjects end up calling these, and implementing their own write{Attributes,Children} methods which begin by calling their superclass. This allows a clean nesting of the serialization routines throughout the class hierarchy. All attributes will be made visible.- Overrides:
toXML
in classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
to write to.tag
- The tag to use.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
internalToXML
private void internalToXML(FreeColXMLWriter xw, java.lang.String tag) throws javax.xml.stream.XMLStreamException
Fundamental (post-cache) version of toXML.- Parameters:
xw
- TheFreeColXMLWriter
to write to.tag
- The tag to use.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
writeAttributes
protected void writeAttributes(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the attributes of this object to a stream. To be overridden if required by any object that has attributes and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeAttributes
in classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
to write to.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
writeChildren
protected void writeChildren(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the children of this object to a stream. To be overridden if required by any object that has children and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeChildren
in classUnitLocation
- Parameters:
xw
- TheFreeColXMLWriter
to write to.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
readAttributes
protected void readAttributes(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.- Overrides:
readAttributes
in classFreeColGameObject
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
readChildren
protected void readChildren(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the children of this object from an XML stream.- Overrides:
readChildren
in classUnitLocation
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
readChild
protected void readChild(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads a single child object. Subclasses must override to read their enclosed elements. This particular instance of the routine always throws XMLStreamException because we should never arrive here. However it is very useful to always call super.readChild() when an unexpected tag is encountered, as the exception thrown here provides some useful debugging context.- Overrides:
readChild
in classUnitLocation
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
getXMLTagName
public java.lang.String getXMLTagName()
Get the serialization tag for this object.- Specified by:
getXMLTagName
in classFreeColObject
- Returns:
- The tag.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classFreeColObject
-
-