Skip to content

Commit

Permalink
refactor: Use stream composition for C3 firing solutions
Browse files Browse the repository at this point in the history
  • Loading branch information
Saklad5 committed Aug 18, 2024
1 parent ddb0a7e commit f1df6d9
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions megamek/src/megamek/common/actions/WeaponAttackAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -1276,7 +1276,7 @@ private static String toHitIsImpossible(Game game, Entity ae, int attackerId, Ta
boolean networkFiringSolution = false;
//Check to see if the attacker has a firing solution. Naval C3 networks share targeting data
if (ae.hasNavalC3() && te != null
&& game.getC3NetworkMembers(ae).stream().anyMatch(en -> en.hasFiringSolutionFor(te.getId())) {
&& game.getC3NetworkMembers(ae).stream().anyMatch(en -> en.hasFiringSolutionFor(te.getId()))) {
networkFiringSolution = true;
}
if (!networkFiringSolution) {
Expand All @@ -1299,15 +1299,14 @@ private static String toHitIsImpossible(Game game, Entity ae, int attackerId, Ta
&& (te != null) && te.hasSeenEntity(ae.getOwner()))
&& !isArtilleryIndirect && !isIndirect && !isBearingsOnlyMissile) {
boolean networkSee = false;
if (ae.hasC3() || ae.hasC3i() || ae.hasActiveNovaCEWS()) {
if (ae.hasC3() || ae.hasC3i() || ae.hasActiveNovaCEWS()
&& game.getEntitiesVector().stream().anyMatch(en ->
!en.isEnemyOf(ae)
&& en.onSameC3NetworkAs(ae)
&& Compute.canSee(game, en, target))) {
// c3 units can fire if any other unit in their network is in
// visual or sensor range
for (Entity en : game.getEntitiesVector()) {
if (!en.isEnemyOf(ae) && en.onSameC3NetworkAs(ae) && Compute.canSee(game, en, target)) {
networkSee = true;
break;
}
}
networkSee = true;
}
if (!networkSee) {
if (!Compute.inSensorRange(game, ae, target, null)) {
Expand Down

0 comments on commit f1df6d9

Please sign in to comment.