Package megamek.common
Class Hex
java.lang.Object
megamek.common.Hex
- All Implemented Interfaces:
Serializable
Hex represents a single hex on the board.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addTerrain
(Terrain terrain) void
applyTerrainPilotingModifiers
(EntityMovementMode moveMode, PilotingRollData roll, boolean enteringRubble) Adds terrain modifiers to PSRs made in this hexint
ceiling()
int
ceiling
(boolean inAtmosphere) int
ceilingAltitude
(boolean inAtmosphere) Returns the altitude ceiling, i.e.void
Clears the "exits" flag for all terrains in the hex where it is not manually specified.boolean
containsAllTerrainsOf
(int... types) boolean
containsAnyTerrainOf
(int... types) boolean
containsAnyTerrainOf
(Set<Integer> types) boolean
containsExit
(int direction) Determines if this Hex contains any exists in the specified direction.boolean
containsTerrain
(int type) boolean
containsTerrain
(int type, int level) boolean
containsTerrainExit
(int terrType, int direction) Determine if thisHex
contains the indicated terrain that exits in the specified direction.int
depth()
int
depth
(boolean hidden) FIXME : I should be a clone implementation, not thisint
floor()
Returns the lowest reachable point of this hex, used for terrain types that can extend below the surface of the hex, such as water and basements.getAnyTerrainOf
(int type, int... types) int
Returns the "Base Terrain" for the hex, or 0 if it is clearint
getBogDownModifier
(EntityMovementMode moveMode, boolean largeVee) get any modifiers to a bog-down roll in this hex.Returns a string representation of this Hex to use for copy/paste actions.Returns the position of this hex on the board.int
int
int
getLevel()
getTerrain
(int type) int[]
getTheme()
The theme is intended as a tag for the tileset file to indicate a special graphic for the hexvoid
getUnstuckModifier
(int elev, PilotingRollData rollTarget) get any modifiers to an unstuck roll in this hex.boolean
hasCliffTopTowards
(Hex otherHex) True if this hex has a clifftop towards otherHex.boolean
boolean
boolean
If there's a road on this tile and it's paved, return trueboolean
boolean
boolean
boolean
void
boolean
boolean
Returns true if the hex is valid for takeoff - either clear, has pavement, or a roadboolean
boolean
boolean
Returns true when the hex has no invalid terrain.int
maxTerrainFeatureElevation
(boolean inAtmosphere) int
movementCost
(Entity entity) static Hex
parseClipboardString
(String clipboardString) Returns a new Hex parsed from a clipboard string representation.void
Removes all Terrains from the hex.void
removeTerrain
(int type) void
void
Resets the theme to what was specified in the board file.void
Sets the coords of this hex.void
Sets the "exits" flag appropriately for the neighbouring hex in the provided direction.void
Sets the "exits" flag appropriately for the neighbouring hex in the provided direction.void
setLevel
(int level) void
int
terrainLevel
(int type) int
toString()
int
-
Constructor Details
-
Hex
public Hex()Constructs a clear, plain hex at level 0. -
Hex
public Hex(int level) Constructs a clean, plain hex at specified level. -
Hex
-
Hex
Constructs a Hex with all parameters. -
Hex
-
Hex
Constructs a Hex from a combined string terrains format
-
-
Method Details
-
getLevel
public int getLevel()- Returns:
- The level of a hex, as defined in TW. This refers to the height of the ground terrain.
-
setLevel
public void setLevel(int level) -
getTheme
The theme is intended as a tag for the tileset file to indicate a special graphic for the hex- Returns:
- the theme name
-
setTheme
-
getTerrainTypes
public int[] getTerrainTypes()- Returns:
- An array that contains an id for each terrain present in this hex.
-
getTerrainTypesSet
- Returns:
- A HashSet that contains an id for each terrain present in this hex.
-
resetTheme
public void resetTheme()Resets the theme to what was specified in the board file. -
clearExits
public void clearExits()Clears the "exits" flag for all terrains in the hex where it is not manually specified. -
setExits
Sets the "exits" flag appropriately for the neighbouring hex in the provided direction. Does not reset connects in other directions. AllTerrain.ROAD
s will automatically connect toTerrain.PAVEMENT
hexes.- Parameters:
other
- the neighbouring hex in the specified directiondirection
- theint
direction of the exit. This value should be between 0 and 5 (inclusive).- See Also:
-
setExits
Sets the "exits" flag appropriately for the neighbouring hex in the provided direction. Does not reset connects in other directions.- Parameters:
other
- the neighbouring hex in the specified directiondirection
- theint
direction of the exit. This value should be between 0 and 5 (inclusive).roadsAutoExit
- if to automatically exit onto Pavement hexes- See Also:
-
containsTerrainExit
public boolean containsTerrainExit(int terrType, int direction) Determine if thisHex
contains the indicated terrain that exits in the specified direction.- Parameters:
terrType
- theint
type of the terrain.direction
- theint
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, orfalse
if bad input is supplied, if no such terrain exists, or if it doesn't exit in that direction.- See Also:
-
containsExit
public boolean containsExit(int direction) Determines if this Hex contains any exists in the specified direction.- Parameters:
direction
- theint
direction of the exit. This value should be between 0 and 5 (inclusive).- Returns:
true
if thisHex
contains any terrain that exits in the specified direction.false
if bad input is supplied or if no terrain exits in that direction.- See Also:
-
hasExitableTerrain
public boolean hasExitableTerrain()- Returns:
- if this hex contains a terrain type that can have exits
-
ceiling
public int ceiling()- Returns:
- the highest level that features in this hex extend to. Above this level is assumed to be air. This assumes a ground map.
-
ceiling
public int ceiling(boolean inAtmosphere) - Parameters:
inAtmosphere
- Determines if the ceiling should be determined for an atmospheric map (eg, altitudes) or ground map (eg, levels)- Returns:
- the highest level or altitude (depending on flag) that features in this hex extend to. Above this level is assumed to be air.
-
ceilingAltitude
public int ceilingAltitude(boolean inAtmosphere) Returns the altitude ceiling, i.e. highest terrain feature influencing aero movement, of this hex. If inAtmosphere is false, the hex is assumed to be a ground map hex and the return value is 0, as airborne aero movement ignores all terrain features of a ground map (TW p.92). Otherwise the hex is assumed to be on a low altitude map and the hex level and a few terrains set an altitude of this hex. Note that the returned value is never below 0 to avoid having to deal with negative altitudes.- Parameters:
inAtmosphere
- True if the ceiling should be determined for an atmospheric or ground map- Returns:
- the altitude ceiling, i.e. highest terrain feature influencing aero movement, of this hex
-
maxTerrainFeatureElevation
public int maxTerrainFeatureElevation(boolean inAtmosphere) - Parameters:
inAtmosphere
- Determines if the ceiling should be determined for an atmospheric map (eg, altitudes) or ground map (eg, levels)- Returns:
- the elevation or altitude of the terrain feature that rises the highest above the surface of the hex. For example, if the hex is on the ground map and contains woods, this would return 2.
-
floor
public int floor()Returns the lowest reachable point of this hex, used for terrain types that can extend below the surface of the hex, such as water and basements. Unrevealed basements will not affect this value.- Returns:
- the lowest level that revealed features in this hex extend to. Below this level is assumed to be bedrock and/or basement. Unrevealed basements will not affect this value.
-
depth
public int depth()- Returns:
- a level indicating how far features in this hex extends below the surface level.
-
depth
public int depth(boolean hidden) -
hasTerrainFactor
public boolean hasTerrainFactor()- Returns:
- true if this hex has a terrain with a non-zero terrain factor
-
containsTerrain
public boolean containsTerrain(int type) - Parameters:
type
- the terrain type to check- Returns:
true
if the specified terrain is represented in the hex at any level.- See Also:
-
containsTerrain
public boolean containsTerrain(int type, int level) - Parameters:
type
- the terrain type to checklevel
- level to check the presence of the given terrain at- Returns:
- if the specified terrain is represented in the hex at given level.
- See Also:
-
containsAnyTerrainOf
public boolean containsAnyTerrainOf(int... types) - Parameters:
types
- the terrains to check- Returns:
- if at least one of the specified terrains are represented in the hex at any level.
- See Also:
-
containsAnyTerrainOf
- Parameters:
types
- the terrains to check- Returns:
- if at least one of the specified terrains are represented in the hex at any level.
- See Also:
-
containsAllTerrainsOf
public boolean containsAllTerrainsOf(int... types) - Parameters:
types
- the terrains to check- Returns:
true
if all the specified terrains are represented in the hex at any level.- See Also:
-
hasPavement
public boolean hasPavement()- Returns:
- True if there is pavement, a paved road or a bridge in the hex.
-
hasPavedRoad
public boolean hasPavedRoad()If there's a road on this tile and it's paved, return true- Returns:
-
hasPavementOrRoad
public boolean hasPavementOrRoad()- Returns:
- True if there is pavement, a road or a bridge in the hex.
-
hasVegetation
public boolean hasVegetation()- Returns:
- True if there is any woods or jungle in this hex, including foliage (i.e., height 1 woods/jungle).
-
vegetationCeiling
public int vegetationCeiling()- Returns:
- The height of woods or jungle in this hex (1, 2 or 3), or 0 if there isn't any.
-
hasDepth1WaterOrDeeper
public boolean hasDepth1WaterOrDeeper()- Returns:
- True if there is water in this hex of at least depth 1 (i.e., not depth 0)
-
terrainLevel
public int terrainLevel(int type) - Returns:
- the level of the terrain specified, or Terrain.LEVEL_NONE if the terrain is not present in the hex
-
getTerrain
- Parameters:
type
- the specified type- Returns:
- the terrain of the specified type, or
null
if the terrain is not present in the hex
-
getAnyTerrainOf
- Parameters:
type
- the preferred type to gettypes
- the terrain types to check- Returns:
- Returns the Terrain for the preferred type, then an unspecified one of the given types of Terrain, or null if none are preset.
-
addTerrain
- Parameters:
terrain
- the terrain to add to this hex
-
removeTerrain
public void removeTerrain(int type) - Parameters:
type
- the terrain type to remove
-
removeAllTerrains
public void removeAllTerrains()Removes all Terrains from the hex. -
terrainsPresent
public int terrainsPresent()- Returns:
- the number of terrain attributes present
-
duplicate
FIXME : I should be a clone implementation, not this- Returns:
- new hex which is equal to this
-
applyTerrainPilotingModifiers
public void applyTerrainPilotingModifiers(EntityMovementMode moveMode, PilotingRollData roll, boolean enteringRubble) Adds terrain modifiers to PSRs made in this hex -
movementCost
- Returns:
- extra movement cost for entering the hex
-
getIgnitionModifier
public int getIgnitionModifier()- Returns:
- the modifier to the roll to ignite this hex
-
isIgnitable
public boolean isIgnitable()- Returns:
- if this hex is ignitable
-
isClearForTakeoff
public boolean isClearForTakeoff()Returns true if the hex is valid for takeoff - either clear, has pavement, or a road- Returns:
-
isClearForLanding
public boolean isClearForLanding() -
getBaseTerrainType
public int getBaseTerrainType()Returns the "Base Terrain" for the hex, or 0 if it is clear- Returns:
-
getFireTurn
public int getFireTurn() -
incrementFireTurn
public void incrementFireTurn() -
resetFireTurn
public void resetFireTurn() -
getBogDownModifier
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 -
getUnstuckModifier
get any modifiers to an unstuck roll in this hex. -
hasCliffTopTowards
True if this hex has a clifftop towards otherHex. This hex must have the terrain CLIFF_TOP, it must have exits specified (exits set to active) for the CLIFF_TOP terrain, and must have an exit in the direction of otherHex. -
getCoords
Returns the position of this hex on the board. -
setCoords
Sets the coords of this hex. DO NOT USE outside board.java! WILL NOT MOVE THE HEX. Only the position of the hex in the board's data[] determines the actual location of the hex. -
isClearHex
public boolean isClearHex()- Returns:
- if this hex is "clear", based on the absence of most terrain types.
-
isValid
Returns true when the hex has no invalid terrain. When the given list of errors is not null, any error reports from this hex are added to it.- Parameters:
errors
- A list to add error messages to- Returns:
- True if the hex is valid
-
toString
-
getClipboardString
Returns a string representation of this Hex to use for copy/paste actions. The string contains the elevation, theme and terrains of this Hex except automatic terrains (such as inclines). The generated string can be parsed to generate a copy of the hex usingparseClipboardString(String)
.- Returns:
- A string representation to use when copying a hex to the clipboard.
-
parseClipboardString
Returns a new Hex parsed from a clipboard string representation. Returns null when the clipboard String is not created bygetClipboardString()
(i.e., when it does not at least start with "MegaMek Hex").- Parameters:
clipboardString
- The string representation of the Hex to parse- Returns:
- A hex containing any features that could be parsed from clipboardString
-