Class BuildableType

    • Field Detail

      • DEFAULT_REQUIRED_POPULATION

        private static final int DEFAULT_REQUIRED_POPULATION
        The required population for an ordinary buildable.
        See Also:
        Constant Field Values
      • requiredPopulation

        private int requiredPopulation
        The minimum population that a Colony needs in order to build this type.
      • requiredAbilities

        private java.util.Map<java.lang.String,​java.lang.Boolean> requiredAbilities
        Stores the abilities required by this Type.
      • requiredGoods

        private java.util.List<AbstractGoods> requiredGoods
        A list of AbstractGoods required to build this type.
      • limits

        private java.util.List<Limit> limits
        Limits on the production of this type.
      • REQUIRED_ABILITY_TAG

        private static final java.lang.String REQUIRED_ABILITY_TAG
        See Also:
        Constant Field Values
      • REQUIRED_GOODS_TAG

        private static final java.lang.String REQUIRED_GOODS_TAG
        See Also:
        Constant Field Values
      • REQUIRED_POPULATION_TAG

        public static final java.lang.String REQUIRED_POPULATION_TAG
        See Also:
        Constant Field Values
    • Constructor Detail

      • BuildableType

        public BuildableType​(java.lang.String id,
                             Specification specification)
        Creates a new buildable type.
        Parameters:
        id - The object identifier.
        specification - The Specification to refer to.
    • Method Detail

      • getRequiredPopulation

        public int getRequiredPopulation()
        Get the population required to build this buildable type.
        Returns:
        The population required.
      • setRequiredPopulation

        public void setRequiredPopulation​(int newPopulation)
        Set the population required to build this buildable type.
        Parameters:
        newPopulation - The new population required.
      • getRequiredAbilities

        public java.util.Map<java.lang.String,​java.lang.Boolean> getRequiredAbilities()
        Gets the abilities required by this type.
        Returns:
        A copy of the required abilities map.
      • requiresAbility

        public boolean requiresAbility​(java.lang.String key)
      • setRequiredAbilities

        public void setRequiredAbilities​(java.util.Map<java.lang.String,​java.lang.Boolean> abilities)
        Sets the abilities required by this type.
        Parameters:
        abilities - The new required abilities.
      • addRequiredAbility

        public void addRequiredAbility​(java.lang.String tag,
                                       boolean value)
        Add a new required ability. Public for specification fixes.
        Parameters:
        tag - The ability name.
        value - The ability value.
      • removeRequiredAbility

        public void removeRequiredAbility​(java.lang.String tag)
        Remove a required ability. Public for specification fixes.
        Parameters:
        tag - The ability name to remove.
      • isAvailableTo

        public boolean isAvailableTo​(FreeColObject... fco)
        Is this buildable available to a given FreeColObject?
        Parameters:
        fco - The FreeColObjects to check.
        Returns:
        True if the buildable is available.
      • getRequiredGoodsList

        public java.util.List<AbstractGoods> getRequiredGoodsList()
        Get the goods required to build an instance of this buildable. Note we must take care to return a deep copy, as these lists are subject to complex manipulations in the role code.
        Returns:
        A deep copy of the list of required goods.
      • getRequiredGoods

        public java.util.stream.Stream<AbstractGoods> getRequiredGoods()
        Get the goods required to build an instance of this buildable as a stream.
        Returns:
        A stream of the required goods.
      • setRequiredGoods

        public void setRequiredGoods​(java.util.List<AbstractGoods> goods)
        Set the goods required to build an instance of this buildable.
        Parameters:
        goods - The new required goods.
      • getRequiredAmountOf

        public int getRequiredAmountOf​(GoodsType type)
        Get the amount required of a given GoodsType to build an instance of this buildable.
        Parameters:
        type - The GoodsType to check.
        Returns:
        The amount of goods required.
      • addRequiredGoods

        private void addRequiredGoods​(AbstractGoods ag)
        Add a new goods requirement.
        Parameters:
        ag - The required AbstractGoods to add.
      • needsGoodsToBuild

        public boolean needsGoodsToBuild()
        Does this buildable need goods to build?
        Returns:
        True if goods are required to build this buildable.
      • getLimits

        public java.util.List<Limit> getLimits()
        Get the limits on this buildable.
        Returns:
        A list of Limits.
      • setLimits

        public void setLimits​(java.util.List<Limit> newLimits)
        Set the limits on this buildable.
        Parameters:
        newLimits - The new Limits value.
      • addLimit

        private void addLimit​(Limit limit)
        Add a new limit.
        Parameters:
        limit - The Limit to add.
      • getCurrentlyBuildingLabel

        public StringTemplate getCurrentlyBuildingLabel()
        Get a label describing this buildable type as being currently built.
        Returns:
        A suitable label.
      • canBeBuiltInColony

        public abstract Colony.NoBuildReason canBeBuiltInColony​(Colony colony,
                                                                java.util.List<BuildableType> assumeBuilt)
        Check to see if this buildable type can be built in a colony based on the buildings or units available.
        Parameters:
        colony - The Colony to check.
        assumeBuilt - A list of BuildableTypes.
        Returns:
        The reason the for failure, or NoBuildReason.NONE on success.
      • getMinimumIndex

        public int getMinimumIndex​(Colony colony,
                                   javax.swing.JList<BuildableType> buildQueueList,
                                   int UNABLE_TO_BUILD)
      • getMaximumIndex

        public int getMaximumIndex​(Colony colony,
                                   javax.swing.JList<BuildableType> buildQueueList,
                                   int UNABLE_TO_BUILD)
      • 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.