ch.sahits.game.openpatrician.model.city.impl
Class City

java.lang.Object
  extended by ch.sahits.game.openpatrician.model.impl.WareHolding
      extended by ch.sahits.game.openpatrician.model.city.impl.City
All Implemented Interfaces:
ICity
Direct Known Subclasses:
Bremen, Cologne, Danzig, Hamburg, Luebeck, Rostock, Stettin, Visby

abstract class City
extends WareHolding
implements ICity

Implementation 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
private  List<IBuilding> buildings
          Store the buildings in the city
private  IWare[] effectiveProduction
           
private  IWare[] ineffectiveProduction
           
private  EKontorType kontorType
           
private  Locale locale
           
private  String name
           
private  Map<IPlayer,Contributions> playersContributions
          Store the contibutions of the players
private  HashMap<EPopulationClass,Integer> population
          Holding the population split by population classes
private  Map<IPlayer,IReputation> reputation
          Map holding the reputation of the different players
 
Constructor Summary
City(String configFileName)
           
 
Method Summary
 void build(IBuilding building)
          Add a new building to the city
 List<IBuilding> getBuildings()
          Retrieve a list of all buildings in the city.
 int getContribution(IPlayer player, IWare ware)
          Check out what the player contributed to the ware
 IWare[] getEffectiveProduction()
          Retrieve the wares that are produced efficiently
 IWare[] getIneffectiveProduction()
          Retrieve the wares that are produced inefficiently
 EKontorType getKontorType()
          Retrieve the city type
 String getName()
          Retrieve the city name
 int getPopulation()
          Retrieve the total population
 int getPopulation(EPopulationClass popclass)
          Retrieve the population count for a class
 IReputation getReputation(IPlayer player)
          Retrieve the reputation of the player in the city
 ESocialRank getSocialRank()
          Retrieve the social rank in this city
private  void initPopulation(Properties props)
          Initialize the population of the different classes based on the properties
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
 int move(IWare ware, int amount, IPlayer player)
          Move ware into this holding.
 void moveIn(IPlayer player)
          Add a player to the city
 void setPopulation(int population, EPopulationClass popClass)
          Set the population count for a apopulation class
 void tearDown(IBuilding building)
          Remove a building from the list of buildings in the city
 
Methods inherited from class ch.sahits.game.openpatrician.model.impl.WareHolding
addNewWare, computeAVGPrice, containsWare, getWare
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface ch.sahits.game.openpatrician.model.city.ICity
getUniqueID, getWare
 

Field Detail

effectiveProduction

private final IWare[] effectiveProduction

ineffectiveProduction

private final IWare[] ineffectiveProduction

name

private final String name

kontorType

private final EKontorType kontorType

locale

private final Locale locale

buildings

private List<IBuilding> buildings
Store the buildings in the city


reputation

private Map<IPlayer,IReputation> reputation
Map holding the reputation of the different players


playersContributions

private Map<IPlayer,Contributions> playersContributions
Store the contibutions of the players


population

private final HashMap<EPopulationClass,Integer> population
Holding the population split by population classes

Constructor Detail

City

public City(String configFileName)
     throws IOException
Throws:
IOException
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


initPopulation

private void initPopulation(Properties props)
Initialize the population of the different classes based on the properties

Parameters:
props -

getPopulation

public int getPopulation()
Retrieve the total population

Specified by:
getPopulation in interface ICity
Returns:

setPopulation

public void setPopulation(int population,
                          EPopulationClass popClass)
Set the population count for a apopulation class

Specified by:
setPopulation in interface ICity
Parameters:
population - count
popClass - population class

getPopulation

public int getPopulation(EPopulationClass popclass)
Retrieve the population count for a class

Specified by:
getPopulation in interface ICity
Parameters:
popclass - population class
Returns:

getName

public String getName()
Description copied from interface: ICity
Retrieve the city name

Specified by:
getName in interface ICity
Returns:

getKontorType

public EKontorType getKontorType()
Description copied from interface: ICity
Retrieve the city type

Specified by:
getKontorType in interface ICity
Returns:

getEffectiveProduction

public IWare[] getEffectiveProduction()
Retrieve the wares that are produced efficiently

Specified by:
getEffectiveProduction in interface ICity
Returns:

getIneffectiveProduction

public IWare[] getIneffectiveProduction()
Retrieve the wares that are produced inefficiently

Specified by:
getIneffectiveProduction in interface ICity
Returns:

getBuildings

public List<IBuilding> getBuildings()
Description copied from interface: ICity
Retrieve a list of all buildings in the city. The list is immutable

Specified by:
getBuildings in interface ICity
Returns:

build

public void build(IBuilding building)
Add a new building to the city

Specified by:
build in interface ICity
Parameters:
building -

tearDown

public void tearDown(IBuilding building)
Remove a building from the list of buildings in the city

Specified by:
tearDown in interface ICity
Parameters:
building -

getReputation

public IReputation getReputation(IPlayer player)
Description copied from interface: ICity
Retrieve the reputation of the player in the city

Specified by:
getReputation in interface ICity
Returns:

moveIn

public void moveIn(IPlayer player)
Description copied from interface: ICity
Add a player to the city

Specified by:
moveIn in interface ICity

getSocialRank

public ESocialRank getSocialRank()
Description copied from interface: ICity
Retrieve the social rank in this city

Specified by:
getSocialRank in interface ICity
Returns:

move

public int move(IWare ware,
                int amount,
                IPlayer 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:
move in interface ICity
Overrides:
move in class WareHolding
Parameters:
ware - to be moved
amount - of the ware that is moved
player - 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: ICity
Check out what the player contributed to the ware

Specified by:
getContribution in interface ICity
Parameters:
player - whose contribution is to be checked
ware - that is checked for contribution
Returns:
amount of the contribution may also be negative


Copyright © 2011-2012 Sahits GmbH. All Rights Reserved.