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 "";
}
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));
}
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.");
}
}
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;
}
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);
}
}
Aggregations