Codechange: remove GetAcceptanceAroundTiles always_accepted out parameter (#15295)

Return multiple values as std::pair instead of using pointers for out parameters.
This commit is contained in:
Peter Nelson
2026-02-17 19:14:54 +00:00
committed by GitHub
parent e33d53e37e
commit 7c9f2c71f4
8 changed files with 30 additions and 18 deletions
+9 -9
View File
@@ -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<CargoArray, CargoTypes> 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<CargoArray, CargoTypes> 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 */