diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/town.h | 2 | ||||
-rw-r--r-- | src/town_cmd.cpp | 51 | ||||
-rw-r--r-- | src/town_gui.cpp | 17 | ||||
-rw-r--r-- | src/town_type.h | 10 |
4 files changed, 33 insertions, 47 deletions
diff --git a/src/town.h b/src/town.h index c90d74a23..9d0240c5d 100644 --- a/src/town.h +++ b/src/town.h @@ -250,7 +250,7 @@ void UpdateAllTownVirtCoords(); void InitializeTown(); void ShowTownViewWindow(TownID town); void ExpandTown(Town *t); -Town *CreateRandomTown(uint attempts, TownSizeMode mode, uint size, TownLayout layout); +Town *CreateRandomTown(uint attempts, TownSize size, bool city, TownLayout layout); enum { ROAD_REMOVE = 0, diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 31eb1c609..5af69578d 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -1428,7 +1428,7 @@ void UpdateTownMaxPass(Town *t) * @param size_mode How the size should be determined * @param size Parameter for size determination */ -static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSizeMode size_mode, uint size, TownLayout layout) +static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSize size, bool city, TownLayout layout) { extern int _nb_orig_names; @@ -1480,26 +1480,11 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSize t->InitializeLayout(layout); - /* Random town size. */ - int x = (Random() & 0xF) + 8; + t->larger_town = city; - switch (size_mode) { - default: NOT_REACHED(); - - case TSM_RANDOM: - t->larger_town = false; - break; - - case TSM_FIXED: - x = size * 16 + 3; - t->larger_town = false; - break; - - case TSM_CITY: - x *= _settings_game.economy.initial_city_size; - t->larger_town = true; - break; - } + int x = (int)size * 16 + 3; + if (size == TS_RANDOM) x = (Random() & 0xF) + 8; + if (city) x *= _settings_game.economy.initial_city_size; t->noise_reached = 0; @@ -1521,20 +1506,21 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSize * as it might be possible in the future to fund your own town :) * @param tile coordinates where town is built * @param flags type of operation - * @param p1 0..15 size of the town (0 = small, 1 = medium, 2 = large) - * 16..31 town road layout - * @param p2 size mode (@see TownSizeMode) + * @param p1 0..1 size of the town (@see TownSize) + * 2 true iff it should be a city + * 3..5 town road layout (@see TownLayout) + * @param p2 unused */ CommandCost CmdBuildTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, const char *text) { /* Only in the scenario editor */ if (_game_mode != GM_EDITOR) return CMD_ERROR; - TownSizeMode tsm = (TownSizeMode)p2; - uint size = GB(p1, 0, 16); - TownLayout layout = (TownLayout)GB(p1, 16, 16); + TownSize size = (TownSize)GB(p1, 0, 2); + bool city = HasBit(p1, 2); + TownLayout layout = (TownLayout)GB(p1, 3, 3); - if (tsm > TSM_CITY) return CMD_ERROR; + if (size > TS_RANDOM) return CMD_ERROR; if (layout > TL_RANDOM) return CMD_ERROR; /* Check if too close to the edge of map */ @@ -1564,14 +1550,14 @@ CommandCost CmdBuildTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, con Town *t = new Town(tile); _generating_world = true; UpdateNearestTownForRoadTiles(true); - DoCreateTown(t, tile, townnameparts, tsm, size, layout); + DoCreateTown(t, tile, townnameparts, size, city, layout); UpdateNearestTownForRoadTiles(false); _generating_world = false; } return CommandCost(); } -Town *CreateRandomTown(uint attempts, TownSizeMode mode, uint size, TownLayout layout) +Town *CreateRandomTown(uint attempts, TownSize size, bool city, TownLayout layout) { if (!Town::CanAllocateItem()) return NULL; @@ -1603,7 +1589,7 @@ Town *CreateRandomTown(uint attempts, TownSizeMode mode, uint size, TownLayout l /* Allocate a town struct */ Town *t = new Town(tile); - DoCreateTown(t, tile, townnameparts, mode, size, layout); + DoCreateTown(t, tile, townnameparts, size, city, layout); return t; } while (--attempts != 0); @@ -1623,13 +1609,12 @@ bool GenerateTowns(TownLayout layout) do { IncreaseGeneratingWorldProgress(GWP_TOWN); /* try 20 times to create a random-sized town for the first loop. */ - TownSizeMode mode = num_cities > 0 ? TSM_CITY : TSM_RANDOM; - if (CreateRandomTown(20, mode, _settings_game.economy.initial_city_size, layout) != NULL) num++; + if (CreateRandomTown(20, TS_RANDOM, num_cities > 0, layout) != NULL) num++; if (num_cities > 0) num_cities--; } while (--n); /* give it a last try, but now more aggressive */ - if (num == 0 && CreateRandomTown(10000, TSM_RANDOM, 0, layout) == NULL) { + if (num == 0 && CreateRandomTown(10000, TS_RANDOM, false, layout) == NULL) { if (GetNumTowns() == 0) { /* XXX - can we handle that more gracefully? */ if (_game_mode != GM_EDITOR) usererror("Could not generate any town"); diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 56fdb653a..d3612bb80 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -28,7 +28,7 @@ typedef GUIList<const Town*> GUITownList; -static int _scengen_town_size = 1; // depress medium-sized towns per default +static uint _scengen_town_size = 1; // select medium-sized towns per default static TownLayout _scengen_town_layout; static const Widget _town_authority_widgets[] = { @@ -603,10 +603,9 @@ void CcBuildTown(bool success, TileIndex tile, uint32 p1, uint32 p2) static void PlaceProc_Town(TileIndex tile) { - uint32 size = min(_scengen_town_size, 2); - uint32 mode = _scengen_town_size > 2 ? TSM_CITY : TSM_FIXED; - uint32 layout = _scengen_town_layout; - DoCommandP(tile, size | (layout << 16), mode, CMD_BUILD_TOWN | CMD_MSG(STR_0236_CAN_T_BUILD_TOWN_HERE), CcBuildTown); + bool city = _scengen_town_size > (uint)TS_LARGE; + TownSize size = city ? TS_RANDOM : (TownSize)_scengen_town_size; + DoCommandP(tile, size | city << 2 | (_scengen_town_layout << 3), 0, CMD_BUILD_TOWN | CMD_MSG(STR_0236_CAN_T_BUILD_TOWN_HERE), CcBuildTown); } static const Widget _scen_edit_town_gen_widgets[] = { @@ -677,14 +676,14 @@ public: break; case TSEW_RANDOMTOWN: { - Town *t; - uint size = min(_scengen_town_size, (int)TSM_CITY); - TownSizeMode mode = _scengen_town_size > TSM_CITY ? TSM_CITY : TSM_FIXED; + bool city = _scengen_town_size == 3; + /* cities will always have 'large size' * initial_city_size */ + TownSize size = city ? TS_RANDOM : (TownSize)_scengen_town_size; this->HandleButtonClick(TSEW_RANDOMTOWN); _generating_world = true; UpdateNearestTownForRoadTiles(true); - t = CreateRandomTown(20, mode, size, _scengen_town_layout); + const Town *t = CreateRandomTown(20, size, city, _scengen_town_layout); UpdateNearestTownForRoadTiles(false); _generating_world = false; diff --git a/src/town_type.h b/src/town_type.h index b863741b9..8da1a198a 100644 --- a/src/town_type.h +++ b/src/town_type.h @@ -14,10 +14,12 @@ typedef uint16 HouseClassID; struct Town; struct HouseSpec; -enum TownSizeMode { - TSM_RANDOM, - TSM_FIXED, - TSM_CITY +/** Supported initial town sizes */ +enum TownSize { + TS_SMALL, ///< small town + TS_MEDIUM, ///< medium town + TS_LARGE, ///< large town + TS_RANDOM, ///< random size, bigger than small, smaller than large }; enum { |