net.sf.freecol.common.model
Class Monarch

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

public final class Monarch
extends FreeColGameObject

This class implements the player's monarch, whose functions prior to the revolution include raising taxes, declaring war on other European countries, and occasionally providing military support.


Nested Class Summary
static class Monarch.MonarchAction
          Constants describing monarch actions.
 
Field Summary
(package private)  int capacity
          The current naval transport capacity.
private static EquipmentType horses
           
private  java.util.List<AbstractUnit> landUnits
          The number of land units in the REF.
private static java.util.logging.Logger logger
           
static int MAXIMUM_TAX_RATE
          The maximum possible tax rate (given in percentage).
static int MINIMUM_PRICE
          The minimum price for mercenaries.
static int MINIMUM_TAX_RATE
          The minimum tax rate (given in percentage) from where it can be lowered
private static EquipmentType muskets
           
private  java.lang.String name
          The name of this monarch.
private  java.util.List<AbstractUnit> navalUnits
          The number of naval units in the REF.
private  Player player
          The player of this monarch.
(package private)  int spaceRequired
          The space required to transport all land units.
private  boolean supportSea
          Whether a frigate has been provided.
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE
 
Constructor Summary
Monarch(Game game, org.w3c.dom.Element e)
          Initiates a new Monarch from an Element and registers this Monarch at the specified game.
Monarch(Game game, Player player, java.lang.String name)
          Constructor.
Monarch(Game game, java.lang.String id)
          Initiates a new Monarch with the given ID.
Monarch(Game game, javax.xml.stream.XMLStreamReader in)
          Initiates a new Monarch from an Element and registers this Monarch at the specified game.
 
Method Summary
 void addToREF(java.util.List<AbstractUnit> units)
          Adds units to the Royal Expeditionary Force.
 java.util.List<AbstractUnit> addToREF(java.util.Random random)
          Returns units to be added to the Royal Expeditionary Force.
 Player declareWar(java.util.Random random)
          Returns the nation of another player to declare war on.
 Monarch.MonarchAction getAction(java.util.Random random)
          Returns a monarch action.
 java.util.List<RandomChoice<Monarch.MonarchAction>> getActionChoices()
           
private  int getEquipmentPrice(EquipmentType equipment)
           
 java.util.List<AbstractUnit> getLandUnits()
          Returns only the land units.
 java.util.List<AbstractUnit> getMercenaries(java.util.Random random)
          Returns units available as mercenaries.
 java.lang.String getName()
           
 java.util.List<AbstractUnit> getNavalUnits()
          Returns only the naval units.
 int getNewTax(Monarch.MonarchAction taxChange, java.util.Random random)
          Returns the new increased tax.
 int getPrice(java.util.List<AbstractUnit> units, boolean rebate)
          Returns the price for the given units.
private  int getPrice(UnitType unitType, Unit.Role role)
           
 java.util.List<AbstractUnit> getREF()
          Returns a List of all REF units.
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-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.
 
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
addModelMessage, addModelMessage, addModelMessage, addToRemoveElement, dispose, equals, equals, getFreeColGameObject, getFreeColGameObject, getGame, getGameOptions, getIntegerID, hashCode, hasID, isDisposed, isUninitialized, readFromXML, readFromXMLPartialByClass, setFakeID, setGame, setId, toSavedXML, toString, 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
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

name

private java.lang.String name
The name of this monarch.


player

private Player player
The player of this monarch.


logger

private static final java.util.logging.Logger logger

muskets

private static final EquipmentType muskets

horses

private static final EquipmentType horses

spaceRequired

int spaceRequired
The space required to transport all land units.


capacity

int capacity
The current naval transport capacity.


landUnits

private java.util.List<AbstractUnit> landUnits
The number of land units in the REF.


navalUnits

private java.util.List<AbstractUnit> navalUnits
The number of naval units in the REF.


MINIMUM_PRICE

public static final int MINIMUM_PRICE
The minimum price for mercenaries.

See Also:
Constant Field Values

MAXIMUM_TAX_RATE

public static final int MAXIMUM_TAX_RATE
The maximum possible tax rate (given in percentage).

See Also:
Constant Field Values

MINIMUM_TAX_RATE

public static final int MINIMUM_TAX_RATE
The minimum tax rate (given in percentage) from where it can be lowered

See Also:
Constant Field Values

supportSea

private boolean supportSea
Whether a frigate has been provided.

Constructor Detail

Monarch

public Monarch(Game game,
               Player player,
               java.lang.String name)
Constructor.

Parameters:
game - The Game this Monarch should be created in.
player - The Player to create the Monarch for.
name - The name of the Monarch.

Monarch

public Monarch(Game game,
               javax.xml.stream.XMLStreamReader in)
        throws javax.xml.stream.XMLStreamException
Initiates a new Monarch from an Element and registers this Monarch at the specified game.

Parameters:
game - The Game this object belongs to.
in - The input stream containing the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

Monarch

public Monarch(Game game,
               org.w3c.dom.Element e)
Initiates a new Monarch from an Element and registers this Monarch at the specified game.

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

Monarch

public Monarch(Game game,
               java.lang.String id)
Initiates a new Monarch 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

getName

public java.lang.String getName()

getAction

public Monarch.MonarchAction getAction(java.util.Random random)
Returns a monarch action. Not all actions are always applicable, and their probability depends on the player's difficulty settings. This method can only be called by the server.

Returns:
A monarch action.

getActionChoices

public java.util.List<RandomChoice<Monarch.MonarchAction>> getActionChoices()

getREF

public java.util.List<AbstractUnit> getREF()
Returns a List of all REF units.

Returns:
a List of all REF units.

getNavalUnits

public java.util.List<AbstractUnit> getNavalUnits()
Returns only the naval units.

Returns:
the naval units

getLandUnits

public java.util.List<AbstractUnit> getLandUnits()
Returns only the land units.

Returns:
the land units

getNewTax

public int getNewTax(Monarch.MonarchAction taxChange,
                     java.util.Random random)
Returns the new increased tax.

Returns:
The increased tax.

getMercenaries

public java.util.List<AbstractUnit> getMercenaries(java.util.Random random)
Returns units available as mercenaries.

Returns:
A troop of mercenaries.

addToREF

public java.util.List<AbstractUnit> addToREF(java.util.Random random)
Returns units to be added to the Royal Expeditionary Force.

Parameters:
random - The Random number source to use.
Returns:
An addition to the Royal Expeditionary Force.

addToREF

public void addToREF(java.util.List<AbstractUnit> units)
Adds units to the Royal Expeditionary Force.

Parameters:
units - The addition to the Royal Expeditionary Force.

getPrice

public int getPrice(java.util.List<AbstractUnit> units,
                    boolean rebate)
Returns the price for the given units.

Parameters:
units - The units to get a price for.
rebate - Whether to grant a rebate.
Returns:
The price fo the units.

getPrice

private int getPrice(UnitType unitType,
                     Unit.Role role)

getEquipmentPrice

private int getEquipmentPrice(EquipmentType equipment)

declareWar

public Player declareWar(java.util.Random random)
Returns the nation of another player to declare war on.

Parameters:
random - The Random number source to use.
Returns:
The enemy nation.

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. This method should be overwritten by any sub-class, preferably with the name of the class with the first letter in lower case.

Returns:
"monarch".