/**
* Handle a charge attack
*/
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;
}
boolean throughFront = true;
if (te != null) {
throughFront = Compute.isThroughFrontHex(game, ae.getPosition(), te);
}
final boolean glancing = game.getOptions().booleanOption("tacops_glancing_blows") && (roll == toHit.getValue());
// Set Margin of Success/Failure.
toHit.setMoS(roll - Math.max(2, toHit.getValue()));
final boolean directBlow = game.getOptions().booleanOption("tacops_direct_blow") && ((toHit.getMoS() / 3) >= 1);
Report r;
// Which building takes the damage?
Building bldg = game.getBoard().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()) {
// who is making the attack
r = new Report(4005);
r.subject = ae.getId();
r.addDesc(ae);
addReport(r);
}
// should we even bother?
if ((target == null) || ((target.getTargetType() == Targetable.TYPE_ENTITY) && (te.isDestroyed() || te.isDoomed() || te.crew.isDead()))) {
r = new Report(4190);
r.subject = ae.getId();
r.indent();
addReport(r);
// 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()) {
r = new Report(4195);
r.subject = ae.getId();
r.indent();
addReport(r);
return;
}
// attacker immobile?
if (ae.isImmobile()) {
r = new Report(4200);
r.subject = ae.getId();
r.indent();
addReport(r);
return;
}
// target fell down, only for attacking Mechs, though
if ((te != null) && (te.isProne()) && (ae instanceof Mech)) {
r = new Report(4205);
r.subject = ae.getId();
r.indent();
addReport(r);
return;
}
r = new Report(4210);
r.subject = ae.getId();
r.indent();
r.add(target.getDisplayName());
r.newlines = 0;
addReport(r);
// target still in the same position?
if (!target.getPosition().equals(caa.getTargetPos())) {
r = new Report(4215);
r.subject = ae.getId();
addReport(r);
addReport(doEntityDisplacement(ae, ae.getPosition(), caa.getTargetPos(), null));
return;
}
// if the attacker's prone, fudge the roll
if (toHit.getValue() == TargetRoll.IMPOSSIBLE) {