1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-03-19 21:10:12 +02:00

Try to fix saving of corrupted random maps

This commit is contained in:
Ivan Savenko 2024-08-15 16:03:00 +00:00
parent 66d96e6ef6
commit be42a8c58b

View File

@ -312,6 +312,28 @@ void CGameState::initNewGame(const IMapService * mapService, bool allowSavingRan
std::unique_ptr<CMap> randomMap = mapGenerator.generate();
progressTracking.exclude(mapGenerator);
map = randomMap.release();
// Update starting options
for(int i = 0; i < map->players.size(); ++i)
{
const auto & playerInfo = map->players[i];
if(playerInfo.canAnyonePlay())
{
PlayerSettings & playerSettings = scenarioOps->playerInfos[PlayerColor(i)];
playerSettings.compOnly = !playerInfo.canHumanPlay;
playerSettings.castle = playerInfo.defaultCastle();
if(playerSettings.isControlledByAI() && playerSettings.name.empty())
{
playerSettings.name = VLC->generaltexth->allTexts[468];
}
playerSettings.color = PlayerColor(i);
}
else
{
scenarioOps->playerInfos.erase(PlayerColor(i));
}
}
if(allowSavingRandomMap)
{
try
@ -341,28 +363,6 @@ void CGameState::initNewGame(const IMapService * mapService, bool allowSavingRan
}
}
map = randomMap.release();
// Update starting options
for(int i = 0; i < map->players.size(); ++i)
{
const auto & playerInfo = map->players[i];
if(playerInfo.canAnyonePlay())
{
PlayerSettings & playerSettings = scenarioOps->playerInfos[PlayerColor(i)];
playerSettings.compOnly = !playerInfo.canHumanPlay;
playerSettings.castle = playerInfo.defaultCastle();
if(playerSettings.isControlledByAI() && playerSettings.name.empty())
{
playerSettings.name = VLC->generaltexth->allTexts[468];
}
playerSettings.color = PlayerColor(i);
}
else
{
scenarioOps->playerInfos.erase(PlayerColor(i));
}
}
logGlobal->info("Generated random map in %i ms.", sw.getDiff());
}
else