Package net.sf.freecol.common.model
Class Region
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColGameObject
-
- net.sf.freecol.common.model.Region
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,Nameable
,ObjectWithId
- Direct Known Subclasses:
ServerRegion
public class Region extends FreeColGameObject implements Nameable
A named region on the map.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Region.RegionType
The type of region.
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
CHILD_TAG
protected java.util.List<Region>
children
The child regions of this region.protected boolean
claimable
Whether this region is claimable.private static java.lang.String
CLAIMABLE_TAG
protected boolean
discoverable
Whether this region is discoverable.private static java.lang.String
DISCOVERABLE_TAG
private static java.lang.String
DISCOVERED_BY_TAG
private static java.lang.String
DISCOVERED_IN_TAG
protected Player
discoveredBy
Which Player the Region was discovered by.protected Turn
discoveredIn
Which Turn the region was discovered in.private java.lang.String
discoverer
Identifier for the unit the region was discovered by.protected java.lang.String
key
The key for this region if it is a predefined one.private static java.lang.String
KEY_TAG
private static java.util.logging.Logger
logger
protected java.lang.String
name
The name of this region, given by a player.private static java.lang.String
NAME_KEY_TAG
private static java.lang.String
NAME_TAG
static java.lang.String
PACIFIC_KEY
Hardwired name key for the Pacific for the benefit of isPacific().protected Region
parent
The parent region of this region.private static java.lang.String
PARENT_TAG
static java.util.List<java.lang.String>
predefinedRegionKeys
The keys for the valid predefined regions.private static java.lang.String
SCORE_VALUE_TAG
protected int
scoreValue
How much discovering this region contributes to your score.static java.lang.String
TAG
protected Region.RegionType
type
The type of region.private static java.lang.String
TYPE_TAG
-
Fields inherited from class net.sf.freecol.common.model.FreeColGameObject
initialized
-
Fields inherited from class net.sf.freecol.common.model.FreeColObject
ARRAY_SIZE_TAG, DEFAULT_CLASS_INDEX, fcoComparator, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE_TAG, VALUE_TAG
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addChild(Region child)
Add a child region to this region.boolean
checkDiscover(Unit unit)
Check if this region is has been discovered.<T extends FreeColObject>
booleancopyIn(T other)
Copy another FreeColObject into this one if it is compatible.java.util.List<Region>
discover(Player player, Unit unit, Turn turn)
Discover this region (and its children).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?java.util.List<Region>
getChildren()
Get a list of the child regions.boolean
getClaimable()
Can this region be claimed?boolean
getDiscoverable()
Can this region be discovered?Region
getDiscoverableRegion()
Gets a discoverable Region or null.Player
getDiscoveredBy()
Gets the player that discovered the region.Turn
getDiscoveredIn()
Gets the turn the region was discovered in.java.lang.String
getDiscoverer()
Get the identifier for the unit that discovered the region.java.lang.String
getKey()
Get the key for this region.StringTemplate
getLabel()
Gets the name or default name of this Region.java.lang.String
getName()
Gets the name of thisNameable
.Region
getParent()
Gets the enclosing parent region.int
getScoreValue()
Gets the score for discovering this region.Region.RegionType
getType()
Gets the type of the region.java.lang.String
getXMLTagName()
Get the serialization tag for this object.boolean
hasName()
Does this region have a name?boolean
isLeaf()
Is this a leaf region?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.void
readAttributes(FreeColXMLReader xr)
Reads the attributes of this object from an XML stream.void
readChild(FreeColXMLReader xr)
Reads a single child object.void
readChildren(FreeColXMLReader xr)
Reads the children of this object from an XML stream.void
setChildren(java.util.List<Region> newChildren)
Sets the child regions.void
setClaimable(boolean newClaimable)
Set the claimability of this region.void
setDiscoverable(boolean newDiscoverable)
Set the discoverability of this region.void
setDiscoveredBy(Player newDiscoveredBy)
Sets the discovering player.void
setDiscoveredIn(Turn newDiscoveredIn)
Sets the discovery turn.void
setName(java.lang.String newName)
Sets the name for thisNameable
.void
setParent(Region newParent)
Sets the parent region.void
setScoreValue(int newScoreValue)
Sets the score for discovering this region.java.lang.String
toString()
protected void
writeAttributes(FreeColXMLWriter xw)
Write the attributes of this object to a stream.protected void
writeChildren(FreeColXMLWriter xw)
Write the children of this object to a stream.-
Methods inherited from class net.sf.freecol.common.model.FreeColGameObject
checkIntegrity, dispose, disposeResources, equals, fundamentalDispose, getClassIndex, getDisposables, getGame, getLinkTarget, getSpecification, hashCode, intern, internId, isDisposed, isInitialized, isInternable, readFromXML, setGame, setSpecification
-
Methods inherited from class net.sf.freecol.common.model.FreeColObject
addAbility, addFeatures, addModifier, addPropertyChangeListener, addPropertyChangeListener, apply, apply, applyModifiers, applyModifiers, arrayKey, compareIds, compareTo, containsAbilityKey, containsModifierKey, copy, copy, copy, copy, copyInCast, dumpObject, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAbilities, getAbilities, getAbilities, getAbilities, getDefenceModifiers, getDisplayObject, getFeatureContainer, getFreeColObjectClass, getFreeColObjectClassByName, getId, getIdNumber, getIdType, getIdTypeByName, getModifiers, getModifiers, getModifiers, getModifiers, getObjectClassIndex, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getSortedAbilities, getSortedModifiers, getSuffix, getSuffix, hasAbility, hasAbility, hasAbility, hasListeners, hasModifier, hasModifier, hasModifier, idEquals, invokeMethod, logFreeColObjects, readFromXMLPartial, removeAbilities, removeAbility, removeFeatures, removeModifier, removeModifiers, removePropertyChangeListener, removePropertyChangeListener, save, save, save, save, serialize, serialize, serialize, serialize, setId, toXML, toXML, toXMLPartial, toXMLPartial
-
-
-
-
Field Detail
-
logger
private static final java.util.logging.Logger logger
-
TAG
public static final java.lang.String TAG
- See Also:
- Constant Field Values
-
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.
-
type
protected Region.RegionType type
The type of region.
-
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.
-
CHILD_TAG
private static final java.lang.String CHILD_TAG
- See Also:
- Constant Field Values
-
CLAIMABLE_TAG
private static final java.lang.String CLAIMABLE_TAG
- See Also:
- Constant Field Values
-
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
-
KEY_TAG
private static final java.lang.String KEY_TAG
- See Also:
- Constant Field Values
-
NAME_TAG
private static final java.lang.String NAME_TAG
- See Also:
- Constant Field Values
-
PARENT_TAG
private static final java.lang.String PARENT_TAG
- See Also:
- Constant Field Values
-
SCORE_VALUE_TAG
private static final java.lang.String SCORE_VALUE_TAG
- See Also:
- Constant Field Values
-
TYPE_TAG
private static final java.lang.String TYPE_TAG
- See Also:
- Constant Field Values
-
NAME_KEY_TAG
private static final java.lang.String NAME_KEY_TAG
- See Also:
- Constant Field Values
-
-
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 childRegion
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
- TheUnit
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 discoveringPlayer
.unit
- The discoveringUnit
.turn
- TheTurn
of discovery.- Returns:
- A list of discovered
Region
s.
-
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 thisNameable
.
-
setName
public void setName(java.lang.String newName)
Sets the name for thisNameable
.
-
copyIn
public <T extends FreeColObject> boolean copyIn(T other)
Copy another FreeColObject into this one if it is compatible.- Overrides:
copyIn
in classFreeColGameObject
- Type Parameters:
T
- TheFreeColObject
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 classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
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 classFreeColObject
- Parameters:
xw
- TheFreeColXMLWriter
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 classFreeColGameObject
- Parameters:
xr
- TheFreeColXMLReader
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 classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
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 classFreeColObject
- Parameters:
xr
- TheFreeColXMLReader
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 classFreeColObject
- Returns:
- The tag.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classFreeColObject
-
-