Class 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.
    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • 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.
      • 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
      • 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 enclosing Game.
        player - The Player to create the Monarch for.
      • Monarch

        public Monarch​(Game game,
                       java.lang.String id)
        Initiates a new Monarch with the given identifier. The object should later be initialized by calling FreeColGameObject.readFromXML(FreeColXMLReader).
        Parameters:
        game - The enclosing Game.
        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 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 - The MonarchAction 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 - The MonarchAction 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 - The Random number source to use.
        Returns:
        The new tax rate.
      • lowerTax

        public int lowerTax​(java.util.Random random)
        Calculates a tax reduction.
        Parameters:
        random - The Random 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 - The Random 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 - The Random 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 enemy Player.
        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 - The Random number source to use.
        mercs - A list to load with mercenary AbstractUnits.
        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 - The Random number source to use.
        mercs - A list to load with mercenary AbstractUnits.
        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 interface Named
        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 class FreeColGameObject
        Type Parameters:
        T - The FreeColObject 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 class FreeColObject
        Parameters:
        xw - The FreeColXMLWriter 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 class FreeColObject
        Parameters:
        xw - The FreeColXMLWriter 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 class FreeColGameObject
        Parameters:
        xr - The FreeColXMLReader 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 class FreeColObject
        Parameters:
        xr - The FreeColXMLReader 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 class FreeColObject
        Parameters:
        xr - The FreeColXMLReader 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 class FreeColObject
        Returns:
        The tag.