Class Force

    • Field Detail

      • landUnits

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

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

        private int spaceRequired
        The space required to transport all land units.
      • capacity

        private int capacity
        The current naval transport capacity.
    • Constructor Detail

      • Force

        public Force​(Specification specification)
        Basic constructor.
        Parameters:
        specification - The Specification for this object.
      • Force

        public Force​(Specification spec,
                     java.util.List<AbstractUnit> units,
                     java.lang.String ability)
        Create a new Force.
        Parameters:
        spec - The Specification for this object.
        units - A list of AbstractUnits defining the force.
        ability - An optional ability name required of the units in the force.
    • Method Detail

      • getSpaceRequired

        public final int getSpaceRequired()
        Get the cargo space required for the land units of this force.
        Returns:
        The required cargo space.
      • getCapacity

        public final int getCapacity()
        Get the cargo space provided by the naval units of this force.
        Returns:
        The provided cargo space.
      • getUnitList

        public final java.util.List<AbstractUnit> getUnitList()
        Gets all units.
        Returns:
        A copy of the list of all units.
      • clearLandUnits

        public final void clearLandUnits()
        Clear the land unit list.
      • clearNavalUnits

        public final void clearNavalUnits()
        Clear the naval unit list.
      • getLandUnitsList

        public final java.util.List<AbstractUnit> getLandUnitsList()
        Gets the land units.
        Returns:
        A list of the land units.
      • setLandUnitList

        protected void setLandUnitList​(java.util.List<AbstractUnit> landUnits)
        Set the land unit list.
        Parameters:
        landUnits - Set the new land AbstractUnits.
      • getNavalUnitsList

        public final java.util.List<AbstractUnit> getNavalUnitsList()
        Gets the naval units.
        Returns:
        A copy of the list of the naval units.
      • setNavalUnitList

        protected void setNavalUnitList​(java.util.List<AbstractUnit> navalUnits)
        Set the naval unit list.
        Parameters:
        navalUnits - Set the new land AbstractUnits.
      • isEmpty

        public final boolean isEmpty()
        Is this Force empty?
        Returns:
        True if there are no land or naval units.
      • add

        public final void add​(AbstractUnit au)
        Add abstract units to this Force.
        Parameters:
        au - The addition to this Force.
      • calculateStrength

        public double calculateStrength​(boolean naval)
        Calculate the approximate offence power of this force.
        Parameters:
        naval - If true, consider only naval units, otherwise consider the land units.
        Returns:
        The approximate offence power.
      • prepareToBoard

        public int prepareToBoard​(UnitType shipType)
        Defend against underprovisioned navies.
        Parameters:
        shipType - Optional ship UnitType to create.
        Returns:
        The amount of extra capacity.
      • matchAll

        public boolean matchAll​(Force other)
        Does another force match?
        Parameters:
        other - The other Force to test.
        Returns:
        True if the other force contains the same units.
      • copyIn

        public <T extends FreeColObject> boolean copyIn​(T other)
        Copy another FreeColObject into this one if it is compatible.
        Overrides:
        copyIn in class FreeColSpecObject
        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.
      • toXML

        public void toXML​(FreeColXMLWriter xw,
                          java.lang.String tag)
                   throws javax.xml.stream.XMLStreamException
        This method writes an XML-representation of this object with a specified tag to the given stream. Almost all FreeColObjects end up calling these, and implementing their own write{Attributes,Children} methods which begin by calling their superclass. This allows a clean nesting of the serialization routines throughout the class hierarchy. All attributes will be made visible.
        Overrides:
        toXML in class FreeColObject
        Parameters:
        xw - The FreeColXMLWriter to write to.
        tag - The tag to use.
        Throws:
        javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.
      • readFromXML

        public void readFromXML​(FreeColXMLReader xr)
                         throws javax.xml.stream.XMLStreamException
        Initializes this object from an XML-representation of this object, unless the PARTIAL_ATTRIBUTE tag is present which indicates a partial update of an existing object.
        Overrides:
        readFromXML in class FreeColObject
        Parameters:
        xr - The input stream with the XML.
        Throws:
        javax.xml.stream.XMLStreamException - if there are any problems 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.