Fix #11801, 51f1e93: CalcClosestTownFromTile needs the kd-tree to be valid

This commit is contained in:
Rubidium 2024-01-17 22:45:33 +01:00 committed by rubidium42
parent 0be26f5856
commit 4cc97e04e6
1 changed files with 6 additions and 1 deletions

View File

@ -499,7 +499,12 @@ static Town *RemapTown(TileIndex fallback)
{
/* In some cases depots, industries and stations could refer to a missing town. */
Town *t = Town::GetIfValid(RemapTownIndex(_old_town_index));
if (t == nullptr) t = CalcClosestTownFromTile(fallback);
if (t == nullptr) {
/* In case the town that was refered to does not exist, find the closest.
* However, this needs the kd-tree to be present. */
RebuildTownKdtree();
t = CalcClosestTownFromTile(fallback);
}
return t;
}