net.sf.freecol.common.model
Class Europe

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColGameObject
      extended by net.sf.freecol.common.model.Europe
All Implemented Interfaces:
Location, Ownable

public final class Europe
extends FreeColGameObject
implements Location, Ownable

Represents Europe in the game. Each Player has it's own Europe.

Europe is the place where you can recruit(int, net.sf.freecol.common.model.Unit, int) and train(net.sf.freecol.common.model.Unit) new units. You may also sell/buy goods.


Field Summary
static java.lang.String COPYRIGHT
           
static java.lang.String LICENSE
           
static java.lang.String REVISION
           
 
Constructor Summary
Europe(Game game, org.w3c.dom.Element e)
          Initializes this object from an XML-representation of this object.
Europe(Game game, Player owner)
          Creates a new Europe.
Europe(Game game, java.lang.String id)
          Initiates a new Europe with the given ID.
Europe(Game game, javax.xml.stream.XMLStreamReader in)
          Initializes this object from an XML-representation of this object.
 
Method Summary
 void add(Locatable locatable)
          Adds a Locatable to this Location.
 boolean canAdd(Locatable locatable)
          Checks wether or not the specified locatable may be added to this Location.
 boolean contains(Locatable locatable)
          Checks if the specified Locatable is at this Location.
 void emigrate(int slot, Unit unit, int newRecruitable)
          Causes a unit to emigrate from Europe.
 int getArtilleryPrice()
          Gets the current price for an artillery.
 Unit getFirstUnit()
          Gets the first Unit in this Europe.
 GoodsContainer getGoodsContainer()
          Gets the GoodsContainer this Location use for storing it's goods.
 Unit getLastUnit()
          Gets the last Unit in this Europe.
 java.lang.String getLocationName()
          Returns the name of this location.
 java.lang.String getName()
          Returns the name of the owner's home port.
 Player getOwner()
          Gets the Player using this Europe.
 int getRecruitable(int slot)
          Gets the type of the recruitable in Europe at the given slot.
 int getRecruitPrice()
          Gets the current price for a recruit.
 Tile getTile()
          Returns null.
 int getUnitCount()
          Gets the amount of Units at this Location.
 java.util.Iterator<Unit> getUnitIterator()
          Gets an Iterator of every Unit directly located in this Europe.
 java.util.List<Unit> getUnitList()
          Gets a List of every Unit directly located in this Europe.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 void newTurn()
          Prepares this object for a new turn.
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
 void recruit(int slot, Unit unit, int newRecruitable)
          Recruits a unit from Europe.
 void remove(Locatable locatable)
          Removes a Locatable from this Location.
 void setOwner(Player p)
          Sets the owner of this Ownable.
 void setRecruitable(int slot, int type)
          Sets the type of the recruitable in Europe at the given slot to the given type.
 java.lang.String toString()
          Returns a suitable name.
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.
 void train(Unit unit)
          Trains a unit in Europe.
 
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
addModelMessage, addModelMessage, dispose, equals, equals, getGame, getGameOptions, getID, getIntegerID, hashCode, hasID, isDisposed, isUninitialized, readFromArrayElement, readFromArrayElement, readFromArrayElement, readFromArrayElement, readFromXML, readFromXMLElement, setFakeID, setGame, setID, toArrayElement, toArrayElement, toArrayElement, toArrayElement, toSavedXML, toXML, toXML, toXML, toXMLElement, toXMLElement, updateID
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.sf.freecol.common.model.Location
getID
 

Field Detail

COPYRIGHT

public static final java.lang.String COPYRIGHT
See Also:
Constant Field Values

LICENSE

public static final java.lang.String LICENSE
See Also:
Constant Field Values

REVISION

public static final java.lang.String REVISION
See Also:
Constant Field Values
Constructor Detail

Europe

public Europe(Game game,
              Player owner)
Creates a new Europe.

Parameters:
game - The Game in which this object belong.
owner - The Player that will be using this object of Europe.

Europe

public Europe(Game game,
              javax.xml.stream.XMLStreamReader in)
       throws javax.xml.stream.XMLStreamException
Initializes this object from an XML-representation of this object.

Parameters:
game - The Game in which this object belong.
in - The input stream containing the XML.
Throws:
javax.xml.stream.XMLStreamException - if an error occured during parsing.

Europe

public Europe(Game game,
              org.w3c.dom.Element e)
Initializes this object from an XML-representation of this object.

Parameters:
game - The Game in which this object belong.
e - An XML-element that will be used to initialize this object.

Europe

public Europe(Game game,
              java.lang.String id)
Initiates a new Europe with the given ID. The object should later be initialized by calling either FreeColGameObject.readFromXML(XMLStreamReader) or FreeColGameObject.readFromXMLElement(Element).

Parameters:
game - The Game in which this object belong.
id - The unique identifier for this object.
Method Detail

getRecruitable

public int getRecruitable(int slot)
Gets the type of the recruitable in Europe at the given slot.

Parameters:
slot - The slot of the recruitable whose type needs to be returned. Should be 0, 1 or 2. NOTE - used to be 1, 2 or 3 and was called with 1-3 by some classes and 0-2 by others, the method itself expected 0-2.
Returns:
The type of the recruitable in Europe at the given slot.
Throws:
java.lang.IllegalArgumentException - if the given slot does not exist.

setRecruitable

public void setRecruitable(int slot,
                           int type)
Sets the type of the recruitable in Europe at the given slot to the given type.

Parameters:
slot - The slot of the recruitable whose type needs to be set. Should be 0, 1 or 2. NOTE - changed in order to match getRecruitable above!
type - The new type for the unit at the given slot in Europe. Should be a valid unit type.

recruit

public void recruit(int slot,
                    Unit unit,
                    int newRecruitable)
Recruits a unit from Europe.

Parameters:
slot - The slot the recruited unit(type) came from. This is needed for setting a new recruitable to this slot.
unit - The recruited unit.
newRecruitable - The recruitable that will fill the now empty slot.
Throws:
java.lang.NullPointerException - if unit == null.
java.lang.IllegalStateException - if the player recruiting the unit cannot afford the price.

emigrate

public void emigrate(int slot,
                     Unit unit,
                     int newRecruitable)
Causes a unit to emigrate from Europe.

Parameters:
slot - The slot the emigrated unit(type) came from. This is needed for setting a new recruitable to this slot.
unit - The recruited unit.
newRecruitable - The recruitable that will fill the now empty slot.
Throws:
java.lang.NullPointerException - If unit == null.
java.lang.IllegalStateException - If there is not enough crosses to emigrate the Unit.

getTile

public Tile getTile()
Returns null.

Specified by:
getTile in interface Location
Returns:
null.

add

public void add(Locatable locatable)
Adds a Locatable to this Location.

Specified by:
add in interface Location
Parameters:
locatable - The Locatable to add to this Location.

remove

public void remove(Locatable locatable)
Removes a Locatable from this Location.

Specified by:
remove in interface Location
Parameters:
locatable - The Locatable to remove from this Location.

contains

public boolean contains(Locatable locatable)
Checks if the specified Locatable is at this Location.

Specified by:
contains in interface Location
Parameters:
locatable - The Locatable to test the presence of.
Returns:
The result.

getGoodsContainer

public GoodsContainer getGoodsContainer()
Description copied from interface: Location
Gets the GoodsContainer this Location use for storing it's goods.

Specified by:
getGoodsContainer in interface Location
Returns:
The GoodsContainer or null if the Location cannot store any goods.

canAdd

public boolean canAdd(Locatable locatable)
Checks wether or not the specified locatable may be added to this Location.

Specified by:
canAdd in interface Location
Parameters:
locatable - The Locatable to test the addabillity of.
Returns:
true.

getUnitCount

public int getUnitCount()
Gets the amount of Units at this Location.

Specified by:
getUnitCount in interface Location
Returns:
The amount of Units at this Location.

getUnitList

public java.util.List<Unit> getUnitList()
Gets a List of every Unit directly located in this Europe. This does not include Units on ships.

Specified by:
getUnitList in interface Location
Returns:
The List.

getUnitIterator

public java.util.Iterator<Unit> getUnitIterator()
Gets an Iterator of every Unit directly located in this Europe. This does not include Units on ships.

Specified by:
getUnitIterator in interface Location
Returns:
The Iterator.

getFirstUnit

public Unit getFirstUnit()
Gets the first Unit in this Europe.

Returns:
The first Unit in this Europe.

getLastUnit

public Unit getLastUnit()
Gets the last Unit in this Europe.

Returns:
The last Unit in this Europe.

train

public void train(Unit unit)
Trains a unit in Europe.

Parameters:
unit - The trained unit.
Throws:
java.lang.NullPointerException - if unit == null.
java.lang.IllegalStateException - if the player recruiting the unit cannot afford the price.

getArtilleryPrice

public int getArtilleryPrice()
Gets the current price for an artillery.

Returns:
The current price of the artillery in this Europe.

getRecruitPrice

public int getRecruitPrice()
Gets the current price for a recruit.

Returns:
The current price of the recruit in this Europe.

getOwner

public Player getOwner()
Gets the Player using this Europe.

Specified by:
getOwner in interface Ownable
Returns:
The Player controlling this Ownable.

setOwner

public void setOwner(Player p)
Sets the owner of this Ownable.

Specified by:
setOwner in interface Ownable
Parameters:
p - The Player that should take ownership of this Ownable.
Throws:
java.lang.UnsupportedOperationException - is always thrown by this method.

newTurn

public void newTurn()
Prepares this object for a new turn.


getLocationName

public java.lang.String getLocationName()
Returns the name of this location.

Specified by:
getLocationName in interface Location
Returns:
The name of this location.

getName

public java.lang.String getName()
Returns the name of the owner's home port.

Returns:
The name of this location.

toString

public java.lang.String toString()
Returns a suitable name.

Overrides:
toString in class FreeColGameObject
Returns:
The String

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.

Specified by:
readFromXMLImpl in class FreeColGameObject
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:
"europe".