Search in sources :

Example 11 with PlayerID

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

the class AirBattle method queryRetreat.

private void queryRetreat(final boolean defender, final IDelegateBridge bridge, final Collection<Territory> availableTerritories) {
    if (availableTerritories.isEmpty()) {
        return;
    }
    final Collection<Unit> units = defender ? new ArrayList<>(m_defendingUnits) : new ArrayList<>(m_attackingUnits);
    if (units.isEmpty()) {
        return;
    }
    final PlayerID retreatingPlayer = defender ? m_defender : m_attacker;
    final String text = retreatingPlayer.getName() + " retreat?";
    final String step = defender ? DEFENDERS_WITHDRAW : ATTACKERS_WITHDRAW;
    getDisplay(bridge).gotoBattleStep(m_battleID, step);
    final Territory retreatTo = getRemote(retreatingPlayer, bridge).retreatQuery(m_battleID, false, m_battleSite, availableTerritories, text);
    if (retreatTo != null && !availableTerritories.contains(retreatTo)) {
        System.err.println("Invalid retreat selection :" + retreatTo + " not in " + MyFormatter.defaultNamedToTextList(availableTerritories));
        Thread.dumpStack();
        return;
    }
    if (retreatTo != null) {
        if (!m_headless) {
            bridge.getSoundChannelBroadcaster().playSoundForAll(SoundPath.CLIP_BATTLE_RETREAT_AIR, m_attacker);
        }
        retreat(units, defender, bridge);
        final String messageShort = retreatingPlayer.getName() + " retreats";
        final String messageLong = retreatingPlayer.getName() + " retreats all units to " + retreatTo.getName();
        getDisplay(bridge).notifyRetreat(messageShort, messageLong, step, retreatingPlayer);
    }
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit)

Example 12 with PlayerID

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

the class AirMovementValidator method canFindLand.

private static boolean canFindLand(final GameData data, final Unit unit, final Territory current, final int movementLeft) {
    if (movementLeft <= 0) {
        return false;
    }
    final boolean areNeutralsPassableByAir = areNeutralsPassableByAir(data);
    final PlayerID player = unit.getOwner();
    final List<Territory> possibleSpots = CollectionUtils.getMatches(data.getMap().getNeighbors(current, movementLeft), Matches.airCanLandOnThisAlliedNonConqueredLandTerritory(player, data));
    // have a lot of movement capacity.
    for (final Territory landingSpot : possibleSpots) {
        if (canAirReachThisSpot(data, player, unit, current, movementLeft, landingSpot, areNeutralsPassableByAir)) {
            return true;
        }
    }
    return false;
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory)

Example 13 with PlayerID

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

the class TerritoryAttachment method setOriginalOwner.

private void setOriginalOwner(final String player) throws GameParseException {
    if (player == null) {
        m_originalOwner = null;
    }
    final PlayerID tempPlayer = getData().getPlayerList().getPlayerId(player);
    if (tempPlayer == null) {
        throw new GameParseException("No player named: " + player + thisErrorMsg());
    }
    m_originalOwner = tempPlayer;
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) GameParseException(games.strategy.engine.data.GameParseException)

Example 14 with PlayerID

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

the class TriggerAttachment method triggerRelationshipChange.

public static void triggerRelationshipChange(final Set<TriggerAttachment> satisfiedTriggers, final IDelegateBridge bridge, final String beforeOrAfter, final String stepName, final boolean useUses, final boolean testUses, final boolean testChance, final boolean testWhen) {
    final GameData data = bridge.getData();
    Collection<TriggerAttachment> trigs = CollectionUtils.getMatches(satisfiedTriggers, relationshipChangeMatch());
    if (testWhen) {
        trigs = CollectionUtils.getMatches(trigs, whenOrDefaultMatch(beforeOrAfter, stepName));
    }
    if (testUses) {
        trigs = CollectionUtils.getMatches(trigs, availableUses);
    }
    final CompositeChange change = new CompositeChange();
    for (final TriggerAttachment t : trigs) {
        if (testChance && !t.testChance(bridge)) {
            continue;
        }
        if (useUses) {
            t.use(bridge);
        }
        for (final String relationshipChange : t.getRelationshipChange()) {
            final String[] s = relationshipChange.split(":");
            final PlayerID player1 = data.getPlayerList().getPlayerId(s[0]);
            final PlayerID player2 = data.getPlayerList().getPlayerId(s[1]);
            final RelationshipType currentRelation = data.getRelationshipTracker().getRelationshipType(player1, player2);
            if (s[2].equals(Constants.RELATIONSHIP_CONDITION_ANY) || (s[2].equals(Constants.RELATIONSHIP_CONDITION_ANY_NEUTRAL) && Matches.relationshipTypeIsNeutral().test(currentRelation)) || (s[2].equals(Constants.RELATIONSHIP_CONDITION_ANY_ALLIED) && Matches.relationshipTypeIsAllied().test(currentRelation)) || (s[2].equals(Constants.RELATIONSHIP_CONDITION_ANY_WAR) && Matches.relationshipTypeIsAtWar().test(currentRelation)) || currentRelation.equals(data.getRelationshipTypeList().getRelationshipType(s[2]))) {
                final RelationshipType triggerNewRelation = data.getRelationshipTypeList().getRelationshipType(s[3]);
                change.add(ChangeFactory.relationshipChange(player1, player2, currentRelation, triggerNewRelation));
                bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": Changing Relationship for " + player1.getName() + " and " + player2.getName() + " from " + currentRelation.getName() + " to " + triggerNewRelation.getName());
                AbstractMoveDelegate.getBattleTracker(data).addRelationshipChangesThisTurn(player1, player2, currentRelation, triggerNewRelation);
            /*
           * creation of new battles is handled at the beginning of the battle delegate, in
           * "setupUnitsInSameTerritoryBattles", not here.
           * if (Matches.relationshipTypeIsAtWar().test(triggerNewRelation))
           * triggerMustFightBattle(player1, player2, aBridge);
           */
            }
        }
    }
    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 15 with PlayerID

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

the class TriggerAttachment method triggerProductionChange.

public static void triggerProductionChange(final Set<TriggerAttachment> satisfiedTriggers, final IDelegateBridge bridge, final String beforeOrAfter, final String stepName, final boolean useUses, final boolean testUses, final boolean testChance, final boolean testWhen) {
    Collection<TriggerAttachment> trigs = CollectionUtils.getMatches(satisfiedTriggers, prodMatch());
    if (testWhen) {
        trigs = CollectionUtils.getMatches(trigs, whenOrDefaultMatch(beforeOrAfter, stepName));
    }
    if (testUses) {
        trigs = CollectionUtils.getMatches(trigs, availableUses);
    }
    final CompositeChange change = new CompositeChange();
    for (final TriggerAttachment t : trigs) {
        if (testChance && !t.testChance(bridge)) {
            continue;
        }
        if (useUses) {
            t.use(bridge);
        }
        for (final PlayerID player : t.getPlayers()) {
            change.add(ChangeFactory.changeProductionFrontier(player, t.getFrontier()));
            bridge.getHistoryWriter().startEvent(MyFormatter.attachmentNameToText(t.getName()) + ": " + player.getName() + " has their production frontier changed to: " + t.getFrontier().getName());
        }
    }
    if (!change.isEmpty()) {
        bridge.addChange(change);
    }
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) CompositeChange(games.strategy.engine.data.CompositeChange)

Aggregations

PlayerID (games.strategy.engine.data.PlayerID)323 Territory (games.strategy.engine.data.Territory)163 Unit (games.strategy.engine.data.Unit)133 Test (org.junit.jupiter.api.Test)122 TripleAUnit (games.strategy.triplea.TripleAUnit)104 ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)94 GameData (games.strategy.engine.data.GameData)90 ArrayList (java.util.ArrayList)79 UnitType (games.strategy.engine.data.UnitType)74 Route (games.strategy.engine.data.Route)67 ScriptedRandomSource (games.strategy.engine.random.ScriptedRandomSource)46 HashSet (java.util.HashSet)44 Change (games.strategy.engine.data.Change)29 CompositeChange (games.strategy.engine.data.CompositeChange)29 IntegerMap (games.strategy.util.IntegerMap)29 List (java.util.List)29 HashMap (java.util.HashMap)28 Collection (java.util.Collection)27 Resource (games.strategy.engine.data.Resource)25 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)23