Skip to content

Commit

Permalink
refactor: Use stream composition for sensor shadows
Browse files Browse the repository at this point in the history
  • Loading branch information
Saklad5 committed Aug 24, 2024
1 parent b21fe79 commit 5b4ce3f
Showing 1 changed file with 21 additions and 14 deletions.
35 changes: 21 additions & 14 deletions megamek/src/megamek/common/actions/WeaponAttackAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -4210,7 +4210,9 @@ else if ((atype != null)

// Aerospace target modifiers
if (te != null && te.isAero() && te.isAirborne()) {
IAero a = (IAero) te;
// Finalized for concurrency reasons
final Entity targetEntity = te;
IAero a = (IAero) targetEntity

// is the target at zero velocity
if ((a.getCurrentVelocity() == 0) && !(a.isSpheroid() && !game.getBoard().inSpace())) {
Expand All @@ -4234,19 +4236,24 @@ else if ((atype != null)
// Target hidden in the sensor shadow of a larger spacecraft
if (game.getOptions().booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_SENSOR_SHADOW)
&& game.getBoard().inSpace()) {
for (Entity en : Compute.getAdjacentEntitiesAlongAttack(ae.getPosition(), target.getPosition(), game)) {
if (!en.isEnemyOf(te) && en.isLargeCraft()
&& ((en.getWeight() - te.getWeight()) >= -STRATOPS_SENSOR_SHADOW_WEIGHT_DIFF)) {
toHit.addModifier(+1, Messages.getString("WeaponAttackAction.SensorShadow"));
break;
}
}
for (Entity en : game.getEntitiesVector(target.getPosition())) {
if (!en.isEnemyOf(te) && en.isLargeCraft() && !en.equals((Entity) a)
&& ((en.getWeight() - te.getWeight()) >= -STRATOPS_SENSOR_SHADOW_WEIGHT_DIFF)) {
toHit.addModifier(+1, Messages.getString("WeaponAttackAction.SensorShadow"));
break;
}
if (Compute.getAdjacentEntitiesAlongAttack(ae.getPosition(), target.getPosition(), game).stream()
.anyMatch(en ->
!en.isEnemyOf(targetEntity)
&& en.isLargeCraft()
&& en.getWeight() - targetEntity.getWeight() >= -STRATOPS_SENSOR_SHADOW_WEIGHT_DIFF
)
) {
toHit.addModifier(+1, Messages.getString("WeaponAttackAction.SensorShadow"));
}
if (game.getEntitiesVector(target.getPosition()).stream()
.anyMatch(en ->
!en.isEnemyOf(targetEntity)
&& en.isLargeCraft()
&& !en.equals(targetEntity)
&& en.getWeight() - targetEntity.getWeight() >= -STRATOPS_SENSOR_SHADOW_WEIGHT_DIFF
)
) {
toHit.addModifier(+1, Messages.getString("WeaponAttackAction.SensorShadow"));
}
}
}
Expand Down

0 comments on commit 5b4ce3f

Please sign in to comment.