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 executingMissions. The methodAIPlayer.startWorking()gets called by theAIInGameInputHandlerwhen it is this player's turn.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.Comparator<AIUnit>aiUnitLocationComparatorA comparator to sort AI units by location.private java.util.List<AIUnit>aiUnitsTemporary variable, used to hold all AIUnit objects belonging to this AI.private static java.util.logging.Loggerlogger-
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 newAIPlayerfrom 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 voidaddAIUnit(AIUnit aiUnit)Add an AI unit owned by this player.abstract intadjustMission(AIUnit aiUnit, PathNode path, java.lang.Class type, int value)Adjusts the score of this proposed mission for this player type.protected voidclearAIUnits()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.MissiongetDefendCurrentSettlementMission(AIUnit aiUnit)Get a DefendSettlementMission for the current settlement of a unit if it is badly defended.MissiongetDefendSettlementMission(AIUnit aiUnit, Settlement target)Gets a new DefendSettlementMission for a unit.MissiongetIdleAtSettlementMission(AIUnit aiUnit)Gets a new IdleAtSettlementMission for a unit.MissiongetSeekAndDestroyMission(AIUnit aiUnit, int range)Gets a UnitSeekAndDestroyMission for a unit.MissiongetSeekAndDestroyMission(AIUnit aiUnit, Location loc)Gets a UnitSeekAndDestroyMission for a unit.intgetSettlementDefenders(Settlement settlement)Counts the number of defenders allocated to a settlement.MissiongetWanderHostileMission(AIUnit aiUnit)Gets a new UnitWanderHostileMission for a unit.booleanisTargetValidForSeekAndDestroy(Unit attacker, Tile tile)Find out if a tile contains a suitable target for seek-and-destroy.protected voidlogMissions(java.util.Map<Unit,java.lang.String> reasons, LogBuilder lb)Log the missions of this player.voidremoveAIObject(AIObject ao)Remove one of our owned objects.private voidremoveAIUnit(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- TheAIMainthe player exists within.player- ThePlayerto associate this AI player with.
-
MissionAIPlayer
public MissionAIPlayer(AIMain aiMain, FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Creates a newAIPlayerfrom 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:
removeAIObjectin classAIPlayer- Parameters:
ao- TheAIObjectto 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- TheAIUnitto add.
-
removeAIUnit
private void removeAIUnit(AIUnit aiu)
Remove an AI unit.- Parameters:
aiu- TheAIUnitto remove.
-
getAIUnits
protected java.util.List<AIUnit> getAIUnits()
Gets a list of AIUnits for the player.- Overrides:
getAIUnitsin classAIPlayer- Returns:
- A list of AIUnits.
-
getSettlementDefenders
public int getSettlementDefenders(Settlement settlement)
Counts the number of defenders allocated to a settlement.- Parameters:
settlement- TheSettlementto 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- TheTileto 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- ALogBuilderto 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- TheAIUnitto 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- TheAIUnitto check.target- TheSettlementto defend.- Returns:
- A new mission, or null if impossible.
-
getIdleAtSettlementMission
public Mission getIdleAtSettlementMission(AIUnit aiUnit)
Gets a new IdleAtSettlementMission for a unit.- Parameters:
aiUnit- TheAIUnitto 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- TheAIUnitto 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- TheAIUnitto 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- TheAIUnitto 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 ofAIUnits to perform missions.lb- ALogBuilderto log to.- Returns:
- A list of
AIUnits 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- TheAIUnitto perform the mission.path- APathNodeto the target of this mission.value- The proposed value.type- The mission type.- Returns:
- A score representing the desirability of this mission.
-
-