Package net.sf.freecol.server.ai.mission
Class IndianDemandMission
- 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.IndianDemandMission
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,ObjectWithId
public final class IndianDemandMission extends Mission
Mission for demanding goods from a specified player.
-
-
Field Summary
Fields Modifier and Type Field Description private Colony
colony
The colony to demand from.private static java.lang.String
COLONY_TAG
private boolean
demanded
Whether the demand has been made or not.private static java.lang.String
DEMANDED_TAG
private static int
GOODS_DEMAND_MIN
The minimum amount of goods to demand.private static java.util.logging.Logger
logger
private static java.util.List<java.util.function.Predicate<GoodsType>>
selectPredicates
Predicates for demand goods selection.private boolean
succeeded
Whether the demand succeeded.private static java.lang.String
SUCCEEDED_TAG
private static java.lang.String
tag
The tag for this mission.static java.lang.String
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 IndianDemandMission(AIMain aiMain, AIUnit aiUnit, FreeColXMLReader xr)
Creates a newIndianDemandMission
from a reader.IndianDemandMission(AIMain aiMain, AIUnit aiUnit, Colony target)
Creates a mission for the givenAIUnit
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private int
capAmount(int amount, int difficulty)
Mission
doMission(LogBuilder lb)
Performs the mission.Location
findTarget()
Finds a new target for this mission.private static IndianSettlement
getHome(AIUnit aiUnit)
Location
getTarget()
Gets the target of this mission, if any.Location
getTransportDestination()
Gets the destination of a required transport.java.lang.String
getXMLTagName()
Get the serialization tag for this object.private static boolean
hasMissionTribute(AIUnit aiUnit)
Checks if a unit is carrying a tribute.private boolean
hasTribute()
Checks if the unit is carrying a tribute (goods).private static java.lang.String
invalidColonyReason(AIUnit aiUnit, Colony colony)
Why would an IndianDemandMission be invalid with the given unit and colony.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 this mission be invalid with the given unit?protected void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.private Goods
selectGoods(Colony target)
Selects the most desirable goods from the colony.void
setSucceeded(boolean result)
Set the result of the demand.void
setTarget(Location target)
Sets the target of this mission, if any.protected void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.-
Methods inherited from class net.sf.freecol.server.ai.mission.Mission
dispose, 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, 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
-
GOODS_DEMAND_MIN
private static final int GOODS_DEMAND_MIN
The minimum amount of goods to demand.- See Also:
- Constant Field Values
-
tag
private static final java.lang.String tag
The tag for this mission.- See Also:
- Constant Field Values
-
selectPredicates
private static final java.util.List<java.util.function.Predicate<GoodsType>> selectPredicates
Predicates for demand goods selection.
-
colony
private Colony colony
The colony to demand from.
-
demanded
private boolean demanded
Whether the demand has been made or not.
-
succeeded
private boolean succeeded
Whether the demand succeeded.
-
COLONY_TAG
private static final java.lang.String COLONY_TAG
- See Also:
- Constant Field Values
-
DEMANDED_TAG
private static final java.lang.String DEMANDED_TAG
- See Also:
- Constant Field Values
-
SUCCEEDED_TAG
private static final java.lang.String SUCCEEDED_TAG
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
IndianDemandMission
public IndianDemandMission(AIMain aiMain, AIUnit aiUnit, Colony target)
Creates a mission for the givenAIUnit
.- Parameters:
aiMain
- The main AI-object.aiUnit
- TheAIUnit
this mission is created for.target
- TheColony
receiving the gift.
-
IndianDemandMission
public IndianDemandMission(AIMain aiMain, AIUnit aiUnit, FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Creates a newIndianDemandMission
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
-
hasTribute
private boolean hasTribute()
Checks if the unit is carrying a tribute (goods).- Returns:
- True if the unit is carrying goods.
-
hasMissionTribute
private static boolean hasMissionTribute(AIUnit aiUnit)
Checks if a unit is carrying a tribute.- Parameters:
aiUnit
- TheAIUnit
to check.- Returns:
- True if the unit is carrying goods.
-
setSucceeded
public void setSucceeded(boolean result)
Set the result of the demand.- Parameters:
result
- The result of making the demand.
-
selectGoods
private Goods selectGoods(Colony target)
Selects the most desirable goods from the colony.- Parameters:
target
- The targetColony
.- Returns:
- The goods to demand.
-
capAmount
private int capAmount(int amount, int difficulty)
-
getHome
private static IndianSettlement getHome(AIUnit aiUnit)
-
invalidUnitReason
private static java.lang.String invalidUnitReason(AIUnit aiUnit)
Why would this mission 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.
-
invalidColonyReason
private static java.lang.String invalidColonyReason(AIUnit aiUnit, Colony colony)
Why would an IndianDemandMission be invalid with the given unit and colony.- Parameters:
aiUnit
- TheAIUnit
to test.colony
- TheColony
to test.- Returns:
- A reason why the mission would be invalid with the unit and colony 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 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.
-
getTransportDestination
public Location 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.
-
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.
-
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.
-
getXMLTagName
public java.lang.String getXMLTagName()
Get the serialization tag for this object.- Specified by:
getXMLTagName
in classFreeColObject
- Returns:
- The tag.
-
-