Skip to content

Commit be1cec7

Browse files
committed
refactor: Use stream composition for NC3 firing solutions
1 parent 2db8795 commit be1cec7

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -955,11 +955,8 @@ private static String toHitIsImpossible(Game game, Entity ae, int attackerId, Ta
955955
toHit = new ToHitData();
956956
}
957957

958-
Entity te = null;
959-
if (ttype == Targetable.TYPE_ENTITY) {
960-
//Some weapons only target valid entities
961-
te = (Entity) target;
962-
}
958+
//Some weapons only target valid entities
959+
final Entity te = ttype == Targetable.TYPE_ENTITY ? (Entity) target : null;
963960

964961
// If the attacker and target are in the same building & hex, they can
965962
// always attack each other, TW pg 175.
@@ -1276,13 +1273,9 @@ private static String toHitIsImpossible(Game game, Entity ae, int attackerId, Ta
12761273
&& ae.isSpaceborne()) {
12771274
boolean networkFiringSolution = false;
12781275
//Check to see if the attacker has a firing solution. Naval C3 networks share targeting data
1279-
if (ae.hasNavalC3()) {
1280-
for (Entity en : game.getC3NetworkMembers(ae)) {
1281-
if (te != null && en.hasFiringSolutionFor(te.getId())) {
1282-
networkFiringSolution = true;
1283-
break;
1284-
}
1285-
}
1276+
if (ae.hasNavalC3() && te != null
1277+
&& game.getC3NetworkMembers(ae).stream().anyMatch(en -> en.hasFiringSolutionFor(te.getId())) {
1278+
networkFiringSolution = true;
12861279
}
12871280
if (!networkFiringSolution) {
12881281
//If we don't check for target type here, we can't fire screens and missiles at hexes...

0 commit comments

Comments
 (0)