Class InfantryCompartment

java.lang.Object
megamek.common.units.InfantryCompartment
All Implemented Interfaces:
Serializable, Transporter, InfantryTransporter

public final class InfantryCompartment extends Object implements Transporter, InfantryTransporter
Represents a volume of space set aside for carrying troops and their equipment under battle conditions. Typically, a component of an APC.
See Also:
  • Constructor Details

    • InfantryCompartment

      public InfantryCompartment(double space)
      Create a space for the given tonnage of troops. For this class, only the weight of the troops (and their equipment) are considered; if you'd like to think that they are stacked like lumber, be my guest.
      Parameters:
      space - The weight of troops (in tons) this space can carry.
  • Method Details

    • canLoad

      public boolean canLoad(Entity unit)
      Description copied from interface: Transporter
      Determines if this object can accept the given unit. The unit may not be of the appropriate type or there may be no room for the unit.
      Specified by:
      canLoad in interface InfantryTransporter
      Specified by:
      canLoad in interface Transporter
      Parameters:
      unit - - the Entity to be loaded.
      Returns:
      true if the unit can be loaded, false otherwise.
    • load

      public void load(Entity unit) throws IllegalArgumentException
      Load the given unit.
      Specified by:
      load in interface InfantryTransporter
      Specified by:
      load in interface Transporter
      Parameters:
      unit - the Entity to be loaded.
      Throws:
      IllegalArgumentException - If the unit can't be loaded
    • getLoadedUnits

      public Vector<Entity> getLoadedUnits()
      Get a List of the units currently loaded into this payload.
      Specified by:
      getLoadedUnits in interface InfantryTransporter
      Specified by:
      getLoadedUnits in interface Transporter
      Returns:
      A List of loaded Entity units. This list will never be null, but it may be empty. The returned List is independent of the underlying data structure; modifying one does not affect the other.
    • unload

      public boolean unload(Entity unit)
      Unload the given unit.
      Specified by:
      unload in interface Transporter
      Parameters:
      unit - - the Entity to be unloaded.
      Returns:
      true if the unit was contained in this space, false otherwise.
    • getUnusedString

      public String getUnusedString()
      Return a string that identifies the unused capacity of this transporter.
      Specified by:
      getUnusedString in interface Transporter
      Returns:
      A String meant for a human.
    • getUnused

      public double getUnused()
      Specified by:
      getUnused in interface InfantryTransporter
      Specified by:
      getUnused in interface Transporter
      Returns:
      the number of unused spaces in this transporter.
    • isWeaponBlockedAt

      public boolean isWeaponBlockedAt(int loc, boolean isRear)
      Determine if transported units prevent a weapon in the given location from firing.
      Specified by:
      isWeaponBlockedAt in interface Transporter
      Parameters:
      loc - - the int location attempting to fire.
      isRear - - a boolean value stating if the given location is rear facing; if false, the location is front facing.
      Returns:
      true if a transported unit is in the way, false if the weapon can fire.
    • getExteriorUnitAt

      public Entity getExteriorUnitAt(int loc, boolean isRear)
      If a unit is being transported on the outside of the transporter, it can suffer damage when the transporter is hit by an attack. Currently, no more than one unit can be at any single location; that same unit can be "spread" over multiple locations.
      Specified by:
      getExteriorUnitAt in interface Transporter
      Parameters:
      loc - - the int location hit by attack.
      isRear - - a boolean value stating if the given location is rear facing; if false, the location is front facing.
      Returns:
      The Entity being transported on the outside at that location. This value will be null if no unit is transported on the outside at that location.
    • getUnusedSlots

      public double getUnusedSlots()
      Specified by:
      getUnusedSlots in interface InfantryTransporter
      Returns:
      The amount of unused space in the bay expressed in slots. For most bays this is the same as the unused space, but bays for units that can take up a variable amount of space (such as infantry bays) this calculates the number of the default unit size that can fit into the remaining space.
    • getDroppableUnits

      public List<Entity> getDroppableUnits()
      Specified by:
      getDroppableUnits in interface InfantryTransporter
      Returns:
      A (possibly empty) list of units from this bay that can be assault-dropped.
    • spaceForUnit

      public double spaceForUnit(Entity unit)
      Specified by:
      spaceForUnit in interface InfantryTransporter
    • getExternalUnits

      public List<Entity> getExternalUnits()
      Specified by:
      getExternalUnits in interface Transporter
      Returns:
      list of all units carried externally by this transporter
    • getCargoMpReduction

      public int getCargoMpReduction(Entity carrier)
      Specified by:
      getCargoMpReduction in interface Transporter
      Returns:
      the MP reduction due to cargo carried by this transporter
    • toString

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

      public String getTransporterType()
      Specified by:
      getTransporterType in interface InfantryTransporter
      Specified by:
      getTransporterType in interface Transporter
    • setGame

      public void setGame(Game game)
      Specified by:
      setGame in interface Transporter
    • resetTransporter

      public void resetTransporter()
      Description copied from interface: Transporter
      clear out all troops listed in the transporter. Used by MHQ to reset units after game
      Specified by:
      resetTransporter in interface Transporter