net.sf.freecol.common.model
Class TileItemContainer

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.TileItemContainer

public class TileItemContainer
extends FreeColGameObject

Contains TileItems and can be used by a Tile to make certain tasks easier.


Field Summary
private static java.util.logging.Logger logger
           
private  Tile tile
          The owner of this TileItemContainer.
private  java.util.Comparator<TileItem> tileItemComparator
           
private  java.util.List<TileItem> tileItems
          All tile items sorted by zIndex.
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE
 
Constructor Summary
TileItemContainer(Game game, Tile tile)
          Creates an empty TileItemContainer.
TileItemContainer(Game game, Tile tile, org.w3c.dom.Element e)
          Initiates a new TileItemContainer from an Element.
TileItemContainer(Game game, Tile tile, PlayerExploredTile pet)
           
TileItemContainer(Game game, Tile tile, javax.xml.stream.XMLStreamReader in)
          Initiates a new TileItemContainer from an Element.
 
Method Summary
 TileImprovement addRiver(int magnitude, int style)
          Creates a river TileImprovement and adds to this Tile/Container.
 TileItem addTileItem(TileItem item)
          Adds a TileItem to this container.
 void clear()
           
 TileItemContainer clone()
          Clone functions for making a clone of this TileItemContainer
 TileItemContainer clone(boolean importBonuses)
           
 TileItemContainer clone(boolean importBonuses, boolean copyOnlyNatural)
           
 boolean contains(TileItem t)
          Checks if the specified TileItem is in this container.
 void copyFrom(TileItemContainer tic)
           
 void copyFrom(TileItemContainer tic, boolean importResources)
           
 void copyFrom(TileItemContainer tic, boolean importResources, boolean copyOnlyNatural)
           
 void dispose()
          Removes all references to this object.
 TileImprovement findTileImprovementType(TileImprovementType type)
          Checks if a TileImprovement of this Type is already in this container.
 java.util.List<TileImprovement> getCompletedImprovements()
          Returns a List of the completed TileImprovements in this TileItemContainer.
 java.util.List<TileImprovement> getImprovements()
          Returns a List of the TileImprovements in this TileItemContainer.
private  java.util.List<TileImprovement> getImprovements(boolean completedOnly)
          Returns a List of the TileImprovements in this TileItemContainer.
 LostCityRumour getLostCityRumour()
          Get the LostCityRumour value.
 int getMoveCost(int basicMoveCost, Tile fromTile)
          Determine the movement cost to this Tile from another Tile.
 java.util.Set<Modifier> getProductionBonus(GoodsType goodsType, UnitType unitType)
          Describe getProductionBonus method here.
 Resource getResource()
           
 TileImprovement getRiver()
           
 TileImprovement getRoad()
           
 Tile getTile()
           
 java.util.List<TileItem> getTileItems()
          Get the TileItems value.
 int getTotalBonusPotential(GoodsType g, UnitType unitType, int tilePotential)
          Determine the total bonus for a GoodsType.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 boolean hasImprovement(TileImprovementType type)
          Will check whether this tile has a completed improvement of the given type.
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
 void removeAll()
          Removes all TileItems.
 void removeAll(java.lang.Class c)
           
 void removeIncompatibleImprovements()
          Remove improvements incompatible with the given TileType.
 TileImprovement removeRiver()
          Removes the river TileImprovement from this Tile/Container.
 TileItem removeTileItem(TileItem item)
          Removes TileItem from this container.
 void setTileItems(java.util.List<TileItem> newTileItems)
          Set the TileItems value.
 java.lang.String toString()
          Creates a String representation of this TileItemContainer.
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.
 
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
addModelMessage, addModelMessage, addModelMessage, addToRemoveElement, equals, equals, getFreeColGameObject, getFreeColGameObject, getGame, getGameOptions, getIntegerID, hashCode, hasID, isDisposed, isUninitialized, readFromXML, readFromXMLPartialByClass, setFakeID, setGame, setId, toSavedXML, toXML, toXMLImpl, toXMLPartialByClass, 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, readAttributes, readChildren, readFromArrayElement, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXMLElement, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, toArrayElement, toArrayElement, toListElement, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute, writeAttributes, writeChildren, writeFreeColGameObject
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

private static final java.util.logging.Logger logger

tile

private Tile tile
The owner of this TileItemContainer.


tileItems

private java.util.List<TileItem> tileItems
All tile items sorted by zIndex.


tileItemComparator

private final java.util.Comparator<TileItem> tileItemComparator
Constructor Detail

TileItemContainer

public TileItemContainer(Game game,
                         Tile tile)
Creates an empty TileItemContainer.

Parameters:
game - The Game in which this TileItemContainer belong.
tile - The Tile this TileItemContainer will be containg TileItems for.

TileItemContainer

public TileItemContainer(Game game,
                         Tile tile,
                         PlayerExploredTile pet)

TileItemContainer

public TileItemContainer(Game game,
                         Tile tile,
                         javax.xml.stream.XMLStreamReader in)
                  throws javax.xml.stream.XMLStreamException
Initiates a new TileItemContainer from an Element.

Parameters:
game - The Game in which this TileItemContainer belong.
tile - The Tile using this TileItemContainer for storing it's TileItem.
in - The input stream containing the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

TileItemContainer

public TileItemContainer(Game game,
                         Tile tile,
                         org.w3c.dom.Element e)
Initiates a new TileItemContainer from an Element.

Parameters:
game - The Game in which this TileItemContainer belong.
tile - The Tile using this TileItemContainer for storing it's TileItem.
e - An XML-element that will be used to initialize this object.
Method Detail

clone

public TileItemContainer clone()
Clone functions for making a clone of this TileItemContainer

Overrides:
clone in class java.lang.Object

clone

public TileItemContainer clone(boolean importBonuses)

clone

public TileItemContainer clone(boolean importBonuses,
                               boolean copyOnlyNatural)

getTile

public Tile getTile()

getTileItems

public final java.util.List<TileItem> getTileItems()
Get the TileItems value.

Returns:
a List value

setTileItems

public final void setTileItems(java.util.List<TileItem> newTileItems)
Set the TileItems value.

Parameters:
newTileItems - The new TileItems value.

getResource

public Resource getResource()

getRoad

public TileImprovement getRoad()

getRiver

public TileImprovement getRiver()

getLostCityRumour

public final LostCityRumour getLostCityRumour()
Get the LostCityRumour value.

Returns:
a LostCityRumour value

clear

public void clear()

removeIncompatibleImprovements

public void removeIncompatibleImprovements()
Remove improvements incompatible with the given TileType. This method is called whenever the type of the container's tile changes, i.e. due to clearing.


getImprovements

public java.util.List<TileImprovement> getImprovements()
Returns a List of the TileImprovements in this TileItemContainer.

Returns:
The List.

getCompletedImprovements

public java.util.List<TileImprovement> getCompletedImprovements()
Returns a List of the completed TileImprovements in this TileItemContainer.

Returns:
The List.

getImprovements

private java.util.List<TileImprovement> getImprovements(boolean completedOnly)
Returns a List of the TileImprovements in this TileItemContainer.

Returns:
The List.

getTotalBonusPotential

public int getTotalBonusPotential(GoodsType g,
                                  UnitType unitType,
                                  int tilePotential)
Determine the total bonus for a GoodsType. Checks Resource and all Improvements.

Parameters:
g - a GoodsType value
unitType - an UnitType value
tilePotential - an int value
Returns:
The total bonus

getProductionBonus

public java.util.Set<Modifier> getProductionBonus(GoodsType goodsType,
                                                  UnitType unitType)
Describe getProductionBonus method here.

Parameters:
goodsType - a GoodsType value
unitType - a UnitType value
Returns:
a Modifier value

getMoveCost

public int getMoveCost(int basicMoveCost,
                       Tile fromTile)
Determine the movement cost to this Tile from another Tile. Does not consider special unit abilities.

Parameters:
basicMoveCost - an int value
fromTile - a Tile value
Returns:
The movement cost

addTileItem

public TileItem addTileItem(TileItem item)
Adds a TileItem to this container.

Parameters:
item - The TileItem to add to this container.
Returns:
The added TileItem or the existing TileItem or null on error

removeTileItem

public TileItem removeTileItem(TileItem item)
Removes TileItem from this container.

Parameters:
item - The TileItem to remove from this container.
Returns:
The TileItem that has been removed from this container (if any).

removeAll

public void removeAll(java.lang.Class c)

copyFrom

public void copyFrom(TileItemContainer tic)

copyFrom

public void copyFrom(TileItemContainer tic,
                     boolean importResources)

copyFrom

public void copyFrom(TileItemContainer tic,
                     boolean importResources,
                     boolean copyOnlyNatural)

removeAll

public void removeAll()
Removes all TileItems.


contains

public boolean contains(TileItem t)
Checks if the specified TileItem is in this container.

Parameters:
t - The TileItem to test the presence of.
Returns:
The result.

findTileImprovementType

public TileImprovement findTileImprovementType(TileImprovementType type)
Checks if a TileImprovement of this Type is already in this container.

Parameters:
type - The TileImprovementType to test the presence of.
Returns:
The result.

hasImprovement

public boolean hasImprovement(TileImprovementType type)
Will check whether this tile has a completed improvement of the given type. Useful for checking whether the tile for instance has a road or is plowed.

Parameters:
type - The type to check for.
Returns:
Whether the tile has the improvement and the improvement is completed.

dispose

public void dispose()
Removes all references to this object.

Overrides:
dispose in class FreeColGameObject

addRiver

public TileImprovement addRiver(int magnitude,
                                int style)
Creates a river TileImprovement and adds to this Tile/Container. Checking for overwrite is done by addTileItem(net.sf.freecol.common.model.TileItem).

Parameters:
magnitude - The Magnitude of the river to be created
style - an int value
Returns:
The new river added, or the existing river TileImprovement

removeRiver

public TileImprovement removeRiver()
Removes the river TileImprovement from this Tile/Container.


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:
"tileitemcontainer".

toString

public java.lang.String toString()
Creates a String representation of this TileItemContainer.

Overrides:
toString in class FreeColGameObject
Returns:
The String