Search in sources :

Example 6 with RelationshipTracker

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;
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) ProTerritory(games.strategy.triplea.ai.pro.data.ProTerritory) TerritoryAttachment(games.strategy.triplea.attachments.TerritoryAttachment) RelationshipTracker(games.strategy.engine.data.RelationshipTracker) Change(games.strategy.engine.data.Change) Unit(games.strategy.engine.data.Unit)

Example 7 with RelationshipTracker

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));
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) PlayerList(games.strategy.engine.data.PlayerList) RelationshipTracker(games.strategy.engine.data.RelationshipTracker) Test(org.junit.jupiter.api.Test)

Aggregations

RelationshipTracker (games.strategy.engine.data.RelationshipTracker)7 PlayerID (games.strategy.engine.data.PlayerID)5 Territory (games.strategy.engine.data.Territory)4 Unit (games.strategy.engine.data.Unit)4 CompositeChange (games.strategy.engine.data.CompositeChange)3 TripleAUnit (games.strategy.triplea.TripleAUnit)3 TerritoryAttachment (games.strategy.triplea.attachments.TerritoryAttachment)3 Change (games.strategy.engine.data.Change)2 GameData (games.strategy.engine.data.GameData)2 ArrayList (java.util.ArrayList)2 PlayerList (games.strategy.engine.data.PlayerList)1 RelationshipType (games.strategy.engine.data.RelationshipType)1 Resource (games.strategy.engine.data.Resource)1 ProTerritory (games.strategy.triplea.ai.pro.data.ProTerritory)1 PlayerAttachment (games.strategy.triplea.attachments.PlayerAttachment)1 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)1 BattleResults (games.strategy.triplea.oddsCalculator.ta.BattleResults)1 HashSet (java.util.HashSet)1 Test (org.junit.jupiter.api.Test)1