From 9dae626237569356b1fe25c439edae3c685c49e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Guilloux?= Date: Tue, 29 Oct 2024 19:56:15 +0100 Subject: [PATCH] Codefix: restore _generating_world and nearest town cache when failing to fund a random town (#13042) --- src/town_cmd.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index c938b85e2d..1a536ec4b5 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -2170,17 +2170,19 @@ std::tuple CmdFoundTown(DoCommandFlag flags, TileInd Town *t; if (random_location) { t = CreateRandomTown(20, townnameparts, size, city, layout); - if (t == nullptr) return { CommandCost(STR_ERROR_NO_SPACE_FOR_TOWN), 0, INVALID_TOWN }; } else { t = new Town(tile); DoCreateTown(t, tile, townnameparts, size, city, layout, true); } - new_town = t->index; UpdateNearestTownForRoadTiles(false); old_generating_world.Restore(); - if (t != nullptr && !text.empty()) { + if (t == nullptr) return { CommandCost(STR_ERROR_NO_SPACE_FOR_TOWN), 0, INVALID_TOWN }; + + new_town = t->index; + + if (!text.empty()) { t->name = text; t->UpdateVirtCoord(); }