Skip to content

Commit f168263

Browse files
committed
refactor: Use stream composition for C3 firing solutions
1 parent b5df54d commit f168263

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

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

+7-8
Original file line numberDiff line numberDiff line change
@@ -1277,7 +1277,7 @@ private static String toHitIsImpossible(Game game, Entity ae, int attackerId, Ta
12771277
boolean networkFiringSolution = false;
12781278
//Check to see if the attacker has a firing solution. Naval C3 networks share targeting data
12791279
if (ae.hasNavalC3() && te != null
1280-
&& game.getC3NetworkMembers(ae).stream().anyMatch(en -> en.hasFiringSolutionFor(te.getId())) {
1280+
&& game.getC3NetworkMembers(ae).stream().anyMatch(en -> en.hasFiringSolutionFor(te.getId()))) {
12811281
networkFiringSolution = true;
12821282
}
12831283
if (!networkFiringSolution) {
@@ -1300,15 +1300,14 @@ private static String toHitIsImpossible(Game game, Entity ae, int attackerId, Ta
13001300
&& (te != null) && te.hasSeenEntity(ae.getOwner()))
13011301
&& !isArtilleryIndirect && !isIndirect && !isBearingsOnlyMissile) {
13021302
boolean networkSee = false;
1303-
if (ae.hasC3() || ae.hasC3i() || ae.hasActiveNovaCEWS()) {
1303+
if (ae.hasC3() || ae.hasC3i() || ae.hasActiveNovaCEWS()
1304+
&& game.getEntitiesVector().stream().anyMatch(en ->
1305+
!en.isEnemyOf(ae)
1306+
&& en.onSameC3NetworkAs(ae)
1307+
&& Compute.canSee(game, en, target))) {
13041308
// c3 units can fire if any other unit in their network is in
13051309
// visual or sensor range
1306-
for (Entity en : game.getEntitiesVector()) {
1307-
if (!en.isEnemyOf(ae) && en.onSameC3NetworkAs(ae) && Compute.canSee(game, en, target)) {
1308-
networkSee = true;
1309-
break;
1310-
}
1311-
}
1310+
networkSee = true;
13121311
}
13131312
if (!networkSee) {
13141313
if (!Compute.inSensorRange(game, ae, target, null)) {

0 commit comments

Comments
 (0)