Exemplo 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);
    }
  }
Exemplo n.º 2
0
 /**
  * Get a list of players that should accept this action and then ask each player if it accepts
  * this action.
  *
  * @param paa the politicalActionAttachment that should be accepted
  */
 private boolean actionIsAccepted(final PoliticalActionAttachment paa) {
   final GameData data = getData();
   final CompositeMatchOr<PoliticalActionAttachment> intoAlliedChainOrIntoOrOutOfWar =
       new CompositeMatchOr<>(
           Matches.politicalActionIsRelationshipChangeOf(
               null,
               Matches.RelationshipTypeIsAlliedAndAlliancesCanChainTogether.invert(),
               Matches.RelationshipTypeIsAlliedAndAlliancesCanChainTogether,
               data),
           Matches.politicalActionIsRelationshipChangeOf(
               null,
               Matches.RelationshipTypeIsAtWar.invert(),
               Matches.RelationshipTypeIsAtWar,
               data),
           Matches.politicalActionIsRelationshipChangeOf(
               null,
               Matches.RelationshipTypeIsAtWar,
               Matches.RelationshipTypeIsAtWar.invert(),
               data));
   if (!games.strategy.triplea.Properties.getAlliancesCanChainTogether(data)
       || !intoAlliedChainOrIntoOrOutOfWar.match(paa)) {
     for (final PlayerID player : paa.getActionAccept()) {
       if (!(getRemotePlayer(player))
           .acceptAction(
               m_player, PoliticsText.getInstance().getAcceptanceQuestion(paa.getText()), true)) {
         return false;
       }
     }
   } else {
     // if alliances chain together, then our allies must have a say in anyone becoming a new
     // ally/enemy
     final LinkedHashSet<PlayerID> playersWhoNeedToAccept = new LinkedHashSet<>();
     playersWhoNeedToAccept.addAll(paa.getActionAccept());
     playersWhoNeedToAccept.addAll(
         Match.getMatches(
             data.getPlayerList().getPlayers(),
             Matches.isAlliedAndAlliancesCanChainTogether(m_player, data)));
     for (final PlayerID player : paa.getActionAccept()) {
       playersWhoNeedToAccept.addAll(
           Match.getMatches(
               data.getPlayerList().getPlayers(),
               Matches.isAlliedAndAlliancesCanChainTogether(player, data)));
     }
     final HashSet<PlayerID> alliesWhoMustAccept = playersWhoNeedToAccept;
     alliesWhoMustAccept.removeAll(paa.getActionAccept());
     for (final PlayerID player : playersWhoNeedToAccept) {
       String actionText = PoliticsText.getInstance().getAcceptanceQuestion(paa.getText());
       if (actionText.equals("NONE")) {
         actionText =
             m_player.getName()
                 + " wants to take the following action: "
                 + MyFormatter.attachmentNameToText(paa.getName())
                 + " \r\n Do you approve?";
       } else {
         actionText =
             m_player.getName()
                 + " wants to take the following action: "
                 + MyFormatter.attachmentNameToText(paa.getName())
                 + ".  Do you approve? \r\n\r\n "
                 + m_player.getName()
                 + " will ask "
                 + MyFormatter.defaultNamedToTextList(paa.getActionAccept())
                 + ", the following question: \r\n "
                 + actionText;
       }
       if (!(getRemotePlayer(player)).acceptAction(m_player, actionText, true)) {
         return false;
       }
     }
     for (final PlayerID player : paa.getActionAccept()) {
       if (!(getRemotePlayer(player))
           .acceptAction(
               m_player, PoliticsText.getInstance().getAcceptanceQuestion(paa.getText()), true)) {
         return false;
       }
     }
   }
   return true;
 }