@Override
protected void handleEntityDamage(Entity entityTarget, Vector<Report> vPhaseReport, Building bldg, int hits, int nCluster, int nDamPerHit, int bldgAbsorbs) {
int nDamage;
missed = false;
HitData hit = entityTarget.rollHitLocation(toHit.getHitTable(), toHit.getSideTable(), waa.getAimedLocation(), waa.getAimingMode());
hit.setGeneralDamageType(generalDamageType);
if (entityTarget.removePartialCoverHits(hit.getLocation(), toHit.getCover(), Compute.targetSideTable(ae, entityTarget))) {
// Weapon strikes Partial Cover.
r = new Report(3460);
r.subject = subjectId;
r.add(entityTarget.getShortName());
r.add(entityTarget.getLocationAbbr(hit));
r.newlines = 0;
r.indent(2);
vPhaseReport.addElement(r);
nDamage = 0;
missed = true;
return;
}
if (!bSalvo) {
// Each hit in the salvo get's its own hit location.
r = new Report(3405);
r.subject = subjectId;
r.add(toHit.getTableDesc());
r.add(entityTarget.getLocationAbbr(hit));
r.newlines = 0;
vPhaseReport.addElement(r);
}
// Resolve damage normally.
nDamage = nDamPerHit * Math.min(nCluster, hits);
// A building may be damaged, even if the squad is not.
if (bldgAbsorbs > 0) {
int toBldg = Math.min(bldgAbsorbs, nDamage);
nDamage -= toBldg;
Report.addNewline(vPhaseReport);
Vector<Report> buildingReport = server.damageBuilding(bldg, toBldg, entityTarget.getPosition());
for (Report report : buildingReport) {
report.subject = subjectId;
}
vPhaseReport.addAll(buildingReport);
}
nDamage = checkTerrain(nDamage, entityTarget,vPhaseReport);
// A building may absorb the entire shot.
if (nDamage == 0) {
r = new Report(3415);
r.subject = subjectId;
r.indent(2);
r.addDesc(entityTarget);
r.newlines = 0;
vPhaseReport.addElement(r);
missed = true;
} else {
if (bGlancing) {
hit.makeGlancingBlow();
}
if ( bDirect && (!(target instanceof Infantry) || (target instanceof BattleArmor))){
hit.makeDirectBlow(toHit.getMoS()/3);
}
if ( (target instanceof BattleArmor) && (((BattleArmor)target).getInternal(hit.getLocation()) != IArmorState.ARMOR_DOOMED) ){
int roll = Compute.d6(2);
int loc = hit.getLocation();
if ( roll >= 10 ){
hit = new HitData(loc, false, HitData.EFFECT_CRITICAL);
}
} else if ((target instanceof Tank) || (target instanceof Mech)) {
if ( bGlancing ) {
hit.setSpecCritmod(-4);
} else if ( bDirect ) {
hit.setSpecCritmod((toHit.getMoS()/3)-2);
} else {
hit.setSpecCritmod(-2);
}
if (entityTarget.hasBARArmor()) {
hit.setSpecCritmod(hit.getSpecCritMod()+2);
}
}
vPhaseReport.addAll(server.damageEntity(entityTarget, hit, nDamage, false, ae.getSwarmTargetId() == entityTarget.getId() ? DamageType.IGNORE_PASSENGER : DamageType.NONE, false, false, throughFront, underWater));
}
}