Package net.sf.freecol.common.model
Class TileImprovementType
- 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.TileImprovementType
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>,Named,ObjectWithId
public final class TileImprovementType extends FreeColSpecObjectType
An improvement to make to a tile.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringADD_WORK_TURNS_TAGprivate intaddWorkTurnsThe number of turns to build this improvement.private java.util.Set<java.lang.String>allowedWorkersThe workers that can make this improvement.private static java.lang.StringDISASTER_TAGprivate java.util.List<RandomChoice<Disaster>>disastersThe disasters that may strike this type of tile improvement.private static java.lang.StringEXPENDED_AMOUNT_TAGprivate intexpendedAmountThe amount of the equipment expended in making this improvement.private static java.lang.StringEXPOSE_RESOURCE_PERCENT_TAGprivate intexposeResourcePercentCan this improvement expose a resource when completed? This should only apply to improvement types that change the underlying tile type (e.g.private static java.lang.StringFROM_TAGprivate intmagnitudeThe magnitude of the improvement.private static java.lang.StringMAGNITUDE_TAGprivate static java.lang.StringMOVEMENT_COST_TAGprivate intmovementCostThe change to the movement cost due to this tile improvement.private booleannaturalIs this improvement natural or man-made?private static java.lang.StringNATURAL_TAGprivate static java.lang.StringOLD_CHANGE_TAGprivate static java.lang.StringOLD_EXPENDED_EQUIPMENT_TYPE_TAGprivate static java.lang.StringOLD_EXPOSE_RESOURCE_PERCENT_TAGprivate static java.lang.StringPROBABILITY_TAGprivate static java.lang.StringREQUIRED_IMPROVEMENT_TAGprivate static java.lang.StringREQUIRED_ROLE_TAGprivate TileImprovementTyperequiredImprovementTypeAny improvement that is required before this one.private RolerequiredRoleThe role required to make this improvement.static java.lang.StringTAGprivate static java.lang.StringTILE_TYPE_CHANGE_TAGprivate java.util.Map<TileType,TileTypeChange>tileTypeChangesThe changes this improvement makes to a particular tile type.private static java.lang.StringTO_TAGprivate static java.lang.StringWORKER_TAGprivate intzIndexThe layer a TileItem belongs to.private static java.lang.StringZINDEX_TAG-
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 Constructor Description TileImprovementType(java.lang.String id, Specification specification)Create a new tile improvement type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddAllowedWorker(java.lang.String id)Add an allowed worker identifier.private voidaddChange(TileTypeChange change)Add a tile type change.private voidaddDisaster(Disaster disaster, int probability)Add a disaster.booleanchangeContainsTarget(TileType tileType)Can this tile improvement type change a tile type to the given tile type.<T extends FreeColObject>
booleancopyIn(T other)Copy another FreeColObject into this one if it is compatible.intgetAddWorkTurns()Get the number of turns to build this tile improvement type.protected java.util.Set<java.lang.String>getAllowedWorkers()Get the set of allowed worker identifiers.intgetBonus(GoodsType goodsType)TileTypegetChange(TileType tileType)Gets the destination type of a tile type change (or null).java.util.stream.Stream<RandomChoice<Disaster>>getDisasterChoices()Get a weighted list of natural disasters than can strike this tile improvement type.protected java.util.List<RandomChoice<Disaster>>getDisasters()Get the list of disasters for this tile type.intgetExpendedAmount()Gets the amount of equipment expended in building this improvement type.intgetExposeResourcePercent()Gets the percent chance that this tile improvement can expose a resource on the tile.intgetImprovementValue(Tile tile, GoodsType goodsType)Gets the increase in production of the given GoodsType this tile improvement type would yield at a specified tile.intgetMagnitude()Get the magnitude of this tile improvement type.intgetMoveCost()Get the standard movement cost of the tile improvement type.intgetMoveCost(int originalCost)Possibly reduce the cost of moving due to this tile improvement type.AbstractGoodsgetProduction(TileType from)Gets the goods produced by applying this TileImprovementType to a Tile with the given TileType.ModifiergetProductionModifier(GoodsType goodsType)TileImprovementTypegetRequiredImprovementType()Gets the required improvement type.RolegetRequiredRole()Get the role required to perform this improvement, if any.protected java.util.Map<TileType,TileTypeChange>getTileTypeChanges()Get the tile type change map.java.lang.StringgetXMLTagName()Get the serialization tag for this object.intgetZIndex()Get the layer.booleanisChangeType()Does this tile improvement change the underlying tile type.booleanisNatural()Is this tile improvement type natural?booleanisTileTypeAllowed(TileType tileType)This will check if in principle this type of improvement can be used on this kind of tile, disregarding the current state of an actual tile.booleanisWorkerAllowed(Unit unit)Is a particular unit allowed to build this improvement? Checks both the unit type and the available equipment.private booleanisWorkerTypeAllowed(UnitType unitType)Is a particular unit type allowed to build this improvement?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 voidsetAllowedWorkers(java.util.Set<java.lang.String> allowed)Set the set of allowed worker identifiers.protected voidsetDisasters(java.util.List<RandomChoice<Disaster>> disasters)Set the list of disasters for this tile type.protected voidsetTileTypeChanges(java.util.Map<TileType,TileTypeChange> changes)Set the tile type change map.voidsetZIndex(int newZIndex)Set the layer.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
-
-
-
-
Field Detail
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
natural
private boolean natural
Is this improvement natural or man-made?
-
magnitude
private int magnitude
The magnitude of the improvement.
-
addWorkTurns
private int addWorkTurns
The number of turns to build this improvement.
-
requiredImprovementType
private TileImprovementType requiredImprovementType
Any improvement that is required before this one.
-
requiredRole
private Role requiredRole
The role required to make this improvement.
-
expendedAmount
private int expendedAmount
The amount of the equipment expended in making this improvement.
-
movementCost
private int movementCost
The change to the movement cost due to this tile improvement.
-
exposeResourcePercent
private int exposeResourcePercent
Can this improvement expose a resource when completed? This should only apply to improvement types that change the underlying tile type (e.g. clearing forests).
-
zIndex
private int zIndex
The layer a TileItem belongs to. Items with higher zIndex will be displayed above items with a lower zIndex. E.g. the LostCityRumour would be displayed above the Plow improvement.
-
allowedWorkers
private java.util.Set<java.lang.String> allowedWorkers
The workers that can make this improvement.
-
tileTypeChanges
private java.util.Map<TileType,TileTypeChange> tileTypeChanges
The changes this improvement makes to a particular tile type.
-
disasters
private java.util.List<RandomChoice<Disaster>> disasters
The disasters that may strike this type of tile improvement.
-
ADD_WORK_TURNS_TAG
private static final java.lang.String ADD_WORK_TURNS_TAG
- See Also:
- Constant Field Values
-
DISASTER_TAG
private static final java.lang.String DISASTER_TAG
- See Also:
- Constant Field Values
-
EXPENDED_AMOUNT_TAG
private static final java.lang.String EXPENDED_AMOUNT_TAG
- See Also:
- Constant Field Values
-
EXPOSE_RESOURCE_PERCENT_TAG
private static final java.lang.String EXPOSE_RESOURCE_PERCENT_TAG
- See Also:
- Constant Field Values
-
FROM_TAG
private static final java.lang.String FROM_TAG
- See Also:
- Constant Field Values
-
MAGNITUDE_TAG
private static final java.lang.String MAGNITUDE_TAG
- See Also:
- Constant Field Values
-
MOVEMENT_COST_TAG
private static final java.lang.String MOVEMENT_COST_TAG
- See Also:
- Constant Field Values
-
NATURAL_TAG
private static final java.lang.String NATURAL_TAG
- See Also:
- Constant Field Values
-
PROBABILITY_TAG
private static final java.lang.String PROBABILITY_TAG
- See Also:
- Constant Field Values
-
REQUIRED_IMPROVEMENT_TAG
private static final java.lang.String REQUIRED_IMPROVEMENT_TAG
- See Also:
- Constant Field Values
-
REQUIRED_ROLE_TAG
private static final java.lang.String REQUIRED_ROLE_TAG
- See Also:
- Constant Field Values
-
TILE_TYPE_CHANGE_TAG
private static final java.lang.String TILE_TYPE_CHANGE_TAG
- See Also:
- Constant Field Values
-
TO_TAG
private static final java.lang.String TO_TAG
- See Also:
- Constant Field Values
-
WORKER_TAG
private static final java.lang.String WORKER_TAG
- See Also:
- Constant Field Values
-
ZINDEX_TAG
private static final java.lang.String ZINDEX_TAG
- See Also:
- Constant Field Values
-
OLD_EXPENDED_EQUIPMENT_TYPE_TAG
private static final java.lang.String OLD_EXPENDED_EQUIPMENT_TYPE_TAG
- See Also:
- Constant Field Values
-
OLD_EXPOSE_RESOURCE_PERCENT_TAG
private static final java.lang.String OLD_EXPOSE_RESOURCE_PERCENT_TAG
- See Also:
- Constant Field Values
-
OLD_CHANGE_TAG
private static final java.lang.String OLD_CHANGE_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TileImprovementType
public TileImprovementType(java.lang.String id, Specification specification)Create a new tile improvement type.- Parameters:
id- The object identifier.specification- TheSpecificationto refer to.
-
-
Method Detail
-
isNatural
public boolean isNatural()
Is this tile improvement type natural?- Returns:
- True if this is a natural tile improvement type.
-
getMagnitude
public int getMagnitude()
Get the magnitude of this tile improvement type.- Returns:
- The magnitude.
-
getAddWorkTurns
public int getAddWorkTurns()
Get the number of turns to build this tile improvement type.- Returns:
- The number of build turns.
-
getRequiredImprovementType
public TileImprovementType getRequiredImprovementType()
Gets the required improvement type.- Returns:
- The required improvement type if any.
-
getRequiredRole
public Role getRequiredRole()
Get the role required to perform this improvement, if any.- Returns:
- The required
Role.
-
getExpendedAmount
public int getExpendedAmount()
Gets the amount of equipment expended in building this improvement type.- Returns:
- The expended equipment amount, if any.
-
getMoveCost
public int getMoveCost()
Get the standard movement cost of the tile improvement type.- Returns:
- The movement cost.
-
getMoveCost
public int getMoveCost(int originalCost)
Possibly reduce the cost of moving due to this tile improvement type. Only applies if movementCost is positive (see spec). Do not return zero from a movement costing routine or units get free moves!- Parameters:
originalCost- The original movement cost.- Returns:
- The movement cost after any change.
-
getExposeResourcePercent
public int getExposeResourcePercent()
Gets the percent chance that this tile improvement can expose a resource on the tile. This only applies to TileImprovementTypes that change the underlying tile type (e.g. clearing forests).- Returns:
- The exposure chance.
-
getZIndex
public int getZIndex()
Get the layer.- Returns:
- The layer.
-
setZIndex
public void setZIndex(int newZIndex)
Set the layer.- Parameters:
newZIndex- The new layer.
-
getAllowedWorkers
protected java.util.Set<java.lang.String> getAllowedWorkers()
Get the set of allowed worker identifiers.- Returns:
- The set of allowed worker identifiers.
-
setAllowedWorkers
protected void setAllowedWorkers(java.util.Set<java.lang.String> allowed)
Set the set of allowed worker identifiers.- Parameters:
allowed- The new set of allowed worker identifiers.
-
addAllowedWorker
private void addAllowedWorker(java.lang.String id)
Add an allowed worker identifier.- Parameters:
id- The worker identifier to add.
-
isWorkerTypeAllowed
private boolean isWorkerTypeAllowed(UnitType unitType)
Is a particular unit type allowed to build this improvement?- Parameters:
unitType- TheUnitTypeto check.- Returns:
- True if the
UnitTypecan build this improvement.
-
isWorkerAllowed
public boolean isWorkerAllowed(Unit unit)
Is a particular unit allowed to build this improvement? Checks both the unit type and the available equipment.- Parameters:
unit- TheUnitto check.- Returns:
- True if the
Unitcan build this improvement.
-
isTileTypeAllowed
public boolean isTileTypeAllowed(TileType tileType)
This will check if in principle this type of improvement can be used on this kind of tile, disregarding the current state of an actual tile. If you want to find out if an improvement is allowed for a tile, callTile.isImprovementAllowed(TileImprovement).- Parameters:
tileType- TheTileTypeto check.- Returns:
- True if improvement is possible.
-
getBonus
public int getBonus(GoodsType goodsType)
-
getTileTypeChanges
protected java.util.Map<TileType,TileTypeChange> getTileTypeChanges()
Get the tile type change map.- Returns:
- The map of tile type to changes.
-
setTileTypeChanges
protected void setTileTypeChanges(java.util.Map<TileType,TileTypeChange> changes)
Set the tile type change map.- Parameters:
changes- A new map of tile type to changes.
-
isChangeType
public boolean isChangeType()
Does this tile improvement change the underlying tile type.- Returns:
- True if this tile improvement changes the tile type.
-
getProduction
public AbstractGoods getProduction(TileType from)
Gets the goods produced by applying this TileImprovementType to a Tile with the given TileType.- Parameters:
from- The originalTileType.- Returns:
- The
AbstractGoodsproduced.
-
getChange
public TileType getChange(TileType tileType)
Gets the destination type of a tile type change (or null).- Parameters:
tileType- TheTileTypethat is to change.- Returns:
- The resulting
TileType.
-
changeContainsTarget
public boolean changeContainsTarget(TileType tileType)
Can this tile improvement type change a tile type to the given tile type.- Parameters:
tileType- The requiredTileType.- Returns:
- True if the required
TileTypecan be changed to.
-
addChange
private void addChange(TileTypeChange change)
Add a tile type change.- Parameters:
change- TheTileTypeChangeto add.
-
getImprovementValue
public int getImprovementValue(Tile tile, GoodsType goodsType)
Gets the increase in production of the given GoodsType this tile improvement type would yield at a specified tile.- Parameters:
tile- TheTileto be considered.goodsType- An optional preferredGoodsType.- Returns:
- The increase in production
-
getDisasters
protected java.util.List<RandomChoice<Disaster>> getDisasters()
Get the list of disasters for this tile type.- Returns:
- The disaster list.
-
setDisasters
protected void setDisasters(java.util.List<RandomChoice<Disaster>> disasters)
Set the list of disasters for this tile type.- Parameters:
disasters- The new list ofDisasters.
-
getDisasterChoices
public java.util.stream.Stream<RandomChoice<Disaster>> getDisasterChoices()
Get a weighted list of natural disasters than can strike this tile improvement 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.
-
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.
-
-