mirror of https://github.com/OpenTTD/OpenTTD.git
Fix: Incorrect save/load array size of Town::cargo_accepted
In 11ab3c4e
the number of cargo types was changed from 32 to 64.
The save/load of Town::cargo_accepted was not updated, such that
only half of the data structure is saved/loaded in savegame versions
199 to 218.
Discard and regenerate data from all savegame versions prior to 219.
This commit is contained in:
parent
54237b0e98
commit
7a09413a1a
|
@ -2830,7 +2830,7 @@ bool AfterLoadGame()
|
||||||
* which is done by StartupEngines(). */
|
* which is done by StartupEngines(). */
|
||||||
if (gcf_res != GLC_ALL_GOOD) StartupEngines();
|
if (gcf_res != GLC_ALL_GOOD) StartupEngines();
|
||||||
|
|
||||||
if (IsSavegameVersionBefore(SLV_166)) {
|
if (IsSavegameVersionBefore(SLV_FIX_TOWN_ACCEPTANCE)) {
|
||||||
/* Update cargo acceptance map of towns. */
|
/* Update cargo acceptance map of towns. */
|
||||||
for (TileIndex t = 0; t < map_size; t++) {
|
for (TileIndex t = 0; t < map_size; t++) {
|
||||||
if (!IsTileType(t, MP_HOUSE)) continue;
|
if (!IsTileType(t, MP_HOUSE)) continue;
|
||||||
|
|
|
@ -302,6 +302,7 @@ enum SaveLoadVersion : uint16 {
|
||||||
SLV_MULTITILE_DOCKS, ///< 216 PR#7380 Multiple docks per station.
|
SLV_MULTITILE_DOCKS, ///< 216 PR#7380 Multiple docks per station.
|
||||||
SLV_TRADING_AGE, ///< 217 PR#7780 Configurable company trading age.
|
SLV_TRADING_AGE, ///< 217 PR#7780 Configurable company trading age.
|
||||||
SLV_ENDING_YEAR, ///< 218 PR#7747 v1.10 Configurable ending year.
|
SLV_ENDING_YEAR, ///< 218 PR#7747 v1.10 Configurable ending year.
|
||||||
|
SLV_FIX_TOWN_ACCEPTANCE, ///< 219 PR#8157 Fix Town::cargo_accepted savegame format.
|
||||||
|
|
||||||
SL_MAX_VERSION, ///< Highest possible saveload version
|
SL_MAX_VERSION, ///< Highest possible saveload version
|
||||||
};
|
};
|
||||||
|
|
|
@ -256,7 +256,7 @@ static void RealSave_Town(Town *t)
|
||||||
SlObject(&t->cargo_accepted, GetTileMatrixDesc());
|
SlObject(&t->cargo_accepted, GetTileMatrixDesc());
|
||||||
if (t->cargo_accepted.area.w != 0) {
|
if (t->cargo_accepted.area.w != 0) {
|
||||||
uint arr_len = t->cargo_accepted.area.w / AcceptanceMatrix::GRID * t->cargo_accepted.area.h / AcceptanceMatrix::GRID;
|
uint arr_len = t->cargo_accepted.area.w / AcceptanceMatrix::GRID * t->cargo_accepted.area.h / AcceptanceMatrix::GRID;
|
||||||
SlArray(t->cargo_accepted.data, arr_len, SLE_UINT32);
|
SlArray(t->cargo_accepted.data, arr_len, SLE_UINT64);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,17 +288,24 @@ static void Load_TOWN()
|
||||||
SlErrorCorrupt("Invalid town name generator");
|
SlErrorCorrupt("Invalid town name generator");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IsSavegameVersionBefore(SLV_166)) continue;
|
if (!IsSavegameVersionBefore(SLV_FIX_TOWN_ACCEPTANCE)) {
|
||||||
|
|
||||||
SlObject(&t->cargo_accepted, GetTileMatrixDesc());
|
SlObject(&t->cargo_accepted, GetTileMatrixDesc());
|
||||||
if (t->cargo_accepted.area.w != 0) {
|
if (t->cargo_accepted.area.w != 0) {
|
||||||
uint arr_len = t->cargo_accepted.area.w / AcceptanceMatrix::GRID * t->cargo_accepted.area.h / AcceptanceMatrix::GRID;
|
uint arr_len = t->cargo_accepted.area.w / AcceptanceMatrix::GRID * t->cargo_accepted.area.h / AcceptanceMatrix::GRID;
|
||||||
t->cargo_accepted.data = MallocT<CargoTypes>(arr_len);
|
t->cargo_accepted.data = MallocT<CargoTypes>(arr_len);
|
||||||
SlArray(t->cargo_accepted.data, arr_len, SLE_UINT32);
|
SlArray(t->cargo_accepted.data, arr_len, SLE_UINT64);
|
||||||
|
|
||||||
/* Rebuild total cargo acceptance. */
|
/* Rebuild total cargo acceptance. */
|
||||||
UpdateTownCargoTotal(t);
|
UpdateTownCargoTotal(t);
|
||||||
}
|
}
|
||||||
|
} else if (!IsSavegameVersionBefore(SLV_166)) {
|
||||||
|
AcceptanceMatrix cargo_accepted;
|
||||||
|
SlObject(&cargo_accepted, GetTileMatrixDesc());
|
||||||
|
if (cargo_accepted.area.w != 0) {
|
||||||
|
uint arr_len = cargo_accepted.area.w / AcceptanceMatrix::GRID * cargo_accepted.area.h / AcceptanceMatrix::GRID;
|
||||||
|
SlSkipBytes(4 * arr_len);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue