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