Class BuildingTerrain

java.lang.Object
megamek.common.units.BuildingTerrain
All Implemented Interfaces:
Serializable, IBuilding
Direct Known Subclasses:
FuelTank

public class BuildingTerrain extends Object implements IBuilding
BuildingTerrain represents a stationary building placed on the board.

It contains a Building (which stores data in relative coordinates) and handles translation between board coordinates and the Building's relative coordinate space.

See Also:
  • Constructor Details

    • BuildingTerrain

      public BuildingTerrain(Coords coords, Board board, int structureType, BasementType basementType)
      Construct a BuildingTerrain from board information. Reads the building from the board and creates internal Building with relative coords.
  • Method Details

    • getBoardOrigin

      public Coords getBoardOrigin()
      Description copied from interface: IBuilding
      Get the board coordinates of this building's origin (where relative 0,0 maps to). For BuildingTerrain: the static placement coords For AbstractBuildingEntity: the entity's current position
      Specified by:
      getBoardOrigin in interface IBuilding
      Returns:
      the board coordinates of the origin, or null if not placed
    • getBoardFacing

      public int getBoardFacing()
      Description copied from interface: IBuilding
      Get the facing/rotation of this building in board space. 0 = north, 1-5 = clockwise rotation
      Specified by:
      getBoardFacing in interface IBuilding
      Returns:
      the facing (0-5)
    • getInternalBuilding

      public Building getInternalBuilding()
      Description copied from interface: IBuilding
      Get the internal Building instance that stores data in relative coordinates. Building returns itself; BuildingTerrain/BuildingEntity override to return wrapped instance.
      Specified by:
      getInternalBuilding in interface IBuilding
      Returns:
      the internal Building instance
    • boardToRelative

      public CubeCoords boardToRelative(Coords boardCoords)
      Description copied from interface: IBuilding
      Convert board coordinates to relative CubeCoordinates. Default: convert board Coords to CubeCoords. BuildingTerrain/BuildingEntity override to translate using their coord maps.
      Specified by:
      boardToRelative in interface IBuilding
      Parameters:
      boardCoords - the board coordinates
      Returns:
      the relative CubeCoordinates
    • relativeToBoard

      public Coords relativeToBoard(CubeCoords relativeCoords)
      Description copied from interface: IBuilding
      Convert relative CubeCoordinates to board coordinates. Default: convert CubeCoords to offset Coords. BuildingTerrain/BuildingEntity override to translate using their coord maps.
      Specified by:
      relativeToBoard in interface IBuilding
      Parameters:
      relativeCoords - the relative CubeCoordinates
      Returns:
      the board coordinates
    • getId

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

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

      public Enumeration<Coords> getCoords()
      Get the BOARD coordinates that the building occupies.
      Specified by:
      getCoords in interface IBuilding
      Returns:
      an Enumeration of the BOARD Coord objects.
    • getCoordsList

      public List<Coords> getCoordsList()
      Returns a list of this Building's BOARD coords. The list is unmodifiable.
      Specified by:
      getCoordsList in interface IBuilding
    • 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
      Specified by:
      getBuildingType in interface IBuilding
      Returns:
      the int code of the building's construction type.
    • getBldgClass

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

      public boolean getBasementCollapsed(Coords coords)
      Get the building basement, per TacOps rules.
      Specified by:
      getBasementCollapsed in interface IBuilding
      Parameters:
      coords - BOARD coordinates
      Returns:
      the int code of the building basement type.
    • collapseBasement

      public void collapseBasement(Coords coords, Board board, Vector<Report> vPhaseReport)
      Specified by:
      collapseBasement in interface IBuilding
    • rollBasement

      public boolean rollBasement(Coords coords, Board board, Vector<Report> vPhaseReport)
      Roll what kind of basement this building has
      Specified by:
      rollBasement in interface IBuilding
      Parameters:
      coords - BOARD coordinates of the building to roll for
      board - the game board
      vPhaseReport - the Report Vector containing the phase report
      Returns:
      a boolean indicating weather the hex and building was changed or not
    • getCurrentCF

      public int getCurrentCF(Coords coords)
      Get the current construction factor of the building hex at the passed coords. Any damage immediately updates this value.
      Specified by:
      getCurrentCF in interface IBuilding
      Parameters:
      coords - the BOARD Coords 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(Coords 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.
      Specified by:
      getPhaseCF in interface IBuilding
      Parameters:
      coords - the BOARD Coords 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(Coords coords)
      Specified by:
      getArmor in interface IBuilding
    • setCurrentCF

      public void setCurrentCF(int cf, Coords coords)
      Set the current construction factor of the building hex. Call this method immediately when the building sustains any damage.
      Specified by:
      setCurrentCF in interface IBuilding
      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 BOARD Coords of the hex in question
      Throws:
      IllegalArgumentException - if the passed value is less than zero
    • setPhaseCF

      public void setPhaseCF(int cf, Coords 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.
      Specified by:
      setPhaseCF in interface IBuilding
      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 BOARD Coords of the hex in question
      Throws:
      IllegalArgumentException - if the passed value is less than zero
    • setArmor

      public void setArmor(int a, Coords coords)
      Specified by:
      setArmor in interface IBuilding
    • getHeight

      public int getHeight(Coords coords)
      Description copied from interface: IBuilding
      Get the height (BLDG_ELEV) of the building hex at the passed coords.
      Specified by:
      getHeight in interface IBuilding
      Parameters:
      coords - the Coords 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, Coords coords)
      Description copied from interface: IBuilding
      Set the height of a specific building hex. Call this method when a hex is destroyed (set to 0).
      Specified by:
      setHeight in interface IBuilding
      Parameters:
      h - the int value of the building hex's height. This value must be greater than or equal to zero.
      coords - the Coords of the hex in question
    • getName

      public String getName()
      Get the name of this building.
      Specified by:
      getName in interface IBuilding
      Returns:
      the String name of this building.
    • isBurning

      public boolean isBurning(Coords coords)
      Determine if this building is on fire.
      Specified by:
      isBurning in interface IBuilding
      Parameters:
      coords - BOARD coordinates
      Returns:
      true if the building is on fire.
    • setBurning

      public void setBurning(boolean onFire, Coords coords)
      Set the flag that indicates that this building is on fire.
      Specified by:
      setBurning in interface IBuilding
      Parameters:
      onFire - - a boolean value that indicates whether this building is on fire.
      coords - BOARD coordinates
    • addDemolitionCharge

      public void addDemolitionCharge(int playerId, int damage, Coords pos)
      Specified by:
      addDemolitionCharge in interface IBuilding
    • removeDemolitionCharge

      public void removeDemolitionCharge(DemolitionCharge charge)
      Specified by:
      removeDemolitionCharge in interface IBuilding
    • getDemolitionCharges

      public List<DemolitionCharge> getDemolitionCharges()
      Specified by:
      getDemolitionCharges in interface IBuilding
    • setDemolitionCharges

      public void setDemolitionCharges(List<DemolitionCharge> charges)
      Specified by:
      setDemolitionCharges in interface IBuilding
    • removeHex

      public void removeHex(Coords coords)
      Remove one building hex from the building
      Specified by:
      removeHex in interface IBuilding
      Parameters:
      coords - - the BOARD Coords of the hex to be removed
    • getOriginalHexCount

      public int getOriginalHexCount()
      Specified by:
      getOriginalHexCount in interface IBuilding
    • getCollapsedHexCount

      public int getCollapsedHexCount()
      Specified by:
      getCollapsedHexCount in interface IBuilding
    • getBasement

      public BasementType getBasement(Coords coords)
      Specified by:
      getBasement in interface IBuilding
    • setBasement

      public void setBasement(Coords coords, BasementType basement)
      Specified by:
      setBasement in interface IBuilding
    • setBasementCollapsed

      public void setBasementCollapsed(Coords coords, boolean collapsed)
      Specified by:
      setBasementCollapsed in interface IBuilding
    • getBoardId

      public int getBoardId()
      Specified by:
      getBoardId in interface IBuilding
    • setBoardId

      public void setBoardId(int boardId)
      Specified by:
      setBoardId in interface IBuilding
    • equals

      public boolean equals(Object other)
      Compare the internal building
      Overrides:
      equals in class Object
    • toString

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

      public int hashCode()
      Overrides:
      hashCode in class Object