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);
}
}
}
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);
}
}
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;
}
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);
}
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);
}
}
Aggregations