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 singlePlayerand is used for controlling this player. The methodstartWorking()gets called by theAIInGameInputHandlerwhen it is this player's turn.
-
-
Field Summary
Fields Modifier and Type Field Description private static java.util.logging.Loggerloggerstatic intMAX_DISTANCE_TO_BRING_GIFTSstatic intMAX_DISTANCE_TO_MAKE_DEMANDSstatic intMAX_NUMBER_OF_DEMANDSstatic intMAX_NUMBER_OF_GIFTS_BEING_DELIVEREDprivate java.util.Map<Unit,java.lang.String>reasonsDebug 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 voidabortInvalidMissions()Aborts all the missions which are no longer valid.intadjustMission(AIUnit aiUnit, PathNode path, java.lang.Class type, int value)Adjusts the score of this proposed mission for this player type.private voidbringGifts(int[] randoms, LogBuilder lb)Brings gifts to nice players with nearby colonies.voidcompleteWish(Wish w)Notify that a wish has been completed.private voiddemandTribute(int[] randoms, LogBuilder lb)Demands tribute from nasty players with nearby colonies.private voiddetermineStances(LogBuilder lb)Determines the stances towards each player.voidequipBraves(IndianSettlement is, LogBuilder lb)Greedily equips braves with horses and muskets.intgetNeededWagons(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 voidgiveNormalMissions(LogBuilder lb)Gives a mission to all units.NativeTrade.NativeTradeActionhandleTrade(NativeTrade.NativeTradeAction action, NativeTrade nt)Handle a native trade request.Constants.IndianDemandActionindianDemand(Unit unit, Colony colony, GoodsType type, int amount, Constants.IndianDemandAction accept)Decide whether to accept an Indian demand, or not.private voidinitializeMissions(LogBuilder lb)Simple initialization of AI missions given that we know the starting conditions.intpioneersNeeded()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.intscoutsNeeded()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.voidsecureIndianSettlement(IndianSettlement is, LogBuilder lb)Takes the necessary actions to secure an indian settlement Public for the test suite.private voidsecureSettlements(int[] randoms, LogBuilder lb)Takes the necessary actions to secure the settlements.voidstartWorking()Tells thisAIPlayerto make decisions.private voidupdateTrade(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- ALogBuilderto log to.
-
determineStances
private void determineStances(LogBuilder lb)
Determines the stances towards each player. That is: should we declare war?- Parameters:
lb- ALogBuilderto 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- ALogBuilderto log to.
-
equipBraves
public void equipBraves(IndianSettlement is, LogBuilder lb)
Greedily equips braves with horses and muskets. Public for the test suite.- Parameters:
is- TheIndianSettlementwhere the equipping occurs.lb- ALogBuilderto 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- TheIndianSettlementto secure.lb- ALogBuilderto log to.
-
giveNormalMissions
private void giveNormalMissions(LogBuilder lb)
Gives a mission to all units.- Parameters:
lb- ALogBuilderto 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- ALogBuilderto 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- ALogBuilderto 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:
indianDemandin classAIPlayer- Parameters:
unit- TheUnitmaking demands.colony- TheColonywhere demands are being made.type- TheGoodsTypedemanded.amount- The amount of gold demanded.accept- The acceptance state of the demand.- Returns:
- The result of the demand.
-
startWorking
public void startWorking()
Tells thisAIPlayerto make decisions. TheAIPlayeris done doing work this turn when this method returns.- Specified by:
startWorkingin 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:
adjustMissionin classMissionAIPlayer- Parameters:
aiUnit- TheAIUnitto perform the mission.path- APathNodeto 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- TheNativeTradeto 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:
handleTradein classAIPlayer- Parameters:
action- TheNativeTradeActionto perform.nt- TheNativeTradeto handle.- Returns:
- The action in response.
-
getNeededWagons
public int getNeededWagons(Tile tile)
Gets the needed wagons for a tile/contiguity.- Specified by:
getNeededWagonsin classAIPlayer- Parameters:
tile- TheTileto 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:
pioneersNeededin 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:
scoutsNeededin 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:
completeWishin classAIPlayer- Parameters:
w- TheWishto complete.
-
-