megamek.common
Class Hex

java.lang.Object
  extended by megamek.common.Hex
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, IHex

public class Hex
extends java.lang.Object
implements IHex, java.io.Serializable

Hex represents a single hex on the board.

Author:
Ben
See Also:
Serialized Form

Constructor Summary
Hex()
          Constructs clear, plain hex at level 0.
Hex(int elevation)
          Constructs clean, plain hex at specified elevation.
Hex(int elevation, ITerrain[] terrains, java.lang.String theme)
           
Hex(int elevation, ITerrain[] terrains, java.lang.String theme, Coords c)
          Constructs hex with all parameters.
Hex(int elevation, java.lang.String terrain, java.lang.String theme)
           
Hex(int elevation, java.lang.String terrain, java.lang.String theme, Coords c)
          Contructs hex with string terrain info
 
Method Summary
 void addTerrain(ITerrain terrain)
          Adds the specified terrain
 int ceiling()
           
 void clearExits()
          Clears the "exits" flag for all terrains in the hex where it is not manually specified.
 boolean containsTerrain(int type)
           
 boolean containsTerrain(int type, int level)
           
 boolean containsTerrainExit(int terrType, int direction)
          Determine if this Hex contains the indicated terrain that exits in the specified direction.
 int depth()
           
 int displayableTerrainsPresent()
           
 IHex duplicate()
           
 int floor()
           
 int getBogDownModifier(EntityMovementMode moveMode, boolean largeVee)
          get any modifiers to a bog-down roll in this hex.
 Coords getCoords()
           
 int getElevation()
           
 int getFireTurn()
           
 int getIgnitionModifier()
           
 ITerrain getTerrain(int type)
           
 java.lang.String getTheme()
          The theme is intended as a tag for the tileset file to indicate a special graphic for the hex.
 int getUnstuckModifier(int elev)
          get any modifiers to a an unstuck roll in this hex.
 boolean hasPavement()
           
 void incrementFireTurn()
           
 boolean isClear()
           
 boolean isIgnitable()
          Is this hex ignitable?
 int movementCost(EntityMovementMode moveMode)
          (Only if statically determinable)
 void removeAllTerrains()
          Removes all Terreains from the hex.
 void removeTerrain(int type)
          Removes the specified terrain
 void resetFireTurn()
           
 void setElevation(int elevation)
          set the elevation
 void setExits(IHex other, int direction)
          Sets the "exits" flag appropriately, assuming the specified hex lies in the specified direction on the board.
 void setExits(IHex other, int direction, boolean roadsAutoExit)
          Sets the "exits" flag appropriately, assuming the specified hex lies in the specified direction on the board.
 void setTheme(java.lang.String theme)
          Set the hex theme.
 int surface()
           
 int terrainLevel(int type)
           
 int terrainPilotingModifier(EntityMovementMode moveMode)
           
 int terrainsPresent()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Hex

public Hex()
Constructs clear, plain hex at level 0.


Hex

public Hex(int elevation)
Constructs clean, plain hex at specified elevation.


Hex

public Hex(int elevation,
           ITerrain[] terrains,
           java.lang.String theme)

Hex

public Hex(int elevation,
           ITerrain[] terrains,
           java.lang.String theme,
           Coords c)
Constructs hex with all parameters.


Hex

public Hex(int elevation,
           java.lang.String terrain,
           java.lang.String theme)

Hex

public Hex(int elevation,
           java.lang.String terrain,
           java.lang.String theme,
           Coords c)
Contructs hex with string terrain info

Method Detail

getElevation

public int getElevation()
Specified by:
getElevation in interface IHex
Returns:
hex elevation

setElevation

public void setElevation(int elevation)
Description copied from interface: IHex
set the elevation

Specified by:
setElevation in interface IHex

getTheme

public java.lang.String getTheme()
Description copied from interface: IHex
The theme is intended as a tag for the tileset file to indicate a special graphic for the hex.

Specified by:
getTheme in interface IHex
Returns:
theme name

setTheme

public void setTheme(java.lang.String theme)
Description copied from interface: IHex
Set the hex theme.

Specified by:
setTheme in interface IHex
Parameters:
theme - theme name
See Also:
getTheme

clearExits

public void clearExits()
Description copied from interface: IHex
Clears the "exits" flag for all terrains in the hex where it is not manually specified.

Specified by:
clearExits in interface IHex

setExits

public void setExits(IHex other,
                     int direction)
Description copied from interface: IHex
Sets the "exits" flag appropriately, assuming the specified hex lies in the specified direction on the board. Does not reset connects in other directions. All Terrain.ROADs will exit onto Terrain.PAVEMENT hexes automatically.

Specified by:
setExits in interface IHex
Parameters:
other - neighbour hex
direction - - the int direction of the exit. This value should be between 0 and 5 (inclusive).
See Also:
IHex.setExits(IHex, int, boolean)

setExits

public void setExits(IHex other,
                     int direction,
                     boolean roadsAutoExit)
Description copied from interface: IHex
Sets the "exits" flag appropriately, assuming the specified hex lies in the specified direction on the board. Does not reset connects in other directions. If the value of roadsAutoExit is true, any Terrain.ROAD will exit onto Terrain.PAVEMENT hexes automatically.

Specified by:
setExits in interface IHex
Parameters:
other - neighbour hex
direction - - the int direction of the exit. This value should be between 0 and 5 (inclusive).
See Also:
IHex.setExits(IHex, int)

containsTerrainExit

public boolean containsTerrainExit(int terrType,
                                   int direction)
Description copied from interface: IHex
Determine if this Hex contains the indicated terrain that exits in the specified direction.

Specified by:
containsTerrainExit in interface IHex
Parameters:
terrType - - the int type of the terrain.
direction - - the int direction of the exit. This value should be between 0 and 5 (inclusive).
Returns:
true if this Hex contains the indicated terrain that exits in the specified direction. false if bad input is supplied, if no such terrain exists, or if it doesn't exit in that direction.
See Also:
IHex.setExits(IHex, int, boolean)

ceiling

public int ceiling()
Specified by:
ceiling in interface IHex
Returns:
the highest level that features in this hex extend to. Above this level is assumed to be air.

surface

public int surface()
Specified by:
surface in interface IHex
Returns:
the surface level of the hex. Equal to getElevation().

floor

public int floor()
Specified by:
floor in interface IHex
Returns:
the lowest level that features in this hex extend to. Below this level is assumed to be bedrock.

depth

public int depth()
Specified by:
depth in interface IHex
Returns:
a level indicating how far features in this hex extend below the surface elevation.

containsTerrain

public boolean containsTerrain(int type)
Specified by:
containsTerrain in interface IHex
Parameters:
type - terrain to check
Returns:
true if the specified terrain is represented in the hex at any level.
See Also:
IHex.containsTerrain(int, int)

containsTerrain

public boolean containsTerrain(int type,
                               int level)
Specified by:
containsTerrain in interface IHex
Parameters:
type - terrain type to check
level - level to check the presence of the given terrain at
Returns:
true if the specified terrain is represented in the hex at given level.
See Also:
IHex.containsTerrain(int)

hasPavement

public boolean hasPavement()
Specified by:
hasPavement in interface IHex
Returns:
true if there is pavement, a road or a bridge in the hex.

terrainLevel

public int terrainLevel(int type)
Specified by:
terrainLevel in interface IHex
Returns:
the level of the terrain specified, or ITerrain.LEVEL_NONE if the terrain is not present in the hex

getTerrain

public ITerrain getTerrain(int type)
Specified by:
getTerrain in interface IHex
Returns:
the terrain of the specified type, or null if the terrain is not present in the hex

addTerrain

public void addTerrain(ITerrain terrain)
Description copied from interface: IHex
Adds the specified terrain

Specified by:
addTerrain in interface IHex
Parameters:
terrain - terrain to add

removeTerrain

public void removeTerrain(int type)
Description copied from interface: IHex
Removes the specified terrain

Specified by:
removeTerrain in interface IHex

removeAllTerrains

public void removeAllTerrains()
Description copied from interface: IHex
Removes all Terreains from the hex.

Specified by:
removeAllTerrains in interface IHex

displayableTerrainsPresent

public int displayableTerrainsPresent()
Specified by:
displayableTerrainsPresent in interface IHex
Returns:
the number of terrain attributes present that are displayable in tooltips

terrainsPresent

public int terrainsPresent()
Specified by:
terrainsPresent in interface IHex
Returns:
the number of terrain attributes present

duplicate

public IHex duplicate()
Specified by:
duplicate in interface IHex
Returns:
new hex wich is equals to this

terrainPilotingModifier

public int terrainPilotingModifier(EntityMovementMode moveMode)
Specified by:
terrainPilotingModifier in interface IHex
Returns:
modifier to PSRs made in the hex

movementCost

public int movementCost(EntityMovementMode moveMode)
Description copied from interface: IHex
(Only if statically determinable)

Specified by:
movementCost in interface IHex
Returns:
extra movement cost for entering the hex

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getIgnitionModifier

public int getIgnitionModifier()
Specified by:
getIgnitionModifier in interface IHex
Returns:
the modifier to the roll to ignite this hex

isIgnitable

public boolean isIgnitable()
Is this hex ignitable?

Specified by:
isIgnitable in interface IHex
Returns:
true if this hex is ignitable

isClear

public boolean isClear()
Specified by:
isClear in interface IHex

getFireTurn

public int getFireTurn()
Specified by:
getFireTurn in interface IHex

incrementFireTurn

public void incrementFireTurn()
Specified by:
incrementFireTurn in interface IHex

resetFireTurn

public void resetFireTurn()
Specified by:
resetFireTurn in interface IHex

getBogDownModifier

public int getBogDownModifier(EntityMovementMode moveMode,
                              boolean largeVee)
get any modifiers to a bog-down roll in this hex. Takes the worst modifier If there is no bog-down chance in this hex, then it returns TargetRoll.AUTOMATIC_SUCCESS

Specified by:
getBogDownModifier in interface IHex

getUnstuckModifier

public int getUnstuckModifier(int elev)
get any modifiers to a an unstuck roll in this hex.

Specified by:
getUnstuckModifier in interface IHex

getCoords

public Coords getCoords()
Specified by:
getCoords in interface IHex