Class UnitType

    • Field Detail

      • defenceComparator

        public static final java.util.Comparator<UnitType> defenceComparator
        Comparator for defence ability.
      • DEFAULT_OFFENCE

        public static final int DEFAULT_OFFENCE
        The default offence value.
        See Also:
        Constant Field Values
      • DEFAULT_DEFENCE

        public static final int DEFAULT_DEFENCE
        The default offence value.
        See Also:
        Constant Field Values
      • baseOffence

        private int baseOffence
        The offence of this UnitType. Only Units with an offence value greater than zero can attack.
      • baseDefence

        private int baseDefence
        The defence of this UnitType.
      • space

        private int space
        The capacity of this UnitType.
      • defaultUnitType

        private boolean defaultUnitType
        Is this the default unit type?
      • hitPoints

        private int hitPoints
        The number of hit points this UnitType has. At the moment, this is only used for ships. All other UnitTypes are downgraded or destroyed if they lose a battle.
      • spaceTaken

        private int spaceTaken
        The space taken by this UnitType.
      • skill

        private int skill
        The skill level of this UnitType.
      • price

        private int price
        The price of this UnitType.
      • mercenaryPrice

        private int mercenaryPrice
        The optional price of this UnitType for use by mercenary forces.
      • movement

        private int movement
        The initial moves of this UnitType.
      • lineOfSight

        private int lineOfSight
        The maximum distance of tiles this UnitType can observe.
      • recruitProbability

        private int recruitProbability
        The probability of recruiting a Unit of this type in Europe.
      • expertProduction

        private GoodsType expertProduction
        The expert production of this UnitType.
      • scoreValue

        private int scoreValue
        How much a Unit of this type contributes to the Player's score.
      • maximumExperience

        private int maximumExperience
        The maximum experience a unit of this type can accumulate.
      • maximumAttrition

        private int maximumAttrition
        The maximum attrition this UnitType can accumulate without being destroyed.
      • priority

        private int priority
        Consumption order.
      • skillTaught

        private UnitType skillTaught
        The skill this UnitType teaches, mostly its own.
      • defaultRole

        private Role defaultRole
        The default role for a unit of this type.
      • consumption

        private TypeCountMap<GoodsType> consumption
        The goods consumed per turn when in a settlement.
      • DEFAULT_ROLE_TAG

        private static final java.lang.String DEFAULT_ROLE_TAG
        See Also:
        Constant Field Values
      • DEFAULT_UNIT_TAG

        private static final java.lang.String DEFAULT_UNIT_TAG
        See Also:
        Constant Field Values
      • EXPERT_PRODUCTION_TAG

        private static final java.lang.String EXPERT_PRODUCTION_TAG
        See Also:
        Constant Field Values
      • LINE_OF_SIGHT_TAG

        private static final java.lang.String LINE_OF_SIGHT_TAG
        See Also:
        Constant Field Values
      • MERCENARY_PRICE_TAG

        private static final java.lang.String MERCENARY_PRICE_TAG
        See Also:
        Constant Field Values
      • MAXIMUM_EXPERIENCE_TAG

        private static final java.lang.String MAXIMUM_EXPERIENCE_TAG
        See Also:
        Constant Field Values
      • MAXIMUM_ATTRITION_TAG

        private static final java.lang.String MAXIMUM_ATTRITION_TAG
        See Also:
        Constant Field Values
      • RECRUIT_PROBABILITY_TAG

        private static final java.lang.String RECRUIT_PROBABILITY_TAG
        See Also:
        Constant Field Values
      • SKILL_TAUGHT_TAG

        private static final java.lang.String SKILL_TAUGHT_TAG
        See Also:
        Constant Field Values
      • OLD_DEFAULT_EQUIPMENT_TAG

        private static final java.lang.String OLD_DEFAULT_EQUIPMENT_TAG
        See Also:
        Constant Field Values
      • OLD_DEFAULT_UNIT_TAG

        private static final java.lang.String OLD_DEFAULT_UNIT_TAG
        See Also:
        Constant Field Values
      • OLD_HIT_POINTS_TAG

        private static final java.lang.String OLD_HIT_POINTS_TAG
        See Also:
        Constant Field Values
      • OLD_LINE_OF_SIGHT_TAG

        private static final java.lang.String OLD_LINE_OF_SIGHT_TAG
        See Also:
        Constant Field Values
      • OLD_MAXIMUM_EXPERIENCE_TAG

        private static final java.lang.String OLD_MAXIMUM_EXPERIENCE_TAG
        See Also:
        Constant Field Values
      • OLD_MAXIMUM_ATTRITION_TAG

        private static final java.lang.String OLD_MAXIMUM_ATTRITION_TAG
        See Also:
        Constant Field Values
      • OLD_RECRUIT_PROBABILITY_TAG

        private static final java.lang.String OLD_RECRUIT_PROBABILITY_TAG
        See Also:
        Constant Field Values
      • OLD_SCORE_VALUE_TAG

        private static final java.lang.String OLD_SCORE_VALUE_TAG
        See Also:
        Constant Field Values
      • OLD_SKILL_TAUGHT_TAG

        private static final java.lang.String OLD_SKILL_TAUGHT_TAG
        See Also:
        Constant Field Values
      • OLD_SPACE_TAKEN_TAG

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

      • UnitType

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

      • getWorkingAsKey

        public final java.lang.String getWorkingAsKey()
        Get a key for the working as this unit type message.
        Returns:
        A message key.
      • canCarryUnits

        public boolean canCarryUnits()
        Can this unit type carry units?
        Returns:
        True if units can be carried.
      • canCarryGoods

        public boolean canCarryGoods()
        Can this unit type carry goods?
        Returns:
        True if goods can be carried.
      • getScoreValue

        public int getScoreValue()
        Gets the score for acquiring a unit of this type.
        Returns:
        The score for this unit type.
      • getBaseOffence

        public int getBaseOffence()
        Get the base offence value.
        Returns:
        The base offence value.
      • getOffence

        public double getOffence()
        Get the offence of this unit type.
        Returns:
        The offence value.
      • isOffensive

        public boolean isOffensive()
        Is this an offensive unit type?
        Returns:
        True if base offensive ability is greater than the default.
      • getBaseDefence

        public int getBaseDefence()
        Get the base defence value.
        Returns:
        The defence value.
      • getDefence

        public double getDefence()
        Get the total defence of this unit type.
        Returns:
        The defence value.
      • isDefensive

        public boolean isDefensive()
        Is this a defensive unit type? Default defence is 1, same a for colonists, thus to be defensive, a colonist must have a military role. Artillery of all sorts has higher defense so they are automatically defensive.
        Returns:
        True if base defensive ability is greater than the default.
      • isDefaultUnitType

        public boolean isDefaultUnitType()
        Is this the default unit type?
        Returns:
        True if this is the default unit type.
      • getLineOfSight

        public int getLineOfSight()
        Get the `line of sight' distance (in tiles).
        Returns:
        The line of sight distance.
      • getSpace

        public int getSpace()
        Get the space this unit type has to carry cargo.
        Returns:
        The cargo capacity of this unit type.
      • setSpace

        public void setSpace​(int newSpace)
        Set the space this unit type has to carry cargo. Required by the test suite.
        Parameters:
        newSpace - The new cargo capacity.
      • getHitPoints

        public int getHitPoints()
        Get the unit type hit points.
        Returns:
        The hit points.
      • getSpaceTaken

        public int getSpaceTaken()
        Gets the number of cargo slots a unit of this type takes on a carrier.
        Returns:
        The number of cargo slots.
      • setSpaceTaken

        public void setSpaceTaken​(int newSpaceTaken)
        Set the number of cargo slots a unit of this type takes on a carrier. Required by the test suite.
        Parameters:
        newSpaceTaken - The new number of cargo slots.
      • isRecruitable

        public boolean isRecruitable()
        Is this UnitType recruitable in Europe?
        Returns:
        True if European-recruitable.
      • getRecruitProbability

        public int getRecruitProbability()
        Get the relative probability of recruiting this unit in Europe.
        Returns:
        A relative probability.
      • getSkill

        public int getSkill()
        Get the skill level associated with this unit type.
        Returns:
        The skill level.
      • setSkill

        public void setSkill​(int newSkill)
        Set the skill level associated with this unit type. Required by the test suite.
        Parameters:
        newSkill - The new skill level.
      • getPrice

        public int getPrice()
        Get the base price of this unit type. For the actual price of the unit, use Europe.getUnitPrice(UnitType)
        Returns:
        The base price.
      • getMercenaryPrice

        public int getMercenaryPrice()
        Get the special price used by mercenary forces when there is no standard base price (e.g. ManOWar).
        Returns:
        The mercenary price.
      • setMercenaryPrice

        public void setMercenaryPrice​(int price)
        Set the mercenary price.
        Parameters:
        price - The mercenary price.
      • getMovement

        public int getMovement()
        Get the base movement of this unit type.
        Returns:
        The base movement.
      • getMaximumExperience

        public final int getMaximumExperience()
        Get the maximum experience required a unit of this type may achieve.
        Returns:
        The maximum experience.
      • hasMaximumAttrition

        public boolean hasMaximumAttrition()
        Is this unit type subject to attrition?
        Returns:
        True if attrition can happen for this unit type.
      • getMaximumAttrition

        public int getMaximumAttrition()
        Get the maximum attrition for this unit type (greater attrition than this destroys the unit).
        Returns:
        The maximum attrition.
      • getExpertProduction

        public GoodsType getExpertProduction()
        Get the type of goods this unit type has expert ability to produce.
        Returns:
        The expert production GoodsType.
      • getSkillTaught

        public UnitType getSkillTaught()
        Get the skill taught by this unit type.
        Returns:
        The skill taught by this unit type.
      • getDefaultRole

        public Role getDefaultRole()
        Gets the default role of this unit type, mostly model.role.default.
        Returns:
        The default Role.
      • getExpertRoles

        public java.util.List<Role> getExpertRoles()
        Returns a list of roles for which a unit of this type is an expert.
        Returns:
        a list of expert roles
      • getDisplayRoleId

        public java.lang.String getDisplayRoleId()
        Get a role identifier for display routines to use for this unit type.
        Returns:
        A suitable role identifier for display purposes.
      • getTeachingType

        public UnitType getTeachingType​(UnitType teacherType)
        Get the type that this unit type can be educated to by a teacher unit type, if any.
        Parameters:
        teacherType - The UnitType of the teacher.
        Returns:
        The UnitType that this unit type can be educated to by the teacher unit type, or null if education is not possible.
      • isNaval

        public boolean isNaval()
        Is this a naval unit type?
        Returns:
        True if this is a naval unit type.
      • isPerson

        public boolean isPerson()
        Is this a person, not a ship or wagon?
        Returns:
        True if this unit type represents a person
      • canBuildColony

        public boolean canBuildColony()
        Is this unit type able to build a colony?
        Returns:
        True if this unit type can build colonies.
      • canMoveToHighSeas

        public boolean canMoveToHighSeas()
        Can this unit type move to the High Seas? ATM this is synonymous with being a naval unit, but we should use this routine instead of isNaval() in case this changes.
        Returns:
        True if units of this type can move to the High Seas.
      • hasSkill

        public boolean hasSkill()
        Does this UnitType have a skill?
        Returns:
        True if this unit type has a skill.
      • hasPrice

        public boolean hasPrice()
        Does this UnitType have a price?
        Returns:
        True if the unit type has a price.
      • getConsumption

        protected TypeCountMap<GoodsType> getConsumption()
        Get the consumption map.
        Returns:
        The map of the consumed goods.
      • setConsumption

        protected void setConsumption​(TypeCountMap<GoodsType> consumption)
        Set the consumption map.
        Parameters:
        consumption - The new map of the consumed goods.
      • getConsumptionOf

        public int getConsumptionOf​(GoodsType goodsType)
        Gets the number of units of the given GoodsType this UnitType consumes per turn (when in a settlement).
        Parameters:
        goodsType - The GoodsType to consume.
        Returns:
        The amount of goods consumed per turn.
      • addConsumption

        private void addConsumption​(GoodsType type,
                                    int amount)
        Add consumption.
        Parameters:
        type - The GoodsType to consume.
        amount - The amount of goods to consume.
      • 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.
      • getConsumedGoods

        public java.util.List<AbstractGoods> getConsumedGoods()
        Returns a list of GoodsTypes this Consumer consumes.
        Specified by:
        getConsumedGoods in interface Consumer
        Returns:
        a List value
      • getPriority

        public int getPriority()
        The priority of this Consumer. The higher the priority, the earlier will the Consumer be allowed to consume the goods it requires.
        Specified by:
        getPriority in interface Consumer
        Returns:
        an int value
      • getConsumptionModifiers

        public java.util.stream.Stream<Modifier> getConsumptionModifiers​(java.lang.String id)
        Get the modifier set with the given id. The modifier most relevant to consumers is "consumeOnlySurplusProduction", which implies that the consumer does not consume stored goods (used by the country and stables).
        Specified by:
        getConsumptionModifiers in interface Consumer
        Parameters:
        id - The object identifier.
        Returns:
        The stream of Modifiers found.
      • 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.