net.sf.freecol.common.model
Class Resource

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.model.FreeColGameObject
          extended by net.sf.freecol.common.model.TileItem
              extended by net.sf.freecol.common.model.Resource
All Implemented Interfaces:
Locatable

public class Resource
extends TileItem

Represents a locatable goods of a specified type and quantity.


Field Summary
private static java.util.logging.Logger logger
           
private  int quantity
           
private  ResourceType type
           
 
Fields inherited from class net.sf.freecol.common.model.TileItem
RESOURCE_ZINDEX, RUMOUR_ZINDEX, tile
 
Fields inherited from class net.sf.freecol.common.model.FreeColGameObject
UNITS_TAG_NAME
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, INFINITY, NO_ID, PARTIAL_ATTRIBUTE, UNDEFINED, VALUE_TAG
 
Constructor Summary
Resource(Game game, Tile tile, ResourceType type)
          Creates a standard Resource-instance.
Resource(Game game, Tile tile, ResourceType type, int quantity)
          Creates a standard Resource-instance.
Resource(Game game, javax.xml.stream.XMLStreamReader in)
           
 
Method Summary
 GoodsType getBestGoodsType()
          Returns the best GoodsType
 int getBonus(GoodsType goodsType, UnitType unitType, int potential)
          Returns the bonus (checking available stock) for next turn.
 java.lang.String getNameKey()
           
 int getQuantity()
          Returns the current quantity.
 ResourceType getType()
          Returns the ResourceType of this Resource.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 int getZIndex()
          Get the ZIndex value.
 boolean isTileTypeAllowed(TileType tileType)
          Returns true if the TileItem is compatible with the given TileType.
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
 void setQuantity(int newQuantity)
          Returns the current quantity.
 java.lang.String toString()
          Returns a textual representation of this object.
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out, Player player, boolean showAll, boolean toSavedGame)
          This method writes an XML-representation of this object to the given stream.
 int useQuantity(GoodsType goodsType, UnitType unitType, int potential)
          Reduces the available quantity by the bonus output of GoodsType.
 int useQuantity(int usedQuantity)
          Reduces the value quantity.
 
Methods inherited from class net.sf.freecol.common.model.TileItem
getLocation, getSpaceTaken, getTile, setLocation
 
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
dispose, disposeList, equals, equals, fundamentalDispose, getFreeColGameObject, getFreeColGameObject, getGame, getIntegerID, getSpecification, hashCode, isDisposed, isUninitialized, newLocation, readFromXML, readFromXMLPartialByClass, setDefaultId, setGame, setId, toXML, toXMLImpl, toXMLPartialByClass, updateFreeColGameObject
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, hasAbility, hasAttribute, hasListeners, readAttributes, readAttributes, readChild, readChild, readChildren, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXMLElement, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setSpecification, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute, writeAttributes, writeChildren
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

private static java.util.logging.Logger logger

type

private ResourceType type

quantity

private int quantity
Constructor Detail

Resource

public Resource(Game game,
                Tile tile,
                ResourceType type,
                int quantity)
Creates a standard Resource-instance. This constructor asserts that the game, tile and type are valid.

Parameters:
game - The Game in which this object belongs.
tile - The Tile on which this object sits.
type - The ResourceType of this Resource.
quantity - an int value

Resource

public Resource(Game game,
                Tile tile,
                ResourceType type)
Creates a standard Resource-instance. This constructor asserts that the game, tile and type are valid.

Parameters:
game - The Game in which this object belongs.
tile - The Tile on which this object sits.
type - The ResourceType of this Resource.

Resource

public Resource(Game game,
                javax.xml.stream.XMLStreamReader in)
         throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException
Method Detail

toString

public java.lang.String toString()
Returns a textual representation of this object.

Overrides:
toString in class FreeColGameObject
Returns:
A String of either:
  1. QUANTITY RESOURCETYPE (eg. 250 Minerals) if there is a limited quantity
  2. RESOURCETYPE (eg. Game) if it is an unlimited resource

getNameKey

public java.lang.String getNameKey()

getType

public ResourceType getType()
Returns the ResourceType of this Resource.


getQuantity

public int getQuantity()
Returns the current quantity.


setQuantity

public void setQuantity(int newQuantity)
Returns the current quantity.


getZIndex

public final int getZIndex()
Get the ZIndex value.

Specified by:
getZIndex in class TileItem
Returns:
an int value

getBestGoodsType

public GoodsType getBestGoodsType()
Returns the best GoodsType


getBonus

public int getBonus(GoodsType goodsType,
                    UnitType unitType,
                    int potential)
Returns the bonus (checking available stock) for next turn.

Parameters:
goodsType - The GoodsType to check
unitType - an UnitType value
potential - Potential of Tile + Improvements
Returns:
an int value

useQuantity

public int useQuantity(GoodsType goodsType,
                       UnitType unitType,
                       int potential)
Reduces the available quantity by the bonus output of GoodsType.

Parameters:
goodsType - The GoodsType to check
unitType - an UnitType value
potential - Potential of Tile + Improvements
Returns:
an int value

useQuantity

public int useQuantity(int usedQuantity)
Reduces the value quantity.

Parameters:
usedQuantity - The quantity that was used up.
Returns:
The final value of quantity.

isTileTypeAllowed

public boolean isTileTypeAllowed(TileType tileType)
Returns true if the TileItem is compatible with the given TileType.

Specified by:
isTileTypeAllowed in class TileItem
Parameters:
tileType - a TileType value
Returns:
a boolean value

toXMLImpl

protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out,
                         Player player,
                         boolean showAll,
                         boolean toSavedGame)
                  throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object to the given stream.

Only attributes visible to the given Player will be added to that representation if showAll is set to false.

Specified by:
toXMLImpl in class FreeColGameObject
Parameters:
out - The target stream.
player - The Player this XML-representation should be made for, or null if showAll == true.
showAll - Only attributes visible to player will be added to the representation if showAll is set to false.
toSavedGame - If true then information that is only needed when saving a game is added.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

readFromXMLImpl

protected void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
                        throws javax.xml.stream.XMLStreamException
Initialize this object from an XML-representation of this object.

Overrides:
readFromXMLImpl in class FreeColObject
Parameters:
in - The input stream with the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

getXMLElementTagName

public static java.lang.String getXMLElementTagName()
Gets the tag name of the root element representing this object.

Returns:
"resource".