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 classMonarch.MonarchActionConstants describing monarch actions.
-
Field Summary
Fields Modifier and Type Field Description private RolearmedRoleThe roles identifiers suitable for land units with support actions.private java.util.List<UnitType>bombardTypesThe bombard unit types suitable for support actions.private booleandispleasureWhether displeasure has been incurred.private static java.lang.StringDISPLEASURE_TAGprivate static java.lang.StringEXPEDITIONARY_FORCE_TAGprivate ForceexpeditionaryForceThe Royal Expeditionary Force, which the Monarch will send to crush the player's rebellion.static intHESSIAN_MINIMUM_PRICEThe minimum price for a Hessian offer of mercenaries.private static java.lang.StringINTERVENTION_FORCE_TAGprivate ForceinterventionForceThe Foreign Intervention Force, which some random country will send to support the player's rebellion.private java.util.List<UnitType>landREFUnitTypesThe land unit types suitable for the REF.private java.util.List<UnitType>landTypesThe land unit types suitable for support actions.private static java.util.logging.Loggerloggerprivate static java.lang.StringMERCENARY_FORCE_TAGprivate java.util.List<UnitType>mercenaryTypesThe land unit types suitable for mercenary support.static intMINIMUM_TAX_RATEThe minimum tax rate (given in percentage) from where it can be lowered.static intMONARCH_MINIMUM_PRICEThe minimum price for a monarch offer of mercenaries.private RolemountedRoleThe roles identifiers suitable for land units with support actions.private static java.lang.StringNAME_TAGprivate java.util.List<UnitType>navalREFUnitTypesThe naval unit types suitable for the REF.private java.util.List<UnitType>navalTypesThe naval unit types suitable for support actions.private PlayerplayerThe player of this monarch.private static java.lang.StringPLAYER_TAGprivate RolerefArmedRoleThe roles identifiers suitable for land units with support actions.private RolerefMountedRoleThe roles identifiers suitable for land units with support actions.private static java.lang.StringSUPPORT_SEA_TAGprivate booleansupportSeaWhether a frigate has been provided.static java.lang.StringTAG-
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 booleanactionIsValid(Monarch.MonarchAction action)Checks if a specified action is valid at present.private voidaddIfValid(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.AbstractUnitaddToREF(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.booleangetDispleasure()Gets the displeasure status.ForcegetExpeditionaryForce()Get the force describing the REF.ForcegetInterventionForce()Get the force describing the Intervention Force.ForcegetMercenaryForce()Gets the force describing the Mercenary Force.java.lang.StringgetNameKey()Gets the name of this named object.UnitTypegetNavalREFUnitType()Get a unit type for the REF navy.protected PlayergetPlayer()Get the owning player.java.util.List<AbstractUnit>getSupport(java.util.Random random, boolean naval)Gets a additions to the colonial forces.booleangetSupportSea()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.ForcegetWarSupportForce()Get the war support force.java.lang.StringgetXMLTagName()Get the serialization tag for this object.private voidinitializeCaches()Cache the unit types and roles for support and mercenary offers.intloadMercenaries(java.util.Random random, java.util.List<AbstractUnit> mercs)Gets some units available as mercenaries.intloadMercenaryForce(java.util.Random random, java.util.List<AbstractUnit> mercs)Load the mercenary force, reduced to the point of being affordable if possible.intlowerTax(java.util.Random random)Calculates a tax reduction.intraiseTax(java.util.Random random)Calculates a tax raise.protected voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.protected voidreadChild(FreeColXMLReader xr)Reads a single child object.protected voidreadChildren(FreeColXMLReader xr)Reads the children of this object from an XML stream.voidsetDispleasure(boolean displeasure)Sets the displeasure status.voidsetSupportSea(boolean supportSea)Sets the sea support status.booleanshouldAddNavalUnit()Should we add a naval unit to the REF next? Expand royal navy to +10% of required size to transport the land units.private inttaxMaximum()Gets the maximum tax rate in this game.voidupdateInterventionForce()Update the intervention force, adding land units depending on turns passed, and naval units sufficient to transport all land units.protected voidwriteAttributes(FreeColXMLWriter xw)Write the attributes of this object to a stream.protected voidwriteChildren(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- ThePlayerto create theMonarchfor.
-
Monarch
public Monarch(Game game, java.lang.String id)
Initiates a newMonarchwith 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
Playerassociated 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
Players.
-
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
Players.
-
actionIsValid
public boolean actionIsValid(Monarch.MonarchAction action)
Checks if a specified action is valid at present.- Parameters:
action- TheMonarchActionto 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- TheMonarchActionto 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- TheRandomnumber source to use.- Returns:
- The new tax rate.
-
lowerTax
public int lowerTax(java.util.Random random)
Calculates a tax reduction.- Parameters:
random- TheRandomnumber 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- TheRandomnumber 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- TheRandomnumber 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
AbstractUnits provided as support.
-
loadMercenaries
public int loadMercenaries(java.util.Random random, java.util.List<AbstractUnit> mercs)Gets some units available as mercenaries.- Parameters:
random- TheRandomnumber source to use.mercs- A list to load with mercenaryAbstractUnits.- 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- TheRandomnumber source to use.mercs- A list to load with mercenaryAbstractUnits.- 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:
getNameKeyin 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:
copyInin classFreeColGameObject- Type Parameters:
T- TheFreeColObjectsubclass 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:
writeAttributesin classFreeColObject- Parameters:
xw- TheFreeColXMLWriterto 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:
writeChildrenin classFreeColObject- Parameters:
xw- TheFreeColXMLWriterto 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:
readAttributesin classFreeColGameObject- Parameters:
xr- TheFreeColXMLReaderto 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:
readChildrenin classFreeColObject- Parameters:
xr- TheFreeColXMLReaderto 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:
readChildin classFreeColObject- Parameters:
xr- TheFreeColXMLReaderto 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:
getXMLTagNamein classFreeColObject- Returns:
- The tag.
-
-