Class MovePath

java.lang.Object
megamek.common.moves.MovePath
All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
AtmosphericLandingMovePath, BulldozerMovePath

public class MovePath extends Object implements Cloneable, Serializable
Holds movement path for an entity.
See Also:
  • Field Details

    • DEFAULT_PATHFINDER_TIME_LIMIT

      public static final int DEFAULT_PATHFINDER_TIME_LIMIT
      See Also:
  • Constructor Details

    • MovePath

      public MovePath(Game game, Entity entity)
      Generates a new, empty, movement path object.
    • MovePath

      public MovePath(Game game, Entity entity, @Nullable Coords waypoint)
      Generates a new, empty, movement path object.
  • Method Details

    • getGame

      public Game getGame()
    • setGame

      public void setGame(Game game)
    • setEntity

      public void setEntity(Entity entity)
    • hasWaypoint

      public boolean hasWaypoint()
      Checks if there is a waypoint referenced by this MovePath.
      Returns:
      true if there is a waypoint, false otherwise.
    • getWaypoint

      @Nullable public Coords getWaypoint()
      Returns the waypoint referenced by this MovePath.
      Returns:
      the waypoint, or null if there is none.
    • getEntity

      public Entity getEntity()
    • getCachedEntityState

      public CachedEntityState getCachedEntityState()
    • getKey

      public Key getKey()
    • toString

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

      public int length()
      Returns the number of steps in this movement
    • addStep

      public MovePath addStep(MoveStepType type)
      Add a new step to the movement path.
      Parameters:
      type - the type of movement.
    • addStep

      public MovePath addStep(MoveStepType type, Targetable target)
      Add a new step to the movement path with the given target.
      Parameters:
      type - the type of movement.
      target - the Targetable object that is the target of this step. For example, the enemy being charged.
    • addStep

      public MovePath addStep(MoveStepType type, Targetable target, Coords pos)
    • addStep

      public MovePath addStep(MoveStepType type, int additionalIntData)
    • addStep

      public MovePath addStep(MoveStepType type, int recover, int mineToLay)
    • addStep

      public MovePath addStep(MoveStepType type, TreeMap<Integer,Vector<Integer>> targets)
    • addStep

      public MovePath addStep(MoveStepType type, boolean noCost)
    • addStep

      public MovePath addStep(MoveStepType type, Map<Integer,Integer> additionalIntData)
    • addStep

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

      public MovePath addStep(MoveStepType type, Minefield mf)
    • addManeuver

      public void addManeuver(int manType)
    • canShift

      public boolean canShift()
    • containsLateralShift

      public boolean containsLateralShift()
      Returns true if this MovePath contains a lateral shift
    • containsVTOLBomb

      @Deprecated(since="0.51.0", forRemoval=true) public boolean containsVTOLBomb()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • addStep

      public MovePath addStep(MoveStep step)
    • getCoordsSet

      public Set<Coords> getCoordsSet()
    • addStep

      protected MovePath addStep(MoveStep step, boolean compile)
      Initializes a step as part of this movement path. Then adds it to the list.
    • compile

      public void compile(Game g, Entity en)
    • compile

      public void compile(Game g, Entity en, boolean clip)
    • removeLastStep

      public void removeLastStep()
    • clear

      public void clear()
    • isValidPositionForBrace

      public boolean isValidPositionForBrace(MoveStep step)
    • isValidPositionForBrace

      public boolean isValidPositionForBrace(Coords coords, int boardId, int facing)
      Given a set of coordinates and a facing, is the entity taking this path in a valid position to execute a brace?
    • getSteps

      public ListIterator<MoveStep> getSteps()
    • getStep

      @Nullable public MoveStep getStep(int index)
    • contains

      public boolean contains(MoveStepType type)
      Check for any of the specified type of step in the path
      Parameters:
      type - The step type to check for
      Returns:
      Whether this step type is contained within this path
    • fliesOffBoard

      public boolean fliesOffBoard()
      Convenience function to determine whether this path results in the unit explicitly moving off board More relevant for aircraft
      Returns:
      Whether this path will result in the unit moving off board
    • hasActiveMASC

      public boolean hasActiveMASC()
      Check for MASC use
    • hasActiveSupercharger

      public boolean hasActiveSupercharger()
      Check for Supercharger use
    • getFinalCoords

      @Nullable public Coords getFinalCoords()
      Returns:
      the final coordinates if a mek were to perform all the steps in this path, or null if there's an issue with determining the coords
    • getFinalBoardId

      public int getFinalBoardId()
      Returns:
      the board ID of the final position of this move path or the unit's own board ID if the path has no steps.
    • getStartCoords

      @Nullable public Coords getStartCoords()
      Returns the starting Coords of this path.
    • getFinalFacing

      public int getFinalFacing()
      Returns the final facing if a mek were to perform all the steps in this path.
    • getFinalProne

      public boolean getFinalProne()
      Returns whether a unit would end up prone after all the steps
    • getFinalHullDown

      public boolean getFinalHullDown()
      Returns whether a unit would end up hull-down after all the steps
    • getFinalClimbMode

      public boolean getFinalClimbMode()
      Returns whether a unit would be in climb mode after all the steps
    • getFinalElevation

      public int getFinalElevation()
      get final elevation relative to the hex.
    • getMaxElevation

      public int getMaxElevation()
      Returns the highest elevation in the current path
    • isAirborne

      public boolean isAirborne()
      returns if the unit had any altitude above 0 during the movement path
    • getFinalAltitude

      public int getFinalAltitude()
      get final altitude
    • getFinalVelocity

      public int getFinalVelocity()
    • getFinalVelocityLeft

      public int getFinalVelocityLeft()
    • getFinalNDown

      public int getFinalNDown()
    • getFinalConversionMode

      public EntityMovementMode getFinalConversionMode()
      If the path contains mode conversions, this will determine the movement mode at the end of movement. Note that LAMs converting from AirMek to Biped mode require two convert commands.
      Returns:
      The movement mode resulting from any mode conversions in the path.
    • getFinalVectors

      public int[] getFinalVectors()
      Returns the final vector for advanced movement
    • getLastStepMovementType

      public EntityMovementType getLastStepMovementType()
    • getStepVector

      public Vector<MoveStep> getStepVector()
    • getLastStep

      @Nullable public MoveStep getLastStep()
    • getSecondLastStep

      @Nullable public MoveStep getSecondLastStep()
    • printAllSteps

      @Deprecated(since="0.51.0", forRemoval=true) public void printAllSteps()
      Deprecated, for removal: This API element is subject to removal in a future version.
    • clipToPossible

      public void clipToPossible()
      Removes impossible steps.
    • lateralShiftForTurn

      public static MoveStepType lateralShiftForTurn(MoveStepType turn, MoveStepType direction)
      Returns the lateral shift that corresponds to the turn direction
    • getDirection

      public static MoveStepType getDirection(int facing, int destFacing)
      Returns the direction (either MovePath.MoveStepType.TURN_LEFT or MoveStepType.TURN_RIGHT) that the destination facing lies in.
    • getAdjustedFacing

      public static int getAdjustedFacing(int facing, MoveStepType movement)
      Returns the adjusted facing, given the start facing.
    • getMpUsed

      public int getMpUsed()
      Returns the number of MPs used in the path
    • getHexesMoved

      public int getHexesMoved()
      Returns the logical number of hexes moved the path (does not count turns, etc.).
    • getDistanceTravelled

      public int getDistanceTravelled()
      Returns the linear distance between the first and last hexes in the path.
    • isJumping

      public boolean isJumping()
      Returns true if the entity is jumping or if it's a flying lam.
    • isChangingMode

      @Deprecated(since="0.51.0", forRemoval=true) public boolean isChangingMode()
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns:
      true if the entity is a QuadVee or LAM changing movement mode
    • findSimplePathTo

      public void findSimplePathTo(Coords dest, MoveStepType type, int direction, int facing)
      Extend the current path to the destination Coords, moving only in one direction. This method works by applying the supplied move step as long as it moves closer to the destination. If the destination cannot be reached solely by the provided move step, the pathfinder will quit once it gets as closer as it can. Only used for Mek Mechanical Jump Boosters.
      Parameters:
      dest - the destination Coords of the move.
      type - the type of movement step required.
      direction - the direction of movement.
    • findPathTo

      public void findPathTo(Coords dest, MoveStepType type)
      Extend the current path to the destination Coords.
      Parameters:
      dest - the destination Coords of the move.
      type - the type of movement step required.
    • isMoveLegal

      public boolean isMoveLegal()
    • getNextMoves

      public List<MovePath> getNextMoves(boolean backward, boolean forward)
      Returns a list of possible moves that result in a facing/position/(jumping|prone) change, special steps (mine clearing and such) must be handled elsewhere.
    • clone

      public MovePath clone()
      Clones this path, will contain a new clone of the steps so that the clone is independent of the original.
      Overrides:
      clone in class Object
      Returns:
      the cloned MovePath
    • copyFields

      protected void copyFields(MovePath copy)
    • rotatePathfinder

      public void rotatePathfinder(int destFacing, boolean isManeuver, int maneuverType)
      Rotate from the current facing to the destination facing.
    • shouldMechanicalJumpCauseFallDamage

      public boolean shouldMechanicalJumpCauseFallDamage()
      Returns:
      true if a jump using mechanical jump boosters would cause falling damage. Mechanical jump boosters are only designed to handle the stress of falls from a height equal to their jumpMP; if a jump has a fall that is further than the jumpMP of the unit, fall damage applies.
    • getJumpPathHighestPoint

      public Coords getJumpPathHighestPoint()
      Returns the highest elevation along a jump path.
    • getJumpMaxElevationChange

      public int getJumpMaxElevationChange()
      Returns the distance between the highest elevation in the jump path and the elevation at the landing point. This gives the largest distance the unit has fallen during the jump.
    • willCrushBuildings

      public boolean willCrushBuildings()
      Returns:
      TRUE if there are any buildings in a dropship's landing zone.
    • automaticWiGELanding

      public boolean automaticWiGELanding(boolean includeMovePathHexes)
      Airborne WiGEs that move less than five hexes (four for glider protomek) in a movement phase must land unless it has taken off in the same phase, jumped, or it is a LAM or glider ProtoMek that is using hover movement.
      Parameters:
      includeMovePathHexes - Whether to include the hexes plotted in this MovePath in the total distance moved. This should be true when plotting movement in the client and false when the server checks for automatic landing at the end of movement.
      Returns:
      whether the unit is an airborne WiGE that must land at the end of movement.
    • isAllUnderwater

      public boolean isAllUnderwater(Game game)
      Returns:
      Whether the entire path is submerged. A unit is only considered submerged when entirely underwater.
    • getSecondFinalPosition

      public Coords getSecondFinalPosition(Coords startPos)
    • isCareful

      public boolean isCareful()
    • setCareful

      public void setCareful(boolean b)
    • countMp

      public int countMp(boolean jumping)
    • addSteps

      public void addSteps(Vector<MoveStep> path, boolean compile)
    • replaceSteps

      public void replaceSteps(Vector<MoveStep> path)
    • isEndStep

      public boolean isEndStep(MoveStep step)
    • isOnAtmosphericGroundMap

      public boolean isOnAtmosphericGroundMap()
      Convenience method to determine whether this path is happening on a ground map with an atmosphere
    • setVTOLBombStep

      public void setVTOLBombStep(Coords pos)
      Searches the movement path for the first step that has the given position and sets it as a VTOL bombing step. If found, any previous bombing step is cleared. If the coordinates are not part of the path nothing is changed.
      Parameters:
      pos - The Coords of the hex to be bombed.
    • setStrafingStep

      public void setStrafingStep(Coords pos)
      Searches the path for the first MoveStep that matches the given position and sets it as a strafing step. In cases where there are multiple steps with the same coordinates, we want the first one because it is the one that enters the hex. In the rare case where the path crosses itself, select the one closest to the end of the path.

      FIXME: this does not deal with paths that cross themselves

      Parameters:
      pos - The Coords of the hex to be strafed
    • getDroppedUnits

      public Set<Integer> getDroppedUnits()
      Returns:
      A list of entity ids for all units that have previously been plotted to be dropped/launched.
    • nextForwardStepOffBoard

      public boolean nextForwardStepOffBoard()
      Convenience function encapsulating logic for whether, if we continue forward along the current path in the current direction, we will run off the board
    • getEndStepCount

      public int getEndStepCount(MoveStepType stepType)
      Worker function that counts the number of steps of the given type at the end of the given path before another step type occurs.
    • getMaxMP

      public int getMaxMP()
      Returns:
      The maximum MP based on the current movement type of this path, including sprint if available
    • equals

      public boolean equals(Object object)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • setFlightPathHex

      public void setFlightPathHex(BoardLocation flightPathHex)
    • getFlightPathHex

      public BoardLocation getFlightPathHex()