From 98c8445519193f1004d5eae56af4de5317bd57f0 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Fri, 15 Nov 2024 08:07:02 +0000 Subject: [PATCH] Codechange: Limit house default cargo label lists to original slot counts. (#13079) Same as for IndustrySpec and IndustryTileSpec. --- src/house.h | 3 ++- src/newgrf.cpp | 4 ++-- src/table/town_land.h | 3 +-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/house.h b/src/house.h index 04cddb5c2d..4f19c6d40b 100644 --- a/src/house.h +++ b/src/house.h @@ -101,7 +101,6 @@ struct HouseSpec { uint8_t mail_generation; ///< mail generation multiplier (tile based, as the acceptances below) uint8_t cargo_acceptance[HOUSE_NUM_ACCEPTS]; ///< acceptance level for the cargo slots CargoID accepts_cargo[HOUSE_NUM_ACCEPTS]; ///< input cargo slots - CargoLabel accepts_cargo_label[HOUSE_NUM_ACCEPTS]; ///< input landscape cargo slots BuildingFlags building_flags; ///< some flags that describe the house (size, stadium etc...) HouseZones building_availability; ///< where can it be built (climates, zones) bool enabled; ///< the house is available to build (true by default, but can be disabled by newgrf) @@ -118,6 +117,8 @@ struct HouseSpec { uint8_t minimum_life; ///< The minimum number of years this house will survive before the town rebuilds it CargoTypes watched_cargoes; ///< Cargo types watched for acceptance. + CargoLabel accepts_cargo_label[HOUSE_ORIGINAL_NUM_ACCEPTS]; ///< input landscape cargo slots + HouseID Index() const; Money GetRemovalCost() const; diff --git a/src/newgrf.cpp b/src/newgrf.cpp index f9ee7b788c..72176bcb87 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -2639,7 +2639,7 @@ static ChangeInfoResult TownHouseChangeInfo(uint hid, int numinfo, int prop, Byt housespec->accepts_cargo[i] = INVALID_CARGO; housespec->cargo_acceptance[i] = 0; } - housespec->accepts_cargo_label[i] = CT_INVALID; + if (i < std::size(housespec->accepts_cargo_label)) housespec->accepts_cargo_label[i] = CT_INVALID; } break; } @@ -9376,7 +9376,7 @@ static void FinaliseHouseArray() } /* Apply default cargo translation map for unset cargo slots */ - for (uint i = 0; i < lengthof(hs->accepts_cargo); ++i) { + for (uint i = 0; i < lengthof(hs->accepts_cargo_label); ++i) { if (!IsValidCargoID(hs->accepts_cargo[i])) hs->accepts_cargo[i] = GetCargoIDByLabel(hs->accepts_cargo_label[i]); /* Disable acceptance if cargo type is invalid. */ if (!IsValidCargoID(hs->accepts_cargo[i])) hs->cargo_acceptance[i] = 0; diff --git a/src/table/town_land.h b/src/table/town_land.h index 586a94b3a8..8fc6ea1ac6 100644 --- a/src/table/town_land.h +++ b/src/table/town_land.h @@ -1813,9 +1813,8 @@ static_assert(lengthof(_town_draw_tile_data) == (NEW_HOUSE_OFFSET) * 4 * 4); {mnd, mxd, p, rc, bn, rr, mg, \ {ca1, ca2, ca3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, \ {INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO, INVALID_CARGO}, \ - {cg1, cg2, cg3, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID, CT_INVALID}, \ bf, ba, true, GRFFileProps(INVALID_HOUSE_ID), 0, {COLOUR_BEGIN, COLOUR_BEGIN, COLOUR_BEGIN, COLOUR_BEGIN}, \ - 16, NO_EXTRA_FLAG, HOUSE_NO_CLASS, {0, 2, 0, 0}, 0, 0, 0} + 16, NO_EXTRA_FLAG, HOUSE_NO_CLASS, {0, 2, 0, 0}, 0, 0, 0, {cg1, cg2, cg3}, } /** House specifications from original data */ extern const HouseSpec _original_house_specs[] = { /** -- 2.11.4.GIT