Package net.sf.freecol.common.model
Class Resource
- 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.Resource
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,Locatable
,Named
,ObjectWithId
public class Resource extends TileItem
Represents a production resource, such as prime tobacco, or an ore vein, located on a Tile. A resource may be exhausted. In the original game, only resources that produced silver were exhausted.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.logging.Logger
logger
private int
quantity
The amount of the resource present.private static java.lang.String
QUANTITY_TAG
static java.lang.String
TAG
private static java.lang.String
TILE_TAG
private ResourceType
type
The type of resource.private static java.lang.String
TYPE_TAG
private static int
UNLIMITED
Some resources are unlimited.-
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 Resource(Game game, java.lang.String id)
Creates newResource
.Resource(Game game, Tile tile, ResourceType type)
Creates a standardResource
-instance.Resource(Game game, Tile tile, ResourceType type, int quantity)
Creates a standardResource
-instance.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.boolean
canProduce(GoodsType goodsType, UnitType unitType)
Does this tile item allow its enclosing tile to produce a given goods type?Constants.IntegrityType
checkIntegrity(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.GoodsType
getBestGoodsType()
Get the best goods type to produce here.Map.Layer
getLayer()
Get the layer associated with this tile item.java.lang.String
getNameKey()
Gets the name of this named object.java.util.stream.Stream<Modifier>
getProductionModifiers(GoodsType goodsType, UnitType unitType)
Gets the production modifiers for the given type of goods and unit.int
getQuantity()
Get the resource quantity.ResourceType
getType()
Get the type of this resource.java.lang.String
getXMLTagName()
Get the serialization tag for this object.int
getZIndex()
Get theZIndex
value.boolean
isComplete()
Is this improvement complete?boolean
isNatural()
Is this a natural TileItem?boolean
isTileTypeAllowed(TileType tileType)
Is a tile type compatible with this tile item?boolean
isUnlimited()
Is this an unlimited resource?protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.void
setQuantity(int newQuantity)
Set the resource quantity.java.lang.String
toString()
private int
useQuantity(int usedQuantity)
Reduces the available quantity.int
useQuantity(GoodsType goodsType, UnitType unitType, int potential)
Reduce the available quantity by the bonus output ofGoodsType
.protected void
writeAttributes(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
-
UNLIMITED
private static final int UNLIMITED
Some resources are unlimited.- See Also:
- Constant Field Values
-
type
private ResourceType type
The type of resource.
-
quantity
private int quantity
The amount of the resource present.
-
QUANTITY_TAG
private static final java.lang.String QUANTITY_TAG
- See Also:
- Constant Field Values
-
TILE_TAG
private static final java.lang.String TILE_TAG
- See Also:
- Constant Field Values
-
TYPE_TAG
private static final java.lang.String TYPE_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Resource
public Resource(Game game, Tile tile, ResourceType type, int quantity)
Creates a standardResource
-instance. This constructor asserts that the game, tile and type are valid.- Parameters:
game
- The enclosingGame
.tile
- TheTile
on which this object sits.type
- TheResourceType
of this Resource.quantity
- The quantity of resource.
-
Resource
public Resource(Game game, Tile tile, ResourceType type)
Creates a standardResource
-instance. This constructor asserts that the game, tile and type are valid.- Parameters:
game
- The enclosingGame
.tile
- TheTile
on which this object sits.type
- TheResourceType
of this Resource.
-
Resource
public Resource(Game game, java.lang.String id)
Creates newResource
.- Parameters:
game
- The enclosingGame
.id
- The object identifier.
-
-
Method Detail
-
getType
public ResourceType getType()
Get the type of this resource.- Returns:
- The resource type.
-
isUnlimited
public boolean isUnlimited()
Is this an unlimited resource?- Returns:
- True if this is an unlimited resource.
-
getQuantity
public int getQuantity()
Get the resource quantity.- Returns:
- The resource quantity.
-
setQuantity
public void setQuantity(int newQuantity)
Set the resource quantity.- Parameters:
newQuantity
- The new resource quantity.
-
getBestGoodsType
public GoodsType getBestGoodsType()
Get the best goods type to produce here.- Returns:
- The best goods type.
-
useQuantity
public int useQuantity(GoodsType goodsType, UnitType unitType, int potential)
Reduce the available quantity by the bonus output ofGoodsType
.- Parameters:
goodsType
- TheGoodsType
to check.unitType
- The producingUnitType
.potential
- The base potential of the tile.- Returns:
- The new quantity of resource.
-
useQuantity
private int useQuantity(int usedQuantity)
Reduces the available quantity.- Parameters:
usedQuantity
- The quantity that was used up.- Returns:
- The final value of quantity.
-
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:
getNameKey
in interfaceNamed
- Specified by:
getNameKey
in classTileItem
- Returns:
- The name of the
Named
.
-
getZIndex
public final int getZIndex()
Get theZIndex
value.
-
isTileTypeAllowed
public boolean isTileTypeAllowed(TileType tileType)
Is a tile type compatible with this tile item?- Specified by:
isTileTypeAllowed
in classTileItem
- Parameters:
tileType
- TheTileType
to 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:
applyBonus
in classTileItem
- Parameters:
goodsType
- TheGoodsType
to produce.unitType
- TheUnitType
that 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:
canProduce
in classTileItem
- Parameters:
goodsType
- TheGoodsType
to produce.unitType
- The optionalunitType
to 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:
getProductionModifiers
in classTileItem
- Parameters:
goodsType
- TheGoodsType
to produce.unitType
- The optionalunitType
to 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:
isComplete
in 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:
checkIntegrity
in classTileItem
- Parameters:
fix
- If true, fix problems if possible.lb
- ALogBuilder
to 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:
writeAttributes
in classFreeColObject
- 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 classFreeColGameObject
- 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.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classFreeColObject
-
-