private static void getNeutralOutOfWarWithAllies( final PoliticalActionAttachment paa, final PlayerID player, final IDelegateBridge aBridge) { final GameData data = aBridge.getData(); if (!games.strategy.triplea.Properties.getAlliancesCanChainTogether(data)) { return; } final Collection<PlayerID> players = data.getPlayerList().getPlayers(); final Collection<PlayerID> p1AlliedWith = Match.getMatches(players, Matches.isAlliedAndAlliancesCanChainTogether(player, data)); final CompositeChange change = new CompositeChange(); for (final String relationshipChangeString : paa.getRelationshipChange()) { final String[] relationshipChange = relationshipChangeString.split(":"); final PlayerID p1 = data.getPlayerList().getPlayerID(relationshipChange[0]); final PlayerID p2 = data.getPlayerList().getPlayerID(relationshipChange[1]); if (!(p1.equals(player) || p2.equals(player))) { continue; } final PlayerID pOther = (p1.equals(player) ? p2 : p1); final RelationshipType currentType = data.getRelationshipTracker().getRelationshipType(p1, p2); final RelationshipType newType = data.getRelationshipTypeList().getRelationshipType(relationshipChange[2]); if (Matches.RelationshipTypeIsAtWar.match(currentType) && Matches.RelationshipTypeIsAtWar.invert().match(newType)) { final Collection<PlayerID> pOtherAlliedWith = Match.getMatches(players, Matches.isAlliedAndAlliancesCanChainTogether(pOther, data)); if (!pOtherAlliedWith.contains(pOther)) { pOtherAlliedWith.add(pOther); } if (!p1AlliedWith.contains(player)) { p1AlliedWith.add(player); } for (final PlayerID p3 : p1AlliedWith) { for (final PlayerID p4 : pOtherAlliedWith) { final RelationshipType currentOther = data.getRelationshipTracker().getRelationshipType(p3, p4); if (!currentOther.equals(newType) && Matches.RelationshipTypeIsAtWar.match(currentOther)) { change.add(ChangeFactory.relationshipChange(p3, p4, currentOther, newType)); aBridge .getHistoryWriter() .addChildToEvent( p3.getName() + " and " + p4.getName() + " sign a " + newType.getName() + " treaty"); MoveDelegate.getBattleTracker(data) .addRelationshipChangesThisTurn(p3, p4, currentOther, newType); } } } } } if (!change.isEmpty()) { aBridge.addChange(change); } }
public static void givesBackOriginalTerritories(final IDelegateBridge aBridge) { final GameData data = aBridge.getData(); final CompositeChange change = new CompositeChange(); final Collection<PlayerID> players = data.getPlayerList().getPlayers(); for (final PlayerID p1 : players) { for (final PlayerID p2 : players) { if (!data.getRelationshipTracker().givesBackOriginalTerritories(p1, p2)) { continue; } for (final Territory t : data.getMap().getTerritoriesOwnedBy(p1)) { final PlayerID original = OriginalOwnerTracker.getOriginalOwner(t); if (original == null) { continue; } if (original.equals(p2)) { change.add(ChangeFactory.changeOwner(t, original)); } } } } if (!change.isEmpty()) { aBridge.getHistoryWriter().startEvent("Giving back territories to original owners"); aBridge.addChange(change); } }
public 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<Unit>(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; }
public static Change unloadAirTransportChange( final TripleAUnit unit, final Territory territory, final PlayerID id, 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<Unit>(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)); } // dependencies for battle calc and casualty selection include unloaded. therefore even if we // have unloaded this unit, it will die if // air transport dies IF we have the unloaded flat set. so don't set it. // TODO: fix this bullshit by re-writing entire transportation engine // change.add(ChangeFactory.unitPropertyChange(transport, newUnloaded, TripleAUnit.UNLOADED)); return change; }
/** * Changes all relationships * * @param paa the political action to change the relationships for */ private void changeRelationships(final PoliticalActionAttachment paa) { getMyselfOutOfAlliance(paa, m_player, m_bridge); getNeutralOutOfWarWithAllies(paa, m_player, m_bridge); final CompositeChange change = new CompositeChange(); for (final String relationshipChange : paa.getRelationshipChange()) { final String[] s = relationshipChange.split(":"); final PlayerID player1 = getData().getPlayerList().getPlayerID(s[0]); final PlayerID player2 = getData().getPlayerList().getPlayerID(s[1]); final RelationshipType oldRelation = getData().getRelationshipTracker().getRelationshipType(player1, player2); final RelationshipType newRelation = getData().getRelationshipTypeList().getRelationshipType(s[2]); if (oldRelation.equals(newRelation)) { continue; } change.add(ChangeFactory.relationshipChange(player1, player2, oldRelation, newRelation)); m_bridge .getHistoryWriter() .addChildToEvent( m_bridge.getPlayerID().getName() + " succeeds on action: " + MyFormatter.attachmentNameToText(paa.getName()) + ": Changing Relationship for " + player1.getName() + " and " + player2.getName() + " from " + oldRelation.getName() + " to " + newRelation.getName()); MoveDelegate.getBattleTracker(getData()) .addRelationshipChangesThisTurn(player1, player2, oldRelation, newRelation); /* * creation of new battles is handled at the beginning of the battle delegate, in * "setupUnitsInSameTerritoryBattles", not here. * if (Matches.RelationshipTypeIsAtWar.match(newRelation)) * TriggerAttachment.triggerMustFightBattle(player1, player2, m_bridge); */ } if (!change.isEmpty()) { m_bridge.addChange(change); } chainAlliancesTogether(m_bridge); }
public static Change unloadTransportChange( final TripleAUnit unit, final Territory territory, final PlayerID id, 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<Unit>(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; }
public static Change combatTransportChange(final TripleAUnit transport, final PlayerID id) { assertTransport(transport); final CompositeChange change = new CompositeChange(); change.add(ChangeFactory.unitPropertyChange(transport, true, TripleAUnit.WAS_IN_COMBAT)); return change; }