diff --git a/src/industry.h b/src/industry.h index 147b928d91..520a6befb4 100644 --- a/src/industry.h +++ b/src/industry.h @@ -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 accepts_cargo{}; - std::array produced_cargo{}; ///< 16 production cargo slots - std::array produced_cargo_waiting{}; ///< amount of cargo produced per cargo - std::array incoming_cargo_waiting{}; ///< incoming cargo waiting to be processed - std::array production_rate{}; ///< production rate for each cargo - std::array this_month_production{}; ///< stats of this month's production per cargo - std::array this_month_transported{}; ///< stats of this month's transport per cargo - std::array last_month_pct_transported{}; ///< percentage transported per cargo in the last full month - std::array last_month_production{}; ///< total units produced per cargo in the last full month - std::array last_month_transported{}; ///< total units transported per cargo in the last full month + std::array accepts_cargo{}; + std::array produced_cargo{}; ///< 16 production cargo slots + std::array produced_cargo_waiting{}; ///< amount of cargo produced per cargo + std::array incoming_cargo_waiting{}; ///< incoming cargo waiting to be processed + std::array production_rate{}; ///< production rate for each cargo + std::array this_month_production{}; ///< stats of this month's production per cargo + std::array this_month_transported{}; ///< stats of this month's transport per cargo + std::array last_month_pct_transported{}; ///< percentage transported per cargo in the last full month + std::array last_month_production{}; ///< total units produced per cargo in the last full month + std::array 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 diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 2b7e787086..01b2a6453e 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -533,10 +533,10 @@ static bool TransportIndustryGoods(TileIndex tile) /* fluctuating economy? */ if (EconomyIsInRecession()) cw = (cw + 1) / 2; - i->this_month_production[j] = std::min(i->this_month_production[j] + cw, 0xFFFF); + i->this_month_production[j] = SaturatingAdd(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(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(i->this_month_transported[j] * 256 / i->this_month_production[j]); + pct = ClampTo(((uint64_t)i->this_month_transported[j]) * 256 / i->this_month_production[j]); } i->last_month_pct_transported[j] = pct; diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 1662bded08..f6a1c12a71 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -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; }; diff --git a/src/newgrf_industries.cpp b/src/newgrf_industries.cpp index e1b7805826..4b9c78eac9 100644 --- a/src/newgrf_industries.cpp +++ b/src/newgrf_industries.cpp @@ -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(this->industry->this_month_production[index]); + case 0x6B: return ClampTo(this->industry->this_month_transported[index]); + case 0x6C: return ClampTo(this->industry->last_month_production[index]); + case 0x6D: return ClampTo(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(this->industry->this_month_production[0]); + case 0x95: return GB(ClampTo(this->industry->this_month_production[0]), 8, 8); + case 0x96: return ClampTo(this->industry->this_month_production[1]); + case 0x97: return GB(ClampTo(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(this->industry->this_month_transported[0]); + case 0x99: return GB(ClampTo(this->industry->this_month_transported[0]), 8, 8); + case 0x9A: return ClampTo(this->industry->this_month_transported[1]); + case 0x9B: return GB(ClampTo(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]; diff --git a/src/saveload/industry_sl.cpp b/src/saveload/industry_sl.cpp index bf4fc3552c..321035ff86 100644 --- a/src/saveload/industry_sl.cpp +++ b/src/saveload/industry_sl.cpp @@ -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), diff --git a/src/sl/extended_ver_sl.cpp b/src/sl/extended_ver_sl.cpp index bdd6180115..76800e85ca 100644 --- a/src/sl/extended_ver_sl.cpp +++ b/src/sl/extended_ver_sl.cpp @@ -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 }, diff --git a/src/sl/extended_ver_sl.h b/src/sl/extended_ver_sl.h index ad5a681ff8..0f478c45bb 100644 --- a/src/sl/extended_ver_sl.h +++ b/src/sl/extended_ver_sl.h @@ -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 diff --git a/src/sl/industry_sl.cpp b/src/sl/industry_sl.cpp index 3fd2571c96..ada384acee 100644 --- a/src/sl/industry_sl.cpp +++ b/src/sl/industry_sl.cpp @@ -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), diff --git a/src/sl/oldloader_sl.cpp b/src/sl/oldloader_sl.cpp index 9e0bbf28c5..406859e5eb 100644 --- a/src/sl/oldloader_sl.cpp +++ b/src/sl/oldloader_sl.cpp @@ -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 ),