@@ -42,28 +42,32 @@ extern CargoMonitorMap _cargo_deliveries
enum CargoCompanyBits {
CCB_TOWN_IND_NUMBER_START = 0, ///< Start bit of the town or industry number.
CCB_TOWN_IND_NUMBER_LENGTH = 16, ///< Number of bits of the town or industry number.
CCB_IS_INDUSTRY_BIT = 16, ///< Bit indicating the town/industry number is an industry.
CCB_IS_INDUSTRY_BIT_VALUE = 1ul << CCB_IS_INDUSTRY_BIT, ///< Value of the #CCB_IS_INDUSTRY_BIT bit.
CCB_CARGO_TYPE_START = 19, ///< Start bit of the cargo type field.
CCB_CARGO_TYPE_LENGTH = 5, ///< Number of bits of the cargo type field.
CCB_COMPANY_START = 24, ///< Start bit of the company field.
CCB_COMPANY_LENGTH = 8, ///< Number of bits of the company field.
CCB_CARGO_TYPE_LENGTH = 6, ///< Number of bits of the cargo type field.
CCB_COMPANY_START = 25, ///< Start bit of the company field.
CCB_COMPANY_LENGTH = 4, ///< Number of bits of the company field.
};
assert_compile(NUM_CARGO <= (1 << CCB_CARGO_TYPE_LENGTH));
assert_compile(MAX_COMPANIES <= (1 << CCB_COMPANY_LENGTH));
/**
* Encode a cargo monitor for pickup or delivery at an industry.
* @param company Company performing the transport.
* @param ctype Cargo type being transported.
* @param ind %Industry providing or accepting the cargo.
* @return The encoded cargo/company/industry number.
*/
static inline CargoMonitorID EncodeCargoIndustryMonitor(CompanyID company, CargoID ctype, IndustryID ind)
{
assert(ctype < (1 << CCB_CARGO_TYPE_LENGTH));
assert(company < (1 << CCB_COMPANY_LENGTH));
uint32 ret = 0;
SB(ret, CCB_TOWN_IND_NUMBER_START, CCB_TOWN_IND_NUMBER_LENGTH, ind);
SetBit(ret, CCB_IS_INDUSTRY_BIT);
SB(ret, CCB_CARGO_TYPE_START, CCB_CARGO_TYPE_LENGTH, ctype);
SB(ret, CCB_COMPANY_START, CCB_COMPANY_LENGTH, company);
@@ -77,12 +81,13 @@ static inline CargoMonitorID EncodeCargo
* @param town %Town providing or accepting the cargo.
* @return The encoded cargo/company/town number.
static inline CargoMonitorID EncodeCargoTownMonitor(CompanyID company, CargoID ctype, TownID town)
SB(ret, CCB_TOWN_IND_NUMBER_START, CCB_TOWN_IND_NUMBER_LENGTH, town);
return ret;
@@ -26,12 +26,27 @@ struct TempStorage {
static const SaveLoad _cargomonitor_pair_desc[] = {
SLE_VAR(TempStorage, number, SLE_UINT32),
SLE_VAR(TempStorage, amount, SLE_UINT32),
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()
TempStorage storage;
int i = 0;
@@ -49,18 +64,21 @@ static void SaveDelivery()
/** Load the #_cargo_deliveries monitoring map. */
static void LoadDelivery()
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);
@@ -84,18 +102,21 @@ static void SavePickup()
/** Load the #_cargo_pickups monitoring map. */
static void LoadPickup()
ClearCargoPickupMonitoring();
_cargo_pickups.insert(p);
/** Chunk definition of the cargomonitoring maps. */
@@ -287,12 +287,13 @@ enum SaveLoadVersion : uint16 {
SLV_EXTEND_INDUSTRY_CARGO_SLOTS, ///< 202 PR#6867 Increase industry cargo slots to 16 in, 16 out
SLV_SHIP_PATH_CACHE, ///< 203 PR#7072 Add path cache for ships
SLV_SHIP_ROTATION, ///< 204 PR#7065 Add extra rotation stages for ships.
SLV_GROUP_LIVERIES, ///< 205 PR#7108 Livery storage change and group liveries.
SLV_SHIPS_STOP_IN_LOCKS, ///< 206 PR#7150 Ship/lock movement changes.
SLV_FIX_CARGO_MONITOR, ///< 207 PR#7175 Cargo monitor data packing fix to support 64 cargotypes.
SL_MAX_VERSION, ///< Highest possible saveload version
/** Save or load result codes. */
enum SaveOrLoadResult {
Status change: