entity.setPosition(curPos); if (doDislodgeSwarmerSkillCheck(entity, rollTarget, curPos)) {  curFacing = entity.getFacing(); curPos = entity.getPosition(); fellDuringMovement = true; break; }  entity.setProne(true);  checkForWashedInfernos(entity, curPos); break;
    private void processMovement(Entity entity, MovePath md) {        Report r;        boolean sideslipped = false; // for VTOL sideslipping        // check for fleeing        if (md.contains(MovePath.STEP_FLEE)) {            // Unit has fled the battlefield.            r = new Report(2005, Report.PUBLIC);            r.addDesc(entity);            addReport(r);            Coords pos = entity.getPosition();            int fleeDirection;            if (pos.x == 0) {                fleeDirection = IOffBoardDirections.WEST;            } else if (pos.y == 0) {                fleeDirection = IOffBoardDirections.SOUTH;            } else if (pos.x == game.getBoard().getWidth()) {                fleeDirection = IOffBoardDirections.EAST;            } else {                fleeDirection = IOffBoardDirections.NORTH;            }            // Is the unit carrying passengers?            final Vector passengers = entity.getLoadedUnits();            if ( !passengers.isEmpty() ) {                final Enumeration iter = passengers.elements();                while ( iter.hasMoreElements() ) {                    final Entity passenger = (Entity) iter.nextElement();                    // Unit has fled the battlefield.                    r = new Report(2010, Report.PUBLIC);                    r.indent();                    r.addDesc(passenger);                    addReport(r);                    passenger.setRetreatedDirection(fleeDirection);                    game.removeEntity( passenger.getId(),                            IEntityRemovalConditions.REMOVE_IN_RETREAT );                    send( createRemoveEntityPacket(passenger.getId(),                            IEntityRemovalConditions.REMOVE_IN_RETREAT) );                }            }            // Handle any picked up MechWarriors            Enumeration iter = entity.getPickedUpMechWarriors().elements();            while (iter.hasMoreElements() ) {                Integer mechWarriorId = (Integer)iter.nextElement();                Entity mw = game.getEntity(mechWarriorId.intValue());                // Is the MechWarrior an enemy?                int condition = IEntityRemovalConditions.REMOVE_IN_RETREAT;                r = new Report(2010);                if (mw.isCaptured()) {                    r = new Report(2015);                    condition = IEntityRemovalConditions.REMOVE_CAPTURED;                } else {                    mw.setRetreatedDirection(fleeDirection);                }                game.removeEntity( mw.getId(), condition );                send( createRemoveEntityPacket(mw.getId(), condition) );                r.addDesc(mw);                r.indent();                addReport(r);            }            // Is the unit being swarmed?            final int swarmerId = entity.getSwarmAttackerId();            if ( Entity.NONE != swarmerId ) {                final Entity swarmer = game.getEntity( swarmerId );                // Has the swarmer taken a turn?                if ( !swarmer.isDone() ) {                    // Dead entities don't take turns.                    game.removeTurnFor(swarmer);                    send(createTurnVectorPacket());                } // End swarmer-still-to-move                // Unit has fled the battlefield.                swarmer.setSwarmTargetId( Entity.NONE );                entity.setSwarmAttackerId( Entity.NONE );                r = new Report(2015, Report.PUBLIC);                r.indent();                r.addDesc(swarmer);                addReport(r);                game.removeEntity( swarmerId, IEntityRemovalConditions.REMOVE_CAPTURED );                send( createRemoveEntityPacket(swarmerId,                        IEntityRemovalConditions.REMOVE_CAPTURED) );            }            entity.setRetreatedDirection(fleeDirection);            game.removeEntity( entity.getId(), IEntityRemovalConditions.REMOVE_IN_RETREAT );            send( createRemoveEntityPacket(entity.getId(),                    IEntityRemovalConditions.REMOVE_IN_RETREAT) );            return;        }        if (md.contains(MovePath.STEP_EJECT)) {            if (entity instanceof Mech) {                r = new Report(2020);                r.subject = entity.getId();                r.add(entity.getCrew().getName());                r.addDesc(entity);                addReport(r);            } else if (entity instanceof Tank) {                r = new Report(2025);                r.subject = entity.getId();                r.addDesc(entity);                addReport(r);            }            addReport( ejectEntity(entity, false));            return;        }        // okay, proceed with movement calculations        Coords lastPos = entity.getPosition();        Coords curPos = entity.getPosition();        int curFacing = entity.getFacing();        int curVTOLElevation = entity.getElevation();        // if the entity already used some MPs,        // it previously tried to get up and fell,        // and then got another turn. set moveType        // and overallMoveType accordingly        // (these are all cleared by Entity.newRound)        int distance = entity.delta_distance;        int mpUsed = entity.mpUsed;        int moveType = entity.moved;        int overallMoveType = entity.moved;;        boolean firstStep;        boolean wasProne;        boolean fellDuringMovement = false;        boolean turnOver;        int prevFacing = curFacing;        IHex prevHex = null;        final boolean isInfantry = entity instanceof Infantry;        AttackAction charge = null;        PilotingRollData rollTarget;        // cache this here, otherwise changing MP in the turn causes        // errorneous gravity PSRs        int cachedGravityLimit = IEntityMovementType.MOVE_JUMP == moveType?            entity.getOriginalJumpMP() : entity.getRunMP(false);        // Compile the move        md.compile(game, entity);        if (md.contains(MovePath.STEP_CLEAR_MINEFIELD)) {            ClearMinefieldAction cma = new ClearMinefieldAction(entity.getId());            entity.setClearingMinefield(true);            game.addAction(cma);        }        overallMoveType = md.getLastStepMovementType();        //check for starting in liquid magma        if(game.getBoard().getHex(entity.getPosition()).terrainLevel(Terrains.MAGMA) == 2            && entity.getElevation() == 0) {            doMagmaDamage(entity, false);        }        // iterate through steps        firstStep = true;        turnOver = false;        /* Bug 754610: Revert fix for bug 702735. */        MoveStep prevStep = null;        Vector movePath = new Vector();        for (final Enumeration i = md.getSteps(); i.hasMoreElements();) {            final MoveStep step = (MoveStep)i.nextElement();            wasProne = entity.isProne();            boolean isPavementStep = step.isPavementStep();            boolean entityFellWhileAttemptingToStand = false;            // stop for illegal movement            if (step.getMovementType() == IEntityMovementType.MOVE_ILLEGAL) {                break;            }            //stop if the entity already killed itself            if(entity.isDestroyed() || entity.isDoomed()) {                break;            }            // check for MASC failure on first step            if (firstStep && entity instanceof Mech) {                Vector crits = new Vector();                Vector vReport = new Vector();                if (((Mech)entity).checkForMASCFailure(md, vReport, crits)) {                    addReport(vReport);                    CriticalSlot cs = null;                    int loc = Entity.LOC_NONE;                    for(Enumeration e = crits.elements();e.hasMoreElements();) {                        Object o = e.nextElement();                        if(o instanceof Integer)                            loc = (Integer) o;                        else if (o instanceof CriticalSlot) {                            cs = (CriticalSlot) o;                            addReport(applyCriticalHit(entity, loc, cs, true));                        }                    }                    //do any PSR immediately                    resolvePilotingRolls(entity);                    game.resetPSRs(entity);                    // let the player replot their move as MP might be changed                    md.clear();                    fellDuringMovement = true; // so they get a new turn                    break;                }            }            // check piloting skill for getting up            rollTarget = entity.checkGetUp(step);            if (rollTarget.getValue() != TargetRoll.CHECK_FALSE) {                entity.heatBuildup += 1;                entity.setProne(false);                entity.setHullDown(false);                wasProne = false;                game.resetPSRs(entity);                entityFellWhileAttemptingToStand = !doSkillCheckInPlace(entity, rollTarget);            }            // did the entity just fall?            if (entityFellWhileAttemptingToStand) {                moveType = step.getMovementType();                curFacing = entity.getFacing();                curPos = entity.getPosition();                mpUsed = step.getMpUsed();                fellDuringMovement = true;                break;            }            if (step.getType() == MovePath.STEP_UNJAM_RAC) {                entity.setUnjammingRAC(true);                game.addAction(new UnjamAction(entity.getId()));                break;            }            if (step.getType() == MovePath.STEP_LAY_MINE) {                LayMinefieldAction lma = new LayMinefieldAction(entity.getId(), step.getMineToLay());                game.addLayMinefieldAction(lma);                entity.setLayingMines(true);                break;            }            if (step.getType() == MovePath.STEP_SEARCHLIGHT && entity.hasSpotlight()) {                final boolean SearchOn = !entity.isUsingSpotlight();                entity.setSpotlightState(SearchOn);                sendServerChat(entity.getDisplayName() + " switched searchlight "+(SearchOn?"on":"off")+'.');            }            // set most step parameters            moveType = step.getMovementType();            distance = step.getDistance();            mpUsed = step.getMpUsed();            // check for charge            if (step.getType() == MovePath.STEP_CHARGE) {                if (entity.canCharge()) {                    checkExtremeGravityMovement(entity, step, curPos, cachedGravityLimit);                    Targetable target = step.getTarget( game );                    ChargeAttackAction caa = new ChargeAttackAction(entity.getId(), target.getTargetType(), target.getTargetId(), target.getPosition());                    entity.setDisplacementAttack(caa);                    game.addCharge(caa);                    charge = caa;                } else {                    sendServerChat("Illegal charge!! I don't think "+entity.getDisplayName() +" should be allowed to charge,"+                                   " but the client of "+entity.getOwner().getName()+" disagrees.");                    sendServerChat("Please make sure "+entity.getOwner().getName()+" is running MegaMek "+MegaMek.VERSION+                                   ", or if that is already the case, submit a bug report at http://megamek.sf.net/");                    return;                }                break;            }            // check for dfa            if (step.getType() == MovePath.STEP_DFA) {                if (entity.canDFA()) {                    checkExtremeGravityMovement(entity, step, curPos, cachedGravityLimit);                    Targetable target = step.getTarget( game );                    DfaAttackAction daa = new DfaAttackAction(entity.getId(), target.getTargetType(), target.getTargetId(), target.getPosition());                    entity.setDisplacementAttack(daa);                    game.addCharge(daa);                    charge = daa;                } else {                    sendServerChat("Illegal DFA!! I don't think "+entity.getDisplayName() +" should be allowed to DFA,"+                                   " but the client of "+entity.getOwner().getName()+" disagrees.");                    sendServerChat("Please make sure "+entity.getOwner().getName()+" is running MegaMek "+MegaMek.VERSION+                                   ", or if that is already the case, submit a bug report at http://megamek.sf.net/");                    return;                }                break;            }                        //check for dig in or fortify            if(entity instanceof Infantry) {                Infantry inf = (Infantry)entity;                if(step.getType() == MovePath.STEP_DIG_IN) {                    inf.setDugIn(Infantry.DUG_IN_WORKING);                    continue;                }                else if(step.getType() == MovePath.STEP_FORTIFY) {                    if(!entity.hasWorkingMisc(MiscType.F_TOOLS, MiscType.S_VIBROSHOVEL)) {                        sendServerChat(entity.getDisplayName() + " failed to fortify because it is missing suitable equipment");                    }                    inf.setDugIn(Infantry.DUG_IN_FORTIFYING1);                    continue;                }                else if(step.getType() != MovePath.STEP_TURN_LEFT &&                        step.getType() != MovePath.STEP_TURN_RIGHT) {                    //other movement clears dug in status                    inf.setDugIn(Infantry.DUG_IN_NONE);                }            }            // set last step parameters            curPos = step.getPosition();            if(moveType != IEntityMovementType.MOVE_JUMP || entity.getJumpType() != Mech.JUMP_BOOSTER)                curFacing = step.getFacing();            //check if a building PSR will be needed later, before setting the new elevation            int buildingMove = entity.checkMovementInBuilding(step, prevStep, curPos, lastPos);            curVTOLElevation = step.getElevation();            //set elevation in case of collapses            entity.setElevation(step.getElevation());            IHex curHex = game.getBoard().getHex(curPos);            // check for automatic unstick            if(entity.canUnstickByJumping() && entity.isStuck() && moveType == IEntityMovementType.MOVE_JUMP) {                entity.setStuck(false);                entity.setCanUnstickByJumping(false);            }                        // Check for skid.            rollTarget = entity.checkSkid(moveType, prevHex, overallMoveType,                                          prevStep, prevFacing, curFacing,                                          lastPos, curPos, isInfantry,                                          distance);            if (rollTarget.getValue() != TargetRoll.CHECK_FALSE) {                // Have an entity-meaningful PSR message.                boolean psrFailed = true;                if ( entity instanceof Mech ) {                    psrFailed = (0 < doSkillCheckWhileMoving( entity, lastPos,                                                          lastPos, rollTarget,                                                          true ));                } else {                    psrFailed = (0 < doSkillCheckWhileMoving( entity, lastPos,                                                          lastPos, rollTarget,                                                          false ));                }                // Does the entity skid?                if ( psrFailed ){                                        if(entity instanceof Tank) {                        addReport(vehicleMotiveDamage((Tank)entity, 0));                    }                    curPos = lastPos;                    int skidDistance = (distance + 1) / 2;                    int skidDirection = prevFacing;                    // All charge damage is based upon                    // the pre-skid move distance.                    entity.delta_distance = distance-1;                    // Attacks against a skidding target have additional +2.                    moveType = IEntityMovementType.MOVE_SKID;                    // What is the first hex in the skid?                    if(step.isThisStepBackwards()) {                        skidDirection = (skidDirection + 3) % 6;                    }                                        if(processSkid(entity, curPos, step.getElevation(), skidDirection, skidDistance, step))                        return;                    // set entity parameters                    curFacing = entity.getFacing();                    curPos = entity.getPosition();                    entity.setSecondaryFacing( curFacing );                    // skid consumes all movement                    if (md.hasActiveMASC()) {                        mpUsed = entity.getRunMP();                    } else {                        mpUsed = entity.getRunMPwithoutMASC();                    }                    entity.moved = moveType;                    fellDuringMovement = true;                    turnOver = true;                    distance = entity.delta_distance;                    break;                } // End failed-skid-psr            } // End need-skid-psr                        // check sideslip            if(entity instanceof VTOL                    || entity.getMovementMode() == IEntityMovementMode.HOVER                    || entity.getMovementMode() == IEntityMovementMode.WIGE) {                rollTarget = entity.checkSideSlip(moveType, prevHex, overallMoveType,                                          prevStep, prevFacing, curFacing,                                          lastPos, curPos,                                          distance);                if(rollTarget.getValue() != TargetRoll.CHECK_FALSE) {                    int MoF = doSkillCheckWhileMoving(entity,lastPos,curPos,rollTarget, false);                     if(MoF > 0) {                        //maximum distance is hexes moved / 2                        int sideslipDistance = Math.min(MoF, distance-1);                        if(sideslipDistance > 0) {                            int skidDirection = prevFacing;                            //report sideslip                            sideslipped = true;                            r = new Report(2100);                            r.subject = entity.getId();                            r.addDesc(entity);                            r.add(sideslipDistance);                            addReport(r);                                                        if(processSkid(entity, lastPos, step.getElevation(), skidDirection, sideslipDistance, step))                                return;                                                        if(!entity.isDestroyed() && !entity.isDoomed()) {                                fellDuringMovement= true; //No, but it should work...                            }                                                        if(entity.getElevation() == 0 && (entity.getMovementMode() == IEntityMovementMode.VTOL ||                                    entity.getMovementMode() == IEntityMovementMode.WIGE)) {                                turnOver = true;                            }                            // set entity parameters                            curFacing = entity.getFacing();                            curPos = entity.getPosition();                            entity.setSecondaryFacing( curFacing );                            break;                        }                    }                }            }            // check if we've moved into rubble            rollTarget = entity.checkRubbleMove(step, curHex, lastPos, curPos);            if (rollTarget.getValue() != TargetRoll.CHECK_FALSE) {                doSkillCheckWhileMoving(entity, lastPos, curPos, rollTarget,                                         true);            }            //check for breaking magma crust            if(curHex.terrainLevel(Terrains.MAGMA) == 1                && step.getElevation() == 0                && step.getMovementType() != IEntityMovementType.MOVE_JUMP) {                int roll = Compute.d6(1);                r = new Report(2395);                r.addDesc(entity);                r.add(roll);                r.subject = entity.getId();                addReport(r);                if(roll == 6) {                    curHex.removeTerrain(Terrains.MAGMA);                    curHex.addTerrain(Terrains.getTerrainFactory().createTerrain(Terrains.MAGMA, 2));                    sendChangedHex(curPos);                    for(Enumeration e=game.getEntities(curPos);e.hasMoreElements();) {                        Entity en = (Entity)e.nextElement();                        if(en != entity)                            doMagmaDamage(en, false);                    }                }            }            //check for entering liquid magma            if(curHex.terrainLevel(Terrains.MAGMA) == 2                && step.getElevation() == 0                && step.getMovementType() != IEntityMovementType.MOVE_JUMP) {                doMagmaDamage(entity, false);            }            // check if we've moved into a swamp            rollTarget = entity.checkSwampMove(step, curHex, lastPos, curPos, isPavementStep);            if (rollTarget.getValue() != TargetRoll.CHECK_FALSE) {                if (0<doSkillCheckWhileMoving(entity, lastPos, curPos, rollTarget,                                         false)){                    entity.setStuck(true);                    entity.setCanUnstickByJumping(true);                    r = new Report(2081);                    r.add(entity.getDisplayName());                    r.subject = entity.getId();                    addReport(r);                    break;                }            }            // check to see if we are a mech and we've moved OUT of fire            IHex lastHex = game.getBoard().getHex(lastPos);            if (entity instanceof Mech) {                if ( !lastPos.equals(curPos)                    && prevStep != null                    && ((lastHex.containsTerrain(Terrains.FIRE) && prevStep.getElevation() <=1)                            || (lastHex.containsTerrain(Terrains.MAGMA) && prevStep.getElevation() == 0))                    && ( step.getMovementType() != IEntityMovementType.MOVE_JUMP                         // Bug #828741 -- jumping bypasses fire, but not on the first step                         //   getMpUsed -- total MP used to this step                         //   getMp -- MP used in this step                         //   the difference will always be 0 on the "first step" of a jump,                         //   and >0 on a step in the midst of a jump                         || 0 == step.getMpUsed() - step.getMp() ) )                {                    int heat=0;                    if(lastHex.containsTerrain(Terrains.FIRE))                        heat+=2;                    if(lastHex.terrainLevel(Terrains.MAGMA) == 1) {                        heat+=2;                    }                    else if(lastHex.terrainLevel(Terrains.MAGMA) == 2) {                        heat+=5;                    }                    entity.heatFromExternal+=heat;                    r = new Report(2115);                    r.subject = entity.getId();                    r.addDesc(entity);                    r.add(heat);                    addReport(r);                }            }            // check to see if we are not a mech and we've moved INTO fire            if (!(entity instanceof Mech)) {                if ( game.getBoard().getHex(curPos).containsTerrain(Terrains.FIRE)                    && !lastPos.equals(curPos)                    && step.getMovementType() != IEntityMovementType.MOVE_JUMP                    && step.getElevation() <= 1 ) {                    if(game.getOptions().booleanOption("vehicle_fires")                            && entity instanceof Tank) {                        checkForVehicleFire((Tank)entity, false);                    } else {                        doFlamingDeath(entity);                    }                }            }            // check for extreme gravity movement            if (!i.hasMoreElements() && !firstStep) {                checkExtremeGravityMovement(entity, step, curPos, cachedGravityLimit);            }            // check for minefields.            if (!lastPos.equals(curPos) && step.getMovementType() != IEntityMovementType.MOVE_JUMP                || overallMoveType == IEntityMovementType.MOVE_JUMP && !i.hasMoreElements()) {                checkVibrabombs(entity, curPos, false, lastPos, curPos);                if (game.containsMinefield(curPos)) {                    Enumeration minefields = game.getMinefields(curPos).elements();                    while (minefields.hasMoreElements()) {                        Minefield mf = (Minefield) minefields.nextElement();                        boolean isOnGround = !i.hasMoreElements();                        isOnGround |= step.getMovementType() != IEntityMovementType.MOVE_JUMP;                        isOnGround &= step.getElevation() == 0;                        // set the new position temporarily, because                        // infantry otherwise would get double damage                        // when moving from clear into mined woods                        entity.setPosition(curPos);                        if (isOnGround) {                            enterMinefield(entity, mf, curPos, curPos, true);                        } else if (mf.getType() == Minefield.TYPE_THUNDER_ACTIVE) {                            enterMinefield(entity, mf, curPos, curPos, true, 2);                        }                        // set original position again.                        entity.setPosition(lastPos);                    }                }            }            // infantry discovers minefields if they end their move            // in a minefield.            if (!lastPos.equals(curPos) &&                !i.hasMoreElements() &&                isInfantry) {                if (game.containsMinefield(curPos)) {                    Player owner = entity.getOwner();                    Enumeration minefields = game.getMinefields(curPos).elements();                    while (minefields.hasMoreElements()) {                        Minefield mf = (Minefield) minefields.nextElement();                        if (!owner.containsMinefield(mf)) {                            r = new Report(2120);                            r.subject = entity.getId();                            r.add(entity.getShortName(), true);                            addReport(r);                            revealMinefield(owner, mf);                        }                    }                }            }            // check if we've moved into water            rollTarget = entity.checkWaterMove(step, curHex, lastPos, curPos, isPavementStep);            if (rollTarget.getValue() != TargetRoll.CHECK_FALSE) {                // Swarmers need special handling.                final int swarmerId = entity.getSwarmAttackerId();                boolean swarmerDone = true;                Entity swarmer = null;                if (Entity.NONE != swarmerId) {                    swarmer = game.getEntity( swarmerId );                    swarmerDone = swarmer.isDone();                }                // Now do the skill check.                doSkillCheckWhileMoving(entity, lastPos, curPos, rollTarget,                                         true);                // Swarming infantry platoons may drown.                if (curHex.terrainLevel(Terrains.WATER) > 1) {                    drownSwarmer(entity, curPos);                }                // Do we need to remove a game turn for the swarmer                if (!swarmerDone &&                    ( swarmer.isDoomed() || swarmer.isDestroyed() )) {                    // We have to diddle with the swarmer's                    // status to get its turn removed.                    swarmer.setDone( false );                    swarmer.setUnloaded( false );                    // Dead entities don't take turns.                    game.removeTurnFor( swarmer );                    send( createTurnVectorPacket() );                    // Return the original status.                    swarmer.setDone( true );                    swarmer.setUnloaded( true );                }                // check for inferno wash-off                checkForWashedInfernos(entity, curPos);            }            // In water, may or may not be a new hex, neccessary to            // check during movement, for breach damage, and always            // set dry if appropriate            //TODO: possibly make the locations local and set later            doSetLocationsExposure(entity, curHex,                    step.getMovementType() == IEntityMovementType.MOVE_JUMP,                    step.getElevation());            //check for breaking ice by breaking through from below            if(prevHex != null && prevStep != null                    && prevStep.getElevation() < 0                    && step.getElevation() == 0                    && prevHex.containsTerrain(Terrains.ICE)                    && prevHex.containsTerrain(Terrains.WATER)                    && step.getMovementType() != IEntityMovementType.MOVE_JUMP                    && !lastPos.equals(curPos)) {                r = new Report(2410);                r.addDesc(entity);                addReport(r);                resolveIceBroken(lastPos);            }            //check for breaking ice by stepping on it            if(curHex.containsTerrain(Terrains.ICE)                    && curHex.containsTerrain(Terrains.WATER)                    && step.getMovementType() != IEntityMovementType.MOVE_JUMP                    && !lastPos.equals(curPos)) {                if(step.getElevation() == 0                        ) {                    int roll = Compute.d6(1);                    r = new Report(2118);                    r.addDesc(entity);                    r.add(roll);                    r.subject = entity.getId();                    addReport(r);                    if(roll == 6) {                        resolveIceBroken(curPos);                        doEntityFallsInto(entity, lastPos, curPos, entity.getBasePilotingRoll(), false);                    }                }                //or intersecting it                else if(step.getElevation() + entity.height() == 0) {                    r = new Report(2410);                    r.addDesc(entity);                    addReport(r);                    resolveIceBroken(curPos);                }            }            // Handle loading units.            if ( step.getType() == MovePath.STEP_LOAD ) {                // Find the unit being loaded.                Entity loaded = null;                Enumeration entities = game.getEntities( curPos );                while ( entities.hasMoreElements() ) {                    // Is the other unit friendly and not the current entity?                    loaded = (Entity)entities.nextElement();                    if ( !entity.isEnemyOf(loaded) &&                         !entity.equals(loaded) ) {                        // The moving unit should be able to load the other                        // unit and the other should be able to have a turn.                        if ( !entity.canLoad(loaded) ||                             !loaded.isLoadableThisTurn() ) {                            // Something is fishy in Denmark.                            System.err.println( entity.getShortName() +                                                " can not load " +                                                loaded.getShortName() );                            loaded = null;                        }                        else {                            // Have the deployed unit load the indicated unit.                            loadUnit( entity, loaded );                            // Stop looking.                            break;                        }                    } else {                        // Nope. Discard it.                        loaded = null;                    }                } // Handle the next entity in this hex.                // We were supposed to find someone to load.                if ( loaded == null ) {                    System.err.println( "Could not find unit for " +                                        entity.getShortName() +                                        " to load in " + curPos );                }            } // End STEP_LOAD            // Handle unloading units.            if ( step.getType() == MovePath.STEP_UNLOAD ) {                Targetable unloaded = step.getTarget( game );                if ( !unloadUnit( entity, unloaded,                                       curPos, curFacing, step.getElevation() ) ) {                    System.err.println( "Error! Server was told to unload " +                                        unloaded.getDisplayName() +                                        " from " + entity.getDisplayName() +                                        " into " + curPos.getBoardNum() );                }            }            // Handle non-infantry moving into a building.            if (buildingMove > 0) {                // Get the building being exited.                Building bldgExited = null;                if((buildingMove & 1) == 1)                    bldgExited = game.getBoard().getBuildingAt( lastPos );                // Get the building being entered.                Building bldgEntered = null;                if((buildingMove & 2) == 2)                    bldgEntered = game.getBoard().getBuildingAt( curPos );                // Get the building being stepped on.                Building bldgStepped = null;                if((buildingMove & 4) == 4)                    bldgStepped = game.getBoard().getBuildingAt( curPos );                boolean collapsed = false;                //are we passing through a building wall?                if(bldgEntered != null || bldgExited != null) {                    // If we're not leaving a building, just handle the "entered".                    if ( bldgExited == null) {                        collapsed = passBuildingWall( entity, bldgEntered,                                                      lastPos, curPos,                                                      distance, "entering" );                        addAffectedBldg( bldgEntered, collapsed );                    }                    // If we're moving withing the same building, just handle                    // the "within".                    else if ( bldgExited.equals( bldgEntered ) ) {                        collapsed = passBuildingWall( entity, bldgEntered,                                                      lastPos, curPos,                                                      distance, "moving in" );                        addAffectedBldg( bldgEntered, collapsed );                    }                    // If we have different buildings, roll for each.                    else if ( bldgExited != null && bldgEntered != null ) {                        collapsed = passBuildingWall( entity, bldgExited,                                                      lastPos, curPos,                                                      distance, "exiting" );                        addAffectedBldg( bldgExited, collapsed );                        collapsed = passBuildingWall( entity, bldgEntered,                                                      lastPos, curPos,                                                      distance, "entering" );                        addAffectedBldg( bldgEntered, collapsed );                    }                    // Otherwise, just handle the "exited".                    else if (bldgExited != null){                        collapsed = passBuildingWall( entity, bldgExited,                                                      lastPos, curPos,                                                      distance, "exiting" );                        addAffectedBldg( bldgExited, collapsed );                    }                }                //stepping on roof, no PSR just check for over weight                if(bldgStepped != null) {                    collapsed = checkBuildingCollapseWhileMoving(bldgStepped, entity, curPos);                    addAffectedBldg( bldgStepped, collapsed );                }                // Clean up the entity if it has been destroyed.                if ( entity.isDoomed() ) {                    entity.setDestroyed(true);                    game.moveToGraveyard(entity.getId());                    send(createRemoveEntityPacket(entity.getId()));                    // The entity's movement is completed.                    return;                }                // TODO: what if a building collapses into rubble?            }            // did the entity just fall?            if (!wasProne && entity.isProne()) {                curFacing = entity.getFacing();                curPos = entity.getPosition();                mpUsed = step.getMpUsed();                fellDuringMovement = true;                break;            }            // dropping prone intentionally?            if (step.getType() == MovePath.STEP_GO_PRONE) {                mpUsed = step.getMpUsed();                rollTarget = entity.checkDislodgeSwarmers(step);                if (rollTarget.getValue() == TargetRoll.CHECK_FALSE) {                    // Not being swarmed                    entity.setProne(true);                    // check to see if we washed off infernos                    checkForWashedInfernos(entity, curPos);                    break;                }				// Being swarmed				entity.setPosition(curPos);				if (doDislodgeSwarmerSkillCheck(entity,				                                rollTarget,				                                curPos)) {				    // Entity falls				    curFacing = entity.getFacing();				    curPos = entity.getPosition();				    fellDuringMovement = true;				    break;				}				// roll failed, go prone but don't dislodge swarmers				entity.setProne(true);				// check to see if we washed off infernos				checkForWashedInfernos(entity, curPos);				break;            }            //going hull down            if(step.getType() == MovePath.STEP_HULL_DOWN) {                mpUsed = step.getMpUsed();                entity.setHullDown(true);            }            // Track this step's location.            movePath.addElement( new UnitLocation( entity.getId(),                                                   curPos,                                                   curFacing ) );            // update lastPos, prevStep, prevFacing & prevHex            lastPos = new Coords(curPos);            prevStep = step;            /* Bug 754610: Revert fix for bug 702735.            if (prevHex != null && !curHex.equals(prevHex)) {            */            if (!curHex.equals(prevHex)) {                prevFacing = curFacing;            }            prevHex = curHex;            firstStep = false;        }        // set entity parameters        entity.setPosition(curPos);        entity.setFacing(curFacing);        entity.setSecondaryFacing(curFacing);        entity.delta_distance = distance;        entity.moved = moveType;        entity.mpUsed = mpUsed;        if (!sideslipped && !fellDuringMovement) {            entity.setElevation(curVTOLElevation);        }        entity.setClimbMode(md.getFinalClimbMode());        // if we ran with destroyed hip or gyro, we need a psr        rollTarget = entity.checkRunningWithDamage(overallMoveType);        if (rollTarget.getValue() != TargetRoll.CHECK_FALSE) {            doSkillCheckInPlace(entity, rollTarget);        }        // If the entity is being swarmed, erratic movement may dislodge the fleas.        final int swarmerId = entity.getSwarmAttackerId();        if ( Entity.NONE != swarmerId && md.contains(MovePath.STEP_SHAKE_OFF_SWARMERS)) {            final Entity swarmer = game.getEntity( swarmerId );            final PilotingRollData roll =                entity.getBasePilotingRoll();            entity.addPilotingModifierForTerrain(roll);            // Add a +4 modifier.            if(md.getLastStepMovementType() == IEntityMovementType.MOVE_VTOL_RUN)                roll.addModifier( 2, "dislodge swarming infantry with VTOL movement" );            else                roll.addModifier( 4, "dislodge swarming infantry" );            // If the swarmer has Assault claws, give a 1 modifier.            // We can stop looking when we find our first match.            for (Mounted mount : swarmer.getMisc()) {                EquipmentType equip = mount.getType();                if ( BattleArmor.ASSAULT_CLAW.equals                     (equip.getInternalName()) ) {                    roll.addModifier( 1, "swarmer has assault claws" );                    break;                }                if ( equip.hasFlag(MiscType.F_MAGNETIC_CLAMP)) {                    roll.addModifier( 1, "swarmer has magnetic claw");                    break;                }            }            // okay, print the info            r = new Report(2125);            r.subject = entity.getId();            r.addDesc(entity);            addReport(r);            // roll            final int diceRoll = Compute.d6(2);            r = new Report(2130);            r.subject = entity.getId();            r.add(roll.getValueAsString());            r.add(roll.getDesc());            r.add(diceRoll);            if (diceRoll < roll.getValue()) {                r.choose(false);                addReport(r);            } else {                // Dislodged swarmers don't get turns.                game.removeTurnFor( swarmer );                send( createTurnVectorPacket() );                // Update the report and the swarmer's status.                r.choose(true);                addReport(r);                entity.setSwarmAttackerId( Entity.NONE );                swarmer.setSwarmTargetId( Entity.NONE );                                IHex curHex = game.getBoard().getHex(curPos);                // Did the infantry fall into water?                if ( curHex.terrainLevel(Terrains.WATER) > 0 ) {                    // Swarming infantry die.                    swarmer.setPosition( curPos );                    r = new Report(2135);                    r.subject = entity.getId();                    r.indent();                    r.addDesc(swarmer);                    addReport(r);                    addReport(                        destroyEntity(swarmer, "a watery grave", false));                } else {                    // Swarming infantry take a 3d6 point hit.                    // ASSUMPTION : damage should not be doubled.                    r = new Report(2140);                    r.subject = entity.getId();                    r.indent();                    r.addDesc(swarmer);                    r.add("3d6");                    addReport(r);                    addReport(damageEntity(swarmer, swarmer.rollHitLocation(ToHitData.HIT_NORMAL, ToHitData.SIDE_FRONT), Compute.d6(3)));                    addNewLines();                    swarmer.setPosition( curPos );                }                entityUpdate( swarmerId );            } // End successful-PSR        } // End try-to-dislodge-swarmers        // but the danger isn't over yet!  landing from a jump can be risky!        if (overallMoveType == IEntityMovementType.MOVE_JUMP && !entity.isMakingDfa()) {            final IHex curHex = game.getBoard().getHex(curPos);            // check for damaged criticals            rollTarget = entity.checkLandingWithDamage();            if (rollTarget.getValue() != TargetRoll.CHECK_FALSE) {                doSkillCheckInPlace(entity, rollTarget);            }            // jumped into water?            int waterLevel = curHex.terrainLevel(Terrains.WATER);            if(curHex.containsTerrain(Terrains.ICE) && waterLevel > 0) {                waterLevel = 0;                //check for breaking ice                int roll = Compute.d6(1);                r = new Report(2122);                r.add(entity.getDisplayName(), true);                r.add(roll);                r.subject = entity.getId();                addReport(r);                if(roll >= 4) {                    //oops!                    resolveIceBroken(curPos);                    doEntityFallsInto(entity, lastPos, curPos, entity.getBasePilotingRoll(), false);                }            }            rollTarget = entity.checkWaterMove(waterLevel);            if (rollTarget.getValue() != TargetRoll.CHECK_FALSE) {                doSkillCheckInPlace(entity, rollTarget);            }            if (waterLevel > 1) {                // Any swarming infantry will be destroyed.                drownSwarmer(entity, curPos);            }            //check for building collapse            Building bldg = game.getBoard().getBuildingAt(curPos);            if(bldg != null) {                checkForCollapse( bldg, game.getPositionMap() );            }            //check for breaking magma crust            if(curHex.terrainLevel(Terrains.MAGMA) == 1) {                int roll = Compute.d6(1);                r = new Report(2395);                r.addDesc(entity);                r.add(roll);                r.subject = entity.getId();                addReport(r);                if(roll == 6) {                    curHex.removeTerrain(Terrains.MAGMA);                    curHex.addTerrain(Terrains.getTerrainFactory().createTerrain(Terrains.MAGMA, 2));                    sendChangedHex(curPos);                    for(Enumeration e=game.getEntities(curPos);e.hasMoreElements();) {                        Entity en = (Entity)e.nextElement();                        if(en != entity)                            doMagmaDamage(en, false);                    }                }            }            //check for entering liquid magma            if(curHex.terrainLevel(Terrains.MAGMA) == 2) {                doMagmaDamage(entity, false);            }            // jumped into swamp? maybe stuck!            if (curHex.containsTerrain(Terrains.SWAMP)                || curHex.containsTerrain(Terrains.MAGMA)                || curHex.containsTerrain(Terrains.SNOW)                || curHex.containsTerrain(Terrains.MUD)                || curHex.containsTerrain(Terrains.TUNDRA)) {                if (entity instanceof Mech) {                    entity.setStuck(true);                    r = new Report(2121);                    r.add(entity.getDisplayName(), true);                    r.subject = entity.getId();                    addReport(r);                } else if (entity instanceof Infantry) {                    PilotingRollData roll = entity.getBasePilotingRoll();                    roll.addModifier(5, "infantry jumping into swamp");                    if (0<doSkillCheckWhileMoving(entity, curPos, curPos, roll, false)) {                        entity.setStuck(true);                        r = new Report(2081);                        r.add(entity.getDisplayName());                        r.subject = entity.getId();                        addReport(r);                    }                }            }            // If the entity is being swarmed, jumping may dislodge the fleas.            if ( Entity.NONE != swarmerId ) {                final Entity swarmer = game.getEntity( swarmerId );                final PilotingRollData roll =                    entity.getBasePilotingRoll();                entity.addPilotingModifierForTerrain(roll);                // Add a +4 modifier.                roll.addModifier( 4, "dislodge swarming infantry" );                // If the swarmer has Assault claws, give a 1 modifier.                // We can stop looking when we find our first match.                for (Mounted mount : swarmer.getMisc()) {                    EquipmentType equip = mount.getType();                    if ( BattleArmor.ASSAULT_CLAW.equals                         (equip.getInternalName()) ) {                        roll.addModifier( 1, "swarmer has assault claws" );                        break;                    }                    if ( equip.hasFlag(MiscType.F_MAGNETIC_CLAMP)) {                        roll.addModifier( 1, "swarmer has magnetic claw");                        break;                    }                }                // okay, print the info                r = new Report(2125);                r.subject = entity.getId();                r.addDesc(entity);                addReport(r);                // roll                final int diceRoll = Compute.d6(2);                r = new Report(2130);                r.subject = entity.getId();                r.add(roll.getValueAsString());                r.add(roll.getDesc());                r.add(diceRoll);                if (diceRoll < roll.getValue()) {                    r.choose(false);                    addReport(r);                } else {                    // Dislodged swarmers don't get turns.                    game.removeTurnFor( swarmer );                    send( createTurnVectorPacket() );                    // Update the report and the swarmer's status.                    r.choose(true);                    addReport(r);                    entity.setSwarmAttackerId( Entity.NONE );                    swarmer.setSwarmTargetId( Entity.NONE );                    // Did the infantry fall into water?                    if ( curHex.terrainLevel(Terrains.WATER) > 0 ) {                        // Swarming infantry die.                        swarmer.setPosition( curPos );                        r = new Report(2135);                        r.subject = entity.getId();                        r.indent();                        r.addDesc(swarmer);                        addReport(r);                        addReport(                            destroyEntity(swarmer, "a watery grave", false));                    } else {                        // Swarming infantry take a 3d6 point hit.                        // ASSUMPTION : damage should not be doubled.                        r = new Report(2140);                        r.subject = entity.getId();                        r.indent();                        r.addDesc(swarmer);                        r.add("3d6");                        addReport(r);                        addReport(damageEntity(swarmer, swarmer.rollHitLocation(ToHitData.HIT_NORMAL, ToHitData.SIDE_FRONT), Compute.d6(3)));                        addNewLines();                        swarmer.setPosition( curPos );                    }                    entityUpdate( swarmerId );                } // End successful-PSR            } // End try-to-dislodge-swarmers            // one more check for inferno wash-off            checkForWashedInfernos(entity, curPos);        } // End entity-is-jumping        // update entity's locations' exposure        doSetLocationsExposure(entity, game.getBoard().getHex(curPos), false, entity.getElevation());        // should we give another turn to the entity to keep moving?        if (!game.getOptions().booleanOption("falls_end_movement") // Not if this option is set        && fellDuringMovement && !turnOver && entity.mpUsed < entity.getRunMP()        && entity.isSelectableThisTurn() && !entity.isDoomed()) {            entity.applyDamage();            entity.setDone(false);            GameTurn newTurn = new GameTurn.SpecificEntityTurn(entity.getOwner().getId(), entity.getId());            game.insertNextTurn(newTurn);            // brief everybody on the turn update            send(createTurnVectorPacket());            // let everyone know about what just happened            send(entity.getOwner().getId(), createSpecialReportPacket());        } else {            entity.setDone(true);        }        // If the entity is being swarmed, update the attacker's position.        if ( Entity.NONE != swarmerId ) {            final Entity swarmer = game.getEntity( swarmerId );            swarmer.setPosition( curPos );            // If the hex is on fire, and the swarming infantry is            // *not* Battle Armor, it drops off.            if ( !(swarmer instanceof BattleArmor) &&                 game.getBoard().getHex(curPos).containsTerrain(Terrains.FIRE) ) {                swarmer.setSwarmTargetId( Entity.NONE );                entity.setSwarmAttackerId( Entity.NONE );                r = new Report(2145);                r.subject = entity.getId();                r.indent();                r.add(swarmer.getShortName(), true);                addReport(r);            }            entityUpdate( swarmerId );        }        // Update the entitiy's position,        // unless it is off the game map.        if (!game.isOutOfGame(entity)) {            entityUpdate( entity.getId(), movePath  );            if (entity.isDoomed()) {                send(createRemoveEntityPacket(entity.getId(), entity.getRemovalCondition()));            }        }        // if using double blind, update the player on new units he might see        if (doBlind()) {            send(entity.getOwner().getId(), createFilteredEntitiesPacket(entity.getOwner()));        }        // if we generated a charge attack, report it now        if (charge != null) {            send(createAttackPacket(charge, 1));        }    }