Package net.sf.freecol.common.model
Class TileImprovement
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColGameObject
-
- net.sf.freecol.common.model.TileItem
-
- net.sf.freecol.common.model.TileImprovement
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>,Locatable,Named,ObjectWithId
public class TileImprovement extends TileItem
Represents a tile improvement, such as a river or road.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringEMPTY_RIVER_STYLEstatic java.lang.StringEMPTY_ROAD_STYLEstatic intFJORD_RIVERstatic intLARGE_RIVERprivate static java.util.logging.Loggerloggerprivate intmagnitudeThe improvement magnitude.private static java.lang.StringMAGNITUDE_TAGstatic intNO_RIVERRiver magnitudesstatic intSMALL_RIVERprivate TileImprovementStylestyleImage and overlay style information for the improvement.private static java.lang.StringSTYLE_TAGstatic java.lang.StringTAGprivate static java.lang.StringTILE_TAGprivate static java.lang.StringTURNS_TAGprivate intturnsToCompleteTurns remaining until the improvement is complete, if any.private TileImprovementTypetypeThe type of this improvement.private static java.lang.StringTYPE_TAGprivate booleanvirtualWhether this is a virtual improvement granted by some structure on the tile (a Colony, for example).private static java.lang.StringVIRTUAL_TAG-
Fields inherited from class net.sf.freecol.common.model.FreeColGameObject
initialized
-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Constructor Summary
Constructors Constructor Description TileImprovement(Game game, java.lang.String id)Create a newTileImprovementwith the given identifier.TileImprovement(Game game, Tile tile, TileImprovementType type, TileImprovementStyle style)Creates a standardTileImprovement-instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intapplyBonus(GoodsType goodsType, UnitType unitType, int potential)Applies the production bonus for the given goods type and unit type to the given potential production.booleancanProduce(GoodsType goodsType, UnitType unitType)Does this tile item allow its enclosing tile to produce a given goods type?Constants.IntegrityTypecheckIntegrity(boolean fix, LogBuilder lb)Checks the integrity of this game object.<T extends FreeColObject>
booleancopyIn(T other)Copy another FreeColObject into this one if it is compatible.TileTypegetChange(TileType tileType)What type of tile does this improvement change a given type to?java.util.List<Direction>getConnectionDirections()Gets the directions that a connection can form across for this this type of improvement.java.util.Map<Direction,java.lang.Integer>getConnections()Gets a map of connection-direction to magnitude.longgetConnectionsFromStyle()Updates the connections from the current style.java.util.stream.Stream<RandomChoice<Disaster>>getDisasterChoices()Get the disaster choices available for this tile improvement.Map.LayergetLayer()Get the layer associated with this tile item.intgetMagnitude()Gets the magnitude of this improvement.intgetMoveCost(Direction direction, int moveCost)Calculates the movement cost on the basis of connected tile improvements.java.lang.StringgetNameKey()Gets the name of this named object.private ModifiergetProductionModifier(GoodsType goodsType)Gets a Modifier for the production bonus this improvement provides for a given type of goods.java.util.stream.Stream<Modifier>getProductionModifiers(GoodsType goodsType, UnitType unitType)Gets the production modifiers for the given type of goods and unit.intgetRiverConnection(Direction direction)Get the magnitude of the river branch in the given direction.TileImprovementStylegetStyle()Gets the style of this improvement.intgetTurnsToComplete()How many turns remain until this improvement is complete?TileImprovementTypegetType()Gets the type of this tile improvement.booleangetVirtual()Is this a virtual improvement?java.lang.StringgetXMLTagName()Get the serialization tag for this object.intgetZIndex()Get theZIndexvalue.booleanisComplete()Is this improvement complete?booleanisConnectedTo(Direction direction)Is this tile improvement connected to a similar improvement on a neighbouring tile? Public for the test suite.booleanisNatural()Is this a natural TileItem?booleanisRiver()Is this tile improvement a river?booleanisRoad()Is this tile improvement a road?booleanisTileTypeAllowed(TileType tileType)Is a tile type compatible with this tile item?booleanisWorkerAllowed(Unit unit)Can a unit build this improvement?protected voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.private voidsetConnected(Direction direction, boolean value)Internal helper method to set the connection status in a given direction.private voidsetConnected(Direction direction, boolean value, java.lang.String magnitude)voidsetMagnitude(int magnitude)Sets the magnitude of this improvement.voidsetRiverStyle(java.lang.String conns)Sets the river style to be as close as possible to the requested style, even when it has to create neighbouring rivers to prevent broken connections or change the magnitude.voidsetStyle(TileImprovementStyle style)Set the style of this improvement.voidsetTurnsToComplete(int turns)Sets the turns required to complete the improvement.voidsetVirtual(boolean virtual)Set the virtual status of this improvement.java.lang.StringtoString()java.lang.StringupdateRiverConnections(java.lang.String conns)Updates the connections from/to this river improvement on the basis of the expected encoded river style, as long as this would not create broken connections.java.lang.StringupdateRoadConnections(boolean connect)Updates the connections from/to this road improvement.protected voidwriteAttributes(FreeColXMLWriter xw)Write the attributes of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.TileItem
getLocation, getSpaceTaken, getTile, isInEurope, setLocation
-
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
dispose, disposeResources, equals, fundamentalDispose, getClassIndex, getDisposables, getGame, getLinkTarget, getSpecification, hashCode, intern, internId, isDisposed, isInitialized, isInternable, readFromXML, setGame, 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, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getDefenceModifiers, getDisplayObject, getFeatureContainer, getFreeColObjectClass, getFreeColObjectClassByName, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, hasAbility, hasAbility, hasAbility, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readChild, readChildren, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setId, toXML, toXML, toXMLPartial, toXMLPartial, writeChildren
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
EMPTY_RIVER_STYLE
public static final java.lang.String EMPTY_RIVER_STYLE
- See Also:
- Constant Field Values
-
EMPTY_ROAD_STYLE
public static final java.lang.String EMPTY_ROAD_STYLE
- See Also:
- Constant Field Values
-
NO_RIVER
public static final int NO_RIVER
River magnitudes- See Also:
- Constant Field Values
-
SMALL_RIVER
public static final int SMALL_RIVER
- See Also:
- Constant Field Values
-
LARGE_RIVER
public static final int LARGE_RIVER
- See Also:
- Constant Field Values
-
FJORD_RIVER
public static final int FJORD_RIVER
- See Also:
- Constant Field Values
-
type
private TileImprovementType type
The type of this improvement.
-
turnsToComplete
private int turnsToComplete
Turns remaining until the improvement is complete, if any.
-
magnitude
private int magnitude
The improvement magnitude. Default is type.getMagnitude(), but this will override.
-
style
private TileImprovementStyle style
Image and overlay style information for the improvement.
-
virtual
private boolean virtual
Whether this is a virtual improvement granted by some structure on the tile (a Colony, for example). Virtual improvements will be removed along with the structure that granted them.
-
MAGNITUDE_TAG
private static final java.lang.String MAGNITUDE_TAG
- See Also:
- Constant Field Values
-
STYLE_TAG
private static final java.lang.String STYLE_TAG
- See Also:
- Constant Field Values
-
TILE_TAG
private static final java.lang.String TILE_TAG
- See Also:
- Constant Field Values
-
TURNS_TAG
private static final java.lang.String TURNS_TAG
- See Also:
- Constant Field Values
-
TYPE_TAG
private static final java.lang.String TYPE_TAG
- See Also:
- Constant Field Values
-
VIRTUAL_TAG
private static final java.lang.String VIRTUAL_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TileImprovement
public TileImprovement(Game game, Tile tile, TileImprovementType type, TileImprovementStyle style)
Creates a standardTileImprovement-instance. This constructor asserts that the game, tile and type are valid. Does not set the style.- Parameters:
game- The enclosingGame.tile- TheTileon which this object sits.type- TheTileImprovementTypeof this improvement.style- TheTileImprovementStyleof this improvement.
-
TileImprovement
public TileImprovement(Game game, java.lang.String id)
Create a newTileImprovementwith the given identifier. The object should be initialized later.- Parameters:
game- The enclosingGame.id- The object identifier.
-
-
Method Detail
-
getType
public TileImprovementType getType()
Gets the type of this tile improvement.- Returns:
- The type of this improvement.
-
isRiver
public boolean isRiver()
Is this tile improvement a river?- Returns:
- True if this is a river improvement.
-
isRoad
public boolean isRoad()
Is this tile improvement a road?- Returns:
- True if this is a road improvement.
-
getConnectionDirections
public java.util.List<Direction> getConnectionDirections()
Gets the directions that a connection can form across for this this type of improvement. - For rivers, it is just the longSided directions. - For roads, it is all directions. - In other cases, no directions are relevant.- Returns:
- An array of relevant directions, or null if none.
-
getTurnsToComplete
public int getTurnsToComplete()
How many turns remain until this improvement is complete?- Returns:
- The current turns to completion.
-
setTurnsToComplete
public void setTurnsToComplete(int turns)
Sets the turns required to complete the improvement.- Parameters:
turns- The new turns to completion.
-
getMagnitude
public int getMagnitude()
Gets the magnitude of this improvement.- Returns:
- The magnitude of this immprovement.
-
setMagnitude
public void setMagnitude(int magnitude)
Sets the magnitude of this improvement.- Parameters:
magnitude- The new magnitude.
-
getStyle
public TileImprovementStyle getStyle()
Gets the style of this improvement.- Returns:
- The style
-
setStyle
public void setStyle(TileImprovementStyle style)
Set the style of this improvement.- Parameters:
style- The newTileImprovementStyle.
-
getVirtual
public final boolean getVirtual()
Is this a virtual improvement?- Returns:
- True if this is a virtual improvement.
-
setVirtual
public final void setVirtual(boolean virtual)
Set the virtual status of this improvement. Used for the roads in a colony center tile.- Parameters:
virtual- The new virtual value.
-
getRiverConnection
public int getRiverConnection(Direction direction)
Get the magnitude of the river branch in the given direction. Precondition: This tile improvement is a river!- Parameters:
direction- TheDirectionto check.- Returns:
- The magnitude of the river branch or 0 if there is none.
-
isConnectedTo
public boolean isConnectedTo(Direction direction)
Is this tile improvement connected to a similar improvement on a neighbouring tile? Public for the test suite.- Parameters:
direction- TheDirectionto check.- Returns:
- True if this improvement is connected.
-
setConnected
private void setConnected(Direction direction, boolean value)
Internal helper method to set the connection status in a given direction. There is no check for backwards connections on neighbouring tiles!- Parameters:
direction- TheDirectionto set.value- The new status for the connection.
-
setConnected
private void setConnected(Direction direction, boolean value, java.lang.String magnitude)
-
getConnections
public java.util.Map<Direction,java.lang.Integer> getConnections()
Gets a map of connection-direction to magnitude.- Returns:
- A map of the connections.
-
getProductionModifier
private Modifier getProductionModifier(GoodsType goodsType)
Gets a Modifier for the production bonus this improvement provides for a given type of goods.- Parameters:
goodsType- TheGoodsTypeto test.- Returns:
- A production
Modifier, or null if none applicable.
-
getMoveCost
public int getMoveCost(Direction direction, int moveCost)
Calculates the movement cost on the basis of connected tile improvements.- Parameters:
direction- TheDirectionto move.moveCost- The original movement cost.- Returns:
- The movement cost with this improvement.
-
getChange
public TileType getChange(TileType tileType)
What type of tile does this improvement change a given type to?- Parameters:
tileType- The originalTileType.- Returns:
- The
TileTypethat results from completing this improvement, or null if nothing changes.
-
isWorkerAllowed
public boolean isWorkerAllowed(Unit unit)
Can a unit build this improvement?- Parameters:
unit- AUnitto do the building.- Returns:
- True if the supplied unit can build this improvement.
-
getConnectionsFromStyle
public final long getConnectionsFromStyle()
Updates the connections from the current style. Public for the test suite.- Returns:
- The connections implied by the current style.
-
setRiverStyle
public void setRiverStyle(java.lang.String conns)
Sets the river style to be as close as possible to the requested style, even when it has to create neighbouring rivers to prevent broken connections or change the magnitude.- Parameters:
conns- The river style to set.
-
updateRiverConnections
public java.lang.String updateRiverConnections(java.lang.String conns)
Updates the connections from/to this river improvement on the basis of the expected encoded river style, as long as this would not create broken connections. Uses magnitude, not the connection strengths inside conns, when adding new connections.- Parameters:
conns- The encoded river connections, or null to disconnect.- Returns:
- The actual encoded connections found.
-
updateRoadConnections
public java.lang.String updateRoadConnections(boolean connect)
Updates the connections from/to this road improvement.- Parameters:
connect- If true, add connections, otherwise remove them.- Returns:
- A string encoding of the correct connections for this improvement.
-
getDisasterChoices
public java.util.stream.Stream<RandomChoice<Disaster>> getDisasterChoices()
Get the disaster choices available for this tile improvement.- Returns:
- A stream of
Disasterchoices.
-
getNameKey
public java.lang.String getNameKey()
Gets the name of this named object. Try to avoid using this directly except in i18n-related routines or to implement itself in more complext objects.- Specified by:
getNameKeyin interfaceNamed- Specified by:
getNameKeyin classTileItem- Returns:
- The name of the
Named.
-
getZIndex
public final int getZIndex()
Get theZIndexvalue.
-
isTileTypeAllowed
public boolean isTileTypeAllowed(TileType tileType)
Is a tile type compatible with this tile item?- Specified by:
isTileTypeAllowedin classTileItem- Parameters:
tileType- TheTileTypeto check.- Returns:
- True if the tile type is compatible.
-
applyBonus
public int applyBonus(GoodsType goodsType, UnitType unitType, int potential)
Applies the production bonus for the given goods type and unit type to the given potential production.- Specified by:
applyBonusin classTileItem- Parameters:
goodsType- TheGoodsTypeto produce.unitType- TheUnitTypethat is to work.potential- The base potential production.- Returns:
- The production with resource bonuses.
-
canProduce
public boolean canProduce(GoodsType goodsType, UnitType unitType)
Does this tile item allow its enclosing tile to produce a given goods type?- Specified by:
canProducein classTileItem- Parameters:
goodsType- TheGoodsTypeto produce.unitType- The optionalunitTypeto produce with.- Returns:
- True if this tile item produces the goods.
-
getProductionModifiers
public java.util.stream.Stream<Modifier> getProductionModifiers(GoodsType goodsType, UnitType unitType)
Gets the production modifiers for the given type of goods and unit.- Specified by:
getProductionModifiersin classTileItem- Parameters:
goodsType- TheGoodsTypeto produce.unitType- The optionalunitTypeto produce them.- Returns:
- A stream of the applicable modifiers.
-
isNatural
public boolean isNatural()
Is this a natural TileItem?
-
isComplete
public boolean isComplete()
Is this improvement complete?- Specified by:
isCompletein classTileItem- Returns:
- True if complete.
-
getLayer
public Map.Layer getLayer()
Get the layer associated with this tile item.
-
checkIntegrity
public Constants.IntegrityType checkIntegrity(boolean fix, LogBuilder lb)
Checks the integrity of this game object.- Overrides:
checkIntegrityin classTileItem- Parameters:
fix- If true, fix problems if possible.lb- ALogBuilderto log to.- Returns:
- A suitable
IntegrityType.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.
-
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.
-
readAttributes
protected void readAttributes(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.- Overrides:
readAttributesin classFreeColGameObject- 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.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classFreeColObject
-
-