if (step.getMpUsed() > (int)Math.ceil(entity.getOriginalWalkMP() * 1.5)) {
if ((step.getMpUsed() > (int)Math.ceil(entity.getWalkMP(false) * 1.5)) && !step.isUsingMASC()) {
    private void processMovement(Entity entity, MovePath md) {        // check for fleeing        if (md.contains(MovePath.STEP_FLEE)) {            // Unit has fled the battlefield.            phaseReport.append("\n" ).append( entity.getDisplayName()            ).append( " flees the battlefield.\n");            // 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.                    phaseReport.append( "   It carries " )                        .append( passenger.getDisplayName() )                        .append( " with it.\n" );                    game.removeEntity( passenger.getId(),                                       Entity.REMOVE_IN_RETREAT );                    send( createRemoveEntityPacket(passenger.getId(),                                                   Entity.REMOVE_IN_RETREAT) );                }            }            // 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 );                phaseReport.append( "   It takes " )                    .append( swarmer.getDisplayName() )                    .append( " with it.\n" );                game.removeEntity( swarmerId, Entity.REMOVE_PUSHED );                send( createRemoveEntityPacket(swarmerId,                                               Entity.REMOVE_PUSHED) );            }            game.removeEntity( entity.getId(), Entity.REMOVE_IN_RETREAT );            send( createRemoveEntityPacket(entity.getId(),                                           Entity.REMOVE_IN_RETREAT) );            return;        }        if (md.contains(MovePath.STEP_EJECT)) {            phaseReport.append("\n" ).append( entity.getDisplayName()).append( " ejects.\n");            phaseReport.append(destroyEntity(entity, "ejection"));            /* this was done in destroyEntity() --^            // 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 should unload.                    // TODO : unloading into stacking violation is not                    //        explicitly prohibited in the BMRr.                    this.unloadUnit( entity, passenger,                                     entity.getPosition(),                                     entity.getFacing() );                }            }            // Is the unit being swarmed?            final int swarmerId = entity.getSwarmAttackerId();            if ( Entity.NONE != swarmerId ) {                final Entity swarmer = game.getEntity( swarmerId );                swarmer.setSwarmTargetId( Entity.NONE );                entity.setSwarmAttackerId( Entity.NONE );                phaseReport.append( swarmer.getDisplayName() );                phaseReport.append( " ends its swarm attack.\n" );                this.entityUpdate( swarmerId );            }            */            // Now remove the unit that ejected.            game.removeEntity( entity.getId(), Entity.REMOVE_EJECTED );            send(createRemoveEntityPacket(entity.getId(), Entity.REMOVE_EJECTED));            return;        }        // okay, proceed with movement calculations        Coords lastPos = entity.getPosition();        Coords curPos = entity.getPosition();        int curFacing = entity.getFacing();        int distance = 0;        int mpUsed = 0;        int moveType = Entity.MOVE_NONE;        int overallMoveType = Entity.MOVE_NONE;        boolean firstStep;        boolean wasProne;        boolean fellDuringMovement;        int prevFacing = curFacing;        Hex prevHex = null;        final boolean isInfantry = (entity instanceof Infantry);        AttackAction charge = null;        PilotingRollData rollTarget;        // 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);        }        // check for MASC failure        if (entity instanceof Mech) {            if (((Mech)entity).checkForMASCFailure(phaseReport,md)) {                // no movement after that                md.clear();            }        }        overallMoveType = md.getLastStepMovementType();        // iterate through steps        firstStep = true;        fellDuringMovement = 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();            // stop for illegal movement            if (step.getMovementType() == Entity.MOVE_ILLEGAL) {                break;            }            // check piloting skill for getting up            rollTarget = entity.checkGetUp(step);            if (rollTarget.getValue() != TargetRoll.CHECK_FALSE) {                entity.heatBuildup += 1;                entity.setProne(false);                wasProne = false;                game.resetPSRs(entity);                doSkillCheckInPlace(entity, rollTarget);            } else if (firstStep) {                // running with destroyed hip or gyro needs a check                rollTarget = entity.checkRunningWithDamage(overallMoveType);                if (rollTarget.getValue() != TargetRoll.CHECK_FALSE) {                    doSkillCheckInPlace(entity, rollTarget);                }                firstStep = false;            }            // did the entity just fall?            if (!wasProne && entity.isProne()) {                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;            }            // 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()) {                    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()) {                    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;            }            // set last step parameters            curPos = step.getPosition();            curFacing = step.getFacing();            final Hex curHex = game.board.getHex(curPos);            // 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 psrPassed = true;                if ( entity instanceof Mech ) {                    psrPassed = doSkillCheckWhileMoving( entity, lastPos,                                                          lastPos, rollTarget,                                                          true );                } else {                    psrPassed = doSkillCheckWhileMoving( entity, lastPos,                                                          lastPos, rollTarget,                                                          false );                }                // Does the entity skid?                if ( !psrPassed ){                    curPos = lastPos;                    Coords nextPos = curPos;                    Hex    nextHex = null;                    int    skidDistance = 0;                    Enumeration targets = null;                    Entity target = null;                    int    curElevation;                    int    nextElevation;                    // 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 = Entity.MOVE_SKID;                    // What is the first hex in the skid?                    nextPos = curPos.translated( prevFacing );                    nextHex = game.board.getHex( nextPos );                    // Move the entity a number hexes from curPos in the                    // prevFacing direction equal to half the distance moved                    // this turn (rounded up), unless something intervenes.                    for ( skidDistance = 0;                          skidDistance < (int) Math.ceil(entity.delta_distance / 2.0);                          skidDistance++ ) {                        // Is the next hex off the board?                        if ( !game.board.contains(nextPos) ) {                            // Can the entity skid off the map?                            if ( game.getOptions().booleanOption("push_off_board") ) {                                // Yup.  One dead entity.                                game.removeEntity(entity.getId(),                                                  Entity.REMOVE_PUSHED);                                send(createRemoveEntityPacket(entity.getId(),                                                              Entity.REMOVE_PUSHED));                                phaseReport.append("*** " )                                    .append( entity.getDisplayName() )                                    .append( " has skidded off the field. ***\n");                                // TODO: remove passengers and swarmers.                                // The entity's movement is completed.                                return;                            } else {                                // Nope.  Update the report.                                phaseReport.append( "   Can't skid off the field.\n" );                            }                            // Stay in the current hex and stop skidding.                            break;                        }                        // Can the skiding entity enter the next hex from this?                        // N.B. can skid along roads.                        if ( ( entity.isHexProhibited(curHex) ||                               entity.isHexProhibited(nextHex) ) &&                             !Compute.canMoveOnPavement(game, curPos, nextPos)                             ) {                            // Update report.                            phaseReport.append( "   Can't skid into hex " )                                .append( nextPos.getBoardNum() )                                .append( ".\n" );                            // N.B. the BMRr pg. 22 says that the unit                            // "crashes" into the terrain but it doesn't                            // mention any damage.                            // Stay in the current hex and stop skidding.                            break;                        }                        // Hovercraft can "skid" over water.                        // TODO: allow entities to occupy different levels of                        //       buildings.                        curElevation = curHex.floor();                        nextElevation = nextHex.floor();                        if ( entity instanceof Tank &&                             entity.getMovementType() ==                             Entity.MovementType.HOVER ) {                            Terrain land = curHex.                                getTerrain(Terrain.WATER);                            if ( land != null ) {                                curElevation += land.getLevel();                            }                            land = nextHex.getTerrain(Terrain.WATER);                            if ( land != null ) {                                nextElevation += land.getLevel();                            }                        }                        // BMRr pg. 22 - Can't skid uphill,                        //      but can skid downhill.                        if ( curElevation < nextElevation ) {                            phaseReport.append                                ( "   Can not skid uphill into hex " +                                  nextPos.getBoardNum() ).append( ".\n" );                            // Stay in the current hex and stop skidding.                            break;                        }                        // Have skidding units suffer falls.                        else if ( curElevation > nextElevation + 1 ) {                            doEntityFallsInto( entity, curPos, nextPos,                                               entity.getBasePilotingRoll() );                            doEntityDisplacementMinefieldCheck(entity, curPos, nextPos);                            // Stay in the current hex and stop skidding.                            break;                        }                        // Get any building in the hex.                        Building bldg = game.board.getBuildingAt(nextPos);                        boolean bldgSuffered = false;                        // Does the next hex contain an entities?                        // ASSUMPTION: hurt EVERYONE in the hex.                        // TODO: allow entities to occupy different levels of                        //       buildings, and only skid into a single level.                        boolean stopTheSkid = false;                        targets = game.getEntities( nextPos );                        while ( targets.hasMoreElements() ) {                            target = (Entity) targets.nextElement();                            // TODO : allow ready targets to move out of way                            // Mechs and vehicles get charged.                            if ( !(target instanceof Infantry) ) {                                // Update report.                                phaseReport.append( "   Skids into " +                                                    target.getShortName() +                                                    " in hex " +                                                    nextPos.getBoardNum() +                                                    "... " );                                // Resolve a charge against the target.                                // ASSUMPTION: buildings block damage for                                //             *EACH* entity charged.                                ToHitData toHit = new ToHitData();                                // Calculate hit location.                                if ( entity instanceof Tank &&                                     entity.getMovementType() ==                                     Entity.MovementType.HOVER &&                                     0 < nextHex.levelOf(Terrain.WATER) ) {                                    if ( 2 <= nextHex.levelOf(Terrain.WATER) ||                                         target.isProne() ) {                                        // Hovercraft can't hit the Mek.                                        continue;                                    }                                    else {                                        toHit.setHitTable(ToHitData.HIT_PUNCH);                                    }                                }                                else if ( entity.getHeight() <                                          target.getHeight() ) {                                    toHit.setHitTable(ToHitData.HIT_KICK);                                } else {                                    toHit.setHitTable(ToHitData.HIT_NORMAL);                                }                                // Resolve the hit.                                toHit.setSideTable                                    (Compute.targetSideTable(entity, target));                                resolveChargeDamage                                    (entity, target, toHit, prevFacing);                                bldgSuffered = true;                                // The skid ends here if the target lives.                                // TODO : we should keep skiding if the target                                //        is pushed off the board as it has                                //        been "destroyed" according to the                                //        MegaMek interpretation of the rules.                                if ( !target.isDoomed() &&                                     !target.isDestroyed() ) {                                    stopTheSkid = true;                                }                            }                            // Resolve "move-through" damage on infantry.                            // Infantry inside of a building don't get a                            // move-through, but suffer "bleed through"                            // from the building.                            else if ( bldg != null ) {                                // Update report.                                phaseReport.append( "   Skids through " +                                                    target.getShortName() +                                                    " in hex " +                                                    nextPos.getBoardNum() +                                                    "... " );                                // Infantry don't have different                                // tables for punches and kicks                                HitData hit = target.rollHitLocation( ToHitData.HIT_NORMAL,                                                                      Compute.targetSideTable(entity, target)                                                                      );                                // Damage equals tonnage, divided by 5.                                // ASSUMPTION: damage is applied in one hit.                                phaseReport.append( damageEntity(target, hit, (int)Math.round(entity.getWeight()/5)) );                                phaseReport.append( "\n" );                            } // End handle-infantry                            // Has the target been destroyed?                            if ( target.isDoomed() ) {                                // Has the target taken a turn?                                if ( !target.isDone() ) {                                    // Dead entities don't take turns.                                    game.removeTurnFor(target);                                    send(createTurnVectorPacket());                                } // End target-still-to-move                                // Clean out the entity.                                target.setDestroyed(true);                                game.moveToGraveyard(target.getId());                                send(createRemoveEntityPacket(target.getId()));                            }                            // Update the target's position,                            // unless it is off the game map.                            if ( !game.isOutOfGame(target) ) {                                entityUpdate( target.getId() );                            }                        } // Check the next entity in the hex.                        // Handle the building in the hex.                        // TODO : BMRr pg. 22, only count buildings that are                        //      higher than our starting terrain height.                        // TODO: allow units to skid on top of buildings.                        if ( bldg != null ) {                            // Report that the entity has entered the bldg.                            phaseReport.append( "   Skids into " )                                .append( bldg.getName() )                                .append( " in hex " )                                .append( nextPos.getBoardNum() )                                .append( ".\n" );                            // If the building hasn't already suffered                            // damage, then apply charge damage to the                            // building and displace the entity inside.                            // ASSUMPTION: you don't charge the building                            //             if Tanks or Mechs were charged.                            int chargeDamage = ChargeAttackAction.getChargeDamageFor                                ( entity );                            if ( !bldgSuffered ) {                                phaseReport.append( "      " )                                    .append( damageBuilding( bldg,                                                             chargeDamage ) );                                // Apply damage to the attacker.                                int toAttacker = ChargeAttackAction.getChargeDamageTakenBy                                    ( entity, bldg );                                HitData hit = entity.rollHitLocation( ToHitData.HIT_NORMAL,                                                                      Compute.targetSideTable(curPos, nextPos, entity.getFacing(), false)                                                                      );                                phaseReport.append( this.damageEntity( entity, hit, toAttacker ) )                                    .append( "\n" );                                entity.setPosition( nextPos );	                            doEntityDisplacementMinefieldCheck(entity, curPos, nextPos);                                curPos = nextPos;                            } // End buildings-suffer-too                            // Any infantry in the building take damage                            // equal to the building being charged.                            // ASSUMPTION: infantry take no damage from the                            //             building absorbing damage from                            //             Tanks and Mechs being charged.                            damageInfantryIn( bldg, chargeDamage );                            // If a building still stands, then end the skid,                            // and add it to the list of affected buildings.                            if ( bldg.getCurrentCF() > 0 ) {                                stopTheSkid = true;                                this.addAffectedBldg( bldg, false );                            }                        } // End handle-building.                        // Do we stay in the current hex and stop skidding?                        if ( stopTheSkid ) {                            break;                        }                        // Update the position and keep skidding.                        entity.setPosition( nextPos );                        doEntityDisplacementMinefieldCheck(entity, curPos, nextPos);                        curPos = nextPos;                        phaseReport.append( "   Skids into hex " ).append(                                            curPos.getBoardNum() ).append( ".\n" );                        // Get the next hex in the skid?                        nextPos = nextPos.translated( prevFacing );                        nextHex = game.board.getHex( nextPos );                    } // Handle the next skid hex.                    // If the skidding entity violates stacking,                    // displace targets until it doesn't.                    curPos = entity.getPosition();                    target = Compute.stackingViolation                        (game, entity.getId(), curPos);                    while (target != null) {                        nextPos = Compute.getValidDisplacement                            (game, target.getId(),                             target.getPosition(), prevFacing);                        // ASSUMPTION                        // There should always be *somewhere* that                        // the target can go... last skid hex if                        // nothing else is available.                        if ( null == nextPos ) {                            // But I don't trust the assumption fully.                            // Report the error and try to continue.                            System.err.println( "The skid of " +                                                entity.getShortName() +                                                " should displace " +                                                target.getShortName() +                                                " in hex " +                                                curPos.getBoardNum() +                                                " but there is nowhere to go."                                                );                            break;                        }                        phaseReport.append( "    " ); // indent displacement                        doEntityDisplacement(target, curPos, nextPos, null);                        doEntityDisplacementMinefieldCheck(entity, curPos, nextPos);                        target = Compute.stackingViolation( game,                                                            entity.getId(),                                                            curPos );                    }                    // Mechs suffer damage for every hex skidded.                    if ( entity instanceof Mech ) {                        // Calculate one half falling damage times skid length.                        int damage = skidDistance * (int) Math.ceil(Math.round(entity.getWeight() / 10.0) / 2.0);                        // report skid damage                        phaseReport.append("    " ).append( entity.getDisplayName() ).append( " suffers " ).append( damage ).append( " damage from the skid.");                        // standard damage loop                        // All skid damage is to the front.                        while (damage > 0) {                            int cluster = Math.min(5, damage);                            HitData hit = entity.rollHitLocation(ToHitData.HIT_NORMAL, ToHitData.SIDE_FRONT);                            phaseReport.append(damageEntity(entity, hit, cluster));                            damage -= cluster;                        }                        phaseReport.append( "\n" );                    }                    // 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;                    }                    // Let the player know the ordeal is over.                    phaseReport.append( "      Skid ends.\n" );                    // 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;                    distance = entity.delta_distance;                    break;                } // End failed-skid-psr            } // End need-skid-psr            // 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 to see if we are a mech and we've moved OUT of fire            if (entity instanceof Mech) {                if ( !lastPos.equals(curPos)                    && game.board.getHex(lastPos).contains(Terrain.FIRE)                    && ( step.getMovementType() != Entity.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() ) ) )                {                    entity.heatBuildup+=2;                    phaseReport.append("\n" ).append( entity.getDisplayName()                    ).append( " passes through a fire.  It will generate 2 more heat this round.\n");                }            }            // check to see if we are not a mech and we've moved INTO fire            if (!(entity instanceof Mech)) {                if ( game.board.getHex(curPos).contains(Terrain.FIRE)                    && !lastPos.equals(curPos)                    && step.getMovementType() != Entity.MOVE_JUMP ) {                        doFlamingDeath(entity);                }            }//          check if we used more MPs than the Mech/Vehicle would have in normal gravity            if (!i.hasMoreElements()) {                HitData hit;                if (entity instanceof Mech) {                    if ((step.getMovementType() == Entity.MOVE_WALK) || (step.getMovementType() == Entity.MOVE_RUN)) {                        if (step.getMpUsed() > (int)Math.ceil(entity.getOriginalWalkMP() * 1.5)) {                            rollTarget = entity.checkMovedTooFast(step);                            if (rollTarget.getValue() != TargetRoll.CHECK_FALSE) {                                if (!doSkillCheckWhileMoving(entity, curPos, curPos, rollTarget, false)) {                                    int j=step.getMpUsed();                                    int damage = 0;                                    while (j > (int)Math.ceil(entity.getOriginalWalkMP() * 1.5)) {                                        j--;                                        damage++;                                    }                                    if (entity instanceof BipedMech) {                                        hit = new HitData (Mech.LOC_LLEG);                                        phaseReport.append(damageEntity(entity, hit, damage, false, 0, true));                                        hit = new HitData (Mech.LOC_RLEG);                                        phaseReport.append(damageEntity(entity, hit, damage, false, 0, true));                                    } else if (entity instanceof QuadMech) {                                        hit = new HitData (Mech.LOC_LLEG);                                        phaseReport.append(damageEntity(entity, hit, damage, false, 0, true));                                        hit = new HitData (Mech.LOC_RLEG);                                        phaseReport.append(damageEntity(entity, hit, damage, false, 0, true));                                        hit = new HitData (Mech.LOC_LARM);                                        phaseReport.append(damageEntity(entity, hit, damage, false, 0, true));                                        hit = new HitData (Mech.LOC_RARM);                                        phaseReport.append(damageEntity(entity, hit, damage, false, 0, true));                                    }                                }                            }                        }                    } else if (step.getMovementType() == Entity.MOVE_JUMP) {                        if (step.getMpUsed() > (entity.getOriginalJumpMP())) {                            rollTarget = entity.checkMovedTooFast(step);                            if (rollTarget.getValue() != TargetRoll.CHECK_FALSE) {                                if (!doSkillCheckWhileMoving(entity, curPos, curPos, rollTarget, false)) {                                    int j=step.getMpUsed();                                    int damage = 0;                                    while (j > entity.getOriginalJumpMP()) {                                        j--;                                        damage++;                                    }                                    if (entity instanceof BipedMech) {                                        hit = new HitData (Mech.LOC_LLEG);                                        phaseReport.append(damageEntity(entity, hit, damage, false, 0, true));                                        hit = new HitData (Mech.LOC_RLEG);                                        phaseReport.append(damageEntity(entity, hit, damage, false, 0, true));                                    } else if (entity instanceof QuadMech) {                                        hit = new HitData (Mech.LOC_LLEG);                                        phaseReport.append(damageEntity(entity, hit, damage, false, 0, true));                                        hit = new HitData (Mech.LOC_RLEG);                                        phaseReport.append(damageEntity(entity, hit, damage, false, 0, true));                                        hit = new HitData (Mech.LOC_LARM);                                        phaseReport.append(damageEntity(entity, hit, damage, false, 0, true));                                        hit = new HitData (Mech.LOC_RARM);                                        phaseReport.append(damageEntity(entity, hit, damage, false, 0, true));                                    }                                }                            }                        }                          }                } else if (entity instanceof Tank) {                    if ((step.getMovementType() == Entity.MOVE_WALK) || (step.getMovementType() == Entity.MOVE_RUN)) {                        if (step.getMpUsed() > (int)Math.ceil(entity.getOriginalWalkMP() * 1.5)) {                            rollTarget = entity.checkMovedTooFast(step);                            if (rollTarget.getValue() != TargetRoll.CHECK_FALSE) {                                if (!doSkillCheckWhileMoving(entity, curPos, curPos, rollTarget, false)) {                                    int j=step.getMpUsed();                                    int damage = 0;                                    while (j > (int)Math.ceil(entity.getOriginalWalkMP() * 1.5)) {                                        j--;                                        damage++;                                    }                                    hit = new HitData (Tank.LOC_FRONT);                                    phaseReport.append(damageEntity(entity, hit, damage, false, 0, true));                                }                            }                        }                    }                   }            }            // check for minefields.//            if ((!lastPos.equals(curPos) && (step.getMovementType() != Entity.MOVE_JUMP))//            	|| ((overallMoveType == Entity.MOVE_JUMP) && (!i.hasMoreElements()))) {            if ((step.getMovementType() != Entity.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();            		switch (mf.getType()) {            			case (Minefield.TYPE_CONVENTIONAL) :            			case (Minefield.TYPE_THUNDER) :            			case (Minefield.TYPE_THUNDER_INFERNO) :            			case (Minefield.TYPE_COMMAND_DETONATED) :            				if ((step.getMovementType() != Entity.MOVE_JUMP) || (!i.hasMoreElements()))            					enterMinefield(entity, mf, curPos, curPos, true);            				break;            			case (Minefield.TYPE_THUNDER_ACTIVE) :            				if ((step.getMovementType() != Entity.MOVE_JUMP) || (!i.hasMoreElements()))	            				enterMinefield(entity, mf, curPos, curPos, true);	            			else	            				enterMinefield(entity, mf, curPos, curPos, true, 2);            				break;            		}            	}            }            // 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)) {		            		phaseReport.append(entity.getShortName() + " discovers a minefield.\n");							revealMinefield(owner, mf);						}	            	}            	}            }            // check if we've moved into water            rollTarget = entity.checkWaterMove(step, curHex, lastPos, curPos,                                               isPavementStep);            if (rollTarget.getValue() != TargetRoll.CHECK_FALSE) {                doSkillCheckWhileMoving(entity, lastPos, curPos, rollTarget,                                         true);                if (curHex.levelOf(Terrain.WATER) > 1) {                    // Any swarming infantry will be destroyed.                    drownSwarmer(entity, curPos);                }                // 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, to set dry if appropriate            //if NOT possible to flood armorless locations while moving, this can be removed            //TODO: possibly make the locations local and set later            doSetLocationsExposure(entity, curHex, isPavementStep, step.getMovementType() == Entity.MOVE_JUMP);            // 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.getOwner() == loaded.getOwner() &&                         !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.isSelectableThisTurn(game) ) {                            // 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.                            this.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 ( !this.unloadUnit( entity, unloaded,                                       curPos, curFacing ) ) {                    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 (entity.checkMovementInBuilding(lastPos, curPos, step,                                               curHex, prevHex)) {                // Get the building being exited.                // TODO: allow units to climb on top of buildings.                Building bldgExited = game.board.getBuildingAt( lastPos );                // Get the building being entered.                // TODO: allow units to climb on top of buildings.                Building bldgEntered = game.board.getBuildingAt( curPos );                // If we're not leaving a building, just handle the "entered".                boolean collapsed = false;                if ( bldgExited == null ) {                    collapsed = passBuildingWall( entity, bldgEntered,                                                  lastPos, curPos,                                                  distance, "entering" );                    this.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" );                    this.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" );                    this.addAffectedBldg( bldgExited, collapsed );                    collapsed = passBuildingWall( entity, bldgEntered,                                                  lastPos, curPos,                                                  distance, "entering" );                    this.addAffectedBldg( bldgEntered, collapsed );                }                // Otherwise, just handle the "exited".                else {                    collapsed = passBuildingWall( entity, bldgExited,                                                  lastPos, curPos,                                                  distance, "exiting" );                    this.addAffectedBldg( bldgExited, 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();                if (rollTarget.getValue() == TargetRoll.CHECK_FALSE) {                    // Not being swarmed                    entity.setProne(true);                    // check to see if we washed off infernos                    checkForWashedInfernos(entity, curPos);                    break;                } else {                    // Being swarmed                    entity.setPosition(curPos);                    if (doDislodgeSwarmerSkillCheck(entity, rollTarget, curPos)) {                        // Entity falls                        curFacing = entity.getFacing();                        curPos = entity.getPosition();                        fellDuringMovement = true;                        break;                    }                }            }            movePath.addElement(new Integer(curPos.hashCode() ^ (curFacing << 16)));            // 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;        }        // set entity parameters        entity.setPosition(curPos);        entity.setFacing(curFacing);        entity.setSecondaryFacing(curFacing);        entity.delta_distance = distance;        entity.moved = moveType;        entity.mpUsed = mpUsed;        // but the danger isn't over yet!  landing from a jump can be risky!        if (overallMoveType == Entity.MOVE_JUMP && !entity.isMakingDfa()) {            // check for damaged criticals            rollTarget = entity.checkLandingWithDamage();            if (rollTarget.getValue() != TargetRoll.CHECK_FALSE) {                doSkillCheckInPlace(entity, rollTarget);            }            // jumped into water?            int waterLevel = game.board.getHex(curPos).levelOf(Terrain.WATER);            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);            }            // If the entity is being swarmed, jumping may dislodge the fleas.            final int swarmerId = entity.getSwarmAttackerId();            if ( Entity.NONE != swarmerId ) {                final Entity swarmer = game.getEntity( swarmerId );                final PilotingRollData roll =                    entity.getBasePilotingRoll();                // 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 ( Enumeration iter = swarmer.getMisc();                      iter.hasMoreElements(); ) {                    Mounted mount = (Mounted) iter.nextElement();                    EquipmentType equip = mount.getType();                    if ( BattleArmor.ASSAULT_CLAW.equals                         (equip.getInternalName()) ) {                        roll.addModifier( 1, "swarmer has assault claws" );                        break;                    }                }                // okay, print the info                phaseReport.append("\n")                    .append( entity.getDisplayName() )                    .append( " tries to dislodge swarming infantry.\n" );                // roll                final int diceRoll = Compute.d6(2);                phaseReport.append("Needs " ).append( roll.getValueAsString()                                   ).append( " [" ).append( roll.getDesc() ).append( "]"                                   ).append( ", rolls " ).append( diceRoll ).append( " : ");                if (diceRoll < roll.getValue()) {                    phaseReport.append("fails.\n");                } else {                    phaseReport.append("succeeds.\n");                    entity.setSwarmAttackerId( Entity.NONE );                    swarmer.setSwarmTargetId( Entity.NONE );                    // Did the infantry fall into water?                    final Hex curHex = game.board.getHex(curPos);                    if ( curHex.levelOf(Terrain.WATER) > 0 ) {                        // Swarming infantry die.                        swarmer.setPosition( curPos );                        phaseReport.append("    ")                            .append(swarmer.getDisplayName())                            .append(" is dislodged and drowns!")                            .append(destroyEntity(swarmer, "a watery grave", false));                    } else {                        // Swarming infantry take an 11 point hit.                        // ASSUMPTION : damage should not be doubled.                        phaseReport.append("    ")                            .append(swarmer.getDisplayName())                            .append(" is dislodged and suffers 11 damage.")                            .append( damageEntity(swarmer,                                                  swarmer.rollHitLocation(ToHitData.HIT_NORMAL, ToHitData.SIDE_FRONT),                                                  11) )                            .append( "\n" );                        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.board.getHex(curPos), game.board.getHex(curPos).surface() <= entity.getElevation(), false);        // should we give another turn to the entity to keep moving?        if (fellDuringMovement && entity.mpUsed < entity.getRunMP()        && entity.isSelectableThisTurn(game) && !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());        } else {            entity.setDone(true);        }        // If the entity is being swarmed, update the attacker's position.        final int swarmerId = entity.getSwarmAttackerId();        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.board.getHex(curPos).contains(Terrain.FIRE) ) {                swarmer.setSwarmTargetId( Entity.NONE );                entity.setSwarmAttackerId( Entity.NONE );                phaseReport.append( "\n   " )                    .append( swarmer.getShortName() )                    .append( " can't stand the fire's heat and drops off.\n" );            }            entityUpdate( swarmerId );        }        // Update the entitiy's position,        // unless it is off the game map.        if (!game.isOutOfGame(entity)) {            if (entity.isDoomed()) {                send(createRemoveEntityPacket(entity.getId(), entity.getRemovalCondition()));            } else {                entityUpdate( entity.getId(), movePath  );            };        };        // 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, true));        }    }