Class TileImprovementType

    • Field Detail

      • natural

        private boolean natural
        Is this improvement natural or man-made?
      • magnitude

        private int magnitude
        The magnitude of the improvement.
      • addWorkTurns

        private int addWorkTurns
        The number of turns to build this improvement.
      • requiredImprovementType

        private TileImprovementType requiredImprovementType
        Any improvement that is required before this one.
      • requiredRole

        private Role requiredRole
        The role required to make this improvement.
      • expendedAmount

        private int expendedAmount
        The amount of the equipment expended in making this improvement.
      • movementCost

        private int movementCost
        The change to the movement cost due to this tile improvement.
      • exposeResourcePercent

        private int exposeResourcePercent
        Can this improvement expose a resource when completed? This should only apply to improvement types that change the underlying tile type (e.g. clearing forests).
      • zIndex

        private int zIndex
        The layer a TileItem belongs to. Items with higher zIndex will be displayed above items with a lower zIndex. E.g. the LostCityRumour would be displayed above the Plow improvement.
      • allowedWorkers

        private java.util.Set<java.lang.String> allowedWorkers
        The workers that can make this improvement.
      • tileTypeChanges

        private java.util.Map<TileType,​TileTypeChange> tileTypeChanges
        The changes this improvement makes to a particular tile type.
      • disasters

        private java.util.List<RandomChoice<Disaster>> disasters
        The disasters that may strike this type of tile improvement.
      • ADD_WORK_TURNS_TAG

        private static final java.lang.String ADD_WORK_TURNS_TAG
        See Also:
        Constant Field Values
      • EXPENDED_AMOUNT_TAG

        private static final java.lang.String EXPENDED_AMOUNT_TAG
        See Also:
        Constant Field Values
      • EXPOSE_RESOURCE_PERCENT_TAG

        private static final java.lang.String EXPOSE_RESOURCE_PERCENT_TAG
        See Also:
        Constant Field Values
      • MOVEMENT_COST_TAG

        private static final java.lang.String MOVEMENT_COST_TAG
        See Also:
        Constant Field Values
      • REQUIRED_IMPROVEMENT_TAG

        private static final java.lang.String REQUIRED_IMPROVEMENT_TAG
        See Also:
        Constant Field Values
      • REQUIRED_ROLE_TAG

        private static final java.lang.String REQUIRED_ROLE_TAG
        See Also:
        Constant Field Values
      • TILE_TYPE_CHANGE_TAG

        private static final java.lang.String TILE_TYPE_CHANGE_TAG
        See Also:
        Constant Field Values
      • OLD_EXPENDED_EQUIPMENT_TYPE_TAG

        private static final java.lang.String OLD_EXPENDED_EQUIPMENT_TYPE_TAG
        See Also:
        Constant Field Values
      • OLD_EXPOSE_RESOURCE_PERCENT_TAG

        private static final java.lang.String OLD_EXPOSE_RESOURCE_PERCENT_TAG
        See Also:
        Constant Field Values
    • Constructor Detail

      • TileImprovementType

        public TileImprovementType​(java.lang.String id,
                                   Specification specification)
        Create a new tile improvement type.
        Parameters:
        id - The object identifier.
        specification - The Specification to refer to.
    • Method Detail

      • isNatural

        public boolean isNatural()
        Is this tile improvement type natural?
        Returns:
        True if this is a natural tile improvement type.
      • getMagnitude

        public int getMagnitude()
        Get the magnitude of this tile improvement type.
        Returns:
        The magnitude.
      • getAddWorkTurns

        public int getAddWorkTurns()
        Get the number of turns to build this tile improvement type.
        Returns:
        The number of build turns.
      • getRequiredImprovementType

        public TileImprovementType getRequiredImprovementType()
        Gets the required improvement type.
        Returns:
        The required improvement type if any.
      • getRequiredRole

        public Role getRequiredRole()
        Get the role required to perform this improvement, if any.
        Returns:
        The required Role.
      • getExpendedAmount

        public int getExpendedAmount()
        Gets the amount of equipment expended in building this improvement type.
        Returns:
        The expended equipment amount, if any.
      • getMoveCost

        public int getMoveCost()
        Get the standard movement cost of the tile improvement type.
        Returns:
        The movement cost.
      • getMoveCost

        public int getMoveCost​(int originalCost)
        Possibly reduce the cost of moving due to this tile improvement type. Only applies if movementCost is positive (see spec). Do not return zero from a movement costing routine or units get free moves!
        Parameters:
        originalCost - The original movement cost.
        Returns:
        The movement cost after any change.
      • getExposeResourcePercent

        public int getExposeResourcePercent()
        Gets the percent chance that this tile improvement can expose a resource on the tile. This only applies to TileImprovementTypes that change the underlying tile type (e.g. clearing forests).
        Returns:
        The exposure chance.
      • getZIndex

        public int getZIndex()
        Get the layer.
        Returns:
        The layer.
      • setZIndex

        public void setZIndex​(int newZIndex)
        Set the layer.
        Parameters:
        newZIndex - The new layer.
      • getAllowedWorkers

        protected java.util.Set<java.lang.String> getAllowedWorkers()
        Get the set of allowed worker identifiers.
        Returns:
        The set of allowed worker identifiers.
      • setAllowedWorkers

        protected void setAllowedWorkers​(java.util.Set<java.lang.String> allowed)
        Set the set of allowed worker identifiers.
        Parameters:
        allowed - The new set of allowed worker identifiers.
      • addAllowedWorker

        private void addAllowedWorker​(java.lang.String id)
        Add an allowed worker identifier.
        Parameters:
        id - The worker identifier to add.
      • isWorkerTypeAllowed

        private boolean isWorkerTypeAllowed​(UnitType unitType)
        Is a particular unit type allowed to build this improvement?
        Parameters:
        unitType - The UnitType to check.
        Returns:
        True if the UnitType can build this improvement.
      • isWorkerAllowed

        public boolean isWorkerAllowed​(Unit unit)
        Is a particular unit allowed to build this improvement? Checks both the unit type and the available equipment.
        Parameters:
        unit - The Unit to check.
        Returns:
        True if the Unit can build this improvement.
      • isTileTypeAllowed

        public boolean isTileTypeAllowed​(TileType tileType)
        This will check if in principle this type of improvement can be used on this kind of tile, disregarding the current state of an actual tile. If you want to find out if an improvement is allowed for a tile, call Tile.isImprovementAllowed(TileImprovement).
        Parameters:
        tileType - The TileType to check.
        Returns:
        True if improvement is possible.
      • getBonus

        public int getBonus​(GoodsType goodsType)
      • getProductionModifier

        public Modifier getProductionModifier​(GoodsType goodsType)
      • getTileTypeChanges

        protected java.util.Map<TileType,​TileTypeChange> getTileTypeChanges()
        Get the tile type change map.
        Returns:
        The map of tile type to changes.
      • setTileTypeChanges

        protected void setTileTypeChanges​(java.util.Map<TileType,​TileTypeChange> changes)
        Set the tile type change map.
        Parameters:
        changes - A new map of tile type to changes.
      • isChangeType

        public boolean isChangeType()
        Does this tile improvement change the underlying tile type.
        Returns:
        True if this tile improvement changes the tile type.
      • getProduction

        public AbstractGoods getProduction​(TileType from)
        Gets the goods produced by applying this TileImprovementType to a Tile with the given TileType.
        Parameters:
        from - The original TileType.
        Returns:
        The AbstractGoods produced.
      • getChange

        public TileType getChange​(TileType tileType)
        Gets the destination type of a tile type change (or null).
        Parameters:
        tileType - The TileType that is to change.
        Returns:
        The resulting TileType.
      • changeContainsTarget

        public boolean changeContainsTarget​(TileType tileType)
        Can this tile improvement type change a tile type to the given tile type.
        Parameters:
        tileType - The required TileType.
        Returns:
        True if the required TileType can be changed to.
      • addChange

        private void addChange​(TileTypeChange change)
        Add a tile type change.
        Parameters:
        change - The TileTypeChange to add.
      • getImprovementValue

        public int getImprovementValue​(Tile tile,
                                       GoodsType goodsType)
        Gets the increase in production of the given GoodsType this tile improvement type would yield at a specified tile.
        Parameters:
        tile - The Tile to be considered.
        goodsType - An optional preferred GoodsType.
        Returns:
        The increase in production
      • getDisasters

        protected java.util.List<RandomChoice<Disaster>> getDisasters()
        Get the list of disasters for this tile type.
        Returns:
        The disaster list.
      • setDisasters

        protected void setDisasters​(java.util.List<RandomChoice<Disaster>> disasters)
        Set the list of disasters for this tile type.
        Parameters:
        disasters - The new list of Disasters.
      • getDisasterChoices

        public java.util.stream.Stream<RandomChoice<Disaster>> getDisasterChoices()
        Get a weighted list of natural disasters than can strike this tile improvement type.
        Returns:
        A stream of Disaster choices.
      • addDisaster

        private void addDisaster​(Disaster disaster,
                                 int probability)
        Add a disaster.
        Parameters:
        disaster - The Disaster to add.
        probability - The probability of the disaster.
      • copyIn

        public <T extends FreeColObject> boolean copyIn​(T other)
        Copy another FreeColObject into this one if it is compatible.
        Overrides:
        copyIn in class FreeColSpecObjectType
        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.
      • 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 FreeColObject
        Parameters:
        xw - The FreeColXMLWriter to write to.
        Throws:
        javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.
      • writeChildren

        protected void writeChildren​(FreeColXMLWriter xw)
                              throws javax.xml.stream.XMLStreamException
        Write the children of this object to a stream. To be overridden if required by any object that has children and uses the toXML(FreeColXMLWriter, String) call.
        Overrides:
        writeChildren in class FreeColSpecObjectType
        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 FreeColSpecObjectType
        Parameters:
        xr - The FreeColXMLReader to read from.
        Throws:
        javax.xml.stream.XMLStreamException - if there is a problem reading the stream.
      • readChildren

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

        protected void readChild​(FreeColXMLReader xr)
                          throws javax.xml.stream.XMLStreamException
        Reads a single child object. Subclasses must override to read their enclosed elements. This particular instance of the routine always throws XMLStreamException because we should never arrive here. However it is very useful to always call super.readChild() when an unexpected tag is encountered, as the exception thrown here provides some useful debugging context.
        Overrides:
        readChild in class FreeColSpecObjectType
        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.