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

public final 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.


Nested Class Summary
static class Modifier.Type
           
 
Field Summary
static java.lang.String CAPITAL_DEFENCE
           
static java.lang.String DEFENCE
           
private  float increment
          The value increments per turn.
private  Modifier.Type incrementType
          Describe incrementType here.
static java.lang.String OFFENCE
           
static java.lang.String SETTLEMENT_DEFENCE
           
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, logger, PARTIAL_ATTRIBUTE
 
Constructor Summary
private Modifier()
           
  Modifier(org.w3c.dom.Element element)
          Creates a new Modifier instance.
  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.
static Modifier createTeaPartyModifier(Turn turn)
           
 boolean equals(java.lang.Object o)
           
 float getIncrement()
          Get the Increment increment.
 Modifier.Type getIncrementType()
          Get the IncrementType 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.
 void readAttributes(javax.xml.stream.XMLStreamReader in, Specification specification)
           
 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 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.
 void writeAttributes(javax.xml.stream.XMLStreamWriter out)
           
 
Methods inherited from class net.sf.freecol.common.model.Feature
appliesTo, appliesTo, getFirstTurn, getLastTurn, getScopes, getSource, hasScope, hasTimeLimit, isOutOfDate, readChildren, readFromXMLImpl, setFirstTurn, setLastTurn, setScopes, setSource, writeChildren
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, hasAbility, hasAttribute, hasListeners, readAttributes, readFromArrayElement, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXML, readFromXMLElement, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, setId, toArrayElement, toArrayElement, toListElement, toXML, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute, writeFreeColGameObject
 
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

CAPITAL_DEFENCE

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

SETTLEMENT_DEFENCE

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

UNKNOWN

public static final float UNKNOWN
See Also:
Constant Field Values

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
Describe incrementType here.

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(org.w3c.dom.Element element)
Creates a new Modifier instance.

Parameters:
element - an Element 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

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

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()
Overrides:
hashCode in class Feature

equals

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

createTeaPartyModifier

public static Modifier createTeaPartyModifier(Turn turn)

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.

getXMLElementTagName

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

Returns:
a String value

readAttributes

public void readAttributes(javax.xml.stream.XMLStreamReader in,
                           Specification specification)
                    throws javax.xml.stream.XMLStreamException
Overrides:
readAttributes in class Feature
Throws:
javax.xml.stream.XMLStreamException

writeAttributes

public void writeAttributes(javax.xml.stream.XMLStreamWriter out)
                     throws javax.xml.stream.XMLStreamException
Overrides:
writeAttributes in class Feature
Throws:
javax.xml.stream.XMLStreamException

toString

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