Package net.sf.freecol.common.model
Class TileType
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColSpecObject
-
- net.sf.freecol.common.model.FreeColSpecObjectType
-
- net.sf.freecol.common.model.TileType
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,BaseProduction
,Named
,ObjectWithId
public final class TileType extends FreeColSpecObjectType implements BaseProduction
The types of tiles.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TileType.RangeType
-
Field Summary
Fields Modifier and Type Field Description private int[]
altitude
The altitude range for this tile type.private static java.lang.String
ALTITUDE_MAX_TAG
private static java.lang.String
ALTITUDE_MIN_TAG
private static java.lang.String
BASIC_MOVE_COST_TAG
private static java.lang.String
BASIC_WORK_TURNS_TAG
private int
basicMoveCost
The base movement cost for this tile type.private int
basicWorkTurns
The base work turns for this tile type.private static java.lang.String
CAN_SETTLE_TAG
private boolean
canSettle
Can this tile be settled?private boolean
connected
Whether this TileType is connected to Europe.private static java.lang.String
DISASTER_TAG
private java.util.List<RandomChoice<Disaster>>
disasters
The disasters that may strike this type of tile.private boolean
elevation
Is this elevated terrain?private boolean
forest
Is this a forested tile?private static java.lang.String
GEN_TAG
private static java.lang.String
GOODS_TYPE_TAG
private int[]
humidity
The humidity range for this tile type.private static java.lang.String
HUMIDITY_MAX_TAG
private static java.lang.String
HUMIDITY_MIN_TAG
private static java.lang.String
IS_CONNECTED_TAG
private static java.lang.String
IS_ELEVATION_TAG
private static java.lang.String
IS_FOREST_TAG
private static java.lang.String
IS_WATER_TAG
static TileType
LAND
private static java.lang.String
OLD_ALTITUDE_MAX_TAG
private static java.lang.String
OLD_ALTITUDE_MIN_TAG
private static java.lang.String
OLD_HUMIDITY_MAX_TAG
private static java.lang.String
OLD_HUMIDITY_MIN_TAG
private static java.lang.String
OLD_TEMPERATURE_MAX_TAG
private static java.lang.String
OLD_TEMPERATURE_MIN_TAG
private static java.lang.String
PRIMARY_PRODUCTION_TAG
private static java.lang.String
PROBABILITY_TAG
private static java.lang.String
PRODUCTION_TAG
private java.util.List<ProductionType>
productionTypes
The possible production types of this tile type.private static java.lang.String
RESOURCE_TAG
private java.util.List<RandomChoice<ResourceType>>
resourceTypes
The resource types that are valid for this tile type.private static java.lang.String
SECONDARY_PRODUCTION_TAG
static java.lang.String
TAG
private int[]
temperature
The temperature range for this tile type.private static java.lang.String
TEMPERATURE_MAX_TAG
private static java.lang.String
TEMPERATURE_MIN_TAG
private static java.lang.String
TYPE_TAG
private boolean
water
Is this a water tile?static TileType
WATER
Use these tile types only for "land maps", i.e.-
Fields inherited from class net.sf.freecol.common.model.FreeColSpecObjectType
DELETE_TAG, EXTENDS_TAG, PRESERVE_TAG
-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, logger, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Constructor Summary
Constructors Modifier Constructor Description private
TileType(java.lang.String id, boolean water)
Creates a newTileType
instance.TileType(java.lang.String id, Specification specification)
Create a new tile type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private void
addDisaster(Disaster disaster, int probability)
Add a disaster.private void
addResourceType(ResourceType type, int prob)
Add a resource type.boolean
canHaveResourceType(ResourceType resourceType)
Can this tile type contain a specified resource type?boolean
canProduce(GoodsType goodsType, UnitType unitType)
Can a tile of this type produce a given goods type?boolean
canSettle()
Can this tile type be settled?<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.protected int
getAltitude(int i)
java.util.List<ProductionType>
getAvailableProductionTypes(boolean unattended)
Gets the production types available at the current difficulty level.java.util.List<ProductionType>
getAvailableProductionTypes(boolean unattended, java.lang.String level)
Gets the production types available for the given combination of colony center tile and production level.int
getBasicMoveCost()
Gets the basic movement cost through this tile type.int
getBasicWorkTurns()
Gets the basic work turns to build an improvement on this tile type.java.util.stream.Stream<RandomChoice<Disaster>>
getDisasterChoices()
Gets the natural disasters than can strike this tile type.protected java.util.List<RandomChoice<Disaster>>
getDisasters()
Get the disaster choices.protected int
getHumidity(int i)
java.util.stream.Stream<AbstractGoods>
getPossibleProduction(boolean unattended)
Get all possible goods produced at a tile of this type.int
getPotentialProduction(GoodsType goodsType, UnitType unitType)
Get the amount of goods of given goods type the given unit type could produce on a tile of this tile type.protected java.util.List<ProductionType>
getProductionTypes()
Get the production type list.java.util.List<RandomChoice<ResourceType>>
getResourceTypes()
Gets the resources that can be placed on this tile type.java.util.List<ResourceType>
getResourceTypeValues()
Gets the resource types that can be found on this tile type.protected int
getTemperature(int i)
java.lang.String
getXMLTagName()
Get the serialization tag for this object.boolean
isDirectlyHighSeasConnected()
Is this tile type directly connected to the high seas, that is, a unit on a tile of this type can move immediately to the high seas.boolean
isElevation()
Is this an elevated tile type?boolean
isForested()
Is this tile type forested?boolean
isHighSeasConnected()
Is this tile type connected to the high seas, by definition.boolean
isWater()
Is this a water tile type?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.protected void
setAltitude(int i, int value)
protected void
setDisasters(java.util.List<RandomChoice<Disaster>> disasters)
Set the disaster choices.protected void
setHumidity(int i, int value)
protected void
setProductionTypes(java.util.List<ProductionType> productionTypes)
Set the production type list.protected void
setResourceTypes(java.util.List<RandomChoice<ResourceType>> resourceTypes)
Set the resource types list.protected void
setTemperature(int i, int value)
boolean
withinRange(TileType.RangeType rangeType, int value)
Is this tile type suitable for a given range type value.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.FreeColSpecObjectType
addScope, appliesTo, copyScopes, getDescriptionKey, getFeatureContainer, getIndex, getNameKey, getScopeList, getScopes, isAbstractType, removeScope, setIndex, toString
-
Methods inherited from class net.sf.freecol.common.model.FreeColSpecObject
getSpecification, 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, equals, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getClassIndex, getDefenceModifiers, getDisplayObject, getFreeColObjectClass, getFreeColObjectClassByName, getGame, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, hasAbility, hasAbility, hasAbility, hashCode, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readFromXML, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setGame, setId, toXML, 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.BaseProduction
getBaseProduction
-
-
-
-
Field Detail
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
WATER
public static final TileType WATER
Use these tile types only for "land maps", i.e. maps that only distinguish water and land.
-
LAND
public static final TileType LAND
-
forest
private boolean forest
Is this a forested tile?
-
water
private boolean water
Is this a water tile?
-
canSettle
private boolean canSettle
Can this tile be settled?
-
connected
private boolean connected
Whether this TileType is connected to Europe.
-
elevation
private boolean elevation
Is this elevated terrain?
-
basicMoveCost
private int basicMoveCost
The base movement cost for this tile type.
-
basicWorkTurns
private int basicWorkTurns
The base work turns for this tile type.
-
humidity
private final int[] humidity
The humidity range for this tile type.
-
temperature
private final int[] temperature
The temperature range for this tile type.
-
altitude
private final int[] altitude
The altitude range for this tile type.
-
resourceTypes
private java.util.List<RandomChoice<ResourceType>> resourceTypes
The resource types that are valid for this tile type.
-
disasters
private java.util.List<RandomChoice<Disaster>> disasters
The disasters that may strike this type of tile.
-
productionTypes
private final java.util.List<ProductionType> productionTypes
The possible production types of this tile type. This includes the production types available if a tile of this type is a colony center tile.
-
ALTITUDE_MIN_TAG
private static final java.lang.String ALTITUDE_MIN_TAG
- See Also:
- Constant Field Values
-
ALTITUDE_MAX_TAG
private static final java.lang.String ALTITUDE_MAX_TAG
- See Also:
- Constant Field Values
-
BASIC_MOVE_COST_TAG
private static final java.lang.String BASIC_MOVE_COST_TAG
- See Also:
- Constant Field Values
-
BASIC_WORK_TURNS_TAG
private static final java.lang.String BASIC_WORK_TURNS_TAG
- See Also:
- Constant Field Values
-
CAN_SETTLE_TAG
private static final java.lang.String CAN_SETTLE_TAG
- See Also:
- Constant Field Values
-
DISASTER_TAG
private static final java.lang.String DISASTER_TAG
- See Also:
- Constant Field Values
-
GEN_TAG
private static final java.lang.String GEN_TAG
- See Also:
- Constant Field Values
-
GOODS_TYPE_TAG
private static final java.lang.String GOODS_TYPE_TAG
- See Also:
- Constant Field Values
-
HUMIDITY_MIN_TAG
private static final java.lang.String HUMIDITY_MIN_TAG
- See Also:
- Constant Field Values
-
HUMIDITY_MAX_TAG
private static final java.lang.String HUMIDITY_MAX_TAG
- See Also:
- Constant Field Values
-
IS_CONNECTED_TAG
private static final java.lang.String IS_CONNECTED_TAG
- See Also:
- Constant Field Values
-
IS_ELEVATION_TAG
private static final java.lang.String IS_ELEVATION_TAG
- See Also:
- Constant Field Values
-
IS_FOREST_TAG
private static final java.lang.String IS_FOREST_TAG
- See Also:
- Constant Field Values
-
IS_WATER_TAG
private static final java.lang.String IS_WATER_TAG
- See Also:
- Constant Field Values
-
PROBABILITY_TAG
private static final java.lang.String PROBABILITY_TAG
- See Also:
- Constant Field Values
-
PRODUCTION_TAG
private static final java.lang.String PRODUCTION_TAG
- See Also:
- Constant Field Values
-
RESOURCE_TAG
private static final java.lang.String RESOURCE_TAG
- See Also:
- Constant Field Values
-
TEMPERATURE_MIN_TAG
private static final java.lang.String TEMPERATURE_MIN_TAG
- See Also:
- Constant Field Values
-
TEMPERATURE_MAX_TAG
private static final java.lang.String TEMPERATURE_MAX_TAG
- See Also:
- Constant Field Values
-
TYPE_TAG
private static final java.lang.String TYPE_TAG
- See Also:
- Constant Field Values
-
PRIMARY_PRODUCTION_TAG
private static final java.lang.String PRIMARY_PRODUCTION_TAG
- See Also:
- Constant Field Values
-
SECONDARY_PRODUCTION_TAG
private static final java.lang.String SECONDARY_PRODUCTION_TAG
- See Also:
- Constant Field Values
-
OLD_ALTITUDE_MIN_TAG
private static final java.lang.String OLD_ALTITUDE_MIN_TAG
- See Also:
- Constant Field Values
-
OLD_ALTITUDE_MAX_TAG
private static final java.lang.String OLD_ALTITUDE_MAX_TAG
- See Also:
- Constant Field Values
-
OLD_HUMIDITY_MIN_TAG
private static final java.lang.String OLD_HUMIDITY_MIN_TAG
- See Also:
- Constant Field Values
-
OLD_HUMIDITY_MAX_TAG
private static final java.lang.String OLD_HUMIDITY_MAX_TAG
- See Also:
- Constant Field Values
-
OLD_TEMPERATURE_MIN_TAG
private static final java.lang.String OLD_TEMPERATURE_MIN_TAG
- See Also:
- Constant Field Values
-
OLD_TEMPERATURE_MAX_TAG
private static final java.lang.String OLD_TEMPERATURE_MAX_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TileType
public TileType(java.lang.String id, Specification specification)
Create a new tile type.- Parameters:
id
- The object identifier.specification
- TheSpecification
to refer to.
-
TileType
private TileType(java.lang.String id, boolean water)
Creates a newTileType
instance. This constructor is used to create the "virtual" tile typesLAND
andWATER
, which are intended to simplify map loading.- Parameters:
id
- The object identifier.water
- True if this is a water tile.
-
-
Method Detail
-
isForested
public boolean isForested()
Is this tile type forested?- Returns:
- True if this is a forested tile type.
-
isWater
public boolean isWater()
Is this a water tile type?- Returns:
- True if this is a water tile type.
-
canSettle
public boolean canSettle()
Can this tile type be settled?- Returns:
- True if this is a settleable tile type.
-
isHighSeasConnected
public boolean isHighSeasConnected()
Is this tile type connected to the high seas, by definition.- Returns:
- True if the tile type is inherently connected to the high seas.
-
isDirectlyHighSeasConnected
public boolean isDirectlyHighSeasConnected()
Is this tile type directly connected to the high seas, that is, a unit on a tile of this type can move immediately to the high seas.- Returns:
- True if the tile type is directly connected.
-
isElevation
public boolean isElevation()
Is this an elevated tile type?- Returns:
- True if this is an elevated tile type.
-
getBasicMoveCost
public int getBasicMoveCost()
Gets the basic movement cost through this tile type.- Returns:
- The basic movement cost.
-
getBasicWorkTurns
public int getBasicWorkTurns()
Gets the basic work turns to build an improvement on this tile type.- Returns:
- The basic work turns.
-
getHumidity
protected int getHumidity(int i)
-
setHumidity
protected void setHumidity(int i, int value)
-
getTemperature
protected int getTemperature(int i)
-
setTemperature
protected void setTemperature(int i, int value)
-
getAltitude
protected int getAltitude(int i)
-
setAltitude
protected void setAltitude(int i, int value)
-
withinRange
public boolean withinRange(TileType.RangeType rangeType, int value)
Is this tile type suitable for a given range type value.- Parameters:
rangeType
- TheRangeType
to test.value
- The value to check.- Returns:
- True if the tile type meets the range limits.
-
getResourceTypes
public java.util.List<RandomChoice<ResourceType>> getResourceTypes()
Gets the resources that can be placed on this tile type.- Returns:
- A weighted list of resource types.
-
setResourceTypes
protected void setResourceTypes(java.util.List<RandomChoice<ResourceType>> resourceTypes)
Set the resource types list.- Parameters:
resourceTypes
- The list of resource type choices.
-
getResourceTypeValues
public java.util.List<ResourceType> getResourceTypeValues()
Gets the resource types that can be found on this tile type.- Returns:
- A list of
ResourceType
s.
-
addResourceType
private void addResourceType(ResourceType type, int prob)
Add a resource type.- Parameters:
type
- TheResourceType
to add.prob
- The percentage probability of the resource being present.
-
canHaveResourceType
public boolean canHaveResourceType(ResourceType resourceType)
Can this tile type contain a specified resource type?- Parameters:
resourceType
- TheResourceType
to test.- Returns:
- True if the
ResourceType
is compatible.
-
getDisasters
protected java.util.List<RandomChoice<Disaster>> getDisasters()
Get the disaster choices.- Returns:
- A list of
Disaster
choices.
-
setDisasters
protected void setDisasters(java.util.List<RandomChoice<Disaster>> disasters)
Set the disaster choices.- Parameters:
disasters
- The newDisaster
choice list.
-
getDisasterChoices
public java.util.stream.Stream<RandomChoice<Disaster>> getDisasterChoices()
Gets the natural disasters than can strike this tile type.- Returns:
- A stream of
Disaster
choices.
-
addDisaster
private void addDisaster(Disaster disaster, int probability)
Add a disaster.- Parameters:
disaster
- TheDisaster
to add.probability
- The probability of the disaster.
-
getProductionTypes
protected java.util.List<ProductionType> getProductionTypes()
Get the production type list.- Returns:
- The
ProductionType
list.
-
setProductionTypes
protected void setProductionTypes(java.util.List<ProductionType> productionTypes)
Set the production type list.- Parameters:
productionTypes
- The newProductionType
list.
-
getAvailableProductionTypes
public java.util.List<ProductionType> getAvailableProductionTypes(boolean unattended)
Gets the production types available at the current difficulty level.- Specified by:
getAvailableProductionTypes
in interfaceBaseProduction
- Parameters:
unattended
- Whether the production is unattended.- Returns:
- A list of
ProductionType
s.
-
getAvailableProductionTypes
public java.util.List<ProductionType> getAvailableProductionTypes(boolean unattended, java.lang.String level)
Gets the production types available for the given combination of colony center tile and production level. If the production level is null, all production levels will be returned. Public for the test suite.- Parameters:
unattended
- Whether the production is unattended.level
- The production level.- Returns:
- A list of
ProductionType
s.
-
canProduce
public boolean canProduce(GoodsType goodsType, UnitType unitType)
Can a tile of this type produce a given goods type?- Parameters:
goodsType
- TheGoodsType
to produce.unitType
- An optionalUnitType
that is to do the work, if null the unattended production is considered.- Returns:
- True if this tile type produces the goods.
-
getPotentialProduction
public int getPotentialProduction(GoodsType goodsType, UnitType unitType)
Get the amount of goods of given goods type the given unit type could produce on a tile of this tile type.- Parameters:
goodsType
- TheGoodsType
to produce.unitType
- An optionalUnitType
that is to do the work, if null the unattended production is considered.- Returns:
- The amount of goods produced.
-
getPossibleProduction
public java.util.stream.Stream<AbstractGoods> getPossibleProduction(boolean unattended)
Get all possible goods produced at a tile of this type. Used by static tile type displays that just list unattended production values. Planning and production routines should usegetPotentialProduction(GoodsType, UnitType)
- Parameters:
unattended
- Select unattended production.- Returns:
- A stream of produced
AbstractGoods
.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classFreeColSpecObjectType
- Type Parameters:
T
- TheFreeColObject
subclass of the object to copy in.- Parameters:
other
- The other object.- Returns:
- True if the copy in is succesful.
-
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 classFreeColSpecObjectType
- 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 classFreeColSpecObjectType
- 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 classFreeColSpecObjectType
- 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 classFreeColSpecObjectType
- 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.
-
-