Class BasePlayerTradeStrategy

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected ch.sahits.game.openpatrician.model.player.IAITradeStrategyType tradeStrategyType  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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
      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.
      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)  
      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)  
      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)  
      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)  
      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)  
      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.
      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)  
      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.
      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.
      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.
      protected HireDismissTradeManagerTradeStep createHireDismissTradeManagerTradeStep​(ch.sahits.game.openpatrician.model.city.ICity city, ch.sahits.game.openpatrician.model.IAIPlayer player)  
      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.
      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.
      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.
      protected TransferToOfficeTradeStep createTransferToOfficeTradeStep​(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.city.ICity city)  
      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)  
      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.
      protected UpgradeShipTradeStep createUpgradeShipTradeStep​(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel, ch.sahits.game.openpatrician.model.IAIPlayer player)  
      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)  
      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 Typically the trade steps are defined up to the travel step.
      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.
      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 list waresOfInterest.
      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 list waresOfInterest.
      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 the wares while 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.ICity getCityToRestartTradeCycle​(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.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.
      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 in nextStop, that can be provided in the current town.
      void handleHireSailors​(ch.sahits.game.openpatrician.event.data.ai.HireSailorEvent event)
      Andling the hiring of sailors.
      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.
      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.
      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.
      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
      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.
      protected boolean isMatchingTradeStrategy​(ch.sahits.game.openpatrician.model.ship.INavigableVessel vessel)
      Check if the strategy belongs to the vessel.
      boolean isNeeded​(ch.sahits.game.openpatrician.model.player.ICityProductionConsumptionKnowledge knowledge, ch.sahits.game.openpatrician.model.product.IWare ware)
      Check if the ware is needed in a city.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
      • Methods inherited from interface ch.sahits.game.openpatrician.model.player.IAITradeStrategy

        handleShipArrivesInPort, initializeTradeCycle, isSelectable
    • Field Detail

      • tradeStrategyType

        protected ch.sahits.game.openpatrician.model.player.IAITradeStrategyType tradeStrategyType
    • Constructor Detail

      • BasePlayerTradeStrategy

        public BasePlayerTradeStrategy()
    • 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:
        getCityToRestartTradeCycle in interface ch.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 step
        step - 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 step
        step - 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 the ware is 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 the vessel. 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 knowledge
        vessel - 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 in nextStop, that can be provided in the current town.
        Parameters:
        knowledge - base knowledge
        knowledgeCurrentTown - knowledge of the current town
        nextStop - 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 list waresOfInterest. This list is ordered so that wares in the front are more important. The next stop is determined by the list of waresOfInterest that should be produced.
        Parameters:
        baseTown - city from which the travel starts
        knowledge - data
        waresOfInterest - ordered list of needed wares
        exclude - 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 list waresOfInterest. The next stop is determined by thelist of waresOfInterest that should be consumed.
        Parameters:
        baseTown - city from which the travel starts
        knowledge - data
        waresOfInterest - list of needed wares
        exclude - 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 travelling
        travelToCity - 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 hired
        city - 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 loan
        city - 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 loan
        city - 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 the maxAmount.
        Parameters:
        vessel - in the trade step
        city - where the trade step happens
        waresToSell - list of wares that should be sold
        maxAmount - 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 hired
        city - in which the captain is hired
        player - 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 added
        city - in which the guild is located
        player - 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
        Typically the trade steps are defined up to the travel step. When the ship then reaches the port the next steps need to be defined.
        Specified by:
        executeTradeSteps in interface ch.sahits.game.openpatrician.model.player.IAITradeStrategy
        Parameters:
        player - for which the trade steps are to be executed
        vessel - 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 destination
        requiredWares - list of required wares
        excludeCity - 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 the wares while not being too far away. The excluded cities are not considered.
        Parameters:
        source - city on which to base distance calculation.
        wares - to be supplied
        excluded - 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:
        1. AggregatesSellTradeStep
        2. PayBackLoanTradeStep
        3. CheckHireCaptainTradeStep
        4. GuildJoinTradeStep
        5. HireDismissTradeManagerTradeStep
        6. TakeLoanTradeStep
        7. HireDismissTradeManagerTradeStep
        8. BuyWeaponTradeStep
        9. TransferToShipTradeStep (optional)
        10. CheckForRepairTradeStep
        11. HireSailorsStep
        12. TravelToTradeStep
        Parameters:
        vessel - doing the trade
        player - owner of the vessel
        city - current city
        nextStop - next stop
        nonSellableWares - wares that cannot be sold
        buyWares - wares that need to be bought
        skipRepair - skip the task for repairing ships.