diff --git a/megamek/src/megamek/common/actions/WeaponAttackAction.java b/megamek/src/megamek/common/actions/WeaponAttackAction.java index 19a137259b1..69f0c5d4171 100644 --- a/megamek/src/megamek/common/actions/WeaponAttackAction.java +++ b/megamek/src/megamek/common/actions/WeaponAttackAction.java @@ -456,48 +456,41 @@ private static ToHitData toHitCalc(Game game, int attackerId, Targetable target, && (munition.contains(AmmoType.Munitions.M_FOLLOW_THE_LEADER) && !ComputeECM.isAffectedByECM(ae, ae.getPosition(), target.getPosition())); - Mounted mLinker = weapon.getLinkedBy(); + Mounted mLinker; - boolean bApollo = ((mLinker != null) && (mLinker.getType() instanceof MiscType) && !mLinker.isDestroyed() - && !mLinker.isMissing() && !mLinker.isBreached() && mLinker.getType().hasFlag(MiscType.F_APOLLO)) - && (atype != null) && (atype.getAmmoType() == AmmoType.T_MRM); + boolean bApollo; - boolean bArtemisV = ((mLinker != null) && (mLinker.getType() instanceof MiscType) && !mLinker.isDestroyed() - && !mLinker.isMissing() && !mLinker.isBreached() && mLinker.getType().hasFlag(MiscType.F_ARTEMIS_V) - && !isECMAffected && !bMekTankStealthActive && (atype != null) - && (munition.contains(AmmoType.Munitions.M_ARTEMIS_V_CAPABLE))); + boolean bArtemisV; - if (ae.usesWeaponBays()) { - for (WeaponMounted bayW : weapon.getBayWeapons()) { - Mounted bayWAmmo = bayW.getLinked(); + (ae.usesWeaponBays() ? weapon.streamBayWeapons() : Stream.of(weapon)).forEach(bayW -> + Mounted bayWAmmo = bayW.getLinked(); - if (bayWAmmo == null) { - //At present, all weapons below using mLinker use ammo, so this won't be a problem - continue; - } - AmmoType bAmmo = (AmmoType) bayWAmmo.getType(); + if (bayWAmmo == null) { + //At present, all weapons below using mLinker use ammo, so this won't be a problem + return; + } + AmmoType bAmmo = (AmmoType) bayWAmmo.getType(); - //If we're using optional rules and firing Arrow Homing missiles from a bay... - isHoming = bAmmo != null && bAmmo.getMunitionType().contains(AmmoType.Munitions.M_HOMING); + //If we're using optional rules and firing Arrow Homing missiles from a bay... + isHoming = bAmmo != null && bAmmo.getMunitionType().contains(AmmoType.Munitions.M_HOMING); - //If the artillery bay is firing cruise missiles, they have some special rules - //It is possible to combine cruise missiles and other artillery in a bay, so - //set this to true if any of the weapons are cruise missile launchers. - if (bayW.getType().hasFlag(WeaponType.F_CRUISE_MISSILE)) { - isCruiseMissile = true; - } + //If the artillery bay is firing cruise missiles, they have some special rules + //It is possible to combine cruise missiles and other artillery in a bay, so + //set this to true if any of the weapons are cruise missile launchers. + if (bayW.getType().hasFlag(WeaponType.F_CRUISE_MISSILE)) { + isCruiseMissile = true; + } - mLinker = bayW.getLinkedBy(); - bApollo = ((mLinker != null) && (mLinker.getType() instanceof MiscType) && !mLinker.isDestroyed() - && !mLinker.isMissing() && !mLinker.isBreached() && mLinker.getType().hasFlag(MiscType.F_APOLLO)) - && (bAmmo != null) && (bAmmo.getAmmoType() == AmmoType.T_MRM); + mLinker = bayW.getLinkedBy(); + bApollo = ((mLinker != null) && (mLinker.getType() instanceof MiscType) && !mLinker.isDestroyed() + && !mLinker.isMissing() && !mLinker.isBreached() && mLinker.getType().hasFlag(MiscType.F_APOLLO)) + && (bAmmo != null) && (bAmmo.getAmmoType() == AmmoType.T_MRM); - bArtemisV = ((mLinker != null) && (mLinker.getType() instanceof MiscType) && !mLinker.isDestroyed() - && !mLinker.isMissing() && !mLinker.isBreached() && mLinker.getType().hasFlag(MiscType.F_ARTEMIS_V) - && !isECMAffected && !bMekTankStealthActive && (atype != null) - && (bAmmo != null) && (bAmmo.getMunitionType().contains(AmmoType.Munitions.M_ARTEMIS_V_CAPABLE))); - } - } + bArtemisV = ((mLinker != null) && (mLinker.getType() instanceof MiscType) && !mLinker.isDestroyed() + && !mLinker.isMissing() && !mLinker.isBreached() && mLinker.getType().hasFlag(MiscType.F_ARTEMIS_V) + && !isECMAffected && !bMekTankStealthActive && (atype != null) + && (bAmmo != null) && (bAmmo.getMunitionType().contains(AmmoType.Munitions.M_ARTEMIS_V_CAPABLE))); + ); boolean inSameBuilding = Compute.isInSameBuilding(game, ae, te);