Class TileImprovement

    • Field Detail

      • logger

        private static final java.util.logging.Logger logger
      • EMPTY_RIVER_STYLE

        public static final java.lang.String EMPTY_RIVER_STYLE
        See Also:
        Constant Field Values
      • EMPTY_ROAD_STYLE

        public static final java.lang.String EMPTY_ROAD_STYLE
        See Also:
        Constant Field Values
      • turnsToComplete

        private int turnsToComplete
        Turns remaining until the improvement is complete, if any.
      • magnitude

        private int magnitude
        The improvement magnitude. Default is type.getMagnitude(), but this will override.
      • style

        private TileImprovementStyle style
        Image and overlay style information for the improvement.
      • virtual

        private boolean virtual
        Whether this is a virtual improvement granted by some structure on the tile (a Colony, for example). Virtual improvements will be removed along with the structure that granted them.
    • Constructor Detail

      • TileImprovement

        public TileImprovement​(Game game,
                               Tile tile,
                               TileImprovementType type,
                               TileImprovementStyle style)
        Creates a standard TileImprovement-instance. This constructor asserts that the game, tile and type are valid. Does not set the style.
        Parameters:
        game - The enclosing Game.
        tile - The Tile on which this object sits.
        type - The TileImprovementType of this improvement.
        style - The TileImprovementStyle of this improvement.
      • TileImprovement

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

      • getType

        public TileImprovementType getType()
        Gets the type of this tile improvement.
        Returns:
        The type of this improvement.
      • isRiver

        public boolean isRiver()
        Is this tile improvement a river?
        Returns:
        True if this is a river improvement.
      • isRoad

        public boolean isRoad()
        Is this tile improvement a road?
        Returns:
        True if this is a road improvement.
      • getConnectionDirections

        public java.util.List<Direction> getConnectionDirections()
        Gets the directions that a connection can form across for this this type of improvement. - For rivers, it is just the longSided directions. - For roads, it is all directions. - In other cases, no directions are relevant.
        Returns:
        An array of relevant directions, or null if none.
      • getTurnsToComplete

        public int getTurnsToComplete()
        How many turns remain until this improvement is complete?
        Returns:
        The current turns to completion.
      • setTurnsToComplete

        public void setTurnsToComplete​(int turns)
        Sets the turns required to complete the improvement.
        Parameters:
        turns - The new turns to completion.
      • getMagnitude

        public int getMagnitude()
        Gets the magnitude of this improvement.
        Returns:
        The magnitude of this immprovement.
      • setMagnitude

        public void setMagnitude​(int magnitude)
        Sets the magnitude of this improvement.
        Parameters:
        magnitude - The new magnitude.
      • getStyle

        public TileImprovementStyle getStyle()
        Gets the style of this improvement.
        Returns:
        The style
      • setStyle

        public void setStyle​(TileImprovementStyle style)
        Set the style of this improvement.
        Parameters:
        style - The new TileImprovementStyle.
      • getVirtual

        public final boolean getVirtual()
        Is this a virtual improvement?
        Returns:
        True if this is a virtual improvement.
      • setVirtual

        public final void setVirtual​(boolean virtual)
        Set the virtual status of this improvement. Used for the roads in a colony center tile.
        Parameters:
        virtual - The new virtual value.
      • getRiverConnection

        public int getRiverConnection​(Direction direction)
        Get the magnitude of the river branch in the given direction. Precondition: This tile improvement is a river!
        Parameters:
        direction - The Direction to check.
        Returns:
        The magnitude of the river branch or 0 if there is none.
      • isConnectedTo

        public boolean isConnectedTo​(Direction direction)
        Is this tile improvement connected to a similar improvement on a neighbouring tile? Public for the test suite.
        Parameters:
        direction - The Direction to check.
        Returns:
        True if this improvement is connected.
      • setConnected

        private void setConnected​(Direction direction,
                                  boolean value)
        Internal helper method to set the connection status in a given direction. There is no check for backwards connections on neighbouring tiles!
        Parameters:
        direction - The Direction to set.
        value - The new status for the connection.
      • setConnected

        private void setConnected​(Direction direction,
                                  boolean value,
                                  java.lang.String magnitude)
      • getConnections

        public java.util.Map<Direction,​java.lang.Integer> getConnections()
        Gets a map of connection-direction to magnitude.
        Returns:
        A map of the connections.
      • getProductionModifier

        private Modifier getProductionModifier​(GoodsType goodsType)
        Gets a Modifier for the production bonus this improvement provides for a given type of goods.
        Parameters:
        goodsType - The GoodsType to test.
        Returns:
        A production Modifier, or null if none applicable.
      • getMoveCost

        public int getMoveCost​(Direction direction,
                               int moveCost)
        Calculates the movement cost on the basis of connected tile improvements.
        Parameters:
        direction - The Direction to move.
        moveCost - The original movement cost.
        Returns:
        The movement cost with this improvement.
      • getChange

        public TileType getChange​(TileType tileType)
        What type of tile does this improvement change a given type to?
        Parameters:
        tileType - The original TileType.
        Returns:
        The TileType that results from completing this improvement, or null if nothing changes.
      • isWorkerAllowed

        public boolean isWorkerAllowed​(Unit unit)
        Can a unit build this improvement?
        Parameters:
        unit - A Unit to do the building.
        Returns:
        True if the supplied unit can build this improvement.
      • getConnectionsFromStyle

        public final long getConnectionsFromStyle()
        Updates the connections from the current style. Public for the test suite.
        Returns:
        The connections implied by the current style.
      • setRiverStyle

        public void setRiverStyle​(java.lang.String conns)
        Sets the river style to be as close as possible to the requested style, even when it has to create neighbouring rivers to prevent broken connections or change the magnitude.
        Parameters:
        conns - The river style to set.
      • updateRiverConnections

        public java.lang.String updateRiverConnections​(java.lang.String conns)
        Updates the connections from/to this river improvement on the basis of the expected encoded river style, as long as this would not create broken connections. Uses magnitude, not the connection strengths inside conns, when adding new connections.
        Parameters:
        conns - The encoded river connections, or null to disconnect.
        Returns:
        The actual encoded connections found.
      • updateRoadConnections

        public java.lang.String updateRoadConnections​(boolean connect)
        Updates the connections from/to this road improvement.
        Parameters:
        connect - If true, add connections, otherwise remove them.
        Returns:
        A string encoding of the correct connections for this improvement.
      • getDisasterChoices

        public java.util.stream.Stream<RandomChoice<Disaster>> getDisasterChoices()
        Get the disaster choices available for this tile improvement.
        Returns:
        A stream of Disaster choices.
      • 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
        Specified by:
        getNameKey in class TileItem
        Returns:
        The name of the Named.
      • getZIndex

        public final int getZIndex()
        Get the ZIndex value.
        Specified by:
        getZIndex in class TileItem
        Returns:
        The z-index.
      • isTileTypeAllowed

        public boolean isTileTypeAllowed​(TileType tileType)
        Is a tile type compatible with this tile item?
        Specified by:
        isTileTypeAllowed in class TileItem
        Parameters:
        tileType - The TileType to check.
        Returns:
        True if the tile type is compatible.
      • applyBonus

        public int applyBonus​(GoodsType goodsType,
                              UnitType unitType,
                              int potential)
        Applies the production bonus for the given goods type and unit type to the given potential production.
        Specified by:
        applyBonus in class TileItem
        Parameters:
        goodsType - The GoodsType to produce.
        unitType - The UnitType that is to work.
        potential - The base potential production.
        Returns:
        The production with resource bonuses.
      • canProduce

        public boolean canProduce​(GoodsType goodsType,
                                  UnitType unitType)
        Does this tile item allow its enclosing tile to produce a given goods type?
        Specified by:
        canProduce in class TileItem
        Parameters:
        goodsType - The GoodsType to produce.
        unitType - The optional unitType to produce with.
        Returns:
        True if this tile item produces the goods.
      • getProductionModifiers

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

        public boolean isNatural()
        Is this a natural TileItem?
        Specified by:
        isNatural in class TileItem
        Returns:
        True if this is a natural TileItem.
      • isComplete

        public boolean isComplete()
        Is this improvement complete?
        Specified by:
        isComplete in class TileItem
        Returns:
        True if complete.
      • getLayer

        public Map.Layer getLayer()
        Get the layer associated with this tile item.
        Specified by:
        getLayer in class TileItem
        Returns:
        The layer.
      • checkIntegrity

        public Constants.IntegrityType checkIntegrity​(boolean fix,
                                                      LogBuilder lb)
        Checks the integrity of this game object.
        Overrides:
        checkIntegrity in class TileItem
        Parameters:
        fix - If true, fix problems if possible.
        lb - A LogBuilder to log to.
        Returns:
        A suitable IntegrityType.
      • copyIn

        public <T extends FreeColObject> boolean copyIn​(T other)
        Copy another FreeColObject into this one if it is compatible.
        Overrides:
        copyIn in class TileItem
        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.
      • 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 FreeColGameObject
        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.