Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix up and reinstate #1646 to not remove infrastructure units #2080

Merged
merged 2 commits into from
Sep 14, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/main/java/games/strategy/triplea/delegate/MustFightBattle.java
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,13 @@ List<IExecutable> getBattleExecutables(final boolean firstRun) {

@Override
public void execute(final ExecutionStack stack, final IDelegateBridge bridge) {
if (getBattlePower(true, m_attackingUnits, bridge, new ArrayList<>()) > 0) {
final List<Unit> unitsToRemove = new ArrayList<>();
if (getBattlePower(false, m_defendingUnits, bridge, unitsToRemove) == 0) {
remove(new ArrayList<>(Match.getMatches(unitsToRemove, Matches.UnitIsInfrastructure.invert())),
bridge, m_battleSite, true);
}
}
clearWaitingToDie(bridge);
}
});
Expand Down Expand Up @@ -2758,6 +2765,19 @@ public void unitsLostInPrecedingBattle(final IBattle battle, final Collection<Un
}
}

private int getBattlePower(final boolean attack, final List<Unit> units, final IDelegateBridge bridge,
final List<Unit> unitsToRemove) {
final Match<Unit> unitTypes = Matches.unitCanBeInBattle(attack, !m_battleSite.isWater(), 1, false, !attack, true);
final List<Unit> sortedUnits = new ArrayList<>(Match.getMatches(units, unitTypes));
Collections.sort(sortedUnits, new UnitBattleComparator(false,
BattleCalculator.getCostsForTUV(bridge.getPlayerID(), m_data),
TerritoryEffectHelper.getEffects(m_battleSite), m_data, false, false));
Collections.reverse(sortedUnits);
unitsToRemove.addAll(sortedUnits);
return DiceRoll.getTotalPower(DiceRoll.getUnitPowerAndRollsForNormalBattles(sortedUnits, units, attack,
false, m_data, m_battleSite, TerritoryEffectHelper.getEffects(m_battleSite), false, null), m_data);
}

/**
* Returns a map of transport -> collection of transported units.
*/
Expand Down