Package net.sf.freecol.server.ai
Class NativeAIPlayer
- 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
-
- net.sf.freecol.server.ai.NativeAIPlayer
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,ObjectWithId
public final class NativeAIPlayer extends MissionAIPlayer
Objects of this class contains AI-information for a singlePlayer
and is used for controlling this player. The methodstartWorking()
gets called by theAIInGameInputHandler
when it is this player's turn.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.logging.Logger
logger
static int
MAX_DISTANCE_TO_BRING_GIFTS
static int
MAX_DISTANCE_TO_MAKE_DEMANDS
static int
MAX_NUMBER_OF_DEMANDS
static int
MAX_NUMBER_OF_GIFTS_BEING_DELIVERED
private java.util.Map<Unit,java.lang.String>
reasons
Debug helper to keep track of why/what the units are doing.-
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 NativeAIPlayer(AIMain aiMain, FreeColXMLReader xr)
Creates a newAIPlayer
.NativeAIPlayer(AIMain aiMain, Player player)
Creates a newAIPlayer
.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
abortInvalidMissions()
Aborts all the missions which are no longer valid.int
adjustMission(AIUnit aiUnit, PathNode path, java.lang.Class type, int value)
Adjusts the score of this proposed mission for this player type.private void
bringGifts(int[] randoms, LogBuilder lb)
Brings gifts to nice players with nearby colonies.void
completeWish(Wish w)
Notify that a wish has been completed.private void
demandTribute(int[] randoms, LogBuilder lb)
Demands tribute from nasty players with nearby colonies.private void
determineStances(LogBuilder lb)
Determines the stances towards each player.void
equipBraves(IndianSettlement is, LogBuilder lb)
Greedily equips braves with horses and muskets.int
getNeededWagons(Tile tile)
Gets the needed wagons for a tile/contiguity.private java.util.List<Modifier>
getShipTradePenalties(boolean sense)
Gets the appropriate ship trade penalties.private void
giveNormalMissions(LogBuilder lb)
Gives a mission to all units.NativeTrade.NativeTradeAction
handleTrade(NativeTrade.NativeTradeAction action, NativeTrade nt)
Handle a native trade request.Constants.IndianDemandAction
indianDemand(Unit unit, Colony colony, GoodsType type, int amount, Constants.IndianDemandAction accept)
Decide whether to accept an Indian demand, or not.private void
initializeMissions(LogBuilder lb)
Simple initialization of AI missions given that we know the starting conditions.int
pioneersNeeded()
How many pioneers should we have? This is the desired total number, not the actual number which would take into account the number of existing PioneeringMissions.int
scoutsNeeded()
How many scouts should we have? This is the desired total number, not the actual number which would take into account the number of existing ScoutingMissions.void
secureIndianSettlement(IndianSettlement is, LogBuilder lb)
Takes the necessary actions to secure an indian settlement Public for the test suite.private void
secureSettlements(int[] randoms, LogBuilder lb)
Takes the necessary actions to secure the settlements.void
startWorking()
Tells thisAIPlayer
to make decisions.private void
updateTrade(NativeTrade nt, int anger)
Price the goods to buy.-
Methods inherited from class net.sf.freecol.server.ai.MissionAIPlayer
addAIUnit, clearAIUnits, doMissions, getAIUnits, getDefendCurrentSettlementMission, getDefendSettlementMission, getIdleAtSettlementMission, getSeekAndDestroyMission, getSeekAndDestroyMission, getSettlementDefenders, getWanderHostileMission, isTargetValidForSeekAndDestroy, logMissions, removeAIObject
-
Methods inherited from class net.sf.freecol.server.ai.AIPlayer
acceptDiplomaticTrade, acceptMercenaries, acceptTax, askServer, checkIntegrity, chooseFoundingFatherHandler, determineStance, diplomacyHandler, firstContactHandler, fountainOfYouthHandler, getAIAdvantage, getAIColonies, getAIColony, getAIRandom, getAIUnit, getConnection, getPlayer, getXMLTagName, indianDemandHandler, invoke, lootCargoHandler, monarchActionHandler, nationSummaryHandler, nativeTradeHandler, newLandNameHandler, newRegionNameHandler, readAttributes, reconnectHandler, selectFoundingFather, setAIHandler, setCurrentPlayerHandler, setInitialized, 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
-
MAX_DISTANCE_TO_BRING_GIFTS
public static final int MAX_DISTANCE_TO_BRING_GIFTS
- See Also:
- Constant Field Values
-
MAX_NUMBER_OF_GIFTS_BEING_DELIVERED
public static final int MAX_NUMBER_OF_GIFTS_BEING_DELIVERED
- See Also:
- Constant Field Values
-
MAX_DISTANCE_TO_MAKE_DEMANDS
public static final int MAX_DISTANCE_TO_MAKE_DEMANDS
- See Also:
- Constant Field Values
-
MAX_NUMBER_OF_DEMANDS
public static final int MAX_NUMBER_OF_DEMANDS
- See Also:
- Constant Field Values
-
reasons
private final java.util.Map<Unit,java.lang.String> reasons
Debug helper to keep track of why/what the units are doing. Do not serialize.
-
-
Constructor Detail
-
NativeAIPlayer
public NativeAIPlayer(AIMain aiMain, Player player)
Creates a newAIPlayer
.- Parameters:
aiMain
- The main AI-class.player
- The player that should be associated with thisAIPlayer
.
-
NativeAIPlayer
public NativeAIPlayer(AIMain aiMain, FreeColXMLReader xr) throws javax.xml.stream.XMLStreamException
Creates a newAIPlayer
.- 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
-
initializeMissions
private void initializeMissions(LogBuilder lb)
Simple initialization of AI missions given that we know the starting conditions.- Parameters:
lb
- ALogBuilder
to log to.
-
determineStances
private void determineStances(LogBuilder lb)
Determines the stances towards each player. That is: should we declare war?- Parameters:
lb
- ALogBuilder
to log to.
-
secureSettlements
private void secureSettlements(int[] randoms, LogBuilder lb)
Takes the necessary actions to secure the settlements. This is done by making new military units or to give existing units new missions.- Parameters:
randoms
- An array of random settlement indexes.lb
- ALogBuilder
to log to.
-
equipBraves
public void equipBraves(IndianSettlement is, LogBuilder lb)
Greedily equips braves with horses and muskets. Public for the test suite.- Parameters:
is
- TheIndianSettlement
where the equipping occurs.lb
- ALogBuilder
to log to.
-
secureIndianSettlement
public void secureIndianSettlement(IndianSettlement is, LogBuilder lb)
Takes the necessary actions to secure an indian settlement Public for the test suite.- Parameters:
is
- TheIndianSettlement
to secure.lb
- ALogBuilder
to log to.
-
giveNormalMissions
private void giveNormalMissions(LogBuilder lb)
Gives a mission to all units.- Parameters:
lb
- ALogBuilder
to log to.
-
bringGifts
private void bringGifts(int[] randoms, LogBuilder lb)
Brings gifts to nice players with nearby colonies.- Parameters:
randoms
- An array of random percentages.lb
- ALogBuilder
to log to.
-
demandTribute
private void demandTribute(int[] randoms, LogBuilder lb)
Demands tribute from nasty players with nearby colonies.- Parameters:
randoms
- An array of random percentages.lb
- ALogBuilder
to log to.
-
getShipTradePenalties
private java.util.List<Modifier> getShipTradePenalties(boolean sense)
Gets the appropriate ship trade penalties.- Parameters:
sense
- The sense to apply the modifiers.- Returns:
- The ship trade penalties.
-
abortInvalidMissions
public void abortInvalidMissions()
Aborts all the missions which are no longer valid. Public for the test suite.
-
indianDemand
public Constants.IndianDemandAction indianDemand(Unit unit, Colony colony, GoodsType type, int amount, Constants.IndianDemandAction accept)
Decide whether to accept an Indian demand, or not. Or for native players, return the result of the demand.- Overrides:
indianDemand
in classAIPlayer
- Parameters:
unit
- TheUnit
making demands.colony
- TheColony
where demands are being made.type
- TheGoodsType
demanded.amount
- The amount of gold demanded.accept
- The acceptance state of the demand.- Returns:
- The result of the demand.
-
startWorking
public void startWorking()
Tells thisAIPlayer
to make decisions. TheAIPlayer
is done doing work this turn when this method returns.- Specified by:
startWorking
in classAIPlayer
-
adjustMission
public 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.- Specified by:
adjustMission
in classMissionAIPlayer
- Parameters:
aiUnit
- TheAIUnit
to perform the mission.path
- APathNode
to the target of this mission.type
- The mission type.value
- The proposed value.- Returns:
- A score representing the desirability of this mission.
-
updateTrade
private void updateTrade(NativeTrade nt, int anger)
Price the goods to buy.- Parameters:
nt
- TheNativeTrade
to update.anger
- A penalty to the native prices due to anger.
-
handleTrade
public NativeTrade.NativeTradeAction handleTrade(NativeTrade.NativeTradeAction action, NativeTrade nt)
Handle a native trade request.- Specified by:
handleTrade
in classAIPlayer
- Parameters:
action
- TheNativeTradeAction
to perform.nt
- TheNativeTrade
to handle.- Returns:
- The action in response.
-
getNeededWagons
public int getNeededWagons(Tile tile)
Gets the needed wagons for a tile/contiguity.- Specified by:
getNeededWagons
in classAIPlayer
- Parameters:
tile
- TheTile
to derive the contiguity from.- Returns:
- The number of wagons needed.
-
pioneersNeeded
public int pioneersNeeded()
How many pioneers should we have? This is the desired total number, not the actual number which would take into account the number of existing PioneeringMissions.- Specified by:
pioneersNeeded
in classAIPlayer
- Returns:
- The desired number of pioneers for this player.
-
scoutsNeeded
public int scoutsNeeded()
How many scouts should we have? This is the desired total number, not the actual number which would take into account the number of existing ScoutingMissions. Current scheme for European AIs is to use up to three scouts in the early part of the game, then one.- Specified by:
scoutsNeeded
in classAIPlayer
- Returns:
- The desired number of scouts for this player.
-
completeWish
public void completeWish(Wish w)
Notify that a wish has been completed. Called from AIColony.- Specified by:
completeWish
in classAIPlayer
- Parameters:
w
- TheWish
to complete.
-
-