|
|||||||||
| 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
An isometric map. The map is represented as a collection of tiles.
| 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. |
private class |
Map.MapIterator
Base class for internal iterators. |
static class |
Map.PathType
Constant used for given options in findPath(Unit, Tile, Tile). |
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 static java.util.logging.Logger |
logger
|
static int |
NUMBER_OF_DIRECTIONS
|
private java.util.Map<java.lang.String,Region> |
regions
|
private Tile[][] |
tiles
|
| Fields inherited from class net.sf.freecol.common.model.FreeColObject |
|---|
ARRAY_SIZE, ID_ATTRIBUTE, ID_ATTRIBUTE_TAG, PARTIAL_ATTRIBUTE |
| 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 | |
|---|---|
PathNode |
findPath(Tile start,
Tile end,
Map.PathType type)
Finds a shortest path between the given tiles. |
PathNode |
findPath(Unit unit,
Tile start,
Tile end)
Finds a shortest path between the given tiles. |
PathNode |
findPath(Unit unit,
Tile start,
Tile end,
CostDecider costDecider)
Finds a shortest path between the given tiles. |
private PathNode |
findPath(Unit unit,
Tile start,
Tile end,
Map.PathType type)
Finds a shortest path between the given tiles. |
private PathNode |
findPath(Unit unit,
Tile start,
Tile end,
Map.PathType type,
Unit carrier,
CostDecider costDecider)
Finds a shortest path between the given tiles. |
PathNode |
findPath(Unit unit,
Tile start,
Tile end,
Unit carrier)
Finds a shortest path between the given tiles. |
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)
Finds the best path to Europe. |
PathNode |
findPathToEurope(Unit unit,
Tile start,
CostDecider costDecider)
Finds the best path to Europe. |
static Map.Position |
getAdjacent(Map.Position position,
Map.Direction direction)
Gets the position adjacent to a given position, in a given direction. |
java.util.Iterator<Map.Position> |
getAdjacentIterator(Map.Position centerPosition)
Get an adjacent iterator. |
Tile |
getAdjacentTile(Map.Position position,
Map.Direction direction)
Gets the position adjacent Tile to a given Tile, in a given direction. |
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. |
Map.Direction |
getDirection(Tile t1,
Tile t2)
Returns the direction a unit needs to move in order to get from t1 to t2 |
int |
getDistance(int ax,
int ay,
int bx,
int by)
Gets the distance in tiles between two map positions. |
int |
getDistance(Map.Position position1,
Map.Position position2)
Gets the distance in tiles between two map positions. |
java.util.Iterator<Map.Position> |
getFloodFillIterator(Map.Position centerPosition)
Get a flood fill iterator. |
int |
getHeight()
Returns the height of this Map. |
Tile |
getNeighbourOrNull(Map.Direction direction,
int x,
int y)
Returns the neighbouring Tile of the given Tile in the given direction. |
Tile |
getNeighbourOrNull(Map.Direction direction,
Tile t)
Returns the neighbouring Tile of the given Tile in the given direction. |
Map.Position |
getRandomLandPosition(java.util.Random random)
Select a random land position on the map. |
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()
|
java.util.List<Tile> |
getSurroundingTiles(Tile t,
int range)
Returns all the tiles surrounding the given tile within the given range. |
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. |
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 |
isAdjacentToMapEdge(Tile tile)
Checks if the given Tile is adjacent to the edge of the
map. |
boolean |
isAdjacentToVerticalMapEdge(Tile tile)
Checks if the given Tile is adjacent to the
east or west edge of the map. |
boolean |
isLandWithinDistance(int x,
int y,
int distance)
Searches for land within the given radius. |
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. |
PathNode |
search(Tile startTile,
GoalDecider gd,
CostDecider costDecider,
int maxTurns)
Finds a path to a goal determined by the given GoalDecider. |
PathNode |
search(Unit unit,
GoalDecider gd,
int maxTurns)
Finds a path to a goal determined by the given GoalDecider. |
PathNode |
search(Unit unit,
GoalDecider gd,
int maxTurns,
Unit carrier)
Finds a path to a goal determined by the given GoalDecider. |
PathNode |
search(Unit unit,
Tile startTile,
GoalDecider gd,
CostDecider costDecider,
int maxTurns)
Finds a path to a goal determined by the given GoalDecider. |
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. |
PathNode |
search(Unit unit,
Tile startTile,
GoalDecider gd,
int maxTurns)
Finds a path to a goal determined by the given GoalDecider. |
PathNode |
search(Unit unit,
Tile startTile,
GoalDecider gd,
int maxTurns,
Unit carrier)
Finds a path to a goal determined by the given GoalDecider. |
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. |
| Methods inherited from class net.sf.freecol.common.model.FreeColGameObject |
|---|
addModelMessage, addModelMessage, addModelMessage, addToRemoveElement, dispose, equals, equals, getFreeColGameObject, getFreeColGameObject, getGame, getGameOptions, getIntegerID, hashCode, hasID, isDisposed, isUninitialized, readFromXML, readFromXMLPartialByClass, setFakeID, setGame, setId, toSavedXML, toString, toXML, toXMLImpl, toXMLPartialByClass, updateFreeColGameObject, updateID |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private static final java.util.logging.Logger logger
public static final int NUMBER_OF_DIRECTIONS
public static final int COST_INFINITY
findPath(Unit, Tile, Tile).
private Tile[][] tiles
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 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 value
public PathNode findPath(Tile start,
Tile end,
Map.PathType type)
Tile at
the end will not be checked against the
options.
PathNode.getTurns(), PathNode.getTotalTurns() and
PathNode.getMovesLeft() will all return -1 for the
generated PathNodes.
findPath(Unit, Tile, Tile) whenever possible.
start - The Tile in which the path starts from.end - The end of the path.type - One of: Map.PathType.BOTH_LAND_AND_SEA,
Map.PathType.BOTH_LAND_AND_SEA, Map.PathType.ONLY_LAND and
Map.PathType.ONLY_SEA.
PathNode for the first tile in the path. Calling
PathNode.getTile() on this object, will return the
Tile right after the specified starting tile, and
PathNode.getDirection() will return the direction you need
to take in order to reach that tile. This method returns
null if no path is found.
java.lang.IllegalArgumentException - if either start or end are
null.findPath(Unit, Tile, Tile),
Unit.findPath(Tile)
public PathNode findPath(Unit unit,
Tile start,
Tile end)
Tile at
the end will not be checked against the unit's
legal moves.
unit - The Unit that should be used to determine
whether or not a path is legal.start - The Tile in which the path starts from.end - The end of the path.
PathNode for the first tile in the path. Calling
PathNode.getTile() on this object, will return the
Tile right after the specified starting tile, and
PathNode.getDirection() will return the direction you need
to take in order to reach that tile. This method returns
null if no path is found.
java.lang.IllegalArgumentException - if either unit, start or
end are null.findPath(Tile, Tile, PathType),
Unit.findPath(Tile)
public PathNode findPath(Unit unit,
Tile start,
Tile end,
CostDecider costDecider)
Tile at
the end will not be checked against the unit's
legal moves.
unit - The Unit that should be used to determine
whether or not a path is legal.start - The Tile in which the path starts from.end - The end of the path.costDecider - The object responsible for determining the cost.
PathNode for the first tile in the path. Calling
PathNode.getTile() on this object, will return the
Tile right after the specified starting tile, and
PathNode.getDirection() will return the direction you need
to take in order to reach that tile. This method returns
null if no path is found.
java.lang.IllegalArgumentException - if either unit, start or
end are null.findPath(Tile, Tile, PathType),
Unit.findPath(Tile)
public PathNode findPath(Unit unit,
Tile start,
Tile end,
Unit carrier,
CostDecider costDecider)
Tile at
the end will not be checked against the unit's
legal moves.
unit - The Unit that should be used to determine
whether or not a path is legal.start - The Tile in which the path starts from.end - The end of the path.carrier - A carrier that currently holds the unit, or
null if the unit is not
presently on a carrier.costDecider - The object responsible for determining the cost.
PathNode for the first tile in the path. Calling
PathNode.getTile() on this object, will return the
Tile right after the specified starting tile, and
PathNode.getDirection() will return the direction you need
to take in order to reach that tile. This method returns
null if no path is found.
java.lang.IllegalArgumentException - if either unit, start or
end are null.findPath(Tile, Tile, PathType),
Unit.findPath(Tile)
public PathNode findPath(Unit unit,
Tile start,
Tile end,
Unit carrier)
Tile at
the end will not be checked against the unit's
legal moves.
unit - The Unit that should be used to determine
whether or not a path is legal.start - The Tile in which the path starts from.end - The end of the path.carrier - A carrier that currently holds the unit, or
null if the unit is not
presently on a carrier.
PathNode for the first tile in the path. Calling
PathNode.getTile() on this object, will return the
Tile right after the specified starting tile, and
PathNode.getDirection() will return the direction you need
to take in order to reach that tile. This method returns
null if no path is found.
java.lang.IllegalArgumentException - if either unit, start or
end are null.findPath(Tile, Tile, PathType),
Unit.findPath(Tile)
private PathNode findPath(Unit unit,
Tile start,
Tile end,
Map.PathType type)
Tile at
the end will not be checked against validity (neither the
options nor allowed movement by the unit.
unit - The Unit that should be used to determine
whether or not a path is legal. The options are
used instead if unit == null.start - The Tile in which the path starts from.end - The end of the path.type - One of: Map.PathType.BOTH_LAND_AND_SEA,
Map.PathType.BOTH_LAND_AND_SEA, Map.PathType.ONLY_LAND and
Map.PathType.ONLY_SEA. This argument if ignored if
unit != null.
PathNode for the first tile in the path. Calling
PathNode.getTile() on this object, will return the
Tile right after the specified starting tile, and
PathNode.getDirection() will return the direction you need
to take in order to reach that tile. This method returns
null if no path is found.
java.lang.IllegalArgumentException - if either start or end are
null.
java.lang.IllegalArgumentException - if start == end.
private PathNode findPath(Unit unit,
Tile start,
Tile end,
Map.PathType type,
Unit carrier,
CostDecider costDecider)
Tile at
the end will not be checked against validity (neither the
options nor allowed movement by the unit.
unit - an Unit valuestart - The Tile in which the path starts from.end - The end of the path.type - One of: Map.PathType.BOTH_LAND_AND_SEA,
Map.PathType.BOTH_LAND_AND_SEA, Map.PathType.ONLY_LAND and
Map.PathType.ONLY_SEA. This argument if ignored if
unit != null.carrier - A carrier that currently holds the unit, or
null if the unit is not
presently on a carrier.costDecider - The object responsible for determining the cost.
PathNode for the first tile in the path. Calling
PathNode.getTile() on this object, will return the
Tile right after the specified starting tile, and
PathNode.getDirection() will return the direction you need
to take in order to reach that tile. This method returns
null if no path is found.
java.lang.IllegalArgumentException - if either start or end are
null.
java.lang.IllegalArgumentException - if either start or end are
null.
public PathNode search(Unit unit,
GoalDecider gd,
int maxTurns)
GoalDecider.
GoalDecider is typically defined inline to serve a
specific need.
unit - The Unit to find the path for.gd - The object responsible for determining whether a given
PathNode is a goal or not.maxTurns - The maximum number of turns the given Unit is
allowed to move. This is the maximum search range for a goal.
GoalDecider.
public PathNode search(Unit unit,
Tile startTile,
GoalDecider gd,
int maxTurns)
GoalDecider.
GoalDecider is typically defined inline to serve a
specific need.
unit - The Unit to find the 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.maxTurns - The maximum number of turns the given Unit is
allowed to move. This is the maximum search range for a goal.
GoalDecider.
public PathNode search(Unit unit,
GoalDecider gd,
int maxTurns,
Unit carrier)
GoalDecider.
GoalDecider is typically defined inline to serve a
specific need.
unit - The Unit to find the path for.gd - The object responsible for determining wether a given
PathNode is a goal or not.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 PathNode search(Tile startTile,
GoalDecider gd,
CostDecider costDecider,
int maxTurns)
GoalDecider.
GoalDecider is typically defined inline to serve a
specific need.
startTile - The Tile to start the search from.gd - The object responsible for determining whether a given
PathNode is a goal or not.costDecider - The object responsible for determining the cost.maxTurns - The maximum number of turns the given Unit is
allowed to move. This is the maximum search range for a goal.
GoalDecider.
public PathNode search(Unit unit,
Tile startTile,
GoalDecider gd,
CostDecider costDecider,
int maxTurns)
GoalDecider.
GoalDecider is typically defined inline to serve a
specific need.
unit - The Unit to find the 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 - The object responsible for determining the cost.maxTurns - The maximum number of turns the given Unit is
allowed to move. This is the maximum search range for a goal.
GoalDecider.
public PathNode search(Unit unit,
Tile startTile,
GoalDecider gd,
int maxTurns,
Unit carrier)
GoalDecider.
GoalDecider is typically defined inline to serve a
specific need.
unit - an Unit valuestartTile - The Tile to start the search from.gd - The object responsible for determining whether a given
PathNode is a goal or not.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 PathNode search(Unit unit,
Tile startTile,
GoalDecider gd,
CostDecider costDecider,
int maxTurns,
Unit carrier)
GoalDecider.
GoalDecider is typically defined inline to serve a
specific need.
unit - an Unit valuestartTile - The Tile to start the search from.gd - The object responsible for determining whether a given
PathNode is a goal or not.costDecider - The object responsible for determining the 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 isAdjacentToMapEdge(Tile tile)
Tile is adjacent to the edge of the
map.
tile - The Tile to be checked.
true if the given tile is at the edge of the map.public boolean isAdjacentToVerticalMapEdge(Tile tile)
Tile is adjacent to the
east or west edge of the map.
tile - The Tile to be checked.
true if the given tile is at the edge of the map.
public PathNode findPathToEurope(Unit unit,
Tile start)
Europe.
unit - The Unit that should be used to determine
whether or not a path is legal.start - The starting Tile.
null if no target can be
found.Europe
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.
null if no target can be
found.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 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 Tile getNeighbourOrNull(Map.Direction direction,
Tile t)
direction - The direction in which the neighbour is located given t.t - The Tile to get a neighbour of.
public Tile getNeighbourOrNull(Map.Direction direction,
int x,
int y)
direction - The direction in which the neighbour is located given the base
tile.x - The base tile X coordinate.y - The base tile Y coordinate.
public java.util.List<Tile> getSurroundingTiles(Tile t,
int range)
t - The tile that lies on the center of the tiles to return.range - How far away do we need to go starting from the center tile.
public Map.WholeMapIterator getWholeMapIterator()
Iterator of every Tile on the map.
Iterator.
public static Map.Position getAdjacent(Map.Position position,
Map.Direction direction)
position - The positiondirection - The direction (N, NE, E, etc.)
public Tile getAdjacentTile(Map.Position position,
Map.Direction direction)
position - The positiondirection - The direction (N, NE, E, etc.)
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 Map.Position getRandomLandPosition(java.util.Random random)
random - A Random number source.
public int getDistance(Map.Position position1,
Map.Position position2)
position1 - The first position.position2 - The second position.
public int getDistance(int ax,
int ay,
int bx,
int by)
ax - Position A x-coordinateay - Position A y-coordinatebx - Position B x-coordinateby - Position B y-coordinate
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 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()
public java.lang.Iterable<Tile> getAllTiles()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||