use of games.strategy.engine.data.CompositeChange in project triplea by triplea-game.
the class AbstractTriggerAttachment method triggerSetUsedForThisRound.
public static CompositeChange triggerSetUsedForThisRound(final PlayerID player) {
final CompositeChange change = new CompositeChange();
for (final TriggerAttachment ta : TriggerAttachment.getTriggers(player, null)) {
if (ta.getUsedThisRound()) {
final int currentUses = ta.getUses();
if (currentUses > 0) {
change.add(ChangeFactory.attachmentPropertyChange(ta, Integer.toString(currentUses - 1), "uses"));
change.add(ChangeFactory.attachmentPropertyChange(ta, false, "usedThisRound"));
}
}
}
return change;
}
use of games.strategy.engine.data.CompositeChange in project triplea by triplea-game.
the class AbstractEndTurnDelegate method changeUnitOwnership.
private static void changeUnitOwnership(final IDelegateBridge bridge) {
final PlayerID player = bridge.getPlayerId();
final PlayerAttachment pa = PlayerAttachment.get(player);
final Collection<PlayerID> possibleNewOwners = pa.getGiveUnitControl();
final Collection<Territory> territories = bridge.getData().getMap().getTerritories();
final CompositeChange change = new CompositeChange();
final Collection<Tuple<Territory, Collection<Unit>>> changeList = new ArrayList<>();
for (final Territory currTerritory : territories) {
final TerritoryAttachment ta = TerritoryAttachment.get(currTerritory);
// if ownership should change in this territory
if (ta != null && ta.getChangeUnitOwners() != null && !ta.getChangeUnitOwners().isEmpty()) {
final Collection<PlayerID> terrNewOwners = ta.getChangeUnitOwners();
for (final PlayerID terrNewOwner : terrNewOwners) {
if (possibleNewOwners.contains(terrNewOwner)) {
// PlayerOwnerChange
final Collection<Unit> units = currTerritory.getUnits().getMatches(Matches.unitOwnedBy(player).and(Matches.unitCanBeGivenByTerritoryTo(terrNewOwner)));
if (!units.isEmpty()) {
change.add(ChangeFactory.changeOwner(units, terrNewOwner, currTerritory));
changeList.add(Tuple.of(currTerritory, units));
}
}
}
}
}
if (!change.isEmpty() && !changeList.isEmpty()) {
if (changeList.size() == 1) {
final Tuple<Territory, Collection<Unit>> tuple = changeList.iterator().next();
bridge.getHistoryWriter().startEvent("Some Units in " + tuple.getFirst().getName() + " change ownership: " + MyFormatter.unitsToTextNoOwner(tuple.getSecond()), tuple.getSecond());
} else {
bridge.getHistoryWriter().startEvent("Units Change Ownership");
for (final Tuple<Territory, Collection<Unit>> tuple : changeList) {
bridge.getHistoryWriter().addChildToEvent("Some Units in " + tuple.getFirst().getName() + " change ownership: " + MyFormatter.unitsToTextNoOwner(tuple.getSecond()), tuple.getSecond());
}
}
bridge.addChange(change);
}
}
use of games.strategy.engine.data.CompositeChange in project triplea by triplea-game.
the class History method getDelta.
public Change getDelta(final HistoryNode start, final HistoryNode end) {
assertCorrectThread();
final int firstChange = getLastChange(start);
final int lastChange = getLastChange(end);
if (firstChange == lastChange) {
return null;
}
final List<Change> deltaChanges = changes.subList(Math.min(firstChange, lastChange), Math.max(firstChange, lastChange));
final Change compositeChange = new CompositeChange(deltaChanges);
return (lastChange >= firstChange) ? compositeChange : compositeChange.invert();
}
use of games.strategy.engine.data.CompositeChange in project triplea by triplea-game.
the class TriggerAttachmentTest method testTriggerProductionFrontierEditChange.
@Test
public void testTriggerProductionFrontierEditChange() {
TriggerAttachment.triggerProductionFrontierEditChange(satisfiedTriggers, bridge, "beforeOrAfter", "stepName", // useUses
false, // testUses
false, // testChance
false, // testWhen
false);
final ArgumentCaptor<CompositeChange> argument = ArgumentCaptor.forClass(CompositeChange.class);
verify(bridge).addChange(argument.capture());
final CompositeChange change = argument.getValue();
assertFalse(change.isEmpty());
final ArgumentCaptor<String> ruleAddArgument = ArgumentCaptor.forClass(String.class);
verify(historyWriter, times(3)).startEvent(ruleAddArgument.capture());
final List<String> allValues = ruleAddArgument.getAllValues();
assertEquals(3, allValues.size());
assertTrue(allValues.stream().anyMatch(s -> s.contains("rule1Name") && s.contains("added")));
assertTrue(allValues.stream().anyMatch(s -> s.contains("rule2Name") && s.contains("removed")));
assertTrue(allValues.stream().anyMatch(s -> s.contains("rule3Name") && s.contains("added")));
assertTrue(allValues.stream().allMatch(s -> s.contains("frontierName")));
}
Aggregations