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);
}
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations