vPhaseReport.addElement(r);
addReport(r);
    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);            vPhaseReport.addElement(r);            // 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);                    vPhaseReport.addElement(r);                    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;                }                game.removeEntity( mw.getId(), condition );                send( createRemoveEntityPacket(mw.getId(), condition) );                r.addDesc(mw);                r.indent();                vPhaseReport.addElement(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);                vPhaseReport.addElement(r);                game.removeEntity( swarmerId, IEntityRemovalConditions.REMOVE_CAPTURED );                send( createRemoveEntityPacket(swarmerId,                        IEntityRemovalConditions.REMOVE_CAPTURED) );            }            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);                vPhaseReport.addElement(r);            } else if (entity instanceof Tank) {                r = new Report(2025);                r.subject = entity.getId();                r.addDesc(entity);                vPhaseReport.addElement(r);            }            vPhaseReport.addAll( 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();        int distance = 0;        int mpUsed = 0;        int moveType = IEntityMovementType.MOVE_NONE;        int overallMoveType = IEntityMovementType.MOVE_NONE;        // 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        if (entity.mpUsed > 0) {            moveType = IEntityMovementType.MOVE_WALK;            overallMoveType = IEntityMovementType.MOVE_WALK;            if (entity.mpUsed > entity.getWalkMP()) {                moveType = IEntityMovementType.MOVE_RUN;                overallMoveType = IEntityMovementType.MOVE_RUN;            }        }        boolean firstStep;        boolean wasProne;        boolean fellDuringMovement;        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);        }        // check for MASC failure        if (entity instanceof Mech) {            Vector crits = new Vector();            if (((Mech)entity).checkForMASCFailure(md, vPhaseReport, crits)) {                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;                        applyCriticalHit(entity, loc, cs, true);                    }                }                // no movement after that                md.clear();            }        }        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;        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();            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 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;            }            // set last step parameters            curPos = step.getPosition();            if(moveType != IEntityMovementType.MOVE_JUMP || entity.getJumpType() != Mech.JUMP_BOOSTER)                curFacing = step.getFacing();            curVTOLElevation = step.getElevation();            //set elevation in case of collapses            entity.setElevation(step.getElevation());            final 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 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;                    IHex    nextHex = null;                    int    skidDistance = 0;                    Enumeration targets = null;                    Entity target = null;                    int    curElevation;                    int    nextElevation;                    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;                    }                    nextPos = curPos.translated( skidDirection );                    nextHex = game.getBoard().getHex( nextPos );                    // Move the entity a number hexes from curPos in the                    // skidDirection 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.getBoard().contains(nextPos) ) {                            // Can the entity skid off the map?                            if (game.getOptions().booleanOption("push_off_board")) {                                // Yup.  One dead entity.                                game.removeEntity(entity.getId(),                                        IEntityRemovalConditions.REMOVE_PUSHED);                                send(createRemoveEntityPacket(entity.getId(),                                        IEntityRemovalConditions.REMOVE_PUSHED));                                r = new Report(2030, Report.PUBLIC);                                r.addDesc(entity);                                vPhaseReport.addElement(r);                                // TODO: remove passengers and swarmers.                                // The entity's movement is completed.                                return;                            } else {                                // Nope.  Update the report.                                r = new Report(2035);                                r.subject = entity.getId();                                r.indent();                                vPhaseReport.addElement(r);                            }                            // 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.                            r = new Report(2040);                            r.subject = entity.getId();                            r.indent();                            r.add(nextPos.getBoardNum(), true);                            vPhaseReport.addElement(r);                            // 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.                        // all units can skid over ice.                        // TODO: allow entities to occupy different levels of                        //       buildings.                        curElevation = curHex.floor();                        nextElevation = nextHex.floor();                        if ( entity instanceof Tank &&                             entity.getMovementMode() ==                             IEntityMovementMode.HOVER ) {                            if ( curHex.containsTerrain(Terrains.WATER) ) {                                curElevation = curHex.surface();                            }                            if ( nextHex.containsTerrain(Terrains.WATER) ) {                                nextElevation += nextHex.surface();                            }                        } else {                            if(curHex.containsTerrain(Terrains.ICE)) {                                curElevation = curHex.surface();                            }                            if(nextHex.containsTerrain(Terrains.ICE)) {                                nextElevation = nextHex.surface();                            }                        }                        // BMRr pg. 22 - Can't skid uphill,                        //      but can skid downhill.                        if ( curElevation < nextElevation ) {                            r = new Report(2045);                            r.subject = entity.getId();                            r.indent();                            r.add(nextPos.getBoardNum(), true);                            vPhaseReport.addElement(r);                            // 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.getBoard().getBuildingAt(nextPos);                        boolean bldgSuffered = false;                        boolean stopTheSkid = 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.                        targets = game.getEntities( nextPos );                        if ( targets.hasMoreElements()) {                            boolean skidChargeHit = false;                            while ( targets.hasMoreElements() ) {                                target = (Entity) targets.nextElement();                                // TODO : allow ready targets to move out of way                                // Mechs and vehicles get charged,                                // but need to make a to-hit roll                                if ( target instanceof Mech ||                                     target instanceof Tank ) {                                    ChargeAttackAction caa = new ChargeAttackAction(entity.getId(), target.getTargetType(), target.getTargetId(), target.getPosition());                                    ToHitData toHit = caa.toHit(game, true);                                    // Calculate hit location.                                    if ( entity instanceof Tank                                         && ((entity.getMovementMode() == IEntityMovementMode.HOVER)                                         || (entity.getMovementMode() == IEntityMovementMode.NAVAL)                                         || (entity.getMovementMode() == IEntityMovementMode.HYDROFOIL))                                         && 0 < nextHex.terrainLevel(Terrains.WATER)                                         && target.getElevation() < 0) {                                        if ( 2 <= nextHex.terrainLevel(Terrains.WATER) ||                                             target.isProne() ) {                                            // Hovercraft/Naval Craft 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);                                    }                                    toHit.setSideTable                                        (Compute.targetSideTable(entity, target));                                    // roll                                    int roll = Compute.d6(2);                                    // Update report.                                    r = new Report(2050);                                    r.subject = entity.getId();                                    r.indent();                                    r.add(target.getShortName(), true);                                    r.add(nextPos.getBoardNum(), true);                                    r.newlines = 0;                                    vPhaseReport.addElement(r);                                    if (toHit.getValue() == ToHitData.IMPOSSIBLE) {                                        roll = -12;                                        r = new Report(2055);                                        r.subject = entity.getId();                                        r.add(toHit.getDesc());                                        r.newlines = 0;                                        vPhaseReport.addElement(r);                                    } else if (toHit.getValue() == ToHitData.AUTOMATIC_SUCCESS) {                                        r = new Report(2060);                                        r.subject = entity.getId();                                        r.add(toHit.getDesc());                                        r.newlines = 0;                                        vPhaseReport.addElement(r);                                        roll = Integer.MAX_VALUE;                                    } else {                                        // report the roll                                        r = new Report(2065);                                        r.subject = entity.getId();                                        r.add(toHit.getValue());                                        r.add(roll);                                        r.newlines = 0;                                        vPhaseReport.addElement(r);                                    }                                    // Resolve a charge against the target.                                    // ASSUMPTION: buildings block damage for                                    //             *EACH* entity charged.                                    if (roll < toHit.getValue()) {                                        r = new Report(2070);                                        r.subject = entity.getId();                                        vPhaseReport.addElement(r);                                    } else {                                        // Resolve the charge.                                        resolveChargeDamage                                            (entity, target, toHit, skidDirection);                                        // HACK: set the entity's location                                        // to the original hex again, for the other targets                                        if (targets.hasMoreElements()) {                                            entity.setPosition(curPos);                                        }                                        bldgSuffered = true;                                        skidChargeHit = true;                                    }                                    // The skid ends here if the target lives.                                    if ( !target.isDoomed() &&                                         !target.isDestroyed() &&                                         !game.isOutOfGame(target) ) {                                        stopTheSkid = true;                                    }                                    // if we don't do this here,                                    // we can have a mech without a leg                                    // standing on the field and moving                                    // as if it still had his leg after                                    // getting skid-charged.                                    if (!target.isDone()) {                                        resolvePilotingRolls(target);                                        game.resetPSRs(target);                                        target.applyDamage();                                        Report.addNewline(vPhaseReport);                                    }                                }                                // 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 ( target instanceof Infantry &&                                          bldg != null ) {                                    // Update report.                                    r = new Report(2075);                                    r.subject = entity.getId();                                    r.indent();                                    r.add(target.getShortName(), true);                                    r.add(nextPos.getBoardNum(), true);                                    r.newlines = 0;                                    vPhaseReport.addElement(r);                                    // 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.                                    vPhaseReport.addAll(                                      damageEntity(target, hit,                                      Math.round(entity.getWeight()/5)));                                    Report.addNewline(vPhaseReport);                                }                                // 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.                            // if we missed all the entities in the hex,                            // move attacker to side hex                            if (!skidChargeHit) {                                Coords src = entity.getPosition();                                Coords dest = Compute.getMissedChargeDisplacement                                    (game, entity.getId(), src, skidDirection);                                doEntityDisplacement(entity, src, dest, null);                            } else {                                // HACK: otherwise, set the entities position to that                                // hex's coords, because we had to move the entity                                // back earlier for the other targets                                entity.setPosition(nextPos);                            }                        }                        // 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.                            r = new Report(2080);                            r.subject = entity.getId();                            r.indent();                            r.add(bldg.getName());                            r.add(nextPos.getBoardNum(), true);                            vPhaseReport.addElement(r);                            // 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.getDamageFor                                ( entity );                            if ( !bldgSuffered ) {                                Report buildingReport = damageBuilding( bldg, chargeDamage );                                buildingReport.indent(2);                                buildingReport.subject = entity.getId();                                vPhaseReport.addElement(buildingReport);                                // Apply damage to the attacker.                                int toAttacker = ChargeAttackAction.getDamageTakenBy                                    ( entity, bldg );                                HitData hit = entity.rollHitLocation( ToHitData.HIT_NORMAL,                                                                      entity.sideTable(nextPos)                                                                      );                                vPhaseReport.addAll(                                                      damageEntity( entity, hit, toAttacker ));                                Report.addNewline(vPhaseReport);                                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;                        }                        // is the next hex a rubble hex?                        rollTarget = entity.checkRubbleMove(step, nextHex,                                                curPos, nextPos);                        if (rollTarget.getValue() != TargetRoll.CHECK_FALSE) {                            doSkillCheckWhileMoving(entity, curPos, nextPos,                                                        rollTarget, true);                            if (entity.isProne()) {                                // if we fell, stop the skid (see bug 1115608)                                break;                            }                        }                                                //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();                            vPhaseReport.addElement(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);                        }                                    // is the next hex a swamp?                        rollTarget = entity.checkSwampMove(step, nextHex,                                                               curPos, nextPos);                        if (rollTarget.getValue() != TargetRoll.CHECK_FALSE) {                            if (!doSkillCheckWhileMoving(entity, curPos,                                                   nextPos, rollTarget, false)){                                entity.setStuck(true);                                r = new Report(2081);                                r.subject = entity.getId();                                r.add(entity.getDisplayName(), true);                                // stay here and stop skidding, see bug 1115608                                break;                            }                        }                        // Update the position and keep skidding.                        entity.setPosition( nextPos );                        doEntityDisplacementMinefieldCheck(entity, curPos, nextPos);                        curPos = nextPos;                        r = new Report(2085);                        r.subject = entity.getId();                        r.indent();                        r.add(curPos.getBoardNum(), true);                        vPhaseReport.addElement(r);                        // Get the next hex in the skid?                        nextPos = nextPos.translated( skidDirection );                        nextHex = game.getBoard().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(), skidDirection);                        // 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;                        }                        // indent displacement                        r = new Report(1210, Report.PUBLIC);                        r.indent();                        r.newlines = 0;                        vPhaseReport.addElement(r);                        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                        r = new Report(2090);                        r.subject = entity.getId();                        r.indent();                        r.addDesc(entity);                        r.add(damage);                        vPhaseReport.addElement(r);                        // 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);                            vPhaseReport.addAll(                                damageEntity(entity, hit, cluster));                            damage -= cluster;                        }                        Report.addNewline(vPhaseReport);                    }                    // 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.                    r = new Report(2095);                    r.subject = entity.getId();                    r.indent();                    vPhaseReport.addElement(r);                    // 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            if(entity instanceof VTOL) {                rollTarget = ((VTOL)entity).checkSideSlip(moveType, prevHex, overallMoveType,                                          prevStep, prevFacing, curFacing,                                          lastPos, curPos,                                          distance);                if(rollTarget.getValue() != TargetRoll.CHECK_FALSE) {                    if(!doSkillCheckWhileMoving(entity,lastPos,curPos,rollTarget, false)) {                        //report sideslip                        sideslipped = true;                        r = new Report(2100);                        r.subject = entity.getId();                        r.addDesc(entity);                        vPhaseReport.addElement(r);                        Coords newPos = lastPos.translated((prevFacing));//does this work for opposing hex?                        // Is the next hex off the board?                        if ( !game.getBoard().contains(newPos) ) {                            // Can the entity skid off the map?                            if (game.getOptions().booleanOption("push_off_board")) {                                // Yup.  One dead entity.                                game.removeEntity(entity.getId(),                                        IEntityRemovalConditions.REMOVE_PUSHED);                                send(createRemoveEntityPacket(entity.getId(),                                        IEntityRemovalConditions.REMOVE_PUSHED));                                r = new Report(2030);                                r.subject = entity.getId();                                r.addDesc(entity);                                vPhaseReport.addElement(r);                                // TODO: remove passengers and swarmers.                                // The entity's movement is completed.                                return;                            } else {                                // Nope.  Update the report.                                r = new Report(2035);                                r.subject = entity.getId();                                vPhaseReport.addElement(r);                            }                            // Stay in the current hex and stop skidding.                            break;                        }                        int newElevation=(entity.calcElevation(game.getBoard().getHex(curPos),game.getBoard().getHex(newPos),curVTOLElevation,step.climbMode()));                        if(newElevation<=0) {                                                        r = new Report(2105);                            r.subject = entity.getId();                            r.add(newPos.getBoardNum(), true);                            vPhaseReport.addElement(r);                            int hitSide=curFacing-prevFacing+6;                            hitSide=hitSide % 6;                            int table=0;                            switch(hitSide) {//quite hackish...I think it ought to work, though.                                case 0://can this happen?                                    table=ToHitData.SIDE_FRONT;                                    break;                                case 1:                                case 2:                                    table=ToHitData.SIDE_LEFT;                                    break;                                case 3:                                    table=ToHitData.SIDE_REAR;                                    break;                                case 4:                                case 5:                                    table=ToHitData.SIDE_RIGHT;                                    break;                            }                            curPos=newPos;                            curVTOLElevation=newElevation;                            vPhaseReport.addAll(                                                  crashVTOL(((VTOL)entity),true,distance,curPos,curVTOLElevation,table));                            curVTOLElevation=0;                            IHex hex = game.getBoard().getHex(newPos);                            if((hex.containsTerrain(Terrains.WATER) && !hex.containsTerrain(Terrains.ICE))                                || hex.containsTerrain(Terrains.WOODS)                                || hex.containsTerrain(Terrains.JUNGLE)) {                                vPhaseReport.addAll(                                                      destroyEntity(entity,"could not land in crash site"));                            } else {                            }                        } else {                            r = new Report(2110);                            r.subject = entity.getId();                            r.add(newPos.getBoardNum(), true);                            vPhaseReport.addElement(r);                            entity.setElevation(entity.calcElevation(game.getBoard().getHex(curPos),game.getBoard().getHex(newPos),curVTOLElevation,step.climbMode()));                            curPos=newPos;                        }                        if(!entity.isDestroyed() && !entity.isDoomed()) {                            fellDuringMovement= true; //No, but it should work...                        }                        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();                vPhaseReport.addElement(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);            if (rollTarget.getValue() != TargetRoll.CHECK_FALSE) {                if (!doSkillCheckWhileMoving(entity, lastPos, curPos, rollTarget,                                         false)){                    entity.setStuck(true);                    entity.setCanUnstickByJumping(true);                    r = new Report(2081);                    r.add(entity.getDisplayName());                    r.subject = entity.getId();                    vPhaseReport.addElement(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)                    && (lastHex.containsTerrain(Terrains.FIRE)                            || lastHex.containsTerrain(Terrains.MAGMA))                    && ( 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.heatBuildup+=heat;                    r = new Report(2115);                    r.subject = entity.getId();                    r.addDesc(entity);                    r.add(heat);                    vPhaseReport.addElement(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;                        if (isOnGround) {                            enterMinefield(entity, mf, curPos, curPos, true);                        } else if (mf.getType() == Minefield.TYPE_THUNDER_ACTIVE) {                            enterMinefield(entity, mf, curPos, curPos, true, 2);                        }                    }                }            }            // 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);                            vPhaseReport.addElement(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);                vPhaseReport.add(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();                    vPhaseReport.addElement(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);                    vPhaseReport.add(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.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() ) {                            // 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, 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.            int buildingMove = entity.checkMovementInBuilding(step, prevStep, curHex, prevHex);            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" );                        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 if (bldgExited != null){                        collapsed = passBuildingWall( entity, bldgExited,                                                      lastPos, curPos,                                                      distance, "exiting" );                        this.addAffectedBldg( bldgExited, collapsed );                    }                }                                //stepping on roof, no PSR just check for over weight                if(bldgStepped != null) {                    collapsed = checkBuildingCollapseWhileMoving(bldgStepped, entity, curPos);                    this.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;                } else {                    // Being swarmed                    entity.setPosition(curPos);                    if (doDislodgeSwarmerSkillCheck(entity,                                                    rollTarget,                                                    curPos)) {                        // Entity falls                        curFacing = entity.getFacing();                        curPos = entity.getPosition();                        fellDuringMovement = true;                        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);        }        // 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();                vPhaseReport.addElement(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();                vPhaseReport.addElement(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();                    vPhaseReport.addElement(r);                } else if (entity instanceof Infantry) {                    PilotingRollData roll = entity.getBasePilotingRoll();                    roll.addModifier(5, "infantry jumping into swamp");                    if (!doSkillCheckWhileMoving(entity, curPos, curPos, roll, false)) {                        entity.setStuck(true);                        r = new Report(2081);                        r.add(entity.getDisplayName());                        r.subject = entity.getId();                        vPhaseReport.addElement(r);                    }                }            }            // 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();                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 ( 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                r = new Report(2125);                r.subject = entity.getId();                r.addDesc(entity);                vPhaseReport.addElement(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);                    vPhaseReport.addElement(r);                } else {                    // Dislodged swarmers don't get turns.                    game.removeTurnFor( swarmer );                    send( createTurnVectorPacket() );                    // Update the report and the swarmer's status.                    r.choose(true);                    vPhaseReport.addElement(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);                        vPhaseReport.addElement(r);                        vPhaseReport.addAll(                            destroyEntity(swarmer, "a watery grave", false));                    } else {                        // Swarming infantry take an 11 point hit.                        // ASSUMPTION : damage should not be doubled.                        r = new Report(2140);                        r.subject = entity.getId();                        r.indent();                        r.addDesc(swarmer);                        vPhaseReport.addElement(r);                        vPhaseReport.addAll(damageEntity(swarmer, swarmer.rollHitLocation(ToHitData.HIT_NORMAL, ToHitData.SIDE_FRONT), 11));                        Report.addNewline(vPhaseReport);                        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 (fellDuringMovement && 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.        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.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);                vPhaseReport.addElement(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));        }    }