use of games.strategy.engine.data.Unit in project triplea by triplea-game.
the class MustFightBattle method reLoadTransports.
void reLoadTransports(final Collection<Unit> units, final CompositeChange change) {
final Collection<Unit> transports = CollectionUtils.getMatches(units, Matches.unitCanTransport());
// Put units back on their transports
for (final Unit transport : transports) {
final Collection<Unit> unloaded = TransportTracker.unloaded(transport);
for (final Unit load : unloaded) {
final Change loadChange = TransportTracker.loadTransportChange((TripleAUnit) transport, load);
change.add(loadChange);
}
}
}
use of games.strategy.engine.data.Unit in project triplea by triplea-game.
the class MustFightBattle method removeAttack.
@Override
public void removeAttack(final Route route, final Collection<Unit> units) {
m_attackingUnits.removeAll(units);
// the route could be null, in the case of a unit in a territory where a sub is submerged.
if (route == null) {
return;
}
final Territory attackingFrom = route.getTerritoryBeforeEnd();
Collection<Unit> attackingFromMapUnits = m_attackingFromMap.get(attackingFrom);
// handle possible null pointer
if (attackingFromMapUnits == null) {
attackingFromMapUnits = new ArrayList<>();
}
attackingFromMapUnits.removeAll(units);
if (attackingFromMapUnits.isEmpty()) {
m_attackingFrom.remove(attackingFrom);
}
// deal with amphibious assaults
if (attackingFrom.isWater()) {
if (route.getEnd() != null && !route.getEnd().isWater() && units.stream().anyMatch(Matches.unitIsLand())) {
m_amphibiousLandAttackers.removeAll(CollectionUtils.getMatches(units, Matches.unitIsLand()));
}
// that territory is no longer an amphibious assault
if (attackingFromMapUnits.stream().noneMatch(Matches.unitIsLand())) {
getAmphibiousAttackTerritories().remove(attackingFrom);
// do we have any amphibious attacks left?
m_isAmphibious = !getAmphibiousAttackTerritories().isEmpty();
}
}
for (final Collection<Unit> dependents : m_dependentUnits.values()) {
dependents.removeAll(units);
}
}
use of games.strategy.engine.data.Unit 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.Unit 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.Unit in project triplea by triplea-game.
the class MustFightBattle method defenderWins.
private void defenderWins(final IDelegateBridge bridge) {
m_whoWon = WhoWon.DEFENDER;
getDisplay(bridge).battleEnd(m_battleID, m_defender.getName() + " win");
if (Properties.getAbandonedTerritoriesMayBeTakenOverImmediately(m_data)) {
if (CollectionUtils.getMatches(m_defendingUnits, Matches.unitIsNotInfrastructure()).size() == 0) {
final List<Unit> allyOfAttackerUnits = m_battleSite.getUnits().getMatches(Matches.unitIsNotInfrastructure());
if (!allyOfAttackerUnits.isEmpty()) {
final PlayerID abandonedToPlayer = AbstractBattle.findPlayerWithMostUnits(allyOfAttackerUnits);
bridge.getHistoryWriter().addChildToEvent(abandonedToPlayer.getName() + " takes over " + m_battleSite.getName() + " as there are no defenders left", allyOfAttackerUnits);
// should we create a new battle records to show the ally capturing the territory (in the case where they
// didn't already own/allied it)?
m_battleTracker.takeOver(m_battleSite, abandonedToPlayer, bridge, null, allyOfAttackerUnits);
}
} else {
// should we create a new battle records to show the defender capturing the territory (in the case where they
// didn't already own/allied it)?
m_battleTracker.takeOver(m_battleSite, m_defender, bridge, null, m_defendingUnits);
}
}
bridge.getHistoryWriter().addChildToEvent(m_defender.getName() + " win", new ArrayList<>(m_defendingUnits));
m_battleResultDescription = BattleRecord.BattleResultDescription.LOST;
showCasualties(bridge);
if (!m_headless) {
m_battleTracker.getBattleRecords().addResultToBattle(m_attacker, m_battleID, m_defender, m_attackerLostTUV, m_defenderLostTUV, m_battleResultDescription, new BattleResults(this, m_data));
}
checkDefendingPlanesCanLand();
BattleTracker.captureOrDestroyUnits(m_battleSite, m_defender, m_defender, bridge, null);
if (!m_headless) {
bridge.getSoundChannelBroadcaster().playSoundForAll(SoundPath.CLIP_BATTLE_FAILURE, m_attacker);
}
}
Aggregations