(svn r15342) -Feature: allow changing town layout in the 'Found new town' window

This commit is contained in:
smatz 2009-02-04 22:52:34 +00:00
parent 47516b31a7
commit df2a387fc3
5 changed files with 72 additions and 27 deletions

View File

@ -26,13 +26,13 @@
#include "saveload/saveload.h"
#include "void_map.h"
#include "settings_type.h"
#include "town.h"
#include "table/sprites.h"
void GenerateClearTile();
void GenerateIndustries();
void GenerateUnmovables();
bool GenerateTowns();
void GenerateTrees();
void StartupEconomy();
@ -121,7 +121,7 @@ static void _GenerateWorld(void *arg)
/* only generate towns, tree and industries in newgame mode. */
if (_game_mode != GM_EDITOR) {
GenerateTowns();
GenerateTowns(_settings_game.economy.town_layout);
GenerateIndustries();
GenerateUnmovables();
GenerateTrees();

View File

@ -764,6 +764,14 @@ STR_SCENARIO_EDITOR_CITY :{BLACK}City
STR_02A4_SELECT_TOWN_SIZE :{BLACK}Select town size
STR_02A5_TOWN_SIZE :{YELLOW}Town size:
STR_TOWN_ROAD_LAYOUT :{YELLOW}Town road layout:
STR_SELECT_TOWN_ROAD_LAYOUT :{BLACK}Select road layout used for this town
STR_SELECT_LAYOUT_ORIGINAL :{BLACK}Original
STR_SELECT_LAYOUT_BETTER_ROADS :{BLACK}Better roads
STR_SELECT_LAYOUT_2X2_GRID :{BLACK}2x2 grid
STR_SELECT_LAYOUT_3X3_GRID :{BLACK}3x3 grid
STR_SELECT_LAYOUT_RANDOM :{BLACK}Random
STR_02B6 :{STRING} - {STRING5}
STR_02B7_SHOW_LAST_MESSAGE_OR_NEWS :{BLACK}Show last message or news report
STR_OFF :Off

View File

@ -184,7 +184,7 @@ struct Town : PoolItem<Town, TownID, &_Town_pool> {
inline bool IsValid() const { return this->xy != INVALID_TILE; }
void InitializeLayout();
void InitializeLayout(TownLayout layout);
/** Calculate the max town noise
* The value is counted using the population divided by the content of the
@ -250,7 +250,7 @@ void UpdateAllTownVirtCoords();
void InitializeTown();
void ShowTownViewWindow(TownID town);
void ExpandTown(Town *t);
Town *CreateRandomTown(uint attempts, TownSizeMode mode, uint size);
Town *CreateRandomTown(uint attempts, TownSizeMode mode, uint size, TownLayout layout);
enum {
ROAD_REMOVE = 0,
@ -358,6 +358,7 @@ void ChangeTownRating(Town *t, int add, int max);
HouseZonesBits GetTownRadiusGroup(const Town *t, TileIndex tile);
void SetTownRatingTestMode(bool mode);
uint GetMaskOfTownActions(int *nump, CompanyID cid, const Town *t);
bool GenerateTowns(TownLayout layout);
/**
* Calculate a hash value from a tile position

View File

@ -115,10 +115,10 @@ Town::~Town()
/**
* Assigns town layout. If Random, generates one based on TileHash.
*/
void Town::InitializeLayout()
void Town::InitializeLayout(TownLayout layout)
{
if (_settings_game.economy.town_layout != TL_RANDOM) {
this->layout = _settings_game.economy.town_layout;
if (layout != TL_RANDOM) {
this->layout = layout;
return;
}
@ -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)
static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSizeMode size_mode, uint size, TownLayout layout)
{
extern int _nb_orig_names;
@ -1478,7 +1478,7 @@ static void DoCreateTown(Town *t, TileIndex tile, uint32 townnameparts, TownSize
UpdateTownVirtCoord(t);
InvalidateWindowData(WC_TOWN_DIRECTORY, 0, 0);
t->InitializeLayout();
t->InitializeLayout(layout);
/* Random town size. */
int x = (Random() & 0xF) + 8;
@ -1521,14 +1521,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 size of the town (0 = small, 1 = medium, 2 = large)
* @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)
*/
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;
if (p2 > TSM_CITY) return CMD_ERROR;
TownSizeMode tsm = (TownSizeMode)p2;
uint size = GB(p1, 0, 16);
TownLayout layout = (TownLayout)GB(p1, 16, 16);
if (tsm > TSM_CITY) return CMD_ERROR;
if (layout > TL_RANDOM) return CMD_ERROR;
/* Check if too close to the edge of map */
if (DistanceFromEdge(tile) < 12)
@ -1557,21 +1564,21 @@ 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, (TownSizeMode)p2, p1);
DoCreateTown(t, tile, townnameparts, tsm, size, layout);
UpdateNearestTownForRoadTiles(false);
_generating_world = false;
}
return CommandCost();
}
Town *CreateRandomTown(uint attempts, TownSizeMode mode, uint size)
Town *CreateRandomTown(uint attempts, TownSizeMode mode, uint size, TownLayout layout)
{
if (!Town::CanAllocateItem()) return NULL;
do {
/* Generate a tile index not too close from the edge */
TileIndex tile = RandomTile();
switch (_settings_game.economy.town_layout) {
switch (layout) {
case TL_2X2_GRID:
tile = TileXY(TileX(tile) - TileX(tile) % 3, TileY(tile) - TileY(tile) % 3);
break;
@ -1596,7 +1603,7 @@ Town *CreateRandomTown(uint attempts, TownSizeMode mode, uint size)
/* Allocate a town struct */
Town *t = new Town(tile);
DoCreateTown(t, tile, townnameparts, mode, size);
DoCreateTown(t, tile, townnameparts, mode, size, layout);
return t;
} while (--attempts != 0);
@ -1605,7 +1612,7 @@ Town *CreateRandomTown(uint attempts, TownSizeMode mode, uint size)
static const byte _num_initial_towns[4] = {5, 11, 23, 46}; // very low, low, normal, high
bool GenerateTowns()
bool GenerateTowns(TownLayout layout)
{
uint num = 0;
uint n = ScaleByMapSize(_num_initial_towns[_settings_game.difficulty.number_towns] + (Random() & 7));
@ -1617,12 +1624,12 @@ bool GenerateTowns()
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) != NULL) num++;
if (CreateRandomTown(20, mode, _settings_game.economy.initial_city_size, 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) == NULL) {
if (num == 0 && CreateRandomTown(10000, TSM_RANDOM, 0, layout) == NULL) {
if (GetNumTowns() == 0) {
/* XXX - can we handle that more gracefully? */
if (_game_mode != GM_EDITOR) usererror("Could not generate any town");

View File

@ -28,8 +28,8 @@
typedef GUIList<const Town*> GUITownList;
extern bool GenerateTowns();
static int _scengen_town_size = 1; // depress medium-sized towns per default
static TownLayout _scengen_town_layout;
static const Widget _town_authority_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_BROWN, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW}, // TWA_CLOSEBOX
@ -603,24 +603,35 @@ void CcBuildTown(bool success, TileIndex tile, uint32 p1, uint32 p2)
static void PlaceProc_Town(TileIndex tile)
{
uint32 size = min(_scengen_town_size, (int)TSM_CITY);
uint32 mode = _scengen_town_size > TSM_CITY ? TSM_CITY : TSM_FIXED;
DoCommandP(tile, size, mode, CMD_BUILD_TOWN | CMD_MSG(STR_0236_CAN_T_BUILD_TOWN_HERE), CcBuildTown);
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);
}
static const Widget _scen_edit_town_gen_widgets[] = {
{ WWT_CLOSEBOX, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 10, 0, 13, STR_00C5, STR_018B_CLOSE_WINDOW},
{ WWT_CAPTION, RESIZE_NONE, COLOUR_DARK_GREEN, 11, 147, 0, 13, STR_0233_TOWN_GENERATION, STR_018C_WINDOW_TITLE_DRAG_THIS},
{ WWT_STICKYBOX, RESIZE_NONE, COLOUR_DARK_GREEN, 148, 159, 0, 13, 0x0, STR_STICKY_BUTTON},
{ WWT_PANEL, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 159, 14, 94, 0x0, STR_NULL},
{ WWT_PANEL, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 159, 14, 146, 0x0, STR_NULL},
{ WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 2, 157, 16, 27, STR_0234_NEW_TOWN, STR_0235_CONSTRUCT_NEW_TOWN},
{ WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 2, 157, 29, 40, STR_023D_RANDOM_TOWN, STR_023E_BUILD_TOWN_IN_RANDOM_LOCATION},
{ WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 2, 157, 42, 53, STR_MANY_RANDOM_TOWNS, STR_RANDOM_TOWNS_TIP},
{ WWT_LABEL, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 147, 54, 67, STR_02A5_TOWN_SIZE, STR_NULL},
{ WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 2, 53, 68, 79, STR_02A1_SMALL, STR_02A4_SELECT_TOWN_SIZE},
{ WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 54, 105, 68, 79, STR_02A2_MEDIUM, STR_02A4_SELECT_TOWN_SIZE},
{ WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 106, 157, 68, 79, STR_02A3_LARGE, STR_02A4_SELECT_TOWN_SIZE},
{ WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 2, 157, 81, 92, STR_SCENARIO_EDITOR_CITY, STR_02A4_SELECT_TOWN_SIZE},
{ WWT_LABEL, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 147, 54, 67, STR_02A5_TOWN_SIZE, STR_NULL},
{ WWT_LABEL, RESIZE_NONE, COLOUR_DARK_GREEN, 0, 147, 93, 106, STR_TOWN_ROAD_LAYOUT, STR_NULL},
{ WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 2, 79, 107, 118, STR_SELECT_LAYOUT_ORIGINAL, STR_SELECT_TOWN_ROAD_LAYOUT},
{ WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 80, 157, 107, 118, STR_SELECT_LAYOUT_BETTER_ROADS, STR_SELECT_TOWN_ROAD_LAYOUT},
{ WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 2, 79, 120, 131, STR_SELECT_LAYOUT_2X2_GRID, STR_SELECT_LAYOUT_2X2_GRID},
{ WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 80, 157, 120, 131, STR_SELECT_LAYOUT_3X3_GRID, STR_SELECT_TOWN_ROAD_LAYOUT},
{ WWT_TEXTBTN, RESIZE_NONE, COLOUR_GREY, 2, 157, 133, 144, STR_SELECT_LAYOUT_RANDOM, STR_SELECT_TOWN_ROAD_LAYOUT},
{ WIDGETS_END},
};
@ -631,10 +642,17 @@ private:
TSEW_NEWTOWN = 4,
TSEW_RANDOMTOWN,
TSEW_MANYRANDOMTOWNS,
TSEW_TOWNSIZE,
TSEW_SMALLTOWN,
TSEW_MEDIUMTOWN,
TSEW_LARGETOWN,
TSEW_CITY,
TSEW_TOWNLAYOUT,
TSEW_LAYOUT_ORIGINAL,
TSEW_LAYOUT_BETTER,
TSEW_LAYOUT_GRID2,
TSEW_LAYOUT_GRID3,
TSEW_LAYOUT_RANDOM,
};
public:
@ -642,6 +660,8 @@ public:
{
this->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN);
this->FindWindowPlacementAndResize(desc);
_scengen_town_layout = _settings_game.economy.town_layout;
this->LowerWidget(_scengen_town_layout + TSEW_LAYOUT_ORIGINAL);
}
virtual void OnPaint()
@ -664,7 +684,7 @@ public:
this->HandleButtonClick(TSEW_RANDOMTOWN);
_generating_world = true;
UpdateNearestTownForRoadTiles(true);
t = CreateRandomTown(20, mode, size);
t = CreateRandomTown(20, mode, size, _scengen_town_layout);
UpdateNearestTownForRoadTiles(false);
_generating_world = false;
@ -680,7 +700,7 @@ public:
_generating_world = true;
UpdateNearestTownForRoadTiles(true);
if (!GenerateTowns()) {
if (!GenerateTowns(_scengen_town_layout)) {
ShowErrorMessage(STR_NO_SPACE_FOR_TOWN, STR_CANNOT_GENERATE_TOWN, 0, 0);
}
UpdateNearestTownForRoadTiles(false);
@ -693,6 +713,14 @@ public:
this->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN);
this->SetDirty();
break;
case TSEW_LAYOUT_ORIGINAL: case TSEW_LAYOUT_BETTER: case TSEW_LAYOUT_GRID2:
case TSEW_LAYOUT_GRID3: case TSEW_LAYOUT_RANDOM:
this->RaiseWidget(_scengen_town_layout + TSEW_LAYOUT_ORIGINAL);
_scengen_town_layout = (TownLayout)(widget - TSEW_LAYOUT_ORIGINAL);
this->LowerWidget(_scengen_town_layout + TSEW_LAYOUT_ORIGINAL);
this->SetDirty();
break;
}
}
@ -712,12 +740,13 @@ public:
{
this->RaiseButtons();
this->LowerWidget(_scengen_town_size + TSEW_SMALLTOWN);
this->LowerWidget(_scengen_town_layout + TSEW_LAYOUT_ORIGINAL);
this->SetDirty();
}
};
static const WindowDesc _scen_edit_town_gen_desc = {
WDP_AUTO, WDP_AUTO, 160, 95, 160, 95,
WDP_AUTO, WDP_AUTO, 160, 147, 160, 147,
WC_SCEN_TOWN_GEN, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_STICKY_BUTTON,
_scen_edit_town_gen_widgets,