Class IndustrialElevator

java.lang.Object
megamek.common.IndustrialElevator
All Implemented Interfaces:
Serializable

public class IndustrialElevator extends Object implements Serializable
Represents a player-controlled industrial elevator within a building.

Industrial elevators have a cargo capacity, a shaft spanning multiple levels, and a platform that moves 1 level per turn. Players can call the elevator during the End Phase, and units can ride it during the Movement Phase.

All shaft and platform levels are relative to the hex surface, matching Entity.getElevation(): level 0 is the hex surface, negative levels are below it (basement shaft), positive levels are above it (building floors). The same terrain encoding therefore works on a hex of any board level.

Key rules:

  • Maximum cargo capacity - elevator won't move if exceeded
  • Platform moves 1 level per turn toward the nearest caller
  • Movement costs 1 Walking/Cruising MP per level
  • Only Walking/Cruising movement allowed (no running/jumping)
  • Elevator disabled if any shaft level is breached/flooded/collapsed
  • Entering shaft without platform causes fall
See Also:
  • Field Details

    • CAPACITY_MULTIPLIER

      public static final int CAPACITY_MULTIPLIER
      Multiplier for capacity encoding (capacity stored as capacityTens * 10 = actual tons)
      See Also:
    • SHAFT_TOP_SHIFT

      public static final int SHAFT_TOP_SHIFT
      Bit shift for the shaft-top value within the terrain exits field: exits = (shaftTop << 8) | capacityTens
      See Also:
    • CAPACITY_MASK

      public static final int CAPACITY_MASK
      Bit mask for the capacity (in tens of tons) packed into the low byte of the terrain exits field
      See Also:
  • Constructor Details

    • IndustrialElevator

      public IndustrialElevator(BoardLocation location, int shaftBottom, int shaftTop, int capacityTons)
      Creates a new industrial elevator.
      Parameters:
      location - The hex location of the elevator shaft
      shaftBottom - The lowest level the platform can reach
      shaftTop - The highest level the platform can reach
      capacityTons - Maximum cargo capacity in tons
  • Method Details

    • fromTerrain

      public static IndustrialElevator fromTerrain(BoardLocation location, int level, int exits)
      Creates an industrial elevator from terrain data.

      Terrain encoding (levels relative to the hex surface, see the class doc):

      • level = shaft bottom, e.g. -3 for a shaft reaching 3 levels below the surface
      • exits = (shaftTop << 8) | capacityTens, with shaft top 0 meaning the hex surface
      Parameters:
      location - The hex location
      level - The terrain level (shaft bottom, relative to the hex surface)
      exits - The terrain exits field (encoded shaft top and capacity)
      Returns:
      A new IndustrialElevator instance
    • getLocation

      public BoardLocation getLocation()
    • getCoords

      public Coords getCoords()
    • getBoardId

      public int getBoardId()
    • getShaftBottom

      public int getShaftBottom()
    • getShaftTop

      public int getShaftTop()
    • getCapacityTons

      public int getCapacityTons()
    • getPlatformLevel

      public int getPlatformLevel()
    • isFunctional

      public boolean isFunctional()
    • getCallQueue

      public List<IndustrialElevator.ElevatorCall> getCallQueue()
    • setPlatformLevel

      public void setPlatformLevel(int level)
    • setFunctional

      public void setFunctional(boolean functional)
    • isPlatformAt

      public boolean isPlatformAt(int level)
      Checks if the platform is currently at the specified level.
      Parameters:
      level - The level to check
      Returns:
      true if the platform is at this level
    • isWithinShaft

      public boolean isWithinShaft(int level)
      Checks if a given level is within the elevator shaft.
      Parameters:
      level - The level to check
      Returns:
      true if the level is within the shaft range
    • getShaftHeight

      public int getShaftHeight()
      Gets the number of levels in the shaft.
      Returns:
      The shaft height in levels
    • getCurrentLoad

      public double getCurrentLoad(Game game)
      Calculates the total tonnage of entities currently on the elevator platform.
      Parameters:
      game - The game instance to query for entities
      Returns:
      The total tonnage of entities on the platform
    • isEntityOnPlatform

      public boolean isEntityOnPlatform(@Nullable Entity entity)
      Checks if an entity is currently on the elevator platform.
      Parameters:
      entity - The entity to check, or null (never on the platform)
      Returns:
      true if the entity is on the platform
    • canMove

      public boolean canMove(Game game)
      Checks if the elevator can move (not overloaded).
      Parameters:
      game - The game instance
      Returns:
      true if current load is within capacity
    • addCall

      public void addCall(IndustrialElevator.ElevatorCall call)
      Adds a call to the elevator queue.
      Parameters:
      call - The elevator call to add
    • removeCall

      public boolean removeCall(IndustrialElevator.ElevatorCall call)
      Removes a call from the queue.
      Parameters:
      call - The call to remove
      Returns:
      true if the call was found and removed
    • clearCallQueue

      public void clearCallQueue()
      Clears all calls from the queue.
    • getNextCall

      @Nullable public IndustrialElevator.ElevatorCall getNextCall()
      Gets the next call the elevator should respond to (nearest caller).
      Returns:
      The next call, or null if queue is empty
    • recalculateCallDistances

      public void recalculateCallDistances()
      Recalculates distances for all calls based on current platform position. Should be called after the platform moves.
    • movePlatformToward

      public int movePlatformToward(int targetLevel)
      Moves the platform one level toward the target level.
      Parameters:
      targetLevel - The level to move toward
      Returns:
      The new platform level after moving
    • processEndPhaseMovement

      public boolean processEndPhaseMovement(Game game)
      Processes the elevator's end phase movement. Moves the platform 1 level toward the nearest caller if any.
      Parameters:
      game - The game instance (for capacity checking)
      Returns:
      true if the platform moved
    • encodeExits

      public int encodeExits()
      Encodes the elevator data for terrain storage.
      Returns:
      The exits value encoding shaft top and capacity
    • syncDisplayLevel

      public boolean syncDisplayLevel(Game game)
      Rewrites this elevator's hex so the board tileset renders the platform at its current level. After initialization the shaft geometry is held in this object, so the terrain's level field is free to carry the platform position for display. Callers must notify clients of the hex change (for example gameManager.sendChangedHex or markHexUpdate).
      Parameters:
      game - the game whose board holds this elevator's hex
      Returns:
      true if the displayed level changed and clients need to be notified
    • toString

      public String toString()
      Overrides:
      toString in class Object