megamek.common
Class MovePath

java.lang.Object
  extended by megamek.common.MovePath
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable
Direct Known Subclasses:
MoveOption

public class MovePath
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

Holds movement path for an entity.

See Also:
Serialized Form

Nested Class Summary
static class MovePath.Key
           
protected static class MovePath.MovePathComparator
           
static class MovePath.MoveStepType
           
 
Field Summary
static int DEFAULT_PATHFINDER_TIME_LIMIT
           
protected  Entity entity
           
protected  IGame game
           
protected  java.util.Vector<MoveStep> steps
           
 
Constructor Summary
MovePath(IGame game, Entity entity)
          Generates a new, empty, movement path object.
 
Method Summary
 MovePath addManeuver(int manType)
           
 MovePath addStep(MovePath.MoveStepType type)
          Add a new step to the movement path.
 MovePath addStep(MovePath.MoveStepType type, boolean noCost)
           
 MovePath addStep(MovePath.MoveStepType type, boolean noCost, boolean isManeuver)
           
 MovePath addStep(MovePath.MoveStepType type, int mineToLay)
           
 MovePath addStep(MovePath.MoveStepType type, int recover, int mineToLay)
           
 MovePath addStep(MovePath.MoveStepType type, Minefield mf)
           
 MovePath addStep(MovePath.MoveStepType type, Targetable target)
          Add a new step to the movement path with the given target.
 MovePath addStep(MovePath.MoveStepType type, java.util.TreeMap<java.lang.Integer,java.util.Vector<java.lang.Integer>> targets)
           
protected  MovePath addStep(MoveStep step)
          Initializes a step as part of this movement path.
 boolean canShift()
           
 void clear()
           
 void clipToPossible()
          Removes impossible steps.
 MovePath clone()
          Clones this path, will contain a new clone of the steps so that the clone is independent from the original.
 void compile(IGame g, Entity en)
           
 boolean contains(MovePath.MoveStepType type)
          Check for any of the specified type of step in the path
 void findPathTo(Coords dest, MovePath.MoveStepType type)
          Extend the current path to the destination Coords.
static int getAdjustedFacing(int facing, MovePath.MoveStepType movement)
          Returns the adjusted facing, given the start facing.
static MovePath.MoveStepType getDirection(int facing, int destFacing)
          Returns the direction (either MovePath.MoveStepType.TURN_LEFT or MoveStepType.TURN_RIGHT) that the destination facing lies in.
 Entity getEntity()
           
 int getFinalAltitude()
          get final altitude
 boolean getFinalClimbMode()
          Returns whether or not a unit would be in climb mode after all the steps
 Coords getFinalCoords()
          Returns the final coordinates if a mech were to perform all the steps in this path.
 int getFinalElevation()
          get final elevation relative to the hex.
 int getFinalFacing()
          Returns the final facing if a mech were to perform all the steps in this path.
 boolean getFinalHullDown()
          Returns whether or not a unit would end up prone after all of the steps
 int getFinalNDown()
           
 boolean getFinalProne()
          Returns whether or not a unit would end up prone after all of the steps
 int[] getFinalVectors()
          Returns the final vector for advanced movement
 int getFinalVelocity()
           
 int getHexesMoved()
          Returns the logical number of hexes moved the path (does not count turns, etc).
 MovePath.Key getKey()
           
 MoveStep getLastStep()
           
 EntityMovementType getLastStepMovementType()
           
 int getMpUsed()
          Returns the number of MPs used in the path
 java.util.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.
 Coords getSecondFinalPosition(Coords startPos)
           
 MoveStep getSecondLastStep()
           
 MoveStep getStep(int index)
           
 java.util.Enumeration<MoveStep> getSteps()
           
 boolean hasActiveMASC()
          Check for MASC use
 boolean isCareful()
           
 boolean isFlying()
          Returns if the entity is flying at the last step of this movepath.
 boolean isJumping()
          Returns true if the entity is jumping or if it's a flying lam.
 boolean isMoveLegal()
           
static MovePath.MoveStepType lateralShiftForTurn(MovePath.MoveStepType turn, MovePath.MoveStepType direction)
          Returns the lateral shift that corresponds to the turn direction
 int length()
          Returns the number of steps in this movement
 void printAllSteps()
           
 void removeLastStep()
           
 void rotatePathfinder(int destFacing, boolean isManeuver)
          Rotate from the current facing to the destination facing.
 void setCareful(boolean b)
           
 java.lang.String toString()
           
(package private) static MovePath.MoveStepType turnForLateralShift(MovePath.MoveStepType shift)
          Returns the turn direction that corresponds to the lateral shift
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

steps

protected java.util.Vector<MoveStep> steps

game

protected transient IGame game

entity

protected transient Entity entity

DEFAULT_PATHFINDER_TIME_LIMIT

public static final int DEFAULT_PATHFINDER_TIME_LIMIT
See Also:
Constant Field Values
Constructor Detail

MovePath

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

Method Detail

getEntity

public Entity getEntity()

getKey

public MovePath.Key getKey()

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

length

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


addStep

public MovePath addStep(MovePath.MoveStepType type)
Add a new step to the movement path.

Parameters:
type - the type of movement.

addStep

public MovePath addStep(MovePath.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(MovePath.MoveStepType type,
                        int mineToLay)

addStep

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

addStep

public MovePath addStep(MovePath.MoveStepType type,
                        java.util.TreeMap<java.lang.Integer,java.util.Vector<java.lang.Integer>> targets)

addStep

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

addStep

public MovePath addStep(MovePath.MoveStepType type,
                        boolean noCost,
                        boolean isManeuver)

addStep

public MovePath addStep(MovePath.MoveStepType type,
                        Minefield mf)

addManeuver

public MovePath addManeuver(int manType)

canShift

public boolean canShift()

addStep

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

Parameters:
step -

compile

public void compile(IGame g,
                    Entity en)

removeLastStep

public void removeLastStep()

clear

public void clear()

getSteps

public java.util.Enumeration<MoveStep> getSteps()

getStep

public MoveStep getStep(int index)

contains

public boolean contains(MovePath.MoveStepType type)
Check for any of the specified type of step in the path


hasActiveMASC

public boolean hasActiveMASC()
Check for MASC use


getFinalCoords

public Coords getFinalCoords()
Returns the final coordinates if a mech were to perform all the steps in this path.


getFinalFacing

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


getFinalProne

public boolean getFinalProne()
Returns whether or not a unit would end up prone after all of the steps


getFinalHullDown

public boolean getFinalHullDown()
Returns whether or not a unit would end up prone after all of the steps


getFinalClimbMode

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


getFinalElevation

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


getFinalAltitude

public int getFinalAltitude()
get final altitude


getFinalVelocity

public int getFinalVelocity()

getFinalNDown

public int getFinalNDown()

getFinalVectors

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


getLastStepMovementType

public EntityMovementType getLastStepMovementType()

getLastStep

public MoveStep getLastStep()

getSecondLastStep

public MoveStep getSecondLastStep()

printAllSteps

public void printAllSteps()

clipToPossible

public void clipToPossible()
Removes impossible steps.


lateralShiftForTurn

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


turnForLateralShift

static MovePath.MoveStepType turnForLateralShift(MovePath.MoveStepType shift)
Returns the turn direction that corresponds to the lateral shift


getDirection

public static MovePath.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,
                                    MovePath.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).


isJumping

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


isFlying

public boolean isFlying()
Returns if the entity is flying at the last step of this movepath. WARNING: This function will only evaluate the path of LandAirMechs, for all other types it will return false.

Returns:
true if it's a flying LAM.

findPathTo

public void findPathTo(Coords dest,
                       MovePath.MoveStepType type)
Extend the current path to the destination Coords.

Parameters:
dest - the destination Coords of the move.
type - the type of movment step required.

isMoveLegal

public boolean isMoveLegal()

getNextMoves

public java.util.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 from the original.

Overrides:
clone in class java.lang.Object
Returns:
the cloned MovePath

rotatePathfinder

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


getSecondFinalPosition

public Coords getSecondFinalPosition(Coords startPos)

isCareful

public boolean isCareful()

setCareful

public void setCareful(boolean b)