use of games.strategy.engine.data.CompositeChange in project triplea by triplea-game.
the class MustFightBattle method submergeUnits.
private void submergeUnits(final Collection<Unit> submerging, final boolean defender, final IDelegateBridge bridge) {
final String transcriptText = MyFormatter.unitsToText(submerging) + " Submerged";
final Collection<Unit> units = defender ? m_defendingUnits : m_attackingUnits;
final Collection<Unit> unitsRetreated = defender ? m_defendingUnitsRetreated : m_attackingUnitsRetreated;
final CompositeChange change = new CompositeChange();
for (final Unit u : submerging) {
change.add(ChangeFactory.unitPropertyChange(u, true, TripleAUnit.SUBMERGED));
}
bridge.addChange(change);
units.removeAll(submerging);
unitsRetreated.addAll(submerging);
if (!units.isEmpty() && !m_isOver) {
getDisplay(bridge).notifyRetreat(m_battleID, submerging);
}
bridge.getHistoryWriter().addChildToEvent(transcriptText, new ArrayList<>(submerging));
}
use of games.strategy.engine.data.CompositeChange in project triplea by triplea-game.
the class MustFightBattle method landParatroops.
private void landParatroops(final IDelegateBridge bridge) {
if (TechAttachment.isAirTransportable(m_attacker)) {
final Collection<Unit> airTransports = CollectionUtils.getMatches(m_battleSite.getUnits().getUnits(), Matches.unitIsAirTransport());
if (!airTransports.isEmpty()) {
final Collection<Unit> dependents = getDependentUnits(airTransports);
if (!dependents.isEmpty()) {
final CompositeChange change = new CompositeChange();
// remove dependency from paratroopers by unloading the air transports
for (final Unit unit : dependents) {
change.add(TransportTracker.unloadAirTransportChange((TripleAUnit) unit, m_battleSite, false));
}
bridge.addChange(change);
// remove bombers from m_dependentUnits
for (final Unit unit : airTransports) {
m_dependentUnits.remove(unit);
}
}
}
}
}
use of games.strategy.engine.data.CompositeChange in project triplea by triplea-game.
the class MustFightBattle method retreatFromNonCombat.
/**
* Retreat landed units from allied territory when their transport retreats.
*/
private Change retreatFromNonCombat(Collection<Unit> units, final Territory retreatTo) {
final CompositeChange change = new CompositeChange();
units = CollectionUtils.getMatches(units, Matches.unitIsTransport());
final Collection<Unit> retreated = getTransportDependents(units);
if (!retreated.isEmpty()) {
for (final Unit unit : units) {
final Territory retreatedFrom = TransportTracker.getTerritoryTransportHasUnloadedTo(unit);
if (retreatedFrom != null) {
reLoadTransports(units, change);
change.add(ChangeFactory.moveUnits(retreatedFrom, retreatTo, retreated));
}
}
}
return change;
}
use of games.strategy.engine.data.CompositeChange in project triplea by triplea-game.
the class MustFightBattle method retreatFromDependents.
private Change retreatFromDependents(final Collection<Unit> units, final Territory retreatTo, final Collection<IBattle> dependentBattles) {
final CompositeChange change = new CompositeChange();
for (final IBattle dependent : dependentBattles) {
final Route route = new Route();
route.setStart(m_battleSite);
route.add(dependent.getTerritory());
final Collection<Unit> retreatedUnits = dependent.getDependentUnits(units);
dependent.removeAttack(route, retreatedUnits);
reLoadTransports(units, change);
change.add(ChangeFactory.moveUnits(dependent.getTerritory(), retreatTo, retreatedUnits));
}
return change;
}
use of games.strategy.engine.data.CompositeChange in project triplea by triplea-game.
the class MustFightBattle method retreatUnitsAndPlanes.
private void retreatUnitsAndPlanes(final Collection<Unit> retreating, final Territory to, final boolean defender, final IDelegateBridge bridge) {
// Remove air from battle
final Collection<Unit> units = defender ? m_defendingUnits : m_attackingUnits;
final Collection<Unit> unitsRetreated = defender ? m_defendingUnitsRetreated : m_attackingUnitsRetreated;
units.removeAll(CollectionUtils.getMatches(units, Matches.unitIsAir()));
// add all land units' dependents
retreating.addAll(getDependentUnits(units));
// our own air units don't retreat with land units
final Predicate<Unit> notMyAir = Matches.unitIsNotAir().or(Matches.unitIsOwnedBy(m_attacker).negate());
final Collection<Unit> nonAirRetreating = CollectionUtils.getMatches(retreating, notMyAir);
final String transcriptText = MyFormatter.unitsToTextNoOwner(nonAirRetreating) + " retreated to " + to.getName();
bridge.getHistoryWriter().addChildToEvent(transcriptText, new ArrayList<>(nonAirRetreating));
final CompositeChange change = new CompositeChange();
change.add(ChangeFactory.moveUnits(m_battleSite, to, nonAirRetreating));
if (m_isOver) {
final Collection<IBattle> dependentBattles = m_battleTracker.getBlocked(this);
// If there are no dependent battles, check landings in allied territories
if (dependentBattles.isEmpty()) {
change.add(retreatFromNonCombat(nonAirRetreating, to));
// Else retreat the units from combat when their transport retreats
} else {
change.add(retreatFromDependents(nonAirRetreating, to, dependentBattles));
}
}
bridge.addChange(change);
units.removeAll(nonAirRetreating);
unitsRetreated.addAll(nonAirRetreating);
if (units.isEmpty() || m_isOver) {
endBattle(bridge);
if (defender) {
attackerWins(bridge);
} else {
defenderWins(bridge);
}
} else {
getDisplay(bridge).notifyRetreat(m_battleID, retreating);
}
}
Aggregations