Skip to content

Commit 4d04897

Browse files
committed
Fix replay compat for removing invalid fish resources
The 200kGFs replay has been updated to use a savegame.
1 parent f958d55 commit 4d04897

5 files changed

Lines changed: 14 additions & 6 deletions

File tree

libs/s25main/Replay.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,8 @@ uint8_t Replay::GetLatestMinorVersion() const
4040
// 8.1: Portraits support
4141
// 8.2: Set correct initial distributions if replay starts without savegame for leather addon (see GameClient.cpp
4242
// StartReplay function for detailed description)
43-
return 2;
43+
// 8.3 Remove invalid fish for replays started from start (i.e. map instead of savegame)
44+
return 3;
4445
}
4546

4647
uint8_t Replay::GetLatestMajorVersion() const

libs/s25main/network/GameClient.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,9 @@ void GameClient::StartGame(const unsigned random_init)
337337
OnError(ClientError::InvalidMap);
338338
return;
339339
}
340-
MapLoader::SetupResources(gameWorld);
340+
// TODO (Replay): Always use true
341+
const bool fixFish = !GetReplay() || GetReplay()->GetMinorVersion() >= 3;
342+
MapLoader::SetupResources(gameWorld, fixFish);
341343
}
342344
gameWorld.InitAfterLoad();
343345

libs/s25main/world/MapLoader.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ bool MapLoader::PlaceHQs(bool addStartWares)
110110
return PlaceHQs(world_, hqPositions, addStartWares);
111111
}
112112

113-
void MapLoader::SetupResources(GameWorldBase& world)
113+
void MapLoader::SetupResources(GameWorldBase& world, const bool fixFish)
114114
{
115115
ResourceType target;
116116
switch(world.GetGGS().getSelection(AddonId::CHANGE_GOLD_DEPOSITS))
@@ -124,7 +124,8 @@ void MapLoader::SetupResources(GameWorldBase& world)
124124
}
125125
ConvertMineResourceTypes(world, ResourceType::Gold, target);
126126
PlaceAndFixWater(world);
127-
RemoveUnusableFishResources(world);
127+
if(fixFish)
128+
RemoveUnusableFishResources(world);
128129
}
129130

130131
void MapLoader::ConvertMineResourceTypes(GameWorldBase& world, ResourceType from, ResourceType to)

libs/s25main/world/MapLoader.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ class MapLoader
5252
/// Return false if there was an error (e.g. invalid start position)
5353
bool PlaceHQs(bool addStartWares = true);
5454
/// Setup resources like gold and water after loading a new map.
55-
static void SetupResources(GameWorldBase& world);
55+
/// TODO(Replay): Remove fixFish (always set to true)
56+
static void SetupResources(GameWorldBase& world, bool fixFish = true);
5657

5758
/// Return the (original/unshuffled) position of the players HQ (only valid after successful load)
5859
MapPoint GetOriginalHQPos(unsigned player) const { return hqPositions_[player]; }

tests/s25Main/autoplay/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ static void playReplay(const boost::filesystem::path& replayPath, const bool isS
8282
BOOST_TEST_REQUIRE(mapInfo.mapData.DecompressToFile(mapfile.filePath));
8383
MapLoader loader(gameWorld);
8484
BOOST_TEST_REQUIRE(loader.Load(mapfile.filePath));
85-
MapLoader::SetupResources(gameWorld);
85+
// TODO(replay): Since 8.3 invalid fish is removed when starting from map
86+
BOOST_TEST_REQUIRE(replay.GetMajorVersion() == 8u);
87+
BOOST_TEST_REQUIRE(replay.GetMinorVersion() < 3u);
88+
MapLoader::SetupResources(gameWorld, false);
8689

8790
for(unsigned i = 0; i < gameWorld.GetNumPlayers(); ++i)
8891
gameWorld.GetPlayer(i).MakeStartPacts();

0 commit comments

Comments
 (0)