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 classTile.IndianSettlementInternalsInformation 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.StringCACHED_TILE_TAGprivate java.util.Map<Player,Tile>cachedTilesA map of cached tiles for each European player, null in clients.private static java.lang.StringCONNECTED_TAGprivate intcontiguityAn artificial contiguous-region number to identify connected parts of the map.private static java.lang.StringCONTIGUITY_TAGprivate static java.lang.StringCOPIED_TAGstatic java.util.Comparator<Tile>edgeDistanceComparatorComparator to sort tiles by increasing distance from the edge.static intFLAG_RECALCULATEFlag to assign to the high seas count to flag that the high seas connectivity needs recalculation after reading in the map.static intFOREST_ZINDEXstatic java.util.Comparator<Tile>highSeasComparatorComparator to find the smallest high seas count.private inthighSeasCountThe number of tiles to traverse to get to the high seas.static java.util.function.Predicate<Tile>isSeaTilePredicate to identify ordinary sea tiles.private static java.util.logging.Loggerloggerprivate static intLOW_PRODUCTION_WARNING_VALUEWarn about colonies that can not produce this amount of a building material.private static java.lang.StringMOVE_TO_EUROPE_TAGprivate java.lang.BooleanmoveToEuropeDoes this tile have an explicit moveToEurope state.static intNEAR_RADIUSThe maximum distance that will still be considered "near" when determining the location name.static java.lang.StringOLD_PLAYER_EXPLORED_TILE_TAGstatic java.lang.StringOLD_TILE_ITEM_CONTAINER_TAGstatic intOVERLAY_ZINDEXprivate PlayerownerThe player that consider this tile to be their land.private static java.lang.StringOWNER_TAGprivate static java.lang.StringOWNING_SETTLEMENT_TAGprivate SettlementowningSettlementIndicates which settlement owns this tile (null indicates no owner).private static java.lang.StringPLAYER_TAGprivate java.util.Map<Player,Tile.IndianSettlementInternals>playerIndianSettlementsA cache of native settlement internals for each European player, null in clients.private RegionregionThe region this tile is in.private static java.lang.StringREGION_TAGstatic intRESOURCE_ZINDEXstatic intRUMOUR_ZINDEXprivate SettlementsettlementThe settlement located on this tile, if any.private intstyleThe style of this Tile, as determined by adjacent tiles.private static java.lang.StringSTYLE_TAGstatic java.lang.StringTAGprivate TileItemContainertileItemContainerStores all Improvements and Resources (if any).private TileTypetypeThe type of the tile.private static java.lang.StringTYPE_TAGstatic java.lang.StringUNIT_CHANGEThis must be distinct from ColonyTile/Building.UNIT_CHANGE or the colony panel can get confused.private intxThe tile coordinates in the enclosing map.private static java.lang.StringX_TAGprivate intyThe tile coordinates in the enclosing map.private static java.lang.StringY_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 booleanadd(Locatable locatable)Adds aLocatableto this Location.voidaddLostCityRumour(LostCityRumour rumour)Adds a lost city rumour to this tile.voidaddResource(Resource resource)Adds a resource to this tile.TileImprovementaddRiver(int magnitude, java.lang.String conns)Adds a new river to this tile.TileImprovementaddRoad()Adds a road to this tile.private booleanaddTileItem(TileItem item)Adds a tile item to this tile.voidcacheUnseen()A change is about to occur on this tile.voidcacheUnseen(Player player)A change is about to occur on this tile.private voidcacheUnseen(Player player, Tile copied)A change may have occured on this tile.voidcacheUnseen(Tile copied)A change may have occured on this tile.booleancanAdd(Locatable locatable)Checks whether or not the specified locatable may be added to thisLocation.booleancanProduce(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.voidchangeOwnership(Player player, Settlement settlement)Change the tile ownership.voidchangeOwningSettlement(Settlement settlement)Changes the owning settlement for this tile.voidchangeType(TileType type)Changes the type of this tile.Constants.IntegrityTypecheckIntegrity(boolean fix, LogBuilder lb)Checks the integrity of this game object.booleancontains(Locatable locatable)Checks if thisLocationcontains the specifiedLocatable.<T extends FreeColObject>
booleancopyIn(T other)Copy another FreeColObject into this one if it is compatible.voiddisposeResources()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.intgetAvailableAdjacentCount()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.intgetBaseProduction(ProductionType productionType, GoodsType goodsType, UnitType unitType)Get the base production exclusive of any bonuses.TilegetBestDisembarkTile(Player player)Get the adjacent land tile with the best defence bonus.AbstractGoodsgetBestFoodProduction()Get the best food type to produce here.StringTemplategetBuildColonyWarnings(Unit unit)A colony is proposed to be built on this tile.private TilegetCachedTile(Player player)Get a players view of this tile.private java.util.Map<Player,Tile>getCachedTiles()Get the cached tile map.StringTemplategetColonyTileLocationLabel(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.intgetContiguity()Get the contiguity identifier for this tile.java.util.Set<Tile>getContiguityAdjacent(int contiguity)Get the adjacent tiles that have a given contiguity.intgetDefenceBonusPercentage()Get the defence bonus as a percent.doublegetDefenceValue()Get the defence value for this tile type.UnitgetDefendingUnit(Unit attacker)Gets the unit that is currently defending this tile.private StringTemplategetDetailedLocationLabel()Get a detailed label for this tile.private StringTemplategetDetailedLocationLabelFor(Player player)Get a detailed label for this tile for a given player.DirectiongetDirection(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.RegiongetDiscoverableRegion()Get the discoverable region of this tile.FreeColObjectgetDisplayObject()Get an object to display when showing the user messages for this object.intgetDistanceTo(Tile tile)Gets the distance in tiles between this tile and the specified one.private intgetEdgeDistance()Get the minimum distance in tiles from this tile to the map edge.intgetHighSeasCount()Gets the high seas count.StringTemplategetLabel()Gets a description of theTile, with the name of the tile and any improvements on it (road/plow/etc) fromTileItemContainer.UnitTypegetLearnableSkill(Player player)FreeColGameObjectgetLinkTarget(Player player)Get a suitable game object to use as a clickable link in messages to a player.StringTemplategetLocationLabel()Get a label for this location.StringTemplategetLocationLabelFor(Player player)Get a label for this location for a particular player.LostCityRumourgetLostCityRumour()Gets a lost city rumour on this tile.MapgetMap()Get the map in which this tile belongs.intgetMaximumPotential(GoodsType goodsType, UnitType unitType)Gets the maximum potential for producing the given type of goods.private intgetMaximumPotential(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.BooleangetMoveToEurope()Get the move-to-Europe state of the tile.java.lang.StringgetNameKey()Gets the name of this named object.SettlementgetNearestSettlement(Player owner, int radius, boolean same)Finds the nearest settlement to this tile.private StringTemplategetNearLocationLabel(Direction direction, StringTemplate location)Get a label for a nearby location.TilegetNeighbourOrNull(Direction direction)Get the neighbouring tile in the given direction.UnitgetOccupyingUnit()Gets the unit that is occupying the tile.PlayergetOwner()Gets the owner of thisOwnable.SettlementgetOwningSettlement()Gets the owning settlement for this tile.private Tile.IndianSettlementInternalsgetPlayerIndianSettlement(Player player)Gets theIndianSettlementInternalsfor the given player.intgetPotentialProduction(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.intgetRank()Get a integer for this location, for the benefit of location comparators.RegiongetRegion()Get the tile region.ResourcegetResource()Gets the resource on this tile.TileImprovementgetRiver()Gets the river on this tile.TileImprovementStylegetRiverStyle()Gets the style of a river improvement on this tile.TileImprovementgetRoad()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.TilegetSafeTile(Player player, java.util.Random random)Finds a safe tile to put a unit on, near to this one.SettlementgetSettlement()Gets the settlement on this tile.StringTemplategetSimpleLabel()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.intgetStyle()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.TilegetTile()Gets the Tile associated with this Location.TileImprovementgetTileImprovement(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.TileItemContainergetTileItemContainer()Gets this tilesTileItemContainer.TilegetTileToCache()Get a copy of this tile suitable for caching (lacking units).TileTypegetType()Gets the type of this Tile.java.util.List<GoodsType>getWantedGoods(Player player)intgetWorkAmount(TileImprovementType workType)Get the number of turns it takes for a non-expert pioneer to build the givenTileImprovementType.intgetX()Gets the x-coordinate of this tile.java.lang.StringgetXMLTagName()Get the serialization tag for this object.intgetY()Gets the y-coordinate of this tile.booleanhasLostCityRumour()Does this tile have a LCR?booleanhasResource()Does this tile have a resource?booleanhasRiver()Does this tile have a river?booleanhasRoad()Does this tile have a road?booleanhasSettlement()Does this tile have a settlement.booleanhasTileImprovement(TileImprovementType type)Does this tile contain a completed improvement of the given type?booleanhasUnexploredAdjacent()Determine whether this tile has adjacent tiles that are unexplored.private voidinternalToXML(FreeColXMLWriter xw, java.lang.String tag)Fundamental (post-cache) version of toXML.booleanisAdjacent(Tile tile)Determines whether this tile is adjacent to the specified tile.booleanisBlocked(Unit unit)Quick test whether this tile is trivially blocked to moves from a unit.booleanisCoastland()Is this a land tile on the sea coast (lakes do not count).booleanisConnectedTo(Tile other)Is this tile connected to another across the same contiguous piece of land or water?booleanisDangerousToShip(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.booleanisDirectlyHighSeasConnected()Can a unit move to the high seas from this tile?booleanisExplored()Check if the tile has been explored.booleanisExploredBy(Player player)Checks if thisTilehas been explored by the givenPlayer.booleanisForested()Is this a forested tile?booleanisGoodHillTile()Is this a good tile to put hills on? Used by the terrain generator.booleanisGoodMountainTile(TileType mountains)Is this a good tile to put mountains on? Used by the terrain generator.booleanisGoodRiverTile(TileImprovementType riverType)Is this a good tile to start a river on? Used by the terrain generator.booleanisHighSeasConnected()Gets whether this tile is connected to the high seas.booleanisImprovementAllowed(TileImprovement tip)Check if a given improvement is valid for this tile.booleanisImprovementTypeAllowed(TileImprovementType type)Check if a given improvement type is valid for this tile.booleanisInUse()Is this tile under active use?booleanisLand()Is this a land tile?booleanisLandLocked()Is this tile land locked?booleanisOccupied()Checks whether there is an enemy unit occupying this tile.booleanisOnRiver()Is this tile on or adjacent to a navigable river but not the ocean.booleanisPolar()Is this tile in the polar regions?booleanisRiverCorner()Is this tile on a river corner?booleanisShore()Is this a shoreline tile? The tile can be water or land, and the water can be ocean, river or an inland lake.protected voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.protected voidreadChild(FreeColXMLReader xr)Reads a single child object.protected voidreadChildren(FreeColXMLReader xr)Reads the children of this object from an XML stream.booleanremove(Locatable locatable)Removes aLocatablefrom this Location.voidremoveIndianSettlementInternals(Player player)LostCityRumourremoveLostCityRumour()Removes the lost city rumour from thisTileif there is one.ResourceremoveResource()Removes a resource from this tile.voidremoveRiver()Removes a river from this tile.TileImprovementremoveRoad()Removes a road from this tile.private <T extends TileItem>
TremoveTileItem(T item)Removes a tile item from this tile.voidseeTile()Set the players view of this tile to the tile itself if the player can see it.voidseeTile(Player player)Set a players view of this tile to the tile itself.voidsetCachedTile(Player player, Tile tile)Set a players view of this tile.private voidsetCachedTiles(java.util.Map<Player,Tile> cachedTiles)Get the cached tile map.voidsetContiguity(int contiguity)Sets the contiguity identifier for this tile.voidsetExplored(Player player, boolean reveal)Explore/unexplore a tile for a player.voidsetHighSeasCount(int count)Set the high seas count.private voidsetIndianSettlementInternals(Player player, UnitType skill, java.util.List<GoodsType> wanted)Set native settlement information.voidsetMoveToEurope(java.lang.Boolean moveToEurope)Set the move-to-Europe state of the tile.voidsetOwner(Player owner)Sets the owner of thisOwnable.voidsetOwningSettlement(Settlement owner)Sets the settlement that owns this tile.voidsetRegion(Region newRegion)Set the tile region.voidsetSettlement(Settlement settlement)Put a settlement onto this tile.voidsetStyle(int newStyle)Set the tile style.voidsetTileItemContainer(TileItemContainer newTileItemContainer)Sets theTileItemContainer.voidsetType(TileType t)Sets the type for this Tile.java.lang.StringtoShortString()Get a short description of this location.java.lang.StringtoString()voidtoXML(FreeColXMLWriter xw, java.lang.String tag)This method writes an XML-representation of this object with a specified tag to the given stream.Locationup()Promote this location to a more meaningful one if possible.private voidupdateColonyTiles()Update production after a change to this tile.voidupdateIndianSettlement(Player player)Updates the information about the native settlement on thisTilefor the givenPlayer.protected voidwriteAttributes(FreeColXMLWriter xw)Write the attributes of this object to a stream.protected voidwriteChildren(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 newTilewith 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 newTileTypefor 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:
getSettlementin interfaceLocation- Overrides:
getSettlementin classUnitLocation- Returns:
- The
Settlementthat 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- ASettlementto 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
Settlementthat 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- TheSettlementto 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 newTileItemContainervalue.
-
getCompleteItems
public java.util.List<TileItem> getCompleteItems()
Get the completed tile items for this tile.- Returns:
- A list of completed
TileItems.
-
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 newRegionvalue.
-
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
Tileis 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
Tilestyle.
-
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 otherTileto check.- Returns:
- True if the
Tiles 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
Tiles 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- TheUnitto test.- Returns:
- True if the unit can not move to this tile.
-
getPlayerIndianSettlement
private Tile.IndianSettlementInternals getPlayerIndianSettlement(Player player)
Gets theIndianSettlementInternalsfor the given player.- Parameters:
player- ThePlayerto query.- Returns:
- The
IndianSettlementInternalsfor 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- TheTileImprovementTypeto 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- TheTileImprovementTypeto look for.- Returns:
- The
TileImprovementof the requested type found, or null if none.
-
hasLostCityRumour
public boolean hasLostCityRumour()
Does this tile have a LCR?- Returns:
- True if this
Tilehas aLostCityRumouron it.
-
getLostCityRumour
public LostCityRumour getLostCityRumour()
Gets a lost city rumour on this tile.- Returns:
- The
LostCityRumouron 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
Tilehas 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- TheTileItemto 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 actualTileItemtype.- Parameters:
item- TheTileItemto 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- TheLostCityRumourto add.
-
removeLostCityRumour
public LostCityRumour removeLostCityRumour()
Removes the lost city rumour from thisTileif 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- TheResourceto 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- TheTileImprovementTypeto 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- TheTileImprovementTypeto 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- TheTileImprovementto 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
Disasterchoices.
-
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
StringTemplatelabel.
-
getNearLocationLabel
private StringTemplate getNearLocationLabel(Direction direction, StringTemplate location)
Get a label for a nearby location.- Parameters:
direction- TheDirectionfrom this tile to the nearby location.location- AStringTemplatedescribing the location.- Returns:
- A
StringTemplatestating 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- ThePlayerto 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- TheColonyassumed 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- TheTileto 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- TheDirectionto check in.- Returns:
- The neighbouring
Tilein 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
Tileis adjacent to thisTile.
-
isPolar
public boolean isPolar()
Is this tile in the polar regions?- Returns:
- True if the
Tileis 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
Tileis 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
Tiles 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
Colonys.
-
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
Tilenear 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- APlayerto use to check for tile access.- Returns:
- A list of land
Tiles.
-
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- APlayerto 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 navalUnitto 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 transportUnitthat needs a anchoring site.- Returns:
- A list of suitable
Tiles.
-
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
Colonyis using thisTile.
-
changeOwningSettlement
public void changeOwningSettlement(Settlement settlement)
Changes the owning settlement for this tile. -til: Changes appearance.- Parameters:
settlement- The new owningSettlementfor 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- ThePlayerto own the tile.settlement- TheSettlementto 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- TheUnitwhich is to build the colony.- Returns:
- A
StringTemplatecontaining 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- TheGoodsTypeto produce.unitType- An optionalUnitTypeto 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 optionalProductionTypeto use, if null the best available one is used.goodsType- TheGoodsTypeto produce.unitType- An optionalUnitTypeto 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- TheGoodsTypeto check the potential for.unitType- An optionalUnitTypeto do the work.- Returns:
- The potential production of this
Tileto produce the givenGoodsType.
-
getProductionModifiers
public java.util.stream.Stream<Modifier> getProductionModifiers(GoodsType goodsType, UnitType unitType)
Get the production modifiers for this tile.- Parameters:
goodsType- TheGoodsTypeto produce.unitType- An optionalUnitTypeto do the work.- Returns:
- A stream of production
Modifiers.
-
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- TheGoodsTypeto check.unitType- AUnitTypeto do the work.tileType- ATileTypeto 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- TheGoodsTypeto check.unitType- AUnitTypeto 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- theUnitto 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- TheUnitTypeto do the work.owner- thePlayerowning 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
AbstractGoodsto 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 cachedTiles.
-
getCachedTile
private Tile getCachedTile(Player player)
Get a players view of this tile.- Parameters:
player- ThePlayerwho 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- ThePlayerwho 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- ThePlayerwho 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- APlayerthat 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 optionalTileto 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- APlayerthat 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 optionalTileto cache.
-
updateIndianSettlement
public void updateIndianSettlement(Player player)
Updates the information about the native settlement on thisTilefor 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- ThePlayerto 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 thisTilehas 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
Tilehas been explored by the givenPlayer.
-
setExplored
public void setExplored(Player player, boolean reveal)
Explore/unexplore a tile for a player.- Parameters:
player- ThePlayerthat 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- TheUnitthat would be attacking thisTile.- Returns:
- The
Unitthat has been chosen to defend thisTile.
-
getOccupyingUnit
public Unit getOccupyingUnit()
Gets the unit that is occupying the tile.- Returns:
- The
Unitthat 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:
getTilein interfaceLocation- Overrides:
getTilein 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:
getLocationLabelin interfaceLocation- Overrides:
getLocationLabelin 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:
getLocationLabelForin interfaceLocation- Overrides:
getLocationLabelForin classUnitLocation- Parameters:
player- ThePlayerto return the name for.- Returns:
- A label for this location.
-
add
public boolean add(Locatable locatable)
Adds aLocatableto this Location. -til: Changes appearance with TileItems.- Specified by:
addin interfaceLocation- Overrides:
addin classUnitLocation- Parameters:
locatable- TheLocatableto add to this Location.- Returns:
- True if the locatable was added.
-
remove
public boolean remove(Locatable locatable)
Removes aLocatablefrom this Location. -til: Changes appearance with TileItems.- Specified by:
removein interfaceLocation- Overrides:
removein classUnitLocation- Parameters:
locatable- TheLocatableto remove from this Location.- Returns:
- True if the locatable was removed.
-
contains
public boolean contains(Locatable locatable)
Checks if thisLocationcontains the specifiedLocatable.- Specified by:
containsin interfaceLocation- Overrides:
containsin classUnitLocation- Parameters:
locatable- TheLocatableto 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:
canAddin interfaceLocation- Overrides:
canAddin classUnitLocation- Parameters:
locatable- TheLocatableto 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:
toShortStringin 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:
getNameKeyin 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:
disposeResourcesin 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:
getLinkTargetin classFreeColGameObject- Parameters:
player- ThePlayerto 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:
checkIntegrityin classFreeColGameObject- Parameters:
fix- If true, fix problems if possible.lb- ALogBuilderto 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:
getAbilitiesin classFreeColObject- Parameters:
id- The object identifier.fcgot- An optionalFreeColSpecObjectTypethe 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:
copyInin classUnitLocation- Type Parameters:
T- TheFreeColObjectsubclass 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:
getDisplayObjectin classFreeColObject- Returns:
- A suitable
FreeColObjectto 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:
toXMLin classFreeColObject- Parameters:
xw- TheFreeColXMLWriterto 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- TheFreeColXMLWriterto 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:
writeAttributesin classFreeColObject- Parameters:
xw- TheFreeColXMLWriterto 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:
writeChildrenin classUnitLocation- Parameters:
xw- TheFreeColXMLWriterto 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:
readAttributesin classFreeColGameObject- Parameters:
xr- TheFreeColXMLReaderto 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:
readChildrenin classUnitLocation- Parameters:
xr- TheFreeColXMLReaderto 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:
readChildin classUnitLocation- Parameters:
xr- TheFreeColXMLReaderto 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:
getXMLTagNamein classFreeColObject- Returns:
- The tag.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classFreeColObject
-
-