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 class
Disaster.Effects
Whether to apply one, many or all applicable disasters.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
BANKRUPTCY
Bankruptcy occurs if upkeep is enabled and a player is unable to pay for the maintenance of all buildings.private static java.lang.String
EFFECT_TAG
private java.util.List<RandomChoice<Effect>>
effects
The effects of this disaster.private static java.lang.String
EFFECTS_TAG
private boolean
natural
Whether this disaster is natural.private static java.lang.String
NATURAL_TAG
private Disaster.Effects
numberOfEffects
The number of effects of this disaster.static java.lang.String
TAG
-
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 void
addEffect(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.Effects
getNumberOfEffects()
Get the number of effects.java.lang.String
getXMLTagName()
Get the serialization tag for this object.boolean
isNatural()
Is this a natural disaster?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.protected void
setEffects(java.util.List<RandomChoice<Effect>> effects)
Set the effect list.java.lang.String
toString()
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.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
- TheSpecification
to 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
Effects
to apply.
-
getEffects
public final java.util.List<RandomChoice<Effect>> getEffects()
Get the random choice list of effects.- Returns:
- A list of random
Effect
choices.
-
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
- TheEffect
to add.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classFreeColSpecObjectType
- 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 classFreeColSpecObjectType
- 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 classFreeColSpecObjectType
- 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 classFreeColSpecObjectType
- 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 classFreeColSpecObjectType
- Parameters:
xr
- TheFreeColXMLReader
to 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:
getXMLTagName
in classFreeColObject
- Returns:
- The tag.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classFreeColSpecObjectType
-
-