Class Modifier

  • All Implemented Interfaces:
    java.lang.Comparable<FreeColObject>, Named, ObjectWithId

    public class Modifier
    extends Feature
    The Modifier class encapsulates a bonus or penalty that can be applied to any action within the game, most obviously combat. The Modifier may be applicable only to certain Objects specified by means of Scope objects.
    • Constructor Detail

      • Modifier

        public Modifier​(Specification specification)
        Deliberately empty constructor.
        Parameters:
        specification - The defining Specification.
      • Modifier

        public Modifier​(java.lang.String id,
                        float value,
                        Modifier.ModifierType type,
                        FreeColObject source,
                        int modifierIndex)
        Creates a new Modifier instance.
        Parameters:
        id - The object identifier.
        value - The modifier value.
        type - The type of the modifier.
        source - The source FreeColObject.
        modifierIndex - The modifier index.
      • Modifier

        public Modifier​(java.lang.String id,
                        float value,
                        Modifier.ModifierType type,
                        FreeColObject source)
        Creates a new Modifier instance.
        Parameters:
        id - The object identifier.
        value - The modifier value.
        type - The type of the modifier.
        source - The source FreeColObject.
      • Modifier

        public Modifier​(java.lang.String id,
                        float value,
                        Modifier.ModifierType type)
        Creates a new Modifier instance.
        Parameters:
        id - The object identifier.
        value - The modifier value.
        type - The type of the modifier.
      • Modifier

        public Modifier​(FreeColXMLReader xr,
                        Specification specification)
                 throws javax.xml.stream.XMLStreamException
        Creates a new Modifier instance.
        Parameters:
        xr - The FreeColXMLReader to read from.
        specification - The Specification to refer to.
        Throws:
        javax.xml.stream.XMLStreamException - if there is an error reading the stream.
    • Method Detail

      • makeModifier

        public static Modifier makeModifier​(Modifier modifier)
        Make a copy of a modifier.
        Parameters:
        modifier - The Modifier to copy.
        Returns:
        A copy of the modifier.
      • makeTimedModifier

        public static Modifier makeTimedModifier​(java.lang.String id,
                                                 Modifier template,
                                                 Turn start)
        Makes a timed modifier (one with start/end turn and increment) with the specified identifier from a template modifier (containing the increment and value) and given start turn. Currently the only suitable template is "model.modifier.colonyGoodsParty".
        Parameters:
        id - The id for the new modifier.
        template - A template Modifier with increment.
        start - The starting Turn.
        Returns:
        A new timed modifier.
      • getType

        public final Modifier.ModifierType getType()
        Get the modifier type.
        Returns:
        The ModifierType.
      • setType

        public final Modifier setType​(Modifier.ModifierType modifierType)
        Set the modifier type.
        Parameters:
        modifierType - The new ModifierType value.
        Returns:
        This modifier.
      • isFloatKnown

        public static boolean isFloatKnown​(float value)
        Is this a "known" value.
        Parameters:
        value - The value to test.
        Returns:
        True if the value is known.
      • isKnown

        public boolean isKnown()
        Does this modifier have a known value? That is, is it not set to the UNKNOWN value.
        Returns:
        True if the value is known.
      • getValue

        public final float getValue()
        Get the modifier value.
        Returns:
        The modifier value.
      • getValue

        public final float getValue​(Turn turn)
        Get the value the modifier during the given Turn.
        Parameters:
        turn - The Turn to check.
        Returns:
        The turn-dependent modifier value.
      • setValue

        public final Modifier setValue​(float value)
        Set the modifier value.
        Parameters:
        value - The new value.
        Returns:
        This modifier.
      • hasIncrement

        public final boolean hasIncrement()
        Does this modifier have an increment?
        Returns:
        True if this modifier has an increment.
      • getIncrementType

        public final Modifier.ModifierType getIncrementType()
        Get the increment type.
        Returns:
        The increment ModifierType.
      • setIncrementType

        public final Modifier setIncrementType​(Modifier.ModifierType incrementType)
        Set the increment type.
        Parameters:
        incrementType - The new increment ModifierType.
        Returns:
        This modifier.
      • getIncrement

        public final float getIncrement()
        Get the increment value.
        Returns:
        The increment value.
      • setIncrement

        public final Modifier setIncrement​(float increment)
        Set the increment value.
        Parameters:
        increment - The new value.
        Returns:
        This modifier.
      • setIncrement

        public final Modifier setIncrement​(Modifier.ModifierType incrementType,
                                           float increment,
                                           Turn firstTurn,
                                           Turn lastTurn)
        Set the whole increment.
        Parameters:
        incrementType - The new ModifierType.
        increment - The new increment value.
        firstTurn - The first Turn the increment is active.
        lastTurn - The last Turn the increment is active.
        Returns:
        This modifier.
      • getModifierIndex

        public final int getModifierIndex()
        Get the modifier index.
        Returns:
        The modifier index.
      • setModifierIndex

        public final Modifier setModifierIndex​(int modifierIndex)
        Set the modifier index.
        Parameters:
        modifierIndex - The new modifier index value.
        Returns:
        This modifier.
      • apply

        public float apply​(float base,
                           float value)
        Applies the given value to the given base value, depending on the type of this Modifier.
        Parameters:
        base - a float value
        value - a float value
        Returns:
        a float value
      • apply

        private float apply​(float base,
                            float value,
                            Modifier.ModifierType type)
        Applies the given value to the given base value, depending on the give modifier Type.
        Parameters:
        base - The base value.
        value - The modifier value.
        type - The ModifierType.
        Returns:
        The result of applying the value to the base.
      • applyTo

        public float applyTo​(float number)
        Applies this Modifier to a number. This method does not take scopes, increments or time limits into account.
        Parameters:
        number - a float value
        Returns:
        a float value
      • applyTo

        public float applyTo​(float number,
                             Turn turn)
        Applies this Modifier to a number. This method does take increments into account.
        Parameters:
        number - The number to modify.
        turn - The Turn to evaluate increments in.
        Returns:
        The modified number.
      • copyIn

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

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