use of games.strategy.engine.data.RelationshipType in project triplea by triplea-game.
the class AiPoliticalUtils method awayFromAlly.
private static boolean awayFromAlly(final PoliticalActionAttachment nextAction, final PlayerID p0, final GameData data) {
for (final String relationshipChangeString : nextAction.getRelationshipChange()) {
final String[] relationshipChange = relationshipChangeString.split(":");
final PlayerID p1 = data.getPlayerList().getPlayerId(relationshipChange[0]);
final PlayerID p2 = data.getPlayerList().getPlayerId(relationshipChange[1]);
// only continue if p1 or p2 is the AI
if (p0.equals(p1) || p0.equals(p2)) {
final RelationshipType currentType = data.getRelationshipTracker().getRelationshipType(p1, p2);
final RelationshipType newType = data.getRelationshipTypeList().getRelationshipType(relationshipChange[2]);
if (currentType.getRelationshipTypeAttachment().isAllied() && (newType.getRelationshipTypeAttachment().isNeutral() || newType.getRelationshipTypeAttachment().isWar())) {
return true;
}
}
}
return false;
}
use of games.strategy.engine.data.RelationshipType in project triplea by triplea-game.
the class PoliticalStateOverview method getRelationshipLabel.
/**
* Gets a label showing the coloured relationshipName between these two
* players.
*/
private JPanel getRelationshipLabel(final PlayerID player1, final PlayerID player2) {
RelationshipType relType = null;
for (final Triple<PlayerID, PlayerID, RelationshipType> changesSoFar : editChanges) {
if ((player1.equals(changesSoFar.getFirst()) && player2.equals(changesSoFar.getSecond())) || (player2.equals(changesSoFar.getFirst()) && player1.equals(changesSoFar.getSecond()))) {
relType = changesSoFar.getThird();
}
}
if (relType == null) {
data.acquireReadLock();
try {
relType = data.getRelationshipTracker().getRelationshipType(player1, player2);
} finally {
data.releaseReadLock();
}
}
final JComponent relationshipLabel = getRelationshipComponent(player1, player2, relType);
final JPanel relationshipLabelPanel = new JPanel();
relationshipLabelPanel.add(relationshipLabel);
relationshipLabelPanel.setBackground(getRelationshipTypeColor(relType));
return relationshipLabelPanel;
}
use of games.strategy.engine.data.RelationshipType in project triplea by triplea-game.
the class PoliticalStateOverview method getRelationshipComponent.
private JComponent getRelationshipComponent(final PlayerID player1, final PlayerID player2, final RelationshipType relType) {
if (!editable) {
return new JLabel(relType.getName());
}
final JButton button = new JButton(relType.getName());
button.addActionListener(e -> {
final List<RelationshipType> types = new ArrayList<>(data.getRelationshipTypeList().getAllRelationshipTypes());
types.remove(data.getRelationshipTypeList().getNullRelation());
types.remove(data.getRelationshipTypeList().getSelfRelation());
final Object[] possibilities = types.toArray();
final RelationshipType chosenRelationship = (RelationshipType) JOptionPane.showInputDialog(PoliticalStateOverview.this, "Change Current Relationship between " + player1.getName() + " and " + player2.getName(), "Change Current Relationship", JOptionPane.PLAIN_MESSAGE, null, possibilities, relType);
if (chosenRelationship != null) {
// remove any old ones
editChanges.removeIf(changesSoFar -> (player1.equals(changesSoFar.getFirst()) && player2.equals(changesSoFar.getSecond())) || (player2.equals(changesSoFar.getFirst()) && player1.equals(changesSoFar.getSecond())));
// see if there is actually a change
data.acquireReadLock();
final RelationshipType actualRelationship;
try {
actualRelationship = data.getRelationshipTracker().getRelationshipType(player1, player2);
} finally {
data.releaseReadLock();
}
if (!chosenRelationship.equals(actualRelationship)) {
// add new change
editChanges.add(Triple.of(player1, player2, chosenRelationship));
}
// redraw everything
redrawPolitics();
}
});
button.setBackground(getRelationshipTypeColor(relType));
return button;
}
use of games.strategy.engine.data.RelationshipType in project triplea by triplea-game.
the class PoliticsDelegate method changeRelationships.
/**
* Changes all relationships.
*
* @param paa
* the political action to change the relationships for
*/
private void changeRelationships(final PoliticalActionAttachment paa) {
getMyselfOutOfAlliance(paa, player, bridge);
getNeutralOutOfWarWithAllies(paa, player, 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));
bridge.getHistoryWriter().addChildToEvent(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);
}
if (!change.isEmpty()) {
bridge.addChange(change);
}
chainAlliancesTogether(bridge);
}
use of games.strategy.engine.data.RelationshipType in project triplea by triplea-game.
the class GameDataExporter method relationshipInitialize.
private void relationshipInitialize(final GameData data) {
if (data.getRelationshipTypeList().getAllRelationshipTypes().size() <= 4) {
return;
}
final RelationshipTracker rt = data.getRelationshipTracker();
xmlfile.append(" <relationshipInitialize>\n");
final Collection<PlayerID> players = data.getPlayerList().getPlayers();
final Collection<PlayerID> playersAlreadyDone = new HashSet<>();
for (final PlayerID p1 : players) {
for (final PlayerID p2 : players) {
if (p1.equals(p2) || playersAlreadyDone.contains(p2)) {
continue;
}
final RelationshipType type = rt.getRelationshipType(p1, p2);
final int roundValue = rt.getRoundRelationshipWasCreated(p1, p2);
xmlfile.append(" <relationship type=\"").append(type.getName()).append("\" player1=\"").append(p1.getName()).append("\" player2=\"").append(p2.getName()).append("\" roundValue=\"").append(roundValue).append("\"/>\n");
}
playersAlreadyDone.add(p1);
}
xmlfile.append(" </relationshipInitialize>\n");
}
Aggregations