Codechange: Simplify storage of WaterTileType in map. (#13030)

This commit is contained in:
Peter Nelson
2024-10-26 10:17:44 +01:00
committed by GitHub
parent e50c1774fc
commit 4f9c10d35f
5 changed files with 144 additions and 120 deletions
+21
View File
@@ -840,6 +840,27 @@ bool AfterLoadGame()
cp->current_station = cp->front->last_station_visited;
}
if (IsSavegameVersionBefore(SLV_WATER_TILE_TYPE)) {
/* Prior to SLV_WATER_TILE_TYPE, the water tile type was stored differently from the enumeration. This has to be
* converted before SLV_72 and SLV_82 conversions which use GetWaterTileType. */
static constexpr uint8_t WBL_COAST_FLAG = 0; ///< Flag for coast.
for (auto t : Map::Iterate()) {
if (!IsTileType(t, MP_WATER)) continue;
switch (GB(t.m5(), 4, 4)) {
case 0x0: /* Previously WBL_TYPE_NORMAL, Clear water or coast. */
SetWaterTileType(t, HasBit(t.m5(), WBL_COAST_FLAG) ? WATER_TILE_COAST : WATER_TILE_CLEAR);
break;
case 0x1: SetWaterTileType(t, WATER_TILE_LOCK); break; /* Previously WBL_TYPE_LOCK */
case 0x8: SetWaterTileType(t, WATER_TILE_DEPOT); break; /* Previously WBL_TYPE_DEPOT */
default: SetWaterTileType(t, WATER_TILE_CLEAR); break; /* Shouldn't happen... */
}
}
}
if (IsSavegameVersionBefore(SLV_72)) {
/* Locks in very old savegames had OWNER_WATER as owner */
for (auto t : Map::Iterate()) {