From 7c9f2c71f4d863affedbcf13e625d4ab92a47b59 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Tue, 17 Feb 2026 19:14:54 +0000 Subject: [PATCH] Codechange: remove GetAcceptanceAroundTiles always_accepted out parameter (#15295) Return multiple values as std::pair instead of using pointers for out parameters. --- src/misc_gui.cpp | 3 ++- src/script/api/script_tile.cpp | 2 +- src/script/api/script_tilelist.cpp | 2 +- src/station_cmd.cpp | 18 +++++++++--------- src/station_func.h | 2 +- src/station_gui.cpp | 2 +- src/subsidy.cpp | 3 ++- src/tile_cmd.h | 16 +++++++++++++--- 8 files changed, 30 insertions(+), 18 deletions(-) diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index f4f4727a11..433c25f2b0 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -143,7 +143,8 @@ public: td.owner_type[0] = STR_LAND_AREA_INFORMATION_OWNER; // At least one owner is displayed, though it might be "N/A". CargoArray acceptance{}; - AddAcceptedCargo(tile, acceptance, nullptr); + CargoTypes always_accepted{}; + AddAcceptedCargo(tile, acceptance, always_accepted); GetTileDesc(tile, td); this->landinfo_data.clear(); diff --git a/src/script/api/script_tile.cpp b/src/script/api/script_tile.cpp index 8235831e55..ba301f95b6 100644 --- a/src/script/api/script_tile.cpp +++ b/src/script/api/script_tile.cpp @@ -235,7 +235,7 @@ { if (!::IsValidTile(tile) || width <= 0 || height <= 0 || radius < 0 || !ScriptCargo::IsValidCargo(cargo_type)) return -1; - CargoArray acceptance = ::GetAcceptanceAroundTiles(tile, width, height, _settings_game.station.modified_catchment ? radius : (int)CA_UNMODIFIED); + CargoArray acceptance = ::GetAcceptanceAroundTiles(tile, width, height, _settings_game.station.modified_catchment ? radius : (int)CA_UNMODIFIED).first; return acceptance[cargo_type]; } diff --git a/src/script/api/script_tilelist.cpp b/src/script/api/script_tilelist.cpp index 7dc0efeeaa..a8369d5742 100644 --- a/src/script/api/script_tilelist.cpp +++ b/src/script/api/script_tilelist.cpp @@ -147,7 +147,7 @@ ScriptTileList_IndustryAccepting::ScriptTileList_IndustryAccepting(IndustryID in for (TileIndex cur_tile = it; cur_tile != INVALID_TILE; cur_tile = ++it) { /* Only add the tile if it accepts the cargo (sometimes just 1 tile of an * industry triggers the acceptance). */ - CargoArray acceptance = ::GetAcceptanceAroundTiles(cur_tile, 1, 1, radius); + CargoArray acceptance = ::GetAcceptanceAroundTiles(cur_tile, 1, 1, radius).first; if (std::none_of(std::begin(i->accepted), std::end(i->accepted), [&acceptance](const auto &a) { return ::IsValidCargoType(a.cargo) && acceptance[a.cargo] != 0; })) continue; this->AddTile(cur_tile); diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 0f6cd61727..670a6c78a7 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -565,12 +565,12 @@ CargoArray GetProductionAroundTiles(TileIndex north_tile, int w, int h, int rad) * @param w X extent of area * @param h Y extent of area * @param rad Search radius in addition to given area - * @param always_accepted bitmask of cargo accepted by houses and headquarters; can be nullptr + * @return Cargo array of accepted cargo types and bitmask of cargo accepted by houses and headquarters. */ -CargoArray GetAcceptanceAroundTiles(TileIndex center_tile, int w, int h, int rad, CargoTypes *always_accepted) +std::pair GetAcceptanceAroundTiles(TileIndex center_tile, int w, int h, int rad) { CargoArray acceptance{}; - if (always_accepted != nullptr) *always_accepted = 0; + CargoTypes always_accepted{}; TileArea ta = TileArea(center_tile, w, h).Expand(rad); @@ -581,25 +581,25 @@ CargoArray GetAcceptanceAroundTiles(TileIndex center_tile, int w, int h, int rad AddAcceptedCargo(tile, acceptance, always_accepted); } - return acceptance; + return {acceptance, always_accepted}; } /** * Get the acceptance of cargoes around the station in. * @param st Station to get acceptance of. - * @param always_accepted bitmask of cargo accepted by houses and headquarters; can be nullptr + * @return Cargo array of accepted cargo types and bitmask of cargo accepted by houses and headquarters. */ -static CargoArray GetAcceptanceAroundStation(const Station *st, CargoTypes *always_accepted) +static std::pair GetAcceptanceAroundStation(const Station *st) { CargoArray acceptance{}; - if (always_accepted != nullptr) *always_accepted = 0; + CargoTypes always_accepted{}; BitmapTileIterator it(st->catchment_tiles); for (TileIndex tile = it; tile != INVALID_TILE; tile = ++it) { AddAcceptedCargo(tile, acceptance, always_accepted); } - return acceptance; + return {acceptance, always_accepted}; } /** @@ -615,7 +615,7 @@ void UpdateStationAcceptance(Station *st, bool show_msg) /* And retrieve the acceptance. */ CargoArray acceptance{}; if (!st->rect.IsEmpty()) { - acceptance = GetAcceptanceAroundStation(st, &st->always_accepted); + std::tie(acceptance, st->always_accepted) = GetAcceptanceAroundStation(st); } /* Adjust in case our station only accepts fewer kinds of goods */ diff --git a/src/station_func.h b/src/station_func.h index 0f9ec8da0f..aa52f00dca 100644 --- a/src/station_func.h +++ b/src/station_func.h @@ -27,7 +27,7 @@ void UpdateAllStationVirtCoords(); void ClearAllStationCachedNames(); CargoArray GetProductionAroundTiles(TileIndex tile, int w, int h, int rad); -CargoArray GetAcceptanceAroundTiles(TileIndex tile, int w, int h, int rad, CargoTypes *always_accepted = nullptr); +std::pair GetAcceptanceAroundTiles(TileIndex tile, int w, int h, int rad); void UpdateStationAcceptance(Station *st, bool show_msg); CargoTypes GetAcceptanceMask(const Station *st); diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 23e4d6a257..9ae9ebf6a9 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -83,7 +83,7 @@ int DrawStationCoverageAreaText(const Rect &r, StationCoverageType sct, int rad, if (supplies) { cargoes = GetProductionAroundTiles(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE, rad); } else { - cargoes = GetAcceptanceAroundTiles(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE, rad); + cargoes = GetAcceptanceAroundTiles(tile, _thd.size.x / TILE_SIZE, _thd.size.y / TILE_SIZE, rad).first; } /* Convert cargo counts to a set of cargo bits, and draw the result. */ diff --git a/src/subsidy.cpp b/src/subsidy.cpp index 0f903cd816..03d99e7cfc 100644 --- a/src/subsidy.cpp +++ b/src/subsidy.cpp @@ -378,10 +378,11 @@ bool FindSubsidyCargoDestination(CargoType cargo_type, Source src) /* Calculate cargo acceptance of houses around town center. */ CargoArray town_cargo_accepted{}; + CargoTypes always_accepted{}; TileArea ta = TileArea(dst_town->xy, 1, 1).Expand(SUBSIDY_TOWN_CARGO_RADIUS); for (TileIndex tile : ta) { if (IsTileType(tile, TileType::House)) { - AddAcceptedCargo(tile, town_cargo_accepted, nullptr); + AddAcceptedCargo(tile, town_cargo_accepted, always_accepted); } } diff --git a/src/tile_cmd.h b/src/tile_cmd.h index 1fb89d88cf..acc44fa048 100644 --- a/src/tile_cmd.h +++ b/src/tile_cmd.h @@ -176,14 +176,24 @@ VehicleEnterTileStates VehicleEnterTile(Vehicle *v, TileIndex tile, int x, int y void ChangeTileOwner(TileIndex tile, Owner old_owner, Owner new_owner); void GetTileDesc(TileIndex tile, TileDesc &td); -inline void AddAcceptedCargo(TileIndex tile, CargoArray &acceptance, CargoTypes *always_accepted) +/** + * Obtain cargo acceptance of a tile. + * @param tile Tile queried for its accepted cargo. + * @param acceptance Storage destination of the cargo acceptance in 1/8. + * @param always_accepted Bitmask of always accepted cargo types. + */ +inline void AddAcceptedCargo(TileIndex tile, CargoArray &acceptance, CargoTypes &always_accepted) { AddAcceptedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_accepted_cargo_proc; if (proc == nullptr) return; - CargoTypes dummy = 0; // use dummy bitmask so there don't need to be several 'always_accepted != nullptr' checks - proc(tile, acceptance, always_accepted == nullptr ? dummy : *always_accepted); + proc(tile, acceptance, always_accepted); } +/** + * Obtain the produced cargo of a tile. + * @param tile Tile being queried. + * @param produced Destination array for produced cargo. + */ inline void AddProducedCargo(TileIndex tile, CargoArray &produced) { AddProducedCargoProc *proc = _tile_type_procs[GetTileType(tile)]->add_produced_cargo_proc;