diff options
Diffstat (limited to 'src/station_cmd.cpp')
-rw-r--r-- | src/station_cmd.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 8b7bf5345..b66ccafb5 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -485,10 +485,25 @@ CargoArray GetProductionAroundTiles(TileIndex tile, int w, int h, int rad) assert(w > 0); assert(h > 0); - for (int yc = y1; yc != y2; yc++) { - for (int xc = x1; xc != x2; xc++) { - TileIndex tile = TileXY(xc, yc); - AddProducedCargo(tile, produced); + TileArea ta(TileXY(x1, y1), TileXY(x2 - 1, y2 - 1)); + + /* Loop over all tiles to get the produced cargo of + * everything except industries */ + TILE_AREA_LOOP(tile, ta) AddProducedCargo(tile, produced); + + /* Loop over the industries. They produce cargo for + * anything that is within 'rad' from their bounding + * box. As such if you have e.g. a oil well the tile + * area loop might not hit an industry tile while + * the industry would produce cargo for the station. + */ + const Industry *i; + FOR_ALL_INDUSTRIES(i) { + if (!ta.Intersects(i->location)) continue; + + for (uint j = 0; j < lengthof(i->produced_cargo); j++) { + CargoID cargo = i->produced_cargo[j]; + if (cargo != CT_INVALID) produced[cargo]++; } } |