Esempio n. 1
0
  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);
    }
  }
Esempio n. 2
0
 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);
   }
 }
Esempio n. 3
0
 /**
  * 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);
 }