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.String
ADD_WORK_TURNS_TAG
private int
addWorkTurns
The number of turns to build this improvement.private java.util.Set<java.lang.String>
allowedWorkers
The workers that can make this improvement.private static java.lang.String
DISASTER_TAG
private java.util.List<RandomChoice<Disaster>>
disasters
The disasters that may strike this type of tile improvement.private static java.lang.String
EXPENDED_AMOUNT_TAG
private int
expendedAmount
The amount of the equipment expended in making this improvement.private static java.lang.String
EXPOSE_RESOURCE_PERCENT_TAG
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.private static java.lang.String
FROM_TAG
private int
magnitude
The magnitude of the improvement.private static java.lang.String
MAGNITUDE_TAG
private static java.lang.String
MOVEMENT_COST_TAG
private int
movementCost
The change to the movement cost due to this tile improvement.private boolean
natural
Is this improvement natural or man-made?private static java.lang.String
NATURAL_TAG
private static java.lang.String
OLD_CHANGE_TAG
private static java.lang.String
OLD_EXPENDED_EQUIPMENT_TYPE_TAG
private static java.lang.String
OLD_EXPOSE_RESOURCE_PERCENT_TAG
private static java.lang.String
PROBABILITY_TAG
private static java.lang.String
REQUIRED_IMPROVEMENT_TAG
private static java.lang.String
REQUIRED_ROLE_TAG
private TileImprovementType
requiredImprovementType
Any improvement that is required before this one.private Role
requiredRole
The role required to make this improvement.static java.lang.String
TAG
private static java.lang.String
TILE_TYPE_CHANGE_TAG
private java.util.Map<TileType,TileTypeChange>
tileTypeChanges
The changes this improvement makes to a particular tile type.private static java.lang.String
TO_TAG
private static java.lang.String
WORKER_TAG
private int
zIndex
The layer a TileItem belongs to.private static java.lang.String
ZINDEX_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 void
addAllowedWorker(java.lang.String id)
Add an allowed worker identifier.private void
addChange(TileTypeChange change)
Add a tile type change.private void
addDisaster(Disaster disaster, int probability)
Add a disaster.boolean
changeContainsTarget(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.int
getAddWorkTurns()
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.int
getBonus(GoodsType goodsType)
TileType
getChange(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.int
getExpendedAmount()
Gets the amount of equipment expended in building this improvement type.int
getExposeResourcePercent()
Gets the percent chance that this tile improvement can expose a resource on the tile.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.int
getMagnitude()
Get the magnitude of this tile improvement type.int
getMoveCost()
Get the standard movement cost of the tile improvement type.int
getMoveCost(int originalCost)
Possibly reduce the cost of moving due to this tile improvement type.AbstractGoods
getProduction(TileType from)
Gets the goods produced by applying this TileImprovementType to a Tile with the given TileType.Modifier
getProductionModifier(GoodsType goodsType)
TileImprovementType
getRequiredImprovementType()
Gets the required improvement type.Role
getRequiredRole()
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.String
getXMLTagName()
Get the serialization tag for this object.int
getZIndex()
Get the layer.boolean
isChangeType()
Does this tile improvement change the underlying tile type.boolean
isNatural()
Is this tile improvement type natural?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.boolean
isWorkerAllowed(Unit unit)
Is a particular unit allowed to build this improvement? Checks both the unit type and the available equipment.private boolean
isWorkerTypeAllowed(UnitType unitType)
Is a particular unit type allowed to build this improvement?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
setAllowedWorkers(java.util.Set<java.lang.String> allowed)
Set the set of allowed worker identifiers.protected void
setDisasters(java.util.List<RandomChoice<Disaster>> disasters)
Set the list of disasters for this tile type.protected void
setTileTypeChanges(java.util.Map<TileType,TileTypeChange> changes)
Set the tile type change map.void
setZIndex(int newZIndex)
Set the layer.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
-
-
-
-
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
- TheSpecification
to 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
- TheUnitType
to check.- Returns:
- True if the
UnitType
can 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
- TheUnit
to check.- Returns:
- True if the
Unit
can 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
- TheTileType
to 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
AbstractGoods
produced.
-
getChange
public TileType getChange(TileType tileType)
Gets the destination type of a tile type change (or null).- Parameters:
tileType
- TheTileType
that 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
TileType
can be changed to.
-
addChange
private void addChange(TileTypeChange change)
Add a tile type change.- Parameters:
change
- TheTileTypeChange
to 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
- TheTile
to 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 ofDisaster
s.
-
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
Disaster
choices.
-
addDisaster
private void addDisaster(Disaster disaster, int probability)
Add a disaster.- Parameters:
disaster
- TheDisaster
to 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:
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.
-
-