From 9a5b74d60326a6f2cd46e51b2d70bf8a6d74b3cd Mon Sep 17 00:00:00 2001 From: asvitkine Date: Wed, 12 Jul 2023 16:38:29 -0400 Subject: [PATCH] Fix issue a cause of "Could not find step name". This was happening because the code to generate step names was not excluding units that would not participate in combat, resulting in infrastructure units getting their own steps (which later did not match what the engine generated once the filtering took place). Uses the same logic as what's done for the battle to exclude units. Fixes: https://github.com/triplea-game/triplea/issues/10647 --- .../general/FiringGroupSplitterGeneral.java | 26 +++++++++++++------ 1 file changed, 18 insertions(+), 8 deletions(-) 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);