Class CityProductionAndConsumptionService

    • Field Detail

      • rnd

        @Autowired
        private java.util.Random rnd
      • consume

        @Autowired
        private PopulationConsume consume
        Provider for the consume numbers
      • map

        @Autowired
        private IMap map
    • Constructor Detail

      • CityProductionAndConsumptionService

        public CityProductionAndConsumptionService()
    • Method Detail

      • init

        @PostConstruct
        private void init()
      • produceWares

        public void produceWares​(CityState cityState)
        Compute the wares produced in the last 12 hours and add the whole quatities to the city. This method is player private for testing purposes.
        Parameters:
        cityState - city for which the wares should be produced.
      • consumeWares

        public void consumeWares​(CityState cityState)
        compute the wares consumed in the last 12 hours and remove them from the city This method is player private for testing purposes.
        Parameters:
        cityState - city for which the wares should be consumed.
      • convertToWholeNumber

        private int convertToWholeNumber​(double value)
      • buyWaresForNextWeek

        void buyWaresForNextWeek​(ICity city)
        Buy wares that are needed for production for the next week and move them into the ProductionStorage of the city.
        Parameters:
        city - for which the wares should be bought
      • calculateConsumptionByProductionChain

        public java.util.Map<IWare,​java.lang.Double> calculateConsumptionByProductionChain​(ICity city)
      • getProductionOutputCurrentWeek

        public int getProductionOutputCurrentWeek​(IWare ware,
                                                  ICity city)
        Calculate the amount of ware that is produced in the current week, based on the maximum that is producable but also on the limitation of available wares in storage.
        Parameters:
        ware - that is produced
        city - in witch the ware is produced
        Returns:
        amount of the ware that is being produced. As the exact output may not be a whole number it is always rounded down, as the rest is put in storage and added to the output in the following week
      • getExactOutputCurrentWeek

        private double getExactOutputCurrentWeek​(IWare ware,
                                                 ICity city)
        Calculate the exact amount of ware that is produced in the current week in the city.
        Parameters:
        ware - to be produced
        city - in which it is being produced.
        Returns:
        exact output
      • getTheoreticalProducableAmount

        public int getTheoreticalProducableAmount​(IWare ware,
                                                  ICity city)
      • isEffectiveProduction

        private boolean isEffectiveProduction​(ICity city,
                                              IWare ware)
        Check if the ware can be produced efficient in city.
        Parameters:
        city - to be checked
        ware - to be checked
        Returns:
        true if city can produce ware efficient
      • isProducable

        private boolean isProducable​(ICity city,
                                     IWare ware)
        Check if the ware can be produced in the city at all.
        Parameters:
        city - to be checked
        ware - to be checked
        Returns:
        true if the city can produce ware.
      • collectProducableWares

        private java.util.List<IWare> collectProducableWares​(ICity city)
      • makeProducedWaresAvailable

        void makeProducedWaresAvailable​(ICity city)
        Make the wares that have be produced in the last week available to the city and remove the used amount of raw material from the storage.
        Parameters:
        city - for which the wares should become available.
      • prepareForProductionNextWeekAndMakeAvailable

        private void prepareForProductionNextWeekAndMakeAvailable​(ICity city,
                                                                  IWare ware)