Class UnitUtil

java.lang.Object
megameklab.util.UnitUtil

public class UnitUtil extends Object
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    addMounted(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 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.
    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.
    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.
    static void
    checkArmor(megamek.common.units.Entity unit)
     
    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
    static megamek.common.units.Entity
    cloneUnit(megamek.common.units.Entity entity)
    Clone an entity.
    static void
    compactCriticalSlots(megamek.common.units.Entity unit)
     
    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.
    static void
    copyLocationEquipment(megamek.common.units.Entity entity, int fromLoc, int toLoc)
    Makes the equipment mounted in one location identical to that in another location.
    static void
    copyLocationEquipment(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 Font
    deriveFont(boolean boldFont, float pointSize)
     
    static Font
    deriveFont(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 double
    getArmorPointsPerTon(megamek.common.units.Entity en)
    Calculate the number of armor points per ton of armor for the given unit.
    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.
    static String
    getCritName(megamek.common.units.Entity unit, megamek.common.equipment.EquipmentType eq)
     
    static int
    getCritsUsed(megamek.common.equipment.Mounted<?> mount)
    Returns the number of critical slots used by EquipmentType for each placement.
    static megamek.client.Client
    Returns a Client object that is used for internal calculations of the units.
    static long
    getEditorTypeForEntity(megamek.common.units.Entity newUnit)
     
    static megamek.common.verifier.TestEntity
    getEntityVerifier(megamek.common.units.Entity unit)
     
    static String
    getHeatSinkType(String type, boolean clan)
     
    static int
    getHighestContinuousNumberOfCrits(megamek.common.units.Entity unit, int location)
     
    static int[]
    getHighestContinuousNumberOfCritsArray(megamek.common.units.Mek unit)
     
    static String
    getJumpJetType(int type)
     
    static Integer
    getMaxArmor(megamek.common.units.Entity entity, int location)
    Determine the maximum number of armor points that can be mounted in a location.
    static int
    getMaximumArmorPoints(megamek.common.units.Entity unit)
     
    static int
    getMaximumArmorPoints(megamek.common.units.Entity unit, int loc)
     
    static double
    getMaximumArmorTonnage(megamek.common.units.Entity unit)
     
    static String
    getPrintName(megamek.common.units.Entity e)
     
    static int
    getTotalHeatGeneration(megamek.common.units.Entity entity)
    Returns the total heat generation of the entity
    static int
    getTotalHeatGeneration(megamek.common.units.Entity entity, boolean countOneShots)
    Returns the total equipment (not movement) heat generation of the entity
    static double
    getUnallocatedAmmoTonnage(megamek.common.units.Entity unit)
     
    static boolean
    hasAmmo(megamek.common.units.Entity unit, int location)
     
    static boolean
    hasSwitchableAmmo(megamek.common.equipment.WeaponType weapon)
     
    static boolean
    hasTargComp(megamek.common.units.Entity unit)
     
    static boolean
    isAMS(megamek.common.equipment.WeaponType weapon)
     
    static boolean
    isArmor(megamek.common.equipment.EquipmentType eq)
    tells if the EquipmentType is a type of armor
    static boolean
    isArmorOrStructure(megamek.common.equipment.EquipmentType eq)
     
    static boolean
    isDamaged(megamek.common.units.Entity entity, boolean includeCrew)
     
    static boolean
    isEntityEquipment(megamek.common.equipment.EquipmentType eq, megamek.common.units.Entity en)
     
    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.
    static boolean
    isHeatSink(megamek.common.equipment.EquipmentType eq)
    Checks if EquipmentType is a heat sink
    static boolean
    isHeatSink(megamek.common.equipment.EquipmentType eq, boolean ignorePrototype)
     
    static boolean
    isHeatSink(megamek.common.equipment.Mounted<?> eq)
    checks if Mounted is a heat sink
    static boolean
    isJumpJet(megamek.common.equipment.EquipmentType eq)
    Checks to see if something is a Jump Jet
    static boolean
    isJumpJet(megamek.common.equipment.Mounted<?> m)
     
    static boolean
    isLastCrit(megamek.common.units.Entity unit, megamek.common.CriticalSlot cs, int slot, int location)
     
    static boolean
    isLegal(megamek.common.units.Entity unit, megamek.common.interfaces.ITechnology tech)
    Checks to see if unit can use the tech level
    static boolean
    isMASC(megamek.common.equipment.EquipmentType eq)
    tells if EquipmentType is MASC
    static boolean
    isMineDispenser(megamek.common.equipment.EquipmentType eq)
     
    static boolean
    isPhysicalWeapon(megamek.common.equipment.EquipmentType eq)
    Checks if EquipmentType is a Mek Physical weapon.
    static boolean
    isPreviousCriticalSlotEmpty(megamek.common.units.Entity unit, int slot, int location)
    Determines if the previous critical slot is empty.
    static boolean
    isRemoteSensorDispenser(megamek.common.equipment.EquipmentType eq)
     
    static boolean
    isStructure(megamek.common.equipment.EquipmentType eq)
    tells if the EquipmentType is a type of armor
    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.
    static boolean
    isTSM(megamek.common.equipment.EquipmentType eq)
    tells if EquipmentType is TSM or TargetComp
    static boolean
    isUnitWeapon(megamek.common.equipment.EquipmentType eq, megamek.common.units.Entity unit)
     
    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.
    static boolean
    isWeaponEnhancement(megamek.common.equipment.EquipmentType type)
    Checks whether equipment can be linked to a weapon to enhance it (e.g.
    static void
     
    static void
    removeAllCriticalSlots(megamek.common.units.Entity unit)
    Removes all critical slots of the given unit, unallocating most equipment (i.e., placing it into Entity.LOC_NONE.
    static void
    removeAllMiscMounted(megamek.common.units.Entity unit, megamek.common.equipment.EquipmentFlag flag)
     
    static void
    removeAllMounted(megamek.common.units.Entity unit, megamek.common.equipment.EquipmentType et)
     
    static void
    removeCriticalSlots(megamek.common.units.Entity unit, megamek.common.equipment.Mounted<?> mounted)
    Sets the corresponding critical slots to null for the Mounted object.
    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.
    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.
    static void
    removeISorArmorCrits(megamek.common.units.Entity unit, boolean internalStructure)
    remove all CriticalSlots on the passed unit that are internal structure or armor
    static void
    removeISorArmorMounts(megamek.common.units.Entity unit, boolean internalStructure)
    remove all Mounted on the passed unit that are internal structure or armor
    static void
    removeMounted(megamek.common.units.Entity unit, megamek.common.equipment.Mounted<?> mount)
    Removes a piece of equipment from the Entity
    static void
    removeOneShotAmmo(megamek.common.units.Entity unit)
     
    static void
    removeTC(megamek.common.units.Entity unit)
     
    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.
    static void
    resetBaseChassis(megamek.common.units.Entity unit)
    Removes all pod-mounted equipment from an omni unit
    static void
    resetUnit(megamek.common.units.Entity entity)
    Reset the damage to the unit to its original state.
    static void
    resizeMount(megamek.common.equipment.Mounted<?> mount, double newSize)
     
    static String
    saveUnitToString(megamek.common.units.Entity entity, boolean includeGeneratorHeader)
    Encodes the unit to a string.
    static void
    setManualBV(int manualBV, megamek.common.units.Entity entity)
    Updates the manual BV value of the given entity.
    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).
    static void
    showValidation(megamek.common.units.Entity entity, JFrame frame)
     
    static void
    updateCritsArmoredStatus(megamek.common.units.Entity unit, megamek.common.CriticalSlot cs, int location)
     
    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.
    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.
    static void
    updateLoadedUnit(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 String
    validateUnit(megamek.common.units.Entity unit)
    Check that the unit is valid.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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 entity
      mount - 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 into Entity.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 entity
      mounted - 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 entity
      eq - The equipment to test
      loc - 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 Entity
      mounted - The equipment to add
      loc - The location for the equipment
      rearMounted - When true, set the equipment to rear-facing if possible
      Throws:
      megamek.common.exceptions.LocationFullException - When the location is full
      See Also:
      • Entity.addEquipment(Mounted, int, boolean)
    • 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

      public static String getHeatSinkType(String type, boolean clan)
    • isJumpJet

      public static boolean isJumpJet(megamek.common.equipment.Mounted<?> m)
    • getJumpJetType

      public static String getJumpJetType(int type)
      Parameters:
      type - The value returned by Mek.getJumpType()
      Returns:
      The EquipmentType lookup 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 modified
      eq - The equipment to test The equipment mount to move
      location - The location to move the mount to
      secondaryLocation - The secondary location for split equipment, otherwise Entity.LOC_NONE
      rear - 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 entity
      at - 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 entity
      eq - 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

      @Nullable public static Integer getMaxArmor(megamek.common.units.Entity entity, int location)
      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 Entity
      loc - 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

      public static Font deriveFont(float pointSize)
    • deriveFont

      public static Font deriveFont(boolean boldFont, float pointSize)
    • 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 sinks
      compact - 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 Location
      location - 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 on
      mount - The mount
      location - 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 on
      mount - 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 test
      unit - 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 entity
      internalStructure - 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 entity
      internalStructure - 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 The Entity
      loc - 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

      public static String validateUnit(megamek.common.units.Entity unit)
      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 designed
      eq - The equipment to test
      location - 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 modified
      fromLoc - The source location index
      toLoc - 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 modified
      fromLoc - The source location index
      toLoc - The target location index
      includeForward - Whether to include forward-mounted equipment
      includeRear - 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 use removeOneShotAmmo(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

      public static void showValidation(megamek.common.units.Entity entity, JFrame frame)
    • 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 unit
      ammoType - The ammo
      includeOneShot - 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 check
      techManager - 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

      public static String getPrintName(megamek.common.units.Entity e)