Skip to content

Commit

Permalink
Fix issue a cause of "Could not find step name".
Browse files Browse the repository at this point in the history
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: triplea-game#10647
  • Loading branch information
asvitkine committed Jul 12, 2023
1 parent 559f26c commit 9a5b74d
Showing 1 changed file with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,28 @@ public enum Type {

@Override
public List<FiringGroup> apply(final BattleState battleState) {
final Collection<Unit> 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<Unit> canParticipateInCombat =
Matches.unitCanParticipateInCombat(
side == OFFENSE,
battleState.getPlayer(OFFENSE),
battleState.getBattleSite(),
1,
enemyUnits);
final Collection<Unit> 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
Expand All @@ -68,14 +86,6 @@ public List<FiringGroup> apply(final BattleState battleState) {
Matches.unitIsOwnedBy(battleState.getPlayer(side)))
.build());

final Collection<Unit> 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<FiringGroup> firingGroups = new ArrayList<>();

final List<TargetGroup> targetGroups = TargetGroup.newTargetGroups(canFire, enemyUnits);
Expand Down

0 comments on commit 9a5b74d

Please sign in to comment.