|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.sf.freecol.common.model.FreeColObject
net.sf.freecol.common.model.FreeColGameObject
net.sf.freecol.common.model.Tile
public final class Tile
Represents a single tile on the Map.
Map| Field Summary | |
|---|---|
private boolean |
connected
Whether this tile is connected to Europe. |
private static java.util.logging.Logger |
logger
|
private java.lang.Boolean |
moveToEurope
Describe moveToEurope here. |
private Player |
owner
The player that consider this tile to be their land. |
private Settlement |
owningSettlement
Indicates which colony or Indian settlement that owns this tile ('null' indicates no owner). |
private java.util.Map<Player,PlayerExploredTile> |
playerExploredTiles
Stores each player's image of this tile. |
private Region |
region
Describe region here. |
private Settlement |
settlement
A pointer to the settlement located on this tile or 'null' if there is no settlement on this tile. |
private int |
style
Describe style here. |
private TileItemContainer |
tileItemContainer
Stores all Improvements and Resources (if any) |
private TileType |
type
|
static java.lang.String |
UNIT_CHANGE
|
private java.util.List<Unit> |
units
Stores all Units (if any). |
private static java.lang.String |
UNITS_TAG_NAME
|
private int |
x
|
private int |
y
|
| Fields inherited from class net.sf.freecol.common.model.FreeColObject |
|---|
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE |
| Constructor Summary | |
|---|---|
Tile(Game game,
org.w3c.dom.Element e)
Initialize this object from an XML-representation of this object. |
|
Tile(Game game,
java.lang.String id)
Initiates a new Tile with the given ID. |
|
Tile(Game game,
TileType type,
int locX,
int locY)
A constructor to use. |
|
Tile(Game game,
javax.xml.stream.XMLStreamReader in)
Initialize this object from an XML-representation of this object. |
|
| Method Summary | |
|---|---|
void |
add(Locatable locatable)
Adds a Locatable to this Location. |
void |
addUnitNoUpdate(Unit unit)
Adds the unit to the tile. |
boolean |
canAdd(Locatable locatable)
Checks whether or not the specified locatable may be added to this Location. |
boolean |
canGetRoad()
Checks whether this Tile can have a road or not. |
boolean |
canMoveToEurope()
Get the MoveToEurope value. |
boolean |
claimable(Player player)
Can the ownership of this tile be claimed? Quick test that does not handle the curly case of tile transfer between colonies, or guarantee success (natives may want to be paid), but just that success is possible. |
boolean |
contains(Locatable locatable)
Checks if this Tile contains the specified
Locatable. |
private void |
createPlayerExploredTile(Player player)
Creates a PlayerExploredTile for the given
Player. |
void |
dispose()
Removes all references to this object. |
void |
disposeAllUnits()
Disposes all units on this Tile. |
void |
expendResource(GoodsType goodsType,
UnitType unitType,
Settlement settlement)
This method is called only when a new turn is beginning. |
TileImprovement |
findTileImprovementType(TileImprovementType type)
Finds the TileImprovement of a given Type, or null if there is no match. |
Colony |
getColony()
Gets the Colony located on this Tile. |
java.util.List<TileImprovement> |
getCompletedTileImprovements()
Returns a List of completed TileImprovements. |
Unit |
getDefendingUnit(Unit attacker)
Gets the Unit that is currently defending this
Tile. |
Region |
getDiscoverableRegion()
Return the discoverable Region of this Tile, or null if there is none. |
int |
getDistanceTo(Tile tile)
Gets the distance in tiles between this Tile and the
specified one. |
Unit |
getFirstUnit()
Gets the first Unit on this tile. |
GoodsContainer |
getGoodsContainer()
Returns null. |
Unit |
getLastUnit()
Gets the last Unit on this tile. |
LostCityRumour |
getLostCityRumour()
Returns the lost city rumour on this Tile if any |
Map |
getMap()
Gets the Map in which this Tile belongs. |
int |
getMaximumPotential(GoodsType goodsType,
UnitType unitType)
Gets the maximum potential for producing the given type of goods. |
Unit |
getMovableUnit()
Gets a Unit that can become active. |
int |
getMoveCost(Tile fromTile)
Returns the cost of moving onto this tile from a given Tile. |
Tile |
getNeighbourOrNull(Map.Direction d)
Describe getNeighbourOrNull method here. |
Unit |
getOccupyingUnit()
Returns the unit who is occupying the tile |
Player |
getOwner()
The nation that consider this tile to be their property. |
Settlement |
getOwningSettlement()
Gets the owner of this tile. |
PlayerExploredTile |
getPlayerExploredTile(Player player)
Gets the PlayerExploredTile for the given
Player. |
Map.Position |
getPosition()
Gets the Position of this Tile. |
java.util.Set<Modifier> |
getProductionBonus(GoodsType goodsType,
UnitType unitType)
Describe getProductionBonus method here. |
Region |
getRegion()
Get the Region value. |
TileImprovement |
getRiver()
Returns the river on this Tile if any |
int |
getRiverStyle()
Returns the style of a river TileImprovement on this Tile. |
TileImprovement |
getRoad()
Returns the road on this tile, if there is one, and null otherwise. |
Settlement |
getSettlement()
Gets the Settlement located on this Tile. |
java.util.List<AbstractGoods> |
getSortedPotential()
Sorts GoodsTypes according to potential based on TileType, TileItemContainer if any. |
java.util.List<AbstractGoods> |
getSortedPotential(Unit unit)
Sorts GoodsTypes according to potential based on TileType, TileItemContainer if any. |
java.util.List<AbstractGoods> |
getSortedPotential(UnitType unitType,
Player owner)
Sorts GoodsTypes according to potential based on TileType, TileItemContainer if any. |
int |
getStyle()
Get the Style value. |
Tile |
getTile()
Gets the Tile where this Location is
located or null if no Tile applies. |
java.util.List<TileImprovement> |
getTileImprovements()
Returns a List of TileImprovements. |
TileItemContainer |
getTileItemContainer()
Returns the TileItemContainer. |
static int |
getTileTypePotential(TileType tileType,
GoodsType goodsType,
TileItemContainer tiContainer,
UnitType unitType)
Calculates the potential of a certain GoodsType. |
int |
getTotalUnitCount()
Returns the total amount of Units at this Location. |
TileType |
getType()
Returns the type of this Tile. |
int |
getUnitCount()
Returns the amount of units at this Location. |
java.util.Iterator<Unit> |
getUnitIterator()
Gets an Iterator of every Unit directly
located on this Tile. |
java.util.List<Unit> |
getUnitList()
Gets a List/code> of every |
int |
getWorkAmount(TileImprovementType workType)
Returns the number of turns it takes for a non-expert pioneer to perform the given TileImprovementType. |
int |
getX()
Returns the x-coordinate of this Tile. |
static java.lang.String |
getXMLElementTagName()
Returns the tag name of the root element representing this object. |
int |
getY()
Returns the y-coordinate of this Tile. |
boolean |
hasImprovement(TileImprovementType type)
Will check whether this tile has a completed improvement of the given type. |
boolean |
hasLostCityRumour()
Returns true if this Tile has a lostCityRumour on it. |
boolean |
hasResource()
Returns true if this Tile has a resource on it. |
boolean |
hasRiver()
Returns true if this Tile has a River. |
boolean |
hasRoad()
Returns true if this Tile has a road. |
boolean |
hasUnexploredAdjacent()
Determine whether this tile has adjacent tiles that are unexplored. |
boolean |
isAdjacent(Tile tile)
Determines whether this tile is adjacent to the specified tile. |
boolean |
isCoast()
Returns true if this tile has at least one adjacent land tile (if water), or at least one adjacent water tile (if land). |
boolean |
isColonizeable()
Check to see if this tile can be used to construct a new Colony. |
boolean |
isConnected()
Whether this tile is connected to Europe. |
boolean |
isExplored()
Check if the tile has been explored. |
boolean |
isExploredBy(Player player)
Checks if this Tile has been explored by the given
Player. |
boolean |
isForested()
Returns true if this Tile is forested. |
boolean |
isLand()
Returns true if this Tile is a land Tile, 'false' otherwise. |
boolean |
isOccupied()
Checks whether there is a fortified enemy unit in the tile. |
boolean |
isSettleable()
Check if the tile type is suitable for a Settlement,
either by a Colony or an IndianSettlement. |
boolean |
isViewShared()
|
int |
potential(GoodsType goodsType,
UnitType unitType)
The potential of this tile to produce a certain type of goods. |
GoodsType |
primaryGoods()
The type of primary good (food) this tile produces best (used for Town Commons squares). |
protected void |
readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
Initialize this object from an XML-representation of this object. |
void |
remove(Locatable locatable)
Removes a Locatable from this Location. |
void |
removeLostCityRumour()
Removes the lost city rumour from this Tile if there
is one. |
void |
removeUnitNoUpdate(Unit unit)
Removes the unit from the tile. |
GoodsType |
secondaryGoods()
The type of secondary good (non-food) this tile produces best (used for Town Commons squares). |
void |
setConnected(boolean newConnected)
Set the Connected value. |
void |
setExploredBy(Player player,
boolean explored)
Sets this Tile to be explored by the given
Player. |
void |
setMoveToEurope(java.lang.Boolean newMoveToEurope)
Set the MoveToEurope value. |
void |
setOwner(Player owner)
Sets the nation that should consider this tile to be their property. |
void |
setOwningSettlement(Settlement owner)
Sets the owner of this tile. |
void |
setRegion(Region newRegion)
Set the Region value. |
void |
setResource(ResourceType r)
Sets the Resource for this Tile |
void |
setSettlement(Settlement s)
Puts a Settlement on this Tile. |
void |
setStyle(int newStyle)
Set the Style value. |
void |
setTileItemContainer(TileItemContainer newTileItemContainer)
Sets the TileItemContainer. |
void |
setType(TileType t)
Sets the type for this Tile. |
java.lang.String |
toString()
Returns a String representation of this Tile. |
protected void |
toXMLImpl(javax.xml.stream.XMLStreamWriter out,
Player player,
boolean showAll,
boolean toSavedGame)
This method writes an XML-representation of this object to the given stream. |
void |
updateIndianSettlementInformation(Player player)
Updates the information about the IndianSettlement located
on this Tile. |
void |
updateIndianSettlementSkill(Player player)
Updates the skill available from the IndianSettlement
located on this Tile. |
void |
updatePlayerExploredTile(Player player)
Updates the information about this Tile for the given
Player. |
void |
updatePlayerExploredTiles()
Updates the PlayerExploredTile for each player. |
| Methods inherited from class net.sf.freecol.common.model.FreeColGameObject |
|---|
addModelMessage, addModelMessage, addModelMessage, addToRemoveElement, equals, equals, getFreeColGameObject, getFreeColGameObject, getGame, getGameOptions, getIntegerID, hashCode, hasID, isDisposed, isUninitialized, readFromXML, readFromXMLPartialByClass, setFakeID, setGame, setId, toSavedXML, toXML, toXMLImpl, toXMLPartialByClass, updateFreeColGameObject, updateID |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface net.sf.freecol.common.model.Location |
|---|
getId |
| Field Detail |
|---|
private static final java.util.logging.Logger logger
private static final java.lang.String UNITS_TAG_NAME
public static final java.lang.String UNIT_CHANGE
private TileType type
private int x
private int y
private Player owner
private Settlement settlement
private TileItemContainer tileItemContainer
private java.util.List<Unit> units
private Settlement owningSettlement
private java.util.Map<Player,PlayerExploredTile> playerExploredTiles
private Region region
private boolean connected
private java.lang.Boolean moveToEurope
private int style
| Constructor Detail |
|---|
public Tile(Game game,
TileType type,
int locX,
int locY)
game - The Game this Tile belongs to.type - The type.locX - The x-position of this tile on the map.locY - The y-position of this tile on the map.
public Tile(Game game,
javax.xml.stream.XMLStreamReader in)
throws javax.xml.stream.XMLStreamException
game - The Game this Tile should be
created in.in - The input stream containing the XML.
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.
public Tile(Game game,
org.w3c.dom.Element e)
game - The Game this Tile should be
created in.e - An XML-element that will be used to initialize this object.
public Tile(Game game,
java.lang.String id)
Tile with the given ID. The object should
later be initialized by calling either
FreeColGameObject.readFromXML(XMLStreamReader) or
FreeColObject.readFromXMLElement(Element).
game - The Game in which this object belong.id - The unique identifier for this object.| Method Detail |
|---|
public boolean isViewShared()
public Region getRegion()
Region value.
Region valuepublic void setRegion(Region newRegion)
Region value.
newRegion - The new Region value.public Region getDiscoverableRegion()
null if there is none.
Region valuepublic int getStyle()
Style value.
int valuepublic void setStyle(int newStyle)
Style value.
newStyle - The new Style value.public int getDistanceTo(Tile tile)
Tile and the
specified one.
tile - The Tile to check the distance to.
public GoodsContainer getGoodsContainer()
getGoodsContainer in interface Locationpublic TileItemContainer getTileItemContainer()
TileItemContainer.
TileItemContainer valuepublic void setTileItemContainer(TileItemContainer newTileItemContainer)
TileItemContainer.
newTileItemContainer - a TileItemContainer valuepublic java.util.List<TileImprovement> getTileImprovements()
TileImprovements.
TileImprovementspublic java.util.List<TileImprovement> getCompletedTileImprovements()
TileImprovements.
TileImprovementspublic Unit getDefendingUnit(Unit attacker)
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.
attacker - The target that would be attacking this tile.
Unit that has been chosen to defend this
tile.public int getMoveCost(Tile fromTile)
Tile.
Unit.getMoveCost(net.sf.freecol.common.model.Tile) whenever it is possible.
fromTile - The Tile the moving Unit comes
from.
Unit.getMoveCost(net.sf.freecol.common.model.Tile)public void disposeAllUnits()
Tile.
public void dispose()
FreeColGameObject
dispose in class FreeColGameObjectpublic Unit getFirstUnit()
Unit on this tile.
Unit on this tile.public Unit getLastUnit()
Unit on this tile.
Unit on this tile.public int getTotalUnitCount()
public boolean contains(Locatable locatable)
Tile contains the specified
Locatable.
contains in interface Locationlocatable - The Locatable to test the presence of.
Locatable is
on this Tile and
public Map getMap()
Map in which this Tile belongs.
Map.public boolean isConnected()
boolean valuepublic void setConnected(boolean newConnected)
Connected value.
newConnected - The new Connected value.public boolean canMoveToEurope()
MoveToEurope value.
Boolean valuepublic void setMoveToEurope(java.lang.Boolean newMoveToEurope)
MoveToEurope value.
newMoveToEurope - The new MoveToEurope value.public boolean isExplored()
public boolean isLand()
true if this Tile is a land Tile, 'false' otherwise.
true if this Tile is a land Tile, 'false' otherwise.public boolean isForested()
true if this Tile is forested.
true if this Tile is forested.public boolean hasRiver()
true if this Tile has a River.
true if this Tile has a River.public boolean hasResource()
true if this Tile has a resource on it.
true if this Tile has a resource on it.public boolean hasLostCityRumour()
true if this Tile has a lostCityRumour on it.
true if this Tile has a lostCityRumour on it.public boolean hasRoad()
true if this Tile has a road.
true if this Tile has a road.public TileImprovement getRoad()
null otherwise.
TileImprovement valuepublic TileType getType()
getType in interface Typed<TileType>public Player getOwner()
getOwner in interface Ownablepublic void setOwner(Player owner)
setOwner in interface Ownableowner - The player, new owner of this tile.getOwner()public boolean claimable(Player player)
player - The Player that may wish to claim the tile.
public TileImprovement getRiver()
Tile if any
TileImprovementpublic LostCityRumour getLostCityRumour()
Tile if any
LostCityRumour valuepublic void removeLostCityRumour()
Tile if there
is one.
public int getRiverStyle()
TileImprovement on this Tile.
int valuepublic Tile getNeighbourOrNull(Map.Direction d)
getNeighbourOrNull method here.
d - a Direction value
Tile valuepublic boolean hasUnexploredAdjacent()
public boolean isCoast()
boolean valuepublic void setSettlement(Settlement s)
Settlement on this Tile. A
Tile can only have one Settlement located
on it. The Settlement will also become the owner of this
Tile.
s - The Settlement that shall be located on this
Tile.getSettlement()public Settlement getSettlement()
Settlement located on this Tile.
Settlement that is located on this
Tile or null if no Settlement
apply.setSettlement(net.sf.freecol.common.model.Settlement)public Colony getColony()
Colony located on this Tile. Only
a convenience method for getSettlement() that makes sure that
the settlement is a colony.
getColony in interface LocationColony that is located on this
Tile or null if no Colony
apply.getSettlement()public void setOwningSettlement(Settlement owner)
Settlement become an owner
of a Tile when having workers placed on it.
owner - The Settlement that owns this tile.getOwner()public Settlement getOwningSettlement()
setOwner(net.sf.freecol.common.model.Player)public void setResource(ResourceType r)
Resource for this Tile
public void setType(TileType t)
t - The new TileType for this Tile.public int getX()
public int getY()
public Map.Position getPosition()
Position of this Tile.
Position of this Tile.public boolean isSettleable()
Settlement,
either by a Colony or an IndianSettlement.
public boolean isColonizeable()
Colony. If there is a colony here or in a tile next to
this one, it is unsuitable for colonization.
public Unit getMovableUnit()
Unit that can become active. This is preferably a
Unit not currently performing any work.
Unit with movesLeft > 0 or
null if no such Unit is located on this
Tile.public Tile getTile()
Tile where this Location is
located or null if no Tile applies.
getTile in interface LocationTile.public void add(Locatable locatable)
Locatable to this Location.
add in interface Locationlocatable - The Locatable to add to this Location.public void remove(Locatable locatable)
Locatable from this Location.
remove in interface Locationlocatable - The Locatable to remove from this
Location.public void removeUnitNoUpdate(Unit unit)
unit - The unit to be removedpublic void addUnitNoUpdate(Unit unit)
unit - The unit to be addedpublic int getUnitCount()
Location.
getUnitCount in interface LocationLocation.public java.util.List<Unit> getUnitList()
List/code> of every Unit directly located on this
Tile. This does not include Units located in a
Settlement or on another Unit on this Tile.
- Specified by:
getUnitList in interface Location
- Returns:
- The
List.
public java.util.Iterator<Unit> getUnitIterator()
Iterator of every Unit directly
located on this Tile. This does not include
Units located in a Settlement or on
another Unit on this Tile.
getUnitIterator in interface LocationIterator.public boolean canAdd(Locatable locatable)
Location.
canAdd in interface Locationlocatable - a Locatable value
boolean value
public int potential(GoodsType goodsType,
UnitType unitType)
goodsType - The type of goods to check the potential for.unitType - an UnitType value
public int getMaximumPotential(GoodsType goodsType,
UnitType unitType)
goodsType - The type of goods.unitType - an UnitType value
public java.util.Set<Modifier> getProductionBonus(GoodsType goodsType,
UnitType unitType)
getProductionBonus method here.
goodsType - a GoodsType value
Modifier valuepublic boolean canGetRoad()
Tile can have a road or not. This
method will return false if a road has already been built.
public TileImprovement findTileImprovementType(TileImprovementType type)
public boolean hasImprovement(TileImprovementType type)
type - The type to check for.
public static int getTileTypePotential(TileType tileType,
GoodsType goodsType,
TileItemContainer tiContainer,
UnitType unitType)
GoodsType.
tileType - The TileType.goodsType - The GoodsType to check the potential for.tiContainer - The TileItemContainer with any TileItems to
give bonuses.unitType - an UnitType value
The Bonus Fish to be considered if valid
public java.util.List<AbstractGoods> getSortedPotential()
public java.util.List<AbstractGoods> getSortedPotential(Unit unit)
unit - the Unit to work on this Tile
public java.util.List<AbstractGoods> getSortedPotential(UnitType unitType,
Player owner)
unitType - the UnitType to work on this Tileowner - the Player owning the unit
public GoodsType primaryGoods()
public GoodsType secondaryGoods()
public void expendResource(GoodsType goodsType,
UnitType unitType,
Settlement settlement)
Resource that is on the tile, if any and if applicable.
ResourceType,
ColonyTile.newTurn()public PlayerExploredTile getPlayerExploredTile(Player player)
PlayerExploredTile for the given
Player.
player - The Player.PlayerExploredTileprivate void createPlayerExploredTile(Player player)
PlayerExploredTile for the given
Player.
player - The Player.PlayerExploredTilepublic void updatePlayerExploredTile(Player player)
Tile for the given
Player.
player - The Player.public void updatePlayerExploredTiles()
PlayerExploredTile for each player. This
update will only be performed if the player
can see this Tile.
public boolean isExploredBy(Player player)
Tile has been explored by the given
Player.
player - The Player.
true if this Tile has been explored
by the given Player and false
otherwise.
public void setExploredBy(Player player,
boolean explored)
Tile to be explored by the given
Player.
player - The Player.explored - true if this Tile should be
explored by the given Player and
false otherwise.public void updateIndianSettlementSkill(Player player)
IndianSettlement
located on this Tile.
player - The Player which should get the updated
information.
java.lang.NullPointerException - If there is no settlement on this
Tile.
java.lang.ClassCastException - If the Settlement on this
Tile is not an
IndianSettlement.IndianSettlementpublic void updateIndianSettlementInformation(Player player)
IndianSettlement located
on this Tile.
player - The Player which should get the updated
information.
java.lang.NullPointerException - If there is no settlement on this
Tile.
java.lang.ClassCastException - If the Settlement on this
Tile is not an
IndianSettlement.IndianSettlementpublic int getWorkAmount(TileImprovementType workType)
TileImprovementType. It will check if it is valid
for this TileType.
workType - The TileImprovementType
public Unit getOccupyingUnit()
isOccupied()public boolean isOccupied()
true if an fortified enemy unit is in the tilepublic boolean isAdjacent(Tile tile)
tile - A potentially adjacent Tile.
true if the tile is adjacent to this tilepublic java.lang.String toString()
toString in class FreeColGameObject
protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out,
Player player,
boolean showAll,
boolean toSavedGame)
throws javax.xml.stream.XMLStreamException
Player will be added
to that representation if showAll is set to
false.
toXMLImpl in class FreeColGameObjectout - The target stream.player - The Player this XML-representation should be
made for, or null if
showAll == true.showAll - Only attributes visible to player will be
added to the representation if showAll is set
to false.toSavedGame - If true then information that is only
needed when saving a game is added.
javax.xml.stream.XMLStreamException - if there are any problems writing to the
stream.
protected void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
throws javax.xml.stream.XMLStreamException
readFromXMLImpl in class FreeColObjectin - The input stream with the XML.
javax.xml.stream.XMLStreamException - if a problem was encountered
during parsing.public static java.lang.String getXMLElementTagName()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||