Search in sources :

Example 41 with CompositeChange

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;
}
Also used : ArrayList(java.util.ArrayList) CompositeChange(games.strategy.engine.data.CompositeChange) Unit(games.strategy.engine.data.Unit) TripleAUnit(games.strategy.triplea.TripleAUnit)

Example 42 with CompositeChange

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.");
    }
}
Also used : IGamePlayer(games.strategy.engine.gamePlayer.IGamePlayer) PlayerID(games.strategy.engine.data.PlayerID) GameData(games.strategy.engine.data.GameData) GameStep(games.strategy.engine.data.GameStep) Step(games.strategy.engine.history.Step) EventChild(games.strategy.engine.history.EventChild) TripleAPlayer(games.strategy.triplea.TripleAPlayer) HistoryNode(games.strategy.engine.history.HistoryNode) Event(games.strategy.engine.history.Event) CompositeChange(games.strategy.engine.data.CompositeChange)

Example 43 with CompositeChange

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;
}
Also used : Territory(games.strategy.engine.data.Territory) GameData(games.strategy.engine.data.GameData) CompositeChange(games.strategy.engine.data.CompositeChange)

Example 44 with CompositeChange

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);
    }
}
Also used : Territory(games.strategy.engine.data.Territory) GameData(games.strategy.engine.data.GameData) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit) CompositeChange(games.strategy.engine.data.CompositeChange) TripleAUnit(games.strategy.triplea.TripleAUnit)

Example 45 with CompositeChange

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;
}
Also used : GameData(games.strategy.engine.data.GameData) CompositeChange(games.strategy.engine.data.CompositeChange) TripleAUnit(games.strategy.triplea.TripleAUnit) Unit(games.strategy.engine.data.Unit)

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