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, Typed<ResourceType>

public class Resource
extends TileItem
implements Typed<ResourceType>

Represents a locatable goods of a specified type and quantity.


Field Summary
 
Fields inherited from class net.sf.freecol.common.model.TileItem
RESOURCE_ZINDEX, RUMOUR_ZINDEX
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ID_ATTRIBUTE_TAG
 
Constructor Summary
Resource(Game game, org.w3c.dom.Element e)
           
Resource(Game game, Tile tile, ResourceType type)
          Creates a standard Resource-instance.
Resource(Game game, javax.xml.stream.XMLStreamReader in)
           
 
Method Summary
 void dispose()
          Disposes this resource.
 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 getOutputString()
          Returns a String with the output of this Resource.
 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.
 void setName(java.lang.String newName)
           
 void setQuantity(int newQuantity)
          Returns the current quantity.
 java.lang.String toString()
          Returns a textual representation of this object.
 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
addToRemoveElement, equals, equals, getFreeColGameObject, getFreeColGameObject, getGame, getGameOptions, getIntegerID, hashCode, hasID, isDisposed, isUninitialized, readFromXML, setGame, setId, toSavedXML, toXML, updateFreeColGameObject, updateID
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, hasAbility, hasAttribute, hasListeners, readFromXMLElement, removePropertyChangeListener, removePropertyChangeListener, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, writeAttribute, writeFreeColGameObject
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

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

Resource

public Resource(Game game,
                org.w3c.dom.Element e)
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

getType

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

Specified by:
getType in interface Typed<ResourceType>
Returns:
The type of this object.

getOutputString

public java.lang.String getOutputString()
Returns a String with the output 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.

dispose

public void dispose()
Disposes this resource.

Overrides:
dispose in class TileItem

getXMLElementTagName

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

Returns:
"resource".

setName

public void setName(java.lang.String newName)