use of games.strategy.engine.data.RelationshipTracker in project triplea by triplea-game.
the class ProSimulateTurnUtils method checkIfCapturedTerritoryIsAlliedCapital.
private static boolean checkIfCapturedTerritoryIsAlliedCapital(final Territory t, final GameData data, final PlayerID player, final IDelegateBridge delegateBridge) {
final PlayerID terrOrigOwner = OriginalOwnerTracker.getOriginalOwner(t);
final RelationshipTracker relationshipTracker = data.getRelationshipTracker();
final TerritoryAttachment ta = TerritoryAttachment.get(t);
if (ta != null && ta.getCapital() != null && terrOrigOwner != null && TerritoryAttachment.getAllCapitals(terrOrigOwner, data).contains(t) && relationshipTracker.isAllied(terrOrigOwner, player)) {
// Give capital and any allied territories back to original owner
final Collection<Territory> originallyOwned = OriginalOwnerTracker.getOriginallyOwned(data, terrOrigOwner);
final List<Territory> friendlyTerritories = CollectionUtils.getMatches(originallyOwned, Matches.isTerritoryAllied(terrOrigOwner, data));
friendlyTerritories.add(t);
for (final Territory item : friendlyTerritories) {
if (item.getOwner() == terrOrigOwner) {
continue;
}
final Change takeOverFriendlyTerritories = ChangeFactory.changeOwner(item, terrOrigOwner);
delegateBridge.addChange(takeOverFriendlyTerritories);
final Collection<Unit> units = CollectionUtils.getMatches(item.getUnits().getUnits(), Matches.unitIsInfrastructure());
if (!units.isEmpty()) {
final Change takeOverNonComUnits = ChangeFactory.changeOwner(units, terrOrigOwner, t);
delegateBridge.addChange(takeOverNonComUnits);
}
}
return true;
}
return false;
}
use of games.strategy.engine.data.RelationshipTracker in project triplea by triplea-game.
the class ParserTest method testAllianceMade.
@Test
public void testAllianceMade() {
final PlayerList players = gameData.getPlayerList();
final PlayerID castro = players.getPlayerId("castro");
final PlayerID chretian = players.getPlayerId("chretian");
final RelationshipTracker alliances = gameData.getRelationshipTracker();
assertTrue(alliances.isAllied(castro, chretian));
}
Aggregations