Class Building

java.lang.Object
megamek.common.units.Building
All Implemented Interfaces:
Serializable

public class Building extends Object implements 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 Details

    • Building

      public Building(BuildingType type, int bldgClass, int id, int structureType)
  • Method Details

    • isIn

      public boolean isIn(CubeCoords coords)
      Determine if the building occupies given coordinates. Multi-hex buildings will occupy multiple coordinates. Only one building per hex.
      Parameters:
      coords - - the CubeCoords being examined.
      Returns:
      true if the building occupies the coordinates. false otherwise.
    • 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 relative CubeCoords of the hex within the building
      cf - the construction factor for this hex
      armorValue - the armor value for this hex
      basementType - the basement type for this hex
      collapsed - whether the basement is collapsed
    • getId

      public int getId()
      Get the ID of this building. The same ID applies to all hexes.
      Returns:
      the int ID of the building.
    • hasCFIn

      public boolean hasCFIn(CubeCoords coords)
      Determines if the coord exist in the currentCF has.
      Parameters:
      coords - - the CubeCoords being examined.
      Returns:
      true if the building has CF at the coordinates. false otherwise.
    • getCoords

      public Enumeration<CubeCoords> getCoords()
      Get the coordinates that the building occupies.
      Returns:
      an Enumeration of the CubeCoord objects.
    • getCoordsList

      public List<CubeCoords> getCoordsList()
      Returns a list of this Building's coords. The list is unmodifiable.
    • getOriginalCoordsList

      public List<CubeCoords> getOriginalCoordsList()
      Returns a list of this Building's original coords (before any hexes were removed). The list is unmodifiable.
    • getBuildingType

      public BuildingType getBuildingType()
      Get the construction type of the building. This value will be one of the values defined in megamek.common.enums.BuildingType
      Returns:
      the int code of the building's construction type.
    • getBldgClass

      public int getBldgClass()
      Get the building class, per TacOps rules.
      Returns:
      the int code of the building's classification.
    • getBasementCollapsed

      public boolean getBasementCollapsed(CubeCoords coords)
      Get the building basement, per TacOps rules.
      Returns:
      the int code of the building basement type.
    • collapseBasement

      public void collapseBasement(CubeCoords coords, Board board, Vector<Report> vPhaseReport)
    • rollBasement

      public boolean rollBasement(CubeCoords coords, Board board, Vector<Report> vPhaseReport)
      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 RELATIVE CubeCoords of the building hex to roll for
      vPhaseReport - the Report Vector containing the phase report
      Returns:
      a boolean indicating whether the hex and building was changed or not
    • getCurrentCF

      public int getCurrentCF(CubeCoords coords)
      Get the current construction factor of the building hex at the passed coords. Any damage immediately updates this value.
      Parameters:
      coords - the CubeCoords of the hex in question
      Returns:
      the int value of the building hex's current construction factor. This value will be greater than or equal to zero.
    • getPhaseCF

      public int getPhaseCF(CubeCoords coords)
      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 - the CubeCoords of the hex in question
      Returns:
      the int value of the building's construction factor at the start of this phase. This value will be greater than or equal to zero.
    • getArmor

      public int getArmor(CubeCoords coords)
    • setCurrentCF

      public void setCurrentCF(int cf, CubeCoords coords)
      Set the current construction factor of the building hex. Call this method immediately when the building sustains any damage.
      Parameters:
      cf - the int value of the building hex's current construction factor. This value must be greater than or equal to zero.
      coords - the CubeCoords of the hex in question
      Throws:
      IllegalArgumentException - if the passed value is less than zero
    • setPhaseCF

      public void setPhaseCF(int cf, CubeCoords coords)
      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 - the int value of the building hex's current construction factor. This value must be greater than or equal to zero.
      coords - the CubeCoords of the hex in question
      Throws:
      IllegalArgumentException - if the passed value is less than zero
    • setArmor

      public void setArmor(int a, CubeCoords coords)
    • getHeight

      public int getHeight(CubeCoords coords)
      Get the height (BLDG_ELEV) of the building hex at the passed coords.
      Parameters:
      coords - the CubeCoords of the hex in question
      Returns:
      the int value of the building hex's height. This value will be 0 if the hex is destroyed.
    • setHeight

      public void setHeight(int h, CubeCoords coords)
      Set the height of a specific building hex. Call this method when a hex is destroyed (set to 0).
      Parameters:
      h - the int value of the building hex's height. This value must be greater than or equal to zero.
      coords - the CubeCoords of 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 int value 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 - the int value of the building's height (BLDG_ELEV).
    • getName

      public String getName()
      Get the name of this building.
      Returns:
      the String name of this building.
    • equals

      public boolean equals(Object other)
      Two Buildings are equal if and only if their IDs are equal.
      Overrides:
      equals in class Object
      Parameters:
      other - The other Object to compare
      Returns:
      True if this and the given other are considered equal
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • className

      public static String className(int bldgClass)
      Returns a string representation of the given building class, e.g. "Hangar".
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • isBurning

      public boolean isBurning(CubeCoords coords)
      Determine if this building is on fire.
      Returns:
      true if the building is on fire.
    • setBurning

      public void setBurning(boolean onFire, CubeCoords coords)
      Set the flag that indicates that this building is on fire.
      Parameters:
      onFire - - a boolean value that indicates whether this building is on fire.
    • addDemolitionCharge

      public void addDemolitionCharge(int playerId, int damage, Coords pos)
      Adds a demolition charge to this building. The position is stored as absolute board coordinates (not building-relative coordinates) because all consumers of DemolitionCharge.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 charge
      damage - the damage the charge inflicts when detonated
      pos - the absolute board Coords of the building hex the charge is placed in
    • removeDemolitionCharge

      public void removeDemolitionCharge(DemolitionCharge charge)
    • getDemolitionCharges

      public List<DemolitionCharge> getDemolitionCharges()
    • setDemolitionCharges

      public void setDemolitionCharges(List<DemolitionCharge> charges)
    • removeHex

      public void removeHex(CubeCoords coords)
      Remove one building hex from the building
      Parameters:
      coords - - the CubeCoords of the hex to be removed
    • getOriginalHexCount

      public int getOriginalHexCount()
    • getCollapsedHexCount

      public int getCollapsedHexCount()
    • getBasement

      public BasementType getBasement(CubeCoords coords)
    • setBasement

      public void setBasement(CubeCoords coords, BasementType basement)
    • setBasementCollapsed

      public void setBasementCollapsed(CubeCoords coords, boolean collapsed)
    • getBoardId

      public int getBoardId()
    • setBoardId

      public void setBoardId(int boardId)