Class BattlefieldSupportAsset

java.lang.Object
megamek.common.turns.TurnOrdered
megamek.common.units.Entity
megamek.common.battlefieldSupport.BattlefieldSupportAsset
All Implemented Interfaces:
Serializable, ICarryable, Transporter, InGameObject, CombatRole, ForceAssignable, ITechnology, ITurnOrdered, PhaseUpdated, RoundUpdated, BTObject, Deployable, Targetable

public class BattlefieldSupportAsset extends Entity
The Entity realization of a Battlefield Support Asset - a simplified unit governed by the Battlefield Support rules rather than by full construction/combat rules. This is the runtime object the rest of the program works with; the whole codebase deals with this entity (and its MekSummary), not with the BattlefieldSupportAssetData stat block, which exists only at the .bfs save/load boundary.

An asset is built from a BattlefieldSupportAssetData (see BattlefieldSupportAsset(BattlefieldSupportAssetData) and setFromData(megamek.common.battlefieldSupport.BattlefieldSupportAssetData)) and can produce one for saving via toAssetData(). A parameterless constructor is provided for tests and for creating a brand-new asset in MegaMekLab. Once built, all stat values live on this entity (chassis, model and role reuse the base Entity fields); MegaMekLab edits them here directly.

A single carrier class represents every asset category (BFSAssetType); behavior that differs by category or movement mode is derived from the stored values. Assets have no hit locations - the whole unit is a single location.

See Also:
  • Field Details

    • BV_PER_BSP

      public static final int BV_PER_BSP
      Battle Value per Battlefield Support Point.
      See Also:
    • GUNNERY_REGULAR

      public static final int GUNNERY_REGULAR
      The Regular/Veteran choice for an asset instance is carried by the crew's Gunnery skill (so it persists through the normal Crew/MUL machinery): a gunnery at or below GUNNERY_VETERAN means Veteran, otherwise Regular. These representative values are used when the UI toggles the level.
      See Also:
    • GUNNERY_VETERAN

      public static final int GUNNERY_VETERAN
      See Also:
    • DESTROYED_DESTROY_CHECK

      public static final int DESTROYED_DESTROY_CHECK
      A current Destroy Check strictly below this value means the asset has been destroyed by persistent damage (and is therefore shown as Entity.DMG_CRIPPLED). A destroyed asset is generally recorded with a Destroy Check of 0.
      See Also:
    • LOC_ASSET

      public static final int LOC_ASSET
      The single, whole-unit location. Assets do not use hit locations.
      See Also:
  • Constructor Details

    • BattlefieldSupportAsset

      public BattlefieldSupportAsset()
      Creates an empty asset with default values (for tests and for a brand-new asset in MegaMekLab).
    • BattlefieldSupportAsset

      public BattlefieldSupportAsset(BattlefieldSupportAssetData data)
      Creates an asset from the given stat block.
      Parameters:
      data - the stat block to build this asset from
  • Method Details

    • setFromData

      public void setFromData(BattlefieldSupportAssetData data)
      Copies every value from the given stat block onto this entity. Identity, role, movement mode and MP use the base Entity fields. Used when loading a .bfs file. Movement mode is applied before MP so that the MP is stored against the correct (walk vs jump) allowance.
      Parameters:
      data - the stat block to copy from
    • toAssetData

      public BattlefieldSupportAssetData toAssetData()
      Returns:
      a new stat block snapshot of this asset, suitable for writing to a .bfs file
    • getLinkedUnitId

      @Nullable public String getLinkedUnitId()
      Returns:
      the unit-file UUID of the base unit this asset is linked to, or null when the asset is standalone (not linked to a base unit)
    • setLinkedUnitId

      public void setLinkedUnitId(@Nullable String linkedUnitId)
      Sets the base unit this asset is linked to, by the base unit's unit-file UUID.
      Parameters:
      linkedUnitId - the base unit's UUID, or null/blank to make this a standalone asset
    • isLinkedToBaseUnit

      public boolean isLinkedToBaseUnit()
      Returns:
      whether this asset is linked to a base unit (has a non-blank getLinkedUnitId())
    • setAssetTechBase

      public void setAssetTechBase(String techBase)
      Applies a .bfs tech-base value (IS/Clan/Mixed) to this asset. Assets are always tech level Standard, so this sets only the base (via the Standard tech-level constant) and the mixed-tech flag.
      Parameters:
      techBase - one of BattlefieldSupportAssetData.TECH_BASE_IS/_CLAN/_MIXED
    • getAssetTechBase

      public String getAssetTechBase()
      Returns:
      this asset's tech base as a .bfs value (IS/Clan/Mixed (IS Chassis)/Mixed (Clan Chassis)).
    • isBattlefieldSupportAsset

      public boolean isBattlefieldSupportAsset()
      Returns:
      True when this object is a Battlefield Support Asset (a simplified unit governed by the Battlefield Support rules rather than by full construction/combat rules). False for all standard units.
    • getEntityType

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

      public int getUnitType()
      Specified by:
      getUnitType in class Entity
      See Also:
    • getConstructionTechAdvancement

      public TechAdvancement getConstructionTechAdvancement()
      Description copied from class: Entity
      return - the base construction option tech advancement
      Specified by:
      getConstructionTechAdvancement in class Entity
    • getAssetType

      public BFSAssetType getAssetType()
    • setAssetType

      public void setAssetType(BFSAssetType assetType)
    • getCardTitle

      @Nullable public String getCardTitle()
    • setCardTitle

      public void setCardTitle(@Nullable String cardTitle)
    • getCardSubtitle

      @Nullable public String getCardSubtitle()
    • setCardSubtitle

      public void setCardSubtitle(@Nullable String cardSubtitle)
    • getEffectiveCardTitle

      public String getEffectiveCardTitle()
      Returns:
      the title to print on the card: getCardTitle() if set, otherwise the chassis
    • getEffectiveCardSubtitle

      public String getEffectiveCardSubtitle()
      Returns:
      the subtitle to print on the card: getCardSubtitle() if set, otherwise the model
    • getMp

      public int getMp()
      Returns:
      the asset's single Movement Point allowance for its declared movement mode - the jump MP for jump modes, otherwise the walk MP
    • setMp

      public void setMp(int mp)
      Sets the asset's single Movement Point allowance against its declared movement mode - the jump MP for jump modes, otherwise the walk MP. Set the movement mode before calling this so the value is stored against the right allowance.
      Parameters:
      mp - the movement allowance
    • isJumpMode

      public boolean isJumpMode()
      Returns:
      true if this asset's movement mode is a jumping mode (its MP is a jump allowance)
    • getMovementDisplay

      public String getMovementDisplay()
      Returns:
      the card display form of movement, for example 8H
    • movementCardLetter

      public static String movementCardLetter(@Nullable EntityMovementMode mode)
      Parameters:
      mode - a movement mode
      Returns:
      the single-letter code shown on the Asset card for the given mode (for example H for hover)
    • getTmm

      public int getTmm()
    • setTmm

      public void setTmm(int tmm)
    • getTmmDisplay

      public String getTmmDisplay()
      Returns:
      the card display form of the TMM, always signed (for example +3). Immobile assets append a * (for example +0*) to indicate that, although the printed TMM is as shown, the -4 Immobile to-hit modifier applies so the effective TMM is -4.
    • isImmobileAsset

      public boolean isImmobileAsset()
      Returns:
      true if this asset has the Immobile Special (its TMM is shown with a * and it cannot move).
    • getRange

      public BFSRange getRange()
    • setRange

      public void setRange(BFSRange range)
    • getRangeDisplay

      public String getRangeDisplay()
      Returns:
      the card display form of the range, using a keyword label derived from Specials where applicable
    • getRangeKeywordLabel

      @Nullable public String getRangeKeywordLabel()
      Returns:
      the keyword label to show for a keyword range - the artillery type (for example Long Tom) when an Artillery Special is present, else Arrow IV for an Arrow Special, else an em dash - or null for a numeric range
    • getSkill

      public int getSkill()
    • setSkill

      public void setSkill(int skill)
    • getVeteranSkill

      @Nullable public Integer getVeteranSkill()
    • setVeteranSkill

      public void setVeteranSkill(@Nullable Integer veteranSkill)
    • getSkillDisplay

      public String getSkillDisplay()
      Returns:
      the card display form of the skill, for example 6(5)
    • getDamage

      public BFSDamage getDamage()
    • setDamage

      public void setDamage(BFSDamage damage)
    • getDamageDisplay

      public String getDamageDisplay()
      Returns:
      the card display form of the damage, for example 5x4
    • getDestroyCheck

      public int getDestroyCheck()
      Returns:
      the current Destroy Check target (lowered by persistent damage; equal to getODestroyCheck() for an undamaged asset). This is the value shown on the card and used in play.
    • setDestroyCheck

      public void setDestroyCheck(int destroyCheck)
      Sets the current Destroy Check target only (persistent damage), leaving the as-constructed value unchanged — mirroring Entity.setArmor(int, megamek.common.HitData). Use setODestroyCheck(int) to set the as-constructed value.
      Parameters:
      destroyCheck - the current Destroy Check target
    • getODestroyCheck

      public int getODestroyCheck()
      Returns:
      the as-constructed Destroy Check target (the designer's value, stored in the .bfs).
    • setODestroyCheck

      public void setODestroyCheck(int oDestroyCheck)
      Sets the as-constructed Destroy Check target and resets the current value to it (an undamaged unit), mirroring Entity.initializeArmor(int, int). Used when defining/editing the asset. Persistent damage is applied afterward via setDestroyCheck(int).
      Parameters:
      oDestroyCheck - the as-constructed Destroy Check target
    • getThreshold

      public int getThreshold()
    • setThreshold

      public void setThreshold(int threshold)
    • getCost

      public int getCost()
    • setCost

      public void setCost(int cost)
    • getVeteranCost

      @Nullable public Integer getVeteranCost()
    • setVeteranCost

      public void setVeteranCost(@Nullable Integer veteranCost)
    • getCostDisplay

      public String getCostDisplay()
      Returns:
      the card display form of the cost in BSP, for example 23(27)
    • getBsp

      public int getBsp()
      Returns:
      the standard cost in Battlefield Support Points
    • getEffectiveBsp

      public int getEffectiveBsp()
      Returns:
      the BSP cost for the current crew level: the Veteran BSP when Veteran is selected, else the Regular BSP.
    • getVeteranBsp

      @Nullable public Integer getVeteranBsp()
      Returns:
      the Veteran cost in Battlefield Support Points, or null if there is no Veteran variant
    • getBv

      public int getBv()
      Returns:
      the standard cost in Battle Value (getBsp() times 20)
    • getVeteranBv

      @Nullable public Integer getVeteranBv()
      Returns:
      the Veteran cost in Battle Value, or null if there is no Veteran variant
    • hasVeteranProfile

      public boolean hasVeteranProfile()
      Returns:
      true if this asset defines a Veteran variant (a Veteran cost/skill), so Veteran can be selected.
    • isVeteranGunnery

      public static boolean isVeteranGunnery(int gunnery)
      Parameters:
      gunnery - a crew Gunnery skill
      Returns:
      true if the given Gunnery skill encodes a Veteran asset crew (see GUNNERY_VETERAN)
    • isVeteranCrew

      public boolean isVeteranCrew()
      Returns:
      true if this asset's current crew is set to the Veteran level and it has a Veteran variant. When there is no Veteran variant the asset is always treated as Regular regardless of the crew skill.
    • getCrewSkillLevel

      public SkillLevel getCrewSkillLevel()
      Returns:
      the crew grade as a SkillLevel: SkillLevel.VETERAN when the crew is Veteran, otherwise SkillLevel.REGULAR. Assets use only these two grades (there are no gunnery/piloting numbers in play); this is the label form used wherever a crew's skill would normally be shown.
    • setVeteranCrew

      public void setVeteranCrew(boolean veteran)
      Sets the crew's Regular/Veteran level, carried by the Gunnery skill. Requires a crew to be present.
      Parameters:
      veteran - true for Veteran, false for Regular
    • getEffectiveBv

      public int getEffectiveBv()
      Returns:
      the Battle Value for the current crew level: the Veteran BV when Veteran is selected, else the Regular BV.
    • doBattleValueCalculation

      protected int doBattleValueCalculation(boolean ignoreC3, boolean ignoreSkill, boolean ignoreTAG, CalculationReport calculationReport)
      Description copied from class: Entity
      Calculates and returns the Battle Value of this unit taking into account the parameters. This method should be overridden by subclasses of Entity to provide a unit type specific calculation of the Battle Value. A report of the calculation should be written to the given calculationReport.
      Overrides:
      doBattleValueCalculation in class Entity
      Parameters:
      ignoreC3 - When true, the BV contributions of any C3 computers are not added
      ignoreSkill - When true, the skill of the crew / pilot is not taken into account for BV
      ignoreTAG - When true, the force bonus for friendly guided munitions (TAG/homing) is not added
      calculationReport - A CalculationReport to write the BV calculation to
      Returns:
      The Battle Value of this unit calculated from its current state
    • getSpecials

      public List<BFSSpecial> getSpecials()
    • setSpecials

      public void setSpecials(List<BFSSpecial> specials)
    • addSpecial

      public void addSpecial(BFSSpecial special)
    • findSpecial

      public Optional<BFSSpecial> findSpecial(BFSSpecialType type)
      Parameters:
      type - the known Special type to look for
      Returns:
      the first Special on this asset whose code matches the given registry entry, or empty if none
    • hasSpecial

      public boolean hasSpecial(BFSSpecialType type)
      Parameters:
      type - the known Special type to look for
      Returns:
      true if this asset carries a Special whose code matches the given registry entry
    • getArtilleryType

      @Nullable public BFSArtilleryType getArtilleryType()
      Returns:
      the artillery type of this asset's Artillery Special (from its value, for example LT), or null if the asset has no Artillery Special or its type is unrecognized
    • getSpecialsDisplay

      public String getSpecialsDisplay()
      Returns:
      the card display form of all Specials, comma-separated, or an em dash when there are none
    • locations

      public int locations()
      Description copied from class: Entity
      Returns the number of locations in the entity
      Specified by:
      locations in class Entity
    • getLocationNames

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

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

      protected int[] getNoOfSlots()
      Specified by:
      getNoOfSlots in class Entity
    • autoSetInternal

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

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

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

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

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

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

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

      public int getWeaponArc(int weaponNumber)
      Description copied from class: Entity
      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)
      Description copied from class: Entity
      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
    • getMovementString

      public String getMovementString(EntityMovementType movementType)
      Description copied from class: Entity
      Returns the name of the type of movement used.
      Specified by:
      getMovementString in class Entity
    • getMovementAbbr

      public String getMovementAbbr(EntityMovementType movementType)
      Description copied from class: Entity
      Returns the abbreviation of the name of the type of movement used.
      Specified by:
      getMovementAbbr in class Entity
    • getRunMP

      public int getRunMP(MPCalculationSetting mpCalculationSetting)
      Overrides:
      getRunMP in class Entity
    • getMaxElevationChange

      public int getMaxElevationChange()
      Description copied from class: Entity
      The maximum elevation change the entity can cross
      Overrides:
      getMaxElevationChange in class Entity
    • addEntityBonuses

      public PilotingRollData addEntityBonuses(PilotingRollData roll)
      Description copied from class: Entity
      Add in any piloting skill mods
      Specified by:
      addEntityBonuses in class Entity
    • getEngineHits

      public int getEngineHits()
      Specified by:
      getEngineHits in class Entity
    • 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)
      Description copied from class: Entity
      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
    • isDestroyedByDamage

      public boolean isDestroyedByDamage()
      Returns:
      true if this asset has been destroyed by persistent damage - its current Destroy Check has fallen below DESTROYED_DESTROY_CHECK. An asset can no longer be damaged past destruction; a destroyed asset is generally recorded with a Destroy Check of 0. This is the only condition under which an asset is shown as Entity.DMG_CRIPPLED.
    • isDmgHeavy

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

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

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

      public double getCost(CalculationReport calcReport, boolean ignoreAmmo)
      Description copied from class: Entity
      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.
    • getGenericBattleValue

      public int getGenericBattleValue()
      Description copied from class: Entity
      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.

      The generic BV values are calculated by a statistical elasticity model based on all data from the MegaMek database.

      Specified by:
      getGenericBattleValue in class Entity
      Returns:
      The generic Battle value for this unit based on its tonnage and type
    • victoryReport

      public Vector<Report> victoryReport()
      Description copied from class: Entity
      Generates a vector containing reports on all useful information about this entity.
      Specified by:
      victoryReport in class Entity