Skip to content

Commit

Permalink
Fix MegaMek#5375: quirks and SPAs applying twice to ADA missiles only
Browse files Browse the repository at this point in the history
  • Loading branch information
Sleet01 committed Apr 19, 2024
1 parent 0742934 commit e3850c8
Showing 1 changed file with 26 additions and 16 deletions.
42 changes: 26 additions & 16 deletions megamek/src/megamek/common/actions/WeaponAttackAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -4937,10 +4937,19 @@ private static ToHitData artilleryDirectToHit(Game game, Entity ae, Targetable t
// Return without SRT set so that regular to-hit mods get applied.
return toHit;
}

// ADA has its to-hit mods calculated separately; handle other direct artillery quirk and SPA mods here:
// Quirks
processAttackerQuirks(toHit, ae, te, weapon);

// SPAs
processAttackerSPAs(toHit, ae, te, weapon, game);
processDefenderSPAs(toHit, ae, te, weapon, game);

//If an airborne unit occupies the target hex, standard artillery ammo makes a flak attack against it
//TN is a flat 3 + the altitude mod + the attacker's weapon skill - 2 for Flak
//Grounded/destroyed/landed/wrecked ASF/VTOL/WiGE should be treated as normal.
else if ((isArtilleryFLAK || (atype.countsAsFlak())) && te != null) {
if ((isArtilleryFLAK || (atype.countsAsFlak())) && te != null) {
if (te.isAirborne() || te.isAirborneVTOLorWIGE()) {
toHit.addModifier(3, Messages.getString("WeaponAttackAction.ArtyFlak"));
toHit.addModifier(-2, Messages.getString("WeaponAttackAction.Flak"));
Expand Down Expand Up @@ -5077,18 +5086,6 @@ private static ToHitData handleArtilleryAttacks(Game game, Entity ae, Targetable
te = (Entity) target;
}

if (toHit == null) {
// Without valid toHit data, the rest of this will fail
toHit = new ToHitData();
}

// Quirks
processAttackerQuirks(toHit, ae, te, weapon);

// SPAs
processAttackerSPAs(toHit, ae, te, weapon, game);
processDefenderSPAs(toHit, ae, te, weapon, game);

//Homing warheads just need a flat 4 to seek out a successful TAG, but Princess needs help
//judging what a good homing target is.
if (isHoming) {
Expand Down Expand Up @@ -5120,16 +5117,29 @@ private static ToHitData handleArtilleryAttacks(Game game, Entity ae, Targetable
return new ToHitData(TargetRoll.AUTOMATIC_SUCCESS, Messages.getString("WeaponAttackAction.ArtyDesTarget"));
}

// If we're not skipping To-Hit calculations, ensure that we have a toHit instance
if (toHit == null) {
// Without valid toHit data, the rest of this will fail
toHit = new ToHitData();
}

// Handle direct artillery attacks.
if (isArtilleryDirect) {
return artilleryDirectToHit(game, ae, target, ttype, losMods, toHit, wtype,
weapon, atype, isArtilleryFLAK, usesAmmo, srt
);
}
//And now for indirect artillery fire
if (isArtilleryIndirect) {
} else if (isArtilleryIndirect) {
//And now for indirect artillery fire; process quirks and SPAs here or they'll be missed
// Quirks
processAttackerQuirks(toHit, ae, te, weapon);

// SPAs
processAttackerSPAs(toHit, ae, te, weapon, game);
processDefenderSPAs(toHit, ae, te, weapon, game);

return artilleryIndirectToHit(ae, target, toHit, wtype, weapon, srt);
}

//If we get here, this isn't an artillery attack
return toHit;
}
Expand Down

0 comments on commit e3850c8

Please sign in to comment.