Class CityProductionAndConsumptionService
- java.lang.Object
-
- ch.sahits.game.openpatrician.clientserverinterface.service.CityProductionAndConsumptionService
-
@Component @Lazy @DependentInitialisation(MapInitializedBean.class) public class CityProductionAndConsumptionService extends java.lang.Object
- Author:
- Andi Hotz, (c) Sahits GmbH, 2016 Created on May 15, 2016
-
-
Field Summary
Fields Modifier and Type Field Description private CityProductionStorage
cityProductionStorage
private CityProperties
cityProperties
private PopulationConsume
consume
Provider for the consume numbersprivate IMap
map
private ProductionChain
productionChain
private java.util.Random
rnd
-
Constructor Summary
Constructors Constructor Description CityProductionAndConsumptionService()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description (package private) void
buyWaresForNextWeek(ICity city)
Buy wares that are needed for production for the next week and move them into theProductionStorage
of the city.java.util.Map<IWare,java.lang.Double>
calculateConsumptionByProductionChain(ICity city)
private java.util.List<IWare>
collectProducableWares(ICity city)
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.private int
convertToWholeNumber(double value)
private double
getExactOutputCurrentWeek(IWare ware, ICity city)
Calculate the exact amount ofware
that is produced in the current week in the city.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.int
getTheoreticalProducableAmount(IWare ware, ICity city)
private void
init()
private boolean
isEffectiveProduction(ICity city, IWare ware)
Check if theware
can be produced efficient incity
.private boolean
isProducable(ICity city, IWare ware)
Check if the ware can be produced in the city at all.(package private) 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.private void
prepareForProductionNextWeekAndMakeAvailable(ICity city, IWare ware)
void
produceWares(CityState cityState)
Compute the wares produced in the last 12 hours and add the whole quatities to the city.
-
-
-
Field Detail
-
rnd
@Autowired private java.util.Random rnd
-
consume
@Autowired private PopulationConsume consume
Provider for the consume numbers
-
cityProductionStorage
@Autowired private CityProductionStorage cityProductionStorage
-
productionChain
@Autowired private ProductionChain productionChain
-
map
@Autowired private IMap map
-
cityProperties
@Autowired private CityProperties cityProperties
-
-
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 theProductionStorage
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 producedcity
- 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 ofware
that is produced in the current week in the city.- Parameters:
ware
- to be producedcity
- in which it is being produced.- Returns:
- exact output
-
isEffectiveProduction
private boolean isEffectiveProduction(ICity city, IWare ware)
Check if theware
can be produced efficient incity
.- Parameters:
city
- to be checkedware
- to be checked- Returns:
- true if
city
can produceware
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 checkedware
- to be checked- Returns:
- true if the
city
can produceware
.
-
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.
-
-