Fix #9407: desync when founding a town nearby a station (#9526)

"stations_near" wasn't updated when founding a town near
a station. As this variable is not saved, any client joining
after the town is founded has a different value for
"stations_near", potentially causing desyncs.

As the intention of this if() statement was to skip an expensive
calculation when there are clearly no stations, better to move
that check inside the function, so other places also enjoy
the speedup.
This commit is contained in:
Patric Stout 2021-08-31 14:31:37 +02:00 committed by GitHub
parent 69e9acd702
commit 2c05412d72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View File

@ -565,6 +565,9 @@ void RebuildStationKdtree();
template<typename Func> template<typename Func>
void ForAllStationsAroundTiles(const TileArea &ta, Func func) void ForAllStationsAroundTiles(const TileArea &ta, Func func)
{ {
/* There are no stations, so we will never find anything. */
if (Station::GetNumItems() == 0) return;
/* Not using, or don't have a nearby stations list, so we need to scan. */ /* Not using, or don't have a nearby stations list, so we need to scan. */
std::set<StationID> seen_stations; std::set<StationID> seen_stations;

View File

@ -2310,12 +2310,10 @@ static void MakeTownHouse(TileIndex t, Town *town, byte counter, byte stage, Hou
if (size & BUILDING_2_TILES_X) ClearMakeHouseTile(t + TileDiffXY(1, 0), town, counter, stage, ++type, random_bits); if (size & BUILDING_2_TILES_X) ClearMakeHouseTile(t + TileDiffXY(1, 0), town, counter, stage, ++type, random_bits);
if (size & BUILDING_HAS_4_TILES) ClearMakeHouseTile(t + TileDiffXY(1, 1), town, counter, stage, ++type, random_bits); 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, TileIndex tile) {
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);
town->stations_near.insert(st); return true;
return true; });
});
}
} }