|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.sf.freecol.common.model.FreeColObject
net.sf.freecol.common.model.FreeColGameObject
net.sf.freecol.common.model.Map
public class Map
A rectangular isometric map. The map is represented as a
two-dimensional array of tiles. Off-map destinations, such as
Europe, can be reached via the HighSeas.
In theory, a Game might contain several Map instances
connected by the HighSeas.
| Nested Class Summary | |
|---|---|
private class |
Map.AdjacentIterator
|
private class |
Map.BorderAdjacentIterator
|
class |
Map.CircleIterator
An interator returning positions in a spiral starting at a given center tile. |
static class |
Map.Direction
The directions a Unit can move to. |
static class |
Map.Layer
The layers included in the map. |
private class |
Map.MapIterator
Base class for internal iterators. |
static class |
Map.Position
Represents a position on the Map. |
class |
Map.WholeMapIterator
|
| Field Summary | |
|---|---|
static int |
COST_INFINITY
The infinity cost as used by #findPath(Unit, Tile, Tile). |
private float |
latitudePerRow
Variable used to convert rows to latitude. |
private Map.Layer |
layer
The highest map layer included. |
private static java.util.logging.Logger |
logger
|
private int |
maximumLatitude
The latitude of the southern edge of the map. |
private int |
minimumLatitude
The latitude of the northern edge of the map. |
static int |
POLAR_HEIGHT
|
private java.util.Map<java.lang.String,Region> |
regions
|
private Tile[][] |
tiles
|
| 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 | |
|---|---|
Map(Game game,
java.lang.String id)
Initiates a new Map with the given ID. |
|
Map(Game game,
Tile[][] tiles)
Create a new Map from a collection of tiles. |
|
Map(Game game,
javax.xml.stream.XMLStreamReader in)
Create a new Map from an Element in a
DOM-parsed XML-tree. |
|
| Method Summary | |
|---|---|
boolean |
add(Locatable locatable)
Adds a Locatable to this Location. |
private void |
calculateLatitudePerRow()
Calculates the LatitudePerRow value. |
boolean |
canAdd(Locatable locatable)
Checks whether or not the specified locatable may be added to this Location. |
boolean |
contains(Locatable locatable)
Checks if this Location contains the specified
Locatable. |
PathNode |
findPath(Unit unit,
Tile start,
Tile end,
Unit carrier,
CostDecider costDecider)
Finds a shortest path between the given tiles. |
PathNode |
findPathToEurope(Tile start)
Finds the best path to Europe independently of any
unit. |
PathNode |
findPathToEurope(Unit unit,
Tile start,
CostDecider costDecider)
Finds the best path to Europe. |
java.util.Iterator<Map.Position> |
getAdjacentIterator(Map.Position centerPosition)
Get an adjacent iterator. |
java.lang.Iterable<Tile> |
getAllTiles()
Make the map usable as a parameter in the for-loop. |
java.util.Iterator<Map.Position> |
getBorderAdjacentIterator(Map.Position centerPosition)
Get a border adjacent iterator. |
Map.CircleIterator |
getCircleIterator(Map.Position center,
boolean isFilled,
int radius)
Get a circle iterator. |
java.util.List<Tile> |
getClaimableTiles(Player player,
Tile centerTile,
int radius)
Gets the list of tiles that might be claimable by a settlement. |
Colony |
getColony()
Returns null. |
Map.Direction |
getDirection(Tile t1,
Tile t2)
Returns the direction a unit needs to move in order to get from t1 to t2 |
java.util.Iterator<Map.Position> |
getFloodFillIterator(Map.Position centerPosition)
Get a flood fill iterator. |
GoodsContainer |
getGoodsContainer()
Gets the GoodsContainer this Location use
for storing it's goods. |
int |
getHeight()
Returns the height of this Map. |
int |
getLatitude(int row)
Get the latitude of the given map row. |
float |
getLatitudePerRow()
Get the LatitudePerRow value. |
Map.Layer |
getLayer()
Get the Layer value. |
StringTemplate |
getLocationName()
Returns the name of this location. |
StringTemplate |
getLocationNameFor(Player player)
Returns the name of this location for a particular player. |
int |
getMaximumLatitude()
Get the MaximumLatitude value. |
int |
getMinimumLatitude()
Get the MinimumLatitude value. |
Region |
getRegion(java.lang.String id)
Returns the Region with the given ID. |
Region |
getRegionByName(java.lang.String id)
Returns the Region with the given name. |
java.util.Collection<Region> |
getRegions()
Returns a Collection containing all map regions. |
int |
getRow(int latitude)
Get the map row with the given latitude. |
Settlement |
getSettlement()
Returns null. |
Tile |
getTile()
Returns null. |
Tile |
getTile(int x,
int y)
Returns the Tile at position (x, y). |
Tile |
getTile(Map.Position p)
Returns the Tile at a requested position. |
int |
getUnitCount()
Returns -1 |
java.util.Iterator<Unit> |
getUnitIterator()
Returns an Iterator for an empty list. |
java.util.List<Unit> |
getUnitList()
Returns an empty list. |
Map.WholeMapIterator |
getWholeMapIterator()
Gets an Iterator of every Tile on the map. |
int |
getWidth()
Returns the width of this Map. |
static java.lang.String |
getXMLElementTagName()
Returns the tag name of the root element representing this object. |
boolean |
isLandWithinDistance(int x,
int y,
int distance)
Searches for land within the given radius. |
boolean |
isPolar(Tile tile)
Is a tile in the map in a polar region? |
boolean |
isValid(int x,
int y)
Checks whether a position is valid (within the map limits). |
static boolean |
isValid(int x,
int y,
int width,
int height)
Checks if the given position is valid. |
boolean |
isValid(Map.Position position)
Checks whether a position is valid (within the map limits). |
static boolean |
isValid(Map.Position position,
int width,
int height)
Checks whether a position is valid. |
protected void |
readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
Initialize this object from an XML-representation of this object. |
boolean |
remove(Locatable locatable)
Removes a Locatable from this Location. |
PathNode |
search(Unit unit,
Tile startTile,
GoalDecider gd,
CostDecider costDecider,
int maxTurns,
Unit carrier)
Finds a path to a goal determined by the given GoalDecider. |
void |
setLayer(Map.Layer newLayer)
Set the Layer value. |
void |
setMaximumLatitude(int newMaximumLatitude)
Set the MaximumLatitude value. |
void |
setMinimumLatitude(int newMinimumLatitude)
Set the MinimumLatitude value. |
void |
setRegion(Region region)
Describe setRegion method here. |
void |
setTile(Tile tile,
int x,
int y)
Sets the given tile the the given coordinates. |
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. |
protected void |
writeAttributes(javax.xml.stream.XMLStreamWriter out,
Player player,
boolean showAll,
boolean toSavedGame)
|
protected void |
writeChildren(javax.xml.stream.XMLStreamWriter out,
Player player,
boolean showAll,
boolean toSavedGame)
|
| 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, toString, toXML, toXMLImpl, toXMLPartialByClass, updateFreeColGameObject |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Methods inherited from interface net.sf.freecol.common.model.Location |
|---|
getId |
| Field Detail |
|---|
private static final java.util.logging.Logger logger
public static final int POLAR_HEIGHT
public static final int COST_INFINITY
#findPath(Unit, Tile, Tile).
private Tile[][] tiles
private Map.Layer layer
private int minimumLatitude
private int maximumLatitude
private float latitudePerRow
private final java.util.Map<java.lang.String,Region> regions
| Constructor Detail |
|---|
public Map(Game game,
Tile[][] tiles)
Map from a collection of tiles.
game - The Game this map belongs to.tiles - The 2D array of tiles.
public Map(Game game,
javax.xml.stream.XMLStreamReader in)
throws javax.xml.stream.XMLStreamException
Map from an Element in a
DOM-parsed XML-tree.
game - The Game this map belongs to.in - The input stream containing the XML.
javax.xml.stream.XMLStreamException - if a problem was encountered during parsing.
public Map(Game game,
java.lang.String id)
Map with the given ID. The object should
later be initialized by calling either
FreeColGameObject.readFromXML(XMLStreamReader) or
FreeColObject.readFromXMLElement(Element).
game - The Game in which this object belong.id - The unique identifier for this object.| Method Detail |
|---|
public java.util.Collection<Region> getRegions()
public final Map.Layer getLayer()
Layer value.
Layer valuepublic final void setLayer(Map.Layer newLayer)
Layer value.
newLayer - The new Layer value.public final int getMinimumLatitude()
MinimumLatitude value.
int valuepublic final void setMinimumLatitude(int newMinimumLatitude)
MinimumLatitude value.
newMinimumLatitude - The new MinimumLatitude value.public final int getMaximumLatitude()
MaximumLatitude value.
int valuepublic final void setMaximumLatitude(int newMaximumLatitude)
MaximumLatitude value.
newMaximumLatitude - The new MaximumLatitude value.public final float getLatitudePerRow()
LatitudePerRow value.
float valueprivate final void calculateLatitudePerRow()
LatitudePerRow value.
public int getLatitude(int row)
row - an int value
int valuepublic int getRow(int latitude)
latitude - an int value
int valuepublic Region getRegion(java.lang.String id)
Region with the given ID.
id - a String value
Region valuepublic Region getRegionByName(java.lang.String id)
Region with the given name.
id - a String value
Region valuepublic void setRegion(Region region)
setRegion method here.
region - a Region valuepublic boolean isPolar(Tile tile)
tile - The Tile to examine.
public java.util.List<Tile> getClaimableTiles(Player player,
Tile centerTile,
int radius)
player - The Player that intends to found a settlement.centerTile - The intended settlement center Tile.radius - The radius of the settlement.
public PathNode findPath(Unit unit,
Tile start,
Tile end,
Unit carrier,
CostDecider costDecider)
unit - The Unit to find the path for.start - The Tile in which the path starts from.end - The Tile at the end of the path.carrier - An optional carrier Unit that
currently holds the unit, or null if it is
not presently on a carrier.costDecider - An optional CostDecider for
determining the movement costs (uses default cost deciders
for the unit/s if not provided).
PathNode for the first tile in the
path, or null if none found.
java.lang.IllegalArgumentException - If start, end, or unitnull, or start equals end.
public PathNode findPathToEurope(Unit unit,
Tile start,
CostDecider costDecider)
Europe.
unit - The Unit that should be used to determine
whether or not a path is legal.start - The starting Tile.costDecider - An optional CostDecider
responsible for determining the path cost.
Europepublic PathNode findPathToEurope(Tile start)
Europe independently of any
unit. This method is meant to be executed by the server/AI
code, with complete knowledge of the map
start - The starting Tile.
null if no target can be
found.Europe
public PathNode search(Unit unit,
Tile startTile,
GoalDecider gd,
CostDecider costDecider,
int maxTurns,
Unit carrier)
GoalDecider.
A GoalDecider is typically defined inline to serve a
specific need.
Using Dijkstra's algorithm with a closedList for marking the
visited nodes and using a PriorityQueue for getting the next
edge with the least cost. This implementation could be improved
by having the visited attribute stored on each Tile in order to
avoid both of the HashMaps currently being used to serve this
purpose.
unit - The Unit to find a path for.startTile - The Tile to start the search from.gd - The object responsible for determining whether a
given PathNode is a goal or not.costDecider - An optional CostDecider
responsible for determining the path cost.maxTurns - The maximum number of turns the given
Unit is allowed to move. This is the
maximum search range for a goal.carrier - The carrier the unit is currently
onboard or null if the unit is
either not onboard a carrier or should not use the
carrier while finding the path.
GoalDecider.
public boolean isLandWithinDistance(int x,
int y,
int distance)
x - X-component of the position to search from.y - Y-component of the position to search from.distance - The radius that should be searched for land, given in number
of tiles.
true if there is land within
the given radius and false otherwise.public Tile getTile(Map.Position p)
p - The position.
public Tile getTile(int x,
int y)
x - The x-coordinate of the Tile.y - The y-coordinate of the Tile.
null if the
position is invalid.
public void setTile(Tile tile,
int x,
int y)
x - The x-coordinate of the Tile.y - The y-coordinate of the Tile.tile - The Tile.public int getWidth()
public int getHeight()
public Map.Direction getDirection(Tile t1,
Tile t2)
t1 to t2
t1 - The tile to move from.t2 - The target tile if moving from t1
in the direction returned by this method.
t1
in order to reach t2, or null if the two
specified tiles are not neighbours.public Map.WholeMapIterator getWholeMapIterator()
Iterator of every Tile on the map.
Iterator.public java.util.Iterator<Map.Position> getAdjacentIterator(Map.Position centerPosition)
centerPosition - The center position to iterate around
public java.util.Iterator<Map.Position> getBorderAdjacentIterator(Map.Position centerPosition)
centerPosition - The center position to iterate around
public java.util.Iterator<Map.Position> getFloodFillIterator(Map.Position centerPosition)
centerPosition - The center position to iterate around
public Map.CircleIterator getCircleIterator(Map.Position center,
boolean isFilled,
int radius)
center - The center position to iterate aroundisFilled - True to get all of the positions in the circleradius - Radius of circle
public boolean isValid(Map.Position position)
position - The position
public boolean isValid(int x,
int y)
x - X coordinatey - Y coordinate
public static boolean isValid(Map.Position position,
int width,
int height)
position - The positionwidth - The width of the map.height - The height of the map.
true if the given position is
within the bounds of the map and false otherwise
public static boolean isValid(int x,
int y,
int width,
int height)
x - The x-coordinate of the position.y - The y-coordinate of the position.width - The width of the map.height - The height of the map.
true if the given position is
within the bounds of the map and false otherwisepublic java.lang.Iterable<Tile> getAllTiles()
public Tile getTile()
null.
getTile in interface Locationnullpublic StringTemplate getLocationName()
getLocationName in interface Locationpublic StringTemplate getLocationNameFor(Player player)
getLocationNameFor in interface Locationplayer - The Player to return the name for.
public boolean add(Locatable locatable)
Locatable to this Location. It the given
Locatable is a Unit, its location is set to its entry location,
otherwise nothing happens.
add in interface Locationlocatable - The Locatable to add to this Location.public boolean remove(Locatable locatable)
Locatable from this Location.
remove in interface Locationlocatable - The Locatable to remove from this Location.public boolean contains(Locatable locatable)
Location contains the specified
Locatable.
contains in interface Locationlocatable - The Locatable to test the presence of.
Locatable is
on this Location and
public boolean canAdd(Locatable locatable)
Location.
canAdd in interface Locationlocatable - The Locatable to add.
public int getUnitCount()
-1
getUnitCount in interface Location-1public java.util.List<Unit> getUnitList()
getUnitList in interface Locationpublic java.util.Iterator<Unit> getUnitIterator()
Iterator for an empty list.
getUnitIterator in interface LocationIterator.public GoodsContainer getGoodsContainer()
GoodsContainer this Location use
for storing it's goods.
getGoodsContainer in interface LocationGoodsContainer or null if the
Location cannot store any goods.public Settlement getSettlement()
null.
getSettlement in interface Locationnullpublic Colony getColony()
null.
getColony in interface Locationnull
protected void toXMLImpl(javax.xml.stream.XMLStreamWriter out,
Player player,
boolean showAll,
boolean toSavedGame)
throws javax.xml.stream.XMLStreamException
Player will be added
to that representation if showAll is set to
false.
toXMLImpl in class FreeColGameObjectout - 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.
javax.xml.stream.XMLStreamException - if there are any problems writing to the stream.
protected void writeAttributes(javax.xml.stream.XMLStreamWriter out,
Player player,
boolean showAll,
boolean toSavedGame)
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
protected void writeChildren(javax.xml.stream.XMLStreamWriter out,
Player player,
boolean showAll,
boolean toSavedGame)
throws javax.xml.stream.XMLStreamException
javax.xml.stream.XMLStreamException
protected void readFromXMLImpl(javax.xml.stream.XMLStreamReader in)
throws javax.xml.stream.XMLStreamException
readFromXMLImpl in class FreeColObjectin - The input stream with the XML.
javax.xml.stream.XMLStreamException - if a problem was encountered
during parsing.public static java.lang.String getXMLElementTagName()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||