MCPcopy Create free account
hub / github.com/OpenTTD/OpenTTD / GetProductionAroundTiles

Function GetProductionAroundTiles

src/station_cmd.cpp:533–560  ·  view source on GitHub ↗

* Get the cargo types being produced around the tile (in a rectangle). * @param north_tile Northern most tile of area * @param w X extent of the area * @param h Y extent of the area * @param rad Search radius in addition to the given area */

Source from the content-addressed store, hash-verified

531 * @param rad Search radius in addition to the given area
532 */
533CargoArray GetProductionAroundTiles(TileIndex north_tile, int w, int h, int rad)
534{
535 CargoArray produced{};
536 FlatSet<IndustryID> industries;
537 TileArea ta = TileArea(north_tile, w, h).Expand(rad);
538
539 /* Loop over all tiles to get the produced cargo of
540 * everything except industries */
541 for (TileIndex tile : ta) {
542 if (IsTileType(tile, MP_INDUSTRY)) industries.insert(GetIndustryIndex(tile));
543 AddProducedCargo(tile, produced);
544 }
545
546 /* Loop over the seen industries. They produce cargo for
547 * anything that is within 'rad' of any one of their tiles.
548 */
549 for (IndustryID industry : industries) {
550 const Industry *i = Industry::Get(industry);
551 /* Skip industry with neutral station */
552 if (i->neutral_station != nullptr && !_settings_game.station.serve_neutral_industries) continue;
553
554 for (const auto &p : i->produced) {
555 if (IsValidCargoType(p.cargo)) produced[p.cargo]++;
556 }
557 }
558
559 return produced;
560}
561
562/**
563 * Get the acceptance of cargoes around the tile in 1/8.

Callers 2

GetCargoProductionMethod · 0.85

Calls 6

IsTileTypeFunction · 0.85
GetIndustryIndexFunction · 0.85
AddProducedCargoFunction · 0.85
IsValidCargoTypeFunction · 0.85
ExpandMethod · 0.80
insertMethod · 0.45

Tested by

no test coverage detected