diff --git a/game-app/game-core/src/main/java/games/strategy/triplea/delegate/battle/steps/fire/general/FiringGroupSplitterGeneral.java b/game-app/game-core/src/main/java/games/strategy/triplea/delegate/battle/steps/fire/general/FiringGroupSplitterGeneral.java index 9bf9ccca39a..1b3d4e925f2 100644 --- a/game-app/game-core/src/main/java/games/strategy/triplea/delegate/battle/steps/fire/general/FiringGroupSplitterGeneral.java +++ b/game-app/game-core/src/main/java/games/strategy/triplea/delegate/battle/steps/fire/general/FiringGroupSplitterGeneral.java @@ -56,10 +56,28 @@ public enum Type { @Override public List apply(final BattleState battleState) { + final Collection enemyUnits = + CollectionUtils.getMatches( + battleState.filterUnits(ALIVE, side.getOpposite()), + PredicateBuilder.of(Matches.unitIsNotInfrastructure()) + .andIf(side == DEFENSE, Matches.unitIsSuicideOnAttack().negate()) + .andIf(side == OFFENSE, Matches.unitIsSuicideOnDefense().negate()) + .build()); + + // Filter participants (same as is done in MustFightBattle.removeNonCombatants()), so that we + // don't end up generating combat step names for units that will be excluded. + final Predicate canParticipateInCombat = + Matches.unitCanParticipateInCombat( + side == OFFENSE, + battleState.getPlayer(OFFENSE), + battleState.getBattleSite(), + 1, + enemyUnits); final Collection canFire = CollectionUtils.getMatches( battleState.filterUnits(ACTIVE, side), PredicateBuilder.of(getFiringUnitPredicate(battleState)) + .and(canParticipateInCombat) // Remove offense allied units if allied air can not participate .andIf( side == OFFENSE @@ -68,14 +86,6 @@ public List apply(final BattleState battleState) { Matches.unitIsOwnedBy(battleState.getPlayer(side))) .build()); - final Collection enemyUnits = - CollectionUtils.getMatches( - battleState.filterUnits(ALIVE, side.getOpposite()), - PredicateBuilder.of(Matches.unitIsNotInfrastructure()) - .andIf(side == DEFENSE, Matches.unitIsSuicideOnAttack().negate()) - .andIf(side == OFFENSE, Matches.unitIsSuicideOnDefense().negate()) - .build()); - final List firingGroups = new ArrayList<>(); final List targetGroups = TargetGroup.newTargetGroups(canFire, enemyUnits);