diff --git a/src/town.h b/src/town.h index f7fe89babe..9b2fc87b68 100644 --- a/src/town.h +++ b/src/town.h @@ -241,6 +241,7 @@ void SetTownRatingTestMode(bool mode); TownActions GetMaskOfTownActions(CompanyID cid, const Town *t); bool GenerateTowns(TownLayout layout); const CargoSpec *FindFirstCargoWithTownAcceptanceEffect(TownAcceptanceEffect effect); +CargoArray GetAcceptedCargoOfHouse(const HouseSpec *hs); extern const uint8_t _town_action_costs[TACT_COUNT]; diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 4800fcd702..bae0eaed1a 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -788,9 +788,17 @@ static void AddAcceptedCargoSetMask(CargoID cargo, uint amount, CargoArray &acce SetBit(always_accepted, cargo); } -static void AddAcceptedCargo_Town(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted) +/** + * Determine accepted cargo for a house. + * @param tile Tile of house, or INVALID_TILE if not yet built. + * @param house HouseID of house. + * @param hs HouseSpec of house. + * @param t Town that house belongs to, or nullptr if not yet built. + * @param[out] acceptance CargoArray to be filled with acceptance information. + * @param[out] always_accepted Bitmask of always accepted cargo types + */ +void AddAcceptedCargoOfHouse(TileIndex tile, HouseID house, const HouseSpec *hs, Town *t, CargoArray &acceptance, CargoTypes &always_accepted) { - const HouseSpec *hs = HouseSpec::Get(GetHouseType(tile)); CargoID accepts[lengthof(hs->accepts_cargo)]; /* Set the initial accepted cargo types */ @@ -800,7 +808,7 @@ static void AddAcceptedCargo_Town(TileIndex tile, CargoArray &acceptance, CargoT /* Check for custom accepted cargo types */ if (HasBit(hs->callback_mask, CBM_HOUSE_ACCEPT_CARGO)) { - uint16_t callback = GetHouseCallback(CBID_HOUSE_ACCEPT_CARGO, 0, 0, GetHouseType(tile), Town::GetByTile(tile), tile); + uint16_t callback = GetHouseCallback(CBID_HOUSE_ACCEPT_CARGO, 0, 0, house, t, tile, tile == INVALID_TILE); if (callback != CALLBACK_FAILED) { /* Replace accepted cargo types with translated values from callback */ accepts[0] = GetCargoTranslation(GB(callback, 0, 5), hs->grf_prop.grffile); @@ -811,7 +819,7 @@ static void AddAcceptedCargo_Town(TileIndex tile, CargoArray &acceptance, CargoT /* Check for custom cargo acceptance */ if (HasBit(hs->callback_mask, CBM_HOUSE_CARGO_ACCEPTANCE)) { - uint16_t callback = GetHouseCallback(CBID_HOUSE_CARGO_ACCEPTANCE, 0, 0, GetHouseType(tile), Town::GetByTile(tile), tile); + uint16_t callback = GetHouseCallback(CBID_HOUSE_CARGO_ACCEPTANCE, 0, 0, house, t, tile, tile == INVALID_TILE); if (callback != CALLBACK_FAILED) { AddAcceptedCargoSetMask(accepts[0], GB(callback, 0, 4), acceptance, always_accepted); AddAcceptedCargoSetMask(accepts[1], GB(callback, 4, 4), acceptance, always_accepted); @@ -831,6 +839,25 @@ static void AddAcceptedCargo_Town(TileIndex tile, CargoArray &acceptance, CargoT } } +static void AddAcceptedCargo_Town(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted) +{ + HouseID house = GetHouseType(tile); + AddAcceptedCargoOfHouse(tile, house, HouseSpec::Get(house), Town::GetByTile(tile), acceptance, always_accepted); +} + +/** + * Get accepted cargo of a house prototype. + * @param hs Spec of the house. + * @return CargoArray filled with cargo accepted by the house. + */ +CargoArray GetAcceptedCargoOfHouse(const HouseSpec *hs) +{ + CargoTypes always_accepted; + CargoArray acceptance{}; + AddAcceptedCargoOfHouse(INVALID_TILE, hs->Index(), hs, nullptr, acceptance, always_accepted); + return acceptance; +} + static void GetTileDesc_Town(TileIndex tile, TileDesc *td) { const HouseID house = GetHouseType(tile);