Class BasePlayerTradeStrategy
- java.lang.Object
-
- ch.sahits.game.openpatrician.engine.player.strategy.BasePlayerTradeStrategy
-
- All Implemented Interfaces:
ch.sahits.game.openpatrician.model.player.IAITradeStrategy
- Direct Known Subclasses:
CentralStorageDeliveryTradeStrategy,CheapProductionTradeStrategy,CollectionWaresStrategy,DynamicTradeRouteStrategy,ProductionChainTradeStrategy,SupplyCentralTradingStationAIStrategy,SupplyHometownAIStrategy,TradeRouteTradeStrategy
public abstract class BasePlayerTradeStrategy extends java.lang.Object implements ch.sahits.game.openpatrician.model.player.IAITradeStrategyBase implementation of the trading strategy. The base strategy maintains a list of TradeSteps, that are executed in order. Once the list is empty the next steps need to be defined. It might be that the last executed step complets a trade cycle and the next step would be the repetition of the first.
-
-
Field Summary
Fields Modifier and Type Field Description protected ch.sahits.game.openpatrician.model.player.IAITradeStrategyTypetradeStrategyType
-
Constructor Summary
Constructors Constructor Description BasePlayerTradeStrategy()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidaddDefaultTradeSteps(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.city.ICity city, ch.sahits.game.openpatrician.model.city.ICity nextStop, java.util.Set<ch.sahits.game.openpatrician.model.product.IWare> nonSellableWares, java.util.Set<ch.sahits.game.openpatrician.model.product.IWare> buyWares, boolean skipRepair)Add default trading steps: AggregatesSellTradeStep PayBackLoanTradeStep CheckHireCaptainTradeStep GuildJoinTradeStep HireDismissTradeManagerTradeStep TakeLoanTradeStep HireDismissTradeManagerTradeStep BuyWeaponTradeStep TransferToShipTradeStep (optional) CheckForRepairTradeStep HireSailorsStep TravelToTradeStepvoidappend(ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.product.ITradeStep step)Add a new trade step for a player.protected AggregatedBuyTradeStepcreateAggregatedBuyTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, java.util.List<ch.sahits.game.openpatrician.model.product.IWare> waresToBuy)protected AggregatedCheckedBuyTradeStepcreateAggregatedCheckedBuyTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, java.util.List<ch.sahits.game.openpatrician.model.product.IWare> waresToBuy)protected AggregatesCheckedSellTradeStepcreateAggregatedCheckedSellStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, java.util.Map<ch.sahits.game.openpatrician.model.product.IWare,java.lang.Integer> waresToSell)protected AggregatesDumpTradeStepcreateAggregatedDumpStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, java.util.List<ch.sahits.game.openpatrician.model.product.IWare> waresToSell)protected AggregatesSellTradeStepcreateAggregatedSellStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, java.util.List<ch.sahits.game.openpatrician.model.product.IWare> waresToSell)protected TakeLoanTradeStepcreateCheckAndTakeLoanStep(ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.city.ICity city)Create a new instance of the TakeLoan trade step.protected CheckedTransferToOfficeTradeStepcreateCheckedTransferToOfficeTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, java.util.Map<ch.sahits.game.openpatrician.model.product.IWare,java.lang.Integer> transferAmounts)protected CheckForRepairTradeStepcreateCheckRepairStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city)Create the trade step to check for repairs.protected AmountBasedAggregatedDumpTradeStepcreateConditionalAggregatedDumpStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, java.util.List<ch.sahits.game.openpatrician.model.product.IWare> waresToSell, int maxAmount)Create a conditional dump trade step.protected CheckHireCaptainTradeStepcreateHireCaptain(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, ch.sahits.game.openpatrician.model.IAIPlayer player)Create the trade step to check and hire a captain.protected HireDismissTradeManagerTradeStepcreateHireDismissTradeManagerTradeStep(ch.sahits.game.openpatrician.model.city.ICity city, ch.sahits.game.openpatrician.model.IAIPlayer player)protected HireSailorsStepcreateHireSailorStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city)Create a new instance forthe hire sailor step.protected GuildJoinTradeStepcreateJoinGuildTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, ch.sahits.game.openpatrician.model.IAIPlayer player)Create a trade step to join the quild.protected PayBackLoanTradeStepcreatePaybackLoanStep(ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.city.ICity city)Create a new instance of the TakeLoan trade step.protected TransferToOfficeTradeStepcreateTransferToOfficeTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city)protected TransferToShipTradeStepcreateTransferToShipTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, java.util.Map<ch.sahits.game.openpatrician.model.product.IWare,java.lang.Integer> transfereableAmounts)protected TravelToTradeStepcreateTravelToStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity travelToCity)Create the travel step to a different city.protected UpgradeShipTradeStepcreateUpgradeShipTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.IAIPlayer player)protected BuyWeaponTradeStepcreateWeaponBuyTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.city.ICity city)booleanexecuteTradeSteps(ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)The implementation of the execute trade steps makes the following assumptions: When called there is at least one trade step defined Typically the trade steps are defined up to the travel step.protected ch.sahits.game.openpatrician.model.city.ICityfindDestinationToBuyRequiredProductionWares(ch.sahits.game.openpatrician.model.IAIPlayer player, java.util.List<ch.sahits.game.openpatrician.model.product.IWare> requiredWares, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, java.util.Set<ch.sahits.game.openpatrician.model.city.ICity> excludeCity)Determine the city to travel to based on the required wares.protected ch.sahits.game.openpatrician.model.city.ICityfindNextStopForBuying(ch.sahits.game.openpatrician.model.city.ICity baseTown, ch.sahits.game.openpatrician.model.player.IProductionConsumptionKnowledge knowledge, java.util.List<ch.sahits.game.openpatrician.model.product.IWare> waresOfInterest, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity exclude)Figure out what the next stop should be to supply the ware in the listwaresOfInterest.protected ch.sahits.game.openpatrician.model.city.ICityfindNextStopForSelling(ch.sahits.game.openpatrician.model.city.ICity baseTown, ch.sahits.game.openpatrician.model.player.IProductionConsumptionKnowledge knowledge, java.util.List<ch.sahits.game.openpatrician.model.product.IWare> waresOfInterest, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity exclude)Figure out what the next stop should be to sell the ware in the listwaresOfInterest.protected ch.sahits.game.openpatrician.model.city.ICityfindProvidingWares(ch.sahits.game.openpatrician.model.city.ICity source, java.util.Collection<ch.sahits.game.openpatrician.model.product.IWare> wares, java.util.Collection<ch.sahits.game.openpatrician.model.city.ICity> excluded, ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)Find the city that provides the best match for supplying thewareswhile not being too far away.protected java.util.ArrayList<ch.sahits.game.openpatrician.model.product.IWare>findWaresOfInterest(java.util.List<javafx.util.Pair<ch.sahits.game.openpatrician.model.product.IWare,java.lang.Number>> sortedNeeds)ch.sahits.game.openpatrician.model.city.ICitygetCityToRestartTradeCycle(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)
The default implementation chooses the closest city.protected java.util.List<ch.sahits.game.openpatrician.model.product.IWare>getLoadedWares(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)Find all wares that are loaded on the ship.java.util.List<javafx.util.Pair<ch.sahits.game.openpatrician.model.product.IWare,java.lang.Number>>getMostNeededWares(ch.sahits.game.openpatrician.model.player.ICityProductionConsumptionKnowledge knowledge)Figure out the ware that are most needed in the city.java.util.List<javafx.util.Pair<ch.sahits.game.openpatrician.model.product.IWare,java.lang.Number>>getMostNeededWares(ch.sahits.game.openpatrician.model.player.ICityProductionConsumptionKnowledge knowledge, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)Figure out the ware that are most needed in the city.ch.sahits.game.openpatrician.model.product.ITradeStepgetNextStep(ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)Retrieve the next trade step that should be executed and remove it from the list of an AI player.protected java.util.List<ch.sahits.game.openpatrician.model.product.IWare>getWaresNeedIn(ch.sahits.game.openpatrician.model.player.IProductionConsumptionKnowledge knowledge, ch.sahits.game.openpatrician.model.player.ICityProductionConsumptionKnowledge knowledgeCurrentTown, ch.sahits.game.openpatrician.model.city.ICity nextStop)Figure out what wares are needed innextStop, that can be provided in the current town.voidhandleHireSailors(ch.sahits.game.openpatrician.event.data.ai.HireSailorEvent event)Andling the hiring of sailors.voidhandleRefitFinished(ch.sahits.game.openpatrician.event.data.RefitFinishedEvent event)Handle the event of the ship coming back from repair and the trade steps have to be picked up again.voidhandleRepairFinished(ch.sahits.game.openpatrician.event.data.RepairFinishedEvent event)Handle the event of the ship coming back from repair and the trade steps have to be picked up again.protected booleanhasBlockingMission(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.IAIPlayer player)Check if there is a blocking mission that would prevent taking further action.booleanhasMoreTradeSteps(ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)Check whether the AI player has more trade stepsvoidinject(ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.product.ITradeStep step)Add a new trade step to the begining of the list.protected booleanisMatchingTradeStrategy(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)Check if the strategy belongs to the vessel.booleanisNeeded(ch.sahits.game.openpatrician.model.player.ICityProductionConsumptionKnowledge knowledge, ch.sahits.game.openpatrician.model.product.IWare ware)Check if thewareis needed in a city.
-
-
-
Method Detail
-
isMatchingTradeStrategy
protected boolean isMatchingTradeStrategy(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)
Check if the strategy belongs to the vessel.
-
hasBlockingMission
protected boolean hasBlockingMission(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.IAIPlayer player)Check if there is a blocking mission that would prevent taking further action.
-
getCityToRestartTradeCycle
public ch.sahits.game.openpatrician.model.city.ICity getCityToRestartTradeCycle(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)
The default implementation chooses the closest city.- Specified by:
getCityToRestartTradeCyclein interfacech.sahits.game.openpatrician.model.player.IAITradeStrategy- Parameters:
vessel- that should travel to a city, so that the trade cycle can be reinitialized- Returns:
-
getNextStep
public ch.sahits.game.openpatrician.model.product.ITradeStep getNextStep(ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)Retrieve the next trade step that should be executed and remove it from the list of an AI player.- Parameters:
player- on witch to retrieve the next task- Returns:
- next trade step for the player with the vessel
-
hasMoreTradeSteps
public boolean hasMoreTradeSteps(ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)Check whether the AI player has more trade steps- Parameters:
player- on which to check- Returns:
- true if there are more tradesteps for the player with the vessel
-
append
public void append(ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.product.ITradeStep step)Add a new trade step for a player.- Parameters:
player- for which to add the trade stepstep- to be added.
-
inject
public void inject(ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.product.ITradeStep step)Add a new trade step to the begining of the list.- Parameters:
player- for which to add the trade stepstep- to be added.vessel- for which the trade step is to be injected.
-
getMostNeededWares
public java.util.List<javafx.util.Pair<ch.sahits.game.openpatrician.model.product.IWare,java.lang.Number>> getMostNeededWares(ch.sahits.game.openpatrician.model.player.ICityProductionConsumptionKnowledge knowledge)
Figure out the ware that are most needed in the city. The need is calculated upon the knowledge of the production, consumption and sotred amount. If a ware is not consumed at all it is not needed at all, compared to wares that have more consumption than stored + produced.- Parameters:
knowledge- base knowledge- Returns:
- sorted list Pair of wares and their importants. The lower the number the more important.
-
isNeeded
public boolean isNeeded(ch.sahits.game.openpatrician.model.player.ICityProductionConsumptionKnowledge knowledge, ch.sahits.game.openpatrician.model.product.IWare ware)Check if thewareis needed in a city.- Parameters:
knowledge- of the city that should be checked.ware- for which should be checked.- Returns:
- true if there is not much of the ware around.
-
getMostNeededWares
public java.util.List<javafx.util.Pair<ch.sahits.game.openpatrician.model.product.IWare,java.lang.Number>> getMostNeededWares(ch.sahits.game.openpatrician.model.player.ICityProductionConsumptionKnowledge knowledge, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)Figure out the ware that are most needed in the city. The need is calculated upon the knowledge of the production, consumption and sotred amount. If a ware is not consumed at all it is not needed at all, compared to wares that have more consumption than stored + produced. Also consider the amount of that ware that is loaded on thevessel. That ware is treated the same way as if it stored in the city, with the effect that on the first call the most needed ware might be BEER, but once an amount is bought the most needed ware might change.- Parameters:
knowledge- base knowledgevessel- on which the wares are loaded.- Returns:
- sorted list Pair of wares and their importants. The lower the number the more important.
-
getWaresNeedIn
protected java.util.List<ch.sahits.game.openpatrician.model.product.IWare> getWaresNeedIn(ch.sahits.game.openpatrician.model.player.IProductionConsumptionKnowledge knowledge, ch.sahits.game.openpatrician.model.player.ICityProductionConsumptionKnowledge knowledgeCurrentTown, ch.sahits.game.openpatrician.model.city.ICity nextStop)Figure out what wares are needed innextStop, that can be provided in the current town.- Parameters:
knowledge- base knowledgeknowledgeCurrentTown- knowledge of the current townnextStop- stop of the next city.- Returns:
- list of wares that can be delivered from the current city to the
nextStop
-
findNextStopForBuying
protected ch.sahits.game.openpatrician.model.city.ICity findNextStopForBuying(ch.sahits.game.openpatrician.model.city.ICity baseTown, ch.sahits.game.openpatrician.model.player.IProductionConsumptionKnowledge knowledge, java.util.List<ch.sahits.game.openpatrician.model.product.IWare> waresOfInterest, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity exclude)Figure out what the next stop should be to supply the ware in the listwaresOfInterest. This list is ordered so that wares in the front are more important. The next stop is determined by the list ofwaresOfInterestthat should be produced.- Parameters:
baseTown- city from which the travel startsknowledge- datawaresOfInterest- ordered list of needed waresexclude- city to which should not be traveled.- Returns:
- City that can provide at least some of the wares and is not to far away.
-
findNextStopForSelling
protected ch.sahits.game.openpatrician.model.city.ICity findNextStopForSelling(ch.sahits.game.openpatrician.model.city.ICity baseTown, ch.sahits.game.openpatrician.model.player.IProductionConsumptionKnowledge knowledge, java.util.List<ch.sahits.game.openpatrician.model.product.IWare> waresOfInterest, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity exclude)Figure out what the next stop should be to sell the ware in the listwaresOfInterest. The next stop is determined by thelist ofwaresOfInterestthat should be consumed.- Parameters:
baseTown- city from which the travel startsknowledge- datawaresOfInterest- list of needed waresexclude- city to which should not be traveled.- Returns:
- City that can provide at least some of the wares and is not to far away.
-
createTravelToStep
protected TravelToTradeStep createTravelToStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity travelToCity)
Create the travel step to a different city.- Parameters:
vessel- that is travellingtravelToCity- destination city- Returns:
- TravelToTradeStep
-
createCheckRepairStep
protected CheckForRepairTradeStep createCheckRepairStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city)
Create the trade step to check for repairs.- Parameters:
vessel- that should be checked.city- in which should be checked.- Returns:
- CheckForRepairTradeStep
-
createHireSailorStep
protected HireSailorsStep createHireSailorStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city)
Create a new instance forthe hire sailor step.- Parameters:
vessel- for which the sailors are hiredcity- in which the sailors are to be hired- Returns:
- trade step to hire silors
-
createCheckAndTakeLoanStep
protected TakeLoanTradeStep createCheckAndTakeLoanStep(ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.city.ICity city)
Create a new instance of the TakeLoan trade step.- Parameters:
player- that takes a loancity- in which the loan is taken- Returns:
- trade step to take a loan
-
createPaybackLoanStep
protected PayBackLoanTradeStep createPaybackLoanStep(ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.city.ICity city)
Create a new instance of the TakeLoan trade step.- Parameters:
player- that takes a loancity- in which the loan is taken- Returns:
- trade step to pay back a loan
-
createAggregatedBuyTradeStep
protected AggregatedBuyTradeStep createAggregatedBuyTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, java.util.List<ch.sahits.game.openpatrician.model.product.IWare> waresToBuy)
-
createAggregatedCheckedBuyTradeStep
protected AggregatedCheckedBuyTradeStep createAggregatedCheckedBuyTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, java.util.List<ch.sahits.game.openpatrician.model.product.IWare> waresToBuy)
-
createAggregatedSellStep
protected AggregatesSellTradeStep createAggregatedSellStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, java.util.List<ch.sahits.game.openpatrician.model.product.IWare> waresToSell)
-
createAggregatedCheckedSellStep
protected AggregatesCheckedSellTradeStep createAggregatedCheckedSellStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, java.util.Map<ch.sahits.game.openpatrician.model.product.IWare,java.lang.Integer> waresToSell)
-
createAggregatedDumpStep
protected AggregatesDumpTradeStep createAggregatedDumpStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, java.util.List<ch.sahits.game.openpatrician.model.product.IWare> waresToSell)
-
createConditionalAggregatedDumpStep
protected AmountBasedAggregatedDumpTradeStep createConditionalAggregatedDumpStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, java.util.List<ch.sahits.game.openpatrician.model.product.IWare> waresToSell, int maxAmount)
Create a conditional dump trade step. All wares are sold if the ships load is greater than themaxAmount.- Parameters:
vessel- in the trade stepcity- where the trade step happenswaresToSell- list of wares that should be soldmaxAmount- max amount of wares that should be on the ship- Returns:
- dump sell trade step
-
createHireCaptain
protected CheckHireCaptainTradeStep createHireCaptain(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, ch.sahits.game.openpatrician.model.IAIPlayer player)
Create the trade step to check and hire a captain.- Parameters:
vessel- for on wich the captain is hiredcity- in which the captain is hiredplayer- who hires the captain- Returns:
- trade step hiring the captain
-
createJoinGuildTradeStep
protected GuildJoinTradeStep createJoinGuildTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, ch.sahits.game.openpatrician.model.IAIPlayer player)
Create a trade step to join the quild.- Parameters:
vessel- for which the trade step is addedcity- in which the guild is locatedplayer- wishing to join the guild- Returns:
- trade step to join the guild
-
createHireDismissTradeManagerTradeStep
protected HireDismissTradeManagerTradeStep createHireDismissTradeManagerTradeStep(ch.sahits.game.openpatrician.model.city.ICity city, ch.sahits.game.openpatrician.model.IAIPlayer player)
-
createWeaponBuyTradeStep
protected BuyWeaponTradeStep createWeaponBuyTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.city.ICity city)
-
createTransferToOfficeTradeStep
protected TransferToOfficeTradeStep createTransferToOfficeTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city)
-
createCheckedTransferToOfficeTradeStep
protected CheckedTransferToOfficeTradeStep createCheckedTransferToOfficeTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, java.util.Map<ch.sahits.game.openpatrician.model.product.IWare,java.lang.Integer> transferAmounts)
-
createTransferToShipTradeStep
protected TransferToShipTradeStep createTransferToShipTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city, java.util.Map<ch.sahits.game.openpatrician.model.product.IWare,java.lang.Integer> transfereableAmounts)
-
createUpgradeShipTradeStep
protected UpgradeShipTradeStep createUpgradeShipTradeStep(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.IAIPlayer player)
-
executeTradeSteps
public boolean executeTradeSteps(ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)The implementation of the execute trade steps makes the following assumptions:- When called there is at least one trade step defined
- Specified by:
executeTradeStepsin interfacech.sahits.game.openpatrician.model.player.IAITradeStrategy- Parameters:
player- for which the trade steps are to be executedvessel- for which the trade steps are to be executed- Returns:
- true if further trade steps can be executed
-
handleRepairFinished
public void handleRepairFinished(ch.sahits.game.openpatrician.event.data.RepairFinishedEvent event)
Handle the event of the ship coming back from repair and the trade steps have to be picked up again.- Parameters:
event- ship repair has finished
-
handleRefitFinished
public void handleRefitFinished(ch.sahits.game.openpatrician.event.data.RefitFinishedEvent event)
Handle the event of the ship coming back from repair and the trade steps have to be picked up again.- Parameters:
event- ship refitting has finished.
-
handleHireSailors
public void handleHireSailors(ch.sahits.game.openpatrician.event.data.ai.HireSailorEvent event)
Andling the hiring of sailors. This event is fired when the last try to hire sailors failed to insufficient amount of sailors available.- Parameters:
event- sailors are hired
-
getLoadedWares
protected java.util.List<ch.sahits.game.openpatrician.model.product.IWare> getLoadedWares(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)
Find all wares that are loaded on the ship.- Parameters:
vessel- for which to check the wares.- Returns:
- list of loaded wares.
-
findWaresOfInterest
protected java.util.ArrayList<ch.sahits.game.openpatrician.model.product.IWare> findWaresOfInterest(java.util.List<javafx.util.Pair<ch.sahits.game.openpatrician.model.product.IWare,java.lang.Number>> sortedNeeds)
-
findDestinationToBuyRequiredProductionWares
protected ch.sahits.game.openpatrician.model.city.ICity findDestinationToBuyRequiredProductionWares(ch.sahits.game.openpatrician.model.IAIPlayer player, java.util.List<ch.sahits.game.openpatrician.model.product.IWare> requiredWares, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, java.util.Set<ch.sahits.game.openpatrician.model.city.ICity> excludeCity)Determine the city to travel to based on the required wares. If there is a city that provides all the wares it is chosen otherwise a city that provides part of the wares is returned.- Parameters:
player- for whom to find the destinationrequiredWares- list of required waresexcludeCity- origin city to which should not be traveled.- Returns:
- destination city to buy the required production wares in.
-
findProvidingWares
protected ch.sahits.game.openpatrician.model.city.ICity findProvidingWares(ch.sahits.game.openpatrician.model.city.ICity source, java.util.Collection<ch.sahits.game.openpatrician.model.product.IWare> wares, java.util.Collection<ch.sahits.game.openpatrician.model.city.ICity> excluded, ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)Find the city that provides the best match for supplying thewareswhile not being too far away. Theexcludedcities are not considered.- Parameters:
source- city on which to base distance calculation.wares- to be suppliedexcluded- cities that should be ignored.- Returns:
- best matching city.
-
addDefaultTradeSteps
protected void addDefaultTradeSteps(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.IAIPlayer player, ch.sahits.game.openpatrician.model.city.ICity city, ch.sahits.game.openpatrician.model.city.ICity nextStop, java.util.Set<ch.sahits.game.openpatrician.model.product.IWare> nonSellableWares, java.util.Set<ch.sahits.game.openpatrician.model.product.IWare> buyWares, boolean skipRepair)Add default trading steps:- AggregatesSellTradeStep
- PayBackLoanTradeStep
- CheckHireCaptainTradeStep
- GuildJoinTradeStep
- HireDismissTradeManagerTradeStep
- TakeLoanTradeStep
- HireDismissTradeManagerTradeStep
- BuyWeaponTradeStep
- TransferToShipTradeStep (optional)
- CheckForRepairTradeStep
- HireSailorsStep
- TravelToTradeStep
- Parameters:
vessel- doing the tradeplayer- owner of the vesselcity- current citynextStop- next stopnonSellableWares- wares that cannot be soldbuyWares- wares that need to be boughtskipRepair- skip the task for repairing ships.
-
-