Package net.sf.freecol.server.model
Class ServerRegion
- java.lang.Object
-
- net.sf.freecol.common.model.FreeColObject
-
- net.sf.freecol.common.model.FreeColGameObject
-
- net.sf.freecol.common.model.Region
-
- net.sf.freecol.server.model.ServerRegion
-
- All Implemented Interfaces:
java.lang.Comparable<FreeColObject>
,Nameable
,ObjectWithId
public class ServerRegion extends Region
The server version of a region.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class net.sf.freecol.common.model.Region
Region.RegionType
-
-
Field Summary
Fields Modifier and Type Field Description private java.awt.Rectangle
bounds
A Rectangle that contains all points of the Region.static int
PACIFIC_SCORE_VALUE
Score for being first to discover the pacific.private int
size
The size of this Region (number of Tiles).-
Fields inherited from class net.sf.freecol.common.model.Region
children, claimable, discoverable, discoveredBy, discoveredIn, key, name, PACIFIC_KEY, parent, predefinedRegionKeys, scoreValue, TAG, type
-
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
-
-
Constructor Summary
Constructors Modifier Constructor Description ServerRegion(Game game, java.lang.String id)
Trivial constructor for serialization.private
ServerRegion(Game game, java.lang.String key, Region.RegionType type, Region parent)
Create a new fixed server region.ServerRegion(Game game, Region region)
Constructor for copying in a new region from an imported game.ServerRegion(Game game, Region.RegionType type)
Create a new discoverable server region of a given type.private
ServerRegion(Map map, java.lang.String key, Region.RegionType type, Region parent)
Create a new fixed server region.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addTile(Tile tile)
Add the given tile to this region.boolean
containsCenter(ServerRegion other)
Does this region contain the center of another?void
csDiscover(Player player, Unit unit, Turn turn, java.lang.String newName, ChangeSet cs)
Discover this region.private static int
fillOcean(Map map, Tile tile, ServerRegion region, java.awt.Rectangle bounds)
Flood fill ocean regions.java.awt.Rectangle
getBounds()
Get the bounding rectangle for this region.int[]
getCenter()
Get the center of the regions bounds.int
getSize()
Get the number of tiles in this region.boolean
isGeographic()
Is this a geographic region?static java.util.List<ServerRegion>
requireFixedRegions(Map map, LogBuilder lb)
Make the fixed regions if they do not exist in a given map.void
setSize(int size)
Set the number of tiles in this region.java.lang.String
toString()
-
Methods inherited from class net.sf.freecol.common.model.Region
addChild, checkDiscover, copyIn, discover, getChildren, getClaimable, getDiscoverable, getDiscoverableRegion, getDiscoveredBy, getDiscoveredIn, getDiscoverer, getKey, getLabel, getName, getParent, getScoreValue, getType, getXMLTagName, hasName, isLeaf, isPacific, readAttributes, readChild, readChildren, setChildren, setClaimable, setDiscoverable, setDiscoveredBy, setDiscoveredIn, setName, setParent, setScoreValue, writeAttributes, writeChildren
-
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
-
PACIFIC_SCORE_VALUE
public static final int PACIFIC_SCORE_VALUE
Score for being first to discover the pacific.- See Also:
- Constant Field Values
-
size
private int size
The size of this Region (number of Tiles).
-
bounds
private java.awt.Rectangle bounds
A Rectangle that contains all points of the Region.
-
-
Constructor Detail
-
ServerRegion
public ServerRegion(Game game, java.lang.String id)
Trivial constructor for serialization.- Parameters:
game
- TheGame
to create in.id
- The object identifier.
-
ServerRegion
public ServerRegion(Game game, Region region)
Constructor for copying in a new region from an imported game.- Parameters:
game
- TheGame
to create in.region
- ARegion
to copy.
-
ServerRegion
public ServerRegion(Game game, Region.RegionType type)
Create a new discoverable server region of a given type.- Parameters:
game
- TheGame
to create in.type
- TheRegionType
to use.
-
ServerRegion
private ServerRegion(Map map, java.lang.String key, Region.RegionType type, Region parent)
Create a new fixed server region.- Parameters:
map
- TheMap
to create in.key
- The key for the region.type
- TheRegionType
to use.parent
- TheRegion
to be the parent of this one.
-
ServerRegion
private ServerRegion(Game game, java.lang.String key, Region.RegionType type, Region parent)
Create a new fixed server region.- Parameters:
game
- TheGame
to create in.key
- The key for the region.type
- TheRegionType
to use.parent
- TheRegion
to be the parent of this one.
-
-
Method Detail
-
getSize
public final int getSize()
Get the number of tiles in this region.- Returns:
- The number of tiles in this region.
-
setSize
public final void setSize(int size)
Set the number of tiles in this region.- Parameters:
size
- The new number of tiles.
-
getBounds
public final java.awt.Rectangle getBounds()
Get the bounding rectangle for this region.- Returns:
- The bounding
Rectangle
.
-
isGeographic
public final boolean isGeographic()
Is this a geographic region?- Returns:
- True if this is a geographic region.
-
getCenter
public int[] getCenter()
Get the center of the regions bounds.- Returns:
- An two member array [x,y] of the center coordinate.
-
containsCenter
public boolean containsCenter(ServerRegion other)
Does this region contain the center of another?- Parameters:
other
- The otherServerRegion
to check.- Returns:
- True if the center of the other region is within this one.
-
addTile
public void addTile(Tile tile)
Add the given tile to this region.- Parameters:
tile
- ATile
to add.
-
csDiscover
public void csDiscover(Player player, Unit unit, Turn turn, java.lang.String newName, ChangeSet cs)
Discover this region.- Parameters:
player
- The discoveringPlayer
.unit
- The discoveringUnit
.turn
- The discoveryTurn
.newName
- The name of the region.cs
- AChangeSet
to update.
-
requireFixedRegions
public static java.util.List<ServerRegion> requireFixedRegions(Map map, LogBuilder lb)
Make the fixed regions if they do not exist in a given map.- Parameters:
map
- TheMap
to check.lb
- ALogBuilder
to log to.- Returns:
- A list of fixed server regions.
-
fillOcean
private static int fillOcean(Map map, Tile tile, ServerRegion region, java.awt.Rectangle bounds)
Flood fill ocean regions.- Parameters:
map
- TheMap
to fill in.tile
- A valid startingTile
.region
- AServerRegion
to fill with.bounds
- ARectangle
that bounds the filling.- Returns:
- The number of tiles filled.
-
-