Package net.sf.freecol.server.ai
Class MissionAIPlayer
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.server.ai.AIObject
-
- net.sf.freecol.server.ai.AIPlayer
-
- net.sf.freecol.server.ai.MissionAIPlayer
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,ObjectWithId
- Direct Known Subclasses:
EuropeanAIPlayer
,NativeAIPlayer
public abstract class MissionAIPlayer extends AIPlayer
An AIPlayer with support for executingMission
s. The methodAIPlayer.startWorking()
gets called by theAIInGameInputHandler
when it is this player's turn.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Comparator<AIUnit>
aiUnitLocationComparator
A comparator to sort AI units by location.private java.util.List<AIUnit>
aiUnits
Temporary variable, used to hold all AIUnit objects belonging to this AI.private static java.util.logging.Logger
logger
-
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 MissionAIPlayer(AIMain aiMain, FreeColXMLReader xr)
Creates a newAIPlayer
from the given XML-representation.MissionAIPlayer(AIMain aiMain, Player player)
Creates a new AI player.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addAIUnit(AIUnit aiUnit)
Add an AI unit owned by this player.abstract int
adjustMission(AIUnit aiUnit, PathNode path, java.lang.Class type, int value)
Adjusts the score of this proposed mission for this player type.protected void
clearAIUnits()
Clears the cache of AI units.protected java.util.List<AIUnit>
doMissions(java.util.List<AIUnit> aiUnits, LogBuilder lb)
Makes every unit perform their mission.protected java.util.List<AIUnit>
getAIUnits()
Gets a list of AIUnits for the player.Mission
getDefendCurrentSettlementMission(AIUnit aiUnit)
Get a DefendSettlementMission for the current settlement of a unit if it is badly defended.Mission
getDefendSettlementMission(AIUnit aiUnit, Settlement target)
Gets a new DefendSettlementMission for a unit.Mission
getIdleAtSettlementMission(AIUnit aiUnit)
Gets a new IdleAtSettlementMission for a unit.Mission
getSeekAndDestroyMission(AIUnit aiUnit, int range)
Gets a UnitSeekAndDestroyMission for a unit.Mission
getSeekAndDestroyMission(AIUnit aiUnit, Location loc)
Gets a UnitSeekAndDestroyMission for a unit.int
getSettlementDefenders(Settlement settlement)
Counts the number of defenders allocated to a settlement.Mission
getWanderHostileMission(AIUnit aiUnit)
Gets a new UnitWanderHostileMission for a unit.boolean
isTargetValidForSeekAndDestroy(Unit attacker, Tile tile)
Find out if a tile contains a suitable target for seek-and-destroy.protected void
logMissions(java.util.Map<Unit,java.lang.String> reasons, LogBuilder lb)
Log the missions of this player.void
removeAIObject(AIObject ao)
Remove one of our owned objects.private void
removeAIUnit(AIUnit aiu)
Remove an AI unit.-
Methods inherited from class net.sf.freecol.server.ai.AIPlayer
acceptDiplomaticTrade, acceptMercenaries, acceptTax, askServer, checkIntegrity, chooseFoundingFatherHandler, completeWish, determineStance, diplomacyHandler, firstContactHandler, fountainOfYouthHandler, getAIAdvantage, getAIColonies, getAIColony, getAIRandom, getAIUnit, getConnection, getNeededWagons, getPlayer, getXMLTagName, handleTrade, indianDemand, indianDemandHandler, invoke, lootCargoHandler, monarchActionHandler, nationSummaryHandler, nativeTradeHandler, newLandNameHandler, newRegionNameHandler, pioneersNeeded, readAttributes, reconnectHandler, scoutsNeeded, selectFoundingFather, setAIHandler, setCurrentPlayerHandler, setInitialized, startWorking, writeAttributes
-
Methods inherited from class net.sf.freecol.server.ai.AIObject
addAIObjectWithId, checkIntegrity, copyIn, dispose, 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, toString, toXML, toXML, toXMLPartial, toXMLPartial, writeChildren
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
aiUnitLocationComparator
private static final java.util.Comparator<AIUnit> aiUnitLocationComparator
A comparator to sort AI units by location.
-
aiUnits
private java.util.List<AIUnit> aiUnits
Temporary variable, used to hold all AIUnit objects belonging to this AI. Any implementation of AIPlayer needs to make sure this list is invalidated as necessary, using clearAIUnits().
-
-
Constructor Detail
-
MissionAIPlayer
public MissionAIPlayer(AIMain aiMain, Player player)
Creates a new AI player.- Parameters:
aiMain
- TheAIMain
the player exists within.player
- ThePlayer
to associate this AI player with.
-
MissionAIPlayer
public MissionAIPlayer(AIMain aiMain, FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Creates a newAIPlayer
from the given XML-representation.- Parameters:
aiMain
- The main AI-object.xr
- The input stream containing the XML.- Throws:
javax.xml.stream.XMLStreamException
- if a problem was encountered during parsing.
-
-
Method Detail
-
removeAIObject
public void removeAIObject(AIObject ao)
Remove one of our owned objects. Subclasses to override.- Overrides:
removeAIObject
in classAIPlayer
- Parameters:
ao
- TheAIObject
to remove.
-
clearAIUnits
protected void clearAIUnits()
Clears the cache of AI units.
-
addAIUnit
public void addAIUnit(AIUnit aiUnit)
Add an AI unit owned by this player.- Parameters:
aiUnit
- TheAIUnit
to add.
-
removeAIUnit
private void removeAIUnit(AIUnit aiu)
Remove an AI unit.- Parameters:
aiu
- TheAIUnit
to remove.
-
getAIUnits
protected java.util.List<AIUnit> getAIUnits()
Gets a list of AIUnits for the player.- Overrides:
getAIUnits
in classAIPlayer
- Returns:
- A list of AIUnits.
-
getSettlementDefenders
public int getSettlementDefenders(Settlement settlement)
Counts the number of defenders allocated to a settlement.- Parameters:
settlement
- TheSettlement
to examine.- Returns:
- The number of defenders.
-
isTargetValidForSeekAndDestroy
public boolean isTargetValidForSeekAndDestroy(Unit attacker, Tile tile)
Find out if a tile contains a suitable target for seek-and-destroy. FIXME: Package for access by a test only - necessary?- Parameters:
attacker
- The attackingUnit
.tile
- TheTile
to attack into.- Returns:
- True if an attack can be launched.
-
logMissions
protected void logMissions(java.util.Map<Unit,java.lang.String> reasons, LogBuilder lb)
Log the missions of this player.- Parameters:
reasons
- A map of reasons for the current mission by unit.lb
- ALogBuilder
to log to.
-
getDefendCurrentSettlementMission
public Mission getDefendCurrentSettlementMission(AIUnit aiUnit)
Get a DefendSettlementMission for the current settlement of a unit if it is badly defended.- Parameters:
aiUnit
- TheAIUnit
to check.- Returns:
- A new misison, or null if impossible or not worthwhile.
-
getDefendSettlementMission
public Mission getDefendSettlementMission(AIUnit aiUnit, Settlement target)
Gets a new DefendSettlementMission for a unit.- Parameters:
aiUnit
- TheAIUnit
to check.target
- TheSettlement
to defend.- Returns:
- A new mission, or null if impossible.
-
getIdleAtSettlementMission
public Mission getIdleAtSettlementMission(AIUnit aiUnit)
Gets a new IdleAtSettlementMission for a unit.- Parameters:
aiUnit
- TheAIUnit
to use.- Returns:
- A new mission, or null if impossible.
-
getSeekAndDestroyMission
public Mission getSeekAndDestroyMission(AIUnit aiUnit, int range)
Gets a UnitSeekAndDestroyMission for a unit.- Parameters:
aiUnit
- TheAIUnit
to check.range
- A maximum range to search for a target within.- Returns:
- A new mission, or null if impossible.
-
getSeekAndDestroyMission
public Mission getSeekAndDestroyMission(AIUnit aiUnit, Location loc)
Gets a UnitSeekAndDestroyMission for a unit.- Parameters:
aiUnit
- TheAIUnit
to check.loc
- The targetLocation
.- Returns:
- A new mission, or null if impossible.
-
getWanderHostileMission
public Mission getWanderHostileMission(AIUnit aiUnit)
Gets a new UnitWanderHostileMission for a unit.- Parameters:
aiUnit
- TheAIUnit
to check.- Returns:
- A new mission, or null if impossible.
-
doMissions
protected java.util.List<AIUnit> doMissions(java.util.List<AIUnit> aiUnits, LogBuilder lb)
Makes every unit perform their mission.- Parameters:
aiUnits
- A list ofAIUnit
s to perform missions.lb
- ALogBuilder
to log to.- Returns:
- A list of
AIUnit
s that have moves left.
-
adjustMission
public abstract int adjustMission(AIUnit aiUnit, PathNode path, java.lang.Class type, int value)
Adjusts the score of this proposed mission for this player type. Subclasses should override and refine this.- Parameters:
aiUnit
- TheAIUnit
to perform the mission.path
- APathNode
to the target of this mission.value
- The proposed value.type
- The mission type.- Returns:
- A score representing the desirability of this mission.
-
-