Package megameklab.util
Class UnitUtil
java.lang.Object
megameklab.util.UnitUtil
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddMounted(megamek.common.units.Entity unit, megamek.common.equipment.Mounted<?> mounted, int loc, boolean rearMounted) Adds the given Mounted equipment to the given unit in the given location, applying rearMounted, by forwarding to Entity.addEquipment() -- see that method for details.static booleancanPodMount(megamek.common.units.Entity unit, megamek.common.equipment.Mounted<?> eq) Checks whether the equipment is eligible for pod mounting in an omni unit, either because the equipment itself can never be pod-mounted (such as armor, structure, or myomer enhancements), or the number of fixed heat sinks have not been assigned locations.static booleancanUseAmmo(megamek.common.units.Entity unit, megamek.common.equipment.AmmoType ammoType, boolean includeOneShot) Checks whether the unit has a weapon that uses the ammo type and the munition is legal for the type of unit.static voidchangeMountStatus(megamek.common.units.Entity unit, megamek.common.equipment.Mounted<?> eq, int location, int secondaryLocation, boolean rear) Updates the location for a Mounted equipment.static voidcheckArmor(megamek.common.units.Entity unit) static booleancheckEquipmentByTechLevel(megamek.common.units.Entity unit, megamek.common.interfaces.ITechManager techManager) Checks for any equipment added on the equipment tab and removes any that is no longer legal for the current year/tech base/tech levelstatic megamek.common.units.EntitycloneUnit(megamek.common.units.Entity entity) Clone an entity.static voidcompactCriticalSlots(megamek.common.units.Entity unit) static voidcompactCriticalSlots(megamek.common.units.Entity unit, int loc) Removes empty crit slots between equipment from the given location on the given unit, if there are any.static voidcopyLocationEquipment(megamek.common.units.Entity entity, int fromLoc, int toLoc) Makes the equipment mounted in one location identical to that in another location.static voidcopyLocationEquipment(megamek.common.units.Entity entity, int fromLoc, int toLoc, boolean includeForward, boolean includeRear) Makes the equipment mounted in one location identical to that in another location.static megamek.common.equipment.Mounted<?> createTCMounts(megamek.common.units.Entity unit, megamek.common.equipment.EquipmentType tc) Creates TC Mount.static FontderiveFont(boolean boldFont, float pointSize) static FontderiveFont(float pointSize) static megamek.common.equipment.Mounted<?> findUnallocatedAmmo(megamek.common.units.Entity unit, megamek.common.equipment.EquipmentType at) Find unallocated ammo of the same type.static doublegetArmorPointsPerTon(megamek.common.units.Entity en) Calculate the number of armor points per ton of armor for the given unit.static intgetCriticalFreeHeatSinks(megamek.common.units.Entity unit, boolean compact) Return the number of critical-space free heat sinks that the given entity can have.static StringgetCritName(megamek.common.units.Entity unit, megamek.common.equipment.EquipmentType eq) static intgetCritsUsed(megamek.common.equipment.Mounted<?> mount) Returns the number of critical slots used by EquipmentType for each placement.static megamek.client.ClientReturns a Client object that is used for internal calculations of the units.static longgetEditorTypeForEntity(megamek.common.units.Entity newUnit) static megamek.common.verifier.TestEntitygetEntityVerifier(megamek.common.units.Entity unit) static StringgetHeatSinkType(String type, boolean clan) static intgetHighestContinuousNumberOfCrits(megamek.common.units.Entity unit, int location) static int[]getHighestContinuousNumberOfCritsArray(megamek.common.units.Mek unit) static StringgetJumpJetType(int type) static IntegergetMaxArmor(megamek.common.units.Entity entity, int location) Determine the maximum number of armor points that can be mounted in a location.static intgetMaximumArmorPoints(megamek.common.units.Entity unit) static intgetMaximumArmorPoints(megamek.common.units.Entity unit, int loc) static doublegetMaximumArmorTonnage(megamek.common.units.Entity unit) static StringgetPrintName(megamek.common.units.Entity e) static intgetTotalHeatGeneration(megamek.common.units.Entity entity) Returns the total heat generation of the entitystatic intgetTotalHeatGeneration(megamek.common.units.Entity entity, boolean countOneShots) Returns the total equipment (not movement) heat generation of the entitystatic doublegetUnallocatedAmmoTonnage(megamek.common.units.Entity unit) static booleanhasAmmo(megamek.common.units.Entity unit, int location) static booleanhasSwitchableAmmo(megamek.common.equipment.WeaponType weapon) static booleanhasTargComp(megamek.common.units.Entity unit) static booleanisAMS(megamek.common.equipment.WeaponType weapon) static booleanisArmor(megamek.common.equipment.EquipmentType eq) tells if the EquipmentType is a type of armorstatic booleanisArmorOrStructure(megamek.common.equipment.EquipmentType eq) static booleanisDamaged(megamek.common.units.Entity entity, boolean includeCrew) static booleanisEntityEquipment(megamek.common.equipment.EquipmentType eq, megamek.common.units.Entity en) static booleanisFixedLocationSpreadEquipment(megamek.common.equipment.EquipmentType equipmentType) Returns true for MiscTypes that are fixed to a single location or to multiple locations; in other words, those Miscs for which there is no location choice when placing them on a unit.static booleanisHeatSink(megamek.common.equipment.EquipmentType eq) Checks if EquipmentType is a heat sinkstatic booleanisHeatSink(megamek.common.equipment.EquipmentType eq, boolean ignorePrototype) static booleanisHeatSink(megamek.common.equipment.Mounted<?> eq) checks if Mounted is a heat sinkstatic booleanisJumpJet(megamek.common.equipment.EquipmentType eq) Checks to see if something is a Jump Jetstatic booleanisJumpJet(megamek.common.equipment.Mounted<?> m) static booleanisLastCrit(megamek.common.units.Entity unit, megamek.common.CriticalSlot cs, int slot, int location) static booleanisLegal(megamek.common.units.Entity unit, megamek.common.interfaces.ITechnology tech) Checks to see if unit can use the tech levelstatic booleanisMASC(megamek.common.equipment.EquipmentType eq) tells if EquipmentType is MASCstatic booleanisMineDispenser(megamek.common.equipment.EquipmentType eq) static booleanisPhysicalWeapon(megamek.common.equipment.EquipmentType eq) Checks if EquipmentType is a Mek Physical weapon.static booleanisPreviousCriticalSlotEmpty(megamek.common.units.Entity unit, int slot, int location) Determines if the previous critical slot is empty.static booleanisRemoteSensorDispenser(megamek.common.equipment.EquipmentType eq) static booleanisStructure(megamek.common.equipment.EquipmentType eq) tells if the EquipmentType is a type of armorstatic booleanisSupportVehicleEquipment(megamek.common.equipment.EquipmentType type, megamek.common.units.Entity unit) Returns true if the given Equipment is available as equipment to the given Support Vehicle.static booleanisTSM(megamek.common.equipment.EquipmentType eq) tells if EquipmentType is TSM or TargetCompstatic booleanisUnitWeapon(megamek.common.equipment.EquipmentType eq, megamek.common.units.Entity unit) static booleanisValidLocation(megamek.common.units.Entity unit, megamek.common.equipment.EquipmentType eq, int location) Returns true when the given equipment can be placed in the given location on the given unit.static booleanisWeaponEnhancement(megamek.common.equipment.EquipmentType type) Checks whether equipment can be linked to a weapon to enhance it (e.g.static voidstatic voidremoveAllCriticalSlots(megamek.common.units.Entity unit) Removes all critical slots of the given unit, unallocating most equipment (i.e., placing it intoEntity.LOC_NONE.static voidremoveAllMiscMounted(megamek.common.units.Entity unit, megamek.common.equipment.EquipmentFlag flag) static voidremoveAllMounted(megamek.common.units.Entity unit, megamek.common.equipment.EquipmentType et) static voidremoveCriticalSlots(megamek.common.units.Entity unit, megamek.common.equipment.Mounted<?> mounted) Sets the corresponding critical slots to null for the Mounted object.static voidremoveCriticalSlots(megamek.common.units.Entity unit, megamek.common.equipment.Mounted<?> eq, int loc) Sets the corresponding critical slots to null for the Mounted object in the given location.static voidremoveHiddenAmmo(megamek.common.equipment.Mounted<?> mounted) If the given Mounted is a one-shot launcher or infantry weapon, this method removes the hidden ammo linked to it, if any.static voidremoveISorArmorCrits(megamek.common.units.Entity unit, boolean internalStructure) remove all CriticalSlots on the passed unit that are internal structure or armorstatic voidremoveISorArmorMounts(megamek.common.units.Entity unit, boolean internalStructure) remove all Mounted on the passed unit that are internal structure or armorstatic voidremoveMounted(megamek.common.units.Entity unit, megamek.common.equipment.Mounted<?> mount) Removes a piece of equipment from the Entitystatic voidremoveOneShotAmmo(megamek.common.units.Entity unit) static voidremoveTC(megamek.common.units.Entity unit) static voidresetArmor(megamek.common.units.Entity unit, int loc) Remove all mounts for the current armor type from a single location on the passed unit and sets the armor type in that location to standard.static voidresetBaseChassis(megamek.common.units.Entity unit) Removes all pod-mounted equipment from an omni unitstatic voidresetUnit(megamek.common.units.Entity entity) Reset the damage to the unit to its original state.static voidresizeMount(megamek.common.equipment.Mounted<?> mount, double newSize) static StringsaveUnitToString(megamek.common.units.Entity entity, boolean includeGeneratorHeader) Encodes the unit to a string.static voidsetManualBV(int manualBV, megamek.common.units.Entity entity) Updates the manual BV value of the given entity.static voidsetVariableSizeMiscTypeMinimumSize(megamek.common.equipment.Mounted<?> mounted) For MiscTypes of variable size such as Ladders this sets the size to the minimum size which is equal to the step size (20m for Ladders, 0.5t for Cargo space and the like).static voidshowValidation(megamek.common.units.Entity entity, JFrame frame) static voidupdateCritsArmoredStatus(megamek.common.units.Entity unit, megamek.common.CriticalSlot cs, int location) static voidupdateCritsArmoredStatus(megamek.common.units.Entity unit, megamek.common.equipment.Mounted<?> mount) Sets the armored component flag on all critical slots occupied by an equipment mount to be the same as the flag on the mount.static voidupdateCritsArmoredStatus(megamek.common.units.Entity unit, megamek.common.equipment.Mounted<?> mount, int location) Finds all the critical slots in the location containing the mount and sets or clears the armored component flag in accordance with the flag on the mount.static voidupdateLoadedUnit(megamek.common.units.Entity unit) static megamek.common.equipment.Mounted<?> updateTC(megamek.common.units.Entity unit, megamek.common.equipment.EquipmentType tc) Updates TC Critical Slots and Mounts based on weapons on a unit or if the TC has been removed.static StringvalidateUnit(megamek.common.units.Entity unit) Check that the unit is valid.
-
Method Details
-
getDummyClient
public static megamek.client.Client getDummyClient()Returns a Client object that is used for internal calculations of the units.- Returns:
- A Client object
-
isFixedLocationSpreadEquipment
public static boolean isFixedLocationSpreadEquipment(megamek.common.equipment.EquipmentType equipmentType) Returns true for MiscTypes that are fixed to a single location or to multiple locations; in other words, those Miscs for which there is no location choice when placing them on a unit. Returns false for anything that is not a MiscType and equipment that can be placed with some choice at least. When this method returns true, the misc in question should not go unallocated on a unit; also, if it cannot be present more than once it should not be offered in the equipment tab (where it can be added multiple times). Rather, its placement should be handled by some checkbox or other GUI item.Dev note: Once this method has a very clear contract, suitable fields in MiscType could be used for it instead. Currently, this method is probably incomplete, unclear on what it's used for exactly and the exact use of the equipment field "spreadable" is also not clarified.
- Parameters:
equipmentType- The equipment to test- Returns:
- True if the equipment type is a MiscType and placed in one or more fixed locations
-
isArmor
public static boolean isArmor(megamek.common.equipment.EquipmentType eq) tells if the EquipmentType is a type of armor- Parameters:
eq- The equipment to test
-
isStructure
public static boolean isStructure(megamek.common.equipment.EquipmentType eq) tells if the EquipmentType is a type of armor- Parameters:
eq- The equipment to test
-
isTSM
public static boolean isTSM(megamek.common.equipment.EquipmentType eq) tells if EquipmentType is TSM or TargetComp- Parameters:
eq- The equipment to test
-
isRemoteSensorDispenser
public static boolean isRemoteSensorDispenser(megamek.common.equipment.EquipmentType eq) - Parameters:
eq- The equipment to test The equipmentType to check- Returns:
- true if this is a Remote Sensor Dispenser (BA or vehicular)
-
isMineDispenser
public static boolean isMineDispenser(megamek.common.equipment.EquipmentType eq) - Parameters:
eq- The equipment to test The equipmentType to check- Returns:
- true if this is a Mine Dispenser (BA or vehicular)
-
isMASC
public static boolean isMASC(megamek.common.equipment.EquipmentType eq) tells if EquipmentType is MASC- Parameters:
eq- The equipment to test
-
getCritsUsed
public static int getCritsUsed(megamek.common.equipment.Mounted<?> mount) Returns the number of critical slots used by EquipmentType for each placement. For most equipment this is the same as the total slots, but some spreadable equipment is allocated a single slot at a time, or split between multiple locations.- Parameters:
mount- The equipment mount- Returns:
- The number of slots per allocation
-
removeMounted
public static void removeMounted(megamek.common.units.Entity unit, megamek.common.equipment.Mounted<?> mount) Removes a piece of equipment from the Entity- Parameters:
unit- The entitymount- The equipment
-
removeAllCriticalSlots
public static void removeAllCriticalSlots(megamek.common.units.Entity unit) Removes all critical slots of the given unit, unallocating most equipment (i.e., placing it intoEntity.LOC_NONE. Generally, equipment that does not make sense when unallocated is either deleted or left in its location. Depending on unit type, ammo is left in place when its placement is not free (fighters). Unallocated Clan CASE is removed (but all other forms of CASE/CASE II/CASE-P are not). Weapon bays are deleted. -
removeCriticalSlots
public static void removeCriticalSlots(megamek.common.units.Entity unit, @Nullable megamek.common.equipment.Mounted<?> mounted) Sets the corresponding critical slots to null for the Mounted object. All crit slots of the unit are checked for any presence of that Mounted (object equality!) and emptied where found. When mounted is null, this method does nothing. Note that the crit slots are checked even if the mounted equipment is unallocated (in Entity.LOC_NONE) or not part of the unit at all.- Parameters:
unit- The entitymounted- The equipment to test
-
removeCriticalSlots
public static void removeCriticalSlots(megamek.common.units.Entity unit, megamek.common.equipment.Mounted<?> eq, int loc) Sets the corresponding critical slots to null for the Mounted object in the given location.- Parameters:
unit- The entityeq- The equipment to testloc- The location to remove critical slots from.
-
addMounted
public static void addMounted(megamek.common.units.Entity unit, megamek.common.equipment.Mounted<?> mounted, int loc, boolean rearMounted) throws megamek.common.exceptions.LocationFullException Adds the given Mounted equipment to the given unit in the given location, applying rearMounted, by forwarding to Entity.addEquipment() -- see that method for details. Also sets the equipment to pod-mounted on Omni units if possible, and updates Clan CASE placement on Meks. This method is an MML wrapper for Entity.addEquipment().- Parameters:
unit- The Entitymounted- The equipment to addloc- The location for the equipmentrearMounted- When true, set the equipment to rear-facing if possible- Throws:
megamek.common.exceptions.LocationFullException- When the location is full- See Also:
-
updateTC
public static megamek.common.equipment.Mounted<?> updateTC(megamek.common.units.Entity unit, megamek.common.equipment.EquipmentType tc) Updates TC Critical Slots and Mounts based on weapons on a unit or if the TC has been removed.- Parameters:
unit- The entity
-
createTCMounts
@Nullable public static megamek.common.equipment.Mounted<?> createTCMounts(megamek.common.units.Entity unit, megamek.common.equipment.EquipmentType tc) Creates TC Mount.- Parameters:
unit- The entity
-
isLegal
public static boolean isLegal(megamek.common.units.Entity unit, megamek.common.interfaces.ITechnology tech) Checks to see if unit can use the tech level- Parameters:
unit- The entity- Returns:
- Boolean if the tech level is legal for the passed unit
-
isHeatSink
public static boolean isHeatSink(megamek.common.equipment.Mounted<?> eq) checks if Mounted is a heat sink- Parameters:
eq- The equipment to test
-
isHeatSink
public static boolean isHeatSink(megamek.common.equipment.EquipmentType eq) Checks if EquipmentType is a heat sink- Parameters:
eq- The equipment to test
-
isHeatSink
public static boolean isHeatSink(megamek.common.equipment.EquipmentType eq, boolean ignorePrototype) -
isPhysicalWeapon
public static boolean isPhysicalWeapon(megamek.common.equipment.EquipmentType eq) Checks if EquipmentType is a Mek Physical weapon.- Parameters:
eq- The equipment to test The equipment to check- Returns:
- Whether the equipment is a physical weapon
-
getHeatSinkType
-
isJumpJet
public static boolean isJumpJet(megamek.common.equipment.Mounted<?> m) -
getJumpJetType
- Parameters:
type- The value returned byMek.getJumpType()- Returns:
- The
EquipmentTypelookup key for the jump jet
-
isWeaponEnhancement
public static boolean isWeaponEnhancement(megamek.common.equipment.EquipmentType type) Checks whether equipment can be linked to a weapon to enhance it (e.g. Artemis, PPC Capacitor, etc.).- Parameters:
type- The equipment to check- Returns:
- true if the equipment is a MiscType that can be linked to a weapon.
-
changeMountStatus
public static void changeMountStatus(megamek.common.units.Entity unit, megamek.common.equipment.Mounted<?> eq, int location, int secondaryLocation, boolean rear) Updates the location for a Mounted equipment. If the equipment was previously in another location, links to other equipment are removed. If it is placed in a location on the unit (i.e., not Entity.LOC_NONE), new links are possibly created using MekFileParser.postLoadInit(). On Meks, Clan CASE placement is updated. This method does *NOT* change nor create Critical Slots.Note: for BattleArmor, this affects which suit the equipment is placed on (as that is what Mounted. Location means for BA), but not where on the suit it's located (ie, BAMountLocation isn't affected). BattleArmor should change this outside of this method.
- Parameters:
unit- The entity The unit being modifiedeq- The equipment to test The equipment mount to movelocation- The location to move the mount tosecondaryLocation- The secondary location for split equipment, otherwiseEntity.LOC_NONErear- Whether to mount with a rear facing
-
resizeMount
public static void resizeMount(megamek.common.equipment.Mounted<?> mount, double newSize) -
findUnallocatedAmmo
public static megamek.common.equipment.Mounted<?> findUnallocatedAmmo(megamek.common.units.Entity unit, megamek.common.equipment.EquipmentType at) Find unallocated ammo of the same type. Used by large aerospace units when removing ammo from a location to find the group to add it to.- Parameters:
unit- The entityat- The type of armor to match- Returns:
- An unallocated non-one-shot ammo mount of the same type, or null if there is not one.
-
canPodMount
public static boolean canPodMount(megamek.common.units.Entity unit, megamek.common.equipment.Mounted<?> eq) Checks whether the equipment is eligible for pod mounting in an omni unit, either because the equipment itself can never be pod-mounted (such as armor, structure, or myomer enhancements), or the number of fixed heat sinks have not been assigned locations.- Parameters:
unit- The entityeq- The equipment to test
-
resetBaseChassis
public static void resetBaseChassis(megamek.common.units.Entity unit) Removes all pod-mounted equipment from an omni unit- Parameters:
unit- The entity
-
hasTargComp
public static boolean hasTargComp(megamek.common.units.Entity unit) -
getHighestContinuousNumberOfCritsArray
public static int[] getHighestContinuousNumberOfCritsArray(megamek.common.units.Mek unit) -
getHighestContinuousNumberOfCrits
public static int getHighestContinuousNumberOfCrits(megamek.common.units.Entity unit, int location) -
getUnallocatedAmmoTonnage
public static double getUnallocatedAmmoTonnage(megamek.common.units.Entity unit) -
getMaximumArmorPoints
public static int getMaximumArmorPoints(megamek.common.units.Entity unit) -
getMaximumArmorPoints
public static int getMaximumArmorPoints(megamek.common.units.Entity unit, int loc) -
getMaximumArmorTonnage
public static double getMaximumArmorTonnage(megamek.common.units.Entity unit) -
getArmorPointsPerTon
public static double getArmorPointsPerTon(megamek.common.units.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
-
compactCriticalSlots
public static void compactCriticalSlots(megamek.common.units.Entity unit) -
getMaxArmor
Determine the maximum number of armor points that can be mounted in a location.- Returns:
- The maximum number of armor points for the location, or null if there is no maximum.
-
compactCriticalSlots
public static void compactCriticalSlots(megamek.common.units.Entity unit, int loc) Removes empty crit slots between equipment from the given location on the given unit, if there are any. Does nothing for an invalid location, including Entity.LOC_NONE.- Parameters:
unit- The Entityloc- The location to compact
-
isAMS
public static boolean isAMS(megamek.common.equipment.WeaponType weapon) -
hasSwitchableAmmo
public static boolean hasSwitchableAmmo(megamek.common.equipment.WeaponType weapon) -
loadFonts
public static void loadFonts() -
deriveFont
-
deriveFont
-
removeOneShotAmmo
public static void removeOneShotAmmo(megamek.common.units.Entity unit) -
hasAmmo
public static boolean hasAmmo(megamek.common.units.Entity unit, int location) -
isJumpJet
public static boolean isJumpJet(megamek.common.equipment.EquipmentType eq) Checks to see if something is a Jump Jet- Parameters:
eq- The equipment to test
-
getCritName
public static String getCritName(megamek.common.units.Entity unit, megamek.common.equipment.EquipmentType eq) - Returns:
- the name of the given equipment with (IS) or (Clan) added for mixed tech units when appropriate.
-
getCriticalFreeHeatSinks
public static int getCriticalFreeHeatSinks(megamek.common.units.Entity unit, boolean compact) Return the number of critical-space free heat sinks that the given entity can have.- Parameters:
unit- The entity The unit mounting the heat sinkscompact- Whether the heat sinks are compact or not- Returns:
- The number of critical-free heat sinks.
-
getTotalHeatGeneration
public static int getTotalHeatGeneration(megamek.common.units.Entity entity) Returns the total heat generation of the entity -
getTotalHeatGeneration
public static int getTotalHeatGeneration(megamek.common.units.Entity entity, boolean countOneShots) Returns the total equipment (not movement) heat generation of the entity- Parameters:
countOneShots- If false, one-shot weapons are excluded.
-
isPreviousCriticalSlotEmpty
public static boolean isPreviousCriticalSlotEmpty(megamek.common.units.Entity unit, int slot, int location) Determines if the previous critical slot is empty.- Parameters:
unit- Unit to check.slot- Critical Slot Locationlocation- Unit Location- Returns:
- True if previous is empty.
-
isLastCrit
public static boolean isLastCrit(megamek.common.units.Entity unit, megamek.common.CriticalSlot cs, int slot, int location) -
updateCritsArmoredStatus
public static void updateCritsArmoredStatus(megamek.common.units.Entity unit, megamek.common.equipment.Mounted<?> mount, int location) Finds all the critical slots in the location containing the mount and sets or clears the armored component flag in accordance with the flag on the mount.- Parameters:
unit- The entity The unit the equipment is mounted onmount- The mountlocation- The location to check
-
updateCritsArmoredStatus
public static void updateCritsArmoredStatus(megamek.common.units.Entity unit, megamek.common.equipment.Mounted<?> mount) Sets the armored component flag on all critical slots occupied by an equipment mount to be the same as the flag on the mount.- Parameters:
unit- The entity The unit the equipment is onmount- The equipment mount
-
updateCritsArmoredStatus
public static void updateCritsArmoredStatus(megamek.common.units.Entity unit, @Nullable megamek.common.CriticalSlot cs, int location) -
isArmorOrStructure
public static boolean isArmorOrStructure(megamek.common.equipment.EquipmentType eq) -
updateLoadedUnit
public static void updateLoadedUnit(megamek.common.units.Entity unit) -
isUnitWeapon
public static boolean isUnitWeapon(megamek.common.equipment.EquipmentType eq, megamek.common.units.Entity unit) -
isEntityEquipment
public static boolean isEntityEquipment(megamek.common.equipment.EquipmentType eq, megamek.common.units.Entity en) -
isSupportVehicleEquipment
public static boolean isSupportVehicleEquipment(megamek.common.equipment.EquipmentType type, megamek.common.units.Entity unit) Returns true if the given Equipment is available as equipment to the given Support Vehicle. Includes WeaponTypes, AmmoTypes and MiscTypes.- Parameters:
type- The equipment to testunit- The support vehicle (an Aero or Tank subclass!)- Returns:
- true if the equipment is usable by the entity
-
removeISorArmorCrits
public static void removeISorArmorCrits(megamek.common.units.Entity unit, boolean internalStructure) remove all CriticalSlots on the passed unit that are internal structure or armor- Parameters:
unit- The entityinternalStructure- true to remove IS, false to remove armor
-
removeISorArmorMounts
public static void removeISorArmorMounts(megamek.common.units.Entity unit, boolean internalStructure) remove all Mounted on the passed unit that are internal structure or armor- Parameters:
unit- The entityinternalStructure- true to remove IS, false to remove armor
-
resetArmor
public static void resetArmor(megamek.common.units.Entity unit, int loc) Remove all mounts for the current armor type from a single location on the passed unit and sets the armor type in that location to standard.- Parameters:
unit- The entity TheEntityloc- The location from which to remove the armor mounts.
-
checkArmor
public static void checkArmor(megamek.common.units.Entity unit) -
getEntityVerifier
public static megamek.common.verifier.TestEntity getEntityVerifier(megamek.common.units.Entity unit) - Parameters:
unit- The entity the supplied entity- Returns:
- a TestEntity instance for the supplied Entity.
-
validateUnit
Check that the unit is valid. When the "Use Game Year" setting is enabled, equipment intro dates are validated against the configured game year rather than the unit's intro year.- Parameters:
unit- The entity
-
removeAllMiscMounted
public static void removeAllMiscMounted(megamek.common.units.Entity unit, megamek.common.equipment.EquipmentFlag flag) -
removeAllMounted
public static void removeAllMounted(megamek.common.units.Entity unit, megamek.common.equipment.EquipmentType et) -
removeTC
public static void removeTC(megamek.common.units.Entity unit) -
isValidLocation
public static boolean isValidLocation(megamek.common.units.Entity unit, megamek.common.equipment.EquipmentType eq, int location) Returns true when the given equipment can be placed in the given location on the given unit. This does not test if it can be added again given other present equipment (i.e., if there are restrictions on the equipment count), only if the location is suitable for the equipment type at all.- Parameters:
unit- The entity being designedeq- The equipment to testlocation- The location- Returns:
- True when an equipment of the given type can be placed in the given location
-
copyLocationEquipment
public static void copyLocationEquipment(megamek.common.units.Entity entity, int fromLoc, int toLoc) throws megamek.common.exceptions.LocationFullException Makes the equipment mounted in one location identical to that in another location. Any equipment previously in the target location that is does not match the source location is removed and assigned to Entity.LOC_NONE.- Parameters:
entity- The unit being modifiedfromLoc- The source location indextoLoc- The target location index- Throws:
megamek.common.exceptions.LocationFullException- If the target location is full
-
copyLocationEquipment
public static void copyLocationEquipment(megamek.common.units.Entity entity, int fromLoc, int toLoc, boolean includeForward, boolean includeRear) throws megamek.common.exceptions.LocationFullException Makes the equipment mounted in one location identical to that in another location. Any equipment previously in the target location that does not match the source location is removed and assigned to Entity.LOC_NONE. This does not handle split location equipment.- Parameters:
entity- The unit being modifiedfromLoc- The source location indextoLoc- The target location indexincludeForward- Whether to include forward-mounted equipmentincludeRear- Whether to include rear-mounted equipment- Throws:
megamek.common.exceptions.LocationFullException- If the target location is full
-
removeHiddenAmmo
public static void removeHiddenAmmo(megamek.common.equipment.Mounted<?> mounted) If the given Mounted is a one-shot launcher or infantry weapon, this method removes the hidden ammo linked to it, if any. During construction, we have no use of hidden ammo. Cannot useremoveOneShotAmmo(Entity)here as it removes all ammo that has no location (which is how hidden ammo is kept when a unit is loaded from file) but during construction normal ammo may not yet have been allocated and also have no location.- Parameters:
mounted- The weapon to remove linked hidden ammo
-
showValidation
-
canUseAmmo
public static boolean canUseAmmo(megamek.common.units.Entity unit, megamek.common.equipment.AmmoType ammoType, boolean includeOneShot) Checks whether the unit has a weapon that uses the ammo type and the munition is legal for the type of unit.- Parameters:
unit- The entity The unitammoType- The ammoincludeOneShot- If false, ignores one-shot weapons- Returns:
- Whether the unit can make use of the ammo
-
checkEquipmentByTechLevel
public static boolean checkEquipmentByTechLevel(megamek.common.units.Entity unit, megamek.common.interfaces.ITechManager techManager) Checks for any equipment added on the equipment tab and removes any that is no longer legal for the current year/tech base/tech level- Parameters:
unit- The entity The unit to checktechManager- The manager that handles the checking- Returns:
- Whether any changes were made
-
setManualBV
public static void setManualBV(int manualBV, megamek.common.units.Entity entity) Updates the manual BV value of the given entity. When manualBV is 0 or less, the entity is set to not use a manual BV value and the manual BV is set to -1.- Parameters:
manualBV- A manual BV value; values less than 1 remove the manual BV from the entity.
-
setVariableSizeMiscTypeMinimumSize
public static void setVariableSizeMiscTypeMinimumSize(megamek.common.equipment.Mounted<?> mounted) For MiscTypes of variable size such as Ladders this sets the size to the minimum size which is equal to the step size (20m for Ladders, 0.5t for Cargo space and the like). -
getEditorTypeForEntity
public static long getEditorTypeForEntity(megamek.common.units.Entity newUnit) -
saveUnitToString
public static String saveUnitToString(megamek.common.units.Entity entity, boolean includeGeneratorHeader) Encodes the unit to a string.- Parameters:
entity- The unit to encode- Returns:
- The encoded unit as a string, or null if the unit is null or an error
-
cloneUnit
public static megamek.common.units.Entity cloneUnit(megamek.common.units.Entity entity) Clone an entity. This method creates a deep copy of the entity, including all its properties and references.- Parameters:
entity- The entity to copy- Returns:
- The copied entity
-
resetUnit
public static void resetUnit(megamek.common.units.Entity entity) Reset the damage to the unit to its original state.- Parameters:
entity- The entity to reset
-
isDamaged
public static boolean isDamaged(megamek.common.units.Entity entity, boolean includeCrew) -
getPrintName
-