use of games.strategy.engine.data.CompositeChange in project triplea by triplea-game.
the class TransportTracker method loadTransportChange.
static Change loadTransportChange(final TripleAUnit transport, final Unit unit) {
assertTransport(transport);
final CompositeChange change = new CompositeChange();
// clear the loaded by
change.add(ChangeFactory.unitPropertyChange(unit, transport, TripleAUnit.TRANSPORTED_BY));
final Collection<Unit> newCarrying = new ArrayList<>(transport.getTransporting());
if (newCarrying.contains(unit)) {
throw new IllegalStateException("Already carrying, transport:" + transport + " unt:" + unit);
}
newCarrying.add(unit);
change.add(ChangeFactory.unitPropertyChange(unit, Boolean.TRUE, TripleAUnit.LOADED_THIS_TURN));
change.add(ChangeFactory.unitPropertyChange(transport, true, TripleAUnit.LOADED_THIS_TURN));
// If the transport was in combat, flag it as being loaded AFTER combat
if (transport.getWasInCombat()) {
change.add(ChangeFactory.unitPropertyChange(transport, true, TripleAUnit.LOADED_AFTER_COMBAT));
}
return change;
}
use of games.strategy.engine.data.CompositeChange in project triplea by triplea-game.
the class ServerGame method addPlayerTypesToGameData.
private void addPlayerTypesToGameData(final Collection<IGamePlayer> localPlayers, final PlayerManager allPlayers, final IDelegateBridge bridge) {
final GameData data = bridge.getData();
// start before making changes.
if (getCurrentStep() == null || getCurrentStep().getPlayerId() == null || (firstRun)) {
firstRun = false;
return;
}
// we can't add a new event or add new changes if we are not in a step.
final HistoryNode curNode = data.getHistory().getLastNode();
if (!(curNode instanceof Step) && !(curNode instanceof Event) && !(curNode instanceof EventChild)) {
return;
}
final CompositeChange change = new CompositeChange();
final Set<String> allPlayersString = allPlayers.getPlayers();
bridge.getHistoryWriter().startEvent("Game Loaded");
for (final IGamePlayer player : localPlayers) {
allPlayersString.remove(player.getName());
final boolean isHuman = player instanceof TripleAPlayer;
bridge.getHistoryWriter().addChildToEvent(player.getName() + ((player.getName().endsWith("s") || player.getName().endsWith("ese") || player.getName().endsWith("ish")) ? " are" : " is") + " now being played by: " + player.getType());
final PlayerID p = data.getPlayerList().getPlayerId(player.getName());
final String newWhoAmI = ((isHuman ? "Human" : "AI") + ":" + player.getType());
if (!p.getWhoAmI().equals(newWhoAmI)) {
change.add(ChangeFactory.changePlayerWhoAmIChange(p, newWhoAmI));
}
}
final Iterator<String> playerIter = allPlayersString.iterator();
while (playerIter.hasNext()) {
final String player = playerIter.next();
playerIter.remove();
bridge.getHistoryWriter().addChildToEvent(player + ((player.endsWith("s") || player.endsWith("ese") || player.endsWith("ish")) ? " are" : " is") + " now being played by: Human:Client");
final PlayerID p = data.getPlayerList().getPlayerId(player);
final String newWhoAmI = "Human:Client";
if (!p.getWhoAmI().equals(newWhoAmI)) {
change.add(ChangeFactory.changePlayerWhoAmIChange(p, newWhoAmI));
}
}
if (!change.isEmpty()) {
bridge.addChange(change);
}
needToInitialize = false;
if (!allPlayersString.isEmpty()) {
throw new IllegalStateException("Not all Player Types (ai/human/client) could be added to game data.");
}
}
use of games.strategy.engine.data.CompositeChange in project triplea by triplea-game.
the class MoveDelegate method giveBonusMovement.
private static Change giveBonusMovement(final IDelegateBridge bridge, final PlayerID player) {
final GameData data = bridge.getData();
final CompositeChange change = new CompositeChange();
for (final Territory t : data.getMap().getTerritories()) {
change.add(giveBonusMovementToUnits(player, data, t));
}
return change;
}
use of games.strategy.engine.data.CompositeChange in project triplea by triplea-game.
the class MoveDelegate method removeMovementFromAirOnDamagedAlliedCarriers.
private static void removeMovementFromAirOnDamagedAlliedCarriers(final IDelegateBridge bridge, final PlayerID player) {
final GameData data = bridge.getData();
final Predicate<Unit> crippledAlliedCarriersMatch = Matches.isUnitAllied(player, data).and(Matches.unitIsOwnedBy(player).negate()).and(Matches.unitIsCarrier()).and(Matches.unitHasWhenCombatDamagedEffect(UnitAttachment.UNITSMAYNOTLEAVEALLIEDCARRIER));
final Predicate<Unit> ownedFightersMatch = Matches.unitIsOwnedBy(player).and(Matches.unitIsAir()).and(Matches.unitCanLandOnCarrier()).and(Matches.unitHasMovementLeft());
final CompositeChange change = new CompositeChange();
for (final Territory t : data.getMap().getTerritories()) {
final Collection<Unit> ownedFighters = t.getUnits().getMatches(ownedFightersMatch);
if (ownedFighters.isEmpty()) {
continue;
}
final Collection<Unit> crippledAlliedCarriers = CollectionUtils.getMatches(t.getUnits().getUnits(), crippledAlliedCarriersMatch);
if (crippledAlliedCarriers.isEmpty()) {
continue;
}
for (final Unit fighter : ownedFighters) {
final TripleAUnit taUnit = (TripleAUnit) fighter;
if (taUnit.getTransportedBy() != null) {
if (crippledAlliedCarriers.contains(taUnit.getTransportedBy())) {
change.add(ChangeFactory.markNoMovementChange(fighter));
}
}
}
}
if (!change.isEmpty()) {
bridge.addChange(change);
}
}
use of games.strategy.engine.data.CompositeChange in project triplea by triplea-game.
the class MoveDelegate method resetBonusMovement.
private Change resetBonusMovement() {
final GameData data = getData();
final CompositeChange change = new CompositeChange();
for (final Unit u : data.getUnits()) {
if (TripleAUnit.get(u).getBonusMovement() != 0) {
change.add(ChangeFactory.unitPropertyChange(u, 0, TripleAUnit.BONUS_MOVEMENT));
}
}
return change;
}
Aggregations