Skip to content

Commit

Permalink
Fix 10k rounds reached combat error. (#12564)
Browse files Browse the repository at this point in the history
This would happen when edit mode was left on when switching to an AI player.
This changes makes such transitions turn off edit mode as well as making all battle simulations ignore edit mode.
  • Loading branch information
asvitkine committed May 4, 2024
1 parent 3eb8bf0 commit 565f203
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
Expand Up @@ -93,7 +93,7 @@ public GameStep(
properties = stepProperties;
}

public GamePlayer getPlayerId() {
public @Nullable GamePlayer getPlayerId() {
return player;
}

Expand Down
@@ -1,6 +1,7 @@
package games.strategy.engine.framework;

import static com.google.common.base.Preconditions.checkNotNull;
import static games.strategy.triplea.Constants.EDIT_MODE;

import games.strategy.engine.GameOverException;
import games.strategy.engine.data.Change;
Expand Down Expand Up @@ -40,6 +41,7 @@
import games.strategy.net.Messengers;
import games.strategy.net.websocket.ClientNetworkBridge;
import games.strategy.triplea.delegate.DiceRoll;
import games.strategy.triplea.delegate.EditDelegate;
import games.strategy.triplea.settings.ClientSetting;
import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -467,6 +469,15 @@ private void runStep(final boolean stepIsRestoredFromSavedGame) {
? launchAction.getAutoSaveFileUtils().getEvenRoundAutoSaveFile()
: launchAction.getAutoSaveFileUtils().getOddRoundAutoSaveFile());
}
// Turn off Edit Mode if we're transitioning to an AI player to prevent infinite round combats.
if (EditDelegate.getEditMode(gameData.getProperties())) {
GamePlayer newPlayer = gameData.getSequence().getStep().getPlayerId();
if (newPlayer != null && newPlayer.isAi() && !newPlayer.equals(currentStep.getPlayerId())) {
String text = "Turning off Edit Mode when switching to AI player";
gameData.getHistory().getHistoryWriter().startEvent(text);
gameData.getProperties().set(EDIT_MODE, false);
}
}
if (!isMoveStep && shouldAutoSaveAfterEnd(currentDelegate)) {
autoSaveAfter(currentDelegate);
}
Expand Down
@@ -1,5 +1,7 @@
package games.strategy.triplea.odds.calculator;

import static games.strategy.triplea.Constants.EDIT_MODE;

import com.google.common.base.Preconditions;
import games.strategy.engine.data.CompositeChange;
import games.strategy.engine.data.GameData;
Expand Down Expand Up @@ -44,6 +46,7 @@ class BattleCalculator implements IBattleCalculator {

BattleCalculator(byte[] data) {
gameData = GameDataUtils.createGameDataFromBytes(data).orElseThrow();
gameData.getProperties().set(EDIT_MODE, false);
}

@Override
Expand Down

0 comments on commit 565f203

Please sign in to comment.