Class MoveStep

java.lang.Object
megamek.common.moves.MoveStep
All Implemented Interfaces:
Serializable

public class MoveStep extends Object implements Serializable
A single step in the entity's movement. Since the path planner uses shallow copies of MovePaths, multiple paths may share the same MoveStep, so this class needs to be agnostic of what path it belongs to.
Since:
Aug 28, 2003
See Also:
  • Field Details

    • CARGO_PICKUP_KEY

      public static final int CARGO_PICKUP_KEY
      When supplying additional int data, use this to key the index of the cargo being picked up
      See Also:
    • CARGO_LOCATION_KEY

      public static final int CARGO_LOCATION_KEY
      When supplying additional int data, use this to key the location of the cargo being picked up (i.e. mek left arm/right arm, vehicle body, etc.)
      See Also:
    • BRIDGE_TARGET_X_KEY

      public static final int BRIDGE_TARGET_X_KEY
      Additional int data keys for a BUILD_BRIDGE step (keys are scoped per step type): the target hex coordinates, the exits bitmask of the two connected hexsides, and the bridge type (light/medium).
      See Also:
    • BRIDGE_TARGET_Y_KEY

      public static final int BRIDGE_TARGET_Y_KEY
      See Also:
    • BRIDGE_EXITS_KEY

      public static final int BRIDGE_EXITS_KEY
      See Also:
    • BRIDGE_TYPE_KEY

      public static final int BRIDGE_TYPE_KEY
      See Also:
  • Constructor Details

    • MoveStep

      public MoveStep(MovePath path, MoveStepType type)
      Create a step of the given type.
      Parameters:
      type - - should match one of the MovePath constants, but this is not currently checked.
    • MoveStep

      public MoveStep(MovePath path, MoveStepType type, Targetable target, Coords pos)
      Create a step with the given target and a position for that target
      Parameters:
      type - - should match one of the MovePath constants, but this is not currently checked.
      target - - the Targetable that is the target of this step. For example, the enemy being charged.
      pos - = the Coords for the target position.
    • MoveStep

      public MoveStep(MovePath path, MoveStepType type, Targetable target)
      Create a step with the given target.
      Parameters:
      type - - should match one of the MovePath constants, but this is not currently checked.
      target - - the Targetable that is the target of this step. For example, the enemy being charged.
    • MoveStep

      public MoveStep(MovePath path, MoveStepType type, int additionalIntData)
      Create a step with the given mine to lay.
      Parameters:
      path - MovePath to work through.
      type - should match one of the MovePath constants, but this is not currently checked.
      additionalIntData - "mineToLay" by default to retain compatibility with existing code "braceLocation" if the move step type is BRACE
    • MoveStep

      public MoveStep(MovePath path, MoveStepType type, Map<Integer,Integer> additionalIntData)
      Creates a step with an arbitrary int-to-int mapping of additional data.
    • MoveStep

      public MoveStep(MovePath path, MoveStepType type, TreeMap<Integer,Vector<Integer>> targets)
      Create a step with the units to launch or drop.
      Parameters:
      path - MovePath to work with.
      type - should match one of the MovePath constants, but this is not currently checked.
      targets - vector of integers identifying the entities to launch
    • MoveStep

      public MoveStep(MovePath path, MoveStepType type, int recovery, int mineToLay)
    • MoveStep

      public MoveStep(MovePath path, MoveStepType type, boolean noCost)
    • MoveStep

      public MoveStep(MovePath path, MoveStepType type, boolean noCost, boolean isManeuver, int maneuverType)
    • MoveStep

      public MoveStep(MovePath path, MoveStepType type, int recovery, int mineToLay, int manType)
    • MoveStep

      public MoveStep(MovePath path, MoveStepType type, Minefield mf)
  • Method Details

    • createChangeBoardMoveStep

      @Deprecated(since="0.51.0", forRemoval=true) public static MoveStep createChangeBoardMoveStep(MovePath path, Coords finalPosition, int finalBoardId)
      Deprecated, for removal: This API element is subject to removal in a future version.
    • isFortifiableTerrain

      public static boolean isFortifiableTerrain(@Nullable Hex hex)
      Determines whether a hex allows digging in or building a fortified hex. Water, pavement, building and road hexes are excluded, as is an already-fortified hex (TO:AR p.106 / TO:AUE p.153). Shared by the move-step legality check and the UI so both agree on the terrain rule.
      Parameters:
      hex - the hex to test, or null
      Returns:
      true if a unit may dig in or fortify in the given hex
    • toString

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

      public MoveStepType getType()
    • setTarget

      public void setTarget(Targetable target)
      Set the target of the current step.
      Parameters:
      target - - the Targetable that is the target of this step. For example, the enemy being charged. If there is no target, pass a null
    • setVTOLBombing

      public void setVTOLBombing(boolean bombing)
      Turns VTOL bombing on or off for this step.
    • setStrafing

      public void setStrafing(boolean strafing)
      Turns VTOL strafing on or off for this step.
    • getTarget

      public Targetable getTarget(Game game)
      Get the target of the current step.
      Parameters:
      game - The current Game
      Returns:
      The Targetable that is the target of this step. For example, the enemy being charged. This value may be null
    • getTargetPosition

      public Coords getTargetPosition()
    • getAdditionalData

      public Integer getAdditionalData(int key)
    • getLaunched

      public TreeMap<Integer,Vector<Integer>> getLaunched()
    • compile

      protected void compile(Game game, Entity entity, MoveStep prev, CachedEntityState cachedEntityState)
      Compile the static move data for this step.
      Parameters:
      game - The current Game
      entity - the Entity taking this step.
      prev - the previous step in the path.
    • setElevation

      protected void setElevation(int el)
    • setAltitude

      protected void setAltitude(int alt)
    • copy

      public void copy(Game game, MoveStep prev)
      Takes the given state as the previous state and sets flags from it.
      Parameters:
      game - The current Game
      prev - Previous MoveStep
    • setFromEntity

      public void setFromEntity(Entity entity, Game game)
      Sets this state as coming from the entity.
      Parameters:
      entity - Set local Entity with passed in one.
    • adjustFacing

      public void adjustFacing(MoveStepType stepType)
      Adjusts facing to comply with the type of step indicated.
      Parameters:
      stepType - MoveStepType Step to adjust facing to.
    • reverseFacing

      public void reverseFacing()
      For yaws, reverse the current facing
    • moveInDir

      public void moveInDir(int dir)
      Parameters:
      dir - Moves the position one hex in the direction indicated. Does not change facing.
    • addDistance

      public void addDistance(int increment)
      Parameters:
      increment - Adds a certain amount to the distance parameter.
    • addMpUsed

      public void addMpUsed(int increment)
      Parameters:
      increment - Adds a certain amount to the mpUsed parameter.
    • isDanger

      public boolean isDanger()
    • getDistance

      public int getDistance()
    • getFacing

      public int getFacing()
    • isFirstStep

      public boolean isFirstStep()
    • isHasJustStood

      public boolean isHasJustStood()
    • isPavementStep

      public boolean isPavementStep()
    • isProne

      public boolean isProne()
    • isFlying

      public boolean isFlying()
    • isHullDown

      public boolean isHullDown()
    • climbMode

      public boolean climbMode()
    • isClimbing

      public boolean isClimbing()
    • setIsClimbing

      public void setIsClimbing(boolean climbing)
    • getClimbingTotalLevels

      public int getClimbingTotalLevels()
      Returns the total remaining levels for this climbing step, used for turn count display.
    • getClimbingChargedLevels

      public int getClimbingChargedLevels()
      Returns the number of climbing levels actually charged this turn (the player's chosen count, capped at the full delta). Differs from getClimbingTotalLevels() when the player picked a partial climb. Used by the turn-count display to compute non-climbing MP correctly without going negative.
    • isTurning

      public boolean isTurning()
    • isUnloaded

      public boolean isUnloaded()
    • isUsingMASC

      public boolean isUsingMASC()
    • isUsingSupercharger

      public boolean isUsingSupercharger()
    • isUsingMekJumpBooster

      public boolean isUsingMekJumpBooster()
    • isEvading

      public boolean isEvading()
    • isSelfDestructing

      public boolean isSelfDestructing()
    • isRolled

      public boolean isRolled()
    • isVTOLBombingStep

      public boolean isVTOLBombingStep()
    • isStrafingStep

      public boolean isStrafingStep()
    • isLegal

      public boolean isLegal(MovePath path)
      Determine if this is a legal step as part of the supplied MovePath.
      Parameters:
      path - A MovePath that contains this step.
      Returns:
      true if the step is legal. false otherwise.
    • getMovementType

      public EntityMovementType getMovementType(boolean isLastStep)
      Return this step's movement type.
      Returns:
      the int constant for this step's movement type.
    • getMovementMode

      public EntityMovementMode getMovementMode()
    • isLegalEndPos

      public boolean isLegalEndPos()
      Check to see if this step's position is a valid end of a path.
      Returns:
      true if this step's position is a legal end of a path. If the step is not legal for an end of a path, then false is returned.
    • setEndPos

      public boolean setEndPos(boolean isEnd)
      Update this step's status as the ending position of a path. See isLegalEndPos(), isEndPos(MovePath), and MovePath.addStep(MoveStep) for additional information.
      Parameters:
      isEnd - the boolean flag that specifies that this step's position is the end of a path.
      Returns:
      true if the path needs to keep updating the steps. false if the update of the path is complete.

    • isEndPos

      public boolean isEndPos(MovePath path)
      A step is in an end position if it is the last legal step, or is an illegal step past the last legal step.
      Parameters:
      path - MovePath to check
      Returns:
      true if a step is considered to be in an end position for the given MovePath.
    • getMpUsed

      public int getMpUsed()
    • isOnlyPavementOrRoad

      public boolean isOnlyPavementOrRoad()
    • getWiGEBonus

      public int getWiGEBonus()
    • getNWigeDescent

      public int getNWigeDescent()
    • isPastDanger

      public boolean isPastDanger()
    • setPastDanger

      public void setPastDanger(boolean pastDanger)
    • isDocking

      public boolean isDocking()
    • setDocking

      public void setDocking(boolean tf)
    • getPosition

      public Coords getPosition()
    • setPosition

      public void setPosition(Coords c)
    • getTargetNumberMASC

      public int getTargetNumberMASC()
    • getTargetNumberSupercharger

      public int getTargetNumberSupercharger()
    • isThisStepBackwards

      public boolean isThisStepBackwards()
    • setDanger

      public void setDanger(boolean b)
    • setDistance

      protected void setDistance(int i)
    • setLeapDistance

      protected void setLeapDistance(int i)
    • setFacing

      protected void setFacing(int i)
    • setFirstStep

      protected void setFirstStep()
    • setHasJustStood

      protected void setHasJustStood(boolean b)
    • setPavementStep

      protected void setPavementStep(boolean b)
    • setProne

      protected void setProne(boolean b)
    • setHullDown

      protected void setHullDown(boolean b)
    • setClimbMode

      protected void setClimbMode(boolean b)
    • setTurning

      protected void setTurning(boolean b)
    • setUnloaded

      protected void setUnloaded(boolean b)
    • setHasEverUnloaded

      @Deprecated(since="0.50.07", forRemoval=true) protected void setHasEverUnloaded(boolean b)
      Deprecated, for removal: This API element is subject to removal in a future version.
      This function is POSSIBLY A HACK!

      DO NOT CALL THIS FUNCTION! I need to find out why this value is being set directly through a couple off functions in the MoveStep compilation process. It should use the setUnloaded(boolean) but I don't know why it does this instead.

      Parameters:
      b - sets hasEverUnloaded to this value
    • setUsingMASC

      protected void setUsingMASC(boolean b)
    • setUsingSupercharger

      protected void setUsingSupercharger(boolean b)
    • setMovementType

      public void setMovementType(EntityMovementType i)
    • setEvading

      protected void setEvading(boolean b)
    • setShuttingDown

      protected void setShuttingDown(boolean b)
    • setStartingUp

      protected void setStartingUp(boolean b)
    • setSelfDestructing

      protected void setSelfDestructing(boolean b)
    • setOnlyPavementOrRoad

      protected void setOnlyPavementOrRoad(boolean b)
    • setTargetNumberMASC

      protected void setTargetNumberMASC(int i)
    • setTargetNumberSupercharger

      protected void setTargetNumberSupercharger(int i)
    • setThisStepBackwards

      protected void setThisStepBackwards(boolean b)
    • getMp

      public int getMp()
      Returns the mp used for just this step.
    • setMp

      protected void setMp(int i)
      sets the mp for this step.
      Parameters:
      i - the mp for this step.
    • setRunProhibited

      protected void setRunProhibited(boolean isRunProhibited)
    • setStackingViolation

      protected void setStackingViolation(boolean isStackingViolation)
    • getHeat

      public int getHeat()
    • calcMovementCostFor

      protected void calcMovementCostFor(Game game, MoveStep prevStep, CachedEntityState cachedEntityState)
      Amount of movement points required to move from start to dest
    • isMovementPossible

      public boolean isMovementPossible(Game game, Coords src, int srcEl, CachedEntityState cachedEntityState)
      Is movement possible from a previous position to this one?

      This function does not comment on whether an overall movement path is possible, just whether the current step is possible.

    • getElevation

      public int getElevation()
    • getClearance

      public int getClearance()
      In hexes with buildings, returns the elevation relative to the roof. Otherwise, returns the elevation relative to the surface.

      Defensive against a deserialized MoveStep whose transient entity reference exists but whose Entity.getGame() hasn't been re-bound on the server. Hit by GameDatasetLogger → SharedUtility.getPSRList while logging a freshly-received path. Falls back to raw elevation when game/hex aren't reachable; the dataset metric is best-effort, not authoritative.

    • getAltitude

      public int getAltitude()
    • getMineToLay

      public int getMineToLay()
    • getEscapePodDistance

      @Deprecated public int getEscapePodDistance()
      Deprecated.
      Use getEscapePodLandingCoords() instead for hex-based selection
      Returns the distance for Combat Vehicle Escape Pod launch (0-4 hexes). Per TO:AUE p.121, the player chooses how far the pod travels behind the vehicle.
    • getEscapePodLandingCoords

      public Coords getEscapePodLandingCoords()
      Returns the landing coordinates for Combat Vehicle Escape Pod launch. Per TO:AUE p.121, the player chooses a hex in the rear arc within 4 hexes.
      Returns:
      The landing coordinates, or null if not set
    • getBraceLocation

      public int getBraceLocation()
    • setBraceLocation

      protected void setBraceLocation(int value)
    • setVelocity

      protected void setVelocity(int vel)
    • getVelocity

      public int getVelocity()
    • setVelocityN

      protected void setVelocityN(int vel)
    • getVelocityN

      public int getVelocityN()
    • setVelocityLeft

      protected void setVelocityLeft(int vel)
    • getVelocityLeft

      public int getVelocityLeft()
    • asfTurnCost

      public int asfTurnCost(Game game, MoveStepType direction, Entity entity)
    • setNTurns

      protected void setNTurns(int turns)
    • getNTurns

      public int getNTurns()
    • setNMoved

      protected void setNMoved(int moved)
    • getNMoved

      public int getNMoved()
    • setNRolls

      protected void setNRolls(int rolls)
    • getNRolls

      public int getNRolls()
    • setOffBoard

      protected void setOffBoard(boolean b)
    • isOffBoard

      public boolean isOffBoard()
    • getVectors

      public int[] getVectors()
    • setVectors

      protected void setVectors(int[] v)
    • hasFreeTurn

      public boolean hasFreeTurn()
    • setFreeTurn

      protected void setFreeTurn(boolean b)
    • getNStraight

      public int getNStraight()
    • setNStraight

      protected void setNStraight(int i)
    • canAeroTurn

      public boolean canAeroTurn(Game game)
      can this aero turn for any reason in atmosphere?
    • dueFreeTurn

      public boolean dueFreeTurn()
    • setNDown

      protected void setNDown(int i)
    • getNDown

      public int getNDown()
    • getRecoveryUnit

      public int getRecoveryUnit()
    • getManeuverType

      public int getManeuverType()
    • hasNoCost

      public boolean hasNoCost()
    • isManeuver

      public boolean isManeuver()
    • isFacingChangeManeuver

      public boolean isFacingChangeManeuver()
      Returns:
      Whether this step is a maneuver that allows a free facing change.
    • getMinefield

      public Minefield getMinefield()
    • getBridgeTargetCoords

      @Nullable public Coords getBridgeTargetCoords()
      Returns:
      The hex a BUILD_BRIDGE step raises its bridge in, from the step's additional data, or null if the step does not carry target coordinates.
    • getBridgeExits

      public int getBridgeExits()
      Returns:
      The exits bitmask of the two hexsides the bridge of a BUILD_BRIDGE step will connect.
    • getBridgeType

      public int getBridgeType()
      Returns:
      The bridge type of a BUILD_BRIDGE step, ConvInfantry.BRIDGE_TYPE_LIGHT or ConvInfantry.BRIDGE_TYPE_MEDIUM.
    • getAdditionalData

      public Map<Integer,Integer> getAdditionalData()
      For serialization purposes
    • useSpheroidAtmosphere

      public boolean useSpheroidAtmosphere(Game game, Entity en)
      Should we treat this movement as if it is occurring for a spheroid unit flying in atmosphere?
    • getCrushedBuildingLocs

      public ArrayList<Coords> getCrushedBuildingLocs()
      Returns:
      An ArrayList of Coords containing buildings within a dropship's landing zone.
    • getEntity

      public Entity getEntity()
    • getGame

      public Game getGame()
    • isJumping

      public boolean isJumping()
    • isCareful

      public boolean isCareful()
    • canUseSprint

      public boolean canUseSprint(Game game)
      Helper function to determine whether sprint is available as a game option to the entity
    • getBoardId

      public int getBoardId()
    • isClimbMode

      public boolean isClimbMode()
      Returns:
      True if this move step is a climb mode change (on or off)