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
TheFeatureclass 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 intdurationThe duration of this Feature.private static java.lang.StringDURATION_TAGprivate static java.lang.StringFIRST_TURN_TAGprivate TurnfirstTurnThe first Turn in which this Feature applies.private static java.lang.StringLAST_TURN_TAGprivate TurnlastTurnThe last Turn in which this Feature applies.private ScopeContainerscopeContainerThe scopes limiting the applicability of this Feature.private FreeColObjectsourceThe source of this Feature, e.g.private static java.lang.StringSOURCE_TAGprivate booleantemporaryTransient 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.StringTEMPORARY_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 voidaddScope(Scope scope)booleanappliesTo(FreeColObject fco)protected booleanappliesTo(FreeColSpecObjectType objectType, Turn turn)Does this feature apply to a given object type and turn.protected booleanappliesTo(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.voidcopyScopes(java.util.Collection<Scope> scopes)booleanequals(java.lang.Object o)intgetDuration()Get the duration of this feature.TurngetFirstTurn()Get the first turn of a time limit.TurngetLastTurn()Get the last turn of a time limit.java.lang.StringgetNameKey()Gets the name of this named object.java.util.List<Scope>getScopeList()java.util.stream.Stream<Scope>getScopes()FreeColObjectgetSource()Get the source of this feature.inthashCode()booleanhasScope()booleanhasTimeLimit()Does this feature have a time limit?booleanisIndependent()Is this feature an independent stand-alone one, or is it derived from some other entity such as a founding father.booleanisOutOfDate(Turn turn)Is this feature out of date with respect to a given turn?booleanisTemporary()Is this a temporary feature?protected voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.protected voidreadChild(FreeColXMLReader xr)Reads a single child object.protected voidreadChildren(FreeColXMLReader xr)Reads the children of this object from an XML stream.voidsetDuration(int newDuration)Set the duration of this feature.voidsetFirstTurn(Turn newFirstTurn)Set the first turn of a time limit.voidsetLastTurn(Turn newLastTurn)Set the last turn of a time limit.voidsetSource(FreeColObject newSource)Set the source of this feature.voidsetTemporary(boolean newTemporary)Set the temporary status.protected voidwriteAttributes(FreeColXMLWriter xw)Write the attributes of this object to a stream.protected voidwriteChildren(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- TheSpecificationto 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- TheTurnto 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- TheFreeColSpecObjectTypeto test.turn- TheTurnto 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- TheTurnto 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:
getNameKeyin 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:
copyInin classFreeColSpecObject- Type Parameters:
T- TheFreeColObjectsubclass 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:
writeAttributesin classFreeColObject- Parameters:
xw- TheFreeColXMLWriterto 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:
writeChildrenin classFreeColObject- Parameters:
xw- TheFreeColXMLWriterto 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:
readAttributesin classFreeColObject- Parameters:
xr- TheFreeColXMLReaderto 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:
readChildrenin classFreeColObject- Parameters:
xr- TheFreeColXMLReaderto 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:
readChildin classFreeColObject- Parameters:
xr- TheFreeColXMLReaderto read from.- Throws:
javax.xml.stream.XMLStreamException- if there is a problem reading the stream.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classFreeColObject
-
hashCode
public int hashCode()
- Overrides:
hashCodein classFreeColObject
-
-