Class CityState
- java.lang.Object
-
- ch.sahits.game.openpatrician.model.city.impl.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 Summary
Fields Modifier and Type Field Description private IBuildingProduction
buildingProduction
private ICity
city
Reference to the city model that is driven by this engineprivate javafx.beans.property.ObjectProperty<ECityState>
cityState
private CityWall
cityWall
private PopulationConsume
consume
Provider for the consume numbersprivate java.util.Map<IWare,java.lang.Double>
consumed
Map of consumed wares, since only whole units can be consumed we need to store the fractionsprivate Date
date
private javafx.beans.binding.BooleanBinding
famine
private static org.slf4j.Logger
LOGGER
private javafx.beans.binding.ObjectBinding<IWare>
longestMissingWare
private java.util.Map<IWare,java.time.LocalDateTime>
longestMissingWares
private PopulationUpdateStats
popUpdateStatistic
private DependentPropertyInitializer
propertyInitializer
private java.util.Random
rnd
private IShipyard
shipyardState
Ship yard state fos the cityprivate double
surplusThreshold
private TavernState
tavernState
Tavern state for this cityprivate com.google.common.eventbus.AsyncEventBus
timerEventBus
-
Constructor Summary
Constructors Constructor Description CityState(ICity city, IShipyard shipard, TavernState tavern)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description javafx.beans.property.ObjectProperty<ECityState>
cityEventProperty()
Property holding the corrent city event, may be null.java.util.Set<java.util.Map.Entry<IWare,java.lang.Double>>
consumedEntries()
Get the consumed entries as a set.void
dailyUpdate(ClockTickPostDayChange dayChange)
Update the missing wares.javafx.beans.binding.BooleanBinding
famineBinding()
Binding indicating if there is a famine.java.util.Optional<IWare>
findMostNeededWare()
Find the ware which is consumed the most and which is missing for the longest time.java.util.Optional<IWare>
findWareWithMostSurplus()
Find the ware that the city sells near the minimal price.double
getConsumedAmount(EWare ware)
Retrieve the amount that is consumed so far.private IWare
getLongestMissingWares()
Retrieve the ware that is missing the longest.(package private) java.util.Map<IWare,java.lang.Integer>
getSortedWareAvailabilityMap()
Find the wares and order them in the amount of their availability.private void
initCity()
private boolean
isFamine()
Check if there is a famine.javafx.beans.binding.ObjectBinding<IWare>
longestMissingWaresBinding()
Retrieve the ware that is missing the longest.void
replaceConsumedAmount(IWare ware, double amount)
Set the amount of the ware that is consumed.
-
-
-
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
-
buildingProduction
@Autowired private IBuildingProduction buildingProduction
-
propertyInitializer
@Autowired private DependentPropertyInitializer propertyInitializer
-
cityWall
@Autowired private CityWall cityWall
-
popUpdateStatistic
@Autowired private PopulationUpdateStats popUpdateStatistic
-
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
-
-
Constructor Detail
-
CityState
public CityState(ICity city, IShipyard shipard, TavernState tavern)
-
-
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 consumedamount
- 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.
-
-