Skip to content

Commit

Permalink
Issue 3827: Fixes target's side's ECM not effecting sensor spotting
Browse files Browse the repository at this point in the history
  • Loading branch information
psikomonkie committed Dec 1, 2024
1 parent 8bfe368 commit dcac807
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
4 changes: 4 additions & 0 deletions megamek/src/megamek/common/Compute.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
25 changes: 25 additions & 0 deletions megamek/src/megamek/common/ComputeECM.java
Original file line number Diff line number Diff line change
Expand Up @@ -517,4 +517,29 @@ public static ArrayList<ECMInfo> computeAllEntitiesECMInfo(
}
return worstECMEffects;
}

/**
* Returns the total friendly ECM effects on the supplied unit.
*
* @param affectedEntity The entity to check.
* @param allECMInfo

Check notice

Code scanning / CodeQL

Spurious Javadoc @param tags Note

@param tag "allECMInfo" does not match any actual parameter of method "getFriendlyECMEffects()".
* @return
*/
public static @Nullable ECMInfo getFriendlyECMEffects(Entity affectedEntity, @Nullable List<ECMInfo> 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;
}
}
21 changes: 21 additions & 0 deletions megamek/src/megamek/common/Sensor.java
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,27 @@ public int getModForECM(Entity en, List<ECMInfo> 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<ECMInfo> allECMInfo) {
// how many ECM fields are affecting the target entity?
Coords pos = targetEntity.getPosition();

Check notice

Code scanning / CodeQL

Unread local variable Note

Variable 'Coords pos' is never read.
ECMInfo ecmInfo = ComputeECM.getFriendlyECMEffects(targetEntity, allECMInfo);
return getECMSensorRangeModifier(ecmInfo);
}

public int getECMSensorRangeModifier(ECMInfo ecmInfo){
double ecm, ecmAngel;
ecm = ecmAngel = 0;
if (ecmInfo != null) {
Expand Down

0 comments on commit dcac807

Please sign in to comment.