Class ExternalCargo

java.lang.Object
megamek.common.equipment.ExternalCargo
All Implemented Interfaces:
Serializable, Transporter
Direct Known Subclasses:
LiftHoist, MekArms, RoofRack

public abstract class ExternalCargo extends Object implements Transporter
Unprotected cargo transporter. Miscellaneous transporters that don't properly protect their cargo like a bay or infantry compartment, but support cargo unlike clamp mounts or BA Handles.
See Also:
  • Field Details

    • game

      protected transient Game game
    • entity

      protected transient Entity entity
    • entityId

      protected int entityId
    • totalSpace

      protected double totalSpace
      The total amount of space available for objects.
  • Constructor Details

    • ExternalCargo

      protected ExternalCargo(Entity entity)
    • ExternalCargo

      protected ExternalCargo(double tonnage, List<Integer> validPickupLocations)
  • Method Details

    • canLoad

      protected boolean canLoad()
      If this specific transporter is capable of loading regardless of what the object is.
      Returns:
      true if the transporter is capable of loading, false otherwise.
    • canLoad

      public boolean canLoad(Entity unit)
      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 Transporter
      Parameters:
      unit - - the Entity to be loaded.
      Returns:
      true if the unit can be loaded, false otherwise.
    • canLoadCarryable

      public boolean canLoadCarryable(ICarryable carryable)
      Determines if this object can accept the given ICarryable. The carryable may not be of the appropriate type or there may be room for the unit.
      Parameters:
      carryable - the ICarryable to be loaded
      Returns:
      true if the carryable can be loaded, false otherwise.
    • load

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

      public void loadCarryable(ICarryable carryable) throws IllegalArgumentException
      Load the given carryable into the given location
      Parameters:
      carryable - the ICarryable to be loaded
      Throws:
      IllegalArgumentException - If the unit can't be loaded
    • loadCarryable

      public void loadCarryable(ICarryable carryable, int location) throws IllegalArgumentException
      Load the given carryable into the given location
      Parameters:
      carryable - the ICarryable to be loaded
      location - the location it should be loaded into
      Throws:
      IllegalArgumentException - If the unit can't be loaded
    • getLoadedUnits

      public List<Entity> getLoadedUnits()
      Get a Vector of the units currently loaded into this payload.
      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 from the underlying data structure; modifying one does not affect the other.
    • getCarryables

      public List<ICarryable> getCarryables()
      Retrieves a list of all ICarryable objects currently carried by this transporter. If no objects are being carried, the returned list will be empty.

      The returned list is a separate instance and modifying it will not affect the underlying data structure of carried objects.

      Specified by:
      getCarryables in interface Transporter
      Returns:
      a list of ICarryable objects currently carried. Never null, but may be empty.
    • getCarryables

      public List<ICarryable> getCarryables(int location)
      Retrieves a list of ICarryable objects currently carried at the specified location. If no objects are being carried at the given location, the returned list will be empty.

      The returned list is a separate instance and modifying it will not affect the underlying data structure of carried objects.

      Parameters:
      location - the integer value representing the location to check for carried objects
      Returns:
      a list of ICarryable objects at the specified location. The list is never null, but it may be empty.
    • getLocations

      public List<Integer> getLocations()
      Retrieves a list of valid pickup locations for this transporter. The returned list is a new instance and modifying it will not affect the underlying data structure of valid pickup locations.
      Returns:
      a list of integers representing valid pickup locations. The list will never be null, but it may be empty.
    • 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.
    • unloadCarryable

      public boolean unloadCarryable(ICarryable carryable)
    • getUnused

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

      public double getCarriedTonnage()
    • 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.
    • 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 location attempting to fire.
      isRear - true if the weapon is rear-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.
    • 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
    • setGame

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

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

      protected boolean maxObjects(int location)
    • setEntity

      public void setEntity(Entity entity)
      External cargo transporters often need to get information about the entity, like if its TSM is active. If this transporter doesn't have an entity, let's set it. Tries to set entityId as well but the entity might not have that if the entity doesn't have a game yet.
      Specified by:
      setEntity in interface Transporter
      Parameters:
      entity - the entity to associate with this transporter