Extend industry production/transported totals to 32 bits

pull/678/head
Jonathan G Rennison 2 months ago
parent cc2521ddf5
commit 9f205727bf

@ -67,16 +67,16 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> {
TileArea location; ///< Location of the industry
Town *town; ///< Nearest town
Station *neutral_station; ///< Associated neutral station
std::array<CargoID, INDUSTRY_NUM_INPUTS> accepts_cargo{};
std::array<CargoID, INDUSTRY_NUM_OUTPUTS> produced_cargo{}; ///< 16 production cargo slots
std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> produced_cargo_waiting{}; ///< amount of cargo produced per cargo
std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> incoming_cargo_waiting{}; ///< incoming cargo waiting to be processed
std::array<byte, INDUSTRY_NUM_OUTPUTS> production_rate{}; ///< production rate for each cargo
std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> this_month_production{}; ///< stats of this month's production per cargo
std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> this_month_transported{}; ///< stats of this month's transport per cargo
std::array<byte, INDUSTRY_NUM_OUTPUTS> last_month_pct_transported{}; ///< percentage transported per cargo in the last full month
std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> last_month_production{}; ///< total units produced per cargo in the last full month
std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> last_month_transported{}; ///< total units transported per cargo in the last full month
std::array<CargoID, INDUSTRY_NUM_INPUTS> accepts_cargo{};
std::array<CargoID, INDUSTRY_NUM_OUTPUTS> produced_cargo{}; ///< 16 production cargo slots
std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> produced_cargo_waiting{}; ///< amount of cargo produced per cargo
std::array<uint16_t, INDUSTRY_NUM_OUTPUTS> incoming_cargo_waiting{}; ///< incoming cargo waiting to be processed
std::array<byte, INDUSTRY_NUM_OUTPUTS> production_rate{}; ///< production rate for each cargo
std::array<uint32_t, INDUSTRY_NUM_OUTPUTS> this_month_production{}; ///< stats of this month's production per cargo
std::array<uint32_t, INDUSTRY_NUM_OUTPUTS> this_month_transported{}; ///< stats of this month's transport per cargo
std::array<byte, INDUSTRY_NUM_OUTPUTS> last_month_pct_transported{}; ///< percentage transported per cargo in the last full month
std::array<uint32_t, INDUSTRY_NUM_OUTPUTS> last_month_production{}; ///< total units produced per cargo in the last full month
std::array<uint32_t, INDUSTRY_NUM_OUTPUTS> last_month_transported{}; ///< total units transported per cargo in the last full month
StationList stations_near; ///< NOSAVE: List of nearby stations.
mutable std::string cached_name; ///< NOSAVE: Cache of the resolved name of the industry

@ -533,10 +533,10 @@ static bool TransportIndustryGoods(TileIndex tile)
/* fluctuating economy? */
if (EconomyIsInRecession()) cw = (cw + 1) / 2;
i->this_month_production[j] = std::min<uint>(i->this_month_production[j] + cw, 0xFFFF);
i->this_month_production[j] = SaturatingAdd<uint32_t>(i->this_month_production[j], cw);
uint am = MoveGoodsToStation(i->produced_cargo[j], cw, SourceType::Industry, i->index, &i->stations_near, i->exclusive_consumer);
i->this_month_transported[j] += am;
i->this_month_transported[j] = SaturatingAdd<uint32_t>(i->this_month_transported[j], am);
moved_cargo |= (am != 0);
}
@ -2578,7 +2578,7 @@ static void UpdateIndustryStatistics(Industry *i)
byte pct = 0;
if (i->this_month_production[j] != 0) {
i->last_prod_year = EconTime::CurYear();
pct = ClampTo<byte>(i->this_month_transported[j] * 256 / i->this_month_production[j]);
pct = ClampTo<byte>(((uint64_t)i->this_month_transported[j]) * 256 / i->this_month_production[j]);
}
i->last_month_pct_transported[j] = pct;

@ -1591,7 +1591,7 @@ protected:
/* Get industry productions (CargoID, production, suffix, transported) */
struct CargoInfo {
CargoID cargo_id;
uint16_t production;
uint32_t production;
const char *suffix;
uint transported;
};

@ -347,10 +347,10 @@ uint32_t IndustriesScopeResolver::GetCountAndDistanceOfClosestInstance(byte para
if (index < 0) return 0; // invalid cargo
switch (variable) {
case 0x69: return this->industry->produced_cargo_waiting[index];
case 0x6A: return this->industry->this_month_production[index];
case 0x6B: return this->industry->this_month_transported[index];
case 0x6C: return this->industry->last_month_production[index];
case 0x6D: return this->industry->last_month_transported[index];
case 0x6A: return ClampTo<uint16_t>(this->industry->this_month_production[index]);
case 0x6B: return ClampTo<uint16_t>(this->industry->this_month_transported[index]);
case 0x6C: return ClampTo<uint16_t>(this->industry->last_month_production[index]);
case 0x6D: return ClampTo<uint16_t>(this->industry->last_month_transported[index]);
case 0x70: return this->industry->production_rate[index];
case 0x71: return this->industry->last_month_pct_transported[index];
default: NOT_REACHED();
@ -396,15 +396,15 @@ uint32_t IndustriesScopeResolver::GetCountAndDistanceOfClosestInstance(byte para
case 0x92: return this->industry->accepts_cargo[variable - 0x90];
case 0x93: return this->industry->prod_level;
/* amount of cargo produced so far THIS month. */
case 0x94: return this->industry->this_month_production[0];
case 0x95: return GB(this->industry->this_month_production[0], 8, 8);
case 0x96: return this->industry->this_month_production[1];
case 0x97: return GB(this->industry->this_month_production[1], 8, 8);
case 0x94: return ClampTo<uint16_t>(this->industry->this_month_production[0]);
case 0x95: return GB(ClampTo<uint16_t>(this->industry->this_month_production[0]), 8, 8);
case 0x96: return ClampTo<uint16_t>(this->industry->this_month_production[1]);
case 0x97: return GB(ClampTo<uint16_t>(this->industry->this_month_production[1]), 8, 8);
/* amount of cargo transported so far THIS month. */
case 0x98: return this->industry->this_month_transported[0];
case 0x99: return GB(this->industry->this_month_transported[0], 8, 8);
case 0x9A: return this->industry->this_month_transported[1];
case 0x9B: return GB(this->industry->this_month_transported[1], 8, 8);
case 0x98: return ClampTo<uint16_t>(this->industry->this_month_transported[0]);
case 0x99: return GB(ClampTo<uint16_t>(this->industry->this_month_transported[0]), 8, 8);
case 0x9A: return ClampTo<uint16_t>(this->industry->this_month_transported[1]);
case 0x9B: return GB(ClampTo<uint16_t>(this->industry->this_month_transported[1]), 8, 8);
/* fraction of cargo transported LAST month. */
case 0x9C:
case 0x9D: return this->industry->last_month_pct_transported[variable - 0x9C];

@ -156,16 +156,16 @@ static const SaveLoad _industry_desc[] = {
SLE_CONDARR(Industry, accepts_cargo, SLE_UINT8, 3, SLV_78, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR(Industry, accepts_cargo, SLE_UINT8, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE),
SLE_VAR(Industry, prod_level, SLE_UINT8),
SLE_CONDARR(Industry, this_month_production, SLE_UINT16, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR(Industry, this_month_production, SLE_UINT16, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE),
SLE_CONDARR(Industry, this_month_transported, SLE_UINT16, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR(Industry, this_month_transported, SLE_UINT16, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE),
SLE_CONDARR(Industry, last_month_pct_transported, SLE_UINT8, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR(Industry, last_month_pct_transported, SLE_UINT8, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE),
SLE_CONDARR(Industry, last_month_production, SLE_UINT16, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR(Industry, last_month_production, SLE_UINT16, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE),
SLE_CONDARR(Industry, last_month_transported, SLE_UINT16, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR(Industry, last_month_transported, SLE_UINT16, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE),
SLE_CONDARR(Industry, this_month_production, SLE_FILE_U16 | SLE_VAR_U32, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR(Industry, this_month_production, SLE_FILE_U16 | SLE_VAR_U32, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE),
SLE_CONDARR(Industry, this_month_transported, SLE_FILE_U16 | SLE_VAR_U32, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR(Industry, this_month_transported, SLE_FILE_U16 | SLE_VAR_U32, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE),
SLE_CONDARR(Industry, last_month_pct_transported, SLE_UINT8, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR(Industry, last_month_pct_transported, SLE_UINT8, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE),
SLE_CONDARR(Industry, last_month_production, SLE_FILE_U16 | SLE_VAR_U32, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR(Industry, last_month_production, SLE_FILE_U16 | SLE_VAR_U32, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE),
SLE_CONDARR(Industry, last_month_transported, SLE_FILE_U16 | SLE_VAR_U32, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR(Industry, last_month_transported, SLE_FILE_U16 | SLE_VAR_U32, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE),
SLE_VAR(Industry, counter, SLE_UINT16),

@ -193,6 +193,7 @@ const SlxiSubChunkInfo _sl_xv_sub_chunk_infos[] = {
{ XSLFI_VARIABLE_TICK_RATE, XSCF_IGNORABLE_ALL, 1, 1, "variable_tick_rate", nullptr, nullptr, nullptr },
{ XSLFI_ROAD_VEH_FLAGS, XSCF_NULL, 1, 1, "road_veh_flags", nullptr, nullptr, nullptr },
{ XSLFI_STATION_TILE_CACHE_FLAGS, XSCF_IGNORABLE_ALL, 1, 1, "station_tile_cache_flags", saveSTC, loadSTC, nullptr },
{ XSLFI_INDUSTRY_CARGO_TOTALS, XSCF_NULL, 1, 1, "industry_cargo_totals", nullptr, nullptr, nullptr },
{ XSLFI_SCRIPT_INT64, XSCF_NULL, 1, 1, "script_int64", nullptr, nullptr, nullptr },
{ XSLFI_U64_TICK_COUNTER, XSCF_NULL, 1, 1, "u64_tick_counter", nullptr, nullptr, nullptr },

@ -142,6 +142,7 @@ enum SlXvFeatureIndex {
XSLFI_VARIABLE_TICK_RATE, ///< Variable tick rate
XSLFI_ROAD_VEH_FLAGS, ///< Road vehicle flags
XSLFI_STATION_TILE_CACHE_FLAGS, ///< Station tile cache flags
XSLFI_INDUSTRY_CARGO_TOTALS, ///< Industry cargo totals are 32 bit
XSLFI_SCRIPT_INT64, ///< See: SLV_SCRIPT_INT64
XSLFI_U64_TICK_COUNTER, ///< See: SLV_U64_TICK_COUNTER

@ -37,16 +37,20 @@ static const SaveLoad _industry_desc[] = {
SLE_CONDARR(Industry, accepts_cargo, SLE_UINT8, 3, SLV_78, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR(Industry, accepts_cargo, SLE_UINT8, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SL_MAX_VERSION),
SLE_VAR(Industry, prod_level, SLE_UINT8),
SLE_CONDARR(Industry, this_month_production, SLE_UINT16, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR(Industry, this_month_production, SLE_UINT16, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SL_MAX_VERSION),
SLE_CONDARR(Industry, this_month_transported, SLE_UINT16, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR(Industry, this_month_transported, SLE_UINT16, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SL_MAX_VERSION),
SLE_CONDARR(Industry, last_month_pct_transported, SLE_UINT8, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR(Industry, last_month_pct_transported, SLE_UINT8, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SL_MAX_VERSION),
SLE_CONDARR(Industry, last_month_production, SLE_UINT16, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR(Industry, last_month_production, SLE_UINT16, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SL_MAX_VERSION),
SLE_CONDARR(Industry, last_month_transported, SLE_UINT16, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR(Industry, last_month_transported, SLE_UINT16, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SL_MAX_VERSION),
SLE_CONDARR(Industry, this_month_production, SLE_FILE_U16 | SLE_VAR_U32, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR_X(Industry, this_month_production, SLE_FILE_U16 | SLE_VAR_U32, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_INDUSTRY_CARGO_TOTALS, 0, 0)),
SLE_CONDARR_X(Industry, this_month_production, SLE_UINT32, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_INDUSTRY_CARGO_TOTALS, 1)),
SLE_CONDARR(Industry, this_month_transported, SLE_FILE_U16 | SLE_VAR_U32, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR_X(Industry, this_month_transported, SLE_FILE_U16 | SLE_VAR_U32, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_INDUSTRY_CARGO_TOTALS, 0, 0)),
SLE_CONDARR_X(Industry, this_month_transported, SLE_UINT32, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_INDUSTRY_CARGO_TOTALS, 1)),
SLE_CONDARR(Industry, last_month_pct_transported, SLE_UINT8, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR(Industry, last_month_pct_transported, SLE_UINT8, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SL_MAX_VERSION),
SLE_CONDARR(Industry, last_month_production, SLE_FILE_U16 | SLE_VAR_U32, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR_X(Industry, last_month_production, SLE_FILE_U16 | SLE_VAR_U32, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_INDUSTRY_CARGO_TOTALS, 0, 0)),
SLE_CONDARR_X(Industry, last_month_production, SLE_UINT32, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_INDUSTRY_CARGO_TOTALS, 1)),
SLE_CONDARR(Industry, last_month_transported, SLE_FILE_U16 | SLE_VAR_U32, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS),
SLE_CONDARR_X(Industry, last_month_transported, SLE_FILE_U16 | SLE_VAR_U32, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_INDUSTRY_CARGO_TOTALS, 0, 0)),
SLE_CONDARR_X(Industry, last_month_transported, SLE_UINT32, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SL_MAX_VERSION, SlXvFeatureTest(XSLFTO_AND, XSLFI_INDUSTRY_CARGO_TOTALS, 1)),
SLE_VAR(Industry, counter, SLE_UINT16),

@ -822,18 +822,18 @@ static const OldChunks industry_chunk[] = {
OCL_SVAR( OC_UINT8, Industry, prod_level ),
OCL_SVAR( OC_UINT16, Industry, this_month_production[0] ),
OCL_SVAR( OC_UINT16, Industry, this_month_production[1] ),
OCL_SVAR( OC_UINT16, Industry, this_month_transported[0] ),
OCL_SVAR( OC_UINT16, Industry, this_month_transported[1] ),
OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Industry, this_month_production[0] ),
OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Industry, this_month_production[1] ),
OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Industry, this_month_transported[0] ),
OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Industry, this_month_transported[1] ),
OCL_SVAR( OC_UINT8, Industry, last_month_pct_transported[0] ),
OCL_SVAR( OC_UINT8, Industry, last_month_pct_transported[1] ),
OCL_SVAR( OC_UINT16, Industry, last_month_production[0] ),
OCL_SVAR( OC_UINT16, Industry, last_month_production[1] ),
OCL_SVAR( OC_UINT16, Industry, last_month_transported[0] ),
OCL_SVAR( OC_UINT16, Industry, last_month_transported[1] ),
OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Industry, last_month_production[0] ),
OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Industry, last_month_production[1] ),
OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Industry, last_month_transported[0] ),
OCL_SVAR( OC_FILE_U16 | OC_VAR_U32, Industry, last_month_transported[1] ),
OCL_SVAR( OC_UINT8, Industry, type ),
OCL_SVAR( OC_TTO | OC_FILE_U8 | OC_VAR_U16, Industry, counter ),

Loading…
Cancel
Save