From 93d275f1be2963ff02f934d840966b1d3c01c516 Mon Sep 17 00:00:00 2001 From: smatz Date: Mon, 21 Sep 2009 20:22:56 +0000 Subject: (svn r17608) -Codechange: use CmdFoundTown when founding 'Random town' too --- src/town_gui.cpp | 46 +++++++++++++++++++++++++--------------------- 1 file changed, 25 insertions(+), 21 deletions(-) (limited to 'src/town_gui.cpp') diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 5b37a9f14..f5bce66a4 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -848,6 +848,15 @@ void CcFoundTown(bool success, TileIndex tile, uint32 p1, uint32 p2) } } +void CcFoundRandomTown(bool success, TileIndex tile, uint32 p1, uint32 p2) +{ + if (success) { + tile = Town::Get(_new_town_id)->xy; + SndPlayTileFx(SND_1F_SPLAT, tile); + ScrollMainWindowToTile(tile); + } +} + /** Widget numbers of town scenario editor window. */ enum TownScenarioEditorWidgets { TSEW_CLOSEBOX, @@ -963,6 +972,18 @@ public: this->SetDirty(); } + void ExecuteFoundTownCommand(TileIndex tile, bool random, StringID errstr, CommandCallback cc) + { + uint32 townnameparts; + if (!GenerateTownName(&townnameparts)) { + ShowErrorMessage(STR_ERROR_TOO_MANY_TOWNS, errstr, 0, 0); + return; + } + + DoCommandP(tile, this->town_size | this->city << 2 | this->town_layout << 3 | random << 6, + townnameparts, CMD_FOUND_TOWN | CMD_MSG(errstr), cc); + } + virtual void OnPaint() { this->DrawWidgets(); @@ -975,20 +996,10 @@ public: HandlePlacePushButton(this, TSEW_NEWTOWN, SPR_CURSOR_TOWN, HT_RECT, NULL); break; - case TSEW_RANDOMTOWN: { + case TSEW_RANDOMTOWN: this->HandleButtonClick(TSEW_RANDOMTOWN); - _generating_world = true; - UpdateNearestTownForRoadTiles(true); - const Town *t = CreateRandomTown(20, this->town_size, this->city, this->town_layout); - UpdateNearestTownForRoadTiles(false); - _generating_world = false; - - if (t == NULL) { - ShowErrorMessage(STR_ERROR_NO_SPACE_FOR_TOWN, STR_ERROR_CAN_T_GENERATE_TOWN, 0, 0); - } else { - ScrollMainWindowToTile(t->xy); - } - } break; + this->ExecuteFoundTownCommand(0, true, STR_ERROR_CAN_T_GENERATE_TOWN, CcFoundRandomTown); + break; case TSEW_MANYRANDOMTOWNS: this->HandleButtonClick(TSEW_MANYRANDOMTOWNS); @@ -1030,14 +1041,7 @@ public: virtual void OnPlaceObject(Point pt, TileIndex tile) { - uint32 townnameparts; - if (!GenerateTownName(&townnameparts)) { - ShowErrorMessage(STR_ERROR_TOO_MANY_TOWNS, STR_ERROR_CAN_T_FOUND_TOWN_HERE, 0, 0); - return; - } - - DoCommandP(tile, this->town_size | this->city << 2 | this->town_layout << 3, townnameparts, - CMD_FOUND_TOWN | CMD_MSG(STR_ERROR_CAN_T_FOUND_TOWN_HERE), CcFoundTown); + this->ExecuteFoundTownCommand(tile, false, STR_ERROR_CAN_T_FOUND_TOWN_HERE, CcFoundTown); } virtual void OnPlaceObjectAbort() -- cgit v1.2.3-54-g00ecf