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 class
FoundingFather.FoundingFatherType
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<Event>
events
The events triggered by this Founding Father.private static java.lang.String
FROM_ID_TAG
static java.lang.String
TAG
private static java.lang.String
TO_ID_TAG
private FoundingFather.FoundingFatherType
type
The type of this FoundingFather.private static java.lang.String
TYPE_TAG
private static java.lang.String
UNIT_TAG
private java.util.List<AbstractUnit>
units
A list of AbstractUnits generated by this FoundingFather.private static java.lang.String
UPGRADE_TAG
private int[]
weight
The probability of this FoundingFather being offered for selection, across the game ages.private static java.lang.String
WEIGHT_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 void
addEvent(Event event)
Add an event.private void
addUnit(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.FoundingFatherType
getType()
Gets the type of this FoundingFather.java.lang.String
getTypeKey()
Get a key for the type of this FoundingFather.java.util.List<AbstractUnit>
getUnitList()
Get the units this father supplies.int
getWeight(int age)
Get the weight of this FoundingFather.java.lang.String
getXMLTagName()
Get the serialization tag for this object.boolean
isAvailableTo(Player player)
Is this Founding Father available to the given player? Note that this does not cover restrictions due to the Age.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
setEvents(java.util.List<Event> newEvents)
Set the events this Founding Father triggers.void
setType(FoundingFather.FoundingFatherType type)
Set the type of this FoundingFather.void
setUnits(java.util.List<AbstractUnit> newUnits)
Set the units supplied by this Founding Father.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, 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
- TheSpecification
to 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
Event
s.
-
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
- TheEvent
to add.
-
getUnitList
public final java.util.List<AbstractUnit> getUnitList()
Get the units this father supplies.- Returns:
- A list of
AbstractUnit
s.
-
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
- TheAbstractUnit
to 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
- ThePlayer
to 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:
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.
-
-