return false; }   if ( step.isThisStepBackwards() && entity.elevationOccupied(destHex) != entity.elevationOccupied(srcHex) ) {
    public static boolean isMovementPossible(Game game, int entityId,                                              Coords src, Coords dest,                                             int entityMoveType,                                             int stepType, boolean firstStep) {        final Entity entity = game.getEntity(entityId);        final Hex srcHex = game.board.getHex(src);        final Hex destHex = game.board.getHex(dest);        final boolean isPavementStep = canMoveOnPavement( game, src, dest );                // arguments valid?        if (entity == null) {            throw new IllegalArgumentException("Entity invalid.");        }        if (src.distance(dest) > 1) {            throw new IllegalArgumentException("Coordinates must be adjacent.");        }                if (entityMoveType == Entity.MOVE_ILLEGAL) {            // that was easy            return false;        }        // super-easy        if (entity.isImmobile()) {            return false;        }        // another easy check        if (!game.board.contains(dest)) {            return false;        }        // Swarming entities can't move.        if ( Entity.NONE != entity.getSwarmTargetId() ) {            return false;        }        // The entity is trying to load.  Check for a valid move.        if ( stepType == MovePath.STEP_LOAD ) {            // Transports can't load after the first step.            if ( !firstStep ) {                return false;            }            // Find the unit being loaded.            Entity other = null;            Enumeration entities = game.getEntities( src );            while ( entities.hasMoreElements() ) {                // Is the other unit friendly and not the current entity?                other = (Entity)entities.nextElement();                if ( entity.getOwner() == other.getOwner() &&                     !entity.equals(other) ) {                    // The moving unit should be able to load the other unit.                    if ( !entity.canLoad(other) ) {                        return false;                    }                    // The other unit should be able to have a turn.                    if ( !other.isSelectableThisTurn(game) ) {                        return false;                    }                    // We can stop looking.                    break;                } else {                    // Nope. Discard it.                    other = null;                }            } // Check the next entity in this position.            // We were supposed to find someone to load.            if ( other == null ) {                return false;            }        } // End STEP_LOAD-checks        // mechs dumping ammo can't run        boolean bDumping = false;        for (Enumeration e = entity.getAmmo(); e.hasMoreElements(); ) {            if (((Mounted)e.nextElement()).isDumping()) {                bDumping = true;                break;            }        }        if ( bDumping && ( entityMoveType == Entity.MOVE_RUN ||                           entityMoveType == Entity.MOVE_JUMP ) ) {            return false;        }                // check elevation difference > max        int nSrcEl = entity.elevationOccupied(srcHex);        int nDestEl = entity.elevationOccupied(destHex);        int nMove = entity.getMovementType();                if (entityMoveType != Entity.MOVE_JUMP             && Math.abs(nSrcEl - nDestEl) > entity.getMaxElevationChange()) {            return false;        }        // units moving backwards may not change elevation levels (I think this rule's dumb)        if ((stepType == MovePath.STEP_BACKWARDS || stepType == MovePath.STEP_LATERAL_LEFT_BACKWARDS            || stepType == MovePath.STEP_LATERAL_RIGHT_BACKWARDS) && nSrcEl != nDestEl) {            return false;        }        // Can't run into water unless hovering, or using a bridge.        if (entityMoveType == Entity.MOVE_RUN             && nMove != Entity.MovementType.HOVER            && destHex.levelOf(Terrain.WATER) > 0 &&             !firstStep && !isPavementStep) {            return false;        }                // ugh, stacking checks.  well, maybe we're immune!        if (entityMoveType != Entity.MOVE_JUMP        && stepType != MovePath.STEP_CHARGE        && stepType != MovePath.STEP_DFA) {            // can't move a mech into a hex with an enemy mech            if (entity instanceof Mech && isEnemyMechIn(game, entityId, dest)) {                return false;            }            // Can't move out of a hex with an enemy unit unless we started            // there, BUT we're allowed to turn, unload, or go prone.            if ( isEnemyUnitIn(game, entityId, src) &&                 !src.equals(entity.getPosition()) &&                 stepType != MovePath.STEP_TURN_LEFT &&                 stepType != MovePath.STEP_TURN_RIGHT &&                 stepType != MovePath.STEP_UNLOAD &&                 stepType != MovePath.STEP_GO_PRONE ) {                return false;            }                    }        // can't jump over too-high terrain        if (entityMoveType == Entity.MOVE_JUMP            && destHex.getElevation()                > (entity.getElevation() +                  entity.getJumpMPWithTerrain())) {            return false;        }                // Certain movement types have terrain restrictions; terrain        // restrictions are lifted when moving along a road or bridge.        if (entityMoveType != Entity.MOVE_JUMP            && entity.isHexProhibited(destHex)             && !isPavementStep) {            return false;        }        // If we are *in* restricted terrain, we can only leave via roads.        if ( entityMoveType != Entity.MOVE_JUMP             && entity.isHexProhibited(srcHex)             && !isPavementStep ) {            return false;        }        return true;    }