From 33a1c1fbc960a4dd784a275f66907b9181c0d184 Mon Sep 17 00:00:00 2001 From: Jeremy Saklad Date: Sat, 24 Aug 2024 16:57:27 -0500 Subject: [PATCH] refactor: Use stream composition for C3 with active probes --- .../common/actions/WeaponAttackAction.java | 26 +++++-------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/megamek/src/megamek/common/actions/WeaponAttackAction.java b/megamek/src/megamek/common/actions/WeaponAttackAction.java index d71f1a4d9a3..b0a36494f92 100644 --- a/megamek/src/megamek/common/actions/WeaponAttackAction.java +++ b/megamek/src/megamek/common/actions/WeaponAttackAction.java @@ -4424,26 +4424,12 @@ 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")); - } + if (Compute.bapInRange(game, ae, te)) { + toHit.addModifier(-1, Messages.getString("WeaponAttackAction.BAPInWoods")); + } else if (game.getC3NetworkMembers(ae).stream() + .anyMatch(en -> !ae.equals(en) && Compute.bapInRange(game, en, target)) + ) { + toHit.addModifier(-1, Messages.getString("WeaponAttackAction.BAPInWoodsC3")); } } }