Class City
- java.lang.Object
-
- ch.sahits.game.openpatrician.model.impl.WareHolding
-
- ch.sahits.game.openpatrician.model.city.impl.City
-
- All Implemented Interfaces:
ICity
@Component @Scope("prototype") public class City extends WareHolding implements ICityImplementation of the city model. The model of the city should only be instanciated once. A city is unique. therefore equality can be tested by identity.- Author:
- Andi Hotz, (c) Sahits GmbH, 2011 Created on Jan 18, 2011
-
-
Field Summary
Fields Modifier and Type Field Description protected com.google.common.collect.Interner<javafx.geometry.Point2D>pointInterner-
Fields inherited from class ch.sahits.game.openpatrician.model.impl.WareHolding
computablePrice
-
-
Constructor Summary
Constructors Constructor Description City(ch.sahits.game.openpatrician.data.xmlmodel.map.Map.Cities.City city)City(FoundNewSettlement futureTown)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddBuildingPermission(IPlayer player)Add the bulidng permission for that player in the city.voidbuild(IBuilding building)Add a new building to the citybooleanequals(java.lang.Object o)<T extends IBuilding>
java.util.List<T>findBuilding(java.lang.Class<T> buildingClass, java.util.Optional<IPlayer> owner)Find all matching buildings in a city.java.util.List<IBuilding>getBuildings()Retrieve a list of all buildings in the city.intgetContribution(IPlayer player, IWare ware)Check out what the player contributed to the warejava.util.Map<IWare,java.time.LocalDateTime>getMissingWares()Retrieve the missing wares along with their timesdoublegetPercentageRoad()Retrieve the amount of road in the city.intgetPopulation(EPopulationClass popclass)Retrieve the population count for a classjavafx.beans.binding.IntegerBindinggetPopulationBinding()Retrieve the binding of the city's total population.javafx.beans.property.IntegerPropertygetPopulationProperty(EPopulationClass popclass)Retrieve the population count for a classIReputationgetReputation(IPlayer player)Retrieve the reputation of the player in the cityjava.util.List<IPlayer>getResidentPlayers()Retrieve all the players that have a office in this city.java.lang.StringgetUniqueID()Retrieve the unique ID of the city.booleanhasBuildingPermission(IPlayer player)The player has building permission in this city.inthashCode()protected voidinitWares()Init the amount of wares available in the city This method is protected so it can be overriden by subclasses for testingintmove(IWare ware, int amount, ICitizen player)Move ware into this holding.voidmoveIn(IPlayer player, IReputation reputaion, Contributions contributions)Add a player to the cityvoidsetPopulation(int population, EPopulationClass popClass)Set the population count for a apopulation classvoidtearDown(IBuilding building)Remove a building from the list of buildings in the cityjava.lang.StringtoString()-
Methods inherited from class ch.sahits.game.openpatrician.model.impl.WareHolding
addNewWare, bindStoredAmount, computeAVGPrice, containsWare, getOccupiedSpace, getWare, occupiedSpaceProperty, setOccupiedSpace, storedAmountBinding, unbindAllAmounts
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface ch.sahits.game.openpatrician.model.city.ICity
getCitizen, getCityState, getCoordinates, getEffectiveProduction, getImported, getIneffectiveProduction, getKontorType, getName, getNameTemplate, getWare, isRiverCity, setCityState
-
-
-
-
Constructor Detail
-
City
public City(ch.sahits.game.openpatrician.data.xmlmodel.map.Map.Cities.City city)
-
City
public City(FoundNewSettlement futureTown)
-
-
Method Detail
-
initWares
protected void initWares()
Init the amount of wares available in the city This method is protected so it can be overriden by subclasses for testing
-
getPopulationBinding
public javafx.beans.binding.IntegerBinding getPopulationBinding()
Description copied from interface:ICityRetrieve the binding of the city's total population.- Specified by:
getPopulationBindingin interfaceICity- Returns:
- Integer binding of the overall population.
-
setPopulation
public void setPopulation(int population, EPopulationClass popClass)Set the population count for a apopulation class- Specified by:
setPopulationin interfaceICity- Parameters:
population- countpopClass- population class
-
getPopulation
public int getPopulation(EPopulationClass popclass)
Retrieve the population count for a class- Specified by:
getPopulationin interfaceICity- Parameters:
popclass- population class- Returns:
- population count of the population class.
-
getPopulationProperty
public javafx.beans.property.IntegerProperty getPopulationProperty(EPopulationClass popclass)
Description copied from interface:ICityRetrieve the population count for a class- Specified by:
getPopulationPropertyin interfaceICity- Parameters:
popclass- population class- Returns:
- integer property for the population of a specific
popclass
-
getBuildings
public java.util.List<IBuilding> getBuildings()
Description copied from interface:ICityRetrieve a list of all buildings in the city. The list is immutable- Specified by:
getBuildingsin interfaceICity- Returns:
- list of buildings in the city.
-
build
public void build(IBuilding building)
Add a new building to the city
-
tearDown
public void tearDown(IBuilding building)
Remove a building from the list of buildings in the city
-
getReputation
public IReputation getReputation(IPlayer player)
Description copied from interface:ICityRetrieve the reputation of the player in the city- Specified by:
getReputationin interfaceICity- Parameters:
player- for whom to retrieve the reputation- Returns:
- reputation of a player
-
moveIn
public void moveIn(IPlayer player, IReputation reputaion, Contributions contributions)
Description copied from interface:ICityAdd a player to the city
-
move
public int move(IWare ware, int amount, ICitizen player)
Move ware into this holding. The player may be null and is not used in this base implementation, but subclasses may be interested for statistical reasons. This method is thread save. Update the contributions as the ware is moved- Specified by:
movein interfaceICity- Overrides:
movein classWareHolding- Parameters:
ware- to be movedamount- of the ware that is movedplayer- that initiates the moving, may be null, e.g. if the moving is initiated by a city- Returns:
- the effective amount that was moved. The amount may be positive if something was added, negative if the ware was removed from the holding or zero if nothing was moved.
-
getContribution
public int getContribution(IPlayer player, IWare ware)
Description copied from interface:ICityCheck out what the player contributed to the ware- Specified by:
getContributionin interfaceICity- Parameters:
player- whose contribution is to be checkedware- that is checked for contribution- Returns:
- amount of the contribution may also be negative
-
getMissingWares
public java.util.Map<IWare,java.time.LocalDateTime> getMissingWares()
Description copied from interface:ICityRetrieve the missing wares along with their times- Specified by:
getMissingWaresin interfaceICity- Returns:
- map of wares and since when they are missing
-
getResidentPlayers
public java.util.List<IPlayer> getResidentPlayers()
Description copied from interface:ICityRetrieve all the players that have a office in this city.- Specified by:
getResidentPlayersin interfaceICity- Returns:
- immutable list
-
getUniqueID
public java.lang.String getUniqueID()
Description copied from interface:ICityRetrieve the unique ID of the city.- Specified by:
getUniqueIDin interfaceICity- Returns:
- UUID of the city
-
findBuilding
public <T extends IBuilding> java.util.List<T> findBuilding(java.lang.Class<T> buildingClass, java.util.Optional<IPlayer> owner)
Description copied from interface:ICityFind all matching buildings in a city.- Specified by:
findBuildingin interfaceICity- Parameters:
buildingClass- class of the buildingowner- search can be restricted to a player.- Returns:
- List of buildings of type T
-
hasBuildingPermission
public boolean hasBuildingPermission(IPlayer player)
Description copied from interface:ICityThe player has building permission in this city.- Specified by:
hasBuildingPermissionin interfaceICity- Parameters:
player- for whom to check building permission- Returns:
- true if
playerhas building permission.
-
addBuildingPermission
public void addBuildingPermission(IPlayer player)
Description copied from interface:ICityAdd the bulidng permission for that player in the city.- Specified by:
addBuildingPermissionin interfaceICity- Parameters:
player- for whom to add a building permission
-
getPercentageRoad
public double getPercentageRoad()
Description copied from interface:ICityRetrieve the amount of road in the city. The amount is the value of number road tiles versus the population.- Specified by:
getPercentageRoadin interfaceICity- Returns:
- percentage [0,1] of the built road in the city.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
-