Class AbstractBuildingEntity

All Implemented Interfaces:
Serializable, ICarryable, Transporter, InGameObject, CombatRole, ForceAssignable, ITechnology, ITurnOrdered, PhaseUpdated, RoundUpdated, BTObject, Deployable, IBuilding, Targetable
Direct Known Subclasses:
BuildingEntity, MobileStructure

public abstract class AbstractBuildingEntity extends Entity implements IBuilding
AbstractBuildingEntity represents a non-terrain building (e.g., a moving fortress). This is the common implementation of the Mobile Structure rules from TO:AUE and Advanced Building rules from TO:AUE.
It contains a Building (which stores data in relative coordinates) and handles translation between board coordinates and the Building's relative coordinate space. Unlike BuildingTerrain, the translation is dynamic based on Entity's current position/facing.
See Also:
  • Field Details

    • HIT_LOCATION_NAMES

      public static final String[] HIT_LOCATION_NAMES
  • Constructor Details

    • AbstractBuildingEntity

      public AbstractBuildingEntity(BuildingType type, int bldgClass)
  • Method Details

    • defaultCrewType

      public CrewType defaultCrewType()
      Overrides:
      defaultCrewType in class Entity
    • 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

      @Nullable public CubeCoords boardToRelative(@Nullable 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
    • getWeaponFiringPosition

      public Coords getWeaponFiringPosition(WeaponMounted weapon)
      Description copied from class: Entity
      What Coords is this weapon physically firing from?
      Overrides:
      getWeaponFiringPosition in class Entity
      Parameters:
      weapon - WeaponMounted
      Returns:
      Coords
    • getWeaponFiringHeight

      public int getWeaponFiringHeight(WeaponMounted weapon)
      Description copied from class: Entity
      What height is this weapon physically firing from?
      Overrides:
      getWeaponFiringHeight in class Entity
      Parameters:
      weapon - WeaponMounted
      Returns:
      int
    • setPosition

      public void setPosition(Coords position)
      Override setPosition to populate the relativeLayout map when the entity is placed. This establishes the mapping between the building's internal relative coordinates and their actual board coordinates.
      Overrides:
      setPosition in class Entity
    • setPosition

      public void setPosition(Coords position, boolean gameUpdate)
      Description copied from class: Entity
      Sets the current position of this entity on the board.
      Overrides:
      setPosition in class Entity
      Parameters:
      position - the new position.
    • isLocationProhibited

      public boolean isLocationProhibited(Coords testPosition, int testBoardId, int testElevation)
      Returns true when the given location cannot legally be entered or deployed into by this unit at the given elevation or altitude. Also returns true when the location doesn't exist. Even when this method returns true, the location need not be deadly to the unit.
      Overrides:
      isLocationProhibited in class Entity
      Parameters:
      testPosition - The position to test
      testBoardId - The board to test
      testElevation - The elevation or altitude to test
      Returns:
      True when the location is illegal to be in for this unit, regardless of elevation
      See Also:
    • computeLayoutForPositionAndFacing

      @Deprecated(since="0.51.0", forRemoval=true) public Map<CubeCoords,Coords> computeLayoutForPositionAndFacing(Coords testPosition, int testFacing)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Computes what the relative layout would be for a hypothetical position and facing WITHOUT modifying the entity's actual position or facing. This is a pure calculation method with no side effects.
      Parameters:
      testPosition - The position to test
      testFacing - The facing to test (0-5)
      Returns:
      Map of relative CubeCoords to their board Coords at the given position/facing
    • isPositionAndFacingValid

      public boolean isPositionAndFacingValid(Coords testPosition, int testFacing, int testElevation, int testBoardId)
      Checks if all hexes of this building would be valid at the given position and facing WITHOUT modifying the entity's state. This is a pure calculation method.
      Parameters:
      testPosition - The position to test
      testFacing - The facing to test (0-5)
      testElevation - The elevation to test
      testBoardId - The board ID to test
      Returns:
      true if all building hexes would be valid at this position/facing
    • getValidFacingsAt

      public List<Integer> getValidFacingsAt(Coords testPosition, int testElevation, int testBoardId)
      Returns all valid facings for this building at the given position and elevation. Does NOT modify the entity's facing - this is a pure calculation method.
      Parameters:
      testPosition - The position to test
      testElevation - The elevation to test
      testBoardId - The board ID to test
      Returns:
      List of valid facings (0-5), or empty list if none valid
    • locations

      public int locations()
      Returns the number of locations in the entity
      Specified by:
      locations in class Entity
    • refreshAdditionalLocations

      public void refreshAdditionalLocations()
    • setFacing

      public void setFacing(int facing)
      Sets the primary facing.
      Overrides:
      setFacing in class Entity
    • canChangeSecondaryFacing

      public boolean canChangeSecondaryFacing()
      Can this entity change secondary facing at all?
      Specified by:
      canChangeSecondaryFacing in class Entity
    • isValidSecondaryFacing

      public boolean isValidSecondaryFacing(int dir)
      Can this entity torso/turret twist the given direction?
      Specified by:
      isValidSecondaryFacing in class Entity
    • clipSecondaryFacing

      public int clipSecondaryFacing(int dir)
      Returns the closest valid secondary facing to the given direction.
      Specified by:
      clipSecondaryFacing in class Entity
      Returns:
      the closest valid secondary facing.
    • getLocationNames

      public String[] getLocationNames()
      Specified by:
      getLocationNames in class Entity
    • getLocationAbbreviations

      public String[] getLocationAbbreviations()
      Specified by:
      getLocationAbbreviations in class Entity
    • sideTable

      public int sideTable(Coords src)
      Specified by:
      sideTable in interface Targetable
      Overrides:
      sideTable in class Entity
      Returns:
      side hit from location
    • rollHitLocation

      public HitData rollHitLocation(int table, int side, int aimedLocation, AimingMode aimingMode, int cover)
      Rolls the to-hit number
      Specified by:
      rollHitLocation in class Entity
    • rollHitLocation

      public HitData rollHitLocation(int table, int side)
      Rolls up a hit location
      Specified by:
      rollHitLocation in class Entity
    • getTransferLocation

      public HitData getTransferLocation(HitData hit)
      Gets the location that excess damage transfers to. That is, one location inwards.
      Specified by:
      getTransferLocation in class Entity
    • autoSetInternal

      public void autoSetInternal()
      Sets the internal structure for every location to appropriate undamaged values for the unit and location.
      Specified by:
      autoSetInternal in class Entity
    • getWeaponArc

      public int getWeaponArc(int weaponNumber)
      Returns the Rules.ARC that the weapon, specified by number, fires into.
      Specified by:
      getWeaponArc in class Entity
      Parameters:
      weaponNumber - integer equipment number, index from equipment list
      Returns:
      arc the specified weapon is in
    • isSecondaryArcWeapon

      public boolean isSecondaryArcWeapon(int weaponId)
      Returns true if this weapon fires into the secondary facing arc. If false, assume it fires into the primary.
      Specified by:
      isSecondaryArcWeapon in class Entity
    • getNoOfSlots

      public int[] getNoOfSlots()
      Specified by:
      getNoOfSlots in class Entity
    • addEquipment

      public void addEquipment(Mounted<?> mounted, int loc, boolean rearMounted) throws LocationFullException
      Description copied from class: Entity
      Adds the given mounted equipment to the unit in the given location, possibly rear-facing depending on the given parameter. This method adds the mounted to the right equipment lists, updates the unit's tech level and adds one-shot ammo where necessary. Overriding methods may perform more tasks. This method, by default, does *NOT* create crit slots, update or add linkages nor handle secondary locations. Overrides for unit types may however do that.
      Overrides:
      addEquipment in class Entity
      Parameters:
      mounted - The new equipment
      loc - The location; may be Entity.LOC_NONE
      rearMounted - True to make the equipment rear-facing
      Throws:
      LocationFullException - When the location is full
    • victoryReport

      public Vector<Report> victoryReport()
      Calculates a "generic" Battle Value that is based on the average of all units of this type and tonnage. The purpose of this generic Battle Value is to allow a comparison of this unit's actual BV to that for units of its class. This can be used to balance forces without respect to unit or pilot quality.

      /** Generates a vector containing reports on all useful information about this entity.

      Specified by:
      victoryReport in class Entity
    • addEntityBonuses

      public PilotingRollData addEntityBonuses(PilotingRollData roll)
      Add in any piloting skill mods
      Specified by:
      addEntityBonuses in class Entity
    • isRepairable

      public boolean isRepairable()
      Description copied from class: Entity
      Determine if the unit can be repaired, or only harvested for spares.
      Overrides:
      isRepairable in class Entity
      Returns:
      A boolean that is true if the unit can be repaired (given enough time and parts); if this value is false, the unit is only a source of spares.
      See Also:
    • isTargetable

      public boolean isTargetable()
      Description copied from class: Entity
      Returns true if this entity is targetable for attacks. A unit is targetable if it is not destroyed, not doomed, deployed, not off board, not being transported, and not captured.
      Overrides:
      isTargetable in class Entity
    • canCharge

      public boolean canCharge()
      Overrides:
      canCharge in class Entity
      Returns:
      Whether this type of unit can perform charges
    • canFlee

      public boolean canFlee(Coords position)
      Description copied from class: Entity
      Returns true when this unit can flee from the given position in its current state. This requires the unit to have mobility and be in control as well as the position being eligible for fleeing. When no special flee area is set by a scenario, the latter will typically be true when the position is at the edge of its board. A null position as well as offboard units are considered to be eligible for fleeing.
      Overrides:
      canFlee in class Entity
      Returns:
      True when the unit can flee from the given position, given its current status
    • canGoDown

      public boolean canGoDown()
      Overrides:
      canGoDown in class Entity
    • canGoDown

      public boolean canGoDown(int assumed, Coords coords, int boardId)
      Description copied from class: Entity
      is it possible to go down, or are we landed/just above the water/treeline? assuming passed elevation.
      Overrides:
      canGoDown in class Entity
    • getCost

      public double getCost(CalculationReport calcReport, boolean ignoreAmmo)
      Calculates and returns the C-bill cost of the unit. The parameter ignoreAmmo can be used to include or exclude ("dry cost") the cost of ammunition on the unit. A report for the cost calculation will be written to the given calcReport.
      Specified by:
      getCost in class Entity
      Parameters:
      calcReport - A CalculationReport to write the report for the cost calculation to
      ignoreAmmo - When true, the cost of ammo on the unit will be excluded from the cost
      Returns:
      The cost in C-Bills of the 'Mek in question.
    • isNuclearHardened

      public boolean isNuclearHardened()
      Description copied from class: Entity
      Checks if the unit is hardened against nuclear strikes.
      Overrides:
      isNuclearHardened in class Entity
      Returns:
      true if this is a hardened unit.
    • getTotalCommGearTons

      public int getTotalCommGearTons()
      Overrides:
      getTotalCommGearTons in class Entity
      Returns:
      the total tonnage of communications gear in this entity
    • getEngineHits

      public int getEngineHits()
      Specified by:
      getEngineHits in class Entity
    • isSalvage

      public boolean isSalvage()
      Buildings are salvageable unless they have completely collapsed. A building has completely collapsed when all hexes have 0 CF.
      Overrides:
      isSalvage in class Entity
      Returns:
      A boolean that is true if the unit has salvageable components; if this value is false the unit is utterly destroyed.
      See Also:
    • isCrippled

      public boolean isCrippled()
      Description copied from class: Entity
      Returns TRUE if the entity meets the requirements for crippling damage as detailed in TW pg 258.
      Specified by:
      isCrippled in class Entity
      Returns:
      boolean
    • isCrippled

      public boolean isCrippled(boolean checkCrew)
      Returns TRUE if the entity meets the requirements for crippling damage as detailed in TW pg 258. Excepting dead or non-existing crew issues
      Specified by:
      isCrippled in class Entity
      Returns:
      boolean
    • isDmgHeavy

      public boolean isDmgHeavy()
      Returns TRUE if the entity has been heavily damaged.
      Specified by:
      isDmgHeavy in class Entity
      Returns:
      boolean
    • isDmgModerate

      public boolean isDmgModerate()
      Returns TRUE if the entity has been moderately damaged.
      Specified by:
      isDmgModerate in class Entity
      Returns:
      boolean
    • isDmgLight

      public boolean isDmgLight()
      Returns TRUE if the entity has been lightly damaged.
      Specified by:
      isDmgLight in class Entity
      Returns:
      boolean
    • getArmorType

      public int getArmorType(int loc)
      Overrides:
      getArmorType in class Entity
    • getArmorTechLevel

      public int getArmorTechLevel(int loc)
      Overrides:
      getArmorTechLevel in class Entity
    • hasStealth

      public boolean hasStealth()
      Overrides:
      hasStealth in class Entity
      Returns:
      True if this unit has working stealth armor (not patchwork armor).
    • getEntityType

      public long getEntityType()
      Specified by:
      getEntityType in class Entity
    • getInternalForReal

      public int getInternalForReal(int loc)
      Overrides:
      getInternalForReal in class Entity
    • getArmor

      public int getArmor(int loc, boolean rear)
      Returns the amount of armor in the location specified, or IArmorState.ARMOR_NA, or IArmorState.ARMOR_DESTROYED.
      Overrides:
      getArmor in class Entity
    • setInternal

      public void setInternal(int val, int loc)
      Override to keep entity internal and building CF synchronized.
      Overrides:
      setInternal in class Entity
    • hasCFIn

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

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

      public List<Coords> getCoordsList()
      Description copied from interface: IBuilding
      Returns a list of this Building's coords. The list is unmodifiable.
      Specified by:
      getCoordsList in interface IBuilding
    • getBuildingType

      public BuildingType getBuildingType()
      Description copied from interface: IBuilding
      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()
      Description copied from interface: IBuilding
      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)
      Description copied from interface: IBuilding
      Get the building basement, per TacOps rules.
      Specified by:
      getBasementCollapsed in interface IBuilding
      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)
      Description copied from interface: IBuilding
      Roll what kind of basement this building has
      Specified by:
      rollBasement in interface IBuilding
      Parameters:
      coords - the Coords of the building to roll for
      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)
      Description copied from interface: IBuilding
      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 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)
      Description copied from interface: IBuilding
      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 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)
      Description copied from interface: IBuilding
      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 Coords of the hex in question
    • setPhaseCF

      public void setPhaseCF(int cf, Coords coords)
      Description copied from interface: IBuilding
      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 Coords of the hex in question
    • 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()
      Description copied from interface: IBuilding
      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)
      Description copied from interface: IBuilding
      Determine if this building is on fire.
      Specified by:
      isBurning in interface IBuilding
      Returns:
      true if the building is on fire.
    • setBurning

      public void setBurning(boolean onFire, Coords coords)
      Description copied from interface: IBuilding
      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.
    • addDemolitionCharge

      public void addDemolitionCharge(int playerId, int damage, Coords pos)
      Demolition charges anchor to an absolute board hex, which only works for structures that cannot move. BuildingEntity overrides this with a real implementation; MobileStructure must provide its own (or remain unsupported) if mobile structures are ever ruled to be valid demolition targets.
      Specified by:
      addDemolitionCharge in interface IBuilding
      Throws:
      UnsupportedOperationException - always; subclasses that support demolition charges must override
    • 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)
      Description copied from interface: IBuilding
      Remove one building hex from the building
      Specified by:
      removeHex in interface IBuilding
      Parameters:
      coords - - the 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
    • updateBuildingEntityHexes

      public void updateBuildingEntityHexes(int boardId, TWGameManager gameManager)
      Once a building entity has set its position, we need to update the board itself and share that with the clients
    • refreshLocations

      public void refreshLocations()
      Overrides:
      refreshLocations in class Entity
    • collapseFloorsOnHex

      public void collapseFloorsOnHex(Coords coords, int numLevelsToCollapse)
      Parameters:
      coords - Board Coords that contain this building and are collapsing
      numLevelsToCollapse - number of floors to collapse, from the top
    • getNCrew

      public int getNCrew()
      Calculate building crew based on Advanced Building Minimum Crew Table (TO:AUE). Crew = Non-Gunners + Gunners + Officers
      Overrides:
      getNCrew in class Entity
      Returns:
      total crew count
    • isBoardable

      public boolean isBoardable()
      Description copied from class: Entity
      Determines if this entity can be boarded by infantry for interior combat. Used for TO:AR p. 167 Infantry vs Infantry combat eligibility as a target for initiation. This will eventually include dropships, large naval vessels, and other boardable entities.
      Overrides:
      isBoardable in class Entity
      Returns:
      true if infantry can board this entity to initiate interior combat
    • canReinforceInfantryVsInfantry

      public boolean canReinforceInfantryVsInfantry()
      Description copied from class: Entity
      Determines if this entity can reinforce ongoing infantry vs infantry combat. Default implementation returns false. Infantry units override this.
      Overrides:
      canReinforceInfantryVsInfantry in class Entity
      Returns:
      true if this entity can reinforce infantry vs infantry combat