Search in sources :

Example 96 with GameData

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

the class HeadlessGameServer method loadGameOptions.

public synchronized void loadGameOptions(final byte[] bytes) {
    // don't change mid-game
    if (setupPanelModel.getPanel() != null && game == null) {
        if (bytes == null || bytes.length == 0) {
            return;
        }
        final GameData data = gameSelectorModel.getGameData();
        if (data == null) {
            return;
        }
        final GameProperties props = data.getProperties();
        if (props == null) {
            return;
        }
        GameProperties.applyByteMapToChangeProperties(bytes, props);
        System.out.println("Changed to user game options.");
    }
}
Also used : GameProperties(games.strategy.engine.data.properties.GameProperties) GameData(games.strategy.engine.data.GameData)

Example 97 with GameData

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

the class HeadlessServerSetup method postStartGame.

@Override
public void postStartGame() {
    final GameData data = gameSelectorModel.getGameData();
    data.getProperties().set(PBEMMessagePoster.PBEM_GAME_PROP_NAME, false);
}
Also used : GameData(games.strategy.engine.data.GameData)

Example 98 with GameData

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

the class GameDataManager method loadGame.

/**
 * Loads game data from the specified stream.
 *
 * @param is The stream from which the game data will be loaded. The caller is responsible for closing this stream; it
 *        will not be closed when this method returns.
 *
 * @return The loaded game data.
 *
 * @throws IOException If an error occurs while loading the game.
 */
public static GameData loadGame(final InputStream is) throws IOException {
    checkNotNull(is);
    final ObjectInputStream input = new ObjectInputStream(new GZIPInputStream(is));
    try {
        final Version readVersion = (Version) input.readObject();
        final boolean headless = HeadlessGameServer.headless();
        if (!GameEngineVersion.of(ClientContext.engineVersion()).isCompatibleWithEngineVersion(readVersion)) {
            // a hack for now, but a headless server should not try to open any savegame that is not its version
            if (headless) {
                final String message = "Incompatible game save, we are: " + ClientContext.engineVersion() + "  Trying to load game created with: " + readVersion;
                HeadlessGameServer.sendChat(message);
                System.out.println(message);
                return null;
            }
            final String error = "Incompatible engine versions. We are: " + ClientContext.engineVersion() + " . Trying to load game created with: " + readVersion + "\nTo download the latest version of TripleA, Please visit " + UrlConstants.LATEST_GAME_DOWNLOAD_WEBSITE;
            throw new IOException(error);
        } else if (!headless && readVersion.isGreaterThan(ClientContext.engineVersion())) {
            // we can still load it because our engine is compatible, however this save was made by a
            // newer engine, so prompt the user to upgrade
            final String messageString = "Your TripleA engine is OUT OF DATE.  This save was made by a newer version of TripleA." + "\nHowever, because the first 3 version numbers are the same as your current version, we can " + "still open the savegame." + "\n\nThis TripleA engine is version " + ClientContext.engineVersion().toStringFull() + " and you are trying to open a savegame made with version " + readVersion.toStringFull() + "\n\nTo download the latest version of TripleA, Please visit " + UrlConstants.LATEST_GAME_DOWNLOAD_WEBSITE + "\n\nIt is recommended that you upgrade to the latest version of TripleA before playing this " + "savegame." + "\n\nDo you wish to continue and open this save with your current 'old' version?";
            final int answer = JOptionPane.showConfirmDialog(null, messageString, "Open Newer Save Game?", JOptionPane.YES_NO_OPTION);
            if (answer != JOptionPane.YES_OPTION) {
                return null;
            }
        }
        final GameData data = (GameData) input.readObject();
        loadDelegates(input, data);
        data.postDeSerialize();
        return data;
    } catch (final ClassNotFoundException cnfe) {
        throw new IOException(cnfe.getMessage());
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) GameData(games.strategy.engine.data.GameData) GameEngineVersion(games.strategy.engine.GameEngineVersion) Version(games.strategy.util.Version) IOException(java.io.IOException) ObjectInputStream(java.io.ObjectInputStream)

Example 99 with GameData

use of games.strategy.engine.data.GameData 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 100 with GameData

use of games.strategy.engine.data.GameData 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)

Aggregations

GameData (games.strategy.engine.data.GameData)204 Unit (games.strategy.engine.data.Unit)100 PlayerID (games.strategy.engine.data.PlayerID)92 Territory (games.strategy.engine.data.Territory)92 ArrayList (java.util.ArrayList)83 TripleAUnit (games.strategy.triplea.TripleAUnit)64 HashSet (java.util.HashSet)50 CompositeChange (games.strategy.engine.data.CompositeChange)40 List (java.util.List)36 HashMap (java.util.HashMap)32 Set (java.util.Set)32 Route (games.strategy.engine.data.Route)31 UnitAttachment (games.strategy.triplea.attachments.UnitAttachment)30 Collection (java.util.Collection)29 UnitType (games.strategy.engine.data.UnitType)26 Change (games.strategy.engine.data.Change)24 Test (org.junit.jupiter.api.Test)23 Resource (games.strategy.engine.data.Resource)22 TestMapGameData (games.strategy.triplea.xml.TestMapGameData)22 Map (java.util.Map)21