Package megamek.common.verifier
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
Abstract parent class for testing and validating instantiations of
Entity subclasses.-
Field Summary
FieldsFields inherited from interface megamek.common.verifier.TestEntityOption
CEIL_TARGETING_COMPUTER_CRITS, FLOOR_TARGETING_COMPUTER_CRITS, ROUND_TARGETING_COMPUTER_CRITS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intcalcHeatNeutralHSRequirement(Entity entity) Computes heat sink requirement for heat-neutral units (vehicles, conventional fighters, protomeks).intcalcMiscCrits(MiscType mt, double size) doubleAccording to TM, unit weights are to be rounded up to the nearest half ton or kilo.doubleAccording 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.static doubleUsed to round values up based on the specified type.static doubleceilMaxHalf(double f, Ceil type) protected booleancorrectArmorOverAllocation(Entity entity, 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.booleancorrectEntity(StringBuffer buff) abstract booleancorrectEntity(StringBuffer buff, int ammoTechLvl) final booleancorrectWeight(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).booleancorrectWeight(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).static booleaneqRequiresLocation(Entity entity, EquipmentType eq) Determines whether a type of equipment requires a particular location on anEntity.static intequipmentCrewRequirements(Mounted<?> mounted) Additional crew requirements for vehicles and aerospace vessels for certain types of equipment.static doubledoublestatic intgetArmorPoints(Entity unit) Returns the number of armor points the given unit has.static intgetArmorPoints(Entity unit, double armorTons) Returns the number of armor points the given unit has with the given armor tonnage.static doubleCalculate the number of armor points per ton of armor for the given unit.abstract intabstract Entitystatic TestEntitygetEntityVerifier(Entity unit) intGets the game year to use for intro date validation.intgetLocationAbbr(int location) static intgetMaximumArmorPoints(Entity unit) doubledoubleabstract StringgetName()intstatic doublegetRawArmorPoints(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).static doublegetRawWeightArmor(ArmorType armor, int totalOArmor) static intgetSIBonusArmorPoints(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).static intgetSystemWideLocation(Entity entity) Determines where to place equipment that does not require a specific location.intintdoubledoubledoubledoublestatic doublegetWeightArmor(ArmorType armor, int totalOArmor, Ceil roundWeight) doubleabstract doubledoubleabstract doubleabstract doubledoubleabstract doubledoubledoubleabstract booleanbooleanbooleanCheck if the unit has combinations of equipment which are not allowed in the construction rules.booleanDeprecated, for removal: This API element is subject to removal in a future version.booleanhasIllegalTechLevels(StringBuffer buff, int ammoTechLvl) booleanCompares intro dates of all components to the unit intro year (or game year if available).protected intComputes heat sink requirement for heat-neutral units (vehicles, conventional fighters, protomeks).booleanignoreFailedEquip(String name) protected booleanincludeMiscEquip(MiscType misc) Gives subclasses a chance to exclude certain misc equipment if it is accounted for in a different category.abstract booleanabstract booleanisAero()booleanisClan()booleanabstract booleanisMek()abstract booleanabstract booleanabstract booleanisTank()static booleanisValidLocation(Entity entity, EquipmentType eq, int location, StringBuffer buffer) final booleanDeprecated, for removal: This API element is subject to removal in a future version.legalArmorsFor(long etype, boolean industrial, boolean primitive, EntityMovementMode movementMode, ITechManager techManager) Filters all armor according to given tech constraintsprintAmmo(StringBuffer buff) printAmmo(StringBuffer buff, int posLoc, int posWeight) printArmorLocation(int loc) abstract StringBufferprintMiscEquip(StringBuffer buff) printMiscEquip(StringBuffer buff, int posLoc, int posWeight) printWeapon(StringBuffer buff) printWeapon(StringBuffer buff, int posLoc, int posWeight) abstract Stringabstract Stringstatic doublevoidsetGameYear(int gameYear) Sets the game year to use for intro date validation.static doublesetPrecision(double value, int precision) Deprecated, for removal: This API element is subject to removal in a future version.booleanbooleanbooleanbooleanbooleanbooleanbooleanskip()intstatic booleanusesKgStandard(Entity entity) static List<EquipmentType> validJumpJets(long entityType, boolean industrial)
-
Field Details
-
engine
-
structure
-
fileString
-
-
Constructor Details
-
TestEntity
-
-
Method Details
-
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
-
printWeightControls
-
correctEntity
-
correctEntity
-
printEntity
-
getName
-
getEntityVerifier
- 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
-
getWeightCeilingEngine
- Specified by:
getWeightCeilingEnginein interfaceTestEntityOption
-
getWeightCeilingStructure
- Specified by:
getWeightCeilingStructurein interfaceTestEntityOption
-
getWeightCeilingArmor
- Specified by:
getWeightCeilingArmorin interfaceTestEntityOption
-
getWeightCeilingControls
- Specified by:
getWeightCeilingControlsin interfaceTestEntityOption
-
getWeightCeilingWeapons
- Specified by:
getWeightCeilingWeaponsin interfaceTestEntityOption
-
getWeightCeilingTargComp
- Specified by:
getWeightCeilingTargCompin interfaceTestEntityOption
-
getWeightCeilingGyro
- Specified by:
getWeightCeilingGyroin interfaceTestEntityOption
-
getWeightCeilingTurret
- Specified by:
getWeightCeilingTurretin interfaceTestEntityOption
-
getWeightCeilingLifting
- Specified by:
getWeightCeilingLiftingin interfaceTestEntityOption
-
getWeightCeilingPowerAmp
- Specified by:
getWeightCeilingPowerAmpin interfaceTestEntityOption
-
getMaxOverweight
public double getMaxOverweight()- Specified by:
getMaxOverweightin interfaceTestEntityOption
-
showOverweightedEntity
public boolean showOverweightedEntity()- Specified by:
showOverweightedEntityin interfaceTestEntityOption
-
getMinUnderweight
public double getMinUnderweight()- Specified by:
getMinUnderweightin interfaceTestEntityOption
-
showUnderweightEntity
public boolean showUnderweightEntity()- Specified by:
showUnderweightEntityin interfaceTestEntityOption
-
showCorrectArmor
public boolean showCorrectArmor()- Specified by:
showCorrectArmorin interfaceTestEntityOption
-
showCorrectCritical
public boolean showCorrectCritical()- Specified by:
showCorrectCriticalin interfaceTestEntityOption
-
showFailedEquip
public boolean showFailedEquip()- Specified by:
showFailedEquipin interfaceTestEntityOption
-
ignoreFailedEquip
- Specified by:
ignoreFailedEquipin interfaceTestEntityOption
-
showIncorrectIntroYear
public boolean showIncorrectIntroYear()- Specified by:
showIncorrectIntroYearin interfaceTestEntityOption
-
getIntroYearMargin
public int getIntroYearMargin()- Specified by:
getIntroYearMarginin interfaceTestEntityOption
-
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:
skipin interfaceTestEntityOption
-
getTargetingComputerCrits
public int getTargetingComputerCrits()- Specified by:
getTargetingComputerCritsin interfaceTestEntityOption
-
getPrintSize
public int getPrintSize()- Specified by:
getPrintSizein interfaceTestEntityOption
-
ceil
Used to round values up based on the specified type.- Parameters:
f- Value to roundtype- Specifies the number of decimals to round to, see TestEntity.CEIL_TON, etc.- Returns:
- Rounded value
-
ceilMaxHalf
-
floor
-
round
-
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 valueprecision- 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 maskindustrial- For meks; industrial meks can only use certain armor types unless allowing experimental rulesprimitive- Whether the unit is primitive/RetroTechmovementMode- For vehicles; hardened armor is illegal for some movement modestechManager- The constraints used to filter the armor types- Returns:
- A list of all armors that meet the tech constraints
-
validJumpJets
-
equipmentCrewRequirements
Additional crew requirements for vehicles and aerospace vessels for certain types of equipment. -
eqRequiresLocation
Determines whether a type of equipment requires a particular location on anEntity. 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 oneq- The equipment to place on the Entity- Returns:
- Whether the equipment requires a location
- See Also:
-
getSystemWideLocation
Determines where to place equipment that does not require a specific location. What this means varies byEntitytype.- 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
-
printShortMovement
-
printWeightHeatSinks
-
printWeightEngine
-
getWeightEngine
public double getWeightEngine() -
printWeightStructure
-
getWeightStructure
public double getWeightStructure() -
printWeightArmor
-
getWeightArmor
public double getWeightArmor() -
getRawWeightArmor
-
getWeightArmor
-
getWeightAllocatedArmor
public double getWeightAllocatedArmor() -
includeMiscEquip
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
-
printMiscEquip
-
printMiscEquip
-
getWeightWeapon
public double getWeightWeapon() -
printWeapon
-
printWeapon
-
printWeapon
-
getWeightAmmo
public double getWeightAmmo() -
getWeightPowerAmp
public abstract double getWeightPowerAmp() -
printAmmo
-
printAmmo
-
printAmmo
-
printLocations
-
calcMiscCrits
-
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
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
-
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
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 toignoreOverweight- When true, ignore overweightignoreUnderweight- When true, ignore underweight- Returns:
- true if there are no problems with the unit's assumed and calculated weight values
-
correctArmorOverAllocation
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 testbuff- A StringBuffer to write error messages to- Returns:
- False when there is surplus armor allocated and the unit is invalid, true otherwise
-
getRawArmorPoints
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
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 unitarmorTons- the armor tonnage- Returns:
- the armor point total of the unit, including SI bonus armor
-
getArmorPoints
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
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
-
getSIBonusArmorPoints
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, for removal: This API element is subject to removal in a future version. -
hasIllegalTechLevels
-
hasIncorrectIntroYear
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:- If
setGameYear(int)was called with a value > 0, use that year - 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
- 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.
- If
-
hasFailedEquipment
-
hasIllegalEquipmentCombinations
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 entityeq- The equipmentlocation- A location index on the Entitybuffer- 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
-
getWeightCarryingSpace
public double getWeightCarryingSpace() -
printWeightCarryingSpace
-
printArmorLocation
-
printArmorPlacement
-
printSource
-
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
-
totalCritSlotCount
public int totalCritSlotCount()
-