net.sf.freecol.common.model
Class Modifier

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.model.Feature
          extended by net.sf.freecol.common.model.Modifier
All Implemented Interfaces:
java.lang.Comparable<Modifier>

public final class Modifier
extends Feature
implements java.lang.Comparable<Modifier>

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.


Nested Class Summary
static class Modifier.Type
           
 
Field Summary
static int AUTO_PRODUCTION_INDEX
           
static int BASIC_PRODUCTION_INDEX
           
static int BUILDING_PRODUCTION_INDEX
           
static int COLONY_PRODUCTION_INDEX
           
static java.lang.String DEFENCE
           
static java.lang.String DEFENCE_AGAINST
           
static int EXPERT_PRODUCTION_INDEX
           
static int FATHER_PRODUCTION_INDEX
           
static int IMPROVEMENT_PRODUCTION_INDEX
           
private  float increment
          The value increments per turn.
private  Modifier.Type incrementType
          The type of increment.
private  int index
          The sorting index.
static int NATION_PRODUCTION_INDEX
           
static java.lang.String OFFENCE
           
static java.lang.String OFFENCE_AGAINST
           
static java.lang.String TILE_TYPE_CHANGE_PRODUCTION
           
private  Modifier.Type type
          The type of this Modifier
static float UNKNOWN
           
private  float value
           
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, INFINITY, logger, NO_ID, PARTIAL_ATTRIBUTE, UNDEFINED, VALUE_TAG
 
Constructor Summary
private Modifier()
           
  Modifier(Modifier template)
          Creates a new Modifier instance.
  Modifier(java.lang.String id, float value, Modifier.Type type)
          Creates a new Modifier instance.
  Modifier(java.lang.String id, FreeColGameObjectType source, float value, Modifier.Type type)
          Creates a new Modifier instance.
  Modifier(javax.xml.stream.XMLStreamReader in, Specification specification)
          Creates a new Modifier instance.
 
Method Summary
 float applyTo(float number)
          Applies this Modifier to a number.
 int compareTo(Modifier modifier)
          Compares this object with the specified object for order.
 boolean equals(java.lang.Object o)
          
 float getIncrement()
          Get the Increment increment.
 Modifier.Type getIncrementType()
          Get the IncrementType value.
 int getIndex()
          Get the Index value.
 Modifier.Type getType()
          Get the Type value.
 float getValue()
          Get the Value value.
static java.lang.String getXMLElementTagName()
          Returns the XML tag name for this element.
 int hashCode()
          
 boolean hasIncrement()
          Returns true if this Modifier has an increment.
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 id from a template modifier (containing the increment and value) and given start turn.
protected  void readAttributes(javax.xml.stream.XMLStreamReader in, Specification specification)
          Reads the attributes of this object from an XML stream.
 void setIncrement(float newIncrement, Modifier.Type type, Turn firstTurn, Turn lastTurn)
          Set the Increment increment.
 void setIncrementType(Modifier.Type newIncrementType)
          Set the IncrementType value.
 void setIndex(int newIndex)
          Set the Index value.
 void setType(Modifier.Type newType)
          Set the Type value.
 void setValue(float newValue)
          Set the Value value.
 java.lang.String toString()
           
 void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
          This method writes an XML-representation of this object to the given stream.
protected  void writeAttributes(javax.xml.stream.XMLStreamWriter out)
          Write the attributes of this object to a stream.
 
Methods inherited from class net.sf.freecol.common.model.Feature
appliesTo, appliesTo, copy, getFirstTurn, getLastTurn, getNameKey, getScopes, getSource, hasScope, hasTimeLimit, isOutOfDate, readChildren, setFirstTurn, setLastTurn, setScopes, setSource, writeChildren
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, getSpecification, hasAbility, hasAttribute, hasListeners, readAttributes, readChild, readChild, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXML, readFromXMLElement, readFromXMLImpl, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setId, setSpecification, toXML, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

OFFENCE

public static final java.lang.String OFFENCE
See Also:
Constant Field Values

DEFENCE

public static final java.lang.String DEFENCE
See Also:
Constant Field Values

OFFENCE_AGAINST

public static final java.lang.String OFFENCE_AGAINST
See Also:
Constant Field Values

DEFENCE_AGAINST

public static final java.lang.String DEFENCE_AGAINST
See Also:
Constant Field Values

TILE_TYPE_CHANGE_PRODUCTION

public static final java.lang.String TILE_TYPE_CHANGE_PRODUCTION
See Also:
Constant Field Values

UNKNOWN

public static final float UNKNOWN
See Also:
Constant Field Values

BASIC_PRODUCTION_INDEX

public static int BASIC_PRODUCTION_INDEX

COLONY_PRODUCTION_INDEX

public static int COLONY_PRODUCTION_INDEX

EXPERT_PRODUCTION_INDEX

public static int EXPERT_PRODUCTION_INDEX

FATHER_PRODUCTION_INDEX

public static int FATHER_PRODUCTION_INDEX

IMPROVEMENT_PRODUCTION_INDEX

public static int IMPROVEMENT_PRODUCTION_INDEX

AUTO_PRODUCTION_INDEX

public static int AUTO_PRODUCTION_INDEX

BUILDING_PRODUCTION_INDEX

public static int BUILDING_PRODUCTION_INDEX

NATION_PRODUCTION_INDEX

public static int NATION_PRODUCTION_INDEX

value

private float value

increment

private float increment
The value increments per turn. This can be used to create Modifiers whose values increase or decrease over time.


type

private Modifier.Type type
The type of this Modifier


incrementType

private Modifier.Type incrementType
The type of increment.


index

private int index
The sorting index.

Constructor Detail

Modifier

private Modifier()

Modifier

public Modifier(java.lang.String id,
                float value,
                Modifier.Type type)
Creates a new Modifier instance.

Parameters:
id - a String value
value - an float value
type - the Type of the modifier

Modifier

public Modifier(java.lang.String id,
                FreeColGameObjectType source,
                float value,
                Modifier.Type type)
Creates a new Modifier instance.

Parameters:
id - a String value
source - a FreeColGameObjectType value
value - an float value
type - the Type of the modifier

Modifier

public Modifier(Modifier template)
Creates a new Modifier instance.

Parameters:
template - a Modifier value

Modifier

public Modifier(javax.xml.stream.XMLStreamReader in,
                Specification specification)
         throws javax.xml.stream.XMLStreamException
Creates a new Modifier instance.

Parameters:
in - a XMLStreamReader value
specification - a Specification value
Throws:
javax.xml.stream.XMLStreamException - if an error occurs
Method Detail

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 id 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 Modifier.Type getType()
Get the Type value.

Returns:
an Type value

setType

public void setType(Modifier.Type newType)
Set the Type value.

Parameters:
newType - The new Type value.

getIncrementType

public Modifier.Type getIncrementType()
Get the IncrementType value.

Returns:
a Type value

setIncrementType

public void setIncrementType(Modifier.Type newIncrementType)
Set the IncrementType value.

Parameters:
newIncrementType - The new IncrementType value.

getValue

public float getValue()
Get the Value value.

Returns:
a float value

setValue

public void setValue(float newValue)
Set the Value value.

Parameters:
newValue - The new Value value.

getIncrement

public float getIncrement()
Get the Increment increment.

Returns:
a float increment

setIncrement

public void setIncrement(float newIncrement,
                         Modifier.Type type,
                         Turn firstTurn,
                         Turn lastTurn)
Set the Increment increment.

Parameters:
newIncrement - The new Increment increment.

hasIncrement

public boolean hasIncrement()
Returns true if this Modifier has an increment.

Returns:
a boolean value

getIndex

public int getIndex()
Get the Index value.

Returns:
an int value

setIndex

public void setIndex(int newIndex)
Set the Index value.

Parameters:
newIndex - The new Index value.

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

hashCode

public int hashCode()
Description copied from class: Feature

Overrides:
hashCode in class Feature

equals

public boolean equals(java.lang.Object o)
Description copied from class: Feature

Overrides:
equals in class Feature

compareTo

public int compareTo(Modifier modifier)
Compares this object with the specified object for order. Returns a negative integer, zero, or a positive integer as this object is less than, equal to, or greater than the specified object.

Specified by:
compareTo in interface java.lang.Comparable<Modifier>
Parameters:
modifier - a Modifier value
Returns:
an int value

toXMLImpl

public void toXMLImpl(javax.xml.stream.XMLStreamWriter out)
               throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object to the given stream.

Specified by:
toXMLImpl in class FreeColObject
Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

writeAttributes

protected void writeAttributes(javax.xml.stream.XMLStreamWriter out)
                        throws javax.xml.stream.XMLStreamException
Write the attributes of this object to a stream.

Overrides:
writeAttributes in class Feature
Parameters:
out - The target stream.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

readAttributes

protected void readAttributes(javax.xml.stream.XMLStreamReader in,
                              Specification specification)
                       throws javax.xml.stream.XMLStreamException
Reads the attributes of this object from an XML stream.

Overrides:
readAttributes in class Feature
Parameters:
in - The XML input stream.
specification - A Specification to use.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getXMLElementTagName

public static java.lang.String getXMLElementTagName()
Returns the XML tag name for this element.

Returns:
a String value