Package megamek.common.board
Class Board
java.lang.Object
megamek.common.board.Board
- All Implemented Interfaces:
Serializable
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final String
static final int
static final String
protected Vector<BoardListener>
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addBoardListener
(BoardListener listener) Adds the specified board listener to receive board events from this board.void
addDeploymentZone
(int zoneId, HexArea hexArea) Adds a deployment zone with the given ID and the hexes described by the given HexArea to this board, replacing the previously present zone of that ID, if there had been one.void
addInfernoTo
(Coords coords, Inferno round, int hits) Record that the given coordinates have received a hit from an inferno.void
addSpecialHexDisplay
(Coords coords, SpecialHexDisplay shd) Adds the given SHD at the given coords to this board.void
addSpecialHexDisplay
(Coords coords, SpecialHexDisplay shd, boolean fireEvent) Adds the given SHD at the given coords to this board.void
Add the given tag string to the board's tags list.static boolean
boardIsSize
(File filepath, BoardDimensions size) Checks if a board file is the specified size.void
void
collapseBuilding
(Vector<Coords> coords) Collapse a vector of building hexes.void
collapseBuilding
(Coords coords) The given building hex has collapsed.void
collapseBuilding
(Building bldg) The given building has collapsed.boolean
contains
(int x, int y) Determines whether this Board "contains" the specified Coords.boolean
contains
(BoardLocation location) Determines whether this Board "contains" the specified location.boolean
Determines whether this Board "contains" the specified Coords.boolean
static Board
createEmptyBoard
(int width, int height) static int
decodeCustomDeploymentZoneID
(int zoneID) Use this method to convert a deployment zone ID as represented in the UI zone selectors (e.g.embeddedBoardPosition
(int boardId) static int
encodeCustomDeploymentZoneID
(int zoneID) Use this method to convert a deployment zone ID as stored in the board to a number suitable for representation in the UI zone selectors (e.g.exitsAsIntList
(int exits) Gets every annotation on the map.Gets the annotations associated with a hex.int
getBuildingAt
(Coords coords) Get the building at the given coordinates.getCustomDeploymentZone
(int zoneID) Gets all the coordinates in the given custom deployment zoneGets the IDs of all custom deployment zones defined for this board.Gets the description of the map.int
getEmbeddedBoardAt
(Coords coords) int
int
getHex
(int x, int y) Determines if this Board contains the (x, y) Coords, and if so, returns the Hex at that position.Returns the Hex at the given Coords, both of which may be null.getHexes
(Collection<Coords> coords) Returns a list of Hexes at the given coords.getHexInDir
(int x, int y, int dir) Gets the hex in the specified direction from the specified starting coordinates.getHexInDir
(Coords c, int dir) Get an enumeration of all coordinates with infernos still burning.int
int
int
getOppositeEdge
(int cardinalEdge) Determine the opposite edge from the given edge Returns START_NONE for non-cardinal edges (North, South, West, East)boolean
Get the current value of the "road auto-exit" option.static BoardDimensions
Inspect specified board file and return its dimensions.static Board
getSkyBoard
(int width, int height) Returns a new atmospheric (low altitude) board with no terrain (sky map) of the given size.static Board
getSpaceBoard
(int width, int height) Returns a new space board of the given size.getSpecialHexDisplay
(Coords coords) getTags()
Inspects the given board file and returns a set of its tags.int
getWidth()
protected void
initializeAll
(List<String> errors) Initialize all hexesvoid
Rebuilds automatic terrains for the whole board, such as incline highlighting.void
initializeAround
(int x, int y) Initialize a hex and the hexes around itvoid
initializeHex
(int x, int y) Initializes a hex in its surroundings.static int
IntListAsExits
(List<Integer> list) Given a list of integers, returns them in a bit-packed form.boolean
isGround()
boolean
boolean
isInfernoBurning
(Coords coords) Determine if the given coordinates has a burning inferno.boolean
isLegalDeployment
(Coords c, int zoneType, int startingWidth, int startingOffset, int startingAnyNWx, int startingAnyNWy, int startingAnySEx, int startingAnySEy) Can an object be deployed at these coordinates, given a starting zone, width of starting zone and offset from edge of board?boolean
isLegalDeployment
(Coords c, Player p) Can the given player deploy at these coordinates?boolean
isLegalDeployment
(Coords c, Entity e) Can the given entity be deployed at these coordinatesboolean
boolean
isOnBoardEdge
(Coords coords) boolean
isSky()
boolean
isSpace()
boolean
isValid()
static boolean
boolean
void
Load board data from a file.void
load
(InputStream is) Loads this board from an InputStreamvoid
load
(InputStream is, List<String> errors, boolean continueLoadOnError) void
void
Creates a new data set for the board, with the specified dimensions and data; notifies listeners that a new data set has been created.void
processBoardEvent
(BoardEvent event) Fires a board event which typically leads to theBoardView
and minimap being redrawn.void
removeBoardListener
(BoardListener listener) Removes the specified board listener.void
removeBombIconsFrom
(Coords coords) void
removeInfernoFrom
(Coords coords) Extinguish inferno at the target hex.void
removeSpecialHexDisplay
(Coords coords, SpecialHexDisplay shd) Removes the given SHD from the given coords.void
removeSpecialHexDisplay
(Coords coords, SpecialHexDisplay shd, boolean fireEvent) Removes the given SHD from the given coords.void
Removes the given tag string from the board's tags list.void
Resets the "intermediate" deployment zones associated with this board, in case the deployment zones changevoid
Resets the Min and Max elevations to their default values.void
save
(OutputStream os) Writes data for the board, as text to the OutputStreamvoid
setAnnotations
(Coords c, Collection<String> a) Sets annotations on a given hex.void
setBoardId
(int boardId) Sets the board's ID.void
setBoardType
(BoardType boardType) void
setBridgeCF
(int value) Set the CF of bridgesvoid
Sets the description of the map.void
setEmbeddedBoard
(int boardId, Coords coords) Sets the given board ID as an embedded board at the given coords of this board.void
setEnclosingBoard
(int enclosingBoardId) void
Determines if this Board contains the (x, y) Coords, and if so, sets the specified Hex into that position and initializes it.void
Sets the hex into the location specified by the Coords.void
setHexes
(Map<BoardLocation, Hex> changedHexes) Copies in the given hexes, overwriting any affected hexes that are on this board.void
setMapName
(String mapName) void
void
setRoadsAutoExit
(boolean value) Set the value of the "road auto-exit" option.void
Sets this board's specialHexes to a new set.void
Sets a tileset theme for all hexes of the board.void
setType
(int t) toString()
void
updateBuilding
(Building receivedBuilding) Update a locally stored building with CF and other values from a building received from the server.
-
Field Details
-
BOARD_REQUEST_ROTATION
- See Also:
-
BOARD_NONE
public static final int BOARD_NONE- See Also:
-
BOARD_NAME_UNNAMED
- See Also:
-
START_NONE
public static final int START_NONE- See Also:
-
START_ANY
public static final int START_ANY- See Also:
-
START_NW
public static final int START_NW- See Also:
-
START_N
public static final int START_N- See Also:
-
START_NE
public static final int START_NE- See Also:
-
START_E
public static final int START_E- See Also:
-
START_SE
public static final int START_SE- See Also:
-
START_S
public static final int START_S- See Also:
-
START_SW
public static final int START_SW- See Also:
-
START_W
public static final int START_W- See Also:
-
START_EDGE
public static final int START_EDGE- See Also:
-
START_CENTER
public static final int START_CENTER- See Also:
-
NUM_ZONES
public static final int NUM_ZONES- See Also:
-
NUM_ZONES_X2
public static final int NUM_ZONES_X2- See Also:
-
DEFAULT_BOARD_HEIGHT
public static final int DEFAULT_BOARD_HEIGHT- See Also:
-
DEFAULT_BOARD_WIDTH
public static final int DEFAULT_BOARD_WIDTH- See Also:
-
boardListeners
-
MAX_DEPLOYMENT_ZONE_NUMBER
public static final int MAX_DEPLOYMENT_ZONE_NUMBER- See Also:
-
-
Constructor Details
-
Board
public Board()Creates a new board with zero as its width and height parameters. -
Board
public Board(int width, int height) Creates a new board of the specified dimensions. All hexes in the board will be null until otherwise set.- Parameters:
width
- the width dimension.height
- the height dimension.
-
Board
Creates a new board of the specified dimensions and specified hex data. Note that the number of Hexes given should be equal to width * height to avoid null Hexes in the board.- Parameters:
width
- the width dimensionheight
- the height dimensiondata
- the Hexes of the new board
-
-
Method Details
-
getSkyBoard
Returns a new atmospheric (low altitude) board with no terrain (sky map) of the given size.- Parameters:
width
- the width of the boardheight
- the height of the board- Returns:
- the new board, ready to be used
-
getSpaceBoard
Returns a new space board of the given size.- Parameters:
width
- the width of the boardheight
- the height of the board- Returns:
- the new board, ready to be used
-
getHeight
public int getHeight()- Returns:
- Map height in hexes
-
getWidth
public int getWidth()- Returns:
- Map width in hexes
-
getCenter
-
newData
Creates a new data set for the board, with the specified dimensions and data; notifies listeners that a new data set has been created.- Parameters:
width
- the width dimension.height
- the height dimension.data
- new hex data appropriate for the board.errors
- A buffer for storing error messages, if any. This is allowed to be null.
-
getHex
Determines if this Board contains the (x, y) Coords, and if so, returns the Hex at that position.- Parameters:
x
- the x Coords.y
- the y Coords.- Returns:
- the Hex, if this Board contains the (x, y) location; null otherwise.
-
getHexInDir
- Parameters:
c
- starting coordinatesdir
- direction- Returns:
- the hex in the specified direction from the specified starting coordinates.
-
getHexInDir
Gets the hex in the specified direction from the specified starting coordinates. This avoids calls to Coords.translated, and thus, object construction.- Parameters:
x
- starting x coordinatey
- starting y coordinatedir
- direction- Returns:
- the hex in the specified direction from the specified starting coordinates.
-
initializeAll
Initialize all hexes -
initializeAround
public void initializeAround(int x, int y) Initialize a hex and the hexes around it -
initializeHex
public void initializeHex(int x, int y) Initializes a hex in its surroundings. Currently, sets the connects parameter appropriately to the surrounding hexes. If a surrounding hex is off the board, it checks the hex opposite the missing hex. -
initializeAllAutomaticTerrain
public void initializeAllAutomaticTerrain()Rebuilds automatic terrains for the whole board, such as incline highlighting. Also fires a BOARD_CHANGED_ALL_HEXES event. -
contains
public boolean contains(int x, int y) Determines whether this Board "contains" the specified Coords.- Parameters:
x
- the x Coords.y
- the y Coords.- Returns:
true
if the board contains the specified coords
-
contains
Determines whether this Board "contains" the specified Coords.- Parameters:
coords
- the Coords.- Returns:
true
if the board contains the specified coords
-
contains
Determines whether this Board "contains" the specified location. True only when the board IDs match and the coords of the location are within the borders of the board.- Parameters:
location
- the location to test- Returns:
- true if the board contains the specified location
-
getHex
Returns the Hex at the given Coords, both of which may be null.- Parameters:
coords
- the Coords to look for the Hex- Returns:
- the Hex at the specified Coords, or null if there is not a hex there
-
getHexes
Returns a list of Hexes at the given coords. The list will never be null but may be empty depending on the given Coords collection. If the given Coords collection is null, the returned list will be empty.- Parameters:
coords
- the Coords to query- Returns:
- the Hexes at the specified Coords
-
setHex
Determines if this Board contains the (x, y) Coords, and if so, sets the specified Hex into that position and initializes it.- Parameters:
x
- the x Coords.y
- the y Coords.hex
- the hex to be set into position.
-
setHexes
Copies in the given hexes, overwriting any affected hexes that are on this board. For simplicity, this method ignoresBoardLocation
's that are not on this board, i.e., it can be called without first filtering the locations for board ID.- Parameters:
changedHexes
- A map of locations and hexes; the locations need not all (or any) match this board
-
setHex
Sets the hex into the location specified by the Coords.- Parameters:
c
- the Coords.hex
- the hex to be set into position.
-
boardIsSize
Checks if a board file is the specified size.- Parameters:
filepath
- The path to the board file.size
- The dimensions of the board to test.- Returns:
true
if the dimensions match.
-
getSize
Inspect specified board file and return its dimensions.- Parameters:
filepath
- The path to the board file.- Returns:
- A
BoardDimensions
object containing the dimension.
-
getTags
Inspects the given board file and returns a set of its tags. -
isValid
-
isLegalDeployment
Can the given player deploy at these coordinates? -
isLegalDeployment
Can the given entity be deployed at these coordinates -
isLegalDeployment
public boolean isLegalDeployment(Coords c, int zoneType, int startingWidth, int startingOffset, int startingAnyNWx, int startingAnyNWy, int startingAnySEx, int startingAnySEy) Can an object be deployed at these coordinates, given a starting zone, width of starting zone and offset from edge of board? -
getOppositeEdge
public int getOppositeEdge(int cardinalEdge) Determine the opposite edge from the given edge Returns START_NONE for non-cardinal edges (North, South, West, East)- Parameters:
cardinalEdge
- The edge to return the opposite of- Returns:
- Constant representing the opposite edge
-
load
Load board data from a file.- Parameters:
filepath
- The path to the file.
-
load
Loads this board from an InputStream -
load
-
load
-
isValid
public boolean isValid() -
isValid
-
save
Writes data for the board, as text to the OutputStream -
addInfernoTo
Record that the given coordinates have received a hit from an inferno.- Parameters:
coords
- theCoords
of the hit.round
- the kind of round that hit the hex.hits
- theint
number of rounds that hit- Throws:
IllegalArgumentException
- if the hits number is negative
-
removeInfernoFrom
Extinguish inferno at the target hex.- Parameters:
coords
- theCoords
of the hit.
-
removeBombIconsFrom
-
clearBombIcons
public void clearBombIcons() -
isInfernoBurning
Determine if the given coordinates has a burning inferno.- Parameters:
coords
- - theCoords
being checked.- Returns:
true
if those coordinates have a burning inferno round.false
if no inferno has hit those coordinates or if it has burned out.
-
getInfernoBurningCoords
Get an enumeration of all coordinates with infernos still burning.- Returns:
- an
Enumeration
ofCoords
that have infernos still burning.
-
getBuildings
- Returns:
- an
Enumeration
ofBuilding
s on the Board
-
getBuildingsVector
- Returns:
- the Vector of all the board's buildings
-
getBuildingAt
Get the building at the given coordinates.- Parameters:
coords
- theCoords
being examined.- Returns:
- a
Building
object, if there is one at the given coordinates, otherwise anull
will be returned.
-
collapseBuilding
Collapse a vector of building hexes.- Parameters:
coords
- theVector
ofCoords
objects to be collapsed.
-
collapseBuilding
The given building hex has collapsed. Remove it from the board and replace it with rubble.- Parameters:
coords
- theBuilding
that has collapsed.
-
collapseBuilding
The given building has collapsed. Remove it from the board and replace it with rubble.- Parameters:
bldg
- theBuilding
that has collapsed.
-
updateBuilding
Update a locally stored building with CF and other values from a building received from the server.- Parameters:
receivedBuilding
- The Building received from the server
-
getRoadsAutoExit
public boolean getRoadsAutoExit()Get the current value of the "road auto-exit" option.- Returns:
true
if roads should automatically exit onto all adjacent pavement hexes.false
otherwise.
-
setRoadsAutoExit
public void setRoadsAutoExit(boolean value) Set the value of the "road auto-exit" option.- Parameters:
value
- The value to set for the option;true
if roads should automatically exit onto all adjacent pavement hexes.false
otherwise.
-
addBoardListener
Adds the specified board listener to receive board events from this board.- Parameters:
listener
- the board listener.
-
removeBoardListener
Removes the specified board listener.- Parameters:
listener
- the board listener.
-
processBoardEvent
Fires a board event which typically leads to theBoardView
and minimap being redrawn. This is public as the boards and minimaps show some data that is not part of the Board class and Board has no way of knowing when a change happens. An example of this is arty auto hexes which are stored in the player class -
getInfernos
- Returns:
- an
Hashtable
ofInfernoTrackers
on the board.
-
setBridgeCF
public void setBridgeCF(int value) Set the CF of bridges- Parameters:
value
- The value to set the bridge CF to.
-
setRandomBasementsOff
public void setRandomBasementsOff() -
getSpecialHexDisplay
- Returns:
- Special events that should be marked on hexes, such as artillery fire as well as notes players can leave manually on hexes. Always returns at least an empty list, never null.
-
addSpecialHexDisplay
Adds the given SHD at the given coords to this board. An event can be fired for this board change (this should not be done on the Server).- Parameters:
coords
- The position of the SHD on this boardshd
- The SpecialHexDisplay to addfireEvent
- When true, a BoardEvent is fired for the affected coords
-
addSpecialHexDisplay
Adds the given SHD at the given coords to this board. This method does not fire an event for the change.- Parameters:
coords
- The position of the SHD on this boardshd
- The SpecialHexDisplay to add
-
removeSpecialHexDisplay
Removes the given SHD from the given coords.- Parameters:
coords
- The position of the SHD on this boardshd
- The SpecialHexDisplay to remove
-
removeSpecialHexDisplay
Removes the given SHD from the given coords.- Parameters:
coords
- The position of the SHD on this boardshd
- The SpecialHexDisplay to remove
-
getSpecialHexDisplayTable
-
setSpecialHexDisplayTable
Sets this board's specialHexes to a new set. This method should be used by the client when receiving an update from the server.- Parameters:
shd
- The new map of SpecialHexDisplays
-
setType
public void setType(int t) -
getMaxElevation
public int getMaxElevation()- Returns:
- the highest elevation hex on the board.
-
getMinElevation
public int getMinElevation()- Returns:
- the lowest elevation hex on the board.
-
resetStoredElevation
public void resetStoredElevation()Resets the Min and Max elevations to their default values. -
containsBridges
public boolean containsBridges() -
getDescription
Gets the description of the map.- Returns:
- The description of the map, if one exists, otherwise null.
-
setDescription
Sets the description of the map.- Parameters:
s
- The description of the map; may be null.
-
getAnnotations
Gets every annotation on the map.- Returns:
- A read-only map of per-hex annotations.
-
getAnnotations
Gets the annotations associated with a hex.- Parameters:
c
- Coordinates of the hex.- Returns:
- A collection of annotations for the hex.
-
setAnnotations
Sets annotations on a given hex.- Parameters:
c
- Coordinates of the hex to apply the annotations to.a
- A collection of annotations to assign to the hex. This may be null.
-
setTheme
Sets a tileset theme for all hexes of the board. Passing null as newTheme resets the theme to the theme specified in the board file. -
isOnBoardEdge
- Returns:
- true when the given
Coords
coords is on the edge of the board.
-
createEmptyBoard
-
addTag
Add the given tag string to the board's tags list. -
removeTag
Removes the given tag string from the board's tags list. -
getTags
- Returns:
- the board's tags list. The list is unmodifiable. Use addTag and removeTag to change it.
-
getBoardName
- Returns:
- The name of this map; this is meant to be displayed in the GUI.
-
setMapName
-
exitsAsIntList
- Returns:
- Given an "exits" value, returns it in a list form. (i.e. exits value of 4 returns {3}, exit value of 5 returns {1, 3}
-
IntListAsExits
Given a list of integers, returns them in a bit-packed form. -
addDeploymentZone
Adds a deployment zone with the given ID and the hexes described by the given HexArea to this board, replacing the previously present zone of that ID, if there had been one. Note that the zone ID can be outside those reachable by board files; e.g. the zone ID can be 1000. Note however that zone IDs in the range of 0 to 50 should be avoided as they'll overwrite terrain deployment zones.- Parameters:
zoneId
- The zone IdhexArea
- The hexes comprising this deployment zone
-
resetDeploymentZones
public void resetDeploymentZones()Resets the "intermediate" deployment zones associated with this board, in case the deployment zones change -
getCustomDeploymentZones
Gets the IDs of all custom deployment zones defined for this board. -
getCustomDeploymentZone
Gets all the coordinates in the given custom deployment zone -
decodeCustomDeploymentZoneID
public static int decodeCustomDeploymentZoneID(int zoneID) Use this method to convert a deployment zone ID as represented in the UI zone selectors (e.g. in the PlayerSettingsDialog) to a deployment zone ID as stored in the board. -
encodeCustomDeploymentZoneID
public static int encodeCustomDeploymentZoneID(int zoneID) Use this method to convert a deployment zone ID as stored in the board to a number suitable for representation in the UI zone selectors (e.g. PlayerSettingsDialog) -
setBoardId
public void setBoardId(int boardId) Sets the board's ID. Within an MM game, the ID must be unique. To preserve "normal" games, 0 is the default. -
getBoardId
public int getBoardId() -
setEnclosingBoard
public void setEnclosingBoard(int enclosingBoardId) -
getEnclosingBoardId
public int getEnclosingBoardId()- Returns:
- The ID of the enclosing board of this board, or -1 if it has no enclosing board.
-
setEmbeddedBoard
Sets the given board ID as an embedded board at the given coords of this board. The board ID is not checked nor the board type. The coords are checked against the size of this board.- Parameters:
boardId
- The board ID to embedcoords
- The location to place the given board- Throws:
IllegalArgumentException
- When this board does not contain the given coords
-
embeddedBoardCoords
-
embeddedBoardPosition
-
getEmbeddedBoardAt
-
getEmbeddedBoardHexes
-
isGround
public boolean isGround() -
isLowAltitude
public boolean isLowAltitude()- Returns:
- True if this board is a low altitude (a.k.a. atmospheric) board, either with terrain or without terrain ("sky").
-
isSky
public boolean isSky()- Returns:
- True if this board is a low altitude (a.k.a. atmospheric) board without terrain ("sky").
-
isSpace
public boolean isSpace()- Returns:
- True if this board is a space board, either close to a planet with some atmospheric hexes ("high altitude") or in deeper space.
-
isHighAltitude
public boolean isHighAltitude()- Returns:
- True if this board is a high altitude board, i.e. a space board close to a planet with some atmospheric hexes.
-
setBoardType
-
getBoardType
-
toString
-