Class Unit

java.lang.Object
mekhq.campaign.unit.Unit
All Implemented Interfaces:
megamek.common.ITechnology
Direct Known Subclasses:
Part.PartUnitRef, Person.PersonUnitRef, TestUnit, Unit.UnitRef, UnitOrder

public class Unit extends Object implements megamek.common.ITechnology
This is a wrapper class for entity, so that we can add some functionality to it
  • Field Details

    • SITE_IMPROVISED

      public static final int SITE_IMPROVISED
      See Also:
    • SITE_FIELD_WORKSHOP

      public static final int SITE_FIELD_WORKSHOP
      See Also:
    • SITE_FACILITY_BASIC

      public static final int SITE_FACILITY_BASIC
      See Also:
    • SITE_FACILITY_MAINTENANCE

      public static final int SITE_FACILITY_MAINTENANCE
      See Also:
    • SITE_FACTORY_CONDITIONS

      public static final int SITE_FACTORY_CONDITIONS
      See Also:
    • SITE_UNKNOWN

      public static final int SITE_UNKNOWN
      See Also:
    • ETYPE_MOTHBALLED

      public static final int ETYPE_MOTHBALLED
      See Also:
    • TECH_WORK_DAY

      public static final int TECH_WORK_DAY
      See Also:
    • entity

      protected megamek.common.Entity entity
    • scenarioId

      protected int scenarioId
    • daysToArrival

      protected int daysToArrival
  • Constructor Details

    • Unit

      public Unit()
    • Unit

      public Unit(megamek.common.Entity en, Campaign c)
  • Method Details

    • getDamageStateName

      public static String getDamageStateName(int i)
    • getCampaign

      public Campaign getCampaign()
    • setCampaign

      public void setCampaign(Campaign c)
    • isAvailable

      public boolean isAvailable()
      A convenience function to tell whether the unit can be acted upon e.g. assigned pilots, techs, repaired, etc.
      Returns:
    • isAvailable

      public boolean isAvailable(boolean ignoreRefit)
      A convenience function to tell whether the unit can be acted upon e.g. assigned pilots, techs, repaired, etc.
      Returns:
    • getStatus

      public String getStatus()
    • getCondition

      public String getCondition()
    • getCrewState

      public CrewAssignmentState getCrewState()
    • getTypeDisplayableNameWithOmni

      public String getTypeDisplayableNameWithOmni()
      Like UnitType.getTypeDisplayableName but prepends "Omni" to omni units
      Returns:
      String displayable name with possible "Omni"
    • reCalc

      public void reCalc()
    • initializeShipTransportSpace

      public void initializeShipTransportSpace()
      Initializes the transport capacity. If the campaign transport capacity type doesn't exist yet, try to create it. If it does already exist, let's recalculate the transport capacity instead for all transporters that this Unit has
      See Also:
    • initializeTacticalTransportSpace

      public void initializeTacticalTransportSpace()
      Initializes the transport capacity. If the campaign transport capacity type doesn't exist yet, try to create it. If it does already exist, let's recalculate the transport capacity instead for all transporters that this Unit has
      See Also:
    • initializeAllTransportSpace

      public void initializeAllTransportSpace()
      For each CampaignTransportType, initialize the transport capacity. If the campaign transport capacity type doesn't exist yet, try to create it. If it does already exist, let's recalculate the transport capacity instead for all transporters that this Unit has
      See Also:
    • clearAllTransportSpace

      public void clearAllTransportSpace()
    • initializeTransportSpace

      public void initializeTransportSpace(CampaignTransportType campaignTransportType)
      Initializes the transport capacity. If the campaign transport capacity type doesn't exist yet, try to create it. If it does already exist, let's recalculate the transport capacity instead for all transporters that this Unit has
      Parameters:
      campaignTransportType - transport type we want to prepare
    • getTransportedUnitsSummary

      @Nullable public AbstractTransportedUnitsSummary getTransportedUnitsSummary(CampaignTransportType campaignTransportType)
      For the provided campaign transport type, what's this unit's transported units summary
      Parameters:
      campaignTransportType - what kind of transport type are we checking
      Returns:
      transported units summary of that type, or null
    • setEntity

      public void setEntity(megamek.common.Entity en)
    • getEntity

      public megamek.common.Entity getEntity()
    • getId

      public UUID getId()
    • setId

      public void setId(UUID i)
    • hasTransportedUnits

      public boolean hasTransportedUnits(CampaignTransportType campaignTransportType)
      For the given transport type, is this unit transporting any other units?
      Parameters:
      campaignTransportType - Transport Type (Enum) we're checking
      Returns:
      true if it has transported units
      See Also:
    • getTransportedUnits

      public Set<Unit> getTransportedUnits(CampaignTransportType campaignTransportType)
      For the given transport type, return the set of units it's transporting, or an empty set
      Parameters:
      campaignTransportType - Transport Type (Enum) we're checking
      Returns:
      Set of Units this transport is carrying, or an empty set
    • clearTransportedUnits

      public void clearTransportedUnits(CampaignTransportType campaignTransportType)
      Clears the set of units being transported by this unit.
    • hasTransportAssignment

      public boolean hasTransportAssignment(CampaignTransportType campaignTransportType)
      Does this unit have a transport assignment for this campaign transport type?
      Parameters:
      campaignTransportType - the transport type (enum) we're interested in
      Returns:
      true if there is a transport assignment of that type, false if not
    • getTransportAssignment

      @Nullable public ITransportAssignment getTransportAssignment(CampaignTransportType campaignTransportType)
      Returns the transport assignment for the given transport type, or null if none is provided
      Parameters:
      campaignTransportType - the transport type (enum) we're interested in
      Returns:
      corresponding transport assignment, or null if there isn't one
    • setTransportAssignment

      public void setTransportAssignment(CampaignTransportType campaignTransportType, @Nullable ITransportAssignment assignment)
      Set this unit's transport assignment to the provided assignment, if possible
      Parameters:
      campaignTransportType - type (enum) of transport type
      assignment - the assignment we're setting for this unit
      See Also:
    • unloadFromTransport

      public Unit unloadFromTransport(CampaignTransportType campaignTransportType)
      Unloads a unit from transport of the provided campaign transport type
      Parameters:
      campaignTransportType - type (enum) of transport type we want to unload from
      Returns:
      transport the unit was assigned to
    • hasTransportShipAssignment

      public boolean hasTransportShipAssignment()
      Gets a value indicating whether this unit is assigned to a transport ship.
    • getTransportShipAssignment

      @Nullable public TransportShipAssignment getTransportShipAssignment()
      Gets the transport ship assignment for this unit, or null if this unit is not being transported.
    • setTransportShipAssignment

      public void setTransportShipAssignment(@Nullable TransportShipAssignment assignment)
      Sets the transport ship assignment for this unit.
      Parameters:
      assignment - The transport ship assignment, or null if this unit is not being transported.
    • hasShipTransportedUnits

      public boolean hasShipTransportedUnits()
      Gets a value indicating whether this unit is transporting units.
    • getShipTransportedUnits

      public Set<Unit> getShipTransportedUnits()
      Returns:
      the set of units being transported by this unit.
    • addShipTransportedUnit

      public void addShipTransportedUnit(Unit unit)
      Adds a unit to our set of transported units.
      Parameters:
      unit - The unit being transported by this instance.
    • removeShipTransportedUnit

      public boolean removeShipTransportedUnit(Unit unit)
      Removes a unit from our set of transported units.
      Parameters:
      unit - The unit to remove from our set of transported units.
      Returns:
      True if the unit was removed from our bays, otherwise false.
    • clearShipTransportedUnits

      public void clearShipTransportedUnits()
      Clears the set of units being transported by this unit.
    • isCarryingSmallerAero

      public boolean isCarryingSmallerAero()
      Gets a value indicating whether we are transporting any smaller aero units
    • isCarryingGround

      public boolean isCarryingGround()
      Gets a value indicating whether we are transporting any ground units.
    • getSite

      public int getSite()
    • setSite

      public void setSite(int i)
    • isSalvage

      public boolean isSalvage()
    • setSalvage

      public void setSalvage(boolean b)
    • getHistory

      public String getHistory()
    • setHistory

      public void setHistory(String s)
    • isFunctional

      public static boolean isFunctional(megamek.common.Entity en)
    • isFunctional

      public boolean isFunctional()
    • isRepairable

      public static boolean isRepairable(megamek.common.Entity en)
    • isRepairable

      public boolean isRepairable()
    • isServiceable

      public boolean isServiceable()
      Determines if this unit can be serviced.
      Returns:
      true if the unit has parts that are salvageable or in need of repair.
    • isLocationDestroyed

      public boolean isLocationDestroyed(int loc)
      Is the given location on the entity destroyed?
      Parameters:
      loc - - an int for the location
      Returns:
      true if the location is destroyed
    • isLocationBreached

      public boolean isLocationBreached(int loc)
    • hasBadHipOrShoulder

      public boolean hasBadHipOrShoulder(int loc)
    • runDiagnostic

      public void runDiagnostic(boolean checkForDestruction)
      Run a diagnostic on this unit
    • getPartsNeedingService

      public List<IPartWork> getPartsNeedingService()
      Gets a list of every part on a unit which need service (either repair or salvage), including parts currently being worked on.
    • getPartsNeedingService

      public List<IPartWork> getPartsNeedingService(boolean onlyNotBeingWorkedOn)
      Gets a list of parts on a unit which need service (either repair or salvage), optionally excluding parts already being worked on.
      Parameters:
      onlyNotBeingWorkedOn - When true, excludes parts currently being repaired or salvaged.
    • getPartsNeedingFixing

      public ArrayList<IPartWork> getPartsNeedingFixing()
    • hasPartsNeedingFixing

      public boolean hasPartsNeedingFixing()
      Determines if this unit has parts in need of repair.
      Returns:
      true if the unit has parts that are in need of repair.
    • getPartsNeedingFixing

      public ArrayList<IPartWork> getPartsNeedingFixing(boolean onlyNotBeingWorkedOn)
    • getSalvageableParts

      public ArrayList<IPartWork> getSalvageableParts()
    • hasSalvageableParts

      public boolean hasSalvageableParts()
      Determines if this unit has parts that are salvageable.
      Returns:
      true if the unit has parts that are salvageable.
    • getSalvageableParts

      public ArrayList<IPartWork> getSalvageableParts(boolean onlyNotBeingWorkedOn)
    • getPartsNeeded

      public ArrayList<IAcquisitionWork> getPartsNeeded()
    • getValueOfAllMissingParts

      public Money getValueOfAllMissingParts()
    • removePart

      public void removePart(Part part)
    • hasPilot

      public boolean hasPilot()
    • getPilotDesc

      public String getPilotDesc()
    • getSiteMod

      public megamek.common.TargetRoll getSiteMod()
    • getSiteName

      public static String getSiteName(int loc)
    • getSiteToolTipText

      public static String getSiteToolTipText(int loc)
    • getCurrentSiteName

      public String getCurrentSiteName()
    • isDeployed

      public boolean isDeployed()
    • undeploy

      public void undeploy()
    • checkDeployment

      @Nullable public String checkDeployment()
      Validates the deployment readiness of the unit.

      This method checks multiple conditions to determine whether the unit is deployable. If the unit is not deployable, a descriptive error message is returned indicating the reason for its ineligibility. If the unit passes all validations, null is returned, implying it is ready for deployment.

      Deployment checks performed:

      • If the unit is not functional, it cannot be deployed.
      • If the unit is unmanned and is not an unmanned trailer, it cannot be deployed.
      • If the unit is in the process of being refitted, it cannot be deployed.
      • If the unit is a tank and does not have the required crew size, it cannot be deployed.
      • If the unit is a BattleArmor unit with empty suits, it cannot be deployed until these are filled or salvaged.
      Returns:
      A descriptive String error message if the unit cannot be deployed, or null if the unit is deployable.
    • hasTSM

      public boolean hasTSM()
      Returns:
      Have to make one here because the one in MegaMek only returns true if operable
    • isSystemMissing

      public boolean isSystemMissing(int system, int loc)
      Returns true if there is at least one missing critical slot for this system in the given location
    • getHitCriticals

      public int getHitCriticals(int type, int index)
      Number of slots doomed, missing or destroyed in all locations
      Parameters:
      type -
      index -
      Returns:
    • getHitCriticals

      public int getHitCriticals(int type, int index, int loc)
      Number of slots doomed, missing or destroyed in a location
    • damageSystem

      public void damageSystem(int type, int equipmentNum, int hits)
    • damageSystem

      public int damageSystem(int type, int equipmentNum, int loc, int hits)
    • destroySystem

      public void destroySystem(int type, int equipmentNum)
    • destroySystem

      public void destroySystem(int type, int equipmentNum, int loc)
    • destroySystem

      public void destroySystem(int type, int equipmentNum, int loc, int hits)
    • repairSystem

      public void repairSystem(int type, int equipmentNum)
    • repairSystem

      public void repairSystem(int type, int equipmentNum, int loc)
    • isDamaged

      public boolean isDamaged()
    • getSellValue

      public Money getSellValue()
    • getCargoCapacity

      public double getCargoCapacity()
      Calculates the total cargo capacity of the entity, considering the usable capacities of transport bays and mounted equipment designated for cargo. The calculation is performed only if the entity is fully crewed.

      The total cargo capacity is derived from the following:

      • The usable capacities of transport bays (CargoBay, RefrigeratedCargoBay, or InsulatedCargoBay), adjusted for existing damage.
      • The tonnage of mounted equipment tagged with the F_CARGO flag, provided the equipment is operable and located in non-destroyed sections of the entity.

      Special Conditions:

      • The method returns 0.0 if the entity is not fully crewed.
      • Bays or mounted equipment damaged beyond usability are excluded from the total.
      • Only equipment in valid (non-destroyed) sections of the entity are considered.
      Returns:
      The total cargo capacity of the entity if fully crewed; otherwise, 0.0.
    • getRefrigeratedCargoCapacity

      public double getRefrigeratedCargoCapacity()
    • getLiquidCargoCapacity

      public double getLiquidCargoCapacity()
    • getLivestockCargoCapacity

      public double getLivestockCargoCapacity()
    • getInsulatedCargoCapacity

      public double getInsulatedCargoCapacity()
    • getTotalWeightOfUnitsAssignedToBeTransported

      public double getTotalWeightOfUnitsAssignedToBeTransported(CampaignTransportType transportType, TransporterType transporterType)
      Calculates the total weight of all units assigned to be transported in this unit for a specific transport type and transporter type.

      This method:

      • Finds all units currently assigned to be transported by this unit with the specified transport type.
      • For each transported unit, checks if it is assigned to a transporter of the specified type.
      • Adds the full weight of each matching transported unit to the total.
      Parameters:
      transportType - The transport type to match when retrieving transported units.
      transporterType - The transporter type to filter assignments (only units assigned to this type are considered).
      Returns:
      The sum weight of all units assigned to this unit via the given transport and transporter type.
      Since:
      0.50.05
    • getCorrectBayCapacity

      public double getCorrectBayCapacity(int unitType, double unitWeight)
      Convenience method to call the right capacity getter based on unit type and weight
      Parameters:
      unitType - integer obtained from a unit's entity that denotes its type (mek, tank, etc.)
      unitWeight - double Weight in tons of the unit's entity. Important for tanks and infantry
    • updateBayCapacity

      public void updateBayCapacity(int unitType, double unitWeight, boolean addUnit, int bayNumber)
      Convenience method to call the right capacity update based on unit type When updating capacity, this method is concerned primarily with ensuring that space isn't released beyond the unit's maximum. Checks are made to keep from going below 0 before we ever get here.
      Parameters:
      unitType - integer obtained from a unit's entity that denotes its type (mek, tank, etc.)
      unitWeight - double Weight in tons of the unit's entity. Important for infantry
      addUnit - boolean value that determines whether to add or subtract 1 from bay capacity
      bayNumber - integer representing the bay number that has been assigned to a cargo entity
    • getDocks

      public int getDocks()
    • getCurrentDocks

      @Deprecated(since="0.50.04") public int getCurrentDocks()
      Deprecated.
      this only checks ship transport type, use getCurrentTransportCapacity(CampaignTransportType.SHIP_TRANSPORT, appropriate bay class) to replicate this
      Get only collars to which a DropShip has been assigned Capacity
      See Also:
    • setDocks

      @Deprecated(since="0.50.04") public void setDocks(int docks)
      Deprecated.
      this only sets for a ship transport type. Transport Capacities should not be manually updated with this, it should happen inside any loading flows. If you really need to replicate this, use setCurrentShipTransportCapacity(CampaignTransportType.SHIP_TRANSPORT, appropriate bay class) - but you probably don't want to do that
      Used to assign a Drop-ship to a collar on a specific Jumpship in the TOE
      Parameters:
      docks -
      See Also:
    • getLightVehicleCapacity

      public double getLightVehicleCapacity()
    • getCurrentLightVehicleCapacity

      @Deprecated(since="0.50.04") public double getCurrentLightVehicleCapacity()
      Deprecated.
      this only checks a ship transport type, use getCurrentTransportCapacity(CampaignTransportType.SHIP_TRANSPORT, appropriate bay class) to replicate this
      Get only bays to which a light tank has been assigned
      Returns:
      capacity
      See Also:
    • setLightVehicleCapacity

      @Deprecated(since="0.50.04") public void setLightVehicleCapacity(double bays)
      Deprecated.
      this only sets for a ship transport type. Transport Capacities should not be manually updated with this, it should happen inside any loading flows. If you really need to replicate this use setCurrentShipTransportCapacity(CampaignTransportType.SHIP_TRANSPORT, appropriate bay class) - but you probably don't want to do that
      Used to assign a tank to a bay on a specific transport ship in the TOE
      Parameters:
      bays -
      See Also:
    • getHeavyVehicleCapacity

      public double getHeavyVehicleCapacity()
    • getCurrentHeavyVehicleCapacity

      @Deprecated(since="0.50.04") public double getCurrentHeavyVehicleCapacity()
      Deprecated.
      this only checks a ship transport type, use getCurrentTransportCapacity(CampaignTransportType.SHIP_TRANSPORT, appropriate bay class) to replicate this
      Get only bays to which a heavy tank has been assigned
      Returns:
      capacity
      See Also:
    • setHeavyVehicleCapacity

      @Deprecated(since="0.50.04") public void setHeavyVehicleCapacity(double bays)
      Deprecated.
      this only sets for a ship transport type. Transport Capacities should not be manually updated with this, it should happen inside any loading flows. If you really need to replicate this use setCurrentShipTransportCapacity(CampaignTransportType.SHIP_TRANSPORT, appropriate bay class) - but you probably don't want to do that
      Used to assign a tank to a bay on a specific transport ship in the TOE
      Parameters:
      bays -
      See Also:
    • getSuperHeavyVehicleCapacity

      public double getSuperHeavyVehicleCapacity()
    • getCurrentSuperHeavyVehicleCapacity

      @Deprecated(since="0.50.04") public double getCurrentSuperHeavyVehicleCapacity()
      Deprecated.
      this only checks a ship transport type, use getCurrentTransportCapacity(CampaignTransportType.SHIP_TRANSPORT, appropriate bay class) to replicate this
      Get only bays to which a super heavy tank has been assigned
      See Also:
    • setSuperHeavyVehicleCapacity

      @Deprecated(since="0.50.04") public void setSuperHeavyVehicleCapacity(double bays)
      Deprecated.
      this only sets for a ship transport type. Transport Capacities should not be manually updated with this, it should happen inside any loading flows. If you really need to replicate this use setCurrentShipTransportCapacity(CampaignTransportType.SHIP_TRANSPORT, appropriate bay class) - but you probably don't want to do that
      Used to assign a tank to a bay on a specific transport ship in the TOE
      Parameters:
      bays -
      See Also:
    • getBattleArmorCapacity

      public double getBattleArmorCapacity()
    • getCurrentBattleArmorCapacity

      @Deprecated(since="0.50.04") public double getCurrentBattleArmorCapacity()
      Deprecated.
      this only checks a ship transport type, use getCurrentTransportCapacity(CampaignTransportType.SHIP_TRANSPORT, appropriate bay class) to replicate this
      Get only bays to which a ba squad has been assigned
      Returns:
      capacity
      See Also:
    • setBattleArmorCapacity

      @Deprecated(since="0.50.04") public void setBattleArmorCapacity(double bays)
      Deprecated.
      this only sets for a ship transport type. Transport Capacities should not be manually updated with this, it should happen inside any loading flows. If you really need to replicate this use setCurrentShipTransportCapacity(CampaignTransportType.SHIP_TRANSPORT, appropriate bay class) - but you probably don't want to do that
      Used to assign a ba squad to a bay on a specific transport ship in the TOE
      Parameters:
      bays -
      See Also:
    • getInfantryCapacity

      public double getInfantryCapacity()
    • getCurrentInfantryCapacity

      @Deprecated(since="0.50.04") public double getCurrentInfantryCapacity()
      Deprecated.
      this only checks a ship transport type, use getCurrentTransportCapacity(CampaignTransportType.SHIP_TRANSPORT, appropriate bay class) to replicate this
      Return the unused tonnage of any conventional infantry bays
      Returns:
      capacity
      See Also:
    • setInfantryCapacity

      @Deprecated(since="0.50.04") public void setInfantryCapacity(double tonnage)
      Deprecated.
      this only sets for ship transport type. Transport Capacities should not be manually updated with this, it should happen inside any loading flows. If you really need to replicate this use setCurrentShipTransportCapacity(CampaignTransportType.SHIP_TRANSPORT, appropriate bay class) - but you probably don't want to do that
      Used to assign an infantry unit to a bay on a specific transport ship in the TOE Tonnage consumed depends on the platoon/squad weight
      Parameters:
      tonnage -
      See Also:
    • getASFCapacity

      public double getASFCapacity()
    • getCurrentASFCapacity

      @Deprecated(since="0.50.04") public double getCurrentASFCapacity()
      Deprecated.
      this only checks ship transport type, use getCurrentTransportCapacity(CampaignTransportType.SHIP_TRANSPORT, appropriate bay class) to replicate this
      Get only bays to which a fighter has been assigned
      Returns:
      capacity
      See Also:
    • setASFCapacity

      @Deprecated(since="0.50.04") public void setASFCapacity(double bays)
      Deprecated.
      this only sets for ship transport type. Transport Capacities should not be manually updated with this, it should happen inside any loading flows. If you really need to replicate this use setCurrentShipTransportCapacity(CampaignTransportType.SHIP_TRANSPORT, appropriate bay class) - but you probably don't want to do that
      Used to assign a fighter to a bay on a specific transport ship in the TOE
      Parameters:
      bays -
      See Also:
    • getSmallCraftCapacity

      public double getSmallCraftCapacity()
    • getCurrentSmallCraftCapacity

      @Deprecated(since="0.50.04") public double getCurrentSmallCraftCapacity()
      Deprecated.
      this only checks ship transport type, use getCurrentTransportCapacity(CampaignTransportType.SHIP_TRANSPORT, appropriate bay class) to replicate this
      Get only bays to which a small craft has been assigned
      Returns:
      capacity
      See Also:
    • setSmallCraftCapacity

      @Deprecated(since="0.50.04") public void setSmallCraftCapacity(double bays)
      Deprecated.
      this only sets for ship transport type. Transport Capacities should not be manually updated with this, it should happen inside any loading flows. If you really need to replicate this use setCurrentShipTransportCapacity(CampaignTransportType.SHIP_TRANSPORT, appropriate bay class) - but you probably don't want to do that
      Used to assign a small craft to a bay on a specific transport ship in the TOE
      Parameters:
      bays -
      See Also:
    • getMekCapacity

      public double getMekCapacity()
    • getCurrentMekCapacity

      @Deprecated(since="0.50.04") public double getCurrentMekCapacity()
      Deprecated.
      this only checks ship transport type, use getCurrentTransportCapacity(CampaignTransportType.SHIP_TRANSPORT, appropriate bay class) to replicate this
      Get only bays to which a mek has been assigned
      Returns:
      capacity
      See Also:
    • setMekCapacity

      @Deprecated(since="0.50.04") public void setMekCapacity(double bays)
      Deprecated.
      this only sets for ship transport type. Transport Capacities should not be manually updated with this, it should happen inside any loading flows. If you really need to replicate this use setCurrentShipTransportCapacity(CampaignTransportType.SHIP_TRANSPORT, appropriate bay class) - but you probably don't want to do that
      Used to assign a mek or LAM to a bay on a specific transport ship in the TOE
      Parameters:
      bays -
      See Also:
    • getProtoMekCapacity

      public double getProtoMekCapacity()
    • getCurrentProtoMekCapacity

      @Deprecated(since="0.50.04") public double getCurrentProtoMekCapacity()
      Deprecated.
      this only checks ship transport type, use getCurrentTransportCapacity(CampaignTransportType.SHIP_TRANSPORT, appropriate bay class) to replicate this
      Get only bays to which a protomek has been assigned
      Returns:
      capacity
      See Also:
    • setProtoCapacity

      @Deprecated(since="0.50.04") public void setProtoCapacity(double bays)
      Deprecated.
      this only sets for ship transport type. Transport Capacities should not be manually updated with this, it should happen inside any loading flows. If you really need to replicate this use setCurrentShipTransportCapacity(CampaignTransportType.SHIP_TRANSPORT, appropriate bay class) - but you probably don't want to do that
      Used to assign a ProtoMek to a bay on a specific transport ship in the TOE
      Parameters:
      bays -
      See Also:
    • loadShipTransport

      public Set<Unit> loadShipTransport(TransporterType transporterType, Set<Unit> units)
      Bay loading utility used when assigning units to bay-equipped transport units For each passed-in unit, this will find the first available, transport bay and set both the target bay and the UUID of the transport ship. Once in the MM lobby, this data will be used to actually load the unit into a bay on the transport.
      Parameters:
      transporterType - type (Enum) of Transporter to transport the units in
      units - Vector of units that we wish to load into this transport
    • unloadFromTransportShip

      public void unloadFromTransportShip(Unit unit)
      Bay unloading utility used when removing units from bay-equipped transport units and/or moving them to a new transport
      Parameters:
      unit - The unit that we wish to unload from this transport
    • getCurrentShipTransportCapacity

      public double getCurrentShipTransportCapacity(TransporterType transporterType)
      Returns the current capacity
      Parameters:
      transporterType - class of Transporter
      Returns:
      capacity
    • hasTacticalTransportAssignment

      public boolean hasTacticalTransportAssignment()
      Gets a value indicating whether this unit is assigned to transport.
      Returns:
      true if this unit has a tacticalTransportAssignment that isn't null
    • getTacticalTransportAssignment

      @Nullable public ITransportAssignment getTacticalTransportAssignment()
      Gets the tactical transport assignment for this unit, or null if this unit is not being transported.
      Returns:
      transport assignment
    • setTacticalTransportAssignment

      public void setTacticalTransportAssignment(@Nullable ITransportAssignment assignment)
      Sets the transport assignment for this unit.
      Parameters:
      assignment - The transport ship assignment, or null if this unit is not being transported.
    • getCurrentTransportCapacity

      public double getCurrentTransportCapacity(CampaignTransportType campaignTransportType, TransporterType transporterType)
      Returns the current capacity
      Parameters:
      campaignTransportType - type (enum) being checked
      transporterType - class of Transporter
      Returns:
      remaining capacity
      See Also:
    • setCurrentShipTransportCapacity

      public void setCurrentShipTransportCapacity(TransporterType transporterType, double capacity)
      Set the transport capacity for the specified transporter type to a specific capacity
      Parameters:
      transporterType - type (Enum) of transporter we want to set the capacity
      capacity - how much this transporter should be able to transport
    • getTransportCapabilities

      public Set<TransporterType> getTransportCapabilities(CampaignTransportType campaignTransportType)
      For the provided campaign transport type (enum), return the transporters this unit
      Parameters:
      campaignTransportType - type (enum) of campaign transport
      Returns:
      set of Transporter types (class)
    • hasTacticalTransportedUnits

      public boolean hasTacticalTransportedUnits()
      Does this unit have any assigned tactical transported units?
      Returns:
      true if the unit is assigned tactical transports
    • unloadTacticalTransport

      public void unloadTacticalTransport(Unit transportedUnit)
      Bay unloading utility used when removing units from bay-equipped transport units and/or moving them to a new transport
      Parameters:
      transportedUnit - The unit that we wish to unload from this transport
    • loadTacticalTransport

      public Set<Unit> loadTacticalTransport(TransporterType transporterType, Set<Unit> units)
      Transporter loading utility used when assigning units to transport units For each passed-in unit, this will assign the unit to the specified bay, or the type of Transporter if one isn't provided. Once in the MM lobby, will be used to actually load the unit into a bay on the transport.
      Parameters:
      transporterType - type (Enum) of bay or Transporter
      units - units being loaded
      Returns:
      the old transports of the units, or an empty set if none
    • towTrailer

      @Nullable public Unit towTrailer(Unit transportedUnit, @Nullable megamek.common.Transporter transportedLocation, TransporterType transporterType)
      Trailer hitching utility used when assigning a trailer to a tractor. It's a bit different from normal loading so it gets its own method. This should be called on the towing unit (or towing entity) - the unit that is specifically pulling the transportedUnit. Do not pass in the tractor that is pulling the entire "train" unless you want the transportedUnit specifically attached to the tractor.
      Parameters:
      transportedUnit - trailer Unit that should be towed
      transportedLocation - specific hitch the trailer should be attached to
      transporterType - type of transporter towing the trailer, should probably be a TANK_TRAILER_HITCH
      Returns:
      original towing unit (Unit) that was pulling the transportedUnit
      See Also:
    • unloadTransport

      public void unloadTransport(CampaignTransportType campaignTransportType)
      Bay unloading utility used when removing a bay-equipped Transport unit This removes all units assigned to the transport from it
    • getBuyCost

      public Money getBuyCost()
    • writeToXML

      public void writeToXML(PrintWriter pw, int indent)
    • generateInstanceFromXML

      public static Unit generateInstanceFromXML(Node wn, megamek.Version version, Campaign campaign)
    • getQuirksList

      @Nullable public String getQuirksList()
      Returns:
      a html-coded list that says what quirks are enabled for this unit
    • getMaintenanceCost

      public Money getMaintenanceCost()
      The weekly maintenance cycle combined with a user defined maintenance cycle length is confusing and difficult to manage so lets just make maintenance costs relative to the length of the maintenance cycle that the user defined
      Returns:
    • getWeeklyMaintenanceCost

      public Money getWeeklyMaintenanceCost()
    • addPart

      public void addPart(Part part)
    • initializeParts

      public void initializeParts(boolean addParts)
      This will check a unit for certain parts and if they are missing, it will create a new version and update its condition. checking for existing parts makes this a more complicated method, but it also ensures that you can call this at any time, and you won't overwrite existing parts
    • getParts

      public List<Part> getParts()
    • findPart

      @Nullable public Part findPart(Predicate<Part> predicate)
      Find a part on a unit.
      Parameters:
      predicate - A predicate to apply to each part on the unit.
      Returns:
      The first part which matched the predicate, otherwise null.
    • setParts

      public void setParts(ArrayList<Part> newParts)
    • getPodSpace

      public List<PodSpace> getPodSpace()
    • refreshPodSpace

      public void refreshPodSpace()
    • getWorkingAmmoBins

      public List<AmmoBin> getWorkingAmmoBins()
    • getCamouflage

      public megamek.common.icons.Camouflage getCamouflage()
    • getUtilizedCamouflage

      public megamek.common.icons.Camouflage getUtilizedCamouflage(Campaign campaign)
    • getImage

      @Nullable public Image getImage(Component component)
    • getImage

      @Nullable public Image getImage(Component component, megamek.common.icons.Camouflage camouflage, boolean showDamage)
    • determineForegroundColor

      public Color determineForegroundColor(String type)
    • determineBackgroundColor

      public Color determineBackgroundColor(String type)
    • getCommander

      @Nullable public Person getCommander()
      Returns the commander of the entity.

      The commander is determined based on the merged list of all crew members, prioritizing certain roles over others. The commander is initialized as the first person in the merged list and then updated by iterating over all crew members and comparing their rank with the current commander. If a crew member outranks the current commander or has the same rank, they are considered as the new commander.

      Returns:
      the commander of the entity, or null if the entity is null or if there are no crew members
    • hasCommander

      public boolean hasCommander()
    • resetPilotAndEntity

      public void resetPilotAndEntity()
    • resetEngineer

      public void resetEngineer()
    • getAeroCrewNeeds

      public int getAeroCrewNeeds()
    • getFullCrewSize

      public int getFullCrewSize()
    • getTotalDriverNeeds

      public int getTotalDriverNeeds()
    • getTotalCrewNeeds

      public int getTotalCrewNeeds()
      Compute the number of generic space/vehicle crew (e.g. not driver, gunner, or navigator)
      Returns:
      The number of generic crew required
    • canTakeMoreDrivers

      public boolean canTakeMoreDrivers()
    • canTakeMoreVesselCrew

      public boolean canTakeMoreVesselCrew()
    • canTakeNavigator

      public boolean canTakeNavigator()
    • canTakeTechOfficer

      public boolean canTakeTechOfficer()
    • canTakeTech

      public boolean canTakeTech()
    • determineUnitTechSkillType

      public String determineUnitTechSkillType()
    • canTakeMoreGunners

      public boolean canTakeMoreGunners()
    • getTotalGunnerNeeds

      public int getTotalGunnerNeeds()
    • usesSoloPilot

      public boolean usesSoloPilot()
    • usesSoldiers

      public boolean usesSoldiers()
    • addDriver

      public void addDriver(Person p)
    • addDriver

      public void addDriver(Person person, boolean useTransfers)
    • addGunner

      public void addGunner(Person p)
    • addGunner

      public void addGunner(Person person, boolean useTransfers)
    • addVesselCrew

      public void addVesselCrew(Person p)
    • addVesselCrew

      public void addVesselCrew(Person person, boolean useTransfers)
    • setNavigator

      public void setNavigator(Person p)
    • setNavigator

      public void setNavigator(Person person, boolean useTransfers)
    • isTechOfficer

      public boolean isTechOfficer(@Nullable Person p)
    • setTechOfficer

      public void setTechOfficer(Person p)
    • setTechOfficer

      public void setTechOfficer(Person person, boolean useTransfers)
    • setTech

      public void setTech(Person p)
    • removeTech

      public void removeTech()
    • addPilotOrSoldier

      public void addPilotOrSoldier(Person person)
    • addPilotOrSoldier

      public void addPilotOrSoldier(Person person, boolean useTransfers)
    • addPilotOrSoldier

      public void addPilotOrSoldier(Person person, @Nullable Unit oldUnit, boolean useTransfers)
    • remove

      public void remove(@Nullable Person person, boolean log)
      Parameters:
      person - the person to remove. If this is null we return immediately without parsing.
      log - whether to log the removal
    • isUnmanned

      public boolean isUnmanned()
    • isUnmannedTrailer

      public boolean isUnmannedTrailer()
      A trailer with no engine or weapons doesn't end any crew.
      Returns:
      true if this Unit is an unmanned trailer, false if it isn't a trailer or has a crew
    • getForceId

      public int getForceId()
    • setForceId

      public void setForceId(int id)
    • getScenarioId

      public int getScenarioId()
    • setScenarioId

      public void setScenarioId(int i)
    • getCrew

      public List<Person> getCrew()
    • clearCrew

      public void clearCrew()
    • getDrivers

      public List<Person> getDrivers()
    • getGunners

      public Set<Person> getGunners()
    • getVesselCrew

      public List<Person> getVesselCrew()
    • getTechOfficer

      @Nullable public Person getTechOfficer()
    • getNavigator

      @Nullable public Person getNavigator()
    • getTech

      @Nullable public Person getTech()
    • isMothballing

      public boolean isMothballing()
      Gets a value indicating whether the unit is being mothballed or activated.
      Returns:
      True if the unit is undergoing mothballing or activation, otherwise false.
    • getMothballTime

      public int getMothballTime()
      Gets the time (in minutes) remaining to mothball or activate the unit.
      Returns:
      The time (in minutes) remaining to mothball or activate the unit.
    • setMothballTime

      public void setMothballTime(int t)
      Sets the time (in minutes) remaining to mothball or activate the unit.
      Parameters:
      t - The time (in minutes) remaining to mothball or activate the unit.
    • isMothballed

      public boolean isMothballed()
      Gets a value indicating whether this unit is mothballed.
      Returns:
      True if the unit is mothballed, otherwise false.
    • setMothballed

      public void setMothballed(boolean b)
      Sets a value indicating whether this unit is mothballed.

      If the unit is being mothballed, all of its personnel will be removed. If the unit is being activated, all of its personnel will be restored (if applicable) and its maintenance cycle will be reset.

      Parameters:
      b - True if the unit is now mothballed, or false if the unit is now activated.
    • startMothballing

      public void startMothballing(Person mothballTech)
      Begins mothballing a unit.
      Parameters:
      mothballTech - The tech performing the mothball.
    • startMothballing

      public void startMothballing(@Nullable Person mothballTech, boolean isGM)
      Begins mothballing a unit, optionally as a GM action.
      Parameters:
      mothballTech - The tech performing the mothball.
      isGM - A value indicating if the mothball action should be performed immediately by the GM.
    • engineerResponsible

      public Optional<Person> engineerResponsible()
      Returns the engineer responsible for the mothballing or activation of this unit.
      Returns:
      Person the previous engineer that worked on this vessel, or an empty object.
    • completeMothball

      public void completeMothball()
      Completes the mothballing of a unit.
    • startActivating

      public void startActivating(Person activationTech)
      Begins activating a unit which has been mothballed.
      Parameters:
      activationTech - The tech performing the activation.
    • startActivating

      public void startActivating(@Nullable Person activationTech, boolean isGM)
      Begins activating a unit which has been mothballed, optionally as a GM action.
      Parameters:
      activationTech - The tech performing the activation.
      isGM - A value indicating if the activation action should be performed immediately by the GM.
    • completeActivation

      public void completeActivation()
      Completes the activation of a unit.
    • cancelMothballOrActivation

      public void cancelMothballOrActivation()
      Cancels a pending mothball or activation work order.
    • getAllInfantry

      public List<Person> getAllInfantry()
      Returns all soldiers or battle armor assigned to the unit. As members of this category appear in both the drivers and gunners list, we only check drivers
    • getActiveCrew

      public List<Person> getActiveCrew()
    • isFullyCrewed

      public boolean isFullyCrewed()
      Returns:
      true if the unit is fully crewed, false otherwise.
    • hasPrototypeTSM

      public boolean hasPrototypeTSM()
      Prototype TSM makes a unit harder to repair and maintain.
      Returns:
      Whether the unit has prototype TSM
    • getMarineCount

      public int getMarineCount()
      Returns a personnel count for each marine platoon/squad assigned to this unit
      Returns:
      The number of marines aboard
    • isDriver

      public boolean isDriver(@Nullable Person person)
    • isGunner

      public boolean isGunner(@Nullable Person person)
    • isCommander

      public boolean isCommander(@Nullable Person person)
      Checks whether a person is considered the commander of this unit.
      Parameters:
      person - A Person in the campaign. The person need not be assigned to the unit as crew, in which case the return value will be false.
      Returns:
      Whether the person is considered the unit commander. If person is null or the unit has no crew, this method will return false
      See Also:
    • isNavigator

      public boolean isNavigator(@Nullable Person person)
    • setRefit

      public void setRefit(Refit r)
    • getRefit

      @Nullable public Refit getRefit()
    • isRefitting

      public boolean isRefitting()
    • getName

      public String getName()
    • getHyperlinkedName

      public String getHyperlinkedName()
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getEngineer

      public Person getEngineer()
    • getPartForEquipmentNum

      @Nullable public Part getPartForEquipmentNum(int index, int loc)
    • getAvailability

      public megamek.common.ITechnology.AvailabilityValue getAvailability(int era)
    • setDaysToArrival

      public void setDaysToArrival(int days)
    • getDaysToArrival

      public int getDaysToArrival()
    • checkArrival

      public boolean checkArrival()
    • isPresent

      public boolean isPresent()
    • getMaintenanceTime

      public int getMaintenanceTime()
      Calculates the maintenance time required for the associated entity, factoring in its type, weight class, and the maintenance multiplier.

      The method determines the time in minutes needed for maintenance based on the specific class of the entity (such as Mek, ProtoMek, BattleArmor, Tank, SmallCraft, etc.) and applies a multiplier for any necessary adjustments. Entity types not specifically handled by this method are considered self-maintaining and return 0.

      Returns:
      the total maintenance time in minutes required per day, or 0 if no maintenance is needed
    • incrementDaysSinceMaintenance

      public void incrementDaysSinceMaintenance(Campaign campaign, boolean maintained, int astechs)
    • resetDaysSinceMaintenance

      public void resetDaysSinceMaintenance()
    • getDaysSinceMaintenance

      public double getDaysSinceMaintenance()
    • getMaintainedPct

      @Deprecated(since="0.50.06", forRemoval=true) public double getMaintainedPct()
      Deprecated, for removal: This API element is subject to removal in a future version.
      no indicated uses.
      there are no official rules about partial maintenance lets say less than half is +2 more than half is +1 penalty also we will take the average rounded down of the number of astechs to figure out shorthanded penalty
    • getAstechsMaintained

      @Deprecated(since="0.50.06", forRemoval=true) public int getAstechsMaintained()
      Deprecated, for removal: This API element is subject to removal in a future version.
      no indicated uses.
    • getMaintenanceMultiplier

      public int getMaintenanceMultiplier()
    • setMaintenanceMultiplier

      public void setMaintenanceMultiplier(int value)
    • getQuality

      public PartQuality getQuality()
    • setQuality

      public void setQuality(PartQuality q)
    • getQualityName

      public String getQualityName()
    • requiresMaintenance

      public boolean requiresMaintenance()
    • isMaintained

      public boolean isMaintained()
      Not always opposite to isUnmaintained() - both are false for units that do not require maintenance.
      Returns:
      true if unit requires maintenance and has a tech assigned, false otherwise.
      See Also:
    • isUnmaintained

      public boolean isUnmaintained()
      Not always opposite to isMaintained() - both are false for units that do not require maintenance.
      Returns:
      true if unit requires maintenance and does not have a tech assigned, false otherwise.
      See Also:
    • isSelfCrewed

      public boolean isSelfCrewed()
    • isUnderRepair

      public boolean isUnderRepair()
    • getLastMaintenanceReport

      public String getLastMaintenanceReport()
    • setLastMaintenanceReport

      public void setLastMaintenanceReport(String r)
    • getDamageState

      public int getDamageState()
    • getDamageState

      public static int getDamageState(megamek.common.Entity en)
    • removeParts

      public void removeParts()
      Removes all the parts from a unit.

      NOTE: this puts the unit in an inconsistent state, and the unit should not be used until its parts have been re-assigned.

    • getFluffName

      public String getFluffName()
      Returns:
      the name
    • setFluffName

      public void setFluffName(String fluffName)
      Parameters:
      fluffName - the name to set
    • isBattleArmorSuitOperable

      public boolean isBattleArmorSuitOperable(int trooper)
      Checks to see if a particular BA suit on BA is currently operable This requires the suit to not be destroyed and to have not missing equipment parts
    • isConventionalInfantry

      public boolean isConventionalInfantry()
      Returns:
      true if the unit is conventional infantry, otherwise false
    • isBattleArmor

      public boolean isBattleArmor()
      Checks if the associated entity is classified as battle armor.

      This method determines whether the entity linked to this object is considered battle armor. It first verifies that the entity is not null, and then checks if the entity meets the criteria for battle armor.

      Returns:
      true if the entity is classified as battle armor and is not null, otherwise false.
    • isIntroducedBy

      public boolean isIntroducedBy(int year)
    • isExtinctIn

      public boolean isExtinctIn(int year)
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • displayMonthlyCost

      public String displayMonthlyCost()
    • getSparePartsCost

      public Money getSparePartsCost()
    • getAmmoCost

      public Money getAmmoCost()
    • getFuelCost

      public Money getFuelCost(int hydrogenProduction)
      Calculates the monthly fuel cost for this unit, applying any available hydrogen production credits.

      Different entity types have different fuel requirements:

      • Large Craft and Small Craft: Calculated based on tons burned per day
      • Conventional Fighters: Use fighter-specific fuel cost calculation
      • Aerospace Fighters: Based on fuel tonnage multiplied by a factor of 4
      • Vehicles and Meks: Use vehicle-specific fuel cost calculation
      • Infantry: Use infantry-specific fuel cost calculation

      Hydrogen produced by fusion engines is credited against the unit's hydrogen usage, reducing the overall fuel cost.

      Parameters:
      hydrogenProduction - The amount of hydrogen produced by fusion engines, which offsets hydrogen usage costs
      Returns:
      The calculated fuel cost as a Money object, always non-negative
    • getTonsBurnMonthCost

      public Money getTonsBurnMonthCost(megamek.common.Entity entity)
      On average, how much does this spaceshift spend burning fuel per month? Based on CO p. 24
      Parameters:
      entity -
      Returns:
      fuel cost for operating this Entity for a month
    • getFighterFuelCost

      public Money getFighterFuelCost(megamek.common.Entity e)
    • getVehicleFuelCost

      public Money getVehicleFuelCost(megamek.common.Entity e)
    • getInfantryFuelCost

      public Money getInfantryFuelCost(megamek.common.Entity e)
    • isClan

      public boolean isClan()
      Specified by:
      isClan in interface megamek.common.ITechnology
    • isMixedTech

      public boolean isMixedTech()
      Specified by:
      isMixedTech in interface megamek.common.ITechnology
    • getTechBase

      public megamek.common.ITechnology.TechBase getTechBase()
      Specified by:
      getTechBase in interface megamek.common.ITechnology
    • getIntroductionDate

      public int getIntroductionDate()
      Specified by:
      getIntroductionDate in interface megamek.common.ITechnology
    • getPrototypeDate

      public int getPrototypeDate()
      Specified by:
      getPrototypeDate in interface megamek.common.ITechnology
    • getProductionDate

      public int getProductionDate()
      Specified by:
      getProductionDate in interface megamek.common.ITechnology
    • getCommonDate

      public int getCommonDate()
      Specified by:
      getCommonDate in interface megamek.common.ITechnology
    • getExtinctionDate

      public int getExtinctionDate()
      Specified by:
      getExtinctionDate in interface megamek.common.ITechnology
    • getReintroductionDate

      public int getReintroductionDate()
      Specified by:
      getReintroductionDate in interface megamek.common.ITechnology
    • getTechRating

      public megamek.common.ITechnology.TechRating getTechRating()
      Specified by:
      getTechRating in interface megamek.common.ITechnology
    • getBaseAvailability

      public megamek.common.ITechnology.AvailabilityValue getBaseAvailability(megamek.common.ITechnology.Era era)
      Specified by:
      getBaseAvailability in interface megamek.common.ITechnology
    • getIntroductionDate

      public int getIntroductionDate(boolean clan, megamek.common.ITechnology.Faction faction)
      Specified by:
      getIntroductionDate in interface megamek.common.ITechnology
    • getPrototypeDate

      public int getPrototypeDate(boolean clan, megamek.common.ITechnology.Faction faction)
      Specified by:
      getPrototypeDate in interface megamek.common.ITechnology
    • getProductionDate

      public int getProductionDate(boolean clan, megamek.common.ITechnology.Faction faction)
      Specified by:
      getProductionDate in interface megamek.common.ITechnology
    • getExtinctionDate

      public int getExtinctionDate(boolean clan, megamek.common.ITechnology.Faction faction)
      Specified by:
      getExtinctionDate in interface megamek.common.ITechnology
    • getReintroductionDate

      public int getReintroductionDate(boolean clan, megamek.common.ITechnology.Faction faction)
      Specified by:
      getReintroductionDate in interface megamek.common.ITechnology
    • getSimpleTechLevel

      public megamek.common.SimpleTechLevel getSimpleTechLevel()
    • getSimpleTechLevel

      public megamek.common.SimpleTechLevel getSimpleTechLevel(int year)
    • getSimpleTechLevel

      public megamek.common.SimpleTechLevel getSimpleTechLevel(int year, boolean clan, megamek.common.ITechnology.Faction faction)
    • getStaticTechLevel

      public megamek.common.SimpleTechLevel getStaticTechLevel()
      Specified by:
      getStaticTechLevel in interface megamek.common.ITechnology
    • calcYearAvailability

      public megamek.common.ITechnology.AvailabilityValue calcYearAvailability(int year, boolean clan, megamek.common.ITechnology.Faction faction)
      Specified by:
      calcYearAvailability in interface megamek.common.ITechnology
    • fixReferences

      public void fixReferences(Campaign campaign)
    • getRandomUnitQuality

      public static PartQuality getRandomUnitQuality(int modifier)
      Generates a random unit quality based on a 2d6 roll and a modifier.
      Parameters:
      modifier - the modifier to be applied to the 2d6 roll
      Returns:
      an integer representing the generated unit quality
      Throws:
      IllegalStateException - if an unexpected value is encountered during the switch statement