Class Role

    • Field Detail

      • militaryComparator

        public static final java.util.Comparator<Role> militaryComparator
        A comparator to order roles by descending total military effectiveness.
      • downgrade

        private Role downgrade
        The Role to downgrade to after losing a battle. Defaults to null. Note that some UnitTypes and Roles may be disposed instead of downgraded when losing a battle.
      • maximumCount

        private int maximumCount
        The maximum multiple of required goods this Role may carry. Defaults to 1.
      • expertUnit

        private UnitType expertUnit
        The expert unit for this Role, e.g. a hardy pioneer is an expert for the pioneer role.
      • roleChanges

        private java.util.List<Role.RoleChange> roleChanges
        The role changes by capture available for this role.
      • MAXIMUM_COUNT_TAG

        private static final java.lang.String MAXIMUM_COUNT_TAG
        See Also:
        Constant Field Values
      • OLD_EXPERT_UNIT_TAG

        private static final java.lang.String OLD_EXPERT_UNIT_TAG
        See Also:
        Constant Field Values
      • OLD_MAXIMUM_COUNT_TAG

        private static final java.lang.String OLD_MAXIMUM_COUNT_TAG
        See Also:
        Constant Field Values
    • Constructor Detail

      • Role

        public Role​(java.lang.String id,
                    Specification specification)
        Creates a new Role instance.
        Parameters:
        id - The object identifier.
        specification - The Specification to refer to.
    • Method Detail

      • isDefaultRoleId

        public static boolean isDefaultRoleId​(java.lang.String roleId)
        Is this the default role?
        Parameters:
        roleId - The role identifier to test.
        Returns:
        True if this is the default role.
      • isDefaultRole

        public boolean isDefaultRole()
        Is this the default role?
        Returns:
        True if this is the default role.
      • getRoleSuffix

        public java.lang.String getRoleSuffix()
        Get the last part of a role identifier.
        Returns:
        The role suffix.
      • getRoleIdSuffix

        public static java.lang.String getRoleIdSuffix​(java.lang.String roleId)
        Get the last part of a role identifier.
        Parameters:
        roleId - A role identifier.
        Returns:
        The role suffix.
      • getDowngrade

        public final Role getDowngrade()
        Get the downgraded role from this one.
        Returns:
        The downgraded role.
      • setDowngrade

        public final void setDowngrade​(Role newDowngrade)
        Sets the downgraded role.
        Parameters:
        newDowngrade - The new downgraded role.
      • getMaximumCount

        public final int getMaximumCount()
        Gets the maximum goods count for the role.
        Returns:
        The maximum goods count.
      • setMaximumCount

        public final void setMaximumCount​(int newMaximumCount)
        Sets the maximum goods count for this role.
        Parameters:
        newMaximumCount - The new maximum goods count.
      • getExpertUnit

        public final UnitType getExpertUnit()
        Gets the expert profession for this role.
        Returns:
        The expert type.
      • setExpertUnit

        public final void setExpertUnit​(UnitType newExpertUnit)
        Sets the expert profession for this role.
        Parameters:
        newExpertUnit - The new expert type.
      • getRequiredGoodsList

        public java.util.List<AbstractGoods> getRequiredGoodsList​(int roleCount)
        Get the required goods for this role, considering also the role count.
        Parameters:
        roleCount - The role count.
        Returns:
        A list of required goods.
      • getRequiredGoods

        public java.util.stream.Stream<AbstractGoods> getRequiredGoods​(int roleCount)
        Get the required goods for this role, considering also the role count, as a stream.
        Parameters:
        roleCount - The role count.
        Returns:
        A stream of required goods.
      • getRequiredGoodsPrice

        public int getRequiredGoodsPrice​(Market market)
        Get the price of the required goods in a given market.
        Parameters:
        market - The Market to evaluate in.
        Returns:
        The price of the goods for this role.
      • getRoleChanges

        public final java.util.List<Role.RoleChange> getRoleChanges()
        Get the role changes that can allow a unit to assume this role.
        Returns:
        A list of RoleChanges.
      • setRoleChanges

        protected final void setRoleChanges​(java.util.List<Role.RoleChange> roleChanges)
        Set the role change list.
        Parameters:
        roleChanges - The new list of RoleChanges.
      • addRoleChange

        private void addRoleChange​(java.lang.String from,
                                   java.lang.String capture)
        Add a new role change.
        Parameters:
        from - The source role identifier.
        capture - The identifier for the role to capture.
      • getOffence

        public double getOffence()
        Get the offense value for this role.
        Returns:
        The offense value.
      • isOffensive

        public boolean isOffensive()
        Is this an offensive role?
        Returns:
        True if this is an offensive role.
      • getDefence

        private double getDefence()
        Get the defence value for this role.
        Returns:
        The defence value.
      • isDefensive

        public boolean isDefensive()
        Is this an defensive role?
        Returns:
        True if this is an defensive role.
      • isCompatibleWith

        public boolean isCompatibleWith​(Role other)
        Is this role compatible with another?
        Parameters:
        other - The other Role to compare with.
        Returns:
        True if the other role is compatible.
      • rolesCompatible

        public static boolean rolesCompatible​(Role role1,
                                              Role role2)
        Are two roles compatible.
        Parameters:
        role1 - A Role to compare.
        role2 - The other Role to compare.
        Returns:
        True if the roles are compatible.
      • getGoodsDifference

        public static java.util.List<AbstractGoods> getGoodsDifference​(Role from,
                                                                       int fromCount,
                                                                       Role to,
                                                                       int toCount)
        Gets a list of goods required to change from the first role to the second. The first role may be null implying the default role, the second must not. Note that excess goods that are left over after the change will appear on the list with negative amounts.
        Parameters:
        from - The current Role.
        fromCount - The role count for the current role.
        to - The new Role to assume.
        toCount - The role count for the new role.
        Returns:
        A list of AbstractGoods required to make the change.
      • getRoleIndex

        public int getRoleIndex()
        Establish a simple ordering. Normal roles, then REF-specific roles, then native-specific roles. Reduce by role-specific equipment amounts to further separate the levels such that the heavier armed roles sort first.
        Returns:
        A role index.
      • getAvailableRoles

        public static java.util.List<Role> getAvailableRoles​(Player player,
                                                             UnitType type,
                                                             java.util.List<Role> roles)
        Filter a list of proposed roles by availability.
        Parameters:
        player - The Player to own the unit.
        type - The UnitType to check.
        roles - A list of proposed Roles.
        Returns:
        A list of available Roles.
      • toFullString

        public java.lang.String toFullString()
        Longer format debug helper.
        Returns:
        A more detailed description of this role.
      • canBeBuiltInColony

        public Colony.NoBuildReason canBeBuiltInColony​(Colony colony,
                                                       java.util.List<BuildableType> assumeBuilt)
        Check to see if this buildable type can be built in a colony based on the buildings or units available.
        Specified by:
        canBeBuiltInColony in class BuildableType
        Parameters:
        colony - The Colony to check.
        assumeBuilt - A list of BuildableTypes.
        Returns:
        The reason the for failure, or NoBuildReason.NONE on success.
      • copyIn

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