Changeset - r23554:d690e3d46135
[Not reviewed]
master
0 2 0
PeterN - 6 years ago 2019-03-27 23:10:02
peter@fuzzle.org
Fix: Incorrect display of industry production around tiles. (#7426)

Display of industry production around tiles (as shown when placing a station)
did not take account of the station catchment changes, so still showed production
from an industry even if it was not covered by a tile.

This is fixed by making a set of nearby industries that are covered, instead of
looping over all possible industries.
2 files changed with 12 insertions and 12 deletions:
0 comments (0 inline, 0 general)
bin/ai/regression/tst_regression/result.txt
Show inline comments
 
@@ -8515,58 +8515,56 @@ ERROR: IsEnd() is invalid as Begin() is 
 
    21487 => 8
 
    21486 => 8
 
    21485 => 8
 
    21484 => 8
 
    21235 => 8
 
    21228 => 8
 
    20979 => 8
 
    20972 => 8
 
    20723 => 8
 
    20716 => 8
 
    20467 => 8
 
    20460 => 8
 
    20211 => 8
 
    20204 => 8
 
    19955 => 8
 
    19948 => 8
 
    19699 => 8
 
    19698 => 8
 
    19694 => 8
 
    19693 => 8
 

	
 
--TileList_IndustryProducing--
 
  Count():             92
 
  Location ListDump:
 
    46920 => 1
 
    46919 => 1
 
    46918 => 1
 
    46917 => 1
 
    46916 => 1
 
    46915 => 1
 
    46914 => 1
 
    46913 => 1
 
    46912 => 1
 
    46911 => 1
 
    46664 => 1
 
    46663 => 1
 
    46662 => 1
 
    46661 => 1
 
    46660 => 1
 
    46659 => 1
 
    46658 => 1
 
    46657 => 1
 
    46656 => 1
 
    46655 => 1
 
    46408 => 1
 
    46407 => 1
 
    46406 => 1
 
    46405 => 1
 
    46404 => 1
 
    46403 => 1
 
    46402 => 1
 
    46401 => 1
 
    46400 => 1
 
    46399 => 1
 
    46152 => 1
 
    46151 => 1
 
    46150 => 1
 
    46149 => 1
 
@@ -8607,48 +8605,50 @@ ERROR: IsEnd() is invalid as Begin() is 
 
    44866 => 1
 
    44865 => 1
 
    44864 => 1
 
    44863 => 1
 
    44616 => 1
 
    44615 => 1
 
    44614 => 1
 
    44613 => 1
 
    44612 => 1
 
    44611 => 1
 
    44610 => 1
 
    44609 => 1
 
    44608 => 1
 
    44607 => 1
 
    44360 => 1
 
    44359 => 1
 
    44358 => 1
 
    44357 => 1
 
    44356 => 1
 
    44355 => 1
 
    44354 => 1
 
    44353 => 1
 
    44352 => 1
 
    44351 => 1
 
    46920 => 0
 
    46911 => 0
 

	
 
--TileList_StationType--
 
  Count():             4
 
  Location ListDump:
 
    33667 => 0
 
    33415 => 0
 
    33413 => 0
 
    33411 => 0
 

	
 
--Town--
 
  GetTownCount():    28
 
  Town 0
 
    IsValidTown():   true
 
    GetName():       Planfield
 
    GetPopulation(): 787
 
    GetLocation():   15508
 
    GetHouseCount(): 30
 
    GetRating():     0
 
    IsCity():        true
 
  Town 1
 
    IsValidTown():   true
 
    GetName():       Trenningville
 
    GetPopulation(): 243
 
    GetLocation():   46751
src/station_cmd.cpp
Show inline comments
 
@@ -491,63 +491,63 @@ static void ShowRejectOrAcceptNews(const
 
 * @param w X extent of the area
 
 * @param h Y extent of the area
 
 * @param rad Search radius in addition to the given area
 
 */
 
CargoArray GetProductionAroundTiles(TileIndex tile, int w, int h, int rad)
 
{
 
	CargoArray produced;
 

	
 
	int x = TileX(tile);
 
	int y = TileY(tile);
 

	
 
	/* expand the region by rad tiles on each side
 
	 * while making sure that we remain inside the board. */
 
	int x2 = min(x + w + rad, MapSizeX());
 
	int x1 = max(x - rad, 0);
 

	
 
	int y2 = min(y + h + rad, MapSizeY());
 
	int y1 = max(y - rad, 0);
 

	
 
	assert(x1 < x2);
 
	assert(y1 < y2);
 
	assert(w > 0);
 
	assert(h > 0);
 

	
 
	std::set<IndustryID> industries;
 
	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.
 
	TILE_AREA_LOOP(tile, ta) {
 
		if (IsTileType(tile, MP_INDUSTRY)) industries.insert(GetIndustryIndex(tile));
 
		AddProducedCargo(tile, produced);
 
	}
 

	
 
	/* Loop over the seen industries. They produce cargo for
 
	 * anything that is within 'rad' of any one of their tiles.
 
	 */
 
	const Industry *i;
 
	FOR_ALL_INDUSTRIES(i) {
 
		if (!ta.Intersects(i->location)) continue;
 
	for (IndustryID industry : industries) {
 
		const Industry *i = Industry::Get(industry);
 
		/* Skip industry with neutral station */
 
		if (i->neutral_station != NULL && !_settings_game.station.serve_neutral_industries) continue;
 

	
 
		for (uint j = 0; j < lengthof(i->produced_cargo); j++) {
 
			CargoID cargo = i->produced_cargo[j];
 
			if (cargo != CT_INVALID) produced[cargo]++;
 
		}
 
	}
 

	
 
	return produced;
 
}
 

	
 
/**
 
 * Get the acceptance of cargoes around the tile in 1/8.
 
 * @param tile Center of the search area
 
 * @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 NULL
 
 * @param ind Industry associated with neutral station (e.g. oil rig) or NULL
 
 */
 
CargoArray GetAcceptanceAroundTiles(TileIndex tile, int w, int h, int rad, CargoTypes *always_accepted)
 
{
 
	CargoArray acceptance;
0 comments (0 inline, 0 general)