Package megamek.common
Class IndustrialElevator
java.lang.Object
megamek.common.IndustrialElevator
- All Implemented Interfaces:
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classRepresents a call to an industrial elevator. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intBit mask for the capacity (in tens of tons) packed into the low byte of the terrain exits fieldstatic final intMultiplier for capacity encoding (capacity stored as capacityTens * 10 = actual tons)static final intBit shift for the shaft-top value within the terrain exits field: exits = (shaftTop << 8) | capacityTens -
Constructor Summary
ConstructorsConstructorDescriptionIndustrialElevator(BoardLocation location, int shaftBottom, int shaftTop, int capacityTons) Creates a new industrial elevator. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a call to the elevator queue.booleanChecks if the elevator can move (not overloaded).voidClears all calls from the queue.intEncodes the elevator data for terrain storage.static IndustrialElevatorfromTerrain(BoardLocation location, int level, int exits) Creates an industrial elevator from terrain data.intintdoublegetCurrentLoad(Game game) Calculates the total tonnage of entities currently on the elevator platform.Gets the next call the elevator should respond to (nearest caller).intintintGets the number of levels in the shaft.intbooleanisEntityOnPlatform(Entity entity) Checks if an entity is currently on the elevator platform.booleanbooleanisPlatformAt(int level) Checks if the platform is currently at the specified level.booleanisWithinShaft(int level) Checks if a given level is within the elevator shaft.intmovePlatformToward(int targetLevel) Moves the platform one level toward the target level.booleanprocessEndPhaseMovement(Game game) Processes the elevator's end phase movement.voidRecalculates distances for all calls based on current platform position.booleanRemoves a call from the queue.voidsetFunctional(boolean functional) voidsetPlatformLevel(int level) booleansyncDisplayLevel(Game game) Rewrites this elevator's hex so the board tileset renders the platform at its current level.toString()
-
Field Details
-
CAPACITY_MULTIPLIER
public static final int CAPACITY_MULTIPLIERMultiplier for capacity encoding (capacity stored as capacityTens * 10 = actual tons)- See Also:
-
SHAFT_TOP_SHIFT
public static final int SHAFT_TOP_SHIFTBit shift for the shaft-top value within the terrain exits field: exits = (shaftTop << 8) | capacityTens- See Also:
-
CAPACITY_MASK
public static final int CAPACITY_MASKBit mask for the capacity (in tens of tons) packed into the low byte of the terrain exits field- See Also:
-
-
Constructor Details
-
IndustrialElevator
Creates a new industrial elevator.- Parameters:
location- The hex location of the elevator shaftshaftBottom- The lowest level the platform can reachshaftTop- The highest level the platform can reachcapacityTons- Maximum cargo capacity in tons
-
-
Method Details
-
fromTerrain
Creates an industrial elevator from terrain data.Terrain encoding (levels relative to the hex surface, see the class doc):
- level = shaft bottom, e.g.
-3for a shaft reaching 3 levels below the surface - exits = (shaftTop << 8) | capacityTens, with shaft top
0meaning the hex surface
- Parameters:
location- The hex locationlevel- 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
- level = shaft bottom, e.g.
-
getLocation
-
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
-
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:
trueif 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:
trueif 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
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
Checks if an entity is currently on the elevator platform.- Parameters:
entity- The entity to check, ornull(never on the platform)- Returns:
trueif the entity is on the platform
-
canMove
Checks if the elevator can move (not overloaded).- Parameters:
game- The game instance- Returns:
trueif current load is within capacity
-
addCall
Adds a call to the elevator queue.- Parameters:
call- The elevator call to add
-
removeCall
Removes a call from the queue.- Parameters:
call- The call to remove- Returns:
trueif the call was found and removed
-
clearCallQueue
public void clearCallQueue()Clears all calls from the queue. -
getNextCall
Gets the next call the elevator should respond to (nearest caller).- Returns:
- The next call, or
nullif 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
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:
trueif the platform moved
-
encodeExits
public int encodeExits()Encodes the elevator data for terrain storage.- Returns:
- The exits value encoding shaft top and capacity
-
syncDisplayLevel
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 examplegameManager.sendChangedHexormarkHexUpdate).- Parameters:
game- the game whose board holds this elevator's hex- Returns:
trueif the displayed level changed and clients need to be notified
-
toString
-