Class Building

    • Constructor Detail

      • Building

        protected Building​(Game game,
                           Colony colony,
                           BuildingType type)
        Constructor for ServerBuilding.
        Parameters:
        game - The enclosing Game.
        colony - The Colony in which this building is located.
        type - The BuildingType of building.
      • Building

        public Building​(Game game,
                        java.lang.String id)
        Create a new Building with the given identifier. The object should later be initialized by calling FreeColGameObject.readFromXML(FreeColXMLReader).
        Parameters:
        game - The enclosing Game.
        id - The object identifier.
    • Method Detail

      • getType

        public BuildingType getType()
        Gets the type of this building.
        Returns:
        The building type.
      • setType

        private java.util.List<Unit> setType​(BuildingType newBuildingType)
        Changes the type of the Building. The type of a building may change when it is upgraded or damaged. -til: If this is a defensive building.
        Parameters:
        newBuildingType - The new BuildingType.
        Returns:
        A list of units present that need to be removed.
        See Also:
        upgrade(), downgrade()
      • getCompetenceModifiers

        public java.util.stream.Stream<Modifier> getCompetenceModifiers​(java.lang.String id,
                                                                        UnitType unitType,
                                                                        Turn turn)
        Gets the production modifiers for the given type of goods and unit type. We use UnitType.getModifiers but modify this according to the competence factor of this building type. Note that we do not modify *multiplicative* modifiers, as this would capture the master blacksmith doubling.
        Parameters:
        id - The String identifier
        turn - The turn number of type Turn
        unitType - The optional UnitType to produce them.
        Returns:
        A stream of the applicable modifiers.
      • canBuildNext

        public boolean canBuildNext()
        Does this building have a higher level?
        Returns:
        True if this Building can have a higher level.
      • canBeDamaged

        public boolean canBeDamaged()
        Can this building can be damaged?
        Returns:
        True if this building can be damaged.
      • downgrade

        public java.util.List<Unit> downgrade()
        Downgrade this building. -til: If this is a defensive building.
        Returns:
        A list of units to eject (usually empty) if the building was downgraded, or null on failure.
      • upgrade

        public java.util.List<Unit> upgrade()
        Upgrade this building to next level. -til: If this is a defensive building.
        Returns:
        A list of units to eject (usually empty) if the building was upgraded, or null on failure.
      • canAddType

        public boolean canAddType​(UnitType unitType)
        Can a particular type of unit be added to this building?
        Parameters:
        unitType - The UnitType to check.
        Returns:
        True if unit type can be added to this building.
      • getAvailable

        private int getAvailable​(GoodsType type,
                                 java.util.List<AbstractGoods> available)
        Convenience function to extract a goods amount from a list of available goods.
        Parameters:
        type - The GoodsType to extract the amount for.
        available - The list of available goods to query.
        Returns:
        The goods amount, or zero if none found.
      • getAdjustedProductionInfo

        public ProductionInfo getAdjustedProductionInfo​(java.util.List<AbstractGoods> inputs,
                                                        java.util.List<AbstractGoods> outputs)
        Gets the production information for this building taking account of the available input and output goods.
        Parameters:
        inputs - The input goods available.
        outputs - The output goods already available in the colony, necessary in order to avoid excess production.
        Returns:
        The production information.
        See Also:
        ProductionCache.update()
      • evaluateFor

        public int evaluateFor​(Player player)
        Evaluate this work location for a given player.
        Overrides:
        evaluateFor in class WorkLocation
        Parameters:
        player - The Player to evaluate for.
        Returns:
        A value for the player.
      • up

        public Location up()
        Promote this location to a more meaningful one if possible. For example: a settlement is more meaningful than the tile it occupies.
        Specified by:
        up in interface Location
        Returns:
        A more meaningful Location, or this one.
      • toShortString

        public java.lang.String toShortString()
        Get a short description of this location.
        Specified by:
        toShortString in interface Location
        Returns:
        A short description.
      • getNoAddReason

        public UnitLocation.NoAddReason getNoAddReason​(Locatable locatable)
        Gets the reason why a given Locatable can not be added to this Location. Be careful to test for unit presence last before success (NoAddReason.NONE) except perhaps for the capacity test, so that we can treat ALREADY_PRESENT as success in some cases (e.g. if the unit changes type --- does it still have a required skill?) FIXME: consider moving this up to Location?
        Overrides:
        getNoAddReason in class WorkLocation
        Parameters:
        locatable - The Locatable to test.
        Returns:
        The reason why adding would fail.
      • getUnitCapacity

        public int getUnitCapacity()
        Gets the maximum number of Units this Location can hold. To be overridden by subclasses.
        Overrides:
        getUnitCapacity in class UnitLocation
        Returns:
        Integer.MAX_VALUE, denoting no effective limit.
      • goodSuggestionCheck

        public boolean goodSuggestionCheck​(UnitType better,
                                           Unit unit,
                                           GoodsType goodsType)
        Description copied from class: WorkLocation
        Determines whether a WorkLocation is a good suggestion
        Overrides:
        goodSuggestionCheck in class WorkLocation
        Parameters:
        better - The type of Unit to check.
        unit - The Unit itself.
        goodsType - The GoodsType to check.
        Returns:
        True or false, depending on whether the suggestion is valid.
      • getLabel

        public StringTemplate getLabel()
        Get a description of the work location, with any expected extra detail.
        Specified by:
        getLabel in class WorkLocation
        Returns:
        A label StringTemplate for this work location.
      • isAvailable

        public boolean isAvailable()
        Is this work location available?
        Specified by:
        isAvailable in class WorkLocation
        Returns:
        True if the work location is either current or can be claimed.
      • isCurrent

        public boolean isCurrent()
        Is this a current work location of this colony?
        Specified by:
        isCurrent in class WorkLocation
        Returns:
        True if the work location is current.
      • getWorkTile

        public Tile getWorkTile()
        Get an associated tile, if any.
        Specified by:
        getWorkTile in class WorkLocation
        Returns:
        The underlying Tile which is worked, if any.
      • getLevel

        public int getLevel()
        Get the "level" of this work location. Note: only meaningful for buildings at present.
        Specified by:
        getLevel in class WorkLocation
        Returns:
        The work location level.
      • canAutoProduce

        public boolean canAutoProduce()
        Can this work location can produce goods without workers?
        Specified by:
        canAutoProduce in class WorkLocation
        Returns:
        True if this work location can produce goods without workers.
      • canProduce

        public boolean canProduce​(GoodsType goodsType,
                                  UnitType unitType)
        Can this work location produce a given goods type with an optional unit.
        Specified by:
        canProduce in class WorkLocation
        Parameters:
        goodsType - The GoodsType to produce.
        unitType - An optional UnitType, if null the unattended production is considered.
        Returns:
        True if this location can produce the goods.
      • getBaseProduction

        public int getBaseProduction​(ProductionType productionType,
                                     GoodsType goodsType,
                                     UnitType unitType)
        Gets the base production of a given goods type optionally using a unit of a given type in this work location. That is, the production exclusive of any modifiers. If no unit type is specified, the unattended production is calculated.
        Specified by:
        getBaseProduction in class WorkLocation
        Parameters:
        productionType - An optional ProductionType to use, if null the best available one is used.
        goodsType - The GoodsType to produce.
        unitType - An optional UnitType to produce the goods.
        Returns:
        The amount of goods potentially produced.
      • getProductionModifiers

        public java.util.stream.Stream<Modifier> getProductionModifiers​(GoodsType goodsType,
                                                                        UnitType unitType)
        Gets the production modifiers for the given type of goods and unit type. If no unit is specified the unattended production is calculated.
        Specified by:
        getProductionModifiers in class WorkLocation
        Parameters:
        goodsType - The GoodsType to produce.
        unitType - The optional UnitType to produce them.
        Returns:
        A stream of the applicable modifiers.
      • getAvailableProductionTypes

        public java.util.List<ProductionType> getAvailableProductionTypes​(boolean unattended)
        Get the production types available for this work location.
        Specified by:
        getAvailableProductionTypes in class WorkLocation
        Parameters:
        unattended - If true, get unattended production types.
        Returns:
        A list of suitable ProductionTypes.
      • getCompetenceFactor

        public float getCompetenceFactor()
        Get a work location specific factor to multiply any goods-specific unit production bonuses by.
        Specified by:
        getCompetenceFactor in class WorkLocation
        Returns:
        The competence factor.
      • getRebelFactor

        public float getRebelFactor()
        Get a work location specific factor to multiply the colony rebel bonus by.
        Specified by:
        getRebelFactor in class WorkLocation
        Returns:
        The rebel factor.
      • getConsumedGoods

        public java.util.List<AbstractGoods> getConsumedGoods()
        Returns a list of GoodsTypes this Consumer consumes.
        Specified by:
        getConsumedGoods in interface Consumer
        Returns:
        a List value
      • getPriority

        public int getPriority()
        The priority of this Consumer. The higher the priority, the earlier will the Consumer be allowed to consume the goods it requires.
        Specified by:
        getPriority in interface Consumer
        Returns:
        an int value
      • getConsumptionModifiers

        public java.util.stream.Stream<Modifier> getConsumptionModifiers​(java.lang.String id)
        Get the modifier set with the given id. The modifier most relevant to consumers is "consumeOnlySurplusProduction", which implies that the consumer does not consume stored goods (used by the country and stables).
        Specified by:
        getConsumptionModifiers in interface Consumer
        Parameters:
        id - The object identifier.
        Returns:
        The stream of Modifiers found.
      • getNameKey

        public java.lang.String getNameKey()
        Gets the name of this named object. Try to avoid using this directly except in i18n-related routines or to implement itself in more complext objects.
        Specified by:
        getNameKey in interface Named
        Returns:
        The name of the Named.
      • getAbilities

        public java.util.stream.Stream<Ability> getAbilities​(java.lang.String id,
                                                             FreeColSpecObjectType type,
                                                             Turn turn)
        Gets the set of abilities with the given identifier from this object. Subclasses with complex ability handling should override this as all prior routines are derived from it.
        Overrides:
        getAbilities in class FreeColObject
        Parameters:
        id - The object identifier.
        type - An optional FreeColSpecObjectType the ability applies to.
        turn - An optional applicable Turn.
        Returns:
        A set of abilities.
      • getModifiers

        public java.util.stream.Stream<Modifier> getModifiers​(java.lang.String id,
                                                              FreeColSpecObjectType fcgot,
                                                              Turn turn)
        Gets the set of modifiers with the given identifier from this object. Subclasses with complex modifier handling may override this routine.
        Overrides:
        getModifiers in class FreeColObject
        Parameters:
        id - The object identifier.
        fcgot - An optional FreeColSpecObjectType the modifier applies to.
        turn - An optional applicable Turn.
        Returns:
        A set of modifiers.
      • copyIn

        public <T extends FreeColObject> boolean copyIn​(T other)
        Copy another FreeColObject into this one if it is compatible.
        Overrides:
        copyIn in class WorkLocation
        Type Parameters:
        T - The FreeColObject subclass of the object to copy in.
        Parameters:
        other - The other object.
        Returns:
        True if the copy in is succesful.
      • getDisplayObject

        public FreeColObject getDisplayObject()
        Get an object to display when showing the user messages for this object. Example: If this object is a Building, the object to display will be the BuildingType.
        Overrides:
        getDisplayObject in class FreeColObject
        Returns:
        A suitable FreeColObject to display, defaults to this.
      • writeAttributes

        protected void writeAttributes​(FreeColXMLWriter xw)
                                throws javax.xml.stream.XMLStreamException
        Write the attributes of this object to a stream. To be overridden if required by any object that has attributes and uses the toXML(FreeColXMLWriter, String) call.
        Overrides:
        writeAttributes in class WorkLocation
        Parameters:
        xw - The FreeColXMLWriter to write to.
        Throws:
        javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.
      • readAttributes

        protected void readAttributes​(FreeColXMLReader xr)
                               throws javax.xml.stream.XMLStreamException
        Reads the attributes of this object from an XML stream.
        Overrides:
        readAttributes in class WorkLocation
        Parameters:
        xr - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if there is a problem reading the stream.
      • getXMLTagName

        public java.lang.String getXMLTagName()
        Get the serialization tag for this object.
        Specified by:
        getXMLTagName in class FreeColObject
        Returns:
        The tag.