Class TestEntity

java.lang.Object
megamek.common.verifier.TestEntity
All Implemented Interfaces:
TestEntityOption
Direct Known Subclasses:
TestAero, TestBattleArmor, TestBuilding, TestHandheldWeapon, TestInfantry, TestMek, TestProtoMek, TestSupportVehicle, TestTank

public abstract class TestEntity extends Object implements TestEntityOption
Abstract parent class for testing and validating instantiations of Entity subclasses.
  • Field Details

    • engine

      protected Engine engine
    • structure

      protected Structure structure
    • fileString

      public String fileString
  • Constructor Details

  • Method Details

    • getEntity

      public abstract Entity getEntity()
    • isTank

      public abstract boolean isTank()
    • isMek

      public abstract boolean isMek()
    • isAero

      public abstract boolean isAero()
    • isSmallCraft

      public abstract boolean isSmallCraft()
    • isAdvancedAerospace

      public abstract boolean isAdvancedAerospace()
    • isProtoMek

      public abstract boolean isProtoMek()
    • getWeightControls

      public abstract double getWeightControls()
    • getWeightMisc

      public abstract double getWeightMisc()
    • getWeightHeatSinks

      public abstract double getWeightHeatSinks()
    • hasDoubleHeatSinks

      public abstract boolean hasDoubleHeatSinks()
    • getCountHeatSinks

      public abstract int getCountHeatSinks()
    • printWeightMisc

      public abstract String printWeightMisc()
    • printWeightControls

      public abstract String printWeightControls()
    • correctEntity

      public boolean correctEntity(StringBuffer buff)
    • correctEntity

      public abstract boolean correctEntity(StringBuffer buff, int ammoTechLvl)
    • printEntity

      public abstract StringBuffer printEntity()
    • getName

      public abstract String getName()
    • getEntityVerifier

      public static TestEntity getEntityVerifier(Entity unit)
      Parameters:
      unit - The entity the supplied entity
      Returns:
      a TestEntity instance for the supplied Entity.
    • isClan

      public boolean isClan()
    • isClanArmor

      public boolean isClanArmor()
    • getWeight

      public double getWeight()
    • getTotalOArmor

      public int getTotalOArmor()
    • getLocationAbbr

      public String getLocationAbbr(int location)
    • getWeightCeilingEngine

      public Ceil getWeightCeilingEngine()
      Specified by:
      getWeightCeilingEngine in interface TestEntityOption
    • getWeightCeilingStructure

      public Ceil getWeightCeilingStructure()
      Specified by:
      getWeightCeilingStructure in interface TestEntityOption
    • getWeightCeilingArmor

      public Ceil getWeightCeilingArmor()
      Specified by:
      getWeightCeilingArmor in interface TestEntityOption
    • getWeightCeilingControls

      public Ceil getWeightCeilingControls()
      Specified by:
      getWeightCeilingControls in interface TestEntityOption
    • getWeightCeilingWeapons

      public Ceil getWeightCeilingWeapons()
      Specified by:
      getWeightCeilingWeapons in interface TestEntityOption
    • getWeightCeilingTargComp

      public Ceil getWeightCeilingTargComp()
      Specified by:
      getWeightCeilingTargComp in interface TestEntityOption
    • getWeightCeilingGyro

      public Ceil getWeightCeilingGyro()
      Specified by:
      getWeightCeilingGyro in interface TestEntityOption
    • getWeightCeilingTurret

      public Ceil getWeightCeilingTurret()
      Specified by:
      getWeightCeilingTurret in interface TestEntityOption
    • getWeightCeilingLifting

      public Ceil getWeightCeilingLifting()
      Specified by:
      getWeightCeilingLifting in interface TestEntityOption
    • getWeightCeilingPowerAmp

      public Ceil getWeightCeilingPowerAmp()
      Specified by:
      getWeightCeilingPowerAmp in interface TestEntityOption
    • getMaxOverweight

      public double getMaxOverweight()
      Specified by:
      getMaxOverweight in interface TestEntityOption
    • showOverweightedEntity

      public boolean showOverweightedEntity()
      Specified by:
      showOverweightedEntity in interface TestEntityOption
    • getMinUnderweight

      public double getMinUnderweight()
      Specified by:
      getMinUnderweight in interface TestEntityOption
    • showUnderweightEntity

      public boolean showUnderweightEntity()
      Specified by:
      showUnderweightEntity in interface TestEntityOption
    • showCorrectArmor

      public boolean showCorrectArmor()
      Specified by:
      showCorrectArmor in interface TestEntityOption
    • showCorrectCritical

      public boolean showCorrectCritical()
      Specified by:
      showCorrectCritical in interface TestEntityOption
    • showFailedEquip

      public boolean showFailedEquip()
      Specified by:
      showFailedEquip in interface TestEntityOption
    • ignoreFailedEquip

      public boolean ignoreFailedEquip(String name)
      Specified by:
      ignoreFailedEquip in interface TestEntityOption
    • showIncorrectIntroYear

      public boolean showIncorrectIntroYear()
      Specified by:
      showIncorrectIntroYear in interface TestEntityOption
    • getIntroYearMargin

      public int getIntroYearMargin()
      Specified by:
      getIntroYearMargin in interface TestEntityOption
    • getGameYear

      public int getGameYear()
      Gets the game year to use for intro date validation. When > 0, equipment intro dates are compared against this year instead of the entity's intro year.
      Returns:
      The game year, or -1 if not set (use entity year)
    • setGameYear

      public void setGameYear(int gameYear)
      Sets the game year to use for intro date validation. When set to a value > 0, equipment intro dates will be compared against this year instead of the entity's intro year. This supports scenarios where equipment availability is determined by a campaign's current year rather than the unit's original intro year.
      Parameters:
      gameYear - The game year to use, or -1 to use entity year
    • skip

      public boolean skip()
      Specified by:
      skip in interface TestEntityOption
    • getTargetingComputerCrits

      public int getTargetingComputerCrits()
      Specified by:
      getTargetingComputerCrits in interface TestEntityOption
    • getPrintSize

      public int getPrintSize()
      Specified by:
      getPrintSize in interface TestEntityOption
    • ceil

      public static double ceil(double f, @Nonnull Ceil type)
      Used to round values up based on the specified type.
      Parameters:
      f - Value to round
      type - Specifies the number of decimals to round to, see TestEntity.CEIL_TON, etc.
      Returns:
      Rounded value
    • ceilMaxHalf

      public static double ceilMaxHalf(double f, @Nonnull Ceil type)
    • floor

      public static double floor(double f, @Nonnull Ceil type)
    • round

      public static double round(double f, @Nonnull Ceil type)
    • setPrecision

      @Deprecated(since="0.51.0", forRemoval=true) public static double setPrecision(double value, int precision)
      Deprecated, for removal: This API element is subject to removal in a future version.
      Allows a value to be truncated to an arbitrary number of decimal places.
      Parameters:
      value - The input value
      precision - The number of decimals to truncate at
      Returns:
      The input value truncated to the number of decimal places supplied
    • legalArmorsFor

      public static List<ArmorType> legalArmorsFor(long etype, boolean industrial, boolean primitive, EntityMovementMode movementMode, ITechManager techManager)
      Filters all armor according to given tech constraints
      Parameters:
      etype - The entity type bit mask
      industrial - For meks; industrial meks can only use certain armor types unless allowing experimental rules
      primitive - Whether the unit is primitive/RetroTech
      movementMode - For vehicles; hardened armor is illegal for some movement modes
      techManager - The constraints used to filter the armor types
      Returns:
      A list of all armors that meet the tech constraints
    • validJumpJets

      public static List<EquipmentType> validJumpJets(long entityType, boolean industrial)
    • equipmentCrewRequirements

      public static int equipmentCrewRequirements(Mounted<?> mounted)
      Additional crew requirements for vehicles and aerospace vessels for certain types of equipment.
    • eqRequiresLocation

      public static boolean eqRequiresLocation(Entity entity, EquipmentType eq)
      Determines whether a type of equipment requires a particular location on an Entity. What this means depends on the type of unit, but typically it does not take up a slot or is not assigned a firing arc.
      Parameters:
      entity - The Entity the equipment is to be placed on
      eq - The equipment to place on the Entity
      Returns:
      Whether the equipment requires a location
      See Also:
    • getSystemWideLocation

      public static int getSystemWideLocation(Entity entity)
      Determines where to place equipment that does not require a specific location. What this means varies by Entity type.
      Parameters:
      entity - The Entity to place the equipment in
      Returns:
      The location to place equipment that is not required to be assigned a location, defaulting to Entity.LOC_NONE for unit types that do not have such a location.
    • getMPBoosters

      public MPBoosters getMPBoosters()
    • printShortMovement

      public String printShortMovement()
    • printWeightHeatSinks

      public String printWeightHeatSinks()
    • printWeightEngine

      public String printWeightEngine()
    • getWeightEngine

      public double getWeightEngine()
    • printWeightStructure

      public String printWeightStructure()
    • getWeightStructure

      public double getWeightStructure()
    • printWeightArmor

      public String printWeightArmor()
    • getWeightArmor

      public double getWeightArmor()
    • getRawWeightArmor

      public static double getRawWeightArmor(ArmorType armor, int totalOArmor)
    • getWeightArmor

      public static double getWeightArmor(ArmorType armor, int totalOArmor, Ceil roundWeight)
    • getWeightAllocatedArmor

      public double getWeightAllocatedArmor()
    • includeMiscEquip

      protected boolean includeMiscEquip(MiscType misc)
      Gives subclasses a chance to exclude certain misc equipment if it is accounted for in a different category.
      Parameters:
      misc - The misc equipment type
      Returns:
      Whether to include the equipment in the misc equipment category
      See Also:
    • getWeightMiscEquip

      public double getWeightMiscEquip()
    • printMiscEquip

      public StringBuffer printMiscEquip()
    • printMiscEquip

      public StringBuffer printMiscEquip(StringBuffer buff)
    • printMiscEquip

      public StringBuffer printMiscEquip(StringBuffer buff, int posLoc, int posWeight)
    • getWeightWeapon

      public double getWeightWeapon()
    • printWeapon

      public StringBuffer printWeapon()
    • printWeapon

      public StringBuffer printWeapon(StringBuffer buff)
    • printWeapon

      public StringBuffer printWeapon(StringBuffer buff, int posLoc, int posWeight)
    • getWeightAmmo

      public double getWeightAmmo()
    • getWeightPowerAmp

      public abstract double getWeightPowerAmp()
    • printAmmo

      public StringBuffer printAmmo()
    • printAmmo

      public StringBuffer printAmmo(StringBuffer buff)
    • printAmmo

      public StringBuffer printAmmo(StringBuffer buff, int posLoc, int posWeight)
    • printLocations

      public String printLocations()
    • calcMiscCrits

      public int calcMiscCrits(MiscType mt, double size)
    • heatNeutralHSRequirement

      protected int heatNeutralHSRequirement()
      Computes heat sink requirement for heat-neutral units (vehicles, conventional fighters, protomeks). This is a total of energy weapons that don't use ammo and some other miscellaneous equipment.
      Returns:
      The number of heat sinks required in construction
    • calcHeatNeutralHSRequirement

      public static int calcHeatNeutralHSRequirement(Entity entity)
      Computes heat sink requirement for heat-neutral units (vehicles, conventional fighters, protomeks). This is a total of energy weapons that don't use ammo and some other miscellaneous equipment.
      Returns:
      The number of heat sinks required in construction
    • calculateWeight

      public double calculateWeight()
      According to TM, unit weights are to be rounded up to the nearest half ton or kilo. This method returns the rounded weight.
      Returns:
      The weight of the unit, rounded up according to TM, p.22.
    • calculateWeightExact

      public double calculateWeightExact()
      According to TM p.22, unit weights are to be rounded up to the nearest half ton or kilo, but in MML for construction at least we should be able to show the exact weight. This method returns the unrounded weight.
      Returns:
      The unrounded weight of the unit.
    • printWeightCalculation

      public String printWeightCalculation()
    • isWeightCorrect

      @Deprecated(since="0.51.0", forRemoval=true) public final boolean isWeightCorrect()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Tests the calculated weight of the unit (the sum of the weights of all its components) and the assumed weight (the fixed tonnage it is constructed with). Returns false if there are errors with the values (e.g. overweight, underweight if the unit type does not allow it, mek weight must be a multiple of 5t).
      Returns:
      true if there are no problems with the unit's assumed and calculated weight values
    • correctWeight

      public final boolean correctWeight(StringBuffer buff)
      Tests the calculated weight of the unit (the sum of the weights of all its components) and the assumed weight (the fixed tonnage it is constructed with). Returns false if there are errors with the values (e.g. overweight, underweight if the unit type does not allow it, mek weight must be a multiple of 5t). Any error reports are appended to the given StringBuffer.
      Returns:
      true if there are no problems with the unit's assumed and calculated weight values
    • correctWeight

      public boolean correctWeight(StringBuffer buff, boolean ignoreOverweight, boolean ignoreUnderweight)
      Tests the calculated weight of the unit (the sum of the weights of all its components) and the assumed weight (the fixed tonnage it is constructed with). Returns false if there are errors with the values (e.g. overweight, underweight if the unit type does not allow it, mek weight must be a multiple of 5t).
      Parameters:
      buff - The StringBuffer to append error messages to
      ignoreOverweight - When true, ignore overweight
      ignoreUnderweight - When true, ignore underweight
      Returns:
      true if there are no problems with the unit's assumed and calculated weight values
    • correctArmorOverAllocation

      protected boolean correctArmorOverAllocation(Entity entity, @Nullable StringBuffer buff)
      For units without patchwork armor, tests if more armor is allocated on the unit's locations than it may have according to its armor tonnage. If it is, returns false and appends an error message to the given error buffer. Otherwise or if the unit has patchwork armor, returns true.
      Parameters:
      entity - The unit to test
      buff - A StringBuffer to write error messages to
      Returns:
      False when there is surplus armor allocated and the unit is invalid, true otherwise
    • getRawArmorPoints

      public static double getRawArmorPoints(Entity unit, double armorTons)
      Returns the total number of armor points available to the unit for a given tonnage of armor -- NOT including the downgrade of primitive aerospace armor which cannot be factored into this number correctly (see IO:AE p.125). This does not round down the calculation or take into account any maximum number of armor points or tonnage allowed to the unit. It also does not include any free armor points due to SI on aerospace units.

      NOTE: only use for non-patchwork armor

      Returns:
      the number of armor points available for the armor tonnage
    • getArmorPoints

      public static int getArmorPoints(Entity unit, double armorTons)
      Returns the number of armor points the given unit has with the given armor tonnage. This includes bonus armor points for SI on DS/SC and capital craft.

      NOTE: only use for non-patchwork armor

      Parameters:
      unit - the unit
      armorTons - the armor tonnage
      Returns:
      the armor point total of the unit, including SI bonus armor
    • getArmorPoints

      public static int getArmorPoints(Entity unit)
      Returns the number of armor points the given unit has. This includes bonus armor points for SI on DS/SC and capital craft.

      NOTE: only use for non-patchwork armor

      Parameters:
      unit - the unit
      Returns:
      the armor point total of the unit, including SI bonus armor
    • getArmorPointsPerTon

      public static double getArmorPointsPerTon(Entity en)
      Calculate the number of armor points per ton of armor for the given unit.
      Parameters:
      en - The unit
      Returns:
      The number of armor points per ton
    • getMaximumArmorPoints

      public static int getMaximumArmorPoints(Entity unit)
    • getSIBonusArmorPoints

      public static int getSIBonusArmorPoints(Entity entity)
      Returns the number of free additional armor points provided for aerospace vessels based on their structural integrity (for primitive capital craft, *without* the 0.66 primitive adjustment factor). For units other than SC/DS and capital craft, this is 0. See TM p.191, SO:AA p.140, IO:AE p.119-125.
      Parameters:
      entity - The unit to compute bonus armor for
      Returns:
      The total number of extra armor points received for SI
    • hasIllegalTechLevels

      @Deprecated(since="0.51.0", forRemoval=true) public boolean hasIllegalTechLevels(StringBuffer buff)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • hasIllegalTechLevels

      public boolean hasIllegalTechLevels(StringBuffer buff, int ammoTechLvl)
    • hasIncorrectIntroYear

      public boolean hasIncorrectIntroYear(StringBuffer buff)
      Compares intro dates of all components to the unit intro year (or game year if available). If the unit has an explicit original build year, that year is also accepted for components retained from the original build. The current/refit year used for comparison is determined in order of priority:
      1. If setGameYear(int) was called with a value > 0, use that year
      2. Otherwise, use Entity.getTechLevelYear() which returns the game's ALLOWED_YEAR if the entity is part of a game, or the entity's intro year if not
      This supports both MegaMek gameplay (using game options) and MegaMekLab (using config settings).
      Parameters:
      buff - Descriptions of problems will be added to the buffer.
      Returns:
      Whether the unit has an intro year equal to or later than all the components.
    • hasFailedEquipment

      public boolean hasFailedEquipment(StringBuffer buff)
    • hasIllegalEquipmentCombinations

      public boolean hasIllegalEquipmentCombinations(StringBuffer buff)
      Check if the unit has combinations of equipment which are not allowed in the construction rules.
      Parameters:
      buff - diagnostics are appended to this
      Returns:
      true if the entity is illegal
    • isValidLocation

      public static boolean isValidLocation(Entity entity, EquipmentType eq, int location, @Nullable StringBuffer buffer)
      Parameters:
      entity - The entity
      eq - The equipment
      location - A location index on the Entity
      buffer - If non-null and the location is invalid, will be appended with an explanation
      Returns:
      Whether the equipment can be mounted in the location on the Entity
    • printFailedEquipment

      public StringBuffer printFailedEquipment(StringBuffer buff)
    • getWeightCarryingSpace

      public double getWeightCarryingSpace()
    • printWeightCarryingSpace

      public String printWeightCarryingSpace()
    • printArmorLocation

      public String printArmorLocation(int loc)
    • printArmorPlacement

      public String printArmorPlacement()
    • printSource

      public String printSource()
    • printTechLevel

      public String printTechLevel()
    • getArmoredComponentWeight

      public double getArmoredComponentWeight()
      Returns:
      The total additional weight due to critical slot armoring. Does not include the weight of the equipment itself.
    • usesKgStandard

      public static boolean usesKgStandard(Entity entity)
    • totalCritSlotCount

      public int totalCritSlotCount()