Skip to content

Commit e6131e9

Browse files
committed
refactor: Use stream composition for sensor shadows
1 parent b21fe79 commit e6131e9

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

megamek/src/megamek/common/actions/WeaponAttackAction.java

+19-14
Original file line numberDiff line numberDiff line change
@@ -4210,7 +4210,7 @@ else if ((atype != null)
42104210

42114211
// Aerospace target modifiers
42124212
if (te != null && te.isAero() && te.isAirborne()) {
4213-
IAero a = (IAero) te;
4213+
final IAero a = (IAero) te;
42144214

42154215
// is the target at zero velocity
42164216
if ((a.getCurrentVelocity() == 0) && !(a.isSpheroid() && !game.getBoard().inSpace())) {
@@ -4234,19 +4234,24 @@ else if ((atype != null)
42344234
// Target hidden in the sensor shadow of a larger spacecraft
42354235
if (game.getOptions().booleanOption(OptionsConstants.ADVAERORULES_STRATOPS_SENSOR_SHADOW)
42364236
&& game.getBoard().inSpace()) {
4237-
for (Entity en : Compute.getAdjacentEntitiesAlongAttack(ae.getPosition(), target.getPosition(), game)) {
4238-
if (!en.isEnemyOf(te) && en.isLargeCraft()
4239-
&& ((en.getWeight() - te.getWeight()) >= -STRATOPS_SENSOR_SHADOW_WEIGHT_DIFF)) {
4240-
toHit.addModifier(+1, Messages.getString("WeaponAttackAction.SensorShadow"));
4241-
break;
4242-
}
4243-
}
4244-
for (Entity en : game.getEntitiesVector(target.getPosition())) {
4245-
if (!en.isEnemyOf(te) && en.isLargeCraft() && !en.equals((Entity) a)
4246-
&& ((en.getWeight() - te.getWeight()) >= -STRATOPS_SENSOR_SHADOW_WEIGHT_DIFF)) {
4247-
toHit.addModifier(+1, Messages.getString("WeaponAttackAction.SensorShadow"));
4248-
break;
4249-
}
4237+
if (Compute.getAdjacentEntitiesAlongAttack(ae.getPosition(), target.getPosition(), game).stream()
4238+
.anyMatch(en ->
4239+
!en.isEnemyOf(a)
4240+
&& en.isLargeCraft()
4241+
&& en.getWeight() - a.getWeight() >= -STRATOPS_SENSOR_SHADOW_WEIGHT_DIFF
4242+
)
4243+
) {
4244+
toHit.addModifier(+1, Messages.getString("WeaponAttackAction.SensorShadow"));
4245+
}
4246+
if (game.getEntitiesVector(target.getPosition()).stream()
4247+
.anyMatch(en ->
4248+
!en.isEnemyOf(a)
4249+
&& en.isLargeCraft()
4250+
&& !en.equals(a)
4251+
&& en.getWeight() - a.getWeight() >= -STRATOPS_SENSOR_SHADOW_WEIGHT_DIFF
4252+
)
4253+
) {
4254+
toHit.addModifier(+1, Messages.getString("WeaponAttackAction.SensorShadow"));
42504255
}
42514256
}
42524257
}

0 commit comments

Comments
 (0)