use of games.strategy.triplea.TripleAUnit in project triplea by triplea-game.
the class TransportTracker method isTransportUnloadRestrictedToAnotherTerritory.
// In some versions, a transport can never unload into
// multiple territories in a given turn.
// In WW2V1 a transport can unload to multiple territories in
// non-combat phase, provided they are both adjacent to the sea zone.
static boolean isTransportUnloadRestrictedToAnotherTerritory(final Unit transport, final Territory territory) {
final Collection<Unit> unloaded = ((TripleAUnit) transport).getUnloaded();
if (unloaded.isEmpty()) {
return false;
}
// See if transport has unloaded anywhere yet
final GameData data = transport.getData();
for (final Unit u : unloaded) {
final TripleAUnit taUnit = (TripleAUnit) u;
if (isWW2V2(data) || isTransportUnloadRestricted(data)) {
// cannot unload to two different territories
if (!taUnit.getUnloadedTo().equals(territory)) {
return true;
}
} else {
// cannot unload to two different territories in combat phase
if (!GameStepPropertiesHelper.isNonCombatMove(transport.getData(), true) && !taUnit.getUnloadedTo().equals(territory)) {
return true;
}
}
}
return false;
}
use of games.strategy.triplea.TripleAUnit in project triplea by triplea-game.
the class TransportTracker method unloadTransportChange.
static Change unloadTransportChange(final TripleAUnit unit, final Territory territory, final boolean dependentBattle) {
final CompositeChange change = new CompositeChange();
final TripleAUnit transport = (TripleAUnit) transportedBy(unit);
if (transport == null) {
return change;
}
assertTransport(transport);
if (!transport.getTransporting().contains(unit)) {
throw new IllegalStateException("Not being carried, unit:" + unit + " transport:" + transport);
}
final ArrayList<Unit> newUnloaded = new ArrayList<>(transport.getUnloaded());
newUnloaded.add(unit);
change.add(ChangeFactory.unitPropertyChange(unit, territory, TripleAUnit.UNLOADED_TO));
if (!GameStepPropertiesHelper.isNonCombatMove(unit.getData(), true)) {
change.add(ChangeFactory.unitPropertyChange(unit, true, TripleAUnit.UNLOADED_IN_COMBAT_PHASE));
change.add(ChangeFactory.unitPropertyChange(unit, true, TripleAUnit.UNLOADED_AMPHIBIOUS));
change.add(ChangeFactory.unitPropertyChange(transport, true, TripleAUnit.UNLOADED_IN_COMBAT_PHASE));
change.add(ChangeFactory.unitPropertyChange(transport, true, TripleAUnit.UNLOADED_AMPHIBIOUS));
}
if (!dependentBattle) {
// TODO: this is causing issues with Scrambling. if the units were unloaded, then scrambling creates a battle,
// there is no longer any
// way to have the units removed if those transports die.
change.add(ChangeFactory.unitPropertyChange(unit, null, TripleAUnit.TRANSPORTED_BY));
}
change.add(ChangeFactory.unitPropertyChange(transport, newUnloaded, TripleAUnit.UNLOADED));
return change;
}
use of games.strategy.triplea.TripleAUnit in project triplea by triplea-game.
the class TransportTracker method unloadAirTransportChange.
static Change unloadAirTransportChange(final TripleAUnit unit, final Territory territory, final boolean dependentBattle) {
final CompositeChange change = new CompositeChange();
final TripleAUnit transport = (TripleAUnit) transportedBy(unit);
if (transport == null) {
return change;
}
assertTransport(transport);
if (!transport.getTransporting().contains(unit)) {
throw new IllegalStateException("Not being carried, unit:" + unit + " transport:" + transport);
}
final ArrayList<Unit> newUnloaded = new ArrayList<>(transport.getUnloaded());
newUnloaded.add(unit);
change.add(ChangeFactory.unitPropertyChange(unit, territory, TripleAUnit.UNLOADED_TO));
if (!GameStepPropertiesHelper.isNonCombatMove(unit.getData(), true)) {
change.add(ChangeFactory.unitPropertyChange(unit, true, TripleAUnit.UNLOADED_IN_COMBAT_PHASE));
// change.add(ChangeFactory.unitPropertyChange(unit, true, TripleAUnit.UNLOADED_AMPHIBIOUS));
change.add(ChangeFactory.unitPropertyChange(transport, true, TripleAUnit.UNLOADED_IN_COMBAT_PHASE));
// change.add(ChangeFactory.unitPropertyChange(transport, true, TripleAUnit.UNLOADED_AMPHIBIOUS));
}
if (!dependentBattle) {
// TODO: this is causing issues with Scrambling. if the units were unloaded, then scrambling creates a battle,
// there is no longer any
// way to have the units removed if those transports die.
change.add(ChangeFactory.unitPropertyChange(unit, null, TripleAUnit.TRANSPORTED_BY));
}
// change.add(ChangeFactory.unitPropertyChange(transport, newUnloaded, TripleAUnit.UNLOADED));
return change;
}
use of games.strategy.triplea.TripleAUnit in project triplea by triplea-game.
the class TransportTracker method loadTransportChange.
static Change loadTransportChange(final TripleAUnit transport, final Unit unit) {
assertTransport(transport);
final CompositeChange change = new CompositeChange();
// clear the loaded by
change.add(ChangeFactory.unitPropertyChange(unit, transport, TripleAUnit.TRANSPORTED_BY));
final Collection<Unit> newCarrying = new ArrayList<>(transport.getTransporting());
if (newCarrying.contains(unit)) {
throw new IllegalStateException("Already carrying, transport:" + transport + " unt:" + unit);
}
newCarrying.add(unit);
change.add(ChangeFactory.unitPropertyChange(unit, Boolean.TRUE, TripleAUnit.LOADED_THIS_TURN));
change.add(ChangeFactory.unitPropertyChange(transport, true, TripleAUnit.LOADED_THIS_TURN));
// If the transport was in combat, flag it as being loaded AFTER combat
if (transport.getWasInCombat()) {
change.add(ChangeFactory.unitPropertyChange(transport, true, TripleAUnit.LOADED_AFTER_COMBAT));
}
return change;
}
use of games.strategy.triplea.TripleAUnit in project triplea by triplea-game.
the class MoveDelegate method removeMovementFromAirOnDamagedAlliedCarriers.
private static void removeMovementFromAirOnDamagedAlliedCarriers(final IDelegateBridge bridge, final PlayerID player) {
final GameData data = bridge.getData();
final Predicate<Unit> crippledAlliedCarriersMatch = Matches.isUnitAllied(player, data).and(Matches.unitIsOwnedBy(player).negate()).and(Matches.unitIsCarrier()).and(Matches.unitHasWhenCombatDamagedEffect(UnitAttachment.UNITSMAYNOTLEAVEALLIEDCARRIER));
final Predicate<Unit> ownedFightersMatch = Matches.unitIsOwnedBy(player).and(Matches.unitIsAir()).and(Matches.unitCanLandOnCarrier()).and(Matches.unitHasMovementLeft());
final CompositeChange change = new CompositeChange();
for (final Territory t : data.getMap().getTerritories()) {
final Collection<Unit> ownedFighters = t.getUnits().getMatches(ownedFightersMatch);
if (ownedFighters.isEmpty()) {
continue;
}
final Collection<Unit> crippledAlliedCarriers = CollectionUtils.getMatches(t.getUnits().getUnits(), crippledAlliedCarriersMatch);
if (crippledAlliedCarriers.isEmpty()) {
continue;
}
for (final Unit fighter : ownedFighters) {
final TripleAUnit taUnit = (TripleAUnit) fighter;
if (taUnit.getTransportedBy() != null) {
if (crippledAlliedCarriers.contains(taUnit.getTransportedBy())) {
change.add(ChangeFactory.markNoMovementChange(fighter));
}
}
}
}
if (!change.isEmpty()) {
bridge.addChange(change);
}
}
Aggregations