/**
* Handle a death from above attack
*/
private void resolveDfaAttack(PhysicalResult pr, int lastEntityId) {
final DfaAttackAction daa = (DfaAttackAction) pr.aaa;
final Entity ae = game.getEntity(daa.getEntityId());
final Targetable target = game.getTarget(daa.getTargetType(), daa.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)) {
// Lets re-write around that horrible hack that was here before.
// So instead of asking if a specific location is wet and praying
// that it won't cause an NPE...
// We'll check 1) if the hex has water, and 2) if it's deep enough
// to cover the unit in question at its current elevation.
// It's especially important to make sure it's done this way,
// because some units (Sylph, submarines) can be at ANY elevation
// underwater, and VTOLs can be well above the surface.
te = (Entity) target;
IHex hex = game.getBoard().getHex(te.getPosition());
if (hex.containsTerrain(Terrains.WATER)) {
if (te.absHeight() < hex.getElevation()) {
damage = (int) Math.ceil(damage * 0.5f);
}
}
}
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(daa.getTargetPos());
// is the attacker dead? because that sure messes up the calculations
if (ae == null) {
return;
}
final int direction = ae.getFacing();
if (lastEntityId != daa.getEntityId()) {
// who is making the attack
r = new Report(4005);
r.subject = ae.getId();
r.addDesc(ae);
addReport(r);
}
// entity isn't DFAing any more
ae.setDisplacementAttack(null);
// should we even bother?
if ((target == null) || ((target.getTargetType() == Targetable.TYPE_ENTITY) && (te.isDestroyed() || te.isDoomed() || te.crew.isDead()))) {
r = new Report(4245);
r.subject = ae.getId();
r.indent();
addReport(r);
if (ae.isProne()) {
// attacker prone during weapons phase
addReport(doEntityFall(ae, daa.getTargetPos(), 2, 3, ae.getBasePilotingRoll()));
} else {
// same effect as successful DFA
addReport(doEntityDisplacement(ae, ae.getPosition(), daa.getTargetPos(), new PilotingRollData(ae.getId(), 4, "executed death from above")));
}
return;
}
r = new Report(4246);
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(daa.getTargetPos())) {
r = new Report(4215);
r.subject = ae.getId();
addReport(r);
addReport(doEntityFallsInto(ae, ae.getPosition(), daa.getTargetPos(), ae.getBasePilotingRoll()));
return;
}
// hack: if the attacker's prone, or incapacitated, fudge the roll
if (ae.isProne() || !ae.isActive()) {