megamek.common
Class Board

java.lang.Object
  extended by megamek.common.Board
All Implemented Interfaces:
java.io.Serializable, IBoard

public class Board
extends java.lang.Object
implements java.io.Serializable, IBoard

See Also:
Serialized Form

Field Summary
static int BOARD_MAX_HEIGHT
           
static int BOARD_MAX_WIDTH
           
static java.lang.String BOARD_REQUEST_ROTATION
           
protected  java.util.Vector<BoardListener> boardListeners
           
protected  int height
           
static int START_ANY
           
static int START_CENTER
           
static int START_E
           
static int START_EDGE
           
static int START_N
           
static int START_NE
           
static int START_NONE
           
static int START_NW
           
static int START_S
           
static int START_SE
           
static int START_SW
           
static int START_W
           
static int T_ATMOSPHERE
           
static int T_GROUND
           
static int T_SPACE
           
protected  int width
           
 
Constructor Summary
Board()
          Creates a new board with zero as its width and height parameters.
Board(int width, int height)
          Creates a new board of the specified dimensions.
Board(int width, int height, IHex[] data)
          Creates a new board of the specified dimensions and specified hex data.
Board(int width, int height, IHex[] hexes, java.util.Vector<Building> bldgs, java.util.Hashtable<Coords,InfernoTracker> infMap)
          Creates a new board of the specified dimensions, hexes, buildings, and inferno trackers.
 
Method Summary
 void addBoardListener(BoardListener listener)
          Adds the specified board listener to receive board events from this board.
 void addInfernoTo(Coords coords, InfernoTracker.Inferno round, int hits)
          Record that the given coordinates have recieved a hit from an inferno.
 void addSpecialHexDisplay(Coords coords, SpecialHexDisplay shd)
           
static boolean boardIsSize(java.lang.String filename, int x, int y)
          Checks if a file in data/boards is the specified size
 boolean burnInferno(Coords coords)
          Record that a new round of burning has passed for the given coordinates.
 void collapseBuilding(Building bldg)
          The given building has collapsed.
 void collapseBuilding(Coords coords)
          The given building hex has collapsed.
 void collapseBuilding(java.util.Vector<Coords> coords)
          Collapse a vector of building hexes.
 boolean contains(Coords c)
          Determines whether this Board "contains" the specified Coords.
 boolean contains(int x, int y)
          Determines whether this Board "contains" the specified Coords.
 Building getBuildingAt(Coords coords)
          Get the building at the given coordinates.
 java.util.Enumeration<Building> getBuildings()
          Get an enumeration of all buildings on the board.
 int getHeight()
           
 IHex getHex(Coords c)
          Returns the Hex at the specified Coords.
 IHex getHex(int x, int y)
          Determines if this Board contains the (x, y) Coords, and if so, returns the Hex at that position.
 java.util.Enumeration<Coords> getHexesAtDistance(Coords coords, int distance)
           
 IHex getHexInDir(Coords c, int dir)
          Gets the hex in the specified direction from the specified starting coordinates.
 IHex getHexInDir(int x, int y, int dir)
          Gets the hex in the specified direction from the specified starting coordinates.
 java.util.Enumeration<Coords> getInfernoBurningCoords()
          Get an enumeration of all coordinates with infernos still burning.
 int getInfernoBurnTurns(Coords coords)
          Determine the remaining number of turns the given coordinates will have a burning inferno.
 int getInfernoIVBurnTurns(Coords coords)
          Determine the remaining number of turns the given coordinates will have a burning Inferno IV round.
 java.util.Hashtable<Coords,InfernoTracker> getInfernos()
          returns a hash of the inferno trackers
protected  java.util.Vector<BoardListener> getListeners()
           
 int getMaxElevation()
          Returns the highest elevation hex on the board.
 int getMinElevation()
          Returns the lowest elevation hex on the board.
 boolean getRoadsAutoExit()
          Get the current value of the "road auto-exit" option.
 java.util.Collection<SpecialHexDisplay> getSpecialHexDisplay(Coords coords)
          This returns special events that should be makred on hexes, such as artilery fire.
 java.util.Hashtable<Coords,java.util.Collection<SpecialHexDisplay>> getSpecialHexDisplayTable()
           
 int getType()
           
static java.lang.String getTypeName(int t)
           
 int getWidth()
           
 boolean inAtmosphere()
           
protected  void initializeAll()
          Initialize all hexes
 void initializeAround(int x, int y)
          Initialize a hex and the hexes around it
 boolean inSpace()
           
 boolean isInfernoBurning(Coords coords)
          Determine if the given coordinates has a burning inferno.
 boolean isLegalDeployment(Coords c, int nDir)
          Can the player deploy an entity here?
 void load(java.io.InputStream is)
          Loads this board from an InputStream
 void load(java.lang.String filename)
          Loads this board from a filename in data/boards
 void newData(int width, int height)
          Creates a new data set for the board, with the specified dimensions; notifies listeners that a new data set has been created.
 void newData(int width, int height, IHex[] data)
          Creates a new data set for the board, with the specified dimensions and data; notifies listeners that a new data set has been created.
 boolean onGround()
           
protected  void processBoardEvent(BoardEvent event)
           
 void removeBoardListener(BoardListener listener)
          Removes the specified board listener.
 void removeInfernoFrom(Coords coords)
          Extinguish inferno at the target hex.
 void resetStoredElevation()
          Resets the Min and Max elevations to their default values.
 void save(java.io.OutputStream os)
          Writes data for the board, as text to the OutputStream
 void save2(java.io.OutputStream os)
          Writes data for the board, as serialization, to the OutputStream
 void setBridgeCF(int value)
          Set the CF of bridges
 void setHex(Coords c, IHex hex)
          Sets the hex into the location specified by the Coords.
 void setHex(int x, int y, IHex hex)
          Determines if this Board contains the (x, y) Coords, and if so, sets the specified Hex into that position and initializes it.
 void setRoadsAutoExit(boolean value)
          Set the value of the "road auto-exit" option.
 void setSpecialHexDisplayTable(java.util.Hashtable<Coords,java.util.Collection<SpecialHexDisplay>> shd)
           
 void setType(int t)
           
 void updateBuildingCF(java.util.Vector<Building> bldgs)
          Update the construction factors on an array of buildings.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BOARD_REQUEST_ROTATION

public static final java.lang.String BOARD_REQUEST_ROTATION
See Also:
Constant Field Values

BOARD_MAX_WIDTH

public static final int BOARD_MAX_WIDTH
See Also:
Constant Field Values

BOARD_MAX_HEIGHT

public static final int BOARD_MAX_HEIGHT
See Also:
Constant Field Values

START_NONE

public static final int START_NONE
See Also:
Constant Field Values

START_ANY

public static final int START_ANY
See Also:
Constant Field Values

START_NW

public static final int START_NW
See Also:
Constant Field Values

START_N

public static final int START_N
See Also:
Constant Field Values

START_NE

public static final int START_NE
See Also:
Constant Field Values

START_E

public static final int START_E
See Also:
Constant Field Values

START_SE

public static final int START_SE
See Also:
Constant Field Values

START_S

public static final int START_S
See Also:
Constant Field Values

START_SW

public static final int START_SW
See Also:
Constant Field Values

START_W

public static final int START_W
See Also:
Constant Field Values

START_EDGE

public static final int START_EDGE
See Also:
Constant Field Values

START_CENTER

public static final int START_CENTER
See Also:
Constant Field Values

width

protected int width

height

protected int height

T_GROUND

public static final int T_GROUND
See Also:
Constant Field Values

T_ATMOSPHERE

public static final int T_ATMOSPHERE
See Also:
Constant Field Values

T_SPACE

public static final int T_SPACE
See Also:
Constant Field Values

boardListeners

protected transient java.util.Vector<BoardListener> boardListeners
Constructor Detail

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

public Board(int width,
             int height,
             IHex[] data)
Creates a new board of the specified dimensions and specified hex data.

Parameters:
width - the width dimension.
height - the height dimension.
data -

Board

public Board(int width,
             int height,
             IHex[] hexes,
             java.util.Vector<Building> bldgs,
             java.util.Hashtable<Coords,InfernoTracker> infMap)
Creates a new board of the specified dimensions, hexes, buildings, and inferno trackers. Do *not* use this method unless you have carefully examined this class.

Parameters:
width - The int width dimension in hexes.
height - The int height dimension in hexes.
hexes - The array of Hexes for this board. This object is used directly without being copied. This value should only be null if either width or height is zero.
bldgs - The Vector of Buildings for this board. This object is used directly without being copied.
infMap - The Hashtable that map Coords to InfernoTrackers for this board. This object is used directly without being copied.
Method Detail

getHeight

public int getHeight()
Specified by:
getHeight in interface IBoard
Returns:
Map height in hexes

getWidth

public int getWidth()
Specified by:
getWidth in interface IBoard
Returns:
Map widht in hexes

newData

public void newData(int width,
                    int height,
                    IHex[] data)
Description copied from interface: IBoard
Creates a new data set for the board, with the specified dimensions and data; notifies listeners that a new data set has been created.

Specified by:
newData in interface IBoard
Parameters:
width - the width dimension.
height - the height dimension.
data - new hex data appropriate for the board.

newData

public void newData(int width,
                    int height)
Description copied from interface: IBoard
Creates a new data set for the board, with the specified dimensions; notifies listeners that a new data set has been created.

Specified by:
newData in interface IBoard
Parameters:
width - the width dimension.
height - the height dimension.

getHexesAtDistance

public java.util.Enumeration<Coords> getHexesAtDistance(Coords coords,
                                                        int distance)
Specified by:
getHexesAtDistance in interface IBoard

getHex

public IHex getHex(int x,
                   int y)
Determines if this Board contains the (x, y) Coords, and if so, returns the Hex at that position.

Specified by:
getHex in interface IBoard
Parameters:
x - the x Coords.
y - the y Coords.
Returns:
the Hex, if this Board contains the (x, y) location; null otherwise.

getHexInDir

public IHex getHexInDir(Coords c,
                        int dir)
Gets the hex in the specified direction from the specified starting coordinates.

Specified by:
getHexInDir in interface IBoard
Parameters:
c - starting coordinates
dir - direction
Returns:
the hex in the specified direction from the specified starting coordinates.

getHexInDir

public IHex getHexInDir(int x,
                        int y,
                        int dir)
Gets the hex in the specified direction from the specified starting coordinates. Avoids calls to Coords.translated, and thus, object construction.

Specified by:
getHexInDir in interface IBoard
Parameters:
x - starting x coordinate
y - starting y coordinate
dir - direction
Returns:
the hex in the specified direction from the specified starting coordinates.

initializeAll

protected void initializeAll()
Initialize all hexes


initializeAround

public void initializeAround(int x,
                             int y)
Initialize a hex and the hexes around it

Specified by:
initializeAround in interface IBoard

contains

public boolean contains(int x,
                        int y)
Determines whether this Board "contains" the specified Coords.

Specified by:
contains in interface IBoard
Parameters:
x - the x Coords.
y - the y Coords.
Returns:
true if the board contains the specified coords

contains

public boolean contains(Coords c)
Determines whether this Board "contains" the specified Coords.

Specified by:
contains in interface IBoard
Parameters:
c - the Coords.
Returns:
true if the board contains the specified coords

getHex

public IHex getHex(Coords c)
Returns the Hex at the specified Coords.

Specified by:
getHex in interface IBoard
Parameters:
c - the Coords.

setHex

public void setHex(int x,
                   int y,
                   IHex hex)
Determines if this Board contains the (x, y) Coords, and if so, sets the specified Hex into that position and initializes it.

Specified by:
setHex in interface IBoard
Parameters:
x - the x Coords.
y - the y Coords.
hex - the hex to be set into position.

setHex

public void setHex(Coords c,
                   IHex hex)
Sets the hex into the location specified by the Coords.

Specified by:
setHex in interface IBoard
Parameters:
c - the Coords.
hex - the hex to be set into position.

boardIsSize

public static boolean boardIsSize(java.lang.String filename,
                                  int x,
                                  int y)
Checks if a file in data/boards is the specified size


isLegalDeployment

public boolean isLegalDeployment(Coords c,
                                 int nDir)
Can the player deploy an entity here? There are no canon rules for the deployment phase (?!). I'm using 3 hexes from map edge.

Specified by:
isLegalDeployment in interface IBoard

load

public void load(java.lang.String filename)
Loads this board from a filename in data/boards

Specified by:
load in interface IBoard
Parameters:
filename - filename to load from

load

public void load(java.io.InputStream is)
Loads this board from an InputStream

Specified by:
load in interface IBoard
Parameters:
is - input stream

save

public void save(java.io.OutputStream os)
Writes data for the board, as text to the OutputStream

Specified by:
save in interface IBoard
Parameters:
os - output stream

save2

public void save2(java.io.OutputStream os)
Writes data for the board, as serialization, to the OutputStream


addInfernoTo

public void addInfernoTo(Coords coords,
                         InfernoTracker.Inferno round,
                         int hits)
Record that the given coordinates have recieved a hit from an inferno.

Specified by:
addInfernoTo in interface IBoard
Parameters:
coords - - the Coords of the hit.
round - - the kind of round that hit the hex.
hits - - the int number of rounds that hit. If a negative number is passed, then an IllegalArgumentException will be thrown.

removeInfernoFrom

public void removeInfernoFrom(Coords coords)
Description copied from interface: IBoard
Extinguish inferno at the target hex.

Specified by:
removeInfernoFrom in interface IBoard
Parameters:
coords - - the Coords of the hit.

isInfernoBurning

public boolean isInfernoBurning(Coords coords)
Determine if the given coordinates has a burning inferno.

Specified by:
isInfernoBurning in interface IBoard
Parameters:
coords - - the Coords 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.

burnInferno

public boolean burnInferno(Coords coords)
Record that a new round of burning has passed for the given coordinates. This routine also determines if the fire is still burning.

Specified by:
burnInferno in interface IBoard
Parameters:
coords - - the Coords 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

public java.util.Enumeration<Coords> getInfernoBurningCoords()
Get an enumeration of all coordinates with infernos still burning.

Specified by:
getInfernoBurningCoords in interface IBoard
Returns:
an Enumeration of Coords that have infernos still burning.

getInfernoBurnTurns

public int getInfernoBurnTurns(Coords coords)
Determine the remaining number of turns the given coordinates will have a burning inferno.

Specified by:
getInfernoBurnTurns in interface IBoard
Parameters:
coords - - the Coords being checked. This value must not be null. Unchecked.
Returns:
the int number of burn turns left for all infernos This value will be non-negative.

getInfernoIVBurnTurns

public int getInfernoIVBurnTurns(Coords coords)
Determine the remaining number of turns the given coordinates will have a burning Inferno IV round.

Specified by:
getInfernoIVBurnTurns in interface IBoard
Parameters:
coords - - the Coords being checked. This value must not be null. Unchecked.
Returns:
the int number of burn turns left for Arrow IV infernos. This value will be non-negative.

getBuildings

public java.util.Enumeration<Building> getBuildings()
Get an enumeration of all buildings on the board.

Specified by:
getBuildings in interface IBoard
Returns:
an Enumeration of Buildings.

getBuildingAt

public Building getBuildingAt(Coords coords)
Get the building at the given coordinates.

Specified by:
getBuildingAt in interface IBoard
Parameters:
coords - - the Coords being examined.
Returns:
a Building object, if there is one at the given coordinates, otherwise a null will be returned.

collapseBuilding

public void collapseBuilding(java.util.Vector<Coords> coords)
Collapse a vector of building hexes.

Specified by:
collapseBuilding in interface IBoard
Parameters:
bldgs - - the Vector of Coord objects to be collapsed.

collapseBuilding

public void collapseBuilding(Coords coords)
The given building hex has collapsed. Remove it from the board and replace it with rubble.

Specified by:
collapseBuilding in interface IBoard
Parameters:
other - - the Building that has collapsed.

collapseBuilding

public void collapseBuilding(Building bldg)
The given building has collapsed. Remove it from the board and replace it with rubble.

Specified by:
collapseBuilding in interface IBoard
Parameters:
other - - the Building that has collapsed.

updateBuildingCF

public void updateBuildingCF(java.util.Vector<Building> bldgs)
Update the construction factors on an array of buildings.

Specified by:
updateBuildingCF in interface IBoard
Parameters:
bldgs - - the Vector of Building objects to be updated.

getRoadsAutoExit

public boolean getRoadsAutoExit()
Get the current value of the "road auto-exit" option.

Specified by:
getRoadsAutoExit in interface IBoard
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.

Specified by:
setRoadsAutoExit in interface IBoard
Parameters:
value - - The value to set for the option; true if roads should automatically exit onto all adjacent pavement hexes. false otherwise.

addBoardListener

public void addBoardListener(BoardListener listener)
Description copied from interface: IBoard
Adds the specified board listener to receive board events from this board.

Specified by:
addBoardListener in interface IBoard
Parameters:
listener - the board listener.

removeBoardListener

public void removeBoardListener(BoardListener listener)
Description copied from interface: IBoard
Removes the specified board listener.

Specified by:
removeBoardListener in interface IBoard
Parameters:
listener - the board listener.

processBoardEvent

protected void processBoardEvent(BoardEvent event)

getListeners

protected java.util.Vector<BoardListener> getListeners()

getInfernos

public java.util.Hashtable<Coords,InfernoTracker> getInfernos()
Description copied from interface: IBoard
returns a hash of the inferno trackers

Specified by:
getInfernos in interface IBoard
Returns:
an HashtableInfernoTrackers on the board.

setBridgeCF

public void setBridgeCF(int value)
Description copied from interface: IBoard
Set the CF of bridges

Specified by:
setBridgeCF in interface IBoard
Parameters:
value - - The value to set the bridge CF to.

getSpecialHexDisplay

public java.util.Collection<SpecialHexDisplay> getSpecialHexDisplay(Coords coords)
Description copied from interface: IBoard
This returns special events that should be makred on hexes, such as artilery fire.

Specified by:
getSpecialHexDisplay in interface IBoard

addSpecialHexDisplay

public void addSpecialHexDisplay(Coords coords,
                                 SpecialHexDisplay shd)
Specified by:
addSpecialHexDisplay in interface IBoard

getSpecialHexDisplayTable

public java.util.Hashtable<Coords,java.util.Collection<SpecialHexDisplay>> getSpecialHexDisplayTable()
Specified by:
getSpecialHexDisplayTable in interface IBoard

setSpecialHexDisplayTable

public void setSpecialHexDisplayTable(java.util.Hashtable<Coords,java.util.Collection<SpecialHexDisplay>> shd)
Specified by:
setSpecialHexDisplayTable in interface IBoard

setType

public void setType(int t)
Specified by:
setType in interface IBoard

getType

public int getType()
Specified by:
getType in interface IBoard

getTypeName

public static java.lang.String getTypeName(int t)

onGround

public boolean onGround()
Specified by:
onGround in interface IBoard

inAtmosphere

public boolean inAtmosphere()
Specified by:
inAtmosphere in interface IBoard

inSpace

public boolean inSpace()
Specified by:
inSpace in interface IBoard

getMaxElevation

public int getMaxElevation()
Description copied from interface: IBoard
Returns the highest elevation hex on the board.

Specified by:
getMaxElevation in interface IBoard
Returns:

getMinElevation

public int getMinElevation()
Description copied from interface: IBoard
Returns the lowest elevation hex on the board.

Specified by:
getMinElevation in interface IBoard
Returns:

resetStoredElevation

public void resetStoredElevation()
Description copied from interface: IBoard
Resets the Min and Max elevations to their default values.

Specified by:
resetStoredElevation in interface IBoard