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 EuropeanPlayer
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 java.util.List<AIColony>
badlyDefended
The colonies that start the turn badly defended.private static java.util.Comparator<AIUnit>
builderComparator
A comparator to sort units by decreasing builder score.private static int
buildingRange
Maximum number of turns to travel to a building site.private static int
cashInRange
Maximum number of turns to travel to a cash in location.private static int
equipPioneerCheatPercent
private static java.util.function.Predicate<Unit>
equipPred
Predicate to select units that can be equipped.private static int
equipScoutCheatPercent
private 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.private static int
landUnitCheatPercent
private static int
liftBoycottCheatPercent
Cheat chances.private static java.util.logging.Logger
logger
private static int
missionaryRange
Maximum number of turns to travel to a missionary target.private int
nBuilders
Current estimate of the number of newBuildColonyMission
s to create.private int
nNavalCarrier
Count of the number of transports needing a naval unit.private int
nPioneers
Current estimate of the number of newPioneeringMission
s to create.private int
nScouts
Current estimate of the number of newScoutingMission
s to create.private static int
offensiveLandUnitCheatPercent
private static int
offensiveNavalUnitCheatPercent
private static java.util.function.Predicate<Modifier>
partyPred
Predicate to select party modifiers.static java.util.Comparator<AIUnit>
pioneerComparator
A comparator to sort units by suitability for a PioneeringMission.private static int
pioneeringRange
Maximum number of turns to travel to make progress on pioneering.private static Role
pioneerRole
The pioneer role.private static int
privateerRange
Maximum number of turns to travel to a privateering target.static java.util.Comparator<AIUnit>
scoutComparator
A comparator to sort units by suitability for a ScoutingMission.private static int
scoutingRange
Maximum number of turns to travel to a scouting target.private static Role
scoutRole
The scouting role.private java.util.Map<Tile,TileImprovementPlan>
tipMap
A cached map of Tile to best TileImprovementPlan.private java.util.Map<Location,java.util.List<Wish>>
transportDemand
A cached map of destination Location to Wishes awaiting transport.private static int
transportNavalUnitCheatPercent
private java.util.List<TransportableAIObject>
transportSupply
A cached list of transportables awaiting transport.private java.util.Map<java.lang.Integer,java.lang.Integer>
wagonsNeeded
A mapping of contiguity number to number of wagons needed in that landmass.private java.util.Map<UnitType,java.util.List<WorkerWish>>
workerWishes
A 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.TradeStatus
acceptDiplomaticTrade(DiplomaticTrade agreement)
Resolves a diplomatic trade offer.boolean
acceptMercenaries()
Decides to accept an offer of mercenaries or not.boolean
acceptTax(int tax)
Decides to accept a tax raise or not.int
adjustMission(AIUnit aiUnit, PathNode path, java.lang.Class type, int value)
Adjusts the score of this proposed mission for this player type.void
allocateTransportables(java.util.List<TransportableAIObject> transportables, java.util.List<TransportMission> missions, LogBuilder lb)
Assign transportable units and goods to available carriers.private void
bringGifts(LogBuilder lb)
Brings gifts to nice players with nearby colonies.private int
buildersNeeded()
Gets the number of units that should build a colony.void
buildTipMap(LogBuilder lb)
Rebuilds a map of locations to TileImprovementPlans.private void
buildTransportMaps(LogBuilder lb)
Rebuild the transport maps.private void
buildWishMaps(LogBuilder lb)
Rebuilds the goods and worker wishes maps.private void
changeNeedWagon(Tile tile, int amount)
Changes the needed wagons map for a specified tile/contiguity.private void
cheat(LogBuilder lb)
Cheats for the AI.void
cheatGold(int amount, LogBuilder lb)
Cheat by adding gold to guarantee the player has a minimum amount.private AIUnit
cheatUnit(java.util.List<RandomChoice<UnitType>> rc, java.lang.String what, LogBuilder lb)
Cheat-build a unit in Europe.private AIUnit
cheatUnit(UnitType unitType, java.lang.String what, LogBuilder lb)
Cheat-build a unit in Europe.private boolean
checkTransport(TransportableAIObject t)
Checks that the carrier assigned to a transportable is has a transport mission and the transport is queued thereon.boolean
claimTransportable(TransportableAIObject t)
Allows a TransportMission to signal that it has taken responsibility for a TransportableAIObject.void
completeWish(Wish w)
Notify that a wish has been completed.private void
consumeGoodsWish(AIGoods aig, GoodsWish gw)
Consume a GoodsWish.private void
consumeWorkerWish(AIUnit aiUnit, WorkerWish ww)
Consume a WorkerWish, yielding a WishRealizationMission for a unit.private void
demandTribute(LogBuilder lb)
Demands goods from players with nearby colonies.protected Stance
determineStance(Player other)
Standard stance change determination.private void
determineStances(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.GoodsWish
getBestGoodsWish(AIUnit aiUnit, GoodsType goodsType)
Gets the best goods wish for a carrier unit.TileImprovementPlan
getBestPlan(Tile tile)
Gets the best plan for a tile from the tipMap.Tile
getBestPlanTile(Colony colony)
Gets the best plan for a colony from the tipMap.private WorkerWish
getBestWorkerWish(AIUnit aiUnit, UnitType unitType)
Gets the best worker wish for a carrier unit.private Mission
getBuildColonyMission(AIUnit aiUnit, Location target)
Gets a new BuildColonyMission for a unit.private Mission
getCashInTreasureTrainMission(AIUnit aiUnit)
Gets a new CashInTreasureTrainMission for a unit.private Mission
getDefendSettlementMission(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.Mission
getMissionaryMission(AIUnit aiUnit)
Gets a new MissionaryMission for a unit.protected NationSummary
getNationSummary(Player other)
Get a nation summary for another player.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.int
getNeededWagons(Tile tile)
Gets the needed wagons for a tile/contiguity.Mission
getPioneeringMission(AIUnit aiUnit, Location target)
Gets a new PioneeringMission for a unit.Mission
getPrivateerMission(AIUnit aiUnit, Location target)
Gets a new PrivateerMission for a unit.Mission
getScoutingMission(AIUnit aiUnit)
Gets a new ScoutingMission for a unit.private Mission
getSimpleMission(AIUnit aiUnit)
Choose a mission for an AIUnit.protected double
getStrengthRatio(Player other)
Get the land force strength ratio of this player with respect to another.Mission
getTransportMission(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 Mission
getWishRealizationMission(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.Mission
getWorkInsideColonyMission(AIUnit aiUnit, AIColony aiColony)
Gets a WorkInsideColonyMission for a unit.protected void
giveNormalMissions(LogBuilder lb)
Ensures all units have a mission.NativeTrade.NativeTradeAction
handleTrade(NativeTrade.NativeTradeAction action, NativeTrade nt)
Handle a native trade request.Constants.IndianDemandAction
indianDemand(Unit unit, Colony colony, GoodsType goods, int gold, Constants.IndianDemandAction accept)
Decide whether to accept an Indian demand, or not.private static void
initializeFromSpecification(Specification spec)
Initialize the static fields that would be final but for needing the specification.private void
initializeMissions(LogBuilder lb)
Simple initialization of AI missions given that we know the starting conditions.private boolean
peaceHolds(Player p)
See if a recent peace treaty still has force.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.private void
rearrangeColonies(LogBuilder lb)
Rearrange colonies.private AIUnit
recruitAIUnitInEurope(int slot)
Asks the server to recruit a unit in Europe on behalf of the AIPlayer.private DiplomaticTrade.TradeStatus
rejectAgreement(TradeItem stance, DiplomaticTrade agreement)
Reject a trade agreement, except if a Franklin-derived stance is supplied.private void
removeAIColony(AIColony aic)
Remove one of our colonies.void
removeAIObject(AIObject ao)
Remove one of our owned objects.void
removeTileImprovementPlan(TileImprovementPlan plan)
Remove aTileImprovementPlan
from the relevant colony.private boolean
requestsTransport(TransportableAIObject t)
Checks if a transportable needs transport.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.FoundingFather
selectFoundingFather(java.util.List<FoundingFather> ffs)
Selects the most useful founding father offered.void
startWorking()
Tells thisAIPlayer
to make decisions.private void
suppressEuropeanTrade(GoodsType type, LogBuilder lb)
Suppress European trade in a goods type.private AIUnit
trainAIUnitInEurope(UnitType unitType)
Helper function for server communication - Ask the server to train a unit in Europe on behalf of the AIGetPlayer().private void
updateTipMap(AIColony aic)
Update the tip map with tips from a new colony.void
updateTransport(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 newBuildColonyMission
s to create.
-
nPioneers
private int nPioneers
Current estimate of the number of newPioneeringMission
s to create.
-
nScouts
private int nScouts
Current estimate of the number of newScoutingMission
s 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:
removeAIObject
in classMissionAIPlayer
- Parameters:
ao
- TheAIObject
to remove.
-
removeAIColony
private void removeAIColony(AIColony aic)
Remove one of our colonies.- Parameters:
aic
- TheAIColony
to remove.
-
initializeFromSpecification
private static void initializeFromSpecification(Specification spec)
Initialize the static fields that would be final but for needing the specification.- Parameters:
spec
- TheSpecification
to initialize from.
-
getBadlyDefended
protected java.util.List<AIColony> getBadlyDefended()
Get the list of badly defended colonies.- Returns:
- A list of
AIColony
s 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
- ALogBuilder
to 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
- ALogBuilder
to 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
- ALogBuilder
to 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
- ALogBuilder
to log to.- Returns:
- The
AIUnit
built.
-
cheatUnit
private AIUnit cheatUnit(UnitType unitType, java.lang.String what, LogBuilder lb)
Cheat-build a unit in Europe.- Parameters:
unitType
- TheUnitType
to build.what
- A description of the unit.lb
- ALogBuilder
to log to.- Returns:
- The
AIUnit
built.
-
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 ofTransportableAIObject
s to allocated transport for.missions
- A list ofTransportMission
s to potentially assign more transportables to.lb
- ALogBuilder
to 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
- ALogBuilder
to log to.
-
demandTribute
private void demandTribute(LogBuilder lb)
Demands goods from players with nearby colonies. FIXME: European players can also demand tribute!- Parameters:
lb
- ALogBuilder
to 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
- ALogBuilder
to 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
- TheTile
to 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
- TheColony
to check.- Returns:
- The tile with the best plan for a colony, or null if none found.
-
removeTileImprovementPlan
public void removeTileImprovementPlan(TileImprovementPlan plan)
Remove aTileImprovementPlan
from the relevant colony.- Parameters:
plan
- TheTileImprovementPlan
to 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
- TheAIUnit
to check.oldTarget
- The old targetLocation
.lb
- ALogBuilder
to log to.
-
requestsTransport
private boolean requestsTransport(TransportableAIObject t)
Checks if a transportable needs transport.- Parameters:
t
- TheTransportableAIObject
to 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
- TheTransportableAIObject
to 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
- TheTile
to 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
- ALogBuilder
to 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
- TheTransportableAIObject
being claimed.- Returns:
- True if the transportable was claimed from the supply map.
-
rearrangeColonies
private void rearrangeColonies(LogBuilder lb)
Rearrange colonies.- Parameters:
lb
- ALogBuilder
to 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
- TheGoodsType
to suppress.lb
- ALogBuilder
to 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
- TheLocation
to look for wishes at.type
- TheUnitType
to look for.- Returns:
- A list of
WorkerWish
es.
-
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
- TheLocation
to look for wishes at.type
- TheGoodsType
to look for.- Returns:
- A list of
GoodsWish
es.
-
getBestWorkerWish
private WorkerWish getBestWorkerWish(AIUnit aiUnit, UnitType unitType)
Gets the best worker wish for a carrier unit.- Parameters:
aiUnit
- The carrierAIUnit
.unitType
- TheUnitType
to 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
- TheGoodsType
to wish for.- Returns:
- The best
GoodsWish
for the unit.
-
buildWishMaps
private void buildWishMaps(LogBuilder lb)
Rebuilds the goods and worker wishes maps.- Parameters:
lb
- ALogBuilder
to log to.
-
consumeWorkerWish
private void consumeWorkerWish(AIUnit aiUnit, WorkerWish ww)
Consume a WorkerWish, yielding a WishRealizationMission for a unit.- Parameters:
aiUnit
- TheAIUnit
to check.ww
- TheWorkerWish
to consume.
-
consumeGoodsWish
private void consumeGoodsWish(AIGoods aig, GoodsWish gw)
Consume a GoodsWish.- Parameters:
aig
- TheAIGoods
to use.gw
- TheGoodsWish
to 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
- TheUnitType
to 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
- ALogBuilder
to log to.
-
peaceHolds
private boolean peaceHolds(Player p)
See if a recent peace treaty still has force.- Parameters:
p
- ThePlayer
to 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 otherPlayer
to get the summary for.- Returns:
- The current
NationSummary
for 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
- TheDiplomaticTrade
to reset.- Returns:
- The
TradeStatus
for the agreement.
-
giveNormalMissions
protected void giveNormalMissions(LogBuilder lb)
Ensures all units have a mission.- Parameters:
lb
- ALogBuilder
to log to.
-
getSimpleMission
private Mission getSimpleMission(AIUnit aiUnit)
Choose a mission for an AIUnit.- Parameters:
aiUnit
- TheAIUnit
to 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
- TheAIUnit
to 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
- TheAIUnit
to 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
- TheAIUnit
to 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
- TheAIUnit
to 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
- TheAIUnit
to 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
- TheAIUnit
to 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
- TheAIUnit
to check.- Returns:
- A new mission, or null if impossible.
-
getTransportMission
public Mission getTransportMission(AIUnit aiUnit)
Gets a new TransportMission for a unit.- Parameters:
aiUnit
- TheAIUnit
to 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
- TheAIUnit
to check.wish
- An optionalWorkerWish
to 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
- TheAIUnit
to check.aiColony
- An optionalAIColony
to work at.- Returns:
- A new mission, or null if impossible.
-
determineStance
protected Stance determineStance(Player other)
Standard stance change determination.- Overrides:
determineStance
in classAIPlayer
- Parameters:
other
- ThePlayer
wrt consider stance.- Returns:
- The new
Stance
.
-
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
-
doMissions
protected java.util.List<AIUnit> doMissions(java.util.List<AIUnit> aiUnits, LogBuilder lb)
Makes every unit perform their mission.- Overrides:
doMissions
in classMissionAIPlayer
- 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 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.
-
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:
indianDemand
in classAIPlayer
- Parameters:
unit
- TheUnit
making demands.colony
- TheColony
where demands are being made.goods
- TheGoodsType
demanded.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:
acceptDiplomaticTrade
in classAIPlayer
- Parameters:
agreement
- The proposedDiplomaticTrade
.- Returns:
- The
TradeStatus
to apply to the agreement.
-
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.
-
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:
acceptMercenaries
in 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:
selectFoundingFather
in 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:
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.
-
-