Fix #6803: CargoMonitorID bit packing updated to handle 64 cargo types.

This requires a saveload bump to change the bitpacking on loading older saves.
This commit is contained in:
Peter Nelson
2019-02-03 23:50:50 +00:00
committed by Charles Pigott
parent 0b10678050
commit 64878320cc
3 changed files with 30 additions and 3 deletions

View File

@@ -29,6 +29,21 @@ static const SaveLoad _cargomonitor_pair_desc[] = {
SLE_END()
};
static CargoMonitorID FixupCargoMonitor(CargoMonitorID number)
{
/* Between SLV_EXTEND_CARGOTYPES and SLV_FIX_CARGO_MONITOR, the
* CargoMonitorID structure had insufficient packing for more
* than 32 cargo types. Here we have to shuffle bits to account
* for the change.
* Company moved from bits 24-31 to 25-28.
* Cargo type increased from bits 19-23 to 19-24.
*/
SB(number, 25, 4, GB(number, 24, 4));
SB(number, 29, 3, 0);
ClrBit(number, 24);
return number;
}
/** Save the #_cargo_deliveries monitoring map. */
static void SaveDelivery()
{
@@ -52,12 +67,15 @@ static void SaveDelivery()
static void LoadDelivery()
{
TempStorage storage;
bool fix = IsSavegameVersionBefore(SLV_FIX_CARGO_MONITOR);
ClearCargoDeliveryMonitoring();
for (;;) {
if (SlIterateArray() < 0) break;
SlObject(&storage, _cargomonitor_pair_desc);
if (fix) storage.number = FixupCargoMonitor(storage.number);
std::pair<CargoMonitorID, uint32> p(storage.number, storage.amount);
_cargo_deliveries.insert(p);
}
@@ -87,12 +105,15 @@ static void SavePickup()
static void LoadPickup()
{
TempStorage storage;
bool fix = IsSavegameVersionBefore(SLV_FIX_CARGO_MONITOR);
ClearCargoPickupMonitoring();
for (;;) {
if (SlIterateArray() < 0) break;
SlObject(&storage, _cargomonitor_pair_desc);
if (fix) storage.number = FixupCargoMonitor(storage.number);
std::pair<CargoMonitorID, uint32> p(storage.number, storage.amount);
_cargo_pickups.insert(p);
}