Package megamek.common.units
Class ConstructionUtil
java.lang.Object
megamek.common.units.ConstructionUtil
Helper methods for constructing/changing units, including adding, moving and removing equipment. This happens mostly
in MML but some units have modular equipment which MM must be able to switch out and doing this is involved and
error-prone and should be unified. Unfortunately, UnitUtil cannot simply be copied over to MM as it accesses too many
other MML classes.
This class contains methods that apply to all or multiple unit types. Type specific methods should be placed in their own construction util classes, such as BaConstructionUtil.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidchangeMountStatus(Entity unit, Mounted<?> eq, int location, int secondaryLocation, boolean rear) Updates the location for a Mounted equipment.static Mounted<?> findUnallocatedAmmo(Entity unit, EquipmentType at) Find unallocated ammo of the same type.static voidremoveCriticalSlots(Entity unit, Mounted<?> mounted) Sets the corresponding critical slots to null for the Mounted object.static voidremoveMounted(Entity unit, Mounted<?> mount) Removes a piece of equipment from the given unit.
-
Constructor Details
-
ConstructionUtil
public ConstructionUtil()
-
-
Method Details
-
removeMounted
Removes a piece of equipment from the given unit. "Remove" means that it is deleted entirely, not just unallocated. Attached equipment, e.g. weapons in a BA AP mount, will become unattached. Note that, in MM, some previously linked equipment should be dealt with (removed) as well to avoid errors.- Parameters:
unit- The entitymount- The equipment
-
removeCriticalSlots
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
-
changeMountStatus
public static void changeMountStatus(Entity unit, 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
-
findUnallocatedAmmo
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.
-