net.sf.freecol.common.model
Class Region

java.lang.Object
  extended by net.sf.freecol.common.model.FreeColObject
      extended by net.sf.freecol.common.model.FreeColGameObject
          extended by net.sf.freecol.common.model.Region
All Implemented Interfaces:
Nameable
Direct Known Subclasses:
ServerRegion

public class Region
extends FreeColGameObject
implements Nameable

A named region on the map.


Nested Class Summary
static class Region.RegionType
           
 
Field Summary
static java.lang.String CHILD_TAG
           
private  java.util.List<Region> children
          The children Regions of this Region.
private  boolean claimable
          Whether this Region is claimable.
private  boolean discoverable
          Whether this Region is discoverable.
private  Player discoveredBy
          Which Player the Region was discovered by.
private  Turn discoveredIn
          Which Turn the Region was discovered in.
private  java.lang.String name
          The name of this Region.
private  java.lang.String nameKey
          Key used to retrieve description from Messages.
static java.lang.String PACIFIC_NAME_KEY
           
private  Region parent
          The parent Region of this Region.
private  boolean prediscovered
          Whether the Region is already discovered when the game starts.
private  int scoreValue
          How much discovering this Region contributes to your score.
private  Region.RegionType type
          Describe type here.
 
Fields inherited from class net.sf.freecol.common.model.FreeColGameObject
UNITS_TAG_NAME
 
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, INFINITY, NO_ID, PARTIAL_ATTRIBUTE, UNDEFINED, VALUE_TAG
 
Constructor Summary
Region(Game game)
          Creates a new Region instance.
Region(Game game, java.lang.String id)
          Creates a new Region instance.
Region(Game game, javax.xml.stream.XMLStreamReader in)
          Initiates a new Region from an XML representation.
 
Method Summary
 void addChild(Region child)
          Add a child region to this region.
 HistoryEvent discover(Player player, Turn turn, java.lang.String newName)
          Mark the Region as discovered.
 java.util.List<Region> getChildren()
          Get the Children value.
 Region getDiscoverableRegion()
          Returns a discoverable Region or null.
 Player getDiscoveredBy()
          Get the DiscoveredBy value.
 Turn getDiscoveredIn()
          Get the DiscoveredIn value.
 StringTemplate getLabel()
          Returns the name or default name of this Region.
 java.lang.String getName()
          Get the Name value.
 java.lang.String getNameKey()
          Get the NameKey value.
 Region getParent()
          Get the Parent value.
 int getScoreValue()
          Get the ScoreValue value.
 Region.RegionType getType()
          Get the Type value.
 java.lang.String getTypeNameKey()
           
static java.lang.String getXMLElementTagName()
          Gets the tag name of the root element representing this object.
 boolean isClaimable()
          Get the Claimable value.
 boolean isDiscoverable()
          Get the Discoverable value.
 boolean isLeaf()
          Returns true if this is a leaf node.
 boolean isPacific()
          Returns true if this Region is the Pacific Ocean.
 boolean isPrediscovered()
          Get the Prediscovered value.
 boolean isRoot()
          Returns true if this is the whole map Region.
protected  void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
          Initialize this object from an XML-representation of this object.
 void setChildren(java.util.List<Region> newChildren)
          Set the Children value.
 void setClaimable(boolean newClaimable)
          Set the Claimable value.
 void setDiscoverable(boolean newDiscoverable)
          Set the Discoverable value.
 void setDiscoveredBy(Player newDiscoveredBy)
          Set the DiscoveredBy value.
 void setDiscoveredIn(Turn newDiscoveredIn)
          Set the DiscoveredIn value.
 void setName(java.lang.String newName)
          Set the Name value.
 void setNameKey(java.lang.String newNameKey)
          Set the NameKey value.
 void setParent(Region newParent)
          Set the Parent value.
 void setPrediscovered(boolean newPrediscovered)
          Set the Prediscovered value.
 void setScoreValue(int newScoreValue)
          Set the ScoreValue value.
 void setType(Region.RegionType newType)
          Set the Type value.
 java.lang.String toString()
          Gets a string representation of the object.
protected  void toXMLImpl(javax.xml.stream.XMLStreamWriter out, Player player, boolean showAll, boolean toSavedGame)
          This method writes an XML-representation of this object to the given stream.
 
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
dispose, disposeList, equals, equals, fundamentalDispose, getFreeColGameObject, getFreeColGameObject, getGame, getIntegerID, getSpecification, hashCode, isDisposed, isUninitialized, newLocation, readFromXML, readFromXMLPartialByClass, setDefaultId, setGame, setId, toXML, toXMLImpl, toXMLPartialByClass, updateFreeColGameObject
 
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addPropertyChangeListener, addPropertyChangeListener, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAttribute, getAttribute, getAttribute, getAttribute, getAttribute, getId, getPropertyChangeListeners, getPropertyChangeListeners, hasAbility, hasAttribute, hasListeners, readAttributes, readAttributes, readChild, readChild, readChildren, readChildren, readFromArrayElement, readFromArrayElement, readFromListElement, readFromXMLElement, readFromXMLImpl, readFromXMLPartialImpl, removePropertyChangeListener, removePropertyChangeListener, save, save, setSpecification, toXML, toXML, toXMLElement, toXMLElement, toXMLElement, toXMLElement, toXMLElementPartial, toXMLPartialImpl, writeAttribute, writeAttributes, writeChildren
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

PACIFIC_NAME_KEY

public static final java.lang.String PACIFIC_NAME_KEY
See Also:
Constant Field Values

CHILD_TAG

public static final java.lang.String CHILD_TAG
See Also:
Constant Field Values

name

private java.lang.String name
The name of this Region.


nameKey

private java.lang.String nameKey
Key used to retrieve description from Messages.


parent

private Region parent
The parent Region of this Region.


claimable

private boolean claimable
Whether this Region is claimable. Ocean Regions and non-leaf Regions should not be claimable.


discoverable

private 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.


discoveredIn

private Turn discoveredIn
Which Turn the Region was discovered in.


discoveredBy

private Player discoveredBy
Which Player the Region was discovered by.


prediscovered

private boolean prediscovered
Whether the Region is already discovered when the game starts.


scoreValue

private int scoreValue
How much discovering this Region contributes to your score. This should be zero unless the Region is discoverable.


type

private Region.RegionType type
Describe type here.


children

private java.util.List<Region> children
The children Regions of this Region.

Constructor Detail

Region

public Region(Game game)
Creates a new Region instance.

Parameters:
game - a Game value

Region

public Region(Game game,
              java.lang.String id)
Creates a new Region instance.

Parameters:
game - a Game value
id - a String value

Region

public Region(Game game,
              javax.xml.stream.XMLStreamReader in)
       throws javax.xml.stream.XMLStreamException
Initiates a new Region from an XML representation.

Parameters:
game - The Game this object belongs to.
in - The input stream containing the XML.
Throws:
javax.xml.stream.XMLStreamException - if an error occurred during parsing.
Method Detail

getNameKey

public final java.lang.String getNameKey()
Get the NameKey value.

Returns:
a String value

setNameKey

public final void setNameKey(java.lang.String newNameKey)
Set the NameKey value.

Parameters:
newNameKey - The new NameKey value.

isPacific

public boolean isPacific()
Returns true if this Region is the Pacific Ocean. The Pacific Ocean is special in so far as it is the only Region that could be discovered in the original game.

Returns:
a boolean value

getName

public final java.lang.String getName()
Get the Name value.

Specified by:
getName in interface Nameable
Returns:
a String value

setName

public final void setName(java.lang.String newName)
Set the Name value.

Specified by:
setName in interface Nameable
Parameters:
newName - The new Name value.

getLabel

public StringTemplate getLabel()
Returns the name or default name of this Region.

Returns:
a String value

getTypeNameKey

public java.lang.String getTypeNameKey()

getParent

public final Region getParent()
Get the Parent value.

Returns:
a Region value

setParent

public final void setParent(Region newParent)
Set the Parent value.

Parameters:
newParent - The new Parent value.

getChildren

public final java.util.List<Region> getChildren()
Get the Children value.

Returns:
a List value

setChildren

public final void setChildren(java.util.List<Region> newChildren)
Set the Children value.

Parameters:
newChildren - The new Children value.

addChild

public void addChild(Region child)
Add a child region to this region.

Parameters:
child - The child Region to add.

isClaimable

public final boolean isClaimable()
Get the Claimable value.

Returns:
a boolean value

setClaimable

public final void setClaimable(boolean newClaimable)
Set the Claimable value.

Parameters:
newClaimable - The new Claimable value.

isDiscoverable

public final boolean isDiscoverable()
Get the Discoverable value.

Returns:
a boolean value

setDiscoverable

public final void setDiscoverable(boolean newDiscoverable)
Set the Discoverable value.

Parameters:
newDiscoverable - The new Discoverable value.

isPrediscovered

public final boolean isPrediscovered()
Get the Prediscovered value.

Returns:
a boolean value

setPrediscovered

public final void setPrediscovered(boolean newPrediscovered)
Set the Prediscovered value.

Parameters:
newPrediscovered - The new Prediscovered value.

getScoreValue

public final int getScoreValue()
Get the ScoreValue value.

Returns:
an int value

setScoreValue

public final void setScoreValue(int newScoreValue)
Set the ScoreValue value.

Parameters:
newScoreValue - The new ScoreValue value.

getType

public final Region.RegionType getType()
Get the Type value.

Returns:
a RegionType value

setType

public final void setType(Region.RegionType newType)
Set the Type value.

Parameters:
newType - The new Type value.

isRoot

public boolean isRoot()
Returns true if this is the whole map Region.

Returns:
a boolean value

isLeaf

public boolean isLeaf()
Returns true if this is a leaf node.

Returns:
a boolean value

getDiscoverableRegion

public Region getDiscoverableRegion()
Returns 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 Region value

getDiscoveredIn

public final Turn getDiscoveredIn()
Get the DiscoveredIn value.

Returns:
a Turn value

setDiscoveredIn

public final void setDiscoveredIn(Turn newDiscoveredIn)
Set the DiscoveredIn value.

Parameters:
newDiscoveredIn - The new DiscoveredIn value.

getDiscoveredBy

public final Player getDiscoveredBy()
Get the DiscoveredBy value.

Returns:
a Player value

setDiscoveredBy

public final void setDiscoveredBy(Player newDiscoveredBy)
Set the DiscoveredBy value.

Parameters:
newDiscoveredBy - The new DiscoveredBy value.

discover

public HistoryEvent discover(Player player,
                             Turn turn,
                             java.lang.String newName)
Mark the Region as discovered.

Parameters:
player - a Player value
turn - a Turn value
newName - a String value

toXMLImpl

protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out,
                         Player player,
                         boolean showAll,
                         boolean toSavedGame)
                  throws javax.xml.stream.XMLStreamException
This method writes an XML-representation of this object to the given stream.

Only attributes visible to the given Player will be added to that representation if showAll is set to false.

Specified by:
toXMLImpl in class FreeColGameObject
Parameters:
out - The target stream.
player - The Player this XML-representation should be made for, or null if showAll == true.
showAll - Only attributes visible to player will be added to the representation if showAll is set to false.
toSavedGame - If true then information that is only needed when saving a game is added.
Throws:
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.

readFromXMLImpl

protected void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
                        throws javax.xml.stream.XMLStreamException
Initialize this object from an XML-representation of this object.

Overrides:
readFromXMLImpl in class FreeColObject
Parameters:
in - The input stream with the XML.
Throws:
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.

toString

public java.lang.String toString()
Description copied from class: FreeColGameObject
Gets a string representation of the object.

Overrides:
toString in class FreeColGameObject
Returns:
A string representation of the object.

getXMLElementTagName

public static java.lang.String getXMLElementTagName()
Gets the tag name of the root element representing this object.

Returns:
"region".