Package net.sf.freecol.common.model
Class Disaster
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColSpecObject
-
- net.sf.freecol.common.model.FreeColSpecObjectType
-
- net.sf.freecol.common.model.Disaster
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>,Named,ObjectWithId
public class Disaster extends FreeColSpecObjectType
This class describes disasters that can happen to a Colony, such as flooding, disease or Indian raids.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classDisaster.EffectsWhether to apply one, many or all applicable disasters.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringBANKRUPTCYBankruptcy occurs if upkeep is enabled and a player is unable to pay for the maintenance of all buildings.private static java.lang.StringEFFECT_TAGprivate java.util.List<RandomChoice<Effect>>effectsThe effects of this disaster.private static java.lang.StringEFFECTS_TAGprivate booleannaturalWhether this disaster is natural.private static java.lang.StringNATURAL_TAGprivate Disaster.EffectsnumberOfEffectsThe number of effects of this disaster.static java.lang.StringTAG-
Fields inherited from class net.sf.freecol.common.model.FreeColSpecObjectType
DELETE_TAG, EXTENDS_TAG, PRESERVE_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 Disaster(java.lang.String id, Specification specification)Create a new disaster.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddEffect(Effect effect)Add an effect.<T extends FreeColObject>
booleancopyIn(T other)Copy another FreeColObject into this one if it is compatible.java.util.List<RandomChoice<Effect>>getEffects()Get the random choice list of effects.Disaster.EffectsgetNumberOfEffects()Get the number of effects.java.lang.StringgetXMLTagName()Get the serialization tag for this object.booleanisNatural()Is this a natural disaster?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.protected voidsetEffects(java.util.List<RandomChoice<Effect>> effects)Set the effect list.java.lang.StringtoString()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.FreeColSpecObjectType
addScope, appliesTo, copyScopes, getDescriptionKey, getFeatureContainer, getIndex, getNameKey, getScopeList, getScopes, isAbstractType, removeScope, setIndex
-
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, equals, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getClassIndex, getDefenceModifiers, getDisplayObject, getFreeColObjectClass, getFreeColObjectClassByName, getGame, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, hasAbility, hasAbility, hasAbility, hashCode, 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, toXML, toXML, toXMLPartial, toXMLPartial
-
-
-
-
Field Detail
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
BANKRUPTCY
public static final java.lang.String BANKRUPTCY
Bankruptcy occurs if upkeep is enabled and a player is unable to pay for the maintenance of all buildings.- See Also:
- Constant Field Values
-
natural
private boolean natural
Whether this disaster is natural. Defaults to false.
-
numberOfEffects
private Disaster.Effects numberOfEffects
The number of effects of this disaster. Defaults toONE.
-
effects
private java.util.List<RandomChoice<Effect>> effects
The effects of this disaster.
-
EFFECT_TAG
private static final java.lang.String EFFECT_TAG
- See Also:
- Constant Field Values
-
EFFECTS_TAG
private static final java.lang.String EFFECTS_TAG
- See Also:
- Constant Field Values
-
NATURAL_TAG
private static final java.lang.String NATURAL_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Disaster
public Disaster(java.lang.String id, Specification specification)Create a new disaster.- Parameters:
id- The object identifier.specification- TheSpecificationto refer to.
-
-
Method Detail
-
isNatural
public final boolean isNatural()
Is this a natural disaster?- Returns:
- True if this is a natural disaster.
-
getNumberOfEffects
public final Disaster.Effects getNumberOfEffects()
Get the number of effects.- Returns:
- The
Effectsto apply.
-
getEffects
public final java.util.List<RandomChoice<Effect>> getEffects()
Get the random choice list of effects.- Returns:
- A list of random
Effectchoices.
-
setEffects
protected void setEffects(java.util.List<RandomChoice<Effect>> effects)
Set the effect list.- Parameters:
effects- The new effects list.
-
addEffect
private void addEffect(Effect effect)
Add an effect.- Parameters:
effect- TheEffectto add.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyInin classFreeColSpecObjectType- 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 classFreeColSpecObjectType- 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 classFreeColSpecObjectType- 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 classFreeColSpecObjectType- 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 classFreeColSpecObjectType- Parameters:
xr- TheFreeColXMLReaderto 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:
getXMLTagNamein classFreeColObject- Returns:
- The tag.
-
toString
public java.lang.String toString()
- Overrides:
toStringin classFreeColSpecObjectType
-
-