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 classTileType.RangeType
-
Field Summary
Fields Modifier and Type Field Description private int[]altitudeThe altitude range for this tile type.private static java.lang.StringALTITUDE_MAX_TAGprivate static java.lang.StringALTITUDE_MIN_TAGprivate static java.lang.StringBASIC_MOVE_COST_TAGprivate static java.lang.StringBASIC_WORK_TURNS_TAGprivate intbasicMoveCostThe base movement cost for this tile type.private intbasicWorkTurnsThe base work turns for this tile type.private static java.lang.StringCAN_SETTLE_TAGprivate booleancanSettleCan this tile be settled?private booleanconnectedWhether this TileType is connected to Europe.private static java.lang.StringDISASTER_TAGprivate java.util.List<RandomChoice<Disaster>>disastersThe disasters that may strike this type of tile.private booleanelevationIs this elevated terrain?private booleanforestIs this a forested tile?private static java.lang.StringGEN_TAGprivate static java.lang.StringGOODS_TYPE_TAGprivate int[]humidityThe humidity range for this tile type.private static java.lang.StringHUMIDITY_MAX_TAGprivate static java.lang.StringHUMIDITY_MIN_TAGprivate static java.lang.StringIS_CONNECTED_TAGprivate static java.lang.StringIS_ELEVATION_TAGprivate static java.lang.StringIS_FOREST_TAGprivate static java.lang.StringIS_WATER_TAGstatic TileTypeLANDprivate static java.lang.StringOLD_ALTITUDE_MAX_TAGprivate static java.lang.StringOLD_ALTITUDE_MIN_TAGprivate static java.lang.StringOLD_HUMIDITY_MAX_TAGprivate static java.lang.StringOLD_HUMIDITY_MIN_TAGprivate static java.lang.StringOLD_TEMPERATURE_MAX_TAGprivate static java.lang.StringOLD_TEMPERATURE_MIN_TAGprivate static java.lang.StringPRIMARY_PRODUCTION_TAGprivate static java.lang.StringPROBABILITY_TAGprivate static java.lang.StringPRODUCTION_TAGprivate java.util.List<ProductionType>productionTypesThe possible production types of this tile type.private static java.lang.StringRESOURCE_TAGprivate java.util.List<RandomChoice<ResourceType>>resourceTypesThe resource types that are valid for this tile type.private static java.lang.StringSECONDARY_PRODUCTION_TAGstatic java.lang.StringTAGprivate int[]temperatureThe temperature range for this tile type.private static java.lang.StringTEMPERATURE_MAX_TAGprivate static java.lang.StringTEMPERATURE_MIN_TAGprivate static java.lang.StringTYPE_TAGprivate booleanwaterIs this a water tile?static TileTypeWATERUse 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 privateTileType(java.lang.String id, boolean water)Creates a newTileTypeinstance.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 voidaddDisaster(Disaster disaster, int probability)Add a disaster.private voidaddResourceType(ResourceType type, int prob)Add a resource type.booleancanHaveResourceType(ResourceType resourceType)Can this tile type contain a specified resource type?booleancanProduce(GoodsType goodsType, UnitType unitType)Can a tile of this type produce a given goods type?booleancanSettle()Can this tile type be settled?<T extends FreeColObject>
booleancopyIn(T other)Copy another FreeColObject into this one if it is compatible.protected intgetAltitude(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.intgetBasicMoveCost()Gets the basic movement cost through this tile type.intgetBasicWorkTurns()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 intgetHumidity(int i)java.util.stream.Stream<AbstractGoods>getPossibleProduction(boolean unattended)Get all possible goods produced at a tile of this type.intgetPotentialProduction(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 intgetTemperature(int i)java.lang.StringgetXMLTagName()Get the serialization tag for this object.booleanisDirectlyHighSeasConnected()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.booleanisElevation()Is this an elevated tile type?booleanisForested()Is this tile type forested?booleanisHighSeasConnected()Is this tile type connected to the high seas, by definition.booleanisWater()Is this a water tile type?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.protected voidsetAltitude(int i, int value)protected voidsetDisasters(java.util.List<RandomChoice<Disaster>> disasters)Set the disaster choices.protected voidsetHumidity(int i, int value)protected voidsetProductionTypes(java.util.List<ProductionType> productionTypes)Set the production type list.protected voidsetResourceTypes(java.util.List<RandomChoice<ResourceType>> resourceTypes)Set the resource types list.protected voidsetTemperature(int i, int value)booleanwithinRange(TileType.RangeType rangeType, int value)Is this tile type suitable for a given range type value.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.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- TheSpecificationto refer to.
-
TileType
private TileType(java.lang.String id, boolean water)Creates a newTileTypeinstance. This constructor is used to create the "virtual" tile typesLANDandWATER, 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- TheRangeTypeto 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
ResourceTypes.
-
addResourceType
private void addResourceType(ResourceType type, int prob)
Add a resource type.- Parameters:
type- TheResourceTypeto 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- TheResourceTypeto test.- Returns:
- True if the
ResourceTypeis compatible.
-
getDisasters
protected java.util.List<RandomChoice<Disaster>> getDisasters()
Get the disaster choices.- Returns:
- A list of
Disasterchoices.
-
setDisasters
protected void setDisasters(java.util.List<RandomChoice<Disaster>> disasters)
Set the disaster choices.- Parameters:
disasters- The newDisasterchoice list.
-
getDisasterChoices
public java.util.stream.Stream<RandomChoice<Disaster>> getDisasterChoices()
Gets the natural disasters than can strike this tile type.- Returns:
- A stream of
Disasterchoices.
-
addDisaster
private void addDisaster(Disaster disaster, int probability)
Add a disaster.- Parameters:
disaster- TheDisasterto add.probability- The probability of the disaster.
-
getProductionTypes
protected java.util.List<ProductionType> getProductionTypes()
Get the production type list.- Returns:
- The
ProductionTypelist.
-
setProductionTypes
protected void setProductionTypes(java.util.List<ProductionType> productionTypes)
Set the production type list.- Parameters:
productionTypes- The newProductionTypelist.
-
getAvailableProductionTypes
public java.util.List<ProductionType> getAvailableProductionTypes(boolean unattended)
Gets the production types available at the current difficulty level.- Specified by:
getAvailableProductionTypesin interfaceBaseProduction- Parameters:
unattended- Whether the production is unattended.- Returns:
- A list of
ProductionTypes.
-
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
ProductionTypes.
-
canProduce
public boolean canProduce(GoodsType goodsType, UnitType unitType)
Can a tile of this type produce a given goods type?- Parameters:
goodsType- TheGoodsTypeto produce.unitType- An optionalUnitTypethat 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- TheGoodsTypeto produce.unitType- An optionalUnitTypethat 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:
copyInin classFreeColSpecObjectType- Type Parameters:
T- TheFreeColObjectsubclass 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:
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 classFreeColSpecObjectType- 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 classFreeColSpecObjectType- 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 classFreeColSpecObjectType- 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 classFreeColSpecObjectType- 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.
-
-