Search in sources :

Example 11 with RelationshipType

use of games.strategy.engine.data.RelationshipType in project triplea by triplea-game.

the class PoliticsDelegate method getNeutralOutOfWarWithAllies.

private static void getNeutralOutOfWarWithAllies(final PoliticalActionAttachment paa, final PlayerID player, final IDelegateBridge bridge) {
    final GameData data = bridge.getData();
    if (!Properties.getAlliancesCanChainTogether(data)) {
        return;
    }
    final Collection<PlayerID> players = data.getPlayerList().getPlayers();
    final Collection<PlayerID> p1AlliedWith = CollectionUtils.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 otherPlayer = (p1.equals(player) ? p2 : p1);
        final RelationshipType currentType = data.getRelationshipTracker().getRelationshipType(p1, p2);
        final RelationshipType newType = data.getRelationshipTypeList().getRelationshipType(relationshipChange[2]);
        if (Matches.relationshipTypeIsAtWar().test(currentType) && Matches.relationshipTypeIsAtWar().negate().test(newType)) {
            final Collection<PlayerID> otherPlayersAlliedWith = CollectionUtils.getMatches(players, Matches.isAlliedAndAlliancesCanChainTogether(otherPlayer, data));
            if (!otherPlayersAlliedWith.contains(otherPlayer)) {
                otherPlayersAlliedWith.add(otherPlayer);
            }
            if (!p1AlliedWith.contains(player)) {
                p1AlliedWith.add(player);
            }
            for (final PlayerID p3 : p1AlliedWith) {
                for (final PlayerID p4 : otherPlayersAlliedWith) {
                    final RelationshipType currentOther = data.getRelationshipTracker().getRelationshipType(p3, p4);
                    if (!currentOther.equals(newType) && Matches.relationshipTypeIsAtWar().test(currentOther)) {
                        change.add(ChangeFactory.relationshipChange(p3, p4, currentOther, newType));
                        bridge.getHistoryWriter().addChildToEvent(p3.getName() + " and " + p4.getName() + " sign a " + newType.getName() + " treaty");
                        MoveDelegate.getBattleTracker(data).addRelationshipChangesThisTurn(p3, p4, currentOther, newType);
                    }
                }
            }
        }
    }
    if (!change.isEmpty()) {
        bridge.addChange(change);
    }
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) GameData(games.strategy.engine.data.GameData) RelationshipType(games.strategy.engine.data.RelationshipType) CompositeChange(games.strategy.engine.data.CompositeChange)

Example 12 with RelationshipType

use of games.strategy.engine.data.RelationshipType in project triplea by triplea-game.

the class PoliticsDelegate method getMyselfOutOfAlliance.

private static void getMyselfOutOfAlliance(final PoliticalActionAttachment paa, final PlayerID player, final IDelegateBridge bridge) {
    final GameData data = bridge.getData();
    if (!Properties.getAlliancesCanChainTogether(data)) {
        return;
    }
    final Collection<PlayerID> players = data.getPlayerList().getPlayers();
    final Collection<PlayerID> p1AlliedWith = CollectionUtils.getMatches(players, Matches.isAlliedAndAlliancesCanChainTogether(player, data));
    p1AlliedWith.remove(player);
    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 otherPlayer = (p1.equals(player) ? p2 : p1);
        if (!p1AlliedWith.contains(otherPlayer)) {
            continue;
        }
        final RelationshipType currentType = data.getRelationshipTracker().getRelationshipType(p1, p2);
        final RelationshipType newType = data.getRelationshipTypeList().getRelationshipType(relationshipChange[2]);
        if (Matches.relationshipTypeIsAlliedAndAlliancesCanChainTogether().test(currentType) && Matches.relationshipTypeIsAlliedAndAlliancesCanChainTogether().negate().test(newType)) {
            for (final PlayerID p3 : p1AlliedWith) {
                final RelationshipType currentOther = data.getRelationshipTracker().getRelationshipType(p3, player);
                if (!currentOther.equals(newType)) {
                    change.add(ChangeFactory.relationshipChange(p3, player, currentOther, newType));
                    bridge.getHistoryWriter().addChildToEvent(player.getName() + " and " + p3.getName() + " sign a " + newType.getName() + " treaty");
                    MoveDelegate.getBattleTracker(data).addRelationshipChangesThisTurn(p3, player, currentOther, newType);
                }
            }
        }
    }
    if (!change.isEmpty()) {
        bridge.addChange(change);
    }
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) GameData(games.strategy.engine.data.GameData) RelationshipType(games.strategy.engine.data.RelationshipType) CompositeChange(games.strategy.engine.data.CompositeChange)

Example 13 with RelationshipType

use of games.strategy.engine.data.RelationshipType in project triplea by triplea-game.

the class TriggerAttachment method setRelationshipTypes.

private void setRelationshipTypes(final String names) throws GameParseException {
    final String[] s = names.split(":");
    for (final String element : s) {
        final RelationshipType relation = getData().getRelationshipTypeList().getRelationshipType(element);
        if (relation == null) {
            throw new GameParseException("Could not find relationshipType. name:" + element + thisErrorMsg());
        }
        m_relationshipTypes.add(relation);
    }
}
Also used : RelationshipType(games.strategy.engine.data.RelationshipType) GameParseException(games.strategy.engine.data.GameParseException)

Example 14 with RelationshipType

use of games.strategy.engine.data.RelationshipType in project triplea by triplea-game.

the class ProUtils method getPotentialEnemyPlayers.

public static List<PlayerID> getPotentialEnemyPlayers(final PlayerID player) {
    final GameData data = ProData.getData();
    final List<PlayerID> otherPlayers = data.getPlayerList().getPlayers();
    for (final Iterator<PlayerID> it = otherPlayers.iterator(); it.hasNext(); ) {
        final PlayerID otherPlayer = it.next();
        final RelationshipType relation = data.getRelationshipTracker().getRelationshipType(player, otherPlayer);
        if (Matches.relationshipTypeIsAllied().test(relation) || isNeutralPlayer(otherPlayer)) {
            it.remove();
        }
    }
    return otherPlayers;
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) GameData(games.strategy.engine.data.GameData) RelationshipType(games.strategy.engine.data.RelationshipType)

Example 15 with RelationshipType

use of games.strategy.engine.data.RelationshipType in project triplea by triplea-game.

the class RulesAttachment method checkRelationships.

/**
 * checks if all relationship requirements are set
 *
 * @return whether all relationships as are required are set correctly.
 */
private boolean checkRelationships() {
    for (final String encodedRelationCheck : m_relationship) {
        final String[] relationCheck = encodedRelationCheck.split(":");
        final PlayerID p1 = getData().getPlayerList().getPlayerId(relationCheck[0]);
        final PlayerID p2 = getData().getPlayerList().getPlayerId(relationCheck[1]);
        final int relationshipsExistance = Integer.parseInt(relationCheck[3]);
        final Relationship currentRelationship = getData().getRelationshipTracker().getRelationship(p1, p2);
        final RelationshipType currentRelationshipType = currentRelationship.getRelationshipType();
        if (!relationShipExistsLongEnnough(currentRelationship, relationshipsExistance)) {
            return false;
        }
        if (!((relationCheck[2].equals(Constants.RELATIONSHIP_CONDITION_ANY_ALLIED) && Matches.relationshipTypeIsAllied().test(currentRelationshipType)) || (relationCheck[2].equals(Constants.RELATIONSHIP_CONDITION_ANY_NEUTRAL) && Matches.relationshipTypeIsNeutral().test(currentRelationshipType)) || (relationCheck[2].equals(Constants.RELATIONSHIP_CONDITION_ANY_WAR) && Matches.relationshipTypeIsAtWar().test(currentRelationshipType)) || currentRelationshipType.equals(getData().getRelationshipTypeList().getRelationshipType(relationCheck[2])))) {
            return false;
        }
    }
    return true;
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Relationship(games.strategy.engine.data.RelationshipTracker.Relationship) RelationshipType(games.strategy.engine.data.RelationshipType)

Aggregations

RelationshipType (games.strategy.engine.data.RelationshipType)17 PlayerID (games.strategy.engine.data.PlayerID)13 GameData (games.strategy.engine.data.GameData)6 CompositeChange (games.strategy.engine.data.CompositeChange)5 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 GameParseException (games.strategy.engine.data.GameParseException)1 RelationshipTracker (games.strategy.engine.data.RelationshipTracker)1 Relationship (games.strategy.engine.data.RelationshipTracker.Relationship)1 ProTerritory (games.strategy.triplea.ai.pro.data.ProTerritory)1 ProTerritoryManager (games.strategy.triplea.ai.pro.data.ProTerritoryManager)1 PoliticalActionAttachment (games.strategy.triplea.attachments.PoliticalActionAttachment)1 PoliticsDelegate (games.strategy.triplea.delegate.PoliticsDelegate)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1 List (java.util.List)1 JButton (javax.swing.JButton)1 JComponent (javax.swing.JComponent)1 JLabel (javax.swing.JLabel)1 JPanel (javax.swing.JPanel)1