diff options
author | dP <dp@dpointer.org> | 2020-05-12 02:21:14 +0300 |
---|---|---|
committer | Charles Pigott <charlespigott@googlemail.com> | 2020-05-13 08:43:01 +0100 |
commit | f2a9a1e2a5282d91760783bd04df3603badd2ba9 (patch) | |
tree | 202b462b0f617bf0b24995685547cb4671d00d88 | |
parent | 7bd52970a1e83cb88069e73e26479eb71bd17726 (diff) | |
download | openttd-f2a9a1e2a5282d91760783bd04df3603badd2ba9.tar.xz |
Fix #8137: New clients can't join (desync) after funding an industry
-rw-r--r-- | src/industry_cmd.cpp | 4 | ||||
-rw-r--r-- | src/station_base.h | 8 | ||||
-rw-r--r-- | src/station_cmd.cpp | 3 | ||||
-rw-r--r-- | src/town_cmd.cpp | 3 |
4 files changed, 12 insertions, 6 deletions
diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 39fc0d6f1..35def4609 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -1697,9 +1697,11 @@ static void PopulateStationsNearby(Industry *ind) return; } - ForAllStationsAroundTiles(ind->location, [ind](Station *st) { + ForAllStationsAroundTiles(ind->location, [ind](Station *st, TileIndex tile) { + if (!IsTileType(tile, MP_INDUSTRY) || GetIndustryIndex(tile) != ind->index) return false; ind->stations_near.insert(st); st->AddIndustryToDeliver(ind); + return true; }); } diff --git a/src/station_base.h b/src/station_base.h index 3be7d4437..75b1c1112 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -560,7 +560,10 @@ void RebuildStationKdtree(); /** * Call a function on all stations that have any part of the requested area within their catchment. - * @param area The tile area to check + * @tparam Func The type of funcion to call + * @param area The TileArea to check + * @param func The function to call, must take two parameters: Station* and TileIndex and return true + * if coverage of that tile is acceptable for a given station or false if search should continue */ template<typename Func> void ForAllStationsAroundTiles(const TileArea &ta, Func func) @@ -586,8 +589,7 @@ void ForAllStationsAroundTiles(const TileArea &ta, Func func) /* Test if the tile is within the station's catchment */ TILE_AREA_LOOP(tile, ta) { if (st->TileIsInCatchment(tile)) { - func(st); - break; + if (func(st, tile)) break; } } } diff --git a/src/station_cmd.cpp b/src/station_cmd.cpp index 7bf2c43df..6cfd94bb2 100644 --- a/src/station_cmd.cpp +++ b/src/station_cmd.cpp @@ -3978,8 +3978,9 @@ const StationList *StationFinder::GetStations() assert(this->w == 1 && this->h == 1); AddNearbyStationsByCatchment(this->tile, &this->stations, Town::GetByTile(this->tile)->stations_near); } else { - ForAllStationsAroundTiles(*this, [this](Station *st) { + ForAllStationsAroundTiles(*this, [this](Station *st, TileIndex tile) { this->stations.insert(st); + return true; }); } this->tile = INVALID_TILE; diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 44c396cba..507cccd56 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -2250,8 +2250,9 @@ static void MakeTownHouse(TileIndex t, Town *town, byte counter, byte stage, Hou if (size & BUILDING_HAS_4_TILES) ClearMakeHouseTile(t + TileDiffXY(1, 1), town, counter, stage, ++type, random_bits); if (!_generating_world) { - ForAllStationsAroundTiles(TileArea(t, (size & BUILDING_2_TILES_X) ? 2 : 1, (size & BUILDING_2_TILES_Y) ? 2 : 1), [town](Station *st) { + ForAllStationsAroundTiles(TileArea(t, (size & BUILDING_2_TILES_X) ? 2 : 1, (size & BUILDING_2_TILES_Y) ? 2 : 1), [town](Station *st, TileIndex tile) { town->stations_near.insert(st); + return true; }); } } |