Search in sources :

Example 31 with CompositeChange

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

the class InitializationDelegate method initDestroyerArtillery.

private static void initDestroyerArtillery(final IDelegateBridge bridge) {
    final GameData data = bridge.getData();
    final boolean addArtilleryAndDestroyers = Properties.getUseDestroyersAndArtillery(data);
    if (!isWW2V2(data) && addArtilleryAndDestroyers) {
        final CompositeChange change = new CompositeChange();
        final ProductionRule artillery = data.getProductionRuleList().getProductionRule("buyArtillery");
        final ProductionRule destroyer = data.getProductionRuleList().getProductionRule("buyDestroyer");
        final ProductionFrontier frontier = data.getProductionFrontierList().getProductionFrontier("production");
        if (artillery != null && !frontier.getRules().contains(artillery)) {
            change.add(ChangeFactory.addProductionRule(artillery, frontier));
        }
        if (destroyer != null && !frontier.getRules().contains(destroyer)) {
            change.add(ChangeFactory.addProductionRule(destroyer, frontier));
        }
        final ProductionRule artilleryIndustrialTechnology = data.getProductionRuleList().getProductionRule("buyArtilleryIndustrialTechnology");
        final ProductionRule destroyerIndustrialTechnology = data.getProductionRuleList().getProductionRule("buyDestroyerIndustrialTechnology");
        final ProductionFrontier frontierIndustrialTechnology = data.getProductionFrontierList().getProductionFrontier("productionIndustrialTechnology");
        if (artilleryIndustrialTechnology != null && !frontierIndustrialTechnology.getRules().contains(artilleryIndustrialTechnology)) {
            change.add(ChangeFactory.addProductionRule(artilleryIndustrialTechnology, frontierIndustrialTechnology));
        }
        if (destroyerIndustrialTechnology != null && !frontierIndustrialTechnology.getRules().contains(destroyerIndustrialTechnology)) {
            change.add(ChangeFactory.addProductionRule(destroyerIndustrialTechnology, frontierIndustrialTechnology));
        }
        if (!change.isEmpty()) {
            bridge.getHistoryWriter().startEvent("Adding destroyers and artillery production rules");
            bridge.addChange(change);
        }
    }
}
Also used : GameData(games.strategy.engine.data.GameData) ProductionRule(games.strategy.engine.data.ProductionRule) CompositeChange(games.strategy.engine.data.CompositeChange) ProductionFrontier(games.strategy.engine.data.ProductionFrontier)

Example 32 with CompositeChange

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

the class InitializationDelegate method initShipyards.

private static void initShipyards(final IDelegateBridge bridge) {
    final GameData data = bridge.getData();
    final boolean useShipyards = Properties.getUseShipyards(data);
    if (useShipyards) {
        final CompositeChange change = new CompositeChange();
        final ProductionFrontier frontierShipyards = data.getProductionFrontierList().getProductionFrontier("productionShipyards");
        /*
       * Find the productionRules, if the unit is NOT a sea unit, add it to the ShipYards prod rule.
       */
        final ProductionFrontier frontierNonShipyards = data.getProductionFrontierList().getProductionFrontier("production");
        final Collection<ProductionRule> rules = frontierNonShipyards.getRules();
        for (final ProductionRule rule : rules) {
            final String ruleName = rule.getName();
            final IntegerMap<NamedAttachable> ruleResults = rule.getResults();
            final NamedAttachable named = ruleResults.keySet().iterator().next();
            if (!(named instanceof UnitType)) {
                continue;
            }
            final UnitType unit = data.getUnitTypeList().getUnitType(named.getName());
            final boolean isSea = UnitAttachment.get(unit).getIsSea();
            if (!isSea) {
                final ProductionRule prodRule = data.getProductionRuleList().getProductionRule(ruleName);
                change.add(ChangeFactory.addProductionRule(prodRule, frontierShipyards));
            }
        }
        bridge.getHistoryWriter().startEvent("Adding shipyard production rules - land/air units");
        bridge.addChange(change);
    }
}
Also used : GameData(games.strategy.engine.data.GameData) ProductionRule(games.strategy.engine.data.ProductionRule) NamedAttachable(games.strategy.engine.data.NamedAttachable) UnitType(games.strategy.engine.data.UnitType) CompositeChange(games.strategy.engine.data.CompositeChange) ProductionFrontier(games.strategy.engine.data.ProductionFrontier)

Example 33 with CompositeChange

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

the class TripleAUnit method translateAttributesToOtherUnits.

/**
 * Currently made for translating unit damage from one unit to another unit. Will adjust damage to be within max
 * damage for the new units.
 *
 * @return change for unit's properties
 */
public static Change translateAttributesToOtherUnits(final Unit unitGivingAttributes, final Collection<Unit> unitsThatWillGetAttributes, final Territory t) {
    final CompositeChange changes = new CompositeChange();
    // must look for m_hits, m_unitDamage,
    final TripleAUnit taUnit = (TripleAUnit) unitGivingAttributes;
    final int combatDamage = taUnit.getHits();
    final IntegerMap<Unit> hits = new IntegerMap<>();
    if (combatDamage > 0) {
        for (final Unit u : unitsThatWillGetAttributes) {
            hits.put(u, combatDamage);
        }
    }
    if (hits.size() > 0) {
        changes.add(ChangeFactory.unitsHit(hits));
    }
    final int unitDamage = taUnit.getUnitDamage();
    final IntegerMap<Unit> damageMap = new IntegerMap<>();
    if (unitDamage > 0) {
        for (final Unit u : unitsThatWillGetAttributes) {
            final TripleAUnit taNew = (TripleAUnit) u;
            final int maxDamage = taNew.getHowMuchDamageCanThisUnitTakeTotal(u, t);
            final int transferDamage = Math.max(0, Math.min(unitDamage, maxDamage));
            if (transferDamage <= 0) {
                continue;
            }
            damageMap.put(u, transferDamage);
        }
    }
    changes.add(ChangeFactory.bombingUnitDamage(damageMap));
    return changes;
}
Also used : IntegerMap(games.strategy.util.IntegerMap) CompositeChange(games.strategy.engine.data.CompositeChange) Unit(games.strategy.engine.data.Unit)

Example 34 with CompositeChange

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

the class PoliticsDelegate method changeRelationships.

/**
 * Changes all relationships.
 *
 * @param paa
 *        the political action to change the relationships for
 */
private void changeRelationships(final PoliticalActionAttachment paa) {
    getMyselfOutOfAlliance(paa, player, bridge);
    getNeutralOutOfWarWithAllies(paa, player, bridge);
    final CompositeChange change = new CompositeChange();
    for (final String relationshipChange : paa.getRelationshipChange()) {
        final String[] s = relationshipChange.split(":");
        final PlayerID player1 = getData().getPlayerList().getPlayerId(s[0]);
        final PlayerID player2 = getData().getPlayerList().getPlayerId(s[1]);
        final RelationshipType oldRelation = getData().getRelationshipTracker().getRelationshipType(player1, player2);
        final RelationshipType newRelation = getData().getRelationshipTypeList().getRelationshipType(s[2]);
        if (oldRelation.equals(newRelation)) {
            continue;
        }
        change.add(ChangeFactory.relationshipChange(player1, player2, oldRelation, newRelation));
        bridge.getHistoryWriter().addChildToEvent(bridge.getPlayerId().getName() + " succeeds on action: " + MyFormatter.attachmentNameToText(paa.getName()) + ": Changing Relationship for " + player1.getName() + " and " + player2.getName() + " from " + oldRelation.getName() + " to " + newRelation.getName());
        MoveDelegate.getBattleTracker(getData()).addRelationshipChangesThisTurn(player1, player2, oldRelation, newRelation);
    }
    if (!change.isEmpty()) {
        bridge.addChange(change);
    }
    chainAlliancesTogether(bridge);
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) RelationshipType(games.strategy.engine.data.RelationshipType) CompositeChange(games.strategy.engine.data.CompositeChange)

Example 35 with CompositeChange

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

the class PoliticsDelegate method givesBackOriginalTerritories.

private static void givesBackOriginalTerritories(final IDelegateBridge bridge) {
    final GameData data = bridge.getData();
    final CompositeChange change = new CompositeChange();
    final Collection<PlayerID> players = data.getPlayerList().getPlayers();
    for (final PlayerID p1 : players) {
        for (final PlayerID p2 : players) {
            if (!data.getRelationshipTracker().givesBackOriginalTerritories(p1, p2)) {
                continue;
            }
            for (final Territory t : data.getMap().getTerritoriesOwnedBy(p1)) {
                final PlayerID original = OriginalOwnerTracker.getOriginalOwner(t);
                if (original == null) {
                    continue;
                }
                if (original.equals(p2)) {
                    change.add(ChangeFactory.changeOwner(t, original));
                }
            }
        }
    }
    if (!change.isEmpty()) {
        bridge.getHistoryWriter().startEvent("Giving back territories to original owners");
        bridge.addChange(change);
    }
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) Territory(games.strategy.engine.data.Territory) GameData(games.strategy.engine.data.GameData) CompositeChange(games.strategy.engine.data.CompositeChange)

Aggregations

CompositeChange (games.strategy.engine.data.CompositeChange)74 Unit (games.strategy.engine.data.Unit)48 TripleAUnit (games.strategy.triplea.TripleAUnit)40 GameData (games.strategy.engine.data.GameData)31 Territory (games.strategy.engine.data.Territory)25 ArrayList (java.util.ArrayList)22 PlayerID (games.strategy.engine.data.PlayerID)21 Change (games.strategy.engine.data.Change)17 UnitType (games.strategy.engine.data.UnitType)14 Resource (games.strategy.engine.data.Resource)9 HashSet (java.util.HashSet)9 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)8 IntegerMap (games.strategy.util.IntegerMap)8 Tuple (games.strategy.util.Tuple)7 Collection (java.util.Collection)7 RelationshipType (games.strategy.engine.data.RelationshipType)6 Set (java.util.Set)6 ProductionFrontier (games.strategy.engine.data.ProductionFrontier)4 ProductionRule (games.strategy.engine.data.ProductionRule)4 HashMap (java.util.HashMap)4