mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-09 07:29:44 +00:00
Codechange: Adapt functions to get accepted cargo of prototype house.
This commit is contained in:
parent
3a158c7609
commit
2ede94bc40
@ -241,6 +241,7 @@ void SetTownRatingTestMode(bool mode);
|
|||||||
TownActions GetMaskOfTownActions(CompanyID cid, const Town *t);
|
TownActions GetMaskOfTownActions(CompanyID cid, const Town *t);
|
||||||
bool GenerateTowns(TownLayout layout);
|
bool GenerateTowns(TownLayout layout);
|
||||||
const CargoSpec *FindFirstCargoWithTownAcceptanceEffect(TownAcceptanceEffect effect);
|
const CargoSpec *FindFirstCargoWithTownAcceptanceEffect(TownAcceptanceEffect effect);
|
||||||
|
CargoArray GetAcceptedCargoOfHouse(const HouseSpec *hs);
|
||||||
|
|
||||||
extern const uint8_t _town_action_costs[TACT_COUNT];
|
extern const uint8_t _town_action_costs[TACT_COUNT];
|
||||||
|
|
||||||
|
@ -788,9 +788,17 @@ static void AddAcceptedCargoSetMask(CargoID cargo, uint amount, CargoArray &acce
|
|||||||
SetBit(always_accepted, cargo);
|
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)];
|
CargoID accepts[lengthof(hs->accepts_cargo)];
|
||||||
|
|
||||||
/* Set the initial accepted cargo types */
|
/* 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 */
|
/* Check for custom accepted cargo types */
|
||||||
if (HasBit(hs->callback_mask, CBM_HOUSE_ACCEPT_CARGO)) {
|
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) {
|
if (callback != CALLBACK_FAILED) {
|
||||||
/* Replace accepted cargo types with translated values from callback */
|
/* Replace accepted cargo types with translated values from callback */
|
||||||
accepts[0] = GetCargoTranslation(GB(callback, 0, 5), hs->grf_prop.grffile);
|
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 */
|
/* Check for custom cargo acceptance */
|
||||||
if (HasBit(hs->callback_mask, CBM_HOUSE_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) {
|
if (callback != CALLBACK_FAILED) {
|
||||||
AddAcceptedCargoSetMask(accepts[0], GB(callback, 0, 4), acceptance, always_accepted);
|
AddAcceptedCargoSetMask(accepts[0], GB(callback, 0, 4), acceptance, always_accepted);
|
||||||
AddAcceptedCargoSetMask(accepts[1], GB(callback, 4, 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)
|
static void GetTileDesc_Town(TileIndex tile, TileDesc *td)
|
||||||
{
|
{
|
||||||
const HouseID house = GetHouseType(tile);
|
const HouseID house = GetHouseType(tile);
|
||||||
|
Loading…
Reference in New Issue
Block a user