Package megameklab.util
Class MekUtil
java.lang.Object
megameklab.util.MekUtil
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classA location CriticalSlot sorter using the official sort order (mostly)static final recordA Mounted sorter using the official sort order (mostly) -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddCompactHeatSinkMounts(megamek.common.units.Mek unit, int hsAmount) static voidaddHeatSinkMounts(megamek.common.units.Mek unit, int hsAmount, String hsType) adds all heat sinks to the Mekstatic voidaddHeatSinkMounts(megamek.common.units.Mek unit, int hsAmount, megamek.common.equipment.EquipmentType sinkType) adds all heat sinks to the Mekstatic booleanaddVGL(megamek.common.units.Mek mek, megamek.common.equipment.Mounted<?> vgl, int location, int slotNumber) Add a vehicular grenade launcher, asking the user for the facing.static intavailableContiguousCrits(megamek.common.units.Entity mek, int location, int startingSlot, boolean ignoreFMU) Returns the number of contiguous slots starting from startingSlot that are either free or can be freed by removing unhittable and movable (FMU) equipment such as Endo Steel.static booleancanFreeContiguousCrits(megamek.common.units.Entity mek, int location, int startingSlot, int numOfSlots) Returns true when numOfSlots contiguous slots starting from startingSlot are either free or can be freed by removing unhittable and movable equipment such as Endo Steel.static voidcompactCriticalSlots(megamek.common.units.Mek mek) Compacts the crit slots in all locations of the given Mek, moving Empty slots to the bottom.static voidcompactCriticalSlots(megamek.common.units.Mek mek, int location) Compacts the crit slots in the given location of the given Mek, moving Empty slots to the bottom.static intcountActualHeatSinks(megamek.common.units.Mek unit) static intcountUnallocatedCriticalSlots(megamek.common.units.Mek unit) static intcountUsedCriticalSlots(megamek.common.units.Mek unit) static megamek.common.equipment.Mounted<?> createSpreadMounts(megamek.common.units.Mek unit, megamek.common.equipment.EquipmentType equip) create a Mounted and corresponding CriticalSlots for the passed inEquipmentTypeon the passed inMekstatic voidexpandUnitMounts(megamek.common.units.Mek unit) Expands crits that are a single mount by have multiple spreadable crits Such as TSM, Endo Steel, Reactive armor.static List<megamek.common.CriticalSlot> extricateCritSlots(megamek.common.units.Mek mek, int location) Removes all crit slots from the given location except for system crit slots (e.g.static voidfillInAllEquipment(megamek.common.units.Mek mek) Moves all equipment that is currently unallocated (LOC_NONE) to free locations on the Mek as long as there are any.static voidfillInFMU(megamek.common.units.Mek mek) Moves all equipment that is freely movable and unhittable (e.g.static intfindSlotWithContiguousNumOfCrits(megamek.common.units.Entity mek, int location, int length) Returns the first slot in the location that together with following slots forms a contiguous block of the given length as size where all slots are either empty of contain freely movable crits such as Endo Steel.static intgetCoarseOrdering(megamek.common.units.Mek mek, megamek.common.equipment.Mounted<?> mounted) Returns a number indicating the order in which equipment should be sorted within a location according to the official crit slot sorting.static intgetMaxContiguousNumOfCrits(megamek.common.units.Mek mek, int location, boolean ignoreFMU) Returns the highest number of contiguous free crit slots available in the given location.static megamek.common.equipment.Mounted<?> getSingleCompactHeatSink(megamek.common.units.Mek unit) get the single non-compact heat sink that is a non-engine sink, if it exitsstatic booleanhasClanDoubleHeatSinks(megamek.common.units.Mek unit) Checks for Clan DHSstatic booleanhasSameHeatSinkType(megamek.common.units.Mek unit, String type) static booleanisCASE(megamek.common.equipment.Mounted<?> mounted) static booleanisFMU(megamek.common.equipment.Mounted<?> equipment) Returns true when a slot's equipment is unhittable and freely movable ("FMU"), such as Endo Steel and Ferro-Fibrous Armor but not CASE (which is unhittable but not freely movable as its location is important).static booleanisLastMekCrit(megamek.common.units.Mek unit, megamek.common.CriticalSlot cs, int slot, int location) static booleanisMekEquipment(megamek.common.equipment.EquipmentType eq, megamek.common.units.Mek unit) Returns true if the given Equipment is available as equipment to the given Mek.static booleanisMekWeapon(megamek.common.equipment.EquipmentType eq, megamek.common.units.Entity unit) static booleanisPartialWing(megamek.common.equipment.Mounted<?> mounted) static voidrefillCritSlots(megamek.common.units.Mek mek, int location, List<megamek.common.CriticalSlot> critList) Fills the given list of crit slots into the given location.static voidremoveArm(megamek.common.units.Mek mek, int location) static voidremoveEnhancements(megamek.common.units.Mek unit) Removes all enhancements (TSM and MASC) from the mekstatic voidremoveFMU(megamek.common.units.Entity mek, int location, int startingSlot, int numOfSlots) Removes all equipment that is freely movable and unhittable (e.g.static voidremoveHand(megamek.common.units.Mek mek, int location) static voidremoveHeatSinks(megamek.common.units.Mek unit, int number) Removes the specified number of heat sinks from the mek Heat sinks are removed first with LOC_NONE above the free crit limit then they are removed with a location, and lastly they are removed below the free crit limitstatic voidremoveJumpJets(megamek.common.units.Mek unit, int number) Removes all jump jets from the mekstatic voidremoveSystemCrits(megamek.common.units.Mek mek, int systemType, int loc) Removes the system crits of the given type from the location on the given mek.static List<megamek.common.CriticalSlot> reOrderLinkedEquipment(List<megamek.common.CriticalSlot> presentGear) Returns a reordered version of the given presentGear list of critical slots wherein LinkedBy mounted such as Artemis and PPC Capacitors are placed directly behind their weapon.static voidsortCrits(megamek.common.units.Mek mek) Sorts the allocated equipment on all locations (except HD) of the Mek using the officially used sort order.static voidsortCritSlots(megamek.common.units.Mek mek, int location) Sorts the crits within the given location.static voidupdateAutoSinks(megamek.common.units.Mek unit, boolean compact) This will cycle through the heat sinks and make sure that enough of them are set LOC_NONE based on the base chassis heat sinksstatic voidupdateClanCasePlacement(megamek.common.units.Mek mek) For the given Mek, removes all existing Clan CASE and then re-adds it to every location that has potentially explosive equipment (this includes PPC Capacitors).static voidupdateCompactHeatSinks(megamek.common.units.Mek mek) Adjusts compact heat sinks to fulfill engine capacity.static voidupdateHeatSinks(megamek.common.units.Mek unit, int hsAmount, String hsType) updates the heat sinks.static voidupdateJumpJets(megamek.common.units.Mek unit, int jjAmount, int jjType) updates the Jump Jets.static voidupdateLoadedMek(megamek.common.units.Mek unit)
-
Method Details
-
hasClanDoubleHeatSinks
public static boolean hasClanDoubleHeatSinks(megamek.common.units.Mek unit) Checks for Clan DHS -
removeHeatSinks
public static void removeHeatSinks(megamek.common.units.Mek unit, int number) Removes the specified number of heat sinks from the mek Heat sinks are removed first with LOC_NONE above the free crit limit then they are removed with a location, and lastly they are removed below the free crit limit -
addHeatSinkMounts
adds all heat sinks to the Mek -
addHeatSinkMounts
public static void addHeatSinkMounts(megamek.common.units.Mek unit, int hsAmount, megamek.common.equipment.EquipmentType sinkType) adds all heat sinks to the Mek -
addCompactHeatSinkMounts
public static void addCompactHeatSinkMounts(megamek.common.units.Mek unit, int hsAmount) -
getSingleCompactHeatSink
public static megamek.common.equipment.Mounted<?> getSingleCompactHeatSink(megamek.common.units.Mek unit) get the single non-compact heat sink that is a non-engine sink, if it exits -
hasSameHeatSinkType
-
updateHeatSinks
updates the heat sinks. -
updateAutoSinks
public static void updateAutoSinks(megamek.common.units.Mek unit, boolean compact) This will cycle through the heat sinks and make sure that enough of them are set LOC_NONE based on the base chassis heat sinks -
updateCompactHeatSinks
public static void updateCompactHeatSinks(megamek.common.units.Mek mek) Adjusts compact heat sinks to fulfill engine capacity. This is more complex than other heat sink types because the engine heat sinks always have one per mount, and those outside the engine are paired in a slot with one single if there are an odd number.- Parameters:
mek- The Mek to adjust heat sinks for
-
removeJumpJets
public static void removeJumpJets(megamek.common.units.Mek unit, int number) Removes all jump jets from the mek -
updateJumpJets
public static void updateJumpJets(megamek.common.units.Mek unit, int jjAmount, int jjType) updates the Jump Jets. -
removeEnhancements
public static void removeEnhancements(megamek.common.units.Mek unit) Removes all enhancements (TSM and MASC) from the mek -
compactCriticalSlots
public static void compactCriticalSlots(megamek.common.units.Mek mek) Compacts the crit slots in all locations of the given Mek, moving Empty slots to the bottom. -
compactCriticalSlots
public static void compactCriticalSlots(megamek.common.units.Mek mek, int location) Compacts the crit slots in the given location of the given Mek, moving Empty slots to the bottom. -
expandUnitMounts
public static void expandUnitMounts(megamek.common.units.Mek unit) Expands crits that are a single mount by have multiple spreadable crits Such as TSM, Endo Steel, Reactive armor. -
createSpreadMounts
public static megamek.common.equipment.Mounted<?> createSpreadMounts(megamek.common.units.Mek unit, megamek.common.equipment.EquipmentType equip) create a Mounted and corresponding CriticalSlots for the passed inEquipmentTypeon the passed inMek -
isLastMekCrit
public static boolean isLastMekCrit(megamek.common.units.Mek unit, megamek.common.CriticalSlot cs, int slot, int location) -
updateLoadedMek
public static void updateLoadedMek(megamek.common.units.Mek unit) -
countUsedCriticalSlots
public static int countUsedCriticalSlots(megamek.common.units.Mek unit) -
countUnallocatedCriticalSlots
public static int countUnallocatedCriticalSlots(megamek.common.units.Mek unit) -
countActualHeatSinks
public static int countActualHeatSinks(megamek.common.units.Mek unit) -
removeHand
public static void removeHand(megamek.common.units.Mek mek, int location) -
removeArm
public static void removeArm(megamek.common.units.Mek mek, int location) -
fillInFMU
public static void fillInFMU(megamek.common.units.Mek mek) Moves all equipment that is freely movable and unhittable (e.g. Endo Steel and Ferro-Fibrous but not CASE) ("FMU") that is currently unallocated (LOC_NONE) to free locations on the Mek as long as there are any. -
removeFMU
public static void removeFMU(megamek.common.units.Entity mek, int location, int startingSlot, int numOfSlots) Removes all equipment that is freely movable and unhittable (e.g. Endo Steel and Ferro-Fibrous but not CASE) ("FMU") from the given location, affecting numOfSlots slots beginning at startingSlot. -
fillInAllEquipment
public static void fillInAllEquipment(megamek.common.units.Mek mek) Moves all equipment that is currently unallocated (LOC_NONE) to free locations on the Mek as long as there are any. -
isFMU
public static boolean isFMU(megamek.common.equipment.Mounted<?> equipment) Returns true when a slot's equipment is unhittable and freely movable ("FMU"), such as Endo Steel and Ferro-Fibrous Armor but not CASE (which is unhittable but not freely movable as its location is important). -
sortCrits
public static void sortCrits(megamek.common.units.Mek mek) Sorts the allocated equipment on all locations (except HD) of the Mek using the officially used sort order. -
sortCritSlots
public static void sortCritSlots(megamek.common.units.Mek mek, int location) Sorts the crits within the given location. This extricates all non-system crits from the location, sorts them and then refills the location. -
extricateCritSlots
public static List<megamek.common.CriticalSlot> extricateCritSlots(megamek.common.units.Mek mek, int location) Removes all crit slots from the given location except for system crit slots (e.g. engine) and returns them as a list. -
refillCritSlots
public static void refillCritSlots(megamek.common.units.Mek mek, int location, List<megamek.common.CriticalSlot> critList) Fills the given list of crit slots into the given location. This does not check or change the respective mounted locations, so care must be taken that all mounted are indeed allocated to this location or that the crit slots have been taken from this location, e.g. withextricateCritSlots(Mek, int). -
reOrderLinkedEquipment
public static List<megamek.common.CriticalSlot> reOrderLinkedEquipment(List<megamek.common.CriticalSlot> presentGear) Returns a reordered version of the given presentGear list of critical slots wherein LinkedBy mounted such as Artemis and PPC Capacitors are placed directly behind their weapon. -
getCoarseOrdering
public static int getCoarseOrdering(megamek.common.units.Mek mek, megamek.common.equipment.Mounted<?> mounted) Returns a number indicating the order in which equipment should be sorted within a location according to the official crit slot sorting. Weapons and ammo require further internal sorting and linked equipment such as Artemis and PPC Capacitors also require extra treatment to be placed behind their weapon. -
isPartialWing
public static boolean isPartialWing(megamek.common.equipment.Mounted<?> mounted) -
isCASE
public static boolean isCASE(megamek.common.equipment.Mounted<?> mounted) -
getMaxContiguousNumOfCrits
public static int getMaxContiguousNumOfCrits(megamek.common.units.Mek mek, int location, boolean ignoreFMU) Returns the highest number of contiguous free crit slots available in the given location. When ignoreFMU is true, slots that contain unhittable and freely moveable (FMU) equipment such as Endo Steel are counted as being free. -
findSlotWithContiguousNumOfCrits
public static int findSlotWithContiguousNumOfCrits(megamek.common.units.Entity mek, int location, int length) Returns the first slot in the location that together with following slots forms a contiguous block of the given length as size where all slots are either empty of contain freely movable crits such as Endo Steel. Returns -1 if there is no such slot. -
canFreeContiguousCrits
public static boolean canFreeContiguousCrits(megamek.common.units.Entity mek, int location, int startingSlot, int numOfSlots) Returns true when numOfSlots contiguous slots starting from startingSlot are either free or can be freed by removing unhittable and movable equipment such as Endo Steel. -
availableContiguousCrits
public static int availableContiguousCrits(megamek.common.units.Entity mek, int location, int startingSlot, boolean ignoreFMU) Returns the number of contiguous slots starting from startingSlot that are either free or can be freed by removing unhittable and movable (FMU) equipment such as Endo Steel. When ignoreFMU is true, slots that contain unhittable and freely movable (FMU) equipment such as Endo Steel are counted as being free. -
addVGL
public static boolean addVGL(megamek.common.units.Mek mek, megamek.common.equipment.Mounted<?> vgl, int location, int slotNumber) throws megamek.common.exceptions.LocationFullException Add a vehicular grenade launcher, asking the user for the facing.- Throws:
megamek.common.exceptions.LocationFullException
-
updateClanCasePlacement
public static void updateClanCasePlacement(megamek.common.units.Mek mek) For the given Mek, removes all existing Clan CASE and then re-adds it to every location that has potentially explosive equipment (this includes PPC Capacitors). Skips locations that already have (IS) CASE or CASE II. Respects per-location opt-out.- Parameters:
mek- the mek to update
-
isMekEquipment
public static boolean isMekEquipment(megamek.common.equipment.EquipmentType eq, megamek.common.units.Mek unit) Returns true if the given Equipment is available as equipment to the given Mek. Only valid to use for MiscTypes, not WeaponTypes nor AmmoTypes, also physical weapons return false despite being MiscType.- Parameters:
eq- The tested equipmentunit- The Mek unit- Returns:
- true if the equipment is usable by the Mek
-
isMekWeapon
public static boolean isMekWeapon(megamek.common.equipment.EquipmentType eq, megamek.common.units.Entity unit) -
removeSystemCrits
public static void removeSystemCrits(megamek.common.units.Mek mek, int systemType, int loc) Removes the system crits of the given type from the location on the given mek.- Parameters:
mek- The MeksystemType- The system type, e.g.Mek.SYSTEM_LIFE_SUPPORTloc- The location
-