Package net.sf.freecol.common.model
Class Role
- java.lang.Object
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>,Named,ObjectWithId
public class Role extends BuildableType
The role of a unit.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRole.RoleChangeContainer for valid role changes.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.StringCAPTURE_TAGprivate RoledowngradeThe Role to downgrade to after losing a battle.private static java.lang.StringDOWNGRADE_TAGprivate static java.lang.StringEXPERT_UNIT_TAGprivate UnitTypeexpertUnitThe expert unit for this Role, e.g.private static java.lang.StringFROM_TAGprivate static java.lang.StringMAXIMUM_COUNT_TAGprivate intmaximumCountThe maximum multiple of required goods this Role may carry.static java.util.Comparator<Role>militaryComparatorA comparator to order roles by descending total military effectiveness.private static java.lang.StringOLD_EXPERT_UNIT_TAGprivate static java.lang.StringOLD_MAXIMUM_COUNT_TAGprivate static java.lang.StringROLE_CHANGE_TAGprivate java.util.List<Role.RoleChange>roleChangesThe role changes by capture available for this role.static java.lang.StringTAG-
Fields inherited from class net.sf.freecol.common.model.BuildableType
REQUIRED_POPULATION_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 Role(java.lang.String id, Specification specification)Creates a newRoleinstance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddRoleChange(java.lang.String from, java.lang.String capture)Add a new role change.Colony.NoBuildReasoncanBeBuiltInColony(Colony colony, java.util.List<BuildableType> assumeBuilt)Check to see if this buildable type can be built in a colony based on the buildings or units available.<T extends FreeColObject>
booleancopyIn(T other)Copy another FreeColObject into this one if it is compatible.static java.util.List<Role>getAvailableRoles(Player player, UnitType type, java.util.List<Role> roles)Filter a list of proposed roles by availability.private doublegetDefence()Get the defence value for this role.RolegetDowngrade()Get the downgraded role from this one.UnitTypegetExpertUnit()Gets the expert profession for this role.static java.util.List<AbstractGoods>getGoodsDifference(Role from, int fromCount, Role to, int toCount)Gets a list of goods required to change from the first role to the second.intgetMaximumCount()Gets the maximum goods count for the role.doublegetOffence()Get the offense value for this role.java.util.stream.Stream<AbstractGoods>getRequiredGoods(int roleCount)Get the required goods for this role, considering also the role count, as a stream.java.util.List<AbstractGoods>getRequiredGoodsList(int roleCount)Get the required goods for this role, considering also the role count.intgetRequiredGoodsPrice(Market market)Get the price of the required goods in a given market.java.util.List<Role.RoleChange>getRoleChanges()Get the role changes that can allow a unit to assume this role.static java.lang.StringgetRoleIdSuffix(java.lang.String roleId)Get the last part of a role identifier.intgetRoleIndex()Establish a simple ordering.java.lang.StringgetRoleSuffix()Get the last part of a role identifier.java.lang.StringgetXMLTagName()Get the serialization tag for this object.booleanisCompatibleWith(Role other)Is this role compatible with another?booleanisDefaultRole()Is this the default role?static booleanisDefaultRoleId(java.lang.String roleId)Is this the default role?booleanisDefensive()Is this an defensive role?booleanisOffensive()Is this an offensive role?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.static booleanrolesCompatible(Role role1, Role role2)Are two roles compatible.voidsetDowngrade(Role newDowngrade)Sets the downgraded role.voidsetExpertUnit(UnitType newExpertUnit)Sets the expert profession for this role.voidsetMaximumCount(int newMaximumCount)Sets the maximum goods count for this role.protected voidsetRoleChanges(java.util.List<Role.RoleChange> roleChanges)Set the role change list.java.lang.StringtoFullString()Longer format debug helper.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.BuildableType
addRequiredAbility, getCurrentlyBuildingLabel, getLimits, getMaximumIndex, getMinimumIndex, getRequiredAbilities, getRequiredAmountOf, getRequiredGoods, getRequiredGoodsList, getRequiredPopulation, isAvailableTo, needsGoodsToBuild, removeRequiredAbility, requiresAbility, setLimits, setRequiredAbilities, setRequiredGoods, setRequiredPopulation
-
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
-
militaryComparator
public static final java.util.Comparator<Role> militaryComparator
A comparator to order roles by descending total military effectiveness.
-
downgrade
private Role downgrade
The Role to downgrade to after losing a battle. Defaults tonull. Note that some UnitTypes and Roles may be disposed instead of downgraded when losing a battle.
-
maximumCount
private int maximumCount
The maximum multiple of required goods this Role may carry. Defaults to1.
-
expertUnit
private UnitType expertUnit
The expert unit for this Role, e.g. a hardy pioneer is an expert for the pioneer role.
-
roleChanges
private java.util.List<Role.RoleChange> roleChanges
The role changes by capture available for this role.
-
CAPTURE_TAG
private static final java.lang.String CAPTURE_TAG
- See Also:
- Constant Field Values
-
DOWNGRADE_TAG
private static final java.lang.String DOWNGRADE_TAG
- See Also:
- Constant Field Values
-
FROM_TAG
private static final java.lang.String FROM_TAG
- See Also:
- Constant Field Values
-
EXPERT_UNIT_TAG
private static final java.lang.String EXPERT_UNIT_TAG
- See Also:
- Constant Field Values
-
MAXIMUM_COUNT_TAG
private static final java.lang.String MAXIMUM_COUNT_TAG
- See Also:
- Constant Field Values
-
ROLE_CHANGE_TAG
private static final java.lang.String ROLE_CHANGE_TAG
- See Also:
- Constant Field Values
-
OLD_EXPERT_UNIT_TAG
private static final java.lang.String OLD_EXPERT_UNIT_TAG
- See Also:
- Constant Field Values
-
OLD_MAXIMUM_COUNT_TAG
private static final java.lang.String OLD_MAXIMUM_COUNT_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Role
public Role(java.lang.String id, Specification specification)Creates a newRoleinstance.- Parameters:
id- The object identifier.specification- TheSpecificationto refer to.
-
-
Method Detail
-
isDefaultRoleId
public static boolean isDefaultRoleId(java.lang.String roleId)
Is this the default role?- Parameters:
roleId- The role identifier to test.- Returns:
- True if this is the default role.
-
isDefaultRole
public boolean isDefaultRole()
Is this the default role?- Returns:
- True if this is the default role.
-
getRoleSuffix
public java.lang.String getRoleSuffix()
Get the last part of a role identifier.- Returns:
- The role suffix.
-
getRoleIdSuffix
public static java.lang.String getRoleIdSuffix(java.lang.String roleId)
Get the last part of a role identifier.- Parameters:
roleId- A role identifier.- Returns:
- The role suffix.
-
getDowngrade
public final Role getDowngrade()
Get the downgraded role from this one.- Returns:
- The downgraded role.
-
setDowngrade
public final void setDowngrade(Role newDowngrade)
Sets the downgraded role.- Parameters:
newDowngrade- The new downgraded role.
-
getMaximumCount
public final int getMaximumCount()
Gets the maximum goods count for the role.- Returns:
- The maximum goods count.
-
setMaximumCount
public final void setMaximumCount(int newMaximumCount)
Sets the maximum goods count for this role.- Parameters:
newMaximumCount- The new maximum goods count.
-
getExpertUnit
public final UnitType getExpertUnit()
Gets the expert profession for this role.- Returns:
- The expert type.
-
setExpertUnit
public final void setExpertUnit(UnitType newExpertUnit)
Sets the expert profession for this role.- Parameters:
newExpertUnit- The new expert type.
-
getRequiredGoodsList
public java.util.List<AbstractGoods> getRequiredGoodsList(int roleCount)
Get the required goods for this role, considering also the role count.- Parameters:
roleCount- The role count.- Returns:
- A list of required goods.
-
getRequiredGoods
public java.util.stream.Stream<AbstractGoods> getRequiredGoods(int roleCount)
Get the required goods for this role, considering also the role count, as a stream.- Parameters:
roleCount- The role count.- Returns:
- A stream of required goods.
-
getRequiredGoodsPrice
public int getRequiredGoodsPrice(Market market)
Get the price of the required goods in a given market.- Parameters:
market- TheMarketto evaluate in.- Returns:
- The price of the goods for this role.
-
getRoleChanges
public final java.util.List<Role.RoleChange> getRoleChanges()
Get the role changes that can allow a unit to assume this role.- Returns:
- A list of
RoleChanges.
-
setRoleChanges
protected final void setRoleChanges(java.util.List<Role.RoleChange> roleChanges)
Set the role change list.- Parameters:
roleChanges- The new list ofRoleChanges.
-
addRoleChange
private void addRoleChange(java.lang.String from, java.lang.String capture)Add a new role change.- Parameters:
from- The source role identifier.capture- The identifier for the role to capture.
-
getOffence
public double getOffence()
Get the offense value for this role.- Returns:
- The offense value.
-
isOffensive
public boolean isOffensive()
Is this an offensive role?- Returns:
- True if this is an offensive role.
-
getDefence
private double getDefence()
Get the defence value for this role.- Returns:
- The defence value.
-
isDefensive
public boolean isDefensive()
Is this an defensive role?- Returns:
- True if this is an defensive role.
-
isCompatibleWith
public boolean isCompatibleWith(Role other)
Is this role compatible with another?- Parameters:
other- The otherRoleto compare with.- Returns:
- True if the other role is compatible.
-
rolesCompatible
public static boolean rolesCompatible(Role role1, Role role2)
Are two roles compatible.- Parameters:
role1- ARoleto compare.role2- The otherRoleto compare.- Returns:
- True if the roles are compatible.
-
getGoodsDifference
public static java.util.List<AbstractGoods> getGoodsDifference(Role from, int fromCount, Role to, int toCount)
Gets a list of goods required to change from the first role to the second. The first role may benullimplying the default role, the second must not. Note that excess goods that are left over after the change will appear on the list with negative amounts.- Parameters:
from- The currentRole.fromCount- The role count for the current role.to- The newRoleto assume.toCount- The role count for the new role.- Returns:
- A list of
AbstractGoodsrequired to make the change.
-
getRoleIndex
public int getRoleIndex()
Establish a simple ordering. Normal roles, then REF-specific roles, then native-specific roles. Reduce by role-specific equipment amounts to further separate the levels such that the heavier armed roles sort first.- Returns:
- A role index.
-
getAvailableRoles
public static java.util.List<Role> getAvailableRoles(Player player, UnitType type, java.util.List<Role> roles)
Filter a list of proposed roles by availability.- Parameters:
player- ThePlayerto own the unit.type- TheUnitTypeto check.roles- A list of proposedRoles.- Returns:
- A list of available
Roles.
-
toFullString
public java.lang.String toFullString()
Longer format debug helper.- Returns:
- A more detailed description of this role.
-
canBeBuiltInColony
public Colony.NoBuildReason canBeBuiltInColony(Colony colony, java.util.List<BuildableType> assumeBuilt)
Check to see if this buildable type can be built in a colony based on the buildings or units available.- Specified by:
canBeBuiltInColonyin classBuildableType- Parameters:
colony- TheColonyto check.assumeBuilt- A list ofBuildableTypes.- Returns:
- The reason the for failure, or NoBuildReason.NONE on success.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyInin classBuildableType- 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 classBuildableType- 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 classBuildableType- 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 classBuildableType- 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 classBuildableType- 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 classBuildableType- 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.
-
-