Package net.sf.freecol.common.model
Class Force
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColSpecObject
-
- net.sf.freecol.common.model.Force
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,ObjectWithId
public class Force extends FreeColSpecObject
A group of units with a common origin and purpose.
-
-
Field Summary
Fields Modifier and Type Field Description private int
capacity
The current naval transport capacity.private static java.lang.String
LAND_UNITS_TAG
private java.util.List<AbstractUnit>
landUnits
The number of land units in the REF.private static java.lang.String
NAVAL_UNITS_TAG
private java.util.List<AbstractUnit>
navalUnits
The number of naval units in the REF.private int
spaceRequired
The space required to transport all land units.static java.lang.String
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 Force(Specification specification)
Basic constructor.Force(Specification spec, java.util.List<AbstractUnit> units, java.lang.String ability)
Create a new Force.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
add(AbstractUnit au)
Add abstract units to this Force.double
calculateStrength(boolean naval)
Calculate the approximate offence power of this force.void
clearLandUnits()
Clear the land unit list.void
clearNavalUnits()
Clear the naval unit list.<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.int
getCapacity()
Get the cargo space provided by the naval units of this force.java.util.List<AbstractUnit>
getLandUnitsList()
Gets the land units.java.util.List<AbstractUnit>
getNavalUnitsList()
Gets the naval units.int
getSpaceRequired()
Get the cargo space required for the land units of this force.java.util.List<AbstractUnit>
getUnitList()
Gets all units.java.lang.String
getXMLTagName()
Get the serialization tag for this object.boolean
isEmpty()
Is this Force empty?boolean
matchAll(Force other)
Does another force match?int
prepareToBoard(UnitType shipType)
Defend against underprovisioned navies.void
readFromXML(FreeColXMLReader xr)
Initializes this object from an XML-representation of this object, unless the PARTIAL_ATTRIBUTE tag is present which indicates a partial update of an existing object.protected void
setLandUnitList(java.util.List<AbstractUnit> landUnits)
Set the land unit list.protected void
setNavalUnitList(java.util.List<AbstractUnit> navalUnits)
Set the naval unit list.java.lang.String
toString()
void
toXML(FreeColXMLWriter xw, java.lang.String tag)
This method writes an XML-representation of this object with a specified tag to the given 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, equals, 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, hasAbility, hasAbility, hasAbility, hashCode, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readAttributes, readChild, readChildren, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setGame, setId, toXML, toXMLPartial, toXMLPartial, writeAttributes, writeChildren
-
-
-
-
Field Detail
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
landUnits
private final java.util.List<AbstractUnit> landUnits
The number of land units in the REF.
-
navalUnits
private final java.util.List<AbstractUnit> navalUnits
The number of naval units in the REF.
-
spaceRequired
private int spaceRequired
The space required to transport all land units.
-
capacity
private int capacity
The current naval transport capacity.
-
LAND_UNITS_TAG
private static final java.lang.String LAND_UNITS_TAG
- See Also:
- Constant Field Values
-
NAVAL_UNITS_TAG
private static final java.lang.String NAVAL_UNITS_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Force
public Force(Specification specification)
Basic constructor.- Parameters:
specification
- TheSpecification
for this object.
-
Force
public Force(Specification spec, java.util.List<AbstractUnit> units, java.lang.String ability)
Create a new Force.- Parameters:
spec
- TheSpecification
for this object.units
- A list ofAbstractUnit
s defining the force.ability
- An optional ability name required of the units in the force.
-
-
Method Detail
-
getSpaceRequired
public final int getSpaceRequired()
Get the cargo space required for the land units of this force.- Returns:
- The required cargo space.
-
getCapacity
public final int getCapacity()
Get the cargo space provided by the naval units of this force.- Returns:
- The provided cargo space.
-
getUnitList
public final java.util.List<AbstractUnit> getUnitList()
Gets all units.- Returns:
- A copy of the list of all units.
-
clearLandUnits
public final void clearLandUnits()
Clear the land unit list.
-
clearNavalUnits
public final void clearNavalUnits()
Clear the naval unit list.
-
getLandUnitsList
public final java.util.List<AbstractUnit> getLandUnitsList()
Gets the land units.- Returns:
- A list of the land units.
-
setLandUnitList
protected void setLandUnitList(java.util.List<AbstractUnit> landUnits)
Set the land unit list.- Parameters:
landUnits
- Set the new landAbstractUnit
s.
-
getNavalUnitsList
public final java.util.List<AbstractUnit> getNavalUnitsList()
Gets the naval units.- Returns:
- A copy of the list of the naval units.
-
setNavalUnitList
protected void setNavalUnitList(java.util.List<AbstractUnit> navalUnits)
Set the naval unit list.- Parameters:
navalUnits
- Set the new landAbstractUnit
s.
-
isEmpty
public final boolean isEmpty()
Is this Force empty?- Returns:
- True if there are no land or naval units.
-
add
public final void add(AbstractUnit au)
Add abstract units to this Force.- Parameters:
au
- The addition to thisForce
.
-
calculateStrength
public double calculateStrength(boolean naval)
Calculate the approximate offence power of this force.- Parameters:
naval
- If true, consider only naval units, otherwise consider the land units.- Returns:
- The approximate offence power.
-
prepareToBoard
public int prepareToBoard(UnitType shipType)
Defend against underprovisioned navies.- Parameters:
shipType
- Optional shipUnitType
to create.- Returns:
- The amount of extra capacity.
-
matchAll
public boolean matchAll(Force other)
Does another force match?- Parameters:
other
- The otherForce
to test.- Returns:
- True if the other force contains the same units.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classFreeColSpecObject
- Type Parameters:
T
- TheFreeColObject
subclass of the object to copy in.- Parameters:
other
- The other object.- Returns:
- True if the copy in is succesful.
-
toXML
public void toXML(FreeColXMLWriter xw, java.lang.String tag) throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object with a specified tag to the given stream. Almost all FreeColObjects end up calling these, and implementing their own write{Attributes,Children} methods which begin by calling their superclass. This allows a clean nesting of the serialization routines throughout the class hierarchy. All attributes will be made visible.- Overrides:
toXML
in classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
to write to.tag
- The tag to use.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems writing to the stream.
-
readFromXML
public void readFromXML(FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Initializes this object from an XML-representation of this object, unless the PARTIAL_ATTRIBUTE tag is present which indicates a partial update of an existing object.- Overrides:
readFromXML
in classFreeColObject
- Parameters:
xr
- The input stream with the XML.- Throws:
javax.xml.stream.XMLStreamException
- if there are any problems 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 classFreeColObject
-
-