Class CityState


  • @Component
    @Scope("prototype")
    public class CityState
    extends java.lang.Object
    This class encapsulates state information used by CityEngine about one city. This class i player private since it should not be used by any other class than CityEngine.
    Author:
    Andi Hotz, (c) Sahits GmbH, 2011 Created on Nov 29, 2011
    • Field Detail

      • LOGGER

        private static final org.slf4j.Logger LOGGER
      • rnd

        @Autowired
        private java.util.Random rnd
      • surplusThreshold

        @DependentValue("ware.surplus.treshold")
        private double surplusThreshold
      • city

        private ICity city
        Reference to the city model that is driven by this engine
      • consumed

        private java.util.Map<IWare,​java.lang.Double> consumed
        Map of consumed wares, since only whole units can be consumed we need to store the fractions
      • tavernState

        private TavernState tavernState
        Tavern state for this city
      • shipyardState

        private IShipyard shipyardState
        Ship yard state fos the city
      • consume

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

        @Autowired
        private CityWall cityWall
      • timerEventBus

        @Autowired
        @Qualifier("timerEventBus")
        private com.google.common.eventbus.AsyncEventBus timerEventBus
      • date

        @Autowired
        private Date date
      • longestMissingWares

        private java.util.Map<IWare,​java.time.LocalDateTime> longestMissingWares
      • longestMissingWare

        private javafx.beans.binding.ObjectBinding<IWare> longestMissingWare
      • famine

        private javafx.beans.binding.BooleanBinding famine
      • cityState

        private javafx.beans.property.ObjectProperty<ECityState> cityState
    • Method Detail

      • initCity

        @PostConstruct
        private void initCity()
      • dailyUpdate

        public void dailyUpdate​(ClockTickPostDayChange dayChange)
        Update the missing wares.
        Parameters:
        dayChange - event indicating a day change
      • getLongestMissingWares

        private IWare getLongestMissingWares()
        Retrieve the ware that is missing the longest.
        Returns:
        ware that is missing the longest
      • longestMissingWaresBinding

        public javafx.beans.binding.ObjectBinding<IWare> longestMissingWaresBinding()
        Retrieve the ware that is missing the longest.
        Returns:
        ware binding for the ware missing longest
      • isFamine

        private boolean isFamine()
        Check if there is a famine. Famine happens if there is no grain for two weeks.
        Returns:
        true if there is a famine
      • famineBinding

        public javafx.beans.binding.BooleanBinding famineBinding()
        Binding indicating if there is a famine.
        Returns:
        boolean binding for the famine
      • cityEventProperty

        public javafx.beans.property.ObjectProperty<ECityState> cityEventProperty()
        Property holding the corrent city event, may be null.
        Returns:
        binding of the city event state
      • consumedEntries

        public java.util.Set<java.util.Map.Entry<IWare,​java.lang.Double>> consumedEntries()
        Get the consumed entries as a set.
        Returns:
        set of entries of wares and their consumption
      • replaceConsumedAmount

        public void replaceConsumedAmount​(IWare ware,
                                          double amount)
        Set the amount of the ware that is consumed. If there is already an amount stored for the ware it is overidden.
        Parameters:
        ware - to be consumed
        amount - to be consumed
      • getConsumedAmount

        public double getConsumedAmount​(EWare ware)
        Retrieve the amount that is consumed so far.
        Parameters:
        ware - which should be checked for consumption.
        Returns:
        consumed amount.
      • findMostNeededWare

        public java.util.Optional<IWare> findMostNeededWare()
        Find the ware which is consumed the most and which is missing for the longest time.
        Returns:
        Optional ware
      • findWareWithMostSurplus

        public java.util.Optional<IWare> findWareWithMostSurplus()
        Find the ware that the city sells near the minimal price.
        Returns:
        Optional ware
      • getSortedWareAvailabilityMap

        java.util.Map<IWare,​java.lang.Integer> getSortedWareAvailabilityMap()
        Find the wares and order them in the amount of their availability. If there is a ware with the same availability, only one is added to the map.
        Returns:
        map of wares and their amounts available in the city.