summaryrefslogtreecommitdiff
path: root/src/cargomonitor.h
diff options
context:
space:
mode:
authorPeter Nelson <peter1138@openttd.org>2019-02-03 23:50:50 +0000
committerCharles Pigott <charlespigott@googlemail.com>2019-02-04 20:43:14 +0000
commit64878320ccac0854b0712730e5f9dedcf0bb591d (patch)
treeab44ae11fa03b8a0e5a31175997bc3825bd24c7d /src/cargomonitor.h
parent0b10678050c82604214136343673a5290f986cdb (diff)
downloadopenttd-64878320ccac0854b0712730e5f9dedcf0bb591d.tar.xz
Fix #6803: CargoMonitorID bit packing updated to handle 64 cargo types.
This requires a saveload bump to change the bitpacking on loading older saves.
Diffstat (limited to 'src/cargomonitor.h')
-rw-r--r--src/cargomonitor.h11
1 files changed, 8 insertions, 3 deletions
diff --git a/src/cargomonitor.h b/src/cargomonitor.h
index 061a1821a..e74f717e0 100644
--- a/src/cargomonitor.h
+++ b/src/cargomonitor.h
@@ -45,11 +45,14 @@ enum CargoCompanyBits {
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.
@@ -61,6 +64,7 @@ enum CargoCompanyBits {
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);
@@ -80,6 +84,7 @@ static inline CargoMonitorID EncodeCargoIndustryMonitor(CompanyID company, Cargo
static inline CargoMonitorID EncodeCargoTownMonitor(CompanyID company, CargoID ctype, TownID town)
{
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, town);