Package net.sf.freecol.server.ai
Class EuropeanAIPlayer
- 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.EuropeanAIPlayer
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>,ObjectWithId
- Direct Known Subclasses:
REFAIPlayer
public class EuropeanAIPlayer extends MissionAIPlayer
Objects of this class contains AI-information for a single EuropeanPlayerand 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 java.util.List<AIColony>badlyDefendedThe colonies that start the turn badly defended.private static java.util.Comparator<AIUnit>builderComparatorA comparator to sort units by decreasing builder score.private static intbuildingRangeMaximum number of turns to travel to a building site.private static intcashInRangeMaximum number of turns to travel to a cash in location.private static intequipPioneerCheatPercentprivate static java.util.function.Predicate<Unit>equipPredPredicate to select units that can be equipped.private static intequipScoutCheatPercentprivate java.util.Map<GoodsType,java.util.List<GoodsWish>>goodsWishesA mapping of goods type to the goods wishes where a colony has requested that goods type.private static intlandUnitCheatPercentprivate static intliftBoycottCheatPercentCheat chances.private static java.util.logging.Loggerloggerprivate static intmissionaryRangeMaximum number of turns to travel to a missionary target.private intnBuildersCurrent estimate of the number of newBuildColonyMissions to create.private intnNavalCarrierCount of the number of transports needing a naval unit.private intnPioneersCurrent estimate of the number of newPioneeringMissions to create.private intnScoutsCurrent estimate of the number of newScoutingMissions to create.private static intoffensiveLandUnitCheatPercentprivate static intoffensiveNavalUnitCheatPercentprivate static java.util.function.Predicate<Modifier>partyPredPredicate to select party modifiers.static java.util.Comparator<AIUnit>pioneerComparatorA comparator to sort units by suitability for a PioneeringMission.private static intpioneeringRangeMaximum number of turns to travel to make progress on pioneering.private static RolepioneerRoleThe pioneer role.private static intprivateerRangeMaximum number of turns to travel to a privateering target.static java.util.Comparator<AIUnit>scoutComparatorA comparator to sort units by suitability for a ScoutingMission.private static intscoutingRangeMaximum number of turns to travel to a scouting target.private static RolescoutRoleThe scouting role.private java.util.Map<Tile,TileImprovementPlan>tipMapA cached map of Tile to best TileImprovementPlan.private java.util.Map<Location,java.util.List<Wish>>transportDemandA cached map of destination Location to Wishes awaiting transport.private static inttransportNavalUnitCheatPercentprivate java.util.List<TransportableAIObject>transportSupplyA cached list of transportables awaiting transport.private java.util.Map<java.lang.Integer,java.lang.Integer>wagonsNeededA mapping of contiguity number to number of wagons needed in that landmass.private java.util.Map<UnitType,java.util.List<WorkerWish>>workerWishesA mapping of unit type to the worker wishes for that type.-
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 EuropeanAIPlayer(AIMain aiMain, FreeColXMLReader xr)Creates a newAIPlayer.EuropeanAIPlayer(AIMain aiMain, Player player)Creates a newEuropeanAIPlayer.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description DiplomaticTrade.TradeStatusacceptDiplomaticTrade(DiplomaticTrade agreement)Resolves a diplomatic trade offer.booleanacceptMercenaries()Decides to accept an offer of mercenaries or not.booleanacceptTax(int tax)Decides to accept a tax raise or not.intadjustMission(AIUnit aiUnit, PathNode path, java.lang.Class type, int value)Adjusts the score of this proposed mission for this player type.voidallocateTransportables(java.util.List<TransportableAIObject> transportables, java.util.List<TransportMission> missions, LogBuilder lb)Assign transportable units and goods to available carriers.private voidbringGifts(LogBuilder lb)Brings gifts to nice players with nearby colonies.private intbuildersNeeded()Gets the number of units that should build a colony.voidbuildTipMap(LogBuilder lb)Rebuilds a map of locations to TileImprovementPlans.private voidbuildTransportMaps(LogBuilder lb)Rebuild the transport maps.private voidbuildWishMaps(LogBuilder lb)Rebuilds the goods and worker wishes maps.private voidchangeNeedWagon(Tile tile, int amount)Changes the needed wagons map for a specified tile/contiguity.private voidcheat(LogBuilder lb)Cheats for the AI.voidcheatGold(int amount, LogBuilder lb)Cheat by adding gold to guarantee the player has a minimum amount.private AIUnitcheatUnit(java.util.List<RandomChoice<UnitType>> rc, java.lang.String what, LogBuilder lb)Cheat-build a unit in Europe.private AIUnitcheatUnit(UnitType unitType, java.lang.String what, LogBuilder lb)Cheat-build a unit in Europe.private booleancheckTransport(TransportableAIObject t)Checks that the carrier assigned to a transportable is has a transport mission and the transport is queued thereon.booleanclaimTransportable(TransportableAIObject t)Allows a TransportMission to signal that it has taken responsibility for a TransportableAIObject.voidcompleteWish(Wish w)Notify that a wish has been completed.private voidconsumeGoodsWish(AIGoods aig, GoodsWish gw)Consume a GoodsWish.private voidconsumeWorkerWish(AIUnit aiUnit, WorkerWish ww)Consume a WorkerWish, yielding a WishRealizationMission for a unit.private voiddemandTribute(LogBuilder lb)Demands goods from players with nearby colonies.protected StancedetermineStance(Player other)Standard stance change determination.private voiddetermineStances(LogBuilder lb)Determines the stances towards each player.protected java.util.List<AIUnit>doMissions(java.util.List<AIUnit> aiUnits, LogBuilder lb)Makes every unit perform their mission.protected java.util.List<AIColony>getBadlyDefended()Get the list of badly defended colonies.GoodsWishgetBestGoodsWish(AIUnit aiUnit, GoodsType goodsType)Gets the best goods wish for a carrier unit.TileImprovementPlangetBestPlan(Tile tile)Gets the best plan for a tile from the tipMap.TilegetBestPlanTile(Colony colony)Gets the best plan for a colony from the tipMap.private WorkerWishgetBestWorkerWish(AIUnit aiUnit, UnitType unitType)Gets the best worker wish for a carrier unit.private MissiongetBuildColonyMission(AIUnit aiUnit, Location target)Gets a new BuildColonyMission for a unit.private MissiongetCashInTreasureTrainMission(AIUnit aiUnit)Gets a new CashInTreasureTrainMission for a unit.private MissiongetDefendSettlementMission(AIUnit aiUnit, boolean relaxed)Gets a new DefendSettlementMission for a unit.java.util.List<GoodsWish>getGoodsWishesAt(Location loc, GoodsType type)Gets a list of the wishes at a given location for a goods type.MissiongetMissionaryMission(AIUnit aiUnit)Gets a new MissionaryMission for a unit.protected NationSummarygetNationSummary(Player other)Get a nation summary for another player.protected doublegetNavalStrengthRatio()Is this player lagging in naval strength? Calculate the ratio of its naval strength to the average strength of other European colonial powers.intgetNeededWagons(Tile tile)Gets the needed wagons for a tile/contiguity.MissiongetPioneeringMission(AIUnit aiUnit, Location target)Gets a new PioneeringMission for a unit.MissiongetPrivateerMission(AIUnit aiUnit, Location target)Gets a new PrivateerMission for a unit.MissiongetScoutingMission(AIUnit aiUnit)Gets a new ScoutingMission for a unit.private MissiongetSimpleMission(AIUnit aiUnit)Choose a mission for an AIUnit.protected doublegetStrengthRatio(Player other)Get the land force strength ratio of this player with respect to another.MissiongetTransportMission(AIUnit aiUnit)Gets a new TransportMission for a unit.java.util.List<TransportableAIObject>getUrgentTransportables()Gets the most urgent transportables.java.util.List<Wish>getWishes()Gets the wishes for all this player's colonies, sorted by thevalue.private MissiongetWishRealizationMission(AIUnit aiUnit, WorkerWish wish)Gets a new WishRealizationMission for a unit.java.util.List<WorkerWish>getWorkerWishesAt(Location loc, UnitType type)Gets a list of the wishes at a given location for a unit type.MissiongetWorkInsideColonyMission(AIUnit aiUnit, AIColony aiColony)Gets a WorkInsideColonyMission for a unit.protected voidgiveNormalMissions(LogBuilder lb)Ensures all units have a mission.NativeTrade.NativeTradeActionhandleTrade(NativeTrade.NativeTradeAction action, NativeTrade nt)Handle a native trade request.Constants.IndianDemandActionindianDemand(Unit unit, Colony colony, GoodsType goods, int gold, Constants.IndianDemandAction accept)Decide whether to accept an Indian demand, or not.private static voidinitializeFromSpecification(Specification spec)Initialize the static fields that would be final but for needing the specification.private voidinitializeMissions(LogBuilder lb)Simple initialization of AI missions given that we know the starting conditions.private booleanpeaceHolds(Player p)See if a recent peace treaty still has force.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.private voidrearrangeColonies(LogBuilder lb)Rearrange colonies.private AIUnitrecruitAIUnitInEurope(int slot)Asks the server to recruit a unit in Europe on behalf of the AIPlayer.private DiplomaticTrade.TradeStatusrejectAgreement(TradeItem stance, DiplomaticTrade agreement)Reject a trade agreement, except if a Franklin-derived stance is supplied.private voidremoveAIColony(AIColony aic)Remove one of our colonies.voidremoveAIObject(AIObject ao)Remove one of our owned objects.voidremoveTileImprovementPlan(TileImprovementPlan plan)Remove aTileImprovementPlanfrom the relevant colony.private booleanrequestsTransport(TransportableAIObject t)Checks if a transportable needs transport.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.FoundingFatherselectFoundingFather(java.util.List<FoundingFather> ffs)Selects the most useful founding father offered.voidstartWorking()Tells thisAIPlayerto make decisions.private voidsuppressEuropeanTrade(GoodsType type, LogBuilder lb)Suppress European trade in a goods type.private AIUnittrainAIUnitInEurope(UnitType unitType)Helper function for server communication - Ask the server to train a unit in Europe on behalf of the AIGetPlayer().private voidupdateTipMap(AIColony aic)Update the tip map with tips from a new colony.voidupdateTransport(AIUnit aiu, Location oldTarget, LogBuilder lb)Update the transport of a unit following a target change.-
Methods inherited from class net.sf.freecol.server.ai.MissionAIPlayer
addAIUnit, clearAIUnits, getAIUnits, getDefendCurrentSettlementMission, getDefendSettlementMission, getIdleAtSettlementMission, getSeekAndDestroyMission, getSeekAndDestroyMission, getSettlementDefenders, getWanderHostileMission, isTargetValidForSeekAndDestroy, logMissions
-
Methods inherited from class net.sf.freecol.server.ai.AIPlayer
askServer, checkIntegrity, chooseFoundingFatherHandler, diplomacyHandler, firstContactHandler, fountainOfYouthHandler, getAIAdvantage, getAIColonies, getAIColony, getAIRandom, getAIUnit, getConnection, getPlayer, getXMLTagName, indianDemandHandler, invoke, lootCargoHandler, monarchActionHandler, nationSummaryHandler, nativeTradeHandler, newLandNameHandler, newRegionNameHandler, readAttributes, reconnectHandler, 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
-
equipPred
private static final java.util.function.Predicate<Unit> equipPred
Predicate to select units that can be equipped.
-
partyPred
private static final java.util.function.Predicate<Modifier> partyPred
Predicate to select party modifiers.
-
buildingRange
private static final int buildingRange
Maximum number of turns to travel to a building site.- See Also:
- Constant Field Values
-
cashInRange
private static final int cashInRange
Maximum number of turns to travel to a cash in location.- See Also:
- Constant Field Values
-
missionaryRange
private static final int missionaryRange
Maximum number of turns to travel to a missionary target.- See Also:
- Constant Field Values
-
pioneeringRange
private static final int pioneeringRange
Maximum number of turns to travel to make progress on pioneering. This is low-ish because it is usually more efficient to ship the tools where they are needed and either create a new pioneer on site or send a hardy pioneer on horseback. The AI is probably smart enough to do the former already, and one day the latter.- See Also:
- Constant Field Values
-
privateerRange
private static final int privateerRange
Maximum number of turns to travel to a privateering target. Low number because of large naval moves.- See Also:
- Constant Field Values
-
scoutingRange
private static final int scoutingRange
Maximum number of turns to travel to a scouting target.- See Also:
- Constant Field Values
-
builderComparator
private static final java.util.Comparator<AIUnit> builderComparator
A comparator to sort units by decreasing builder score.
-
pioneerComparator
public static final java.util.Comparator<AIUnit> pioneerComparator
A comparator to sort units by suitability for a PioneeringMission. We do not check if a unit is near to a colony that can provide tools, as that is likely to be too expensive. FIXME: perhaps we should.
-
scoutComparator
public static final java.util.Comparator<AIUnit> scoutComparator
A comparator to sort units by suitability for a ScoutingMission. We do not check if a unit is near to a colony that can provide horses, as that is likely to be too expensive. FIXME: perhaps we should.
-
liftBoycottCheatPercent
private static int liftBoycottCheatPercent
Cheat chances.
-
equipScoutCheatPercent
private static int equipScoutCheatPercent
-
equipPioneerCheatPercent
private static int equipPioneerCheatPercent
-
landUnitCheatPercent
private static int landUnitCheatPercent
-
offensiveLandUnitCheatPercent
private static int offensiveLandUnitCheatPercent
-
offensiveNavalUnitCheatPercent
private static int offensiveNavalUnitCheatPercent
-
transportNavalUnitCheatPercent
private static int transportNavalUnitCheatPercent
-
pioneerRole
private static Role pioneerRole
The pioneer role.
-
scoutRole
private static Role scoutRole
The scouting role.
-
tipMap
private final java.util.Map<Tile,TileImprovementPlan> tipMap
A cached map of Tile to best TileImprovementPlan. Used to choose a tile improvement for a pioneer to work on.
-
transportDemand
private final java.util.Map<Location,java.util.List<Wish>> transportDemand
A cached map of destination Location to Wishes awaiting transport.
-
transportSupply
private final java.util.List<TransportableAIObject> transportSupply
A cached list of transportables awaiting transport.
-
goodsWishes
private final java.util.Map<GoodsType,java.util.List<GoodsWish>> goodsWishes
A mapping of goods type to the goods wishes where a colony has requested that goods type. Used to retarget goods that have gone astray.
-
workerWishes
private final java.util.Map<UnitType,java.util.List<WorkerWish>> workerWishes
A mapping of unit type to the worker wishes for that type. Used to allocate WishRealizationMissions for units.
-
wagonsNeeded
private final java.util.Map<java.lang.Integer,java.lang.Integer> wagonsNeeded
A mapping of contiguity number to number of wagons needed in that landmass.
-
badlyDefended
private final java.util.List<AIColony> badlyDefended
The colonies that start the turn badly defended.
-
nBuilders
private int nBuilders
Current estimate of the number of newBuildColonyMissions to create.
-
nPioneers
private int nPioneers
Current estimate of the number of newPioneeringMissions to create.
-
nScouts
private int nScouts
Current estimate of the number of newScoutingMissions to create.
-
nNavalCarrier
private int nNavalCarrier
Count of the number of transports needing a naval unit.
-
-
Constructor Detail
-
EuropeanAIPlayer
public EuropeanAIPlayer(AIMain aiMain, Player player)
Creates a newEuropeanAIPlayer.- Parameters:
aiMain- The main AI-class.player- The player that should be associated with thisAIPlayer.
-
EuropeanAIPlayer
public EuropeanAIPlayer(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
-
removeAIObject
public void removeAIObject(AIObject ao)
Remove one of our owned objects. Subclasses to override.- Overrides:
removeAIObjectin classMissionAIPlayer- Parameters:
ao- TheAIObjectto remove.
-
removeAIColony
private void removeAIColony(AIColony aic)
Remove one of our colonies.- Parameters:
aic- TheAIColonyto remove.
-
initializeFromSpecification
private static void initializeFromSpecification(Specification spec)
Initialize the static fields that would be final but for needing the specification.- Parameters:
spec- TheSpecificationto initialize from.
-
getBadlyDefended
protected java.util.List<AIColony> getBadlyDefended()
Get the list of badly defended colonies.- Returns:
- A list of
AIColonys that were badly defended at the start of this turn.
-
initializeMissions
private void initializeMissions(LogBuilder lb)
Simple initialization of AI missions given that we know the starting conditions.- Parameters:
lb- ALogBuilderto log to.
-
cheatGold
public void cheatGold(int amount, LogBuilder lb)Cheat by adding gold to guarantee the player has a minimum amount.- Parameters:
amount- The minimum amount of gold required.lb- ALogBuilderto log to.
-
cheat
private void cheat(LogBuilder lb)
Cheats for the AI. Please try to centralize cheats here. FIXME: Remove when the AI is good enough.- Parameters:
lb- ALogBuilderto log to.
-
cheatUnit
private AIUnit cheatUnit(java.util.List<RandomChoice<UnitType>> rc, java.lang.String what, LogBuilder lb)
Cheat-build a unit in Europe.- Parameters:
rc- A list of random choices to choose from.what- A description of the unit.lb- ALogBuilderto log to.- Returns:
- The
AIUnitbuilt.
-
cheatUnit
private AIUnit cheatUnit(UnitType unitType, java.lang.String what, LogBuilder lb)
Cheat-build a unit in Europe.- Parameters:
unitType- TheUnitTypeto build.what- A description of the unit.lb- ALogBuilderto log to.- Returns:
- The
AIUnitbuilt.
-
allocateTransportables
public void allocateTransportables(java.util.List<TransportableAIObject> transportables, java.util.List<TransportMission> missions, LogBuilder lb)
Assign transportable units and goods to available carriers. These supply driven assignments supplement the demand driven calls inside TransportMission.- Parameters:
transportables- A list ofTransportableAIObjects to allocated transport for.missions- A list ofTransportMissions to potentially assign more transportables to.lb- ALogBuilderto log to.
-
bringGifts
private void bringGifts(LogBuilder lb)
Brings gifts to nice players with nearby colonies. FIXME: European players can also bring gifts! However, this might be folded into a trade mission, since European gifts are just a special case of trading.- Parameters:
lb- ALogBuilderto log to.
-
demandTribute
private void demandTribute(LogBuilder lb)
Demands goods from players with nearby colonies. FIXME: European players can also demand tribute!- Parameters:
lb- ALogBuilderto log to.
-
buildTipMap
public void buildTipMap(LogBuilder lb)
Rebuilds a map of locations to TileImprovementPlans. Called by startWorking at the start of every turn. Public for the test suite.- Parameters:
lb- ALogBuilderto log to.
-
updateTipMap
private void updateTipMap(AIColony aic)
Update the tip map with tips from a new colony.- Parameters:
aic- The newAIColony.
-
getBestPlan
public TileImprovementPlan getBestPlan(Tile tile)
Gets the best plan for a tile from the tipMap.- Parameters:
tile- TheTileto lookup.- Returns:
- The best plan for a tile.
-
getBestPlanTile
public Tile getBestPlanTile(Colony colony)
Gets the best plan for a colony from the tipMap.- Parameters:
colony- TheColonyto check.- Returns:
- The tile with the best plan for a colony, or null if none found.
-
removeTileImprovementPlan
public void removeTileImprovementPlan(TileImprovementPlan plan)
Remove aTileImprovementPlanfrom the relevant colony.- Parameters:
plan- TheTileImprovementPlanto remove.
-
updateTransport
public void updateTransport(AIUnit aiu, Location oldTarget, LogBuilder lb)
Update the transport of a unit following a target change. If the target has changed - drop all non-boarded transport unless the target is the same - dump boarded transport with no target - requeue all boarded transport unless the target is the same- Parameters:
aiu- TheAIUnitto check.oldTarget- The old targetLocation.lb- ALogBuilderto log to.
-
requestsTransport
private boolean requestsTransport(TransportableAIObject t)
Checks if a transportable needs transport.- Parameters:
t- TheTransportableAIObjectto check.- Returns:
- True if no transport is already present or the transportable is already aboard a carrier, and there is a well defined source and destination location.
-
checkTransport
private boolean checkTransport(TransportableAIObject t)
Checks that the carrier assigned to a transportable is has a transport mission and the transport is queued thereon.- Parameters:
t- TheTransportableAIObjectto check.- Returns:
- True if all is well.
-
changeNeedWagon
private void changeNeedWagon(Tile tile, int amount)
Changes the needed wagons map for a specified tile/contiguity. If the change is zero, that is a special flag that a connected port is available, and thus that the map should be initialized for that contiguity.- Parameters:
tile- TheTileto derive the contiguity from.amount- The change to make.
-
buildTransportMaps
private void buildTransportMaps(LogBuilder lb)
Rebuild the transport maps. Count the number of transports requiring naval/land carriers.- Parameters:
lb- ALogBuilderto log to.
-
getUrgentTransportables
public java.util.List<TransportableAIObject> getUrgentTransportables()
Gets the most urgent transportables.- Returns:
- The most urgent 10% of the available transportables.
-
claimTransportable
public boolean claimTransportable(TransportableAIObject t)
Allows a TransportMission to signal that it has taken responsibility for a TransportableAIObject.- Parameters:
t- TheTransportableAIObjectbeing claimed.- Returns:
- True if the transportable was claimed from the supply map.
-
rearrangeColonies
private void rearrangeColonies(LogBuilder lb)
Rearrange colonies.- Parameters:
lb- ALogBuilderto log to.
-
suppressEuropeanTrade
private void suppressEuropeanTrade(GoodsType type, LogBuilder lb)
Suppress European trade in a goods type. A goods party and boycott is incoming.- Parameters:
type- TheGoodsTypeto suppress.lb- ALogBuilderto log to.
-
getWorkerWishesAt
public java.util.List<WorkerWish> getWorkerWishesAt(Location loc, UnitType type)
Gets a list of the wishes at a given location for a unit type.- Parameters:
loc- TheLocationto look for wishes at.type- TheUnitTypeto look for.- Returns:
- A list of
WorkerWishes.
-
getGoodsWishesAt
public java.util.List<GoodsWish> getGoodsWishesAt(Location loc, GoodsType type)
Gets a list of the wishes at a given location for a goods type.- Parameters:
loc- TheLocationto look for wishes at.type- TheGoodsTypeto look for.- Returns:
- A list of
GoodsWishes.
-
getBestWorkerWish
private WorkerWish getBestWorkerWish(AIUnit aiUnit, UnitType unitType)
Gets the best worker wish for a carrier unit.- Parameters:
aiUnit- The carrierAIUnit.unitType- TheUnitTypeto find a wish for.- Returns:
- The best worker wish for the unit.
-
getBestGoodsWish
public GoodsWish getBestGoodsWish(AIUnit aiUnit, GoodsType goodsType)
Gets the best goods wish for a carrier unit.- Parameters:
aiUnit- The carrierAIUnit.goodsType- TheGoodsTypeto wish for.- Returns:
- The best
GoodsWishfor the unit.
-
buildWishMaps
private void buildWishMaps(LogBuilder lb)
Rebuilds the goods and worker wishes maps.- Parameters:
lb- ALogBuilderto log to.
-
consumeWorkerWish
private void consumeWorkerWish(AIUnit aiUnit, WorkerWish ww)
Consume a WorkerWish, yielding a WishRealizationMission for a unit.- Parameters:
aiUnit- TheAIUnitto check.ww- TheWorkerWishto consume.
-
consumeGoodsWish
private void consumeGoodsWish(AIGoods aig, GoodsWish gw)
Consume a GoodsWish.- Parameters:
aig- TheAIGoodsto use.gw- TheGoodsWishto consume.
-
buildersNeeded
private int buildersNeeded()
Gets the number of units that should build a colony. This is the desired total number, not the actual number which would take into account the number of existing BuildColonyMissions.- Returns:
- The desired number of colony builders for this player.
-
recruitAIUnitInEurope
private AIUnit recruitAIUnitInEurope(int slot)
Asks the server to recruit a unit in Europe on behalf of the AIPlayer. FIXME: Move this to a specialized Handler class (AIEurope?) FIXME: Give protected access?- Parameters:
slot- The migration slot to recruit from.- Returns:
- The new AIUnit created by this action or null on failure.
-
trainAIUnitInEurope
private AIUnit trainAIUnitInEurope(UnitType unitType)
Helper function for server communication - Ask the server to train a unit in Europe on behalf of the AIGetPlayer(). FIXME: Move this to a specialized Handler class (AIEurope?) FIXME: Give protected access?- Parameters:
unitType- TheUnitTypeto train.- Returns:
- the new AIUnit created by this action. May be null.
-
getWishes
public java.util.List<Wish> getWishes()
Gets the wishes for all this player's colonies, sorted by thevalue.- Returns:
- A list of wishes.
-
determineStances
private void determineStances(LogBuilder lb)
Determines the stances towards each player.- Parameters:
lb- ALogBuilderto log to.
-
peaceHolds
private boolean peaceHolds(Player p)
See if a recent peace treaty still has force.- Parameters:
p- ThePlayerto check for a peace treaty with.- Returns:
- True if peace gets another chance.
-
getNationSummary
protected NationSummary getNationSummary(Player other)
Get a nation summary for another player.- Parameters:
other- The otherPlayerto get the summary for.- Returns:
- The current
NationSummaryfor a player.
-
getStrengthRatio
protected double getStrengthRatio(Player other)
Get the land force strength ratio of this player with respect to another.- Parameters:
other- The otherPlayer.- Returns:
- The strength ratio (strength/sum(strengths)).
-
getNavalStrengthRatio
protected double getNavalStrengthRatio()
Is this player lagging in naval strength? Calculate the ratio of its naval strength to the average strength of other European colonial powers.- Returns:
- The naval strength ratio, or negative if there are no other European colonial nations.
-
rejectAgreement
private DiplomaticTrade.TradeStatus rejectAgreement(TradeItem stance, DiplomaticTrade agreement)
Reject a trade agreement, except if a Franklin-derived stance is supplied.- Parameters:
stance- A stanceTradeItem.agreement- TheDiplomaticTradeto reset.- Returns:
- The
TradeStatusfor the agreement.
-
giveNormalMissions
protected void giveNormalMissions(LogBuilder lb)
Ensures all units have a mission.- Parameters:
lb- ALogBuilderto log to.
-
getSimpleMission
private Mission getSimpleMission(AIUnit aiUnit)
Choose a mission for an AIUnit.- Parameters:
aiUnit- TheAIUnitto choose for.- Returns:
- A suitable
Mission, or null if none found.
-
getBuildColonyMission
private Mission getBuildColonyMission(AIUnit aiUnit, Location target)
Gets a new BuildColonyMission for a unit.- Parameters:
aiUnit- TheAIUnitto check.target- An optional targetLocation.- Returns:
- A new mission, or null if impossible.
-
getCashInTreasureTrainMission
private Mission getCashInTreasureTrainMission(AIUnit aiUnit)
Gets a new CashInTreasureTrainMission for a unit.- Parameters:
aiUnit- TheAIUnitto check.- Returns:
- A new mission, or null if impossible.
-
getDefendSettlementMission
private Mission getDefendSettlementMission(AIUnit aiUnit, boolean relaxed)
Gets a new DefendSettlementMission for a unit.- Parameters:
aiUnit- TheAIUnitto check.relaxed- Use a relaxed cost decider to choose the target.- Returns:
- A new mission, or null if impossible.
-
getMissionaryMission
public Mission getMissionaryMission(AIUnit aiUnit)
Gets a new MissionaryMission for a unit.- Parameters:
aiUnit- TheAIUnitto check.- Returns:
- A new mission, or null if impossible.
-
getPioneeringMission
public Mission getPioneeringMission(AIUnit aiUnit, Location target)
Gets a new PioneeringMission for a unit. FIXME: pioneers to make roads between colonies- Parameters:
aiUnit- TheAIUnitto check.target- An optional targetLocation.- Returns:
- A new mission, or null if impossible.
-
getPrivateerMission
public Mission getPrivateerMission(AIUnit aiUnit, Location target)
Gets a new PrivateerMission for a unit.- Parameters:
aiUnit- TheAIUnitto check.target- An optional targetLocation.- Returns:
- A new mission, or null if impossible.
-
getScoutingMission
public Mission getScoutingMission(AIUnit aiUnit)
Gets a new ScoutingMission for a unit.- Parameters:
aiUnit- TheAIUnitto check.- Returns:
- A new mission, or null if impossible.
-
getTransportMission
public Mission getTransportMission(AIUnit aiUnit)
Gets a new TransportMission for a unit.- Parameters:
aiUnit- TheAIUnitto check.- Returns:
- A new mission, or null if impossible.
-
getWishRealizationMission
private Mission getWishRealizationMission(AIUnit aiUnit, WorkerWish wish)
Gets a new WishRealizationMission for a unit.- Parameters:
aiUnit- TheAIUnitto check.wish- An optionalWorkerWishto realize.- Returns:
- A new mission, or null if impossible.
-
getWorkInsideColonyMission
public Mission getWorkInsideColonyMission(AIUnit aiUnit, AIColony aiColony)
Gets a WorkInsideColonyMission for a unit.- Parameters:
aiUnit- TheAIUnitto check.aiColony- An optionalAIColonyto work at.- Returns:
- A new mission, or null if impossible.
-
determineStance
protected Stance determineStance(Player other)
Standard stance change determination.- Overrides:
determineStancein classAIPlayer- Parameters:
other- ThePlayerwrt consider stance.- Returns:
- The new
Stance.
-
startWorking
public void startWorking()
Tells thisAIPlayerto make decisions. TheAIPlayeris done doing work this turn when this method returns.- Specified by:
startWorkingin classAIPlayer
-
doMissions
protected java.util.List<AIUnit> doMissions(java.util.List<AIUnit> aiUnits, LogBuilder lb)
Makes every unit perform their mission.- Overrides:
doMissionsin classMissionAIPlayer- Parameters:
aiUnits- A list ofAIUnits to perform missions.lb- ALogBuilderto log to.- Returns:
- A list of
AIUnits that have moves left.
-
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.
-
indianDemand
public Constants.IndianDemandAction indianDemand(Unit unit, Colony colony, GoodsType goods, int gold, 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.goods- TheGoodsTypedemanded.gold- The amount of gold demanded.accept- The acceptance state of the demand.- Returns:
- The result of the demand.
-
acceptDiplomaticTrade
public DiplomaticTrade.TradeStatus acceptDiplomaticTrade(DiplomaticTrade agreement)
Resolves a diplomatic trade offer.- Overrides:
acceptDiplomaticTradein classAIPlayer- Parameters:
agreement- The proposedDiplomaticTrade.- Returns:
- The
TradeStatusto apply to the agreement.
-
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.
-
acceptTax
public boolean acceptTax(int tax)
Decides to accept a tax raise or not. Overridden by the European player.
-
acceptMercenaries
public boolean acceptMercenaries()
Decides to accept an offer of mercenaries or not. Overridden by the European player.- Overrides:
acceptMercenariesin classAIPlayer- Returns:
- True if the mercenaries are accepted.
-
selectFoundingFather
public FoundingFather selectFoundingFather(java.util.List<FoundingFather> ffs)
Selects the most useful founding father offered. Overridden by EuropeanAIPlayers.- Overrides:
selectFoundingFatherin classAIPlayer- Parameters:
ffs- The founding fathers on offer.- Returns:
- The founding father selected.
-
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.
-
-