Package megamek.common.units
Class Building
java.lang.Object
megamek.common.units.Building
- All Implemented Interfaces:
Serializable
This class represents a single, possibly multi-hex building on the board.
FIXME : This needs a complete rewrite to properly handle the latest building rules
Rewrite Notes: TODO : 1) Migrate Magic Numbers to Enums TODO : 2) Offboard Gun Emplacements: Revisit with a required rules query (CustomMekDialog - 22-Feb-2022)
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddDemolitionCharge(int playerId, int damage, Coords pos) Adds a demolition charge to this building.voidaddHex(CubeCoords relativeCoords, int cf, int armorValue, BasementType basementType, boolean collapsed) Add a hex to this building at the given RELATIVE coordinates.static StringclassName(int bldgClass) Returns a string representation of the given building class, e.g.voidcollapseBasement(CubeCoords coords, Board board, Vector<Report> vPhaseReport) booleanTwo Buildings are equal if and only if their IDs are equal.intgetArmor(CubeCoords coords) getBasement(CubeCoords coords) booleangetBasementCollapsed(CubeCoords coords) Get the building basement, per TacOps rules.intGet the building class, per TacOps rules.intintGet the default height of the building.Get the construction type of the building.intGet the coordinates that the building occupies.Returns a list of this Building's coords.intgetCurrentCF(CubeCoords coords) Get the current construction factor of the building hex at the passed coords.intgetHeight(CubeCoords coords) Get the height (BLDG_ELEV) of the building hex at the passed coords.intgetId()Get the ID of this building.getName()Get the name of this building.Returns a list of this Building's original coords (before any hexes were removed).intintgetPhaseCF(CubeCoords coords) Get the construction factor of the building hex at the passed coords at the start of the current phase.booleanhasCFIn(CubeCoords coords) Determines if the coord exist in the currentCF has.inthashCode()booleanisBurning(CubeCoords coords) Determine if this building is on fire.booleanisIn(CubeCoords coords) Determine if the building occupies given coordinates.voidvoidremoveHex(CubeCoords coords) Remove one building hex from the buildingbooleanrollBasement(CubeCoords coords, Board board, Vector<Report> vPhaseReport) Roll what kind of basement this building has at the given RELATIVE coordinates.voidsetArmor(int a, CubeCoords coords) voidsetBasement(CubeCoords coords, BasementType basement) voidsetBasementCollapsed(CubeCoords coords, boolean collapsed) voidsetBoardId(int boardId) voidsetBuildingHeight(int buildingHeight) Set the default height of the building.voidsetBurning(boolean onFire, CubeCoords coords) Set the flag that indicates that this building is on fire.voidsetCurrentCF(int cf, CubeCoords coords) Set the current construction factor of the building hex.voidsetDemolitionCharges(List<DemolitionCharge> charges) voidsetHeight(int h, CubeCoords coords) Set the height of a specific building hex.voidsetPhaseCF(int cf, CubeCoords coords) Set the construction factor of the building hex for the start of the next phase.toString()
-
Constructor Details
-
Building
-
-
Method Details
-
isIn
Determine if the building occupies given coordinates. Multi-hex buildings will occupy multiple coordinates. Only one building per hex.- Parameters:
coords- - theCubeCoordsbeing examined.- Returns:
trueif the building occupies the coordinates.falseotherwise.
-
addHex
public void addHex(CubeCoords relativeCoords, int cf, int armorValue, BasementType basementType, boolean collapsed) Add a hex to this building at the given RELATIVE coordinates. All coordinates are relative to the building's origin (0,0,0).Building stores everything in its own local coordinate space using CubeCoords. BuildingTerrain and AbstractBuildingEntity handle translation between board Coords and relative CubeCoords.
- Parameters:
relativeCoords- the relativeCubeCoordsof the hex within the buildingcf- the construction factor for this hexarmorValue- the armor value for this hexbasementType- the basement type for this hexcollapsed- whether the basement is collapsed
-
getId
public int getId()Get the ID of this building. The same ID applies to all hexes.- Returns:
- the
intID of the building.
-
hasCFIn
Determines if the coord exist in the currentCF has.- Parameters:
coords- - theCubeCoordsbeing examined.- Returns:
trueif the building has CF at the coordinates.falseotherwise.
-
getCoords
Get the coordinates that the building occupies.- Returns:
- an
Enumerationof theCubeCoordobjects.
-
getCoordsList
Returns a list of this Building's coords. The list is unmodifiable. -
getOriginalCoordsList
Returns a list of this Building's original coords (before any hexes were removed). The list is unmodifiable. -
getBuildingType
Get the construction type of the building. This value will be one of the values defined in megamek.common.enums.BuildingType- Returns:
- the
intcode of the building's construction type.
-
getBldgClass
public int getBldgClass()Get the building class, per TacOps rules.- Returns:
- the
intcode of the building's classification.
-
getBasementCollapsed
Get the building basement, per TacOps rules.- Returns:
- the
intcode of the building basement type.
-
collapseBasement
-
rollBasement
Roll what kind of basement this building has at the given RELATIVE coordinates. Building works in relative CubeCoords - BuildingTerrain/BuildingEntity handle board coord translation.- Parameters:
coords- the RELATIVECubeCoordsof the building hex to roll forvPhaseReport- theReportVectorcontaining the phase report- Returns:
- a
booleanindicating whether the hex and building was changed or not
-
getCurrentCF
Get the current construction factor of the building hex at the passed coords. Any damage immediately updates this value.- Parameters:
coords- theCubeCoordsof the hex in question- Returns:
- the
intvalue of the building hex's current construction factor. This value will be greater than or equal to zero.
-
getPhaseCF
Get the construction factor of the building hex at the passed coords at the start of the current phase. Damage that is received during the phase is applied at the end of the phase.- Parameters:
coords- theCubeCoordsof the hex in question- Returns:
- the
intvalue of the building's construction factor at the start of this phase. This value will be greater than or equal to zero.
-
getArmor
-
setCurrentCF
Set the current construction factor of the building hex. Call this method immediately when the building sustains any damage.- Parameters:
cf- theintvalue of the building hex's current construction factor. This value must be greater than or equal to zero.coords- theCubeCoordsof the hex in question- Throws:
IllegalArgumentException- if the passed value is less than zero
-
setPhaseCF
Set the construction factor of the building hex for the start of the next phase. Call this method at the end of the phase to apply damage sustained by the building during the phase.- Parameters:
cf- theintvalue of the building hex's current construction factor. This value must be greater than or equal to zero.coords- theCubeCoordsof the hex in question- Throws:
IllegalArgumentException- if the passed value is less than zero
-
setArmor
-
getHeight
Get the height (BLDG_ELEV) of the building hex at the passed coords.- Parameters:
coords- theCubeCoordsof the hex in question- Returns:
- the
intvalue of the building hex's height. This value will be 0 if the hex is destroyed.
-
setHeight
Set the height of a specific building hex. Call this method when a hex is destroyed (set to 0).- Parameters:
h- theintvalue of the building hex's height. This value must be greater than or equal to zero.coords- theCubeCoordsof the hex in question- Throws:
IllegalArgumentException- if the passed value is less than zero
-
getBuildingHeight
public int getBuildingHeight()Get the default height of the building. All hexes start with this height.- Returns:
- the
intvalue of the building's height (BLDG_ELEV).
-
setBuildingHeight
public void setBuildingHeight(int buildingHeight) Set the default height of the building. This should be called when creating a BuildingTerrain from board data.- Parameters:
buildingHeight- theintvalue of the building's height (BLDG_ELEV).
-
getName
Get the name of this building.- Returns:
- the
Stringname of this building.
-
equals
Two Buildings are equal if and only if their IDs are equal. -
hashCode
public int hashCode() -
className
Returns a string representation of the given building class, e.g. "Hangar". -
toString
-
isBurning
Determine if this building is on fire.- Returns:
trueif the building is on fire.
-
setBurning
Set the flag that indicates that this building is on fire.- Parameters:
onFire- - abooleanvalue that indicates whether this building is on fire.
-
addDemolitionCharge
Adds a demolition charge to this building. The position is stored as absolute board coordinates (not building-relative coordinates) because all consumers ofDemolitionCharge.pos- the touch-off menu, the end-phase building lookup and the damage application - operate on board coordinates.- Parameters:
playerId- the ID of the player that owns the chargedamage- the damage the charge inflicts when detonatedpos- the absolute boardCoordsof the building hex the charge is placed in
-
removeDemolitionCharge
-
getDemolitionCharges
-
setDemolitionCharges
-
removeHex
Remove one building hex from the building- Parameters:
coords- - theCubeCoordsof the hex to be removed
-
getOriginalHexCount
public int getOriginalHexCount() -
getCollapsedHexCount
public int getCollapsedHexCount() -
getBasement
-
setBasement
-
setBasementCollapsed
-
getBoardId
public int getBoardId() -
setBoardId
public void setBoardId(int boardId)
-