Class Region

    • Field Detail

      • logger

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

        public static final java.util.List<java.lang.String> predefinedRegionKeys
        The keys for the valid predefined regions.
      • PACIFIC_KEY

        public static final java.lang.String PACIFIC_KEY
        Hardwired name key for the Pacific for the benefit of isPacific().
        See Also:
        Constant Field Values
      • name

        protected java.lang.String name
        The name of this region, given by a player.
      • key

        protected java.lang.String key
        The key for this region if it is a predefined one.
      • parent

        protected Region parent
        The parent region of this region.
      • children

        protected java.util.List<Region> children
        The child regions of this region.
      • claimable

        protected boolean claimable
        Whether this region is claimable. Ocean regions and non-leaf regions are not claimable.
      • discoverable

        protected boolean discoverable
        Whether this region is discoverable. The Eastern Ocean regions should not be discoverable. In general, non-leaf regions should not be discoverable. The Pacific Ocean is an exception however, unless players start there.
      • discoveredIn

        protected Turn discoveredIn
        Which Turn the region was discovered in.
      • discoveredBy

        protected Player discoveredBy
        Which Player the Region was discovered by.
      • discoverer

        private java.lang.String discoverer
        Identifier for the unit the region was discovered by. Using an identifier as units may subsequently die.
      • scoreValue

        protected int scoreValue
        How much discovering this region contributes to your score. This should be zero unless the region is discoverable.
      • DISCOVERABLE_TAG

        private static final java.lang.String DISCOVERABLE_TAG
        See Also:
        Constant Field Values
      • DISCOVERED_BY_TAG

        private static final java.lang.String DISCOVERED_BY_TAG
        See Also:
        Constant Field Values
      • DISCOVERED_IN_TAG

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

      • Region

        public Region​(Game game)
        Creates a new Region instance.
        Parameters:
        game - The enclosing Game.
      • Region

        public Region​(Game game,
                      java.lang.String id)
        Creates a new Region instance.
        Parameters:
        game - The enclosing Game.
        id - The object identifier.
    • Method Detail

      • getKey

        public java.lang.String getKey()
        Get the key for this region.
        Returns:
        The region key, which will be null for non-fixed regions.
      • hasName

        public boolean hasName()
        Does this region have a name?
        Returns:
        True if the region has been named or was predefined.
      • isPacific

        public boolean isPacific()
        Is this region the Pacific Ocean? The Pacific Ocean is special in that it is the only Region that could be discovered in the original game.
        Returns:
        True if this region is the Pacific.
      • getLabel

        public StringTemplate getLabel()
        Gets the name or default name of this Region.
        Returns:
        The i18n-ready name for the region.
      • getType

        public final Region.RegionType getType()
        Gets the type of the region.
        Returns:
        The region type.
      • getParent

        public final Region getParent()
        Gets the enclosing parent region.
        Returns:
        The parent region
      • setParent

        public final void setParent​(Region newParent)
        Sets the parent region.
        Parameters:
        newParent - The new parent region.
      • getChildren

        public final java.util.List<Region> getChildren()
        Get a list of the child regions.
        Returns:
        The child regions.
      • setChildren

        public final void setChildren​(java.util.List<Region> newChildren)
        Sets the child regions.
        Parameters:
        newChildren - The new child regions.
      • addChild

        public void addChild​(Region child)
        Add a child region to this region.
        Parameters:
        child - The child Region to add.
      • isLeaf

        public boolean isLeaf()
        Is this a leaf region?
        Returns:
        True if the region has no children.
      • getClaimable

        public final boolean getClaimable()
        Can this region be claimed?
        Returns:
        True if the region can be claimed.
      • setClaimable

        public final void setClaimable​(boolean newClaimable)
        Set the claimability of this region.
        Parameters:
        newClaimable - True if the region can be claimed.
      • getDiscoverable

        public final boolean getDiscoverable()
        Can this region be discovered?
        Returns:
        True if the region can be discovered.
      • setDiscoverable

        public final void setDiscoverable​(boolean newDiscoverable)
        Set the discoverability of this region.
        Parameters:
        newDiscoverable - True if the region can be discovered.
      • getDiscoverer

        public final java.lang.String getDiscoverer()
        Get the identifier for the unit that discovered the region.
        Returns:
        The unit identifier, or null if none yet.
      • getDiscoverableRegion

        public Region getDiscoverableRegion()
        Gets a discoverable Region or null. If this region is discoverable, it is returned. If not, a discoverable parent is returned, unless there is none. This is intended for discovering the Pacific Ocean when discovering one of its sub-Regions.
        Returns:
        A discoverable a region, or null if none found.
      • getDiscoveredIn

        public final Turn getDiscoveredIn()
        Gets the turn the region was discovered in.
        Returns:
        The discovery turn.
      • setDiscoveredIn

        public final void setDiscoveredIn​(Turn newDiscoveredIn)
        Sets the discovery turn.
        Parameters:
        newDiscoveredIn - The new discoveredy turn.
      • getDiscoveredBy

        public final Player getDiscoveredBy()
        Gets the player that discovered the region.
        Returns:
        The discovering Player.
      • setDiscoveredBy

        public final void setDiscoveredBy​(Player newDiscoveredBy)
        Sets the discovering player.
        Parameters:
        newDiscoveredBy - The new discovering player.
      • getScoreValue

        public final int getScoreValue()
        Gets the score for discovering this region.
        Returns:
        The score.
      • setScoreValue

        public final void setScoreValue​(int newScoreValue)
        Sets the score for discovering this region.
        Parameters:
        newScoreValue - The new score.
      • checkDiscover

        public boolean checkDiscover​(Unit unit)
        Check if this region is has been discovered. Reserve the ability to discover this region by setting the discoverer field. Called in csCheckDiscoverRegion when the unit moves into a discoverable region.
        Parameters:
        unit - The Unit that might have discovered the region.
        Returns:
        True if the region has been discovered.
      • discover

        public java.util.List<Region> discover​(Player player,
                                               Unit unit,
                                               Turn turn)
        Discover this region (and its children).
        Parameters:
        player - The discovering Player.
        unit - The discovering Unit.
        turn - The Turn of discovery.
        Returns:
        A list of discovered Regions.
      • fixRegionKey

        private java.lang.String fixRegionKey​(java.lang.String key)
        Is a key one of the dodgy keys that were generated up to 0.11.3?
        Parameters:
        key - The key to check.
        Returns:
        A valid key or null if already null or invalid.
      • getName

        public java.lang.String getName()
        Gets the name of this Nameable.
        Specified by:
        getName in interface Nameable
        Returns:
        The name of the Nameable.
      • setName

        public void setName​(java.lang.String newName)
        Sets the name for this Nameable.
        Specified by:
        setName in interface Nameable
        Parameters:
        newName - The new name for the Nameable.
      • copyIn

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

        public 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.
      • readChildren

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

        public 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 FreeColObject
        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.