Search in sources :

Example 56 with Territory

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

the class FinishedBattle method removeAttack.

@Override
public void removeAttack(final Route route, final Collection<Unit> units) {
    m_attackingUnits.removeAll(units);
    // the route could be null, in the case of a unit in a territory where a sub is submerged.
    if (route == null) {
        return;
    }
    final Territory attackingFrom = route.getTerritoryBeforeEnd();
    Collection<Unit> attackingFromMapUnits = m_attackingFromMap.get(attackingFrom);
    // handle possible null pointer
    if (attackingFromMapUnits == null) {
        attackingFromMapUnits = new ArrayList<>();
    }
    attackingFromMapUnits.removeAll(units);
    if (attackingFromMapUnits.isEmpty()) {
        m_attackingFrom.remove(attackingFrom);
    }
    // deal with amphibious assaults
    if (attackingFrom.isWater()) {
        if (route.getEnd() != null && !route.getEnd().isWater() && units.stream().anyMatch(Matches.unitIsLand())) {
            m_amphibiousLandAttackers.removeAll(CollectionUtils.getMatches(units, Matches.unitIsLand()));
        }
        // that territory is no longer an amphibious assault
        if (attackingFromMapUnits.stream().noneMatch(Matches.unitIsLand())) {
            m_amphibiousAttackFrom.remove(attackingFrom);
            // do we have any amphibious attacks left?
            m_isAmphibious = !m_amphibiousAttackFrom.isEmpty();
        }
    }
    for (final Collection<Unit> dependent : m_dependentUnits.values()) {
        dependent.removeAll(units);
    }
}
Also used : Territory(games.strategy.engine.data.Territory) Unit(games.strategy.engine.data.Unit)

Example 57 with Territory

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

the class FinishedBattle method addAttackChange.

@Override
public Change addAttackChange(final Route route, final Collection<Unit> units, final HashMap<Unit, HashSet<Unit>> targets) {
    final Map<Unit, Collection<Unit>> addedTransporting = TransportTracker.transporting(units);
    for (final Unit unit : addedTransporting.keySet()) {
        if (m_dependentUnits.get(unit) != null) {
            m_dependentUnits.get(unit).addAll(addedTransporting.get(unit));
        } else {
            m_dependentUnits.put(unit, addedTransporting.get(unit));
        }
    }
    final Territory attackingFrom = route.getTerritoryBeforeEnd();
    m_attackingFrom.add(attackingFrom);
    m_attackingUnits.addAll(units);
    m_attackingFromMap.putIfAbsent(attackingFrom, new ArrayList<>());
    final Collection<Unit> attackingFromMapUnits = m_attackingFromMap.get(attackingFrom);
    attackingFromMapUnits.addAll(units);
    // are we amphibious
    if (route.getStart().isWater() && route.getEnd() != null && !route.getEnd().isWater() && units.stream().anyMatch(Matches.unitIsLand())) {
        m_amphibiousAttackFrom.add(route.getTerritoryBeforeEnd());
        m_amphibiousLandAttackers.addAll(CollectionUtils.getMatches(units, Matches.unitIsLand()));
        m_isAmphibious = true;
    }
    return ChangeFactory.EMPTY_CHANGE;
}
Also used : Territory(games.strategy.engine.data.Territory) Collection(java.util.Collection) Unit(games.strategy.engine.data.Unit)

Example 58 with Territory

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

the class EndRoundDelegate method checkVictoryCities.

private void checkVictoryCities(final IDelegateBridge bridge, final String victoryMessage, final String victoryType) {
    final GameData data = bridge.getData();
    final Collection<Territory> territories = data.getMap().getTerritories();
    for (final String allianceName : data.getAllianceTracker().getAlliances()) {
        final int vcAmount = getVcAmount(data, allianceName, victoryType);
        final Set<PlayerID> teamMembers = data.getAllianceTracker().getPlayersInAlliance(allianceName);
        int teamVCs = 0;
        for (final Territory t : territories) {
            if (Matches.isTerritoryOwnedBy(teamMembers).test(t)) {
                final TerritoryAttachment ta = TerritoryAttachment.get(t);
                if (ta != null) {
                    teamVCs += ta.getVictoryCity();
                }
            }
        }
        if (teamVCs >= vcAmount) {
            bridge.getHistoryWriter().startEvent(allianceName + victoryMessage + vcAmount + " Victory Cities!");
            final Collection<PlayerID> winners = data.getAllianceTracker().getPlayersInAlliance(allianceName);
            // Added this to end the game on victory conditions
            signalGameOver(allianceName + victoryMessage + vcAmount + " Victory Cities!", winners, bridge);
        }
    }
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) GameData(games.strategy.engine.data.GameData) TerritoryAttachment(games.strategy.triplea.attachments.TerritoryAttachment)

Example 59 with Territory

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

the class InitializationDelegate method initOriginalOwner.

private static void initOriginalOwner(final IDelegateBridge bridge) {
    final GameData data = bridge.getData();
    final CompositeChange changes = new CompositeChange();
    for (final Territory current : data.getMap()) {
        if (!current.getOwner().isNull()) {
            final TerritoryAttachment territoryAttachment = TerritoryAttachment.get(current);
            if (territoryAttachment == null) {
                throw new IllegalStateException("No territory attachment for " + current);
            }
            if (territoryAttachment.getOriginalOwner() == null && current.getOwner() != null) {
                changes.add(OriginalOwnerTracker.addOriginalOwnerChange(current, current.getOwner()));
            }
            final Collection<Unit> factoryAndInfrastructure = current.getUnits().getMatches(Matches.unitIsInfrastructure());
            changes.add(OriginalOwnerTracker.addOriginalOwnerChange(factoryAndInfrastructure, current.getOwner()));
        } else if (!current.isWater()) {
            final TerritoryAttachment territoryAttachment = TerritoryAttachment.get(current);
            if (territoryAttachment == null) {
                throw new IllegalStateException("No territory attachment for " + current);
            }
        }
    }
    bridge.getHistoryWriter().startEvent("Adding original owners");
    bridge.addChange(changes);
}
Also used : Territory(games.strategy.engine.data.Territory) GameData(games.strategy.engine.data.GameData) TerritoryAttachment(games.strategy.triplea.attachments.TerritoryAttachment) CompositeChange(games.strategy.engine.data.CompositeChange) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit)

Example 60 with Territory

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

the class GameDataExporter method ownerInitialize.

private void ownerInitialize(final GameData data) {
    xmlfile.append("        <ownerInitialize>\n");
    for (final Territory terr : data.getMap().getTerritories()) {
        if (!terr.getOwner().getName().equals(Constants.PLAYER_NAME_NEUTRAL)) {
            xmlfile.append("            <territoryOwner territory=\"").append(terr.getName()).append("\" owner=\"").append(terr.getOwner().getName()).append("\"/>\n");
        }
    }
    xmlfile.append("        </ownerInitialize>\n");
}
Also used : Territory(games.strategy.engine.data.Territory)

Aggregations

Territory (games.strategy.engine.data.Territory)420 Unit (games.strategy.engine.data.Unit)254 TripleAUnit (games.strategy.triplea.TripleAUnit)195 PlayerID (games.strategy.engine.data.PlayerID)164 ArrayList (java.util.ArrayList)160 Test (org.junit.jupiter.api.Test)140 Route (games.strategy.engine.data.Route)137 ITestDelegateBridge (games.strategy.engine.data.ITestDelegateBridge)118 GameData (games.strategy.engine.data.GameData)94 HashSet (java.util.HashSet)87 UnitType (games.strategy.engine.data.UnitType)65 HashMap (java.util.HashMap)65 ScriptedRandomSource (games.strategy.engine.random.ScriptedRandomSource)50 Collection (java.util.Collection)47 IntegerMap (games.strategy.util.IntegerMap)45 Set (java.util.Set)41 ProTerritory (games.strategy.triplea.ai.pro.data.ProTerritory)39 TerritoryAttachment (games.strategy.triplea.attachments.TerritoryAttachment)37 List (java.util.List)36 ProPurchaseTerritory (games.strategy.triplea.ai.pro.data.ProPurchaseTerritory)34