Search in sources :

Example 91 with GameData

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

the class EndTurnDelegate method doNationalObjectivesAndOtherEndTurnEffects.

@Override
protected String doNationalObjectivesAndOtherEndTurnEffects(final IDelegateBridge bridge) {
    final GameData data = getData();
    final PlayerList playerList = data.getPlayerList();
    final PlayerID british = playerList.getPlayerId(Constants.PLAYER_NAME_BRITISH);
    final PlayerID japanese = playerList.getPlayerId(Constants.PLAYER_NAME_JAPANESE);
    // Quick check to see who still owns their own capital
    final boolean britain = TerritoryAttachment.getFirstOwnedCapitalOrFirstUnownedCapital(british, data).getOwner().equals(british);
    final boolean japan = TerritoryAttachment.getFirstOwnedCapitalOrFirstUnownedCapital(japanese, data).getOwner().equals(japanese);
    if (!m_gameOver) {
        if (britain && !japan) {
            m_gameOver = true;
            bridge.getHistoryWriter().startEvent("British win.");
        }
        if (!britain && japan) {
            m_gameOver = true;
            bridge.getHistoryWriter().startEvent("Japanese win.");
        }
    }
    return "";
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) GameData(games.strategy.engine.data.GameData) PlayerList(games.strategy.engine.data.PlayerList)

Example 92 with GameData

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

the class GameDataManagerTest method testLoadStoreKeepsGameUuid.

@Test
public void testLoadStoreKeepsGameUuid() throws IOException {
    final GameData data = new GameData();
    final byte[] bytes = IoUtils.writeToMemory(os -> GameDataManager.saveGame(os, data));
    final GameData loaded = IoUtils.readFromMemory(bytes, GameDataManager::loadGame);
    assertEquals(loaded.getProperties().get(GameData.GAME_UUID), data.getProperties().get(GameData.GAME_UUID));
}
Also used : GameData(games.strategy.engine.data.GameData) Test(org.junit.jupiter.api.Test)

Example 93 with GameData

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

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

the class AvailableGames method addToAvailableGames.

private static boolean addToAvailableGames(@Nonnull final URI uri, @Nonnull final Map<String, URI> availableGames) {
    final Optional<InputStream> inputStream = UrlStreams.openStream(uri);
    if (inputStream.isPresent()) {
        try (InputStream input = inputStream.get()) {
            final GameData data = GameParser.parse(uri.toString(), input);
            final String name = data.getGameName();
            if (!availableGames.containsKey(name)) {
                availableGames.put(name, uri);
                return true;
            }
        } catch (final Exception e) {
            ClientLogger.logError("Exception while parsing: " + uri.toString(), e);
        }
    }
    return false;
}
Also used : GameData(games.strategy.engine.data.GameData) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 95 with GameData

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

the class HeadlessGameServer method loadGameSave.

public synchronized void loadGameSave(final InputStream input, final String fileName) {
    // don't change mid-game
    if (setupPanelModel.getPanel() != null && game == null) {
        if (input == null || fileName == null) {
            return;
        }
        final GameData data = gameSelectorModel.getGameData(input);
        if (data == null) {
            System.out.println("Loading GameData failed for: " + fileName);
            return;
        }
        final String mapNameProperty = data.getProperties().get(Constants.MAP_NAME, "");
        if (!availableGames.containsMapName(mapNameProperty)) {
            System.out.println("Game mapName not in available games listing: " + mapNameProperty);
            return;
        }
        gameSelectorModel.load(data, fileName);
        System.out.println("Changed to user savegame: " + fileName);
    }
}
Also used : GameData(games.strategy.engine.data.GameData)

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