Skip to content

Commit

Permalink
refactor: Use stream composition for C3 with active probes
Browse files Browse the repository at this point in the history
  • Loading branch information
Saklad5 committed Aug 24, 2024
1 parent 12ed947 commit 014cb8f
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions megamek/src/megamek/common/actions/WeaponAttackAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -4424,26 +4424,14 @@ private static ToHitData compileTerrainAndLosToHitMods(Game game, Entity ae, Tar
&& (game.getBoard().getHex(te.getPosition()).containsTerrain(Terrains.WOODS)
|| game.getBoard().getHex(te.getPosition()).containsTerrain(Terrains.JUNGLE));
if (los.canSee() && (targetWoodsAffectModifier || los.thruWoods())) {
boolean bapInRange = Compute.bapInRange(game, ae, te);
boolean c3BAP = false;
if (!bapInRange) {
for (Entity en : game.getC3NetworkMembers(ae)) {
if (ae.equals(en)) {
continue;
}
bapInRange = Compute.bapInRange(game, en, te);
if (bapInRange) {
c3BAP = true;
break;
}
}
}
if (bapInRange) {
if (c3BAP) {
toHit.addModifier(-1, Messages.getString("WeaponAttackAction.BAPInWoodsC3"));
} else {
toHit.addModifier(-1, Messages.getString("WeaponAttackAction.BAPInWoods"));
}
// Necessary for concurrency reasons
final Entity targetEntity = te;
if (Compute.bapInRange(game, ae, targetEntity)) {
toHit.addModifier(-1, Messages.getString("WeaponAttackAction.BAPInWoods"));
} else if (game.getC3NetworkMembers(ae).stream()
.anyMatch(en -> !ae.equals(en) && Compute.bapInRange(game, en, targetEntity))
) {
toHit.addModifier(-1, Messages.getString("WeaponAttackAction.BAPInWoodsC3"));
}
}
}
Expand Down

0 comments on commit 014cb8f

Please sign in to comment.