use of games.strategy.engine.data.GameStep in project triplea by triplea-game.
the class AbstractEndTurnDelegate method findEstimatedIncome.
/**
* Find estimated income for given player. This only takes into account income from territories,
* units, NOs, and triggers. It ignores blockades, war bonds, relationship upkeep, and bonus income.
*/
public static IntegerMap<Resource> findEstimatedIncome(final PlayerID player, final GameData data) {
final IntegerMap<Resource> resources = new IntegerMap<>();
// Only add territory resources if endTurn not endTurnNoPU
for (GameStep step : data.getSequence()) {
if (player.equals(step.getPlayerId()) && step.getDelegate().getName().equals("endTurn")) {
final List<Territory> territories = data.getMap().getTerritoriesOwnedBy(player);
final int pusFromTerritories = getProduction(territories, data) * Properties.getPuMultiplier(data);
resources.add(new Resource(Constants.PUS, data), pusFromTerritories);
resources.add(EndTurnDelegate.getResourceProduction(territories, data));
}
}
// Add unit generated resources, NOs, and triggers
resources.add(EndTurnDelegate.findUnitCreatedResources(player, data));
resources.add(EndTurnDelegate.findNationalObjectiveAndTriggerResources(player, data));
return resources;
}
use of games.strategy.engine.data.GameStep in project triplea by triplea-game.
the class ServerGame method runStep.
private void runStep(final boolean stepIsRestoredFromSavedGame) {
if (getCurrentStep().hasReachedMaxRunCount()) {
gameData.getSequence().next();
return;
}
if (isGameOver) {
return;
}
final GameStep currentStep = gameData.getSequence().getStep();
final IDelegate currentDelegate = currentStep.getDelegate();
if (!stepIsRestoredFromSavedGame && currentDelegate.getClass().isAnnotationPresent(AutoSave.class) && currentDelegate.getClass().getAnnotation(AutoSave.class).beforeStepStart()) {
autoSaveBefore(currentDelegate);
}
startStep(stepIsRestoredFromSavedGame);
if (!stepIsRestoredFromSavedGame && currentDelegate.getClass().isAnnotationPresent(AutoSave.class) && currentDelegate.getClass().getAnnotation(AutoSave.class).afterStepStart()) {
autoSaveBefore(currentDelegate);
}
if (isGameOver) {
return;
}
waitForPlayerToFinishStep();
if (isGameOver) {
return;
}
// save after the step has advanced
// otherwise, the delegate will execute again.
final boolean autoSaveThisDelegate = currentDelegate.getClass().isAnnotationPresent(AutoSave.class) && currentDelegate.getClass().getAnnotation(AutoSave.class).afterStepEnd();
if (autoSaveThisDelegate && currentStep.getName().endsWith("Move")) {
autoSave(getAutoSaveAfterFileNameForGameStep(currentStep));
}
endStep();
if (isGameOver) {
return;
}
if (gameData.getSequence().next()) {
gameData.getHistory().getHistoryWriter().startNextRound(gameData.getSequence().getRound());
autoSave(gameData.getSequence().getRound() % 2 == 0 ? SaveGameFileChooser.getAutoSaveEvenFileName() : SaveGameFileChooser.getAutoSaveOddFileName());
}
if (autoSaveThisDelegate && !currentStep.getName().endsWith("Move")) {
autoSave(getAutoSaveAfterFileNameForDelegate(currentDelegate));
}
}
use of games.strategy.engine.data.GameStep in project triplea by triplea-game.
the class PlayerOrder method saveToFile.
void saveToFile(final PrintGenerationData printData) throws IOException {
final GameData gameData = printData.getData();
for (final GameStep currentStep : gameData.getSequence()) {
if (currentStep.getDelegate() != null && currentStep.getDelegate().getClass() != null) {
final String delegateClassName = currentStep.getDelegate().getClass().getName();
if (delegateClassName.equals(InitializationDelegate.class.getName()) || delegateClassName.equals(BidPurchaseDelegate.class.getName()) || delegateClassName.equals(BidPlaceDelegate.class.getName()) || delegateClassName.equals(EndRoundDelegate.class.getName())) {
continue;
}
} else if (currentStep.getName() != null && (currentStep.getName().endsWith("Bid") || currentStep.getName().endsWith("BidPlace"))) {
continue;
}
final PlayerID currentPlayerId = currentStep.getPlayerId();
if (currentPlayerId != null && !currentPlayerId.isNull()) {
playerSet.add(currentPlayerId);
}
}
printData.getOutDir().mkdir();
final File outFile = new File(printData.getOutDir(), "General Information.csv");
try (Writer turnWriter = Files.newBufferedWriter(outFile.toPath(), StandardCharsets.UTF_8, StandardOpenOption.CREATE, StandardOpenOption.APPEND)) {
turnWriter.write("Turn Order\r\n");
int count = 1;
for (final PlayerID currentPlayerId : removeDups(playerSet)) {
turnWriter.write(count + ". " + currentPlayerId.getName() + "\r\n");
count++;
}
}
}
use of games.strategy.engine.data.GameStep in project triplea by triplea-game.
the class ServerGame method notifyGameStepChanged.
private void notifyGameStepChanged(final boolean loadedFromSavedGame) {
final GameStep currentStep = getCurrentStep();
final String stepName = currentStep.getName();
final String delegateName = currentStep.getDelegate().getName();
final String displayName = currentStep.getDisplayName();
final int round = gameData.getSequence().getRound();
final PlayerID id = currentStep.getPlayerId();
notifyGameStepListeners(stepName, delegateName, id, round, displayName);
getGameModifiedBroadcaster().stepChanged(stepName, delegateName, id, round, displayName, loadedFromSavedGame);
}
use of games.strategy.engine.data.GameStep in project triplea by triplea-game.
the class GameDataExporter method sequence.
private void sequence(final GameData data) {
xmlfile.append("\n");
xmlfile.append(" <sequence>\n");
for (final GameStep step : data.getSequence()) {
try {
// TODO: unchecked reflection
final Field delegateField = GameStep.class.getDeclaredField("m_delegate");
delegateField.setAccessible(true);
final String delegate = (String) delegateField.get(step);
xmlfile.append(" <step name=\"").append(step.getName()).append("\" delegate=\"").append(delegate).append("\"");
} catch (final NullPointerException | NoSuchFieldException | IllegalArgumentException | IllegalAccessException e) {
ClientLogger.logError("An Error occured whilst trying to sequence in game " + data.getGameName(), e);
}
if (step.getPlayerId() != null) {
xmlfile.append(" player=\"").append(step.getPlayerId().getName()).append("\"");
}
if (step.getDisplayName() != null) {
xmlfile.append(" display=\"").append(step.getDisplayName()).append("\"");
}
if (step.getMaxRunCount() > -1) {
int maxRun = step.getMaxRunCount();
if (maxRun == 0) {
maxRun = 1;
}
xmlfile.append(" maxRunCount=\"").append(maxRun).append("\"");
}
xmlfile.append("/>\n");
}
xmlfile.append(" </sequence>\n");
}
Aggregations