diff --git a/src/house.h b/src/house.h index 65ce03786b..f80aeb3746 100644 --- a/src/house.h +++ b/src/house.h @@ -30,6 +30,7 @@ static const HouseID NUM_HOUSES = 512; ///< Total number of houses. static const HouseID INVALID_HOUSE_ID = 0xFFFF; static const uint HOUSE_NUM_ACCEPTS = 16; ///< Max number of cargoes accepted by a tile +static const uint HOUSE_ORIGINAL_NUM_ACCEPTS = 3; ///< Original number of accepted cargo types. enum BuildingFlags { TILE_NO_FLAG = 0, diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index c2d38d829c..3f97162dad 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -438,7 +438,7 @@ static void AddAcceptedCargo_Industry(TileIndex tile, CargoArray &acceptance, Ca uint16_t res = GetIndustryTileCallback(CBID_INDTILE_ACCEPT_CARGO, 0, 0, gfx, Industry::GetByTile(tile), tile); if (res != CALLBACK_FAILED) { accepts_cargo.fill(INVALID_CARGO); - for (uint i = 0; i < 3; i++) accepts_cargo[i] = GetCargoTranslation(GB(res, i * 5, 5), itspec->grf_prop.grffile); + for (uint i = 0; i < INDUSTRY_ORIGINAL_NUM_INPUTS; i++) accepts_cargo[i] = GetCargoTranslation(GB(res, i * 5, 5), itspec->grf_prop.grffile); } } @@ -447,7 +447,7 @@ static void AddAcceptedCargo_Industry(TileIndex tile, CargoArray &acceptance, Ca uint16_t res = GetIndustryTileCallback(CBID_INDTILE_CARGO_ACCEPTANCE, 0, 0, gfx, Industry::GetByTile(tile), tile); if (res != CALLBACK_FAILED) { cargo_acceptance.fill(0); - for (uint i = 0; i < 3; i++) cargo_acceptance[i] = GB(res, i * 4, 4); + for (uint i = 0; i < INDUSTRY_ORIGINAL_NUM_INPUTS; i++) cargo_acceptance[i] = GB(res, i * 4, 4); } } diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index 4f2762f253..ade687df5f 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -177,10 +177,12 @@ static inline void GetAllCargoSuffixes(CargoSuffixInOut use_input, CargoSuffixTy } switch (use_input) { case CARGOSUFFIX_OUT: + // Handle INDUSTRY_ORIGINAL_NUM_OUTPUTS cargoes if (IsValidCargoID(cargoes[0])) GetCargoSuffix(3, cst, ind, ind_type, indspec, suffixes[0]); if (IsValidCargoID(cargoes[1])) GetCargoSuffix(4, cst, ind, ind_type, indspec, suffixes[1]); break; case CARGOSUFFIX_IN: + // Handle INDUSTRY_ORIGINAL_NUM_INPUTS cargoes if (IsValidCargoID(cargoes[0])) GetCargoSuffix(0, cst, ind, ind_type, indspec, suffixes[0]); if (IsValidCargoID(cargoes[1])) GetCargoSuffix(1, cst, ind, ind_type, indspec, suffixes[1]); if (IsValidCargoID(cargoes[2])) GetCargoSuffix(2, cst, ind, ind_type, indspec, suffixes[2]); @@ -212,9 +214,9 @@ void GetCargoSuffix(CargoSuffixInOut use_input, CargoSuffixType cst, const Indus uint cargotype = local_id << 16 | use_input; GetCargoSuffix(cargotype, cst, ind, ind_type, indspec, suffix); } else if (use_input == CARGOSUFFIX_IN) { - if (slot < 3) GetCargoSuffix(slot, cst, ind, ind_type, indspec, suffix); + if (slot < INDUSTRY_ORIGINAL_NUM_INPUTS) GetCargoSuffix(slot, cst, ind, ind_type, indspec, suffix); } else if (use_input == CARGOSUFFIX_OUT) { - if (slot < 2) GetCargoSuffix(slot + 3, cst, ind, ind_type, indspec, suffix); + if (slot < INDUSTRY_ORIGINAL_NUM_OUTPUTS) GetCargoSuffix(slot + INDUSTRY_ORIGINAL_NUM_INPUTS, cst, ind, ind_type, indspec, suffix); } } diff --git a/src/industry_type.h b/src/industry_type.h index 185e1f3a79..1ae903ad20 100644 --- a/src/industry_type.h +++ b/src/industry_type.h @@ -37,6 +37,8 @@ static const int INDUSTRY_COMPLETED = 3; ///< final stage of industry constructi static const int INDUSTRY_NUM_INPUTS = 16; ///< Number of cargo types an industry can accept static const int INDUSTRY_NUM_OUTPUTS = 16; ///< Number of cargo types an industry can produce +static const int INDUSTRY_ORIGINAL_NUM_INPUTS = 3; ///< Original number of accepted cargo types. +static const int INDUSTRY_ORIGINAL_NUM_OUTPUTS = 2; ///< Original number of produced cargo types. void CheckIndustries(); diff --git a/src/newgrf.cpp b/src/newgrf.cpp index de39a4e601..45208a3c9c 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -2559,7 +2559,7 @@ static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, Byt /* Check if the cargo types should not be changed */ if (cargotypes == 0xFFFFFFFF) break; - for (uint j = 0; j < 3; j++) { + for (uint j = 0; j < HOUSE_ORIGINAL_NUM_ACCEPTS; j++) { /* Get the cargo number from the 'list' */ uint8_t cargo_part = GB(cargotypes, 8 * j, 8); CargoID cargo = GetCargoTranslation(cargo_part, _cur.grffile); @@ -3392,14 +3392,14 @@ static ChangeInfoResult IgnoreIndustryProperty(int prop, ByteReader *buf) case 0x0C: case 0x0D: case 0x0E: - case 0x10: + case 0x10: // INDUSTRY_ORIGINAL_NUM_OUTPUTS bytes case 0x1B: case 0x1F: case 0x24: buf->ReadWord(); break; - case 0x11: + case 0x11: // INDUSTRY_ORIGINAL_NUM_INPUTS bytes + 1 case 0x1A: case 0x1C: case 0x1D: @@ -3431,7 +3431,7 @@ static ChangeInfoResult IgnoreIndustryProperty(int prop, ByteReader *buf) } case 0x16: - for (uint8_t j = 0; j < 3; j++) buf->ReadByte(); + for (uint8_t j = 0; j < INDUSTRY_ORIGINAL_NUM_INPUTS; j++) buf->ReadByte(); break; case 0x15: @@ -3679,14 +3679,14 @@ static ChangeInfoResult IndustriesChangeInfo(uint indid, int numinfo, int prop, break; case 0x10: // Production cargo types - for (uint8_t j = 0; j < 2; j++) { + for (uint8_t j = 0; j < INDUSTRY_ORIGINAL_NUM_OUTPUTS; j++) { indsp->produced_cargo[j] = GetCargoTranslation(buf->ReadByte(), _cur.grffile); indsp->produced_cargo_label[j] = CT_INVALID; } break; case 0x11: // Acceptance cargo types - for (uint8_t j = 0; j < 3; j++) { + for (uint8_t j = 0; j < INDUSTRY_ORIGINAL_NUM_INPUTS; j++) { indsp->accepts_cargo[j] = GetCargoTranslation(buf->ReadByte(), _cur.grffile); indsp->accepts_cargo_label[j] = CT_INVALID; } @@ -5472,22 +5472,22 @@ static void NewSpriteGroup(ByteReader *buf) act_group = group; group->version = type; if (type == 0) { - group->num_input = 3; - for (uint i = 0; i < 3; i++) { + group->num_input = INDUSTRY_ORIGINAL_NUM_INPUTS; + for (uint i = 0; i < INDUSTRY_ORIGINAL_NUM_INPUTS; i++) { group->subtract_input[i] = (int16_t)buf->ReadWord(); // signed } - group->num_output = 2; - for (uint i = 0; i < 2; i++) { + group->num_output = INDUSTRY_ORIGINAL_NUM_OUTPUTS; + for (uint i = 0; i < INDUSTRY_ORIGINAL_NUM_OUTPUTS; i++) { group->add_output[i] = buf->ReadWord(); // unsigned } group->again = buf->ReadByte(); } else if (type == 1) { - group->num_input = 3; - for (uint i = 0; i < 3; i++) { + group->num_input = INDUSTRY_ORIGINAL_NUM_INPUTS; + for (uint i = 0; i < INDUSTRY_ORIGINAL_NUM_INPUTS; i++) { group->subtract_input[i] = buf->ReadByte(); } - group->num_output = 2; - for (uint i = 0; i < 2; i++) { + group->num_output = INDUSTRY_ORIGINAL_NUM_OUTPUTS; + for (uint i = 0; i < INDUSTRY_ORIGINAL_NUM_OUTPUTS; i++) { group->add_output[i] = buf->ReadByte(); } group->again = buf->ReadByte(); diff --git a/src/saveload/industry_sl.cpp b/src/saveload/industry_sl.cpp index ad3f0dc7eb..6edea24e05 100644 --- a/src/saveload/industry_sl.cpp +++ b/src/saveload/industry_sl.cpp @@ -153,25 +153,25 @@ static const SaveLoad _industry_desc[] = { SLE_VAR(Industry, location.h, SLE_FILE_U8 | SLE_VAR_U16), SLE_REF(Industry, town, REF_TOWN), SLE_CONDREF(Industry, neutral_station, REF_STATION, SLV_SERVE_NEUTRAL_INDUSTRIES, SL_MAX_VERSION), - SLEG_CONDARR("produced_cargo", SlIndustryProduced::old_cargo, SLE_UINT8, 2, SLV_78, SLV_EXTEND_INDUSTRY_CARGO_SLOTS), - SLEG_CONDARR("produced_cargo", SlIndustryProduced::old_cargo, SLE_UINT8, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE), - SLEG_CONDARR("incoming_cargo_waiting", SlIndustryAccepted::old_waiting, SLE_UINT16, 3, SLV_70, SLV_EXTEND_INDUSTRY_CARGO_SLOTS), - SLEG_CONDARR("incoming_cargo_waiting", SlIndustryAccepted::old_waiting, SLE_UINT16, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE), - SLEG_CONDARR("produced_cargo_waiting", SlIndustryProduced::old_waiting, SLE_UINT16, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS), - SLEG_CONDARR("produced_cargo_waiting", SlIndustryProduced::old_waiting, SLE_UINT16, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE), - SLEG_CONDARR("production_rate", SlIndustryProduced::old_rate, SLE_UINT8, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS), - SLEG_CONDARR("production_rate", SlIndustryProduced::old_rate, SLE_UINT8, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE), - SLEG_CONDARR("accepts_cargo", SlIndustryAccepted::old_cargo, SLE_UINT8, 3, SLV_78, SLV_EXTEND_INDUSTRY_CARGO_SLOTS), - SLEG_CONDARR("accepts_cargo", SlIndustryAccepted::old_cargo, SLE_UINT8, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE), + SLEG_CONDARR("produced_cargo", SlIndustryProduced::old_cargo, SLE_UINT8, INDUSTRY_ORIGINAL_NUM_OUTPUTS, SLV_78, SLV_EXTEND_INDUSTRY_CARGO_SLOTS), + SLEG_CONDARR("produced_cargo", SlIndustryProduced::old_cargo, SLE_UINT8, INDUSTRY_NUM_OUTPUTS, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE), + SLEG_CONDARR("incoming_cargo_waiting", SlIndustryAccepted::old_waiting, SLE_UINT16, INDUSTRY_ORIGINAL_NUM_INPUTS, SLV_70, SLV_EXTEND_INDUSTRY_CARGO_SLOTS), + SLEG_CONDARR("incoming_cargo_waiting", SlIndustryAccepted::old_waiting, SLE_UINT16, INDUSTRY_NUM_INPUTS, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE), + SLEG_CONDARR("produced_cargo_waiting", SlIndustryProduced::old_waiting, SLE_UINT16, INDUSTRY_ORIGINAL_NUM_OUTPUTS, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS), + SLEG_CONDARR("produced_cargo_waiting", SlIndustryProduced::old_waiting, SLE_UINT16, INDUSTRY_NUM_OUTPUTS, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE), + SLEG_CONDARR("production_rate", SlIndustryProduced::old_rate, SLE_UINT8, INDUSTRY_ORIGINAL_NUM_OUTPUTS, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS), + SLEG_CONDARR("production_rate", SlIndustryProduced::old_rate, SLE_UINT8, INDUSTRY_NUM_OUTPUTS, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE), + SLEG_CONDARR("accepts_cargo", SlIndustryAccepted::old_cargo, SLE_UINT8, INDUSTRY_ORIGINAL_NUM_INPUTS, SLV_78, SLV_EXTEND_INDUSTRY_CARGO_SLOTS), + SLEG_CONDARR("accepts_cargo", SlIndustryAccepted::old_cargo, SLE_UINT8, INDUSTRY_NUM_INPUTS, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE), SLE_VAR(Industry, prod_level, SLE_UINT8), - SLEG_CONDARR("this_month_production", SlIndustryProduced::old_this_month_production, SLE_UINT16, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS), - SLEG_CONDARR("this_month_production", SlIndustryProduced::old_this_month_production, SLE_UINT16, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE), - SLEG_CONDARR("this_month_transported", SlIndustryProduced::old_this_month_transported, SLE_UINT16, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS), - SLEG_CONDARR("this_month_transported", SlIndustryProduced::old_this_month_transported, SLE_UINT16, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE), - SLEG_CONDARR("last_month_production", SlIndustryProduced::old_last_month_production, SLE_UINT16, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS), - SLEG_CONDARR("last_month_production", SlIndustryProduced::old_last_month_production, SLE_UINT16, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE), - SLEG_CONDARR("last_month_transported", SlIndustryProduced::old_last_month_transported, SLE_UINT16, 2, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS), - SLEG_CONDARR("last_month_transported", SlIndustryProduced::old_last_month_transported, SLE_UINT16, 16, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE), + SLEG_CONDARR("this_month_production", SlIndustryProduced::old_this_month_production, SLE_UINT16, INDUSTRY_ORIGINAL_NUM_OUTPUTS, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS), + SLEG_CONDARR("this_month_production", SlIndustryProduced::old_this_month_production, SLE_UINT16, INDUSTRY_NUM_OUTPUTS, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE), + SLEG_CONDARR("this_month_transported", SlIndustryProduced::old_this_month_transported, SLE_UINT16, INDUSTRY_ORIGINAL_NUM_OUTPUTS, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS), + SLEG_CONDARR("this_month_transported", SlIndustryProduced::old_this_month_transported, SLE_UINT16, INDUSTRY_NUM_OUTPUTS, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE), + SLEG_CONDARR("last_month_production", SlIndustryProduced::old_last_month_production, SLE_UINT16, INDUSTRY_ORIGINAL_NUM_OUTPUTS, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS), + SLEG_CONDARR("last_month_production", SlIndustryProduced::old_last_month_production, SLE_UINT16, INDUSTRY_NUM_OUTPUTS, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE), + SLEG_CONDARR("last_month_transported", SlIndustryProduced::old_last_month_transported, SLE_UINT16, INDUSTRY_ORIGINAL_NUM_OUTPUTS, SL_MIN_VERSION, SLV_EXTEND_INDUSTRY_CARGO_SLOTS), + SLEG_CONDARR("last_month_transported", SlIndustryProduced::old_last_month_transported, SLE_UINT16, INDUSTRY_NUM_OUTPUTS, SLV_EXTEND_INDUSTRY_CARGO_SLOTS, SLV_INDUSTRY_CARGO_REORGANISE), SLE_VAR(Industry, counter, SLE_UINT16), @@ -261,7 +261,7 @@ struct INDYChunkHandler : ChunkHandler { std::copy(std::begin(_old_ind_persistent_storage.storage), std::end(_old_ind_persistent_storage.storage), std::begin(i->psa->storage)); } if (IsSavegameVersionBefore(SLV_EXTEND_INDUSTRY_CARGO_SLOTS)) { - LoadMoveAcceptsProduced(i, 3, 2); + LoadMoveAcceptsProduced(i, INDUSTRY_ORIGINAL_NUM_INPUTS, INDUSTRY_ORIGINAL_NUM_OUTPUTS); } else if (IsSavegameVersionBefore(SLV_INDUSTRY_CARGO_REORGANISE)) { LoadMoveAcceptsProduced(i, INDUSTRY_NUM_INPUTS, INDUSTRY_NUM_OUTPUTS); } diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp index e5127b9ad3..7beb30a490 100644 --- a/src/saveload/oldloader_sl.cpp +++ b/src/saveload/oldloader_sl.cpp @@ -805,8 +805,8 @@ static bool LoadOldStation(LoadgameState *ls, int num) } /* Old save games always have 3 input and 2 output slots per industry. */ -static std::array _old_accepted{}; -static std::array _old_produced{}; +static std::array _old_accepted{}; +static std::array _old_produced{}; static const OldChunks industry_chunk[] = { OCL_SVAR( OC_TILE, Industry, location.tile ),