resolveChargeDamage( ae, te, toHit, direction );
resolveChargeDamage( ae, te, toHit, direction, glancing );
    private void resolveChargeAttack(PhysicalResult pr, int lastEntityId) {    	final ChargeAttackAction caa = (ChargeAttackAction)pr.aaa;        final Entity ae = game.getEntity(caa.getEntityId());        final Targetable target = game.getTarget(caa.getTargetType(), caa.getTargetId());        // get damage, ToHitData and roll from the PhysicalResult        int damage = pr.damage;        final ToHitData toHit = pr.toHit;        int roll = pr.roll;        Entity te = null;        if (target != null && target.getTargetType() == Targetable.TYPE_ENTITY) {            te = (Entity)target;        }        // Which building takes the damage?        Building bldg = game.board.getBuildingAt( caa.getTargetPos() );        // is the attacker dead?  because that sure messes up the calculations        if (ae == null) {            return;        }        final int direction = ae.getFacing();        // entity isn't charging any more        ae.setDisplacementAttack(null);        if (lastEntityId != caa.getEntityId()) {            phaseReport.append("\nPhysical attacks for " ).append( ae.getDisplayName() ).append( "\n");        }        // should we even bother?        if (target == null || (target.getTargetType() == Targetable.TYPE_ENTITY             && (te.isDestroyed() || te.isDoomed() || te.crew.isDead()))) {            phaseReport.append("    Charge cancelled as the target has been destroyed.\n");            // doEntityDisplacement(ae, ae.getPosition(), caa.getTargetPos(), null);            // Randall said that if a charge fails because of target destruction,            // the attacker stays in the hex he was in at the end of the movement phase            // See Bug 912094            return;        }        // attacker fell down?        if (ae.isProne()) {            phaseReport.append("    Charge cancelled as the attacker has fallen.\n");            return;        }        // attacker immobile?        if (ae.isImmobile()) {            phaseReport.append("    Charge cancelled as the attacker has been immobilized.\n");            return;        }                if (te.isProne()) {            phaseReport.append("    Charge cancelled as the target has fallen.\n");            return;        }        phaseReport.append("    Charging " ).append( target.getDisplayName());        // target still in the same position?        if (!target.getPosition().equals(caa.getTargetPos())) {            phaseReport.append(" but the target has moved.\n");            doEntityDisplacement(ae, ae.getPosition(), caa.getTargetPos(), null);            return;        }        // if the attacker's prone, fudge the roll        if (toHit.getValue() == ToHitData.IMPOSSIBLE) {            roll = -12;            phaseReport.append(", but the charge is impossible (" ).append( toHit.getDesc() ).append( ") : ");        } else if (toHit.getValue() == ToHitData.AUTOMATIC_SUCCESS) {            phaseReport.append(", the charge is an automatic hit (" ).append( toHit.getDesc() ).append( "), ");            roll = Integer.MAX_VALUE;        } else {            // report the roll            phaseReport.append("; needs " ).append( toHit.getValue() ).append( ", ");            phaseReport.append("rolls " ).append( roll ).append( " : ");        }        // do we hit?        if (roll < toHit.getValue()) {            Coords src = ae.getPosition();            Coords dest = Compute.getMissedChargeDisplacement(game, ae.getId(), src, direction);            // TODO: handle movement into/out of/through a building.  Do it here?            phaseReport.append("misses.\n");            // move attacker to side hex            doEntityDisplacement(ae, src, dest, null);        }        // Targeting a building.        else if ( target.getTargetType() == Targetable.TYPE_BUILDING ) {            // The building takes the full brunt of the attack.            phaseReport.append( "hits.\n  " )                .append( damageBuilding( bldg, damage ) );            // Damage any infantry in the hex.            this.damageInfantryIn( bldg, damage );            // Apply damage to the attacker.            int toAttacker = ChargeAttackAction.getChargeDamageTakenBy( ae, bldg );            HitData hit = ae.rollHitLocation( ToHitData.HIT_NORMAL,                                              Compute.targetSideTable(target.getPosition(), ae.getPosition(), ae.getFacing(), false)                                                  );            phaseReport.append( this.damageEntity( ae, hit, toAttacker ) )                .append( "\n" );            entityUpdate( ae.getId() );            // TODO: Does the attacker enter the building?            // TODO: What if the building collapses?        }        else {            // Resolve the damage.            resolveChargeDamage( ae, te, toHit, direction );        }        return;    }