Class UnitChangeType

    • Field Detail

      • CAPTURE

        public static final java.lang.String CAPTURE
        Changes due to the unit being captured.
        See Also:
        Constant Field Values
      • CLEAR_SKILL

        public static final java.lang.String CLEAR_SKILL
        Changes due to a clear-skill command.
        See Also:
        Constant Field Values
      • CONVERSION

        public static final java.lang.String CONVERSION
        Changes due to a unit being converted by missionaries.
        See Also:
        Constant Field Values
      • CREATION

        public static final java.lang.String CREATION
        Changes to be made immediately at creation of a unit.
        See Also:
        Constant Field Values
      • DEMOTION

        public static final java.lang.String DEMOTION
        Changes due to a unit being demoted after losing a battle.
        See Also:
        Constant Field Values
      • EDUCATION

        public static final java.lang.String EDUCATION
        Changes due to education.
        See Also:
        Constant Field Values
      • ENTER_COLONY

        public static final java.lang.String ENTER_COLONY
        Changes when a unit begins to work in a colony. This is not in the standard spec but in the convertUpgrade mod. However it needs coding support to work.
        See Also:
        Constant Field Values
      • EXPERIENCE

        public static final java.lang.String EXPERIENCE
        Changes due to experience.
        See Also:
        Constant Field Values
      • FOUNDING_FATHER

        public static final java.lang.String FOUNDING_FATHER
        Change when a founding father is elected.
        See Also:
        Constant Field Values
      • INDEPENDENCE

        public static final java.lang.String INDEPENDENCE
        Changes at declaration of independence.
        See Also:
        Constant Field Values
      • LOST_CITY

        public static final java.lang.String LOST_CITY
        Changes from exploring a lost city.
        See Also:
        Constant Field Values
      • NATIVES

        public static final java.lang.String NATIVES
        Changes from living with the natives.
        See Also:
        Constant Field Values
      • PROMOTION

        public static final java.lang.String PROMOTION
        Changes due to the unit being promoted after winning a battle.
        See Also:
        Constant Field Values
      • UNDEAD

        public static final java.lang.String UNDEAD
        Changes due to the undead claiming the unit.
        See Also:
        Constant Field Values
      • changes

        public final java.util.Map<UnitType,​java.util.List<UnitTypeChange>> changes
        The individual unit changes valid for this change type.
      • ownerChange

        private boolean ownerChange
        True if this type of change always implies a change of owner.
      • OWNER_CHANGE_TAG

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

      • UnitChangeType

        public UnitChangeType​(java.lang.String id,
                              Specification specification)
        Trivial constructor.
        Parameters:
        id - The object identifier.
        specification - The Specification to use.
    • Method Detail

      • getOwnerChange

        public boolean getOwnerChange()
        Get the owner change state.
        Returns:
        True if this type change is expected to be accompanied by an owner change.
      • getChanges

        protected java.util.Map<UnitType,​java.util.List<UnitTypeChange>> getChanges()
        Get the change map.
        Returns:
        The map of unit type to eligible changes.
      • setChanges

        protected void setChanges​(java.util.Map<UnitType,​java.util.List<UnitTypeChange>> changes)
        Set the change map.
        Parameters:
        changes - The new map of unit type to eligible changes.
      • addUnitTypeChange

        public void addUnitTypeChange​(UnitTypeChange uc)
        Add a new change. Public for the test suite.
        Parameters:
        uc - The UnitTypeChange to add.
      • getUnitChanges

        public java.util.List<UnitTypeChange> getUnitChanges​(UnitType from)
        Get the unit changes possible from a given unit type.
        Parameters:
        from - The source UnitType.
        Returns:
        A list of UnitChanges.
      • getUnitChange

        public UnitTypeChange getUnitChange​(UnitType fromType,
                                            UnitType toType)
        Get a specific unit change for this unit change type, a source unit type to change, and an optional destination unit type.
        Parameters:
        fromType - The UnitType to change from.
        toType - An optional UnitType to change to.
        Returns:
        The UnitChange found, or null if the change is impossible.
      • deleteUnitChanges

        public void deleteUnitChanges​(UnitType from)
      • copyIn

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