Class City

  • All Implemented Interfaces:
    ICity

    @Component
    @Scope("prototype")
    public 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 Detail

      • pointInterner

        @Autowired
        protected com.google.common.collect.Interner<javafx.geometry.Point2D> pointInterner
    • Constructor Detail

      • City

        public City​(ch.sahits.game.openpatrician.data.xmlmodel.map.Map.Cities.City city)
    • 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: ICity
        Retrieve the binding of the city's total population.
        Specified by:
        getPopulationBinding in interface ICity
        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:
        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:
        population count of the population class.
      • getPopulationProperty

        public javafx.beans.property.IntegerProperty getPopulationProperty​(EPopulationClass popclass)
        Description copied from interface: ICity
        Retrieve the population count for a class
        Specified by:
        getPopulationProperty in interface ICity
        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: ICity
        Retrieve a list of all buildings in the city. The list is immutable
        Specified by:
        getBuildings in interface ICity
        Returns:
        list of buildings in the city.
      • build

        public void build​(IBuilding building)
        Add a new building to the city
        Specified by:
        build in interface ICity
        Parameters:
        building - to be added
      • 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 - to be demolished
      • 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
        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: ICity
        Add a player to the city
        Specified by:
        moveIn in interface ICity
        Parameters:
        player - that is added to the city
        reputaion - of that player in the city
        contributions - contibutions of that player in 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:
        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
      • getMissingWares

        public java.util.Map<IWare,​java.time.LocalDateTime> getMissingWares()
        Description copied from interface: ICity
        Retrieve the missing wares along with their times
        Specified by:
        getMissingWares in interface ICity
        Returns:
        map of wares and since when they are missing
      • getResidentPlayers

        public java.util.List<IPlayer> getResidentPlayers()
        Description copied from interface: ICity
        Retrieve all the players that have a office in this city.
        Specified by:
        getResidentPlayers in interface ICity
        Returns:
        immutable list
      • getUniqueID

        public java.lang.String getUniqueID()
        Description copied from interface: ICity
        Retrieve the unique ID of the city.
        Specified by:
        getUniqueID in interface ICity
        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: ICity
        Find all matching buildings in a city.
        Specified by:
        findBuilding in interface ICity
        Parameters:
        buildingClass - class of the building
        owner - search can be restricted to a player.
        Returns:
        List of buildings of type T
      • hasBuildingPermission

        public boolean hasBuildingPermission​(IPlayer player)
        Description copied from interface: ICity
        The player has building permission in this city.
        Specified by:
        hasBuildingPermission in interface ICity
        Parameters:
        player - for whom to check building permission
        Returns:
        true if player has building permission.
      • addBuildingPermission

        public void addBuildingPermission​(IPlayer player)
        Description copied from interface: ICity
        Add the bulidng permission for that player in the city.
        Specified by:
        addBuildingPermission in interface ICity
        Parameters:
        player - for whom to add a building permission
      • getPercentageRoad

        public double getPercentageRoad()
        Description copied from interface: ICity
        Retrieve the amount of road in the city. The amount is the value of number road tiles versus the population.
        Specified by:
        getPercentageRoad in interface ICity
        Returns:
        percentage [0,1] of the built road in the city.
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object