Skip to content

Commit 29643a5

Browse files
committed
refactor: Use stream composition for C3 firing solutions
1 parent be1cec7 commit 29643a5

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
@@ -1274,7 +1274,7 @@ private static String toHitIsImpossible(Game game, Entity ae, int attackerId, Ta
12741274
boolean networkFiringSolution = false;
12751275
//Check to see if the attacker has a firing solution. Naval C3 networks share targeting data
12761276
if (ae.hasNavalC3() && te != null
1277-
&& game.getC3NetworkMembers(ae).stream().anyMatch(en -> en.hasFiringSolutionFor(te.getId())) {
1277+
&& game.getC3NetworkMembers(ae).stream().anyMatch(en -> en.hasFiringSolutionFor(te.getId()))) {
12781278
networkFiringSolution = true;
12791279
}
12801280
if (!networkFiringSolution) {
@@ -1297,15 +1297,14 @@ private static String toHitIsImpossible(Game game, Entity ae, int attackerId, Ta
12971297
&& (te != null) && te.hasSeenEntity(ae.getOwner()))
12981298
&& !isArtilleryIndirect && !isIndirect && !isBearingsOnlyMissile) {
12991299
boolean networkSee = false;
1300-
if (ae.hasC3() || ae.hasC3i() || ae.hasActiveNovaCEWS()) {
1300+
if (ae.hasC3() || ae.hasC3i() || ae.hasActiveNovaCEWS()
1301+
&& game.getEntitiesVector().stream().anyMatch(en ->
1302+
!en.isEnemyOf(ae)
1303+
&& en.onSameC3NetworkAs(ae)
1304+
&& Compute.canSee(game, en, target))) {
13011305
// c3 units can fire if any other unit in their network is in
13021306
// visual or sensor range
1303-
for (Entity en : game.getEntitiesVector()) {
1304-
if (!en.isEnemyOf(ae) && en.onSameC3NetworkAs(ae) && Compute.canSee(game, en, target)) {
1305-
networkSee = true;
1306-
break;
1307-
}
1308-
}
1307+
networkSee = true;
13091308
}
13101309
if (!networkSee) {
13111310
if (!Compute.inSensorRange(game, ae, target, null)) {

0 commit comments

Comments
 (0)