Class Feature

  • All Implemented Interfaces:
    java.lang.Comparable<FreeColObject>, Named, ObjectWithId
    Direct Known Subclasses:
    Ability, Modifier

    public abstract class Feature
    extends FreeColSpecObject
    implements Named
    The Feature class encapsulates a bonus or penalty that can be applied to any action within the game, most obviously combat. Do not make this a FCSOT because that has a FeatureContainer. Lumping features onto features would be incoherent.
    • Field Detail

      • source

        private FreeColObject source
        The source of this Feature, e.g. a UnitType.
      • firstTurn

        private Turn firstTurn
        The first Turn in which this Feature applies.
      • lastTurn

        private Turn lastTurn
        The last Turn in which this Feature applies.
      • duration

        private int duration
        The duration of this Feature. By default, the duration is unlimited.
      • temporary

        private boolean temporary
        Transient features are provided by events such as disasters and goods parties, and need to be serialized by the FreeColGameObject they apply to.
      • scopeContainer

        private ScopeContainer scopeContainer
        The scopes limiting the applicability of this Feature.
    • Constructor Detail

      • Feature

        public Feature​(Specification specification)
        Deliberately trivial constructor.
        Parameters:
        specification - The Specification to use.
    • Method Detail

      • hasTimeLimit

        public final boolean hasTimeLimit()
        Does this feature have a time limit?
        Returns:
        True if the feature is time limited.
      • getFirstTurn

        public final Turn getFirstTurn()
        Get the first turn of a time limit.
        Returns:
        The first turn, or null if none.
      • setFirstTurn

        public final void setFirstTurn​(Turn newFirstTurn)
        Set the first turn of a time limit.
        Parameters:
        newFirstTurn - The new first turn value.
      • getLastTurn

        public final Turn getLastTurn()
        Get the last turn of a time limit.
        Returns:
        The last turn, or null if none.
      • setLastTurn

        public final void setLastTurn​(Turn newLastTurn)
        Set the last turn of a time limit.
        Parameters:
        newLastTurn - The new last turn value.
      • getSource

        public final FreeColObject getSource()
        Get the source of this feature.
        Returns:
        The source object.
      • setSource

        public final void setSource​(FreeColObject newSource)
        Set the source of this feature.
        Parameters:
        newSource - The new source.
      • getDuration

        public final int getDuration()
        Get the duration of this feature.
        Returns:
        The number of turns this feature lasts.
      • setDuration

        public final void setDuration​(int newDuration)
        Set the duration of this feature.
        Parameters:
        newDuration - The new duration.
      • isTemporary

        public final boolean isTemporary()
        Is this a temporary feature?
        Returns:
        True if this is a temporary feature.
      • setTemporary

        public final void setTemporary​(boolean newTemporary)
        Set the temporary status.
        Parameters:
        newTemporary - The new temporary status.
      • appliesTo

        protected boolean appliesTo​(Turn turn)
        Does this feature apply to a given turn?
        Parameters:
        turn - The Turn to test.
        Returns:
        True if the turn is null or not outside a valid time limit.
      • appliesTo

        protected boolean appliesTo​(FreeColSpecObjectType objectType,
                                    Turn turn)
        Does this feature apply to a given object type and turn.
        Parameters:
        objectType - The FreeColSpecObjectType to test.
        turn - The Turn to test.
        Returns:
        True if the feature applies.
      • isOutOfDate

        public boolean isOutOfDate​(Turn turn)
        Is this feature out of date with respect to a given turn?
        Parameters:
        turn - The Turn to compare to.
        Returns:
        True if the Feature has an lastTurn turn smaller than the given turn.
      • isIndependent

        public boolean isIndependent()
        Is this feature an independent stand-alone one, or is it derived from some other entity such as a founding father. This is important for player and colony serialization, where we do *not* want to read or write derived features because they are added to the player by the source.
        Returns:
        True if the feature is independent.
      • 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.
      • hasScope

        public final boolean hasScope()
      • getScopeList

        public final java.util.List<Scope> getScopeList()
      • getScopes

        public final java.util.stream.Stream<Scope> getScopes()
      • copyScopes

        public final void copyScopes​(java.util.Collection<Scope> scopes)
      • addScope

        public final void addScope​(Scope scope)
      • 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.
      • 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 FreeColObject
        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.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class FreeColObject