net.sf.freecol.common.model
Class Europe

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.UnitLocation
              extended by net.sf.freecol.common.model.Europe
All Implemented Interfaces:
Location, Named, Ownable
Direct Known Subclasses:
ServerEurope

public class Europe
extends UnitLocation
implements Ownable, Named

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

In Europe, you can recruit, train and purchase new units. You can also equip units, as well as sell and buy goods.


Nested Class Summary
static class Europe.MigrationType
           
 
Nested classes/interfaces inherited from class net.sf.freecol.common.model.UnitLocation
UnitLocation.NoAddReason
 
Field Summary
private  FeatureContainer featureContainer
           
private static java.util.logging.Logger logger
           
private static int LOWER_CAP_INITIAL
           
private  Player owner
           
static int RECRUIT_COUNT
           
private static int RECRUIT_PRICE_INITIAL
           
private  UnitType[] recruitables
          This array represents the types of the units that can be recruited in Europe.
private  int recruitLowerCap
           
private  int recruitPrice
           
static java.lang.String UNIT_CHANGE
           
protected  java.util.Map<UnitType,java.lang.Integer> unitPrices
           
 
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
protected Europe()
          Constructor for ServerEurope.
protected Europe(Game game, Player owner)
          Constructor for ServerEurope.
  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
 boolean add(Locatable locatable)
          Adds a Locatable to this Location.
 boolean canAdd(Locatable locatable)
          Checks whether or not the specified locatable may be added to this Location.
 boolean canBuildEquipment(EquipmentType equipmentType)
          Return true if this Europe could build at least one item of the given EquipmentType.
 FeatureContainer getFeatureContainer()
          Returns the FeatureContainer.
 StringTemplate getLocationName()
          Returns the name of this location.
 java.lang.String getNameKey()
          Returns the name of the owner's home port.
 Player getOwner()
          Gets the Player using this Europe.
 UnitType getRecruitable(int slot)
          Gets the type of the recruitable in Europe at the given slot.
 int getRecruitPrice()
          Gets the current price for a recruit.
 int getUnitPrice(UnitType unitType)
          Returns the price of a unit in Europe.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 boolean hasAbility(java.lang.String id)
          Describe hasAbility method here.
 boolean hasCarrierWithSpace(int space)
          Checks if there is a useable carrier unit with a specified minimum amount of space available docked in this European port.
 void increaseRecruitmentDifficulty()
          Increases the base price and lower cap for recruits.
protected  void readChild(javax.xml.stream.XMLStreamReader in)
          Reads a single child object.
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
protected  void readFromXMLPartialImpl(javax.xml.stream.XMLStreamReader in)
          Partial reader, so that "remove" messages can be brief.
 boolean recruitablesDiffer()
          Returns true if not all recruitables are of the same type.
protected  void setFeatureContainer(FeatureContainer container)
          Sets the FeatureContainer.
 void setOwner(Player p)
          Sets the owner of this Ownable.
 void setRecruitable(int slot, UnitType 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.
protected  void toXMLPartialImpl(javax.xml.stream.XMLStreamWriter out, java.lang.String[] fields)
          Partial writer, so that "remove" messages can be brief.
 
Methods inherited from class net.sf.freecol.common.model.UnitLocation
contains, dispose, disposeList, getColony, getGoodsContainer, getLocationNameFor, getNoAddReason, getSettlement, getSpaceTaken, getTile, getUnitCapacity, getUnitCount, getUnitIterator, getUnitList, isEmpty, isFull, readChildren, remove, writeAttributes, writeChildren
 
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
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, hasAttribute, hasListeners, readAttributes, readAttributes, readChild, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXMLElement, readFromXMLImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setSpecification, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, writeAttribute, writeChildren
 
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

logger

private static final java.util.logging.Logger logger

RECRUIT_PRICE_INITIAL

private static final int RECRUIT_PRICE_INITIAL
See Also:
Constant Field Values

LOWER_CAP_INITIAL

private static final int LOWER_CAP_INITIAL
See Also:
Constant Field Values

UNIT_CHANGE

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

recruitables

private UnitType[] recruitables
This array represents the types of the units that can be recruited in Europe. They correspond to the slots that can be seen in the gui and that can be used to communicate with the server/client. The array holds exactly 3 elements and element 0 corresponds to recruit slot 1.


RECRUIT_COUNT

public static final int RECRUIT_COUNT
See Also:
Constant Field Values

unitPrices

protected java.util.Map<UnitType,java.lang.Integer> unitPrices

recruitPrice

private int recruitPrice

recruitLowerCap

private int recruitLowerCap

owner

private Player owner

featureContainer

private FeatureContainer featureContainer
Constructor Detail

Europe

protected Europe()
Constructor for ServerEurope.


Europe

protected Europe(Game game,
                 Player owner)
Constructor for ServerEurope.

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 occurred during parsing.

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 FreeColObject.readFromXMLElement(Element).

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

hasAbility

public boolean hasAbility(java.lang.String id)
Describe hasAbility method here.

Overrides:
hasAbility in class FreeColObject
Parameters:
id - a String value
Returns:
a boolean value

getFeatureContainer

public FeatureContainer getFeatureContainer()
Returns the FeatureContainer.

Returns:
a FeatureContainer value

setFeatureContainer

protected void setFeatureContainer(FeatureContainer container)
Sets the FeatureContainer.

Parameters:
container - a FeatureContainer value

hasCarrierWithSpace

public boolean hasCarrierWithSpace(int space)
Checks if there is a useable carrier unit with a specified minimum amount of space available docked in this European port.

Parameters:
space - The amount of space to require.
Returns:
True if there is a suitable unit present.
See Also:
Unit.isCarrier()

canBuildEquipment

public boolean canBuildEquipment(EquipmentType equipmentType)
Return true if this Europe could build at least one item of the given EquipmentType.

Parameters:
equipmentType - an EquipmentType value
Returns:
a boolean value

recruitablesDiffer

public boolean recruitablesDiffer()
Returns true if not all recruitables are of the same type.

Returns:
a boolean value

getRecruitable

public UnitType 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,
                           UnitType 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.

add

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

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

canAdd

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

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

getUnitPrice

public int getUnitPrice(UnitType unitType)
Returns the price of a unit in Europe.

Parameters:
unitType - The type of unit of which you need the price.
Returns:
The price of this unit when trained in Europe. 'UNDEFINED' is returned in case the unit cannot be bought.

getRecruitPrice

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

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

increaseRecruitmentDifficulty

public void increaseRecruitmentDifficulty()
Increases the base price and lower cap for recruits. Only called from the server side.


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.

getLocationName

public StringTemplate getLocationName()
Returns the name of this location.

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

getNameKey

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

Specified by:
getNameKey in interface Named
Returns:
The name of this location.

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.

readChild

protected void readChild(javax.xml.stream.XMLStreamReader in)
                  throws javax.xml.stream.XMLStreamException
Description copied from class: FreeColObject
Reads a single child object. This method does calls readChild with a null specification parameter.

Overrides:
readChild in class UnitLocation
Parameters:
in - The XML input stream.
Throws:
javax.xml.stream.XMLStreamException - if an error occurs

toXMLPartialImpl

protected void toXMLPartialImpl(javax.xml.stream.XMLStreamWriter out,
                                java.lang.String[] fields)
                         throws javax.xml.stream.XMLStreamException
Partial writer, so that "remove" messages can be brief.

Overrides:
toXMLPartialImpl in class FreeColObject
Parameters:
out - The target stream.
fields - The fields to write.
Throws:
javax.xml.stream.XMLStreamException - If there are problems writing the stream.

readFromXMLPartialImpl

protected void readFromXMLPartialImpl(javax.xml.stream.XMLStreamReader in)
                               throws javax.xml.stream.XMLStreamException
Partial reader, so that "remove" messages can be brief.

Overrides:
readFromXMLPartialImpl in class FreeColObject
Parameters:
in - The input stream with the XML.
Throws:
javax.xml.stream.XMLStreamException - If there are problems reading the stream.

toString

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

Overrides:
toString in class FreeColGameObject
Returns:
A string representation of the object.

getXMLElementTagName

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

Returns:
"europe".