Package net.sf.freecol.server.ai.mission
Class TransportMission
- 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.TransportMission
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,ObjectWithId
public final class TransportMission extends Mission
Mission for transporting units and goods on a carrier.- See Also:
Unit
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
TransportMission.CargoResult
-
Field Summary
Fields Modifier and Type Field Description private java.util.List<Cargo>
cargoes
A list ofCargo
s to work on.private static int
DESTINATION_UPPER_BOUND
Insist transport lists remain simple by imposing an upper bound on the distinct destination locations to visit.private static java.util.logging.Logger
logger
private static int
MINIMUM_GOLD_TO_STAY_IN_EUROPE
private static java.lang.String
tag
static java.lang.String
TAG
private Location
target
The current target location to travel to.private static java.lang.String
TARGET_TAG
-
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 TransportMission(AIMain aiMain, AIUnit aiUnit)
Creates a mission for the givenAIUnit
.TransportMission(AIMain aiMain, AIUnit aiUnit, FreeColXMLReader xr)
Creates a newTransportMission
from a reader.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
addCargo(Cargo cargo, int index, LogBuilder lb)
Add the given Cargo to the cargoes list.private void
checkCargoes(LogBuilder lb)
Checks for invalid cargoes, and units and goods on board but not in the cargoes list.private java.lang.String
clearCargoes()
Clears all the cargoes.int
destinationCapacity()
How many more destinations are desirable on the current cargoes list? Must be public! This is checked in European AI player.private int
destinationCount()
Count distinct non-adjacent destinations in a list of cargoes.void
dispose()
Disposes of thisMission
.Mission
doMission(LogBuilder lb)
Performs the mission.private void
doTransport(LogBuilder lb)
Perform the transport load/unload operations on arrival at the target for the top cargo.private void
dropTransportable(TransportableAIObject t)
If this carrier is the current carrier of a transportable, drop it.private boolean
dumpCargo(Cargo cargo, LogBuilder lb)
Dump a currently carried cargo.boolean
dumpTransportable(TransportableAIObject t, LogBuilder lb)
Dump a transportable.Location
findTarget()
Finds a new target for this mission.boolean
forceCollection(AIUnit aiu, LogBuilder lb)
Drop all collections so that cargo is delivered only, then collect this unit.private Cargo
getBestCargo(Unit carrier)
What is the best transportable for a carrier to collect?Location
getTarget()
Gets the target of this mission, if any.Tile
getTransportDestination()
Gets the destination of a required transport.Location
getTransportTarget(TransportableAIObject t)
Get the collection location for an uncollected transportable.int
getTransportTurns(TransportableAIObject t)
Get the expected turns for an uncollected transport Public so that mobile transportables (units) can renege on transport if they find themselves better able to get there themselves.java.lang.String
getXMLTagName()
Get the serialization tag for this object.private static java.lang.String
invalidCargoReason(Cargo cargo)
Why would this mission be invalid with a given cargo? Checks the cargo locations.static java.lang.String
invalidMissionReason(AIUnit aiUnit)
Why would this mission be invalid with the given AI unit?static java.lang.String
invalidMissionReason(AIUnit aiUnit, Location loc)
Why would this mission be invalid with the given AI unit and location?java.lang.String
invalidReason()
Why is this mission invalid? Mission subclasses must implement this routine, which probably should start by checking invalidAIUnitReason.private static java.lang.String
invalidUnitReason(AIUnit aiUnit)
Why would an TransportMission be invalid with the given unit?private boolean
isCarrying(TransportableAIObject t)
Checks if the carrier using this mission is carrying the givenTransportableAIObject
.boolean
isEmpty()
Is there nothing currently queued for this carrier?boolean
isTransporting(TransportableAIObject t)
Is a transportable waiting for delivery on the cargoes list?Cargo
makeCargo(TransportableAIObject t, LogBuilder lb)
For a given transportable, work out where the carrier has to go to advance the cargo (target), and what to do there (mode), allowing a newCargo
to be defined.private void
optimizeCargoes(LogBuilder lb)
Sets the current target.private boolean
queueCargo(Cargo cargo, boolean requireMatch, LogBuilder lb)
Incrementally queue a cargo to the cargoes list.boolean
queueTransportable(TransportableAIObject t, boolean requireMatch, LogBuilder lb)
Wrapper for queueCargo.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.private void
removeCargo(Cargo cargo)
Removes the given Cargo from the cargoes list.boolean
removeTransportable(TransportableAIObject t)
Removes the givenTransportableAIObject
from the cargo list.private boolean
requeueCargo(Cargo cargo, LogBuilder lb)
Requeue an existing cargo.boolean
requeueTransportable(TransportableAIObject t, LogBuilder lb)
Retargets a transportable that should already be on board the carrier.private float
scoreCargoOrder(Location initialLocation, java.util.List<Cargo> order)
Calculates a score for a proposed list ofCargo
s using the current unit.void
setTarget(Location target)
Sets the target of this mission, if any.private boolean
shouldAttack(Unit other)
Decide if this unit has a good chance of defeating another.boolean
spaceAvailable(Cargo cargo)
Is there space available for a new cargo?boolean
spaceAvailable(TransportableAIObject t)
Is there space available for a new cargo?void
suppressEuropeanTrade(GoodsType type, LogBuilder lb)
Suppress European trade in a type of goods which is about to be boycotted.private boolean
tAdd(Cargo cargo, int index)
Adds a cargo to the cargoes list.private void
takeTransportable(TransportableAIObject t)
If this carrier is the not the current carrier of a transportable, make it so.private java.util.List<Cargo>
tClear()
Clears the cargoes list.private java.util.List<Cargo>
tCopy()
Gets the cargoes.private Cargo
tFind(TransportableAIObject t)
Find aCargo
with the givenTransportableAIObject
.private Cargo
tFirst()
Gets the first cargo.java.lang.String
toFullString()
More verbose version of toString().private boolean
tRemove(Cargo cargo)
Remove a cargo from the cargoes list.private void
tRetarget()
Reset the carrier target after a change to the first cargo.private TransportMission.CargoResult
tryCargo(Cargo cargo, LogBuilder lb)
Check aCargo
for continued validity and whether action is needed at the current location.private java.util.List<Cargo>
tSet(java.util.List<Cargo> nxt, boolean setSpace)
Sets the cargoes to a new list.private int
tSize()
Gets the size of the cargoes.private void
tSpace()
Sets the spaceLeft fields in the cargoes.private java.util.List<Cargo>
unwrapCargoes(java.util.List<Cargo> ts)
Unwrap a wrapped list of cargoes.private java.util.List<Cargo>
wrapCargoes()
Wrap up the compatible cargoes in a list.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.server.ai.mission.Mission
findCircleTarget, getAIPlayer, getAIRandom, getAIUnit, getBaseTransportPriority, getBestSettlement, getEuropeanAIPlayer, getPlayer, getUnit, invalidAIUnitReason, invalidAttackReason, invalidNewMissionReason, invalidTargetReason, invalidTargetReason, invalidTransportableReason, isOneTime, isTargetReason, isValid, lbAt, lbAttack, lbDodge, lbDone, lbDrop, lbFail, 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, readFromXML, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setId, toXML, toXMLPartial, toXMLPartial
-
-
-
-
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
- See Also:
- Constant Field Values
-
DESTINATION_UPPER_BOUND
private static final int DESTINATION_UPPER_BOUND
Insist transport lists remain simple by imposing an upper bound on the distinct destination locations to visit.- See Also:
- Constant Field Values
-
MINIMUM_GOLD_TO_STAY_IN_EUROPE
private static final int MINIMUM_GOLD_TO_STAY_IN_EUROPE
- See Also:
- Constant Field Values
-
cargoes
private final java.util.List<Cargo> cargoes
A list ofCargo
s to work on.
-
target
private Location target
The current target location to travel to.
-
TARGET_TAG
private static final java.lang.String TARGET_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TransportMission
public TransportMission(AIMain aiMain, AIUnit aiUnit)
Creates a mission for the givenAIUnit
.- Parameters:
aiMain
- The main AI-object.aiUnit
- TheAIUnit
this mission is created for.
-
TransportMission
public TransportMission(AIMain aiMain, AIUnit aiUnit, FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Creates a newTransportMission
from a reader.- Parameters:
aiMain
- The main AI-object.aiUnit
- TheAIUnit
this 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
-
isCarrying
private boolean isCarrying(TransportableAIObject t)
Checks if the carrier using this mission is carrying the givenTransportableAIObject
.- Parameters:
t
- TheTransportableAIObject
to check.- Returns:
- True if the carrier is carrying the transportable.
-
isTransporting
public boolean isTransporting(TransportableAIObject t)
Is a transportable waiting for delivery on the cargoes list?- Parameters:
t
- TheTransportableAIObject
to check.- Returns:
- True if the transportable is queued in this mission.
-
shouldAttack
private boolean shouldAttack(Unit other)
Decide if this unit has a good chance of defeating another. If there is cargo aboard, be more conservative. FIXME: magic numbers to the spec.- Parameters:
other
- The otherUnit
to attack.- Returns:
- True if the attack should proceed.
-
tCopy
private java.util.List<Cargo> tCopy()
Gets the cargoes.- Returns:
- A copy of the list of cargoes.
-
tClear
private java.util.List<Cargo> tClear()
Clears the cargoes list.- Returns:
- The old cargoes list.
-
tSet
private java.util.List<Cargo> tSet(java.util.List<Cargo> nxt, boolean setSpace)
Sets the cargoes to a new list.- Parameters:
nxt
- The new cargoes list.setSpace
- If true, call tSpace to reset the space left values.- Returns:
- The old cargoes list.
-
tSize
private int tSize()
Gets the size of the cargoes.- Returns:
- The size of the cargoes.
-
tFind
private Cargo tFind(TransportableAIObject t)
Find aCargo
with the givenTransportableAIObject
.- Parameters:
t
- TheTransportableAIObject
to look for.- Returns:
- The
Cargo
found, or null if none found.
-
tFirst
private Cargo tFirst()
Gets the first cargo.- Returns:
- The first valid cargo, or null if none found.
-
tAdd
private boolean tAdd(Cargo cargo, int index)
Adds a cargo to the cargoes list.- Parameters:
cargo
- TheCargo
to add.index
- The position to add it.- Returns:
- True if the addition succeeded or the cargo was already present.
-
tRemove
private boolean tRemove(Cargo cargo)
Remove a cargo from the cargoes list.- Parameters:
cargo
- TheCargo
to remove.- Returns:
- True if the remove succeeded.
-
tSpace
private void tSpace()
Sets the spaceLeft fields in the cargoes. To be called with synchronized (cargoes).
-
tRetarget
private void tRetarget()
Reset the carrier target after a change to the first cargo.
-
destinationCount
private int destinationCount()
Count distinct non-adjacent destinations in a list of cargoes.- Returns:
- The number of distinct destinations.
-
destinationCapacity
public int destinationCapacity()
How many more destinations are desirable on the current cargoes list? Must be public! This is checked in European AI player.- Returns:
- The number of desired extra destinations.
-
dropTransportable
private void dropTransportable(TransportableAIObject t)
If this carrier is the current carrier of a transportable, drop it.- Parameters:
t
- TheTransportableAIObject
to check.
-
takeTransportable
private void takeTransportable(TransportableAIObject t)
If this carrier is the not the current carrier of a transportable, make it so.- Parameters:
t
- TheTransportableAIObject
to check.
-
getTransportTarget
public Location getTransportTarget(TransportableAIObject t)
Get the collection location for an uncollected transportable. Public so that mobile transportables (units) can move to the collection point.- Parameters:
t
- TheTransportableAIObject
to collect.- Returns:
- The collection
Location
, or null if not found.
-
getTransportTurns
public int getTransportTurns(TransportableAIObject t)
Get the expected turns for an uncollected transport Public so that mobile transportables (units) can renege on transport if they find themselves better able to get there themselves.- Parameters:
t
- TheTransportableAIObject
to collect.- Returns:
- The expected transport turns.
-
wrapCargoes
private java.util.List<Cargo> wrapCargoes()
Wrap up the compatible cargoes in a list. O(N^2) alas.- Returns:
- A wrapped list of cargoes.
-
unwrapCargoes
private java.util.List<Cargo> unwrapCargoes(java.util.List<Cargo> ts)
Unwrap a wrapped list of cargoes.- Parameters:
ts
- The list ofCargo
s to unwrap.- Returns:
- The unwrapped list of cargoes.
-
clearCargoes
private java.lang.String clearCargoes()
Clears all the cargoes.- Returns:
- A message about the cargoes being cleared.
-
isEmpty
public boolean isEmpty()
Is there nothing currently queued for this carrier?- Returns:
- True if there is no work allocated to this carrier.
-
makeCargo
public Cargo makeCargo(TransportableAIObject t, LogBuilder lb)
For a given transportable, work out where the carrier has to go to advance the cargo (target), and what to do there (mode), allowing a newCargo
to be defined. AIUnit cargo is harder than AIGoods, because AIUnits might have their own inland paths, and thus we need to consider drop nodes.- Parameters:
t
- TheTransportableAIObject
to consider.lb
- ALogBuilder
to log to.- Returns:
- A new
Cargo
defining the action to take with theTransportableAIObject
, or null if impossible.
-
addCargo
private boolean addCargo(Cargo cargo, int index, LogBuilder lb)
Add the given Cargo to the cargoes list.- Parameters:
cargo
- TheCargo
to add.index
- The index of where to add the cargo.lb
- ALogBuilder
to log to.- Returns:
- True if the cargo was added.
-
removeCargo
private void removeCargo(Cargo cargo)
Removes the given Cargo from the cargoes list.- Parameters:
cargo
- TheCargo
to remove.
-
spaceAvailable
public boolean spaceAvailable(Cargo cargo)
Is there space available for a new cargo?- Parameters:
cargo
- TheCargo
to check.- Returns:
- True if there is space available for this cargo.
-
spaceAvailable
public boolean spaceAvailable(TransportableAIObject t)
Is there space available for a new cargo?- Parameters:
t
- TheTransportableAIObject
to check.- Returns:
- True if there is space available for this transportable.
-
queueCargo
private boolean queueCargo(Cargo cargo, boolean requireMatch, LogBuilder lb)
Incrementally queue a cargo to the cargoes list. If the carrier is at the collection point favour immediate collection. Otherwise try to place it with other cargoes with the same target, but do not break the space restrictions. If this does not work, it has to go at the end.- Parameters:
cargo
- The newCargo
to add.requireMatch
- Fail if an existing destination is not matched.lb
- ALogBuilder
to log to.- Returns:
- True if the cargo was queued.
-
dumpCargo
private boolean dumpCargo(Cargo cargo, LogBuilder lb)
Dump a currently carried cargo.- Parameters:
cargo
- TheCargo
to dump.lb
- ALogBuilder
to log to.- Returns:
- True if the cargo is no longer on board and not on the transport list, or is on board but is scheduled to be dumped.
-
requeueCargo
private boolean requeueCargo(Cargo cargo, LogBuilder lb)
Requeue an existing cargo. Typically done when the target changes.- Parameters:
cargo
- TheCargo
to requeue.lb
- ALogBuilder
to log to.- Returns:
- True if the queuing succeeded.
-
checkCargoes
private void checkCargoes(LogBuilder lb)
Checks for invalid cargoes, and units and goods on board but not in the cargoes list. On exit from this routine, every cargo on board should be on the cargoes list but the list is not necessarily going to be in a sensible order.- Parameters:
lb
- ALogBuilder
to log to.
-
tryCargo
private TransportMission.CargoResult tryCargo(Cargo cargo, LogBuilder lb)
Check aCargo
for continued validity and whether action is needed at the current location.- Parameters:
cargo
- TheCargo
to check.lb
- ALogBuilder
to log to.- Returns:
- TCONTINUE if the
Cargo
should continue, TDONE if it has completed, TFAIL if it has failed, TNEXT if it has progressed to the next stage, TRETRY if a blockage has occurred and it should be retried,
-
doTransport
private void doTransport(LogBuilder lb)
Perform the transport load/unload operations on arrival at the target for the top cargo.- Parameters:
lb
- ALogBuilder
to log to.
-
scoreCargoOrder
private float scoreCargoOrder(Location initialLocation, java.util.List<Cargo> order)
Calculates a score for a proposed list ofCargo
s using the current unit. Disallows routes that would overfill the carrier. Useful for comparing proposed cargo delivery routes. The score is based primarily on the number of turns it takes, but to break ties we also consider the hold*turn product to reduce the risk of losses due to enemy action.- Parameters:
initialLocation
- The initialLocation
.order
- An ordering ofCargo
s.- Returns:
- A score for the cargo ordering.
-
optimizeCargoes
private void optimizeCargoes(LogBuilder lb)
Sets the current target. Tries all permutations of cargoes and picks the fastest/safest one. Leaves the cargoes in the order they are expected to execute, with valid spaceLeft values.- Parameters:
lb
- ALogBuilder
to log to.
-
getBestCargo
private Cargo getBestCargo(Unit carrier)
What is the best transportable for a carrier to collect?- Parameters:
carrier
- The carrierUnit
to consider.- Returns:
- The best available new
Cargo
, or null if none found.
-
invalidUnitReason
private static java.lang.String invalidUnitReason(AIUnit aiUnit)
Why would an TransportMission be invalid with the given unit?- Parameters:
aiUnit
- TheAIUnit
to test.- Returns:
- A reason why the mission would be invalid with the unit, or null if none found.
-
invalidCargoReason
private static java.lang.String invalidCargoReason(Cargo cargo)
Why would this mission be invalid with a given cargo? Checks the cargo locations. A location becomes invalid if: - step is a null location - step is disposed - step is a captured settlement- Parameters:
cargo
- TheCargo
to test.- 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
- TheAIUnit
to 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
- TheAIUnit
to check.loc
- TheLocation
to check.- Returns:
- A reason for invalidity, or null if none found.
-
removeTransportable
public boolean removeTransportable(TransportableAIObject t)
Removes the givenTransportableAIObject
from the cargo list.- Parameters:
t
- TheTransportableAIObject
to remove.- Returns:
- True if the removal succeeded.
-
requeueTransportable
public boolean requeueTransportable(TransportableAIObject t, LogBuilder lb)
Retargets a transportable that should already be on board the carrier.- Parameters:
t
- TheTransportableAIObject
to retarget.lb
- ALogBuilder
to log to.- Returns:
- True if the retargeting succeeded.
-
queueTransportable
public boolean queueTransportable(TransportableAIObject t, boolean requireMatch, LogBuilder lb)
Wrapper for queueCargo. Public for the benefit of EuropeanAIPlayer.allocateTransportables and CashInTreasureTrain.doMission.- Parameters:
t
- TheTransportableAIObject
to add.requireMatch
- Fail if an existing destination is not matched.lb
- ALogBuilder
to log to.- Returns:
- True if the transportable was queued.
-
dumpTransportable
public boolean dumpTransportable(TransportableAIObject t, LogBuilder lb)
Dump a transportable.- Parameters:
t
- TheTransportableAIObject
to dump.lb
- ALogBuilder
to log to.- Returns:
- True if the transportable is no longer on board, queued, or was reset to be dumped at the next stop.
-
forceCollection
public boolean forceCollection(AIUnit aiu, LogBuilder lb)
Drop all collections so that cargo is delivered only, then collect this unit. Useful for prioritizing treasure collection.- Parameters:
aiu
- TheAIUnit
to collect.lb
- ALogBuilder
to log to.- Returns:
- True if the unit was queued.
-
suppressEuropeanTrade
public void suppressEuropeanTrade(GoodsType type, LogBuilder lb)
Suppress European trade in a type of goods which is about to be boycotted.- Parameters:
type
- TheGoodsType
to suppress.lb
- ALogBuilder
to log to.
-
getTransportDestination
public Tile getTransportDestination()
Gets the destination of a required transport. Override this in the child mission classes if there is a useful intermediate point to deliver the unit distinct from the target.- Overrides:
getTransportDestination
in classMission
- Returns:
- The mission target, or null if the mission is invalid, otherwise lacks a target (e.g. UnitWanderHostile), or the unit does not need transport.
-
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:
findTarget
in 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:
invalidReason
in classMission
- Returns:
- A reason for mission invalidity, or null if none found.
-
doMission
public Mission doMission(LogBuilder lb)
Performs the mission.
-
toFullString
public java.lang.String toFullString()
More verbose version of toString().- Returns:
- A summary of this mission including its transportables.
-
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 classMission
- 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 classFreeColObject
- 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 classMission
- 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 classFreeColObject
- 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 classFreeColObject
- 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.
-
-