Package net.sf.freecol.common.model
Class FoundingFather
- 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.FoundingFather
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>,Named,ObjectWithId
public class FoundingFather extends FreeColSpecObjectType
Represents one FoundingFather to be contained in a Player object. The FoundingFather is able to grant new abilities or bonuses to the player, or to cause certain events.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFoundingFather.FoundingFatherType
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<Event>eventsThe events triggered by this Founding Father.private static java.lang.StringFROM_ID_TAGstatic java.lang.StringTAGprivate static java.lang.StringTO_ID_TAGprivate FoundingFather.FoundingFatherTypetypeThe type of this FoundingFather.private static java.lang.StringTYPE_TAGprivate static java.lang.StringUNIT_TAGprivate java.util.List<AbstractUnit>unitsA list of AbstractUnits generated by this FoundingFather.private static java.lang.StringUPGRADE_TAGprivate int[]weightThe probability of this FoundingFather being offered for selection, across the game ages.private static java.lang.StringWEIGHT_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 FoundingFather(java.lang.String id, Specification specification)Create a new Founding Father.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddEvent(Event event)Add an event.private voidaddUnit(AbstractUnit unit)Add a unit.<T extends FreeColObject>
booleancopyIn(T other)Copy another FreeColObject into this one if it is compatible.java.util.List<Event>getEvents()Get the events this father triggers.FoundingFather.FoundingFatherTypegetType()Gets the type of this FoundingFather.java.lang.StringgetTypeKey()Get a key for the type of this FoundingFather.java.util.List<AbstractUnit>getUnitList()Get the units this father supplies.intgetWeight(int age)Get the weight of this FoundingFather.java.lang.StringgetXMLTagName()Get the serialization tag for this object.booleanisAvailableTo(Player player)Is this Founding Father available to the given player? Note that this does not cover restrictions due to the Age.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.voidsetEvents(java.util.List<Event> newEvents)Set the events this Founding Father triggers.voidsetType(FoundingFather.FoundingFatherType type)Set the type of this FoundingFather.voidsetUnits(java.util.List<AbstractUnit> newUnits)Set the units supplied by this Founding Father.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, toString
-
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
-
type
private FoundingFather.FoundingFatherType type
The type of this FoundingFather.
-
weight
private final int[] weight
The probability of this FoundingFather being offered for selection, across the game ages.
-
events
private java.util.List<Event> events
The events triggered by this Founding Father.
-
units
private java.util.List<AbstractUnit> units
A list of AbstractUnits generated by this FoundingFather.
-
FROM_ID_TAG
private static final java.lang.String FROM_ID_TAG
- See Also:
- Constant Field Values
-
TO_ID_TAG
private static final java.lang.String TO_ID_TAG
- See Also:
- Constant Field Values
-
TYPE_TAG
private static final java.lang.String TYPE_TAG
- See Also:
- Constant Field Values
-
UNIT_TAG
private static final java.lang.String UNIT_TAG
- See Also:
- Constant Field Values
-
WEIGHT_TAG
private static final java.lang.String WEIGHT_TAG
- See Also:
- Constant Field Values
-
UPGRADE_TAG
private static final java.lang.String UPGRADE_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
FoundingFather
public FoundingFather(java.lang.String id, Specification specification)Create a new Founding Father.- Parameters:
id- The object identifier.specification- TheSpecificationto refer to.
-
-
Method Detail
-
getType
public FoundingFather.FoundingFatherType getType()
Gets the type of this FoundingFather.- Returns:
- The type of this FoundingFather.
-
setType
public void setType(FoundingFather.FoundingFatherType type)
Set the type of this FoundingFather. Public for the test suite.- Parameters:
type- A newFoundingFatherType.
-
getTypeKey
public java.lang.String getTypeKey()
Get a key for the type of this FoundingFather.- Returns:
- A type key.
-
getWeight
public int getWeight(int age)
Get the weight of this FoundingFather. This is used to select a random FoundingFather.- Parameters:
age- The age ([0, 2])- Returns:
- The weight of this father in the given age.
-
getEvents
public final java.util.List<Event> getEvents()
Get the events this father triggers.- Returns:
- A list of
Events.
-
setEvents
public final void setEvents(java.util.List<Event> newEvents)
Set the events this Founding Father triggers. Public for the test suite.- Parameters:
newEvents- The new events.
-
addEvent
private void addEvent(Event event)
Add an event.- Parameters:
event- TheEventto add.
-
getUnitList
public final java.util.List<AbstractUnit> getUnitList()
Get the units this father supplies.- Returns:
- A list of
AbstractUnits.
-
setUnits
public final void setUnits(java.util.List<AbstractUnit> newUnits)
Set the units supplied by this Founding Father. Public for the test suite.- Parameters:
newUnits- The new units.
-
addUnit
private void addUnit(AbstractUnit unit)
Add a unit.- Parameters:
unit- TheAbstractUnitto add.
-
isAvailableTo
public boolean isAvailableTo(Player player)
Is this Founding Father available to the given player? Note that this does not cover restrictions due to the Age.- Parameters:
player- ThePlayerto test.- Returns:
- True if the father is available.
-
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.
-
-