Class FoundingFather

  • All Implemented Interfaces:
    java.lang.Comparable<FreeColObject>, Named, ObjectWithId

    public class FoundingFather
    extends FreeColSpecObjectType
    Represents one FoundingFather to be contained in a Player object. The FoundingFather is able to grant new abilities or bonuses to the player, or to cause certain events.
    • Field Detail

      • weight

        private final int[] weight
        The probability of this FoundingFather being offered for selection, across the game ages.
      • events

        private java.util.List<Event> events
        The events triggered by this Founding Father.
      • units

        private java.util.List<AbstractUnit> units
        A list of AbstractUnits generated by this FoundingFather.
    • Constructor Detail

      • FoundingFather

        public FoundingFather​(java.lang.String id,
                              Specification specification)
        Create a new Founding Father.
        Parameters:
        id - The object identifier.
        specification - The Specification to refer to.
    • Method Detail

      • setType

        public void setType​(FoundingFather.FoundingFatherType type)
        Set the type of this FoundingFather. Public for the test suite.
        Parameters:
        type - A new FoundingFatherType.
      • getTypeKey

        public java.lang.String getTypeKey()
        Get a key for the type of this FoundingFather.
        Returns:
        A type key.
      • getWeight

        public int getWeight​(int age)
        Get the weight of this FoundingFather. This is used to select a random FoundingFather.
        Parameters:
        age - The age ([0, 2])
        Returns:
        The weight of this father in the given age.
      • getEvents

        public final java.util.List<Event> getEvents()
        Get the events this father triggers.
        Returns:
        A list of Events.
      • setEvents

        public final void setEvents​(java.util.List<Event> newEvents)
        Set the events this Founding Father triggers. Public for the test suite.
        Parameters:
        newEvents - The new events.
      • addEvent

        private void addEvent​(Event event)
        Add an event.
        Parameters:
        event - The Event to add.
      • getUnitList

        public final java.util.List<AbstractUnit> getUnitList()
        Get the units this father supplies.
        Returns:
        A list of AbstractUnits.
      • setUnits

        public final void setUnits​(java.util.List<AbstractUnit> newUnits)
        Set the units supplied by this Founding Father. Public for the test suite.
        Parameters:
        newUnits - The new units.
      • addUnit

        private void addUnit​(AbstractUnit unit)
        Add a unit.
        Parameters:
        unit - The AbstractUnit to add.
      • isAvailableTo

        public boolean isAvailableTo​(Player player)
        Is this Founding Father available to the given player? Note that this does not cover restrictions due to the Age.
        Parameters:
        player - The Player to test.
        Returns:
        True if the father is available.
      • 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.