diff --git a/megamek/src/megamek/common/Compute.java b/megamek/src/megamek/common/Compute.java index 03f1fef53a2..21385ba505d 100644 --- a/megamek/src/megamek/common/Compute.java +++ b/megamek/src/megamek/common/Compute.java @@ -5094,10 +5094,14 @@ public static int getSensorRangeBracket(Entity ae, Targetable target, if (ae.getGame().getOptions().booleanOption(OptionsConstants.ADVANCED_METAL_CONTENT)) { check += sensor.getModForMetalContent(ae, te); } + + check += sensor.getModForTargetECM(te, allECMInfo); + } // ECM bubbles check += sensor.getModForECM(ae, allECMInfo); + return Compute.getSensorBracket(check); } diff --git a/megamek/src/megamek/common/ComputeECM.java b/megamek/src/megamek/common/ComputeECM.java index b81853348b1..608af22c1d5 100644 --- a/megamek/src/megamek/common/ComputeECM.java +++ b/megamek/src/megamek/common/ComputeECM.java @@ -517,4 +517,29 @@ public static ArrayList computeAllEntitiesECMInfo( } return worstECMEffects; } + + /** + * Returns the total friendly ECM effects on the supplied unit. + * + * @param affectedEntity The entity to check. + * @param allECMInfo + * @return + */ + public static @Nullable ECMInfo getFriendlyECMEffects(Entity affectedEntity, @Nullable List allEcmInfo){ + if (allEcmInfo == null) { + allEcmInfo = computeAllEntitiesECMInfo(affectedEntity.getGame().getEntitiesVector()); + } + + Coords entityPosition = affectedEntity.getPosition(); + + ECMInfo affectedInfo = new ECMInfo(0, 0, affectedEntity.getOwner(), entityPosition); + for (ECMInfo ecmInfo : allEcmInfo) { + // Is the ECMInfo in range of this position? + int dist = entityPosition.distance(ecmInfo.getPos()); + if (dist <= ecmInfo.getRange()) { + affectedInfo.addAlliedECMEffects(ecmInfo); + } + } + return affectedInfo; + } } diff --git a/megamek/src/megamek/common/Sensor.java b/megamek/src/megamek/common/Sensor.java index c7a78b3ce26..5b7d6a6e344 100644 --- a/megamek/src/megamek/common/Sensor.java +++ b/megamek/src/megamek/common/Sensor.java @@ -438,6 +438,27 @@ public int getModForECM(Entity en, List allECMInfo) { Coords pos = en.getPosition(); ECMInfo ecmInfo = ComputeECM.getECMEffects(en, pos, pos, true, allECMInfo); + return getECMSensorRangeModifier(ecmInfo); + } + + /** + * Computes the sensor check modifier for ECM. + * + * @param targetEntity + * @param allECMInfo A collection of ECMInfo for all entities, this value + * can be null and it will be computed when it's + * needed, however passing in the pre-computed + * collection is much faster + * @return + */ + public int getModForTargetECM(Entity targetEntity, List allECMInfo) { + // how many ECM fields are affecting the target entity? + Coords pos = targetEntity.getPosition(); + ECMInfo ecmInfo = ComputeECM.getFriendlyECMEffects(targetEntity, allECMInfo); + return getECMSensorRangeModifier(ecmInfo); + } + + public int getECMSensorRangeModifier(ECMInfo ecmInfo){ double ecm, ecmAngel; ecm = ecmAngel = 0; if (ecmInfo != null) {