Package net.sf.freecol.common.model
Class Feature
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColSpecObject
-
- net.sf.freecol.common.model.Feature
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,Named
,ObjectWithId
public abstract class Feature extends FreeColSpecObject implements Named
TheFeature
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 Summary
Fields Modifier and Type Field Description private int
duration
The duration of this Feature.private static java.lang.String
DURATION_TAG
private static java.lang.String
FIRST_TURN_TAG
private Turn
firstTurn
The first Turn in which this Feature applies.private static java.lang.String
LAST_TURN_TAG
private Turn
lastTurn
The last Turn in which this Feature applies.private ScopeContainer
scopeContainer
The scopes limiting the applicability of this Feature.private FreeColObject
source
The source of this Feature, e.g.private static java.lang.String
SOURCE_TAG
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.private static java.lang.String
TEMPORARY_TAG
-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, logger, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Constructor Summary
Constructors Constructor Description Feature(Specification specification)
Deliberately trivial constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addScope(Scope scope)
boolean
appliesTo(FreeColObject fco)
protected boolean
appliesTo(FreeColSpecObjectType objectType, Turn turn)
Does this feature apply to a given object type and turn.protected boolean
appliesTo(Turn turn)
Does this feature apply to a given turn?<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.void
copyScopes(java.util.Collection<Scope> scopes)
boolean
equals(java.lang.Object o)
int
getDuration()
Get the duration of this feature.Turn
getFirstTurn()
Get the first turn of a time limit.Turn
getLastTurn()
Get the last turn of a time limit.java.lang.String
getNameKey()
Gets the name of this named object.java.util.List<Scope>
getScopeList()
java.util.stream.Stream<Scope>
getScopes()
FreeColObject
getSource()
Get the source of this feature.int
hashCode()
boolean
hasScope()
boolean
hasTimeLimit()
Does this feature have a time limit?boolean
isIndependent()
Is this feature an independent stand-alone one, or is it derived from some other entity such as a founding father.boolean
isOutOfDate(Turn turn)
Is this feature out of date with respect to a given turn?boolean
isTemporary()
Is this a temporary feature?protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.protected void
readChild(FreeColXMLReader xr)
Reads a single child object.protected void
readChildren(FreeColXMLReader xr)
Reads the children of this object from an XML stream.void
setDuration(int newDuration)
Set the duration of this feature.void
setFirstTurn(Turn newFirstTurn)
Set the first turn of a time limit.void
setLastTurn(Turn newLastTurn)
Set the last turn of a time limit.void
setSource(FreeColObject newSource)
Set the source of this feature.void
setTemporary(boolean newTemporary)
Set the temporary status.protected void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.protected void
writeChildren(FreeColXMLWriter xw)
Write the children of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.FreeColSpecObject
getSpecification, setSpecification
-
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addAbility, addFeatures, addModifier, addPropertyChangeListener, addPropertyChangeListener, apply, apply, applyModifiers, applyModifiers, arrayKey, compareIds, compareTo, containsAbilityKey, containsModifierKey, copy, copy, copy, copy, copyInCast, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getClassIndex, getDefenceModifiers, getDisplayObject, getFeatureContainer, getFreeColObjectClass, getFreeColObjectClassByName, getGame, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, getXMLTagName, hasAbility, hasAbility, hasAbility, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readFromXML, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setGame, setId, toString, toXML, toXML, toXMLPartial, toXMLPartial
-
-
-
-
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.
-
DURATION_TAG
private static final java.lang.String DURATION_TAG
- See Also:
- Constant Field Values
-
FIRST_TURN_TAG
private static final java.lang.String FIRST_TURN_TAG
- See Also:
- Constant Field Values
-
LAST_TURN_TAG
private static final java.lang.String LAST_TURN_TAG
- See Also:
- Constant Field Values
-
SOURCE_TAG
private static final java.lang.String SOURCE_TAG
- See Also:
- Constant Field Values
-
TEMPORARY_TAG
private static final java.lang.String TEMPORARY_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Feature
public Feature(Specification specification)
Deliberately trivial constructor.- Parameters:
specification
- TheSpecification
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
- TheTurn
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
- TheFreeColSpecObjectType
to test.turn
- TheTurn
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
- TheTurn
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 interfaceNamed
- 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)
-
appliesTo
public boolean appliesTo(FreeColObject fco)
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classFreeColSpecObject
- Type Parameters:
T
- TheFreeColObject
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 classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
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 classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
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 classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
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 classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
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 classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
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 classFreeColObject
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classFreeColObject
-
-