if (target.getTargetType() == Targetable.TYPE_ENTITY) {
if (target != null && target.getTargetType() == Targetable.TYPE_ENTITY) {
    private void resolveDfaAttack(DfaAttackAction daa, int lastEntityId) {        final Entity ae = game.getEntity(daa.getEntityId());        final Targetable target = game.getTarget(daa.getTargetType(), daa.getTargetId());        Entity te = null;        if (target.getTargetType() == Targetable.TYPE_ENTITY) {            te = (Entity)target;        }        // Which building takes the damage?        Building bldg = game.board.getBuildingAt( target.getPosition() );        // is the attacker dead?  because that sure messes up the calculations        if (ae == null) {            return;        }                final int direction = ae.getFacing();                if (lastEntityId != daa.getEntityId()) {            phaseReport.append("\nPhysical attacks for " ).append( ae.getDisplayName() ).append( "\n");        }                // entity isn't charging any more        ae.setDisplacementAttack(null);                // should we even bother?        if ( target.getTargetType() == Targetable.TYPE_ENTITY &&             ( te == null || te.isDestroyed() ||               te.isDoomed() || te.crew.isDead() ) ) {            phaseReport.append("    Death from above deals no damage as the target has been destroyed.\n");            if (ae.isProne()) {                // attacker prone during weapons phase                doEntityFall(ae, daa.getTargetPos(), 2, 3, Compute.getBasePilotingRoll(game, ae.getId()));            } else {                // same effect as successful DFA                doEntityDisplacement(ae, ae.getPosition(), daa.getTargetPos(), new PilotingRollData(ae.getId(), 4, "executed death from above"));            }            return;        }                phaseReport.append("    Attempting death from above on " ).append( target.getDisplayName());                // target still in the same position?        if ( !target.getPosition().equals(daa.getTargetPos()) ) {            phaseReport.append(" but the target has moved.\n");            return;        }                // compute to-hit        ToHitData toHit = Compute.toHitDfa(game, daa);                // hack: if the attacker's prone, or incapacitated, fudge the roll        int roll;        if (ae.isProne() || !ae.isActive()) {            roll = -12;            phaseReport.append(" but the attacker is prone or incapacitated : ");        } else if (toHit.getValue() == ToHitData.IMPOSSIBLE) {            roll = -12;            phaseReport.append(" but the attack is impossible (" ).append( toHit.getDesc() ).append( ") : ");        } else if (toHit.getValue() == ToHitData.AUTOMATIC_SUCCESS) {            phaseReport.append(", the DFA is an automatic hit (" ).append( toHit.getDesc() ).append( "), ");            roll = Integer.MAX_VALUE;        } else {            // roll            roll = Compute.d6(2);            phaseReport.append("; needs " ).append( toHit.getValue() ).append( ", ");            phaseReport.append("rolls " ).append( roll ).append( " : ");        }                // do we hit?        if (roll < toHit.getValue()) {            Coords dest = te.getPosition();            Coords targetDest = Compute.getPreferredDisplacement(game, te.getId(), dest, direction);            phaseReport.append("misses.\n");            if (targetDest != null) {                // move target to preferred hex                doEntityDisplacement(te, dest, targetDest, null);                // attacker falls into destination hex                phaseReport.append(ae.getDisplayName() ).append( " falls into hex " ).append( dest.getBoardNum() ).append( ".\n");                doEntityFall(ae, dest, 2, 3, Compute.getBasePilotingRoll(game, ae.getId()));            } else {                // attacker destroyed                phaseReport.append(destroyEntity(ae, "impossible displacement", false));            }            return;        }                // we hit...        // Can't DFA a target inside of a building.        int damage = Compute.getDfaDamageFor(ae);        int damageTaken = Compute.getDfaDamageTakenBy(ae);                phaseReport.append("hits.");                // Targeting a building.        if ( target.getTargetType() == Targetable.TYPE_BUILDING ) {                    // The building takes the full brunt of the attack.            phaseReport.append( "\n  " )                .append( damageBuilding( bldg, damage ) )                .append( "\n" );                    // Damage any infantry in the hex.            this.damageInfantryIn( bldg, damage );        }        // Target isn't building.        else {            phaseReport.append("\n  Defender takes " ).append( damage ).append( " damage" ).append( toHit.getTableDesc() ).append( ".");            while (damage > 0) {                int cluster = Math.min(5, damage);                HitData hit = te.rollHitLocation(toHit.getHitTable(), toHit.getSideTable());                phaseReport.append(damageEntity(te, hit, cluster));                damage -= cluster;            }        }        phaseReport.append("\n  Attacker takes " ).append( damageTaken ).append( " damage.");        while (damageTaken > 0) {            int cluster = Math.min(5, damageTaken);            HitData hit = ae.rollHitLocation(ToHitData.HIT_KICK, toHit.SIDE_FRONT);            phaseReport.append(damageEntity(ae, hit, cluster));            damageTaken -= cluster;        }        phaseReport.append("\n");        // That's it for target buildings.        // TODO: where do I put the attacker?!?        if ( target.getTargetType() == Targetable.TYPE_BUILDING ) {            return;        }        // Target entities are pushed away or destroyed.        Coords dest = te.getPosition();        Coords targetDest = Compute.getValidDisplacement(game, te.getId(), dest, direction);        if (game.getOptions().booleanOption("push_off_board") && !game.board.contains(dest.translated(direction))) {            game.removeEntity(te.getId(),                              Game.UNIT_IN_RETREAT);            send(createRemoveEntityPacket(te.getId(),                                          Game.UNIT_IN_RETREAT));            phaseReport.append("\n*** " ).append( te.getDisplayName() ).append( " target has been forced from the field. ***\n");        } else {            if (targetDest != null) {                doEntityDisplacement(te, dest, targetDest, new PilotingRollData(te.getId(), 2, "hit by death from above"));            } else {                // ack!  automatic death!                phaseReport.append(destroyEntity(te, "impossible displacement", false));            }        }        // HACK: to avoid automatic falls, displace from dest to dest        doEntityDisplacement(ae, dest, dest, new PilotingRollData(ae.getId(), 4, "executed death from above"));    }