Skip to content

Commit

Permalink
refactor: Use stream composition for NC3 firing solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
Saklad5 committed Aug 18, 2024
1 parent 2db8795 commit be1cec7
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions megamek/src/megamek/common/actions/WeaponAttackAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -955,11 +955,8 @@ private static String toHitIsImpossible(Game game, Entity ae, int attackerId, Ta
toHit = new ToHitData();
}

Entity te = null;
if (ttype == Targetable.TYPE_ENTITY) {
//Some weapons only target valid entities
te = (Entity) target;
}
//Some weapons only target valid entities
final Entity te = ttype == Targetable.TYPE_ENTITY ? (Entity) target : null;

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

0 comments on commit be1cec7

Please sign in to comment.