Search in sources :

Example 1 with GameStep

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;
}
Also used : IntegerMap(games.strategy.util.IntegerMap) Territory(games.strategy.engine.data.Territory) Resource(games.strategy.engine.data.Resource) GameStep(games.strategy.engine.data.GameStep)

Example 2 with GameStep

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));
    }
}
Also used : AutoSave(games.strategy.engine.delegate.AutoSave) GameStep(games.strategy.engine.data.GameStep) IDelegate(games.strategy.engine.delegate.IDelegate)

Example 3 with GameStep

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++;
        }
    }
}
Also used : BidPlaceDelegate(games.strategy.triplea.delegate.BidPlaceDelegate) PlayerID(games.strategy.engine.data.PlayerID) GameData(games.strategy.engine.data.GameData) GameStep(games.strategy.engine.data.GameStep) File(java.io.File) Writer(java.io.Writer)

Example 4 with GameStep

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);
}
Also used : PlayerID(games.strategy.engine.data.PlayerID) GameStep(games.strategy.engine.data.GameStep)

Example 5 with GameStep

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");
}
Also used : Field(java.lang.reflect.Field) GameStep(games.strategy.engine.data.GameStep)

Aggregations

GameStep (games.strategy.engine.data.GameStep)9 PlayerID (games.strategy.engine.data.PlayerID)5 GameData (games.strategy.engine.data.GameData)4 GameSequence (games.strategy.engine.data.GameSequence)2 Territory (games.strategy.engine.data.Territory)2 IDelegate (games.strategy.engine.delegate.IDelegate)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Resource (games.strategy.engine.data.Resource)1 AutoSave (games.strategy.engine.delegate.AutoSave)1 IDelegateBridge (games.strategy.engine.delegate.IDelegateBridge)1 IGame (games.strategy.engine.framework.IGame)1 SystemProperties (games.strategy.engine.framework.system.SystemProperties)1 PBEMMessagePoster (games.strategy.engine.pbem.PBEMMessagePoster)1 ProPurchaseTerritory (games.strategy.triplea.ai.pro.data.ProPurchaseTerritory)1 ProTerritory (games.strategy.triplea.ai.pro.data.ProTerritory)1 ProDummyDelegateBridge (games.strategy.triplea.ai.pro.simulate.ProDummyDelegateBridge)1 PoliticalActionAttachment (games.strategy.triplea.attachments.PoliticalActionAttachment)1 BidPlaceDelegate (games.strategy.triplea.delegate.BidPlaceDelegate)1 GameStepPropertiesHelper (games.strategy.triplea.delegate.GameStepPropertiesHelper)1