Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(gameclient): restart a skirmish with the seed it was started with

Olcay Seygana14c42545ed0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a925b6ca8..f72fd461a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -163,6 +163,10 @@ map. Ctrl+A is still everything at once.
- **Loading a save remembers what your guards were guarding.** The guard order was written to the
file one slot too far and overwrote the position it was guarding, so units restored from a save
could come back watching the wrong place.
+- **Restarting a skirmish restarts the same skirmish.** Hitting restart threw away the number the
+ match was built from and started the next attempt on a different one, so the replay it was writing
+ no longer matched the game being played and would not play back. Restart now hands the game back
+ the number it had.
- **Somebody quitting no longer ends the game for everyone else.** The game checks that all the
machines still agree by comparing a fingerprint of the world every so often, and if two of them
differ the match stops. A player leaving sent one last fingerprint from a machine that was already
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/QuitMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/QuitMenu.cpp
index df4920b5b..3df988332 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/QuitMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/QuitMenu.cpp
@@ -52,6 +52,7 @@
#include "GameClient/GameWindowTransitions.h"
#include "GameClient/DisconnectMenu.h"
#include "GameLogic/ScriptEngine.h"
+#include "GameNetwork/GameInfo.h"
#ifdef _INTERNAL
// for occasional debugging...
@@ -204,6 +205,13 @@ static void restartMissionMenu()
Int gameMode = TheGameLogic->getGameMode();
AsciiString mapName = TheGlobalData->m_mapName;
+ /* Read the seed before clearGameData() takes the game apart. A skirmish restart has to be the
+ same match again - EA reseeded with a flat 0 whatever mode was running, so the replay of a
+ restarted skirmish was played back against a different random stream than it was recorded
+ with and diverged immediately. Campaign, challenge and a solo map launched from the skirmish
+ menu all run as GAME_SINGLE_PLAYER and are seeded with 0 everywhere else, so that stays. */
+ const Int seed = (gameMode == GAME_SKIRMISH && TheSkirmishGameInfo) ? TheSkirmishGameInfo->getSeed() : 0;
+
//
// if the map name was from a save game it will have "Save/" at the front of it,
// we want to go back to the original pristine map string for the map name when restarting
@@ -242,11 +250,7 @@ static void restartMissionMenu()
TheScriptEngine->getGlobalDifficulty(),
rankPointsStartedWith)
);
- //if (TheGlobalData->m_fixedSeed >= 0)
- //InitRandom(TheGlobalData->m_fixedSeed);
- InitRandom(0);
- //else
- // InitGameLogicRandom(GameClientRandomValue(0, INT_MAX - 1));
+ InitRandom(seed);
}
//TheTransitionHandler->remove("QuitFull"); //KRISMORNESS ADD
//quitMenuLayout = NULL; //KRISMORNESS ADD
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp
index 043b19d79..13fcd0b26 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp
@@ -431,7 +431,6 @@ void reallyDoStart( void )
TheWritableGlobalData->m_mapName = TheSkirmishGameInfo->getMap();
TheSkirmishGameInfo->startGame(0);
- InitGameLogicRandom(TheSkirmishGameInfo->getSeed());
Bool isSkirmish = TRUE;
const MapMetaData *md = TheMapCache->findMap(TheSkirmishGameInfo->getMap());
@@ -442,6 +441,8 @@ void reallyDoStart( void )
if (isSkirmish)
{
+ InitGameLogicRandom(TheSkirmishGameInfo->getSeed());
+
GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_NEW_GAME );
msg->appendIntegerArgument(GAME_SKIRMISH);
msg->appendIntegerArgument(DIFFICULTY_NORMAL); // not really used; just specified so we can add the game speed last
@@ -450,6 +451,12 @@ void reallyDoStart( void )
}
else
{
+ /* A solo campaign map can be launched from the skirmish menu, and it runs as
+ GAME_SINGLE_PLAYER - which is seeded with 0 everywhere else in the game. EA seeded it
+ with the skirmish lobby's seed here and nowhere else, so the same mission played from the
+ two menus was not the same mission. */
+ InitGameLogicRandom(0);
+
GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_NEW_GAME );
msg->appendIntegerArgument(GAME_SINGLE_PLAYER);
msg->appendIntegerArgument(DIFFICULTY_NORMAL); // not really used; just specified so we can add the game speed last