77#include " Game.h"
88#include " GamePlayer.h"
99#include " Replay.h"
10+ #include " Savegame.h"
1011#include " Timer.h"
1112#include " helpers/chronoIO.h"
1213#include " network/PlayerGameCommands.h"
@@ -31,6 +32,14 @@ struct Fixture : rttr::test::Fixture
3132{
3233 Fixture () { libsiedler2::setAllocator (new GlAllocator); }
3334};
35+ struct MockGameState : ILocalGameState
36+ {
37+ public:
38+ unsigned GetPlayerId () const override { return 0 ; }
39+ bool IsHost () const override { return true ; }
40+ std::string FormatGFTime (unsigned ) const override { return " " ; }
41+ void SystemChat (const std::string& text) override {}
42+ };
3443BOOST_GLOBAL_FIXTURE (Fixture);
3544
3645static boost::test_tools::predicate_result verifyChecksum (const AsyncChecksum& actual, const AsyncChecksum& expected,
@@ -47,30 +56,38 @@ static boost::test_tools::predicate_result verifyChecksum(const AsyncChecksum& a
4756 // LCOV_EXCL_STOP
4857}
4958
50- static void playReplay (const boost::filesystem::path& replayPath)
59+ static void playReplay (const boost::filesystem::path& replayPath, const bool isSavegame )
5160{
5261 Replay replay;
5362 BOOST_TEST_REQUIRE (replay.LoadHeader (replayPath));
5463 MapInfo mapInfo;
5564 BOOST_TEST_REQUIRE (replay.LoadGameData (mapInfo));
56- BOOST_TEST_REQUIRE (!mapInfo.savegame ); // Must be from start
57- TmpFile mapfile;
58- mapfile.close ();
59- BOOST_TEST_REQUIRE (mapInfo.mapData .DecompressToFile (mapfile.filePath ));
60-
6165 std::vector<PlayerInfo> players;
6266 for (unsigned i = 0 ; i < replay.GetNumPlayers (); i++)
6367 players.emplace_back (replay.GetPlayer (i));
6468 Game game (replay.ggs , /* startGF*/ 0 , players);
6569 RANDOM .Init (replay.getSeed ());
6670 GameWorld& gameWorld = game.world_ ;
6771
68- for (unsigned i = 0 ; i < gameWorld.GetNumPlayers (); ++i)
69- gameWorld.GetPlayer (i).MakeStartPacts ();
72+ if (isSavegame)
73+ {
74+ BOOST_TEST_REQUIRE (mapInfo.savegame );
75+ MockGameState gs;
76+ mapInfo.savegame ->sgd .ReadSnapshot (game, gs);
77+ } else
78+ {
79+ TmpFile mapfile;
80+ mapfile.close ();
81+ BOOST_TEST_REQUIRE (!mapInfo.savegame );
82+ BOOST_TEST_REQUIRE (mapInfo.mapData .DecompressToFile (mapfile.filePath ));
83+ MapLoader loader (gameWorld);
84+ BOOST_TEST_REQUIRE (loader.Load (mapfile.filePath ));
85+ MapLoader::SetupResources (gameWorld);
86+
87+ for (unsigned i = 0 ; i < gameWorld.GetNumPlayers (); ++i)
88+ gameWorld.GetPlayer (i).MakeStartPacts ();
89+ }
7090
71- MapLoader loader (gameWorld);
72- BOOST_TEST_REQUIRE (loader.Load (mapfile.filePath ));
73- MapLoader::SetupResources (gameWorld);
7491 gameWorld.InitAfterLoad ();
7592
7693 bool endOfReplay = false ;
@@ -111,14 +128,15 @@ static void playReplay(const boost::filesystem::path& replayPath)
111128
112129BOOST_AUTO_TEST_CASE (Play200kReplay)
113130{
114- // Map: Big Slaughter v2
131+ // Map: Others/ Big Slaughter v2
115132 // 7 x Hard KI
116133 // 2 KIs each in Teams 1-3, 1 in Team 4
117134 // Player KI without team ("WINTER" + F10)
118135 // Default addon settings
136+ // Save immediately, then load (so savegame is embedded instead of map)
119137 // 200k GFs run (+ a bit)
120138 const boost::filesystem::path replayPath = rttr::test::rttrBaseDir / " tests" / " testData" / " 200kGFs.rpl" ;
121- playReplay (replayPath);
139+ playReplay (replayPath, true );
122140}
123141
124142BOOST_AUTO_TEST_CASE (PlaySeaReplay)
@@ -128,5 +146,5 @@ BOOST_AUTO_TEST_CASE(PlaySeaReplay)
128146 // No teams, Sea attacks enabled (harbors block), ships fast
129147 // 300k GFs run (+ a bit)
130148 const boost::filesystem::path replayPath = rttr::test::rttrBaseDir / " tests" / " testData" / " SeaMap300kGfs.rpl" ;
131- playReplay (replayPath);
149+ playReplay (replayPath, false );
132150}
0 commit comments