Package net.sf.freecol.server.ai.mission
Class PioneeringMission
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.server.ai.AIObject
-
- net.sf.freecol.server.ai.mission.Mission
-
- net.sf.freecol.server.ai.mission.PioneeringMission
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>,ObjectWithId
public final class PioneeringMission extends Mission
Mission for controlling a pioneer.
-
-
Field Summary
Fields Modifier and Type Field Description private static intDEFAULT_THREAT_TURNSDefault distance in turns to a threatening unit.private static java.util.logging.Loggerloggerprivate static java.lang.StringtagThe tag for this mission.static java.lang.StringTAGprivate LocationtargetThe target location to go to: - a tile where the tileImprovement is - a colony to go to to equip - just an initial colony to retarget fromprivate static java.lang.StringTARGET_TAGprivate TileImprovementPlantileImprovementPlanThe improvement this pioneer is to work on.-
Fields inherited from class net.sf.freecol.server.ai.mission.Mission
AIUNITDIED, AIUNITNULL, MINIMUM_TRANSPORT_PRIORITY, NO_MORE_MOVES_LEFT, NO_PATH_TO_TARGET, NORMAL_TRANSPORT_PRIORITY, TARGETINVALID, TARGETNOTFOUND, TARGETNULL, TARGETOWNERSHIP, UNITNOTAPERSON, UNITNOTOFFENSIVE, UNITNOTONMAP
-
Fields inherited from class net.sf.freecol.server.ai.AIObject
initialized
-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Constructor Summary
Constructors Constructor Description PioneeringMission(AIMain aiMain, AIUnit aiUnit, FreeColXMLReader xr)Creates a newPioneeringMissionfrom a reader.PioneeringMission(AIMain aiMain, AIUnit aiUnit, Location target)Creates a pioneering mission for the givenAIUnit.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidabandonTileImprovementPlan()Abandons the current plan if any.voiddispose()Disposes of this pioneering mission.MissiondoMission(LogBuilder lb)Performs the mission.private static LocationextractTarget(AIUnit aiUnit, PathNode path)Extract a valid target for this mission from a path.static LocationfindMissionTarget(AIUnit aiUnit, int range, boolean deferOK)Finds a suitable pioneering target for the supplied unit.LocationfindTarget()Finds a new target for this mission.private static PathNodefindTargetPath(AIUnit aiUnit, int range, boolean deferOK)Finds a suitable pioneering target for the supplied unit.intgetBaseTransportPriority()Get the base transport priority for the unit performing this mission.private static TileImprovementPlangetBestMissionPlan(AIUnit aiUnit, Tile tile)Get the best improvement associated with a tile for a given unit.private static ColonygetBestPioneeringColony(AIUnit aiUnit)Gets the Colony that most needs a pioneer.private TileImprovementPlangetBestPlan(Tile tile)Get the best improvement associated with a tile.private static GoalDecidergetGoalDecider(AIUnit aiUnit, boolean deferOK)Makes a goal decider that checks pioneering sites.private static TileImprovementPlangetPlan(AIUnit aiUnit, Tile tile)Gets the existing tile improvement plan for a unit and tile.LocationgetTarget()Gets the target of this mission, if any.TileImprovementPlangetTileImprovementPlan()Gets theTileImprovementPlanfor this mission.java.lang.StringgetXMLTagName()Get the serialization tag for this object.private static booleanhasMissionTools(AIUnit aiUnit)Does a supplied unit have tools?private booleanhasTools()Does this pioneer have tools?private static java.lang.StringinvalidColonyReason(AIUnit aiUnit, Colony colony)Why would a PioneeringMission be invalid with the given unit and colony.static java.lang.StringinvalidMissionReason(AIUnit aiUnit)Why would this mission be invalid with the given AI unit?static java.lang.StringinvalidMissionReason(AIUnit aiUnit, Location loc)Why would this mission be invalid with the given AI unit and location?java.lang.StringinvalidReason()Why is this mission invalid? Mission subclasses must implement this routine, which probably should start by checking invalidAIUnitReason.private static java.lang.StringinvalidTileReason(AIUnit aiUnit, Tile tile)Why would a PioneeringMission be invalid with the given unit and tile.private static java.lang.StringinvalidUnitReason(AIUnit aiUnit)Why would a PioneeringMission be invalid with the given unit.protected MissionlbFail(LogBuilder lb, boolean cont, java.lang.Object... reasons)The current mission has failed.static java.lang.Stringprepare(AIUnit aiUnit)Prepare a unit for this mission.protected voidreadAttributes(FreeColXMLReader xr)Reads the attributes of this object from an XML stream.static intscorePath(AIUnit aiUnit, PathNode path)Evaluate a potential pioneering mission for a given unit and path.voidsetTarget(Location target)Sets the target of this mission, if any.voidsetTileImprovementPlan(TileImprovementPlan tip)Sets theTileImprovementPlanwhich should be the next target.protected voidwriteAttributes(FreeColXMLWriter xw)Write the attributes of this object to a stream.-
Methods inherited from class net.sf.freecol.server.ai.mission.Mission
findCircleTarget, getAIPlayer, getAIRandom, getAIUnit, getBestSettlement, getEuropeanAIPlayer, getPlayer, getTransportDestination, getUnit, invalidAIUnitReason, invalidAttackReason, invalidNewMissionReason, invalidTargetReason, invalidTargetReason, invalidTransportableReason, isOneTime, isTargetReason, isValid, lbAt, lbAttack, lbDodge, lbDone, lbDrop, lbMove, lbRetarget, lbWait, moveRandomly, moveRandomlyTurn, resolveBlockage, retargetMission, setInitialized, toString, toXML, travelToTarget
-
Methods inherited from class net.sf.freecol.server.ai.AIObject
addAIObjectWithId, checkIntegrity, checkIntegrity, copyIn, getAIMain, getGame, getSpecification, isDisposed, setGame, 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, 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, readChild, readChildren, readFromXML, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setId, toXML, toXMLPartial, toXMLPartial, writeChildren
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
tag
private static final java.lang.String tag
The tag for this mission.- See Also:
- Constant Field Values
-
DEFAULT_THREAT_TURNS
private static final int DEFAULT_THREAT_TURNS
Default distance in turns to a threatening unit.- See Also:
- Constant Field Values
-
tileImprovementPlan
private TileImprovementPlan tileImprovementPlan
The improvement this pioneer is to work on.
-
target
private Location target
The target location to go to: - a tile where the tileImprovement is - a colony to go to to equip - just an initial colony to retarget from
-
TARGET_TAG
private static final java.lang.String TARGET_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
PioneeringMission
public PioneeringMission(AIMain aiMain, AIUnit aiUnit, Location target)
Creates a pioneering mission for the givenAIUnit. Note that PioneeringMission.isValid(aiUnit) should be called before this, to guarantee that findTileImprovementPlan/findColonyWithTools succeed.- Parameters:
aiMain- The main AI-object.aiUnit- TheAIUnitthis mission is created for.target- The targetLocation.
-
PioneeringMission
public PioneeringMission(AIMain aiMain, AIUnit aiUnit, FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Creates a newPioneeringMissionfrom a reader.- Parameters:
aiMain- The main AI-object.aiUnit- TheAIUnitthis mission is created for.xr- The input stream containing the XML.- Throws:
javax.xml.stream.XMLStreamException- if a problem was encountered during parsing.- See Also:
FreeColObject.readFromXML(net.sf.freecol.common.io.FreeColXMLReader)
-
-
Method Detail
-
getBestPlan
private TileImprovementPlan getBestPlan(Tile tile)
Get the best improvement associated with a tile.- Parameters:
tile- TheTileto get a plan for.- Returns:
- The
TileImprovementPlan, or null if not found.
-
getBestMissionPlan
private static TileImprovementPlan getBestMissionPlan(AIUnit aiUnit, Tile tile)
Get the best improvement associated with a tile for a given unit. Take care to first check if the unit has a plan already, if so, return that.- Parameters:
aiUnit- TheAIUnitto get a plan for.tile- TheTileto get a plan for.- Returns:
- The
TileImprovementPlan, or null if not found.
-
getTileImprovementPlan
public TileImprovementPlan getTileImprovementPlan()
Gets theTileImprovementPlanfor this mission.- Returns:
- The
TileImprovementPlan.
-
setTileImprovementPlan
public void setTileImprovementPlan(TileImprovementPlan tip)
Sets theTileImprovementPlanwhich should be the next target.- Parameters:
tip- TheTileImprovementPlan.
-
abandonTileImprovementPlan
private void abandonTileImprovementPlan()
Abandons the current plan if any.
-
dispose
public void dispose()
Disposes of this pioneering mission.
-
hasMissionTools
private static boolean hasMissionTools(AIUnit aiUnit)
Does a supplied unit have tools?- Parameters:
aiUnit- The pioneerAIUnitto check.- Returns:
- True if the pioneer has tools.
-
hasTools
private boolean hasTools()
Does this pioneer have tools?- Returns:
- True if the pioneer has tools.
-
extractTarget
private static Location extractTarget(AIUnit aiUnit, PathNode path)
Extract a valid target for this mission from a path.- Parameters:
aiUnit- AAIUnitto perform the mission.path- APathNodeto extract a target from.- Returns:
- A target for this mission, or null if none found.
-
scorePath
public static int scorePath(AIUnit aiUnit, PathNode path)
Evaluate a potential pioneering mission for a given unit and path.- Parameters:
aiUnit- TheAIUnitto do the mission.path- APathNodeto take to the target.- Returns:
- A score for the proposed mission.
-
getGoalDecider
private static GoalDecider getGoalDecider(AIUnit aiUnit, boolean deferOK)
Makes a goal decider that checks pioneering sites.- Parameters:
aiUnit- TheAIUnitto search with.deferOK- Keep track of the nearest colonies to use as a fallback destination.- Returns:
- A suitable
GoalDecider.
-
findTargetPath
private static PathNode findTargetPath(AIUnit aiUnit, int range, boolean deferOK)
Finds a suitable pioneering target for the supplied unit.- Parameters:
aiUnit- TheAIUnitto execute this mission.range- An upper bound on the number of moves.deferOK- Enables deferring to a fallback colony.- Returns:
- A path to the new target, or null if none found.
-
getBestPioneeringColony
private static Colony getBestPioneeringColony(AIUnit aiUnit)
Gets the Colony that most needs a pioneer.- Parameters:
aiUnit- The pioneerAIUnit.- Returns:
- The colony with the most outstanding tile improvement plans.
-
findMissionTarget
public static Location findMissionTarget(AIUnit aiUnit, int range, boolean deferOK)
Finds a suitable pioneering target for the supplied unit. Falls back to the best settlement if the unit is not on the map.- Parameters:
aiUnit- TheAIUnitto test.range- An upper bound on the number of moves.deferOK- Enables deferring to a fallback colony.- Returns:
- A target for this mission.
-
prepare
public static java.lang.String prepare(AIUnit aiUnit)
Prepare a unit for this mission.- Parameters:
aiUnit- TheAIUnitto prepare.- Returns:
- A reason why the unit can not perform this mission, or null if none.
-
invalidUnitReason
private static java.lang.String invalidUnitReason(AIUnit aiUnit)
Why would a PioneeringMission be invalid with the given unit.- Parameters:
aiUnit- TheAIUnitto check.- Returns:
- A reason why the mission would be invalid with the unit, or null if none found.
-
invalidColonyReason
private static java.lang.String invalidColonyReason(AIUnit aiUnit, Colony colony)
Why would a PioneeringMission be invalid with the given unit and colony.- Parameters:
aiUnit- TheAIUnitto check.colony- TheColonyto check.- Returns:
- A reason why the mission would be invalid, or null if none found.
-
getPlan
private static TileImprovementPlan getPlan(AIUnit aiUnit, Tile tile)
Gets the existing tile improvement plan for a unit and tile.- Parameters:
aiUnit- TheAIUnitto check.tile- TheTileto check.- Returns:
- The associated
TileImprovementPlan.
-
invalidTileReason
private static java.lang.String invalidTileReason(AIUnit aiUnit, Tile tile)
Why would a PioneeringMission be invalid with the given unit and tile.- Parameters:
aiUnit- TheAIUnitto check.tile- TheTileto check.- Returns:
- A reason why the mission would be invalid, or null if none found.
-
invalidMissionReason
public static java.lang.String invalidMissionReason(AIUnit aiUnit)
Why would this mission be invalid with the given AI unit?- Parameters:
aiUnit- TheAIUnitto check.- Returns:
- A reason for mission invalidity, or null if none found.
-
invalidMissionReason
public static java.lang.String invalidMissionReason(AIUnit aiUnit, Location loc)
Why would this mission be invalid with the given AI unit and location?- Parameters:
aiUnit- TheAIUnitto check.loc- TheLocationto check.- Returns:
- A reason for invalidity, or null if none found.
-
getBaseTransportPriority
public int getBaseTransportPriority()
Get the base transport priority for the unit performing this mission.- Overrides:
getBaseTransportPriorityin classMission- Returns:
- A base transport priority.
-
getTarget
public Location getTarget()
Gets the target of this mission, if any.
-
setTarget
public void setTarget(Location target)
Sets the target of this mission, if any. The actual target is handled in the missions that really have them, this is a helper to make sure the unit is updated.
-
findTarget
public Location findTarget()
Finds a new target for this mission.- Specified by:
findTargetin classMission- Returns:
- A new target for this mission.
-
invalidReason
public java.lang.String invalidReason()
Why is this mission invalid? Mission subclasses must implement this routine, which probably should start by checking invalidAIUnitReason. A mission can be invalid for a number of subclass-specific reasons. For example: a seek-and-destroy mission could be invalid because of a improved stance towards the targeted player.- Specified by:
invalidReasonin classMission- Returns:
- A reason for mission invalidity, or null if none found.
-
lbFail
protected Mission lbFail(LogBuilder lb, boolean cont, java.lang.Object... reasons)
The current mission has failed.
-
doMission
public Mission doMission(LogBuilder lb)
Performs the mission.
-
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 classMission- 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 classMission- 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.
-
-