use of games.strategy.triplea.delegate.IBattle.BattleType in project triplea by triplea-game.
the class ProSimulateTurnUtils method simulateBattles.
public static void simulateBattles(final GameData data, final PlayerID player, final IDelegateBridge delegateBridge, final ProOddsCalculator calc) {
ProLogger.info("Starting battle simulation phase");
final BattleDelegate battleDelegate = DelegateFinder.battleDelegate(data);
final Map<BattleType, Collection<Territory>> battleTerritories = battleDelegate.getBattles().getBattles();
for (final Entry<BattleType, Collection<Territory>> entry : battleTerritories.entrySet()) {
for (final Territory t : entry.getValue()) {
final IBattle battle = battleDelegate.getBattleTracker().getPendingBattle(t, entry.getKey().isBombingRun(), entry.getKey());
final List<Unit> attackers = (List<Unit>) battle.getAttackingUnits();
attackers.retainAll(t.getUnits().getUnits());
final List<Unit> defenders = (List<Unit>) battle.getDefendingUnits();
defenders.retainAll(t.getUnits().getUnits());
final Set<Unit> bombardingUnits = new HashSet<>(battle.getBombardingUnits());
ProLogger.debug("---" + t);
ProLogger.debug("attackers=" + attackers);
ProLogger.debug("defenders=" + defenders);
ProLogger.debug("bombardingUnits=" + bombardingUnits);
final ProBattleResult result = calc.callBattleCalculator(t, attackers, defenders, bombardingUnits);
final List<Unit> remainingUnits = result.getAverageAttackersRemaining();
ProLogger.debug("remainingUnits=" + remainingUnits);
// Make updates to data
final List<Unit> attackersToRemove = new ArrayList<>(attackers);
attackersToRemove.removeAll(remainingUnits);
final List<Unit> defendersToRemove = CollectionUtils.getMatches(defenders, Matches.unitIsInfrastructure().negate());
final List<Unit> infrastructureToChangeOwner = CollectionUtils.getMatches(defenders, Matches.unitIsInfrastructure());
ProLogger.debug("attackersToRemove=" + attackersToRemove);
ProLogger.debug("defendersToRemove=" + defendersToRemove);
ProLogger.debug("infrastructureToChangeOwner=" + infrastructureToChangeOwner);
final Change attackerskilledChange = ChangeFactory.removeUnits(t, attackersToRemove);
delegateBridge.addChange(attackerskilledChange);
final Change defenderskilledChange = ChangeFactory.removeUnits(t, defendersToRemove);
delegateBridge.addChange(defenderskilledChange);
BattleTracker.captureOrDestroyUnits(t, player, player, delegateBridge, null);
if (!checkIfCapturedTerritoryIsAlliedCapital(t, data, player, delegateBridge)) {
delegateBridge.addChange(ChangeFactory.changeOwner(t, player));
}
battleDelegate.getBattleTracker().getConquered().add(t);
battleDelegate.getBattleTracker().removeBattle(battle);
final Territory updatedTerritory = data.getMap().getTerritory(t.getName());
ProLogger.debug("after changes owner=" + updatedTerritory.getOwner() + ", units=" + updatedTerritory.getUnits().getUnits());
}
}
}
use of games.strategy.triplea.delegate.IBattle.BattleType in project triplea by triplea-game.
the class BattlePanel method display.
@Override
public void display(final PlayerID id) {
super.display(id);
SwingUtilities.invokeLater(() -> {
removeAll();
actionLabel.setText(id.getName() + " battle");
setLayout(new BorderLayout());
final JPanel panel = JPanelBuilder.builder().gridLayout(0, 1).add(actionLabel).build();
for (final Entry<BattleType, Collection<Territory>> entry : battles.entrySet()) {
for (final Territory t : entry.getValue()) {
addBattleActions(panel, t, entry.getKey().isBombingRun(), entry.getKey());
}
}
add(panel, BorderLayout.NORTH);
SwingUtilities.invokeLater(refresh);
});
}
Aggregations