Package net.sf.freecol.common.model
Class Monarch
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColGameObject
-
- net.sf.freecol.common.model.Monarch
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,Named
,ObjectWithId
public final class Monarch extends FreeColGameObject implements Named
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
Nested Classes Modifier and Type Class Description static class
Monarch.MonarchAction
Constants describing monarch actions.
-
Field Summary
Fields Modifier and Type Field Description private Role
armedRole
The roles identifiers suitable for land units with support actions.private java.util.List<UnitType>
bombardTypes
The bombard unit types suitable for support actions.private boolean
displeasure
Whether displeasure has been incurred.private static java.lang.String
DISPLEASURE_TAG
private static java.lang.String
EXPEDITIONARY_FORCE_TAG
private Force
expeditionaryForce
The Royal Expeditionary Force, which the Monarch will send to crush the player's rebellion.static int
HESSIAN_MINIMUM_PRICE
The minimum price for a Hessian offer of mercenaries.private static java.lang.String
INTERVENTION_FORCE_TAG
private Force
interventionForce
The Foreign Intervention Force, which some random country will send to support the player's rebellion.private java.util.List<UnitType>
landREFUnitTypes
The land unit types suitable for the REF.private java.util.List<UnitType>
landTypes
The land unit types suitable for support actions.private static java.util.logging.Logger
logger
private static java.lang.String
MERCENARY_FORCE_TAG
private java.util.List<UnitType>
mercenaryTypes
The land unit types suitable for mercenary support.static int
MINIMUM_TAX_RATE
The minimum tax rate (given in percentage) from where it can be lowered.static int
MONARCH_MINIMUM_PRICE
The minimum price for a monarch offer of mercenaries.private Role
mountedRole
The roles identifiers suitable for land units with support actions.private static java.lang.String
NAME_TAG
private java.util.List<UnitType>
navalREFUnitTypes
The naval unit types suitable for the REF.private java.util.List<UnitType>
navalTypes
The naval unit types suitable for support actions.private Player
player
The player of this monarch.private static java.lang.String
PLAYER_TAG
private Role
refArmedRole
The roles identifiers suitable for land units with support actions.private Role
refMountedRole
The roles identifiers suitable for land units with support actions.private static java.lang.String
SUPPORT_SEA_TAG
private boolean
supportSea
Whether a frigate has been provided.static java.lang.String
TAG
-
Fields inherited from class net.sf.freecol.common.model.FreeColGameObject
initialized
-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
actionIsValid(Monarch.MonarchAction action)
Checks if a specified action is valid at present.private void
addIfValid(java.util.List<RandomChoice<Monarch.MonarchAction>> choices, Monarch.MonarchAction action, int weight)
Convenience hack to check if an action is valid, and if so add it to a choice list with a given weight.AbstractUnit
addToREF(java.util.Random random)
Add units to the Royal Expeditionary Force.java.util.List<Player>
collectPotentialEnemies()
Collects a list of potential enemies for this player.java.util.List<Player>
collectPotentialFriends()
Collects a list of potential friends for this player.<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.java.util.List<RandomChoice<Monarch.MonarchAction>>
getActionChoices()
Builds a weighted list of monarch actions.boolean
getDispleasure()
Gets the displeasure status.Force
getExpeditionaryForce()
Get the force describing the REF.Force
getInterventionForce()
Get the force describing the Intervention Force.Force
getMercenaryForce()
Gets the force describing the Mercenary Force.java.lang.String
getNameKey()
Gets the name of this named object.UnitType
getNavalREFUnitType()
Get a unit type for the REF navy.protected Player
getPlayer()
Get the owning player.java.util.List<AbstractUnit>
getSupport(java.util.Random random, boolean naval)
Gets a additions to the colonial forces.boolean
getSupportSea()
Gets the sea support status.java.util.List<AbstractUnit>
getWarSupport(Player enemy, java.util.Random random)
Check if the monarch provides support for a war.Force
getWarSupportForce()
Get the war support force.java.lang.String
getXMLTagName()
Get the serialization tag for this object.private void
initializeCaches()
Cache the unit types and roles for support and mercenary offers.int
loadMercenaries(java.util.Random random, java.util.List<AbstractUnit> mercs)
Gets some units available as mercenaries.int
loadMercenaryForce(java.util.Random random, java.util.List<AbstractUnit> mercs)
Load the mercenary force, reduced to the point of being affordable if possible.int
lowerTax(java.util.Random random)
Calculates a tax reduction.int
raiseTax(java.util.Random random)
Calculates a tax raise.protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.protected void
readChild(FreeColXMLReader xr)
Reads a single child object.protected void
readChildren(FreeColXMLReader xr)
Reads the children of this object from an XML stream.void
setDispleasure(boolean displeasure)
Sets the displeasure status.void
setSupportSea(boolean supportSea)
Sets the sea support status.boolean
shouldAddNavalUnit()
Should we add a naval unit to the REF next? Expand royal navy to +10% of required size to transport the land units.private int
taxMaximum()
Gets the maximum tax rate in this game.void
updateInterventionForce()
Update the intervention force, adding land units depending on turns passed, and naval units sufficient to transport all land units.protected void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.protected void
writeChildren(FreeColXMLWriter xw)
Write the children of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
checkIntegrity, dispose, disposeResources, equals, fundamentalDispose, getClassIndex, getDisposables, getGame, getLinkTarget, getSpecification, hashCode, intern, internId, isDisposed, isInitialized, isInternable, readFromXML, setGame, setSpecification
-
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addAbility, addFeatures, addModifier, addPropertyChangeListener, addPropertyChangeListener, apply, apply, applyModifiers, applyModifiers, arrayKey, compareIds, compareTo, containsAbilityKey, containsModifierKey, copy, copy, copy, copy, copyInCast, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getDefenceModifiers, getDisplayObject, getFeatureContainer, getFreeColObjectClass, getFreeColObjectClassByName, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, hasAbility, hasAbility, hasAbility, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setId, toString, toXML, toXML, toXMLPartial, toXMLPartial
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
MONARCH_MINIMUM_PRICE
public static final int MONARCH_MINIMUM_PRICE
The minimum price for a monarch offer of mercenaries.- See Also:
- Constant Field Values
-
HESSIAN_MINIMUM_PRICE
public static final int HESSIAN_MINIMUM_PRICE
The minimum price for a Hessian offer of mercenaries.- 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
-
player
private Player player
The player of this monarch.
-
supportSea
private boolean supportSea
Whether a frigate has been provided.
-
displeasure
private boolean displeasure
Whether displeasure has been incurred.
-
expeditionaryForce
private Force expeditionaryForce
The Royal Expeditionary Force, which the Monarch will send to crush the player's rebellion.
-
interventionForce
private Force interventionForce
The Foreign Intervention Force, which some random country will send to support the player's rebellion.
-
navalTypes
private java.util.List<UnitType> navalTypes
The naval unit types suitable for support actions.
-
bombardTypes
private java.util.List<UnitType> bombardTypes
The bombard unit types suitable for support actions.
-
landTypes
private java.util.List<UnitType> landTypes
The land unit types suitable for support actions.
-
mountedRole
private Role mountedRole
The roles identifiers suitable for land units with support actions.
-
armedRole
private Role armedRole
The roles identifiers suitable for land units with support actions.
-
refMountedRole
private Role refMountedRole
The roles identifiers suitable for land units with support actions.
-
refArmedRole
private Role refArmedRole
The roles identifiers suitable for land units with support actions.
-
mercenaryTypes
private java.util.List<UnitType> mercenaryTypes
The land unit types suitable for mercenary support.
-
navalREFUnitTypes
private java.util.List<UnitType> navalREFUnitTypes
The naval unit types suitable for the REF.
-
landREFUnitTypes
private java.util.List<UnitType> landREFUnitTypes
The land unit types suitable for the REF.
-
DISPLEASURE_TAG
private static final java.lang.String DISPLEASURE_TAG
- See Also:
- Constant Field Values
-
EXPEDITIONARY_FORCE_TAG
private static final java.lang.String EXPEDITIONARY_FORCE_TAG
- See Also:
- Constant Field Values
-
INTERVENTION_FORCE_TAG
private static final java.lang.String INTERVENTION_FORCE_TAG
- See Also:
- Constant Field Values
-
PLAYER_TAG
private static final java.lang.String PLAYER_TAG
- See Also:
- Constant Field Values
-
SUPPORT_SEA_TAG
private static final java.lang.String SUPPORT_SEA_TAG
- See Also:
- Constant Field Values
-
NAME_TAG
private static final java.lang.String NAME_TAG
- See Also:
- Constant Field Values
-
MERCENARY_FORCE_TAG
private static final java.lang.String MERCENARY_FORCE_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Monarch
public Monarch(Game game, Player player)
Constructor.- Parameters:
game
- The enclosingGame
.player
- ThePlayer
to create theMonarch
for.
-
Monarch
public Monarch(Game game, java.lang.String id)
Initiates a newMonarch
with the given identifier. The object should later be initialized by callingFreeColGameObject.readFromXML(FreeColXMLReader)
.- Parameters:
game
- The enclosingGame
.id
- The object identifier.
-
-
Method Detail
-
getPlayer
protected Player getPlayer()
Get the owning player. Note: Monarchs are not and should not be Ownable.- Returns:
- The
Player
associated with this monarch.
-
getExpeditionaryForce
public Force getExpeditionaryForce()
Get the force describing the REF.- Returns:
- The REF
Force
.
-
getInterventionForce
public Force getInterventionForce()
Get the force describing the Intervention Force.- Returns:
- The intervention
Force
.
-
getMercenaryForce
public Force getMercenaryForce()
Gets the force describing the Mercenary Force. This is never updated, and directly derived from the spec.- Returns:
- The mercenary
Force
.
-
getWarSupportForce
public Force getWarSupportForce()
Get the war support force. This is never updated, and directly derived from the spec.- Returns:
- The war support
Force
.
-
getSupportSea
public boolean getSupportSea()
Gets the sea support status.- Returns:
- Gets the sea support status.
-
setSupportSea
public void setSupportSea(boolean supportSea)
Sets the sea support status.- Parameters:
supportSea
- The new sea support status.
-
getDispleasure
public boolean getDispleasure()
Gets the displeasure status.- Returns:
- Gets the displeasure status.
-
setDispleasure
public void setDispleasure(boolean displeasure)
Sets the displeasure status.- Parameters:
displeasure
- The new displeasure status.
-
taxMaximum
private int taxMaximum()
Gets the maximum tax rate in this game.- Returns:
- The maximum tax rate in the game.
-
initializeCaches
private void initializeCaches()
Cache the unit types and roles for support and mercenary offers.
-
collectPotentialEnemies
public java.util.List<Player> collectPotentialEnemies()
Collects a list of potential enemies for this player.- Returns:
- A list of potential enemy
Player
s.
-
collectPotentialFriends
public java.util.List<Player> collectPotentialFriends()
Collects a list of potential friends for this player. Do not apply Franklin, he stops wars, not peace.- Returns:
- A list of potential friendly
Player
s.
-
actionIsValid
public boolean actionIsValid(Monarch.MonarchAction action)
Checks if a specified action is valid at present.- Parameters:
action
- TheMonarchAction
to check.- Returns:
- True if the action is valid.
-
getActionChoices
public java.util.List<RandomChoice<Monarch.MonarchAction>> getActionChoices()
Builds a weighted list of monarch actions.- Returns:
- A weighted list of monarch actions.
-
addIfValid
private void addIfValid(java.util.List<RandomChoice<Monarch.MonarchAction>> choices, Monarch.MonarchAction action, int weight)
Convenience hack to check if an action is valid, and if so add it to a choice list with a given weight.- Parameters:
choices
- The list of choices.action
- TheMonarchAction
to check.weight
- The weight to add the action with if valid.
-
raiseTax
public int raiseTax(java.util.Random random)
Calculates a tax raise.- Parameters:
random
- TheRandom
number source to use.- Returns:
- The new tax rate.
-
lowerTax
public int lowerTax(java.util.Random random)
Calculates a tax reduction.- Parameters:
random
- TheRandom
number source to use.- Returns:
- The new tax rate.
-
getNavalREFUnitType
public UnitType getNavalREFUnitType()
Get a unit type for the REF navy.- Returns:
- A naval REF unit type.
-
shouldAddNavalUnit
public boolean shouldAddNavalUnit()
Should we add a naval unit to the REF next? Expand royal navy to +10% of required size to transport the land units.- Returns:
- True if a naval unit should be added next.
-
addToREF
public AbstractUnit addToREF(java.util.Random random)
Add units to the Royal Expeditionary Force.- Parameters:
random
- TheRandom
number source to use.- Returns:
- An addition to the Royal Expeditionary Force.
-
updateInterventionForce
public void updateInterventionForce()
Update the intervention force, adding land units depending on turns passed, and naval units sufficient to transport all land units. Called when the IVF is created.
-
getSupport
public java.util.List<AbstractUnit> getSupport(java.util.Random random, boolean naval)
Gets a additions to the colonial forces.- Parameters:
random
- TheRandom
number source to use.naval
- If the addition should be a naval unit.- Returns:
- An addition to the colonial forces.
-
getWarSupport
public java.util.List<AbstractUnit> getWarSupport(Player enemy, java.util.Random random)
Check if the monarch provides support for a war.- Parameters:
enemy
- The enemyPlayer
.random
- A pseudo-random number source.- Returns:
- A list of
AbstractUnit
s provided as support.
-
loadMercenaries
public int loadMercenaries(java.util.Random random, java.util.List<AbstractUnit> mercs)
Gets some units available as mercenaries.- Parameters:
random
- TheRandom
number source to use.mercs
- A list to load with mercenaryAbstractUnit
s.- Returns:
- The price the monarch will ask or negative if nothing to offer.
-
loadMercenaryForce
public int loadMercenaryForce(java.util.Random random, java.util.List<AbstractUnit> mercs)
Load the mercenary force, reduced to the point of being affordable if possible.- Parameters:
random
- TheRandom
number source to use.mercs
- A list to load with mercenaryAbstractUnit
s.- Returns:
- The price the monarch will ask, or negative if nothing to offer.
-
getNameKey
public java.lang.String getNameKey()
Gets the name of this named object. Try to avoid using this directly except in i18n-related routines or to implement itself in more complext objects.- Specified by:
getNameKey
in interfaceNamed
- Returns:
- The name of the
Named
.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classFreeColGameObject
- Type Parameters:
T
- TheFreeColObject
subclass of the object to copy in.- Parameters:
other
- The other object.- Returns:
- True if the copy in is succesful.
-
writeAttributes
protected void writeAttributes(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the attributes of this object to a stream. To be overridden if required by any object that has attributes and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeAttributes
in classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
to write to.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
writeChildren
protected void writeChildren(FreeColXMLWriter xw) throws javax.xml.stream.XMLStreamException
Write the children of this object to a stream. To be overridden if required by any object that has children and uses the toXML(FreeColXMLWriter, String) call.- Overrides:
writeChildren
in classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
to write to.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
readAttributes
protected void readAttributes(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.- Overrides:
readAttributes
in classFreeColGameObject
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
readChildren
protected void readChildren(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads the children of this object from an XML stream.- Overrides:
readChildren
in classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
readChild
protected void readChild(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Reads a single child object. Subclasses must override to read their enclosed elements. This particular instance of the routine always throws XMLStreamException because we should never arrive here. However it is very useful to always call super.readChild() when an unexpected tag is encountered, as the exception thrown here provides some useful debugging context.- Overrides:
readChild
in classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
to read from.- Throws:
javax.xml.stream.XMLStreamException
- if there is a problem reading the stream.
-
getXMLTagName
public java.lang.String getXMLTagName()
Get the serialization tag for this object.- Specified by:
getXMLTagName
in classFreeColObject
- Returns:
- The tag.
-
-