# genworld_gui.cpp

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
    00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
    00008  */
    00009
    00012 #include "stdafx.h"
    00013 #include "heightmap.h"
    00014 #include "debug.h"
    00015 #include "genworld.h"
    00016 #include "network/network.h"
    00017 #include "strings_func.h"
    00018 #include "window_func.h"
    00019 #include "date_func.h"
    00020 #include "sound_func.h"
    00021 #include "fios.h"
    00022 #include "string_func.h"
    00023 #include "gui.h"
    00024 #include "widgets/dropdown_type.h"
    00025 #include "widgets/dropdown_func.h"
    00026 #include "landscape_type.h"
    00027 #include "querystring_gui.h"
    00028 #include "town.h"
    00029 #include "thread/thread.h"
    00030 #include "settings_func.h"
    00031 #include "core/geometry_func.hpp"
    00032 #include "core/random_func.hpp"
    00033 #include "tile_map.h"
    00034
    00035 #include "table/strings.h"
    00036 #include "table/sprites.h"
    00037
    00041 enum GenenerateLandscapeWindowMode {
    00042   GLWM_GENERATE,
    00043   GLWM_HEIGHTMAP,
    00044   GLWM_SCENARIO,
    00045 };
    00046
    00047 extern void SwitchToMode(SwitchMode new_mode);
    00048 extern void MakeNewgameSettingsLive();
    00049
    00054 void SetNewLandscapeType(byte landscape)
    00055 {
    00056   _settings_newgame.game_creation.landscape = landscape;
    00057   InvalidateWindowClassesData(WC_SELECT_GAME);
    00058   InvalidateWindowClassesData(WC_GENERATE_LANDSCAPE);
    00059 }
    00060
    00062 enum GenerateLandscapeWindowWidgets {
    00063   GLAND_TEMPERATE,
    00064   GLAND_ARCTIC,
    00065   GLAND_TROPICAL,
    00066   GLAND_TOYLAND,
    00067
    00068   GLAND_MAPSIZE_X_PULLDOWN,
    00069   GLAND_MAPSIZE_Y_PULLDOWN,
    00070
    00071   GLAND_TOWN_PULLDOWN,
    00072   GLAND_INDUSTRY_PULLDOWN,
    00073
    00074   GLAND_RANDOM_EDITBOX,
    00075   GLAND_RANDOM_BUTTON,
    00076
    00077   GLAND_GENERATE_BUTTON,
    00078
    00079   GLAND_START_DATE_DOWN,
    00080   GLAND_START_DATE_TEXT,
    00081   GLAND_START_DATE_UP,
    00082
    00083   GLAND_SNOW_LEVEL_DOWN,
    00084   GLAND_SNOW_LEVEL_TEXT,
    00085   GLAND_SNOW_LEVEL_UP,
    00086
    00087   GLAND_DESERT_AMOUNT_DOWN,
    00088   GLAND_DESERT_AMOUNT_TEXT,
    00089   GLAND_DESERT_AMOUNT_UP,
    00090
    00091   GLAND_TREE_LEVEL_DOWN,
    00092   GLAND_TREE_LEVEL_TEXT,
    00093   GLAND_TREE_LEVEL_UP,
    00094
    00095   GLAND_TREE_PULLDOWN,
    00096   GLAND_LANDSCAPE_PULLDOWN,
    00097
    00098   GLAND_HEIGHTMAP_NAME_TEXT,
    00099   GLAND_HEIGHTMAP_NAME_SPACER,
    00100   GLAND_HEIGHTMAP_SIZE_TEXT,
    00101   GLAND_HEIGHTMAP_ROTATION_PULLDOWN,
    00102
    00103   GLAND_TERRAIN_PULLDOWN,
    00104   GLAND_WATER_PULLDOWN,
    00105   GLAND_SMOOTHNESS_PULLDOWN,
    00106   GLAND_VARIETY_PULLDOWN,
    00107
    00108   GLAND_BORDERS_RANDOM,
    00109   GLAND_WATER_NW,
    00110   GLAND_WATER_NE,
    00111   GLAND_WATER_SE,
    00112   GLAND_WATER_SW,
    00113 };
    00114
    00116 static const NWidgetPart _nested_generate_landscape_widgets[] = {
    00117   NWidget(NWID_HORIZONTAL),
    00118     NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
    00119     NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MAPGEN_WORLD_GENERATION_CAPTION, STR_NULL),
    00120   EndContainer(),
    00121   NWidget(WWT_PANEL, COLOUR_BROWN),
    00122     NWidget(NWID_SPACER), SetMinimalSize(0, 10),
    00123     /* Landscape selection. */
    00124     NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 10),
    00125       NWidget(NWID_SPACER), SetFill(1, 0),
    00126       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, GLAND_TEMPERATE), SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
    00127       NWidget(NWID_SPACER), SetFill(1, 0),
    00128       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, GLAND_ARCTIC), SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
    00129       NWidget(NWID_SPACER), SetFill(1, 0),
    00130       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, GLAND_TROPICAL), SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
    00131       NWidget(NWID_SPACER), SetFill(1, 0),
    00132       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, GLAND_TOYLAND), SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
    00133       NWidget(NWID_SPACER), SetFill(1, 0),
    00134     EndContainer(),
    00135     NWidget(NWID_SPACER), SetMinimalSize(0, 11),
    00136     NWidget(NWID_HORIZONTAL), SetPIP(10, 5, 10),
    00137       NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
    00138         /* Left column with labels. */
    00139         NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
    00140           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAPSIZE, STR_NULL), SetFill(1, 1),
    00141           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_LAND_GENERATOR, STR_NULL), SetFill(1, 1),
    00142           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TREE_PLACER, STR_NULL), SetFill(1, 1),
    00143           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_TOWNS, STR_NULL), SetFill(1, 1),
    00144           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TERRAIN_TYPE, STR_NULL), SetFill(1, 1),
    00145 // TODO: put variety back after sea lakes after having created a stacked widget ... for snowline/desert_amount
    00146           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_VARIETY, STR_NULL), SetFill(1, 1),
    00147           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_RANDOM_SEED, STR_NULL), SetFill(1, 1),
    00148           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_QUANTITY_OF_SEA_LAKES, STR_NULL), SetFill(1, 1),
    00149           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BORDER_TYPE, STR_NULL), SetFill(1, 1),
    00150         EndContainer(),
    00151         /* Widgets at the right of the labels. */
    00152         NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
    00153           /* Mapsize X * Y. */
    00154           NWidget(NWID_HORIZONTAL), SetPIP(0, 4, 0),
    00155             NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_MAPSIZE_X_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetFill(1, 0),
    00156             NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BY, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(1, 1),
    00157             NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_MAPSIZE_Y_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetFill(1, 0),
    00158           EndContainer(),
    00159           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_LANDSCAPE_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00160           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_TREE_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00161           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_TOWN_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00162           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_TERRAIN_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00163 // TODO: put variety pulldown back after sea lakes after having created a stacked widget ... for snowline/desert_amount
    00164           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_VARIETY_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00165           NWidget(WWT_EDITBOX, COLOUR_WHITE, GLAND_RANDOM_EDITBOX), SetDataTip(STR_MAPGEN_RANDOM_SEED_OSKTITLE, STR_MAPGEN_RANDOM_SEED_HELP), SetFill(1, 1),
    00166           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_WATER_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00167           NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, GLAND_BORDERS_RANDOM), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00168         EndContainer(),
    00169       EndContainer(),
    00170       NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
    00171         NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
    00172           NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
    00173             NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetFill(1, 1),
    00174 //TODO: make stacked widget snowline / desert_amount here (toggled between Tropic and Arctic)
    00175             NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SNOW_LINE_HEIGHT, STR_NULL), SetFill(1, 1),
    00176             NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DESERT_AMOUNT, STR_NULL), SetFill(1, 1),
    00177             NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TREE_LINE_HEIGHT, STR_NULL), SetFill(1, 1),
    00178             NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_INDUSTRIES, STR_NULL), SetFill(1, 1),
    00179             NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SMOOTHNESS, STR_NULL), SetFill(1, 1),
    00180           EndContainer(),
    00181           NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
    00182             /* Starting date. */
    00183             NWidget(NWID_HORIZONTAL),
    00184               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_START_DATE_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_BACKWARD), SetFill(0, 1),
    00185               NWidget(WWT_TEXTBTN, COLOUR_ORANGE, GLAND_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL), SetFill(1, 0),
    00186               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_START_DATE_UP), SetDataTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_FORWARD), SetFill(0, 1),
    00187             EndContainer(),
    00188 //TODO: make stacked widget snowline / desert_amount here (toggled between Tropic and Arctic)
    00189             /* Snow line. */
    00190             NWidget(NWID_HORIZONTAL),
    00191               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_SNOW_LEVEL_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_SNOW_LINE_DOWN), SetFill(0, 1),
    00192               NWidget(WWT_TEXTBTN, COLOUR_ORANGE, GLAND_SNOW_LEVEL_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL), SetFill(1, 0),
    00193               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_SNOW_LEVEL_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_SNOW_LINE_UP), SetFill(0, 1),
    00194             EndContainer(),
    00195             /* Amount of desert. */
    00196             NWidget(NWID_HORIZONTAL),
    00197               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_DESERT_AMOUNT_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_DESERT_AMOUNT_DOWN), SetFill(0, 1),
    00198               NWidget(WWT_TEXTBTN, COLOUR_ORANGE, GLAND_DESERT_AMOUNT_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL), SetFill(1, 0),
    00199               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_DESERT_AMOUNT_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_DESERT_AMOUNT_UP), SetFill(0, 1),
    00200             EndContainer(),
    00201             /* Tree line. */
    00202             NWidget(NWID_HORIZONTAL),
    00203               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_TREE_LEVEL_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_TREE_LINE_DOWN), SetFill(0, 1),
    00204               NWidget(WWT_TEXTBTN, COLOUR_ORANGE, GLAND_TREE_LEVEL_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL), SetFill(1, 0),
    00205               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_TREE_LEVEL_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_TREE_LINE_UP), SetFill(0, 1),
    00206             EndContainer(),
    00207             NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_INDUSTRY_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00208             NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_SMOOTHNESS_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00209           EndContainer(),
    00210         EndContainer(),
    00211         NWidget(WWT_TEXTBTN, COLOUR_ORANGE, GLAND_RANDOM_BUTTON), SetDataTip(STR_MAPGEN_RANDOM, STR_MAPGEN_RANDOM_HELP), SetFill(1, 0),
    00212 // TODO: put back after having created a stacked widget ... for snowline/desert_amount
    00213 //        NWidget(NWID_SPACER), SetFill(1, 1),
    00214         NWidget(WWT_TEXTBTN, COLOUR_GREEN, GLAND_GENERATE_BUTTON), SetMinimalSize(84, 30), SetDataTip(STR_MAPGEN_GENERATE, STR_NULL), SetFill(1, 0),
    00215       EndContainer(),
    00216     EndContainer(),
    00217     NWidget(NWID_SPACER), SetMinimalSize(0, 4),
    00218     /* Map borders buttons for each edge. */
    00219     NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 0, 10),
    00220       NWidget(NWID_HORIZONTAL), SetPIP(0, 0, 3),
    00221         NWidget(NWID_SPACER), SetFill(1, 1),
    00222         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NORTHWEST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
    00223       EndContainer(),
    00224       NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, GLAND_WATER_NW), SetDataTip(STR_JUST_STRING, STR_MAPGEN_NORTHWEST), SetFill(1, 1),
    00225       NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, GLAND_WATER_NE), SetDataTip(STR_JUST_STRING, STR_MAPGEN_NORTHEAST), SetFill(1, 1),
    00226       NWidget(NWID_HORIZONTAL), SetPIP(3, 0, 0),
    00227         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NORTHEAST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
    00228         NWidget(NWID_SPACER), SetFill(1, 1),
    00229       EndContainer(),
    00230     EndContainer(),
    00231     NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 0, 10),
    00232       NWidget(NWID_HORIZONTAL), SetPIP(0, 0, 3),
    00233         NWidget(NWID_SPACER), SetFill(1, 1),
    00234         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SOUTHWEST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
    00235       EndContainer(),
    00236       NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, GLAND_WATER_SW), SetDataTip(STR_JUST_STRING, STR_MAPGEN_SOUTHWEST), SetFill(1, 1),
    00237       NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, GLAND_WATER_SE), SetDataTip(STR_JUST_STRING, STR_MAPGEN_SOUTHEAST), SetFill(1, 1),
    00238       NWidget(NWID_HORIZONTAL), SetPIP(3, 0, 0),
    00239         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SOUTHEAST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
    00240         NWidget(NWID_SPACER), SetFill(1, 1),
    00241       EndContainer(),
    00242     EndContainer(),
    00243     NWidget(NWID_SPACER), SetMinimalSize(0, 9), SetFill(1, 1),
    00244   EndContainer(),
    00245 };
    00246
    00248 static const NWidgetPart _nested_heightmap_load_widgets[] = {
    00249   /* Window header. */
    00250   NWidget(NWID_HORIZONTAL),
    00251     NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
    00252     NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MAPGEN_WORLD_GENERATION_CAPTION, STR_NULL),
    00253   EndContainer(),
    00254   NWidget(WWT_PANEL, COLOUR_BROWN),
    00255     NWidget(NWID_SPACER), SetMinimalSize(0, 10),
    00256     /* Landscape selection. */
    00257     NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 10),
    00258       NWidget(NWID_SPACER), SetFill(1, 0),
    00259       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, GLAND_TEMPERATE), SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
    00260       NWidget(NWID_SPACER), SetFill(1, 0),
    00261       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, GLAND_ARCTIC), SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
    00262       NWidget(NWID_SPACER), SetFill(1, 0),
    00263       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, GLAND_TROPICAL), SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
    00264       NWidget(NWID_SPACER), SetFill(1, 0),
    00265       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, GLAND_TOYLAND), SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
    00266       NWidget(NWID_SPACER), SetFill(1, 0),
    00267     EndContainer(),
    00268     NWidget(NWID_SPACER), SetMinimalSize(0, 11), SetFill(0, 1),
    00269     NWidget(NWID_HORIZONTAL), SetPIP(10, 3, 10),
    00270       /* Labels at the left side. */
    00271       NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
    00272         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_HEIGHTMAP_NAME, STR_NULL), SetFill(1, 1),
    00273         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAPSIZE, STR_NULL), SetFill(1, 1),
    00274         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_TOWNS, STR_NULL), SetFill(1, 1),
    00275         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_INDUSTRIES, STR_NULL), SetFill(1, 1),
    00276         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TREE_LINE_HEIGHT, STR_NULL), SetFill(1, 1),
    00277 //TODO: put back tree placer after random box having made a stacked widget for snowline / desert amount
    00278         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TREE_PLACER, STR_NULL), SetFill(1, 1),
    00279         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_RANDOM_SEED, STR_NULL), SetFill(1, 1),
    00280         NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_HEIGHTMAP_ROTATION, STR_NULL), SetFill(1, 1),
    00281       EndContainer(),
    00282       /* Widgets at the right of the labels. */
    00283       NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
    00284         NWidget(WWT_EMPTY, COLOUR_ORANGE, GLAND_HEIGHTMAP_NAME_TEXT), SetFill(1, 0),
    00285         /* Mapsize X * Y. */
    00286         NWidget(NWID_HORIZONTAL), SetPIP(0, 4, 0),
    00287           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_MAPSIZE_X_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetFill(1, 0),
    00288           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BY, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(1, 1),
    00289           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_MAPSIZE_Y_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetFill(1, 0),
    00290         EndContainer(),
    00291         NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_TOWN_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00292         NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_INDUSTRY_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00293         /* treeline height */
    00294         NWidget(NWID_HORIZONTAL),
    00295           NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_TREE_LEVEL_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_TREE_LINE_DOWN), SetFill(0, 1),
    00296           NWidget(WWT_TEXTBTN, COLOUR_ORANGE, GLAND_TREE_LEVEL_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL), SetFill(1, 0),
    00297           NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_TREE_LEVEL_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_TREE_LINE_UP), SetFill(0, 1),
    00298         EndContainer(),
    00299 //TODO: put back tree puldown after random box having made a stacked widget for snowline / desert amount
    00300         NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_TREE_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00301         NWidget(WWT_EDITBOX, COLOUR_WHITE, GLAND_RANDOM_EDITBOX), SetDataTip(STR_MAPGEN_RANDOM_SEED_OSKTITLE, STR_MAPGEN_RANDOM_SEED_HELP), SetFill(1, 1),
    00302         NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_HEIGHTMAP_ROTATION_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00303       EndContainer(),
    00304       NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
    00305         NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
    00306           NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
    00307             NWidget(WWT_EMPTY, INVALID_COLOUR, GLAND_HEIGHTMAP_NAME_SPACER), SetFill(1, 0),
    00308             NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_HEIGHTMAP_SIZE_LABEL, STR_NULL), SetFill(1, 1),
    00309             NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TERRAIN_TYPE, STR_NULL), SetFill(1, 1),
    00310             NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetFill(1, 1),
    00311 //TODO: make stacked widget snowline / desert_amount here (toggled between Tropic and Arctic)
    00312             NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SNOW_LINE_HEIGHT, STR_NULL), SetFill(1, 1),
    00313             NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DESERT_AMOUNT, STR_NULL), SetFill(1, 1),
    00314           EndContainer(),
    00315           NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, 4, 0),
    00316             NWidget(WWT_EMPTY, INVALID_COLOUR, GLAND_HEIGHTMAP_NAME_SPACER), SetFill(1, 0),
    00317             NWidget(WWT_TEXT, COLOUR_ORANGE, GLAND_HEIGHTMAP_SIZE_TEXT), SetDataTip(STR_MAPGEN_HEIGHTMAP_SIZE, STR_NULL), SetFill(1, 0),
    00318             NWidget(WWT_DROPDOWN, COLOUR_ORANGE, GLAND_TERRAIN_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
    00319             NWidget(NWID_HORIZONTAL),
    00320               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_START_DATE_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_BACKWARD), SetFill(0, 1),
    00321               NWidget(WWT_TEXTBTN, COLOUR_ORANGE, GLAND_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL), SetFill(1, 0),
    00322               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_START_DATE_UP), SetDataTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_FORWARD), SetFill(0, 1),
    00323             EndContainer(),
    00324 //TODO: make stacked widget snowline / desert_amount here (toggled between Tropic and Arctic)
    00325             /* Snowline height. */
    00326             NWidget(NWID_HORIZONTAL),
    00327               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_SNOW_LEVEL_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_SNOW_LINE_DOWN), SetFill(0, 1),
    00328               NWidget(WWT_TEXTBTN, COLOUR_ORANGE, GLAND_SNOW_LEVEL_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL), SetFill(1, 0),
    00329               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_SNOW_LEVEL_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_SNOW_LINE_UP), SetFill(0, 1),
    00330             EndContainer(),
    00331             /* Desert amount. */
    00332             NWidget(NWID_HORIZONTAL),
    00333               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_DESERT_AMOUNT_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_DESERT_AMOUNT_DOWN), SetFill(0, 1),
    00334               NWidget(WWT_TEXTBTN, COLOUR_ORANGE, GLAND_DESERT_AMOUNT_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL), SetFill(1, 0),
    00335               NWidget(WWT_IMGBTN, COLOUR_ORANGE, GLAND_DESERT_AMOUNT_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_DESERT_AMOUNT_UP), SetFill(0, 1),
    00336             EndContainer(),
    00337           EndContainer(),
    00338         EndContainer(),
    00339         NWidget(WWT_TEXTBTN, COLOUR_ORANGE, GLAND_RANDOM_BUTTON), SetDataTip(STR_MAPGEN_RANDOM, STR_MAPGEN_RANDOM_HELP), SetFill(1, 0),
    00340         NWidget(WWT_TEXTBTN, COLOUR_GREEN, GLAND_GENERATE_BUTTON), SetDataTip(STR_MAPGEN_GENERATE, STR_NULL), SetFill(1, 1),
    00341       EndContainer(),
    00342     EndContainer(),
    00343     NWidget(NWID_SPACER), SetMinimalSize(0, 9), SetFill(1, 1),
    00344   EndContainer(),
    00345 };
    00346
    00347 static void StartGeneratingLandscape(GenenerateLandscapeWindowMode mode)
    00348 {
    00349   DeleteAllNonVitalWindows();
    00350
    00351   /* Copy all XXX_newgame to XXX when coming from outside the editor */
    00352   MakeNewgameSettingsLive();
    00353   ResetGRFConfig(true);
    00354
    00355   SndPlayFx(SND_15_BEEP);
    00356   switch (mode) {
    00357     case GLWM_GENERATE:  _switch_mode = (_game_mode == GM_EDITOR) ? SM_GENRANDLAND    : SM_NEWGAME;         break;
    00358     case GLWM_HEIGHTMAP: _switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_HEIGHTMAP : SM_START_HEIGHTMAP; break;
    00359     case GLWM_SCENARIO:  _switch_mode = SM_EDITOR; break;
    00360     default: NOT_REACHED();
    00361   }
    00362 }
    00363
    00364 static void LandscapeGenerationCallback(Window *w, bool confirmed)
    00365 {
    00366   if (confirmed) StartGeneratingLandscape((GenenerateLandscapeWindowMode)w->window_number);
    00367 }
    00368
    00374 static bool CheckMapSize(bool print_warning = true)
    00375  {
    00376   uint64 tiles = 1ULL << (_settings_newgame.game_creation.map_x + _settings_newgame.game_creation.map_y);
    00377
    00378   if (_settings_newgame.game_creation.map_x + _settings_newgame.game_creation.map_y > MAX_MAP_TILES_BITS) {
    00379     if (print_warning) {
    00380       SetDParam(0, MAX_MAP_TILES);
    00381       SetDParam(1, tiles);
    00382       ShowErrorMessage(STR_MAPGEN_TOO_MANY_TILES_MESSAGE, INVALID_STRING_ID, WL_ERROR, 0, 0);
    00383     }
    00384     return false;
    00385   }
    00386   return true;
    00387 }
    00388
    00394 static DropDownList *BuildMapsizeDropDown(int other_dimension)
    00395 {
    00396   DropDownList *list = new DropDownList();
    00397
    00398   for (uint i = MIN_MAP_SIZE_BITS; i <= MAX_MAP_SIZE_BITS; i++) {
    00399     DropDownListParamStringItem *item = new DropDownListParamStringItem((i + other_dimension > MAX_MAP_TILES_BITS) ? STR_RED_INT : STR_JUST_INT, i, false);
    00400     item->SetParam(0, 1 << i);
    00401     list->push_back(item);
    00402   }
    00403
    00404   return list;
    00405 }
    00406
    00407 static const StringID _elevations[]  = {STR_TERRAIN_TYPE_FALLEN, STR_TERRAIN_TYPE_VERY_FLAT, STR_TERRAIN_TYPE_FLAT, STR_TERRAIN_TYPE_BUMPY, STR_TERRAIN_TYPE_HILLY, STR_TERRAIN_TYPE_MOUNTAINOUS, STR_TERRAIN_TYPE_ALPINIST, INVALID_STRING_ID};
    00408 static const StringID _sea_lakes[]   = {STR_SEA_LEVEL_VERY_LOW, STR_SEA_LEVEL_LOW, STR_SEA_LEVEL_MEDIUM, STR_SEA_LEVEL_HIGH, STR_SEA_LEVEL_CUSTOM, INVALID_STRING_ID};
    00409 static const StringID _smoothness[]  = {STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_VERY_SMOOTH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_SMOOTH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_ROUGH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_VERY_ROUGH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_CEREALLY_ROUGH, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_COMMUTORZ, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_GO_WITH_THE_FLOW, INVALID_STRING_ID};
    00410 static const StringID _tree_placer[] = {STR_CONFIG_SETTING_TREE_PLACER_NONE, STR_CONFIG_SETTING_TREE_PLACER_ORIGINAL, STR_CONFIG_SETTING_TREE_PLACER_IMPROVED, INVALID_STRING_ID};
    00411 static const StringID _rotation[]    = {STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE, STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_CLOCKWISE, INVALID_STRING_ID};
    00412 static const StringID _landscape[]   = {STR_CONFIG_SETTING_LAND_GENERATOR_ORIGINAL, STR_CONFIG_SETTING_LAND_GENERATOR_TERRA_GENESIS, INVALID_STRING_ID};
    00413 static const StringID _num_towns[]   = {STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM, INVALID_STRING_ID};
    00414 static const StringID _num_inds[]    = {STR_FUNDING_ONLY, STR_MINIMAL, STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, INVALID_STRING_ID};
    00415 static const StringID _variety[]     = {STR_VARIETY_NONE, STR_VARIETY_VERY_LOW, STR_VARIETY_LOW, STR_VARIETY_MEDIUM, STR_VARIETY_HIGH, STR_VARIETY_VERY_HIGH, INVALID_STRING_ID};
    00416
    00417 assert_compile(lengthof(_num_inds) == ID_END + 1);
    00418
    00419 struct GenerateLandscapeWindow : public QueryStringBaseWindow {
    00420   uint widget_id;
    00421   uint x;
    00422   uint y;
    00423   char name[64];
    00424   GenenerateLandscapeWindowMode mode;
    00425
    00426   void SetDropDownColor()
    00427   {
    00428     /* Draw sizes in mapsize selection dropdowns in red if too large size is selected */
    00429     bool mapsize_valid = CheckMapSize(false);
    00430     this->GetWidget<NWidgetCore>(GLAND_MAPSIZE_X_PULLDOWN)->widget_data = mapsize_valid ? STR_JUST_INT : STR_RED_INT;
    00431     this->GetWidget<NWidgetCore>(GLAND_MAPSIZE_Y_PULLDOWN)->widget_data = mapsize_valid ? STR_JUST_INT : STR_RED_INT;
    00432   }
    00433
    00434   GenerateLandscapeWindow(const WindowDesc *desc, WindowNumber number = 0) : QueryStringBaseWindow(11)
    00435   {
    00436     this->InitNested(desc, number);
    00437
    00438     this->LowerWidget(_settings_newgame.game_creation.landscape + GLAND_TEMPERATE);
    00439
    00440     /* snprintf() always outputs trailing '\0', so whole buffer can be used */
    00441     snprintf(this->edit_str_buf, this->edit_str_size, "%u", _settings_newgame.game_creation.generation_seed);
    00442     InitializeTextBuffer(&this->text, this->edit_str_buf, this->edit_str_size);
    00443     this->caption = STR_NULL;
    00444     this->afilter = CS_NUMERAL;
    00445
    00446     this->mode = (GenenerateLandscapeWindowMode)this->window_number;
    00447
    00448     SetDropDownColor();
    00449
    00450     /* Disable town, industry and trees in SE */
    00451     this->SetWidgetDisabledState(GLAND_TOWN_PULLDOWN,     _game_mode == GM_EDITOR);
    00452     this->SetWidgetDisabledState(GLAND_INDUSTRY_PULLDOWN, _game_mode == GM_EDITOR);
    00453     this->SetWidgetDisabledState(GLAND_TREE_PULLDOWN,     _game_mode == GM_EDITOR);
    00454
    00455     this->OnInvalidateData();
    00456   }
    00457
    00458   virtual void SetStringParameters(int widget) const
    00459   {
    00460     switch (widget) {
    00461       case GLAND_START_DATE_TEXT:     SetDParam(0, ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1)); break;
    00462       case GLAND_MAPSIZE_X_PULLDOWN:  SetDParam(0, 1 << _settings_newgame.game_creation.map_x); break;
    00463       case GLAND_MAPSIZE_Y_PULLDOWN:  SetDParam(0, 1 << _settings_newgame.game_creation.map_y); break;
    00464       case GLAND_SNOW_LEVEL_TEXT:     SetDParam(0, _settings_newgame.game_creation.snow_line_height); break;
    00465       case GLAND_DESERT_AMOUNT_TEXT:  SetDParam(0, _settings_newgame.game_creation.desert_amount); break;
    00466       case GLAND_TREE_LEVEL_TEXT:     SetDParam(0, _settings_newgame.game_creation.tree_line_height); break;
    00467
    00468       case GLAND_TOWN_PULLDOWN:
    00469         if (_game_mode == GM_EDITOR) {
    00470           SetDParam(0, STR_DISASTERS_OFF);
    00471         } else if (_settings_newgame.difficulty.number_towns == CUSTOM_TOWN_NUMBER_DIFFICULTY) {
    00472           SetDParam(0, STR_NUM_CUSTOM_NUMBER);
    00473           SetDParam(1, _settings_newgame.game_creation.custom_town_number);
    00474         } else {
    00475           SetDParam(0, _num_towns[_settings_newgame.difficulty.number_towns]);
    00476         }
    00477         break;
    00478
    00479       case GLAND_INDUSTRY_PULLDOWN:   SetDParam(0, _game_mode == GM_EDITOR ? STR_DISASTERS_OFF : _num_inds[_settings_newgame.difficulty.industry_density]); break;
    00480       case GLAND_LANDSCAPE_PULLDOWN:  SetDParam(0, _landscape[_settings_newgame.game_creation.land_generator]); break;
    00481       case GLAND_TREE_PULLDOWN:       SetDParam(0, _tree_placer[_settings_newgame.game_creation.tree_placer]); break;
    00482       case GLAND_TERRAIN_PULLDOWN:    SetDParam(0, _elevations[_settings_newgame.difficulty.terrain_type]); break;
    00483
    00484       case GLAND_WATER_PULLDOWN:
    00485         if (_settings_newgame.difficulty.quantity_sea_lakes == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
    00486           SetDParam(0, STR_SEA_LEVEL_CUSTOM_PERCENTAGE);
    00487           SetDParam(1, _settings_newgame.game_creation.custom_sea_level);
    00488         } else {
    00489           SetDParam(0, _sea_lakes[_settings_newgame.difficulty.quantity_sea_lakes]);
    00490         }
    00491         break;
    00492
    00493       case GLAND_SMOOTHNESS_PULLDOWN: SetDParam(0, _smoothness[_settings_newgame.game_creation.tgen_smoothness]); break;
    00494       case GLAND_VARIETY_PULLDOWN:    SetDParam(0, _variety[_settings_newgame.game_creation.variety]); break;
    00495       case GLAND_BORDERS_RANDOM:      SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOMIZE : STR_MAPGEN_BORDER_MANUAL); break;
    00496       case GLAND_WATER_NE: SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOM : HasBit(_settings_newgame.game_creation.water_borders, BORDER_NE) ? STR_MAPGEN_BORDER_WATER : STR_MAPGEN_BORDER_FREEFORM); break;
    00497       case GLAND_WATER_NW: SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOM : HasBit(_settings_newgame.game_creation.water_borders, BORDER_NW) ? STR_MAPGEN_BORDER_WATER : STR_MAPGEN_BORDER_FREEFORM); break;
    00498       case GLAND_WATER_SE: SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOM : HasBit(_settings_newgame.game_creation.water_borders, BORDER_SE) ? STR_MAPGEN_BORDER_WATER : STR_MAPGEN_BORDER_FREEFORM); break;
    00499       case GLAND_WATER_SW: SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOM : HasBit(_settings_newgame.game_creation.water_borders, BORDER_SW) ? STR_MAPGEN_BORDER_WATER : STR_MAPGEN_BORDER_FREEFORM); break;
    00500       case GLAND_HEIGHTMAP_ROTATION_PULLDOWN: SetDParam(0, _rotation[_settings_newgame.game_creation.heightmap_rotation]); break;
    00501
    00502       case GLAND_HEIGHTMAP_SIZE_TEXT:
    00503         if (_settings_newgame.game_creation.heightmap_rotation == HM_CLOCKWISE) {
    00504           SetDParam(0, this->y);
    00505           SetDParam(1, this->x);
    00506         } else {
    00507           SetDParam(0, this->x);
    00508           SetDParam(1, this->y);
    00509         }
    00510         break;
    00511     }
    00512   }
    00513
    00519   virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
    00520   {
    00521     if (!gui_scope) return;
    00522     /* Update the climate buttons */
    00523     this->SetWidgetLoweredState(GLAND_TEMPERATE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
    00524     this->SetWidgetLoweredState(GLAND_ARCTIC,    _settings_newgame.game_creation.landscape == LT_ARCTIC);
    00525     this->SetWidgetLoweredState(GLAND_TROPICAL,  _settings_newgame.game_creation.landscape == LT_TROPIC);
    00526     this->SetWidgetLoweredState(GLAND_TOYLAND,   _settings_newgame.game_creation.landscape == LT_TOYLAND);
    00527
    00528     /* You can't select smoothness / non-water borders if not terragenesis */
    00529     if (mode == GLWM_GENERATE) {
    00530       this->SetWidgetDisabledState(GLAND_SMOOTHNESS_PULLDOWN, _settings_newgame.game_creation.land_generator == 0);
    00531       this->SetWidgetDisabledState(GLAND_VARIETY_PULLDOWN, _settings_newgame.game_creation.land_generator == 0);
    00532       this->SetWidgetDisabledState(GLAND_BORDERS_RANDOM, _settings_newgame.game_creation.land_generator == 0 || !_settings_newgame.construction.freeform_edges);
    00533       this->SetWidgetsDisabledState(_settings_newgame.game_creation.land_generator == 0 || !_settings_newgame.construction.freeform_edges || _settings_newgame.game_creation.water_borders == BORDERS_RANDOM,
    00534           GLAND_WATER_NW, GLAND_WATER_NE, GLAND_WATER_SE, GLAND_WATER_SW, WIDGET_LIST_END);
    00535
    00536       this->SetWidgetLoweredState(GLAND_BORDERS_RANDOM, _settings_newgame.game_creation.water_borders == BORDERS_RANDOM);
    00537
    00538       this->SetWidgetLoweredState(GLAND_WATER_NW, HasBit(_settings_newgame.game_creation.water_borders, BORDER_NW));
    00539       this->SetWidgetLoweredState(GLAND_WATER_NE, HasBit(_settings_newgame.game_creation.water_borders, BORDER_NE));
    00540       this->SetWidgetLoweredState(GLAND_WATER_SE, HasBit(_settings_newgame.game_creation.water_borders, BORDER_SE));
    00541       this->SetWidgetLoweredState(GLAND_WATER_SW, HasBit(_settings_newgame.game_creation.water_borders, BORDER_SW));
    00542
    00543       this->SetWidgetsDisabledState(_settings_newgame.game_creation.land_generator == 0 && (_settings_newgame.game_creation.landscape == LT_ARCTIC || _settings_newgame.game_creation.landscape == LT_TROPIC),
    00544           GLAND_TERRAIN_PULLDOWN, GLAND_WATER_PULLDOWN, WIDGET_LIST_END);
    00545     }
    00546
    00547     /* Disable snowline if not arctic. */
    00548     this->SetWidgetDisabledState(GLAND_SNOW_LEVEL_TEXT, _settings_newgame.game_creation.landscape != LT_ARCTIC);
    00549     /* Disable desertline if not tropic. */
    00550     this->SetWidgetDisabledState(GLAND_DESERT_AMOUNT_TEXT, _settings_newgame.game_creation.landscape != LT_TROPIC);
    00551
    00552     /* Update availability of decreasing / increasing start date, snow level and treeline level */
    00553     this->SetWidgetDisabledState(GLAND_START_DATE_DOWN,    _settings_newgame.game_creation.starting_year <= MIN_YEAR);
    00554     this->SetWidgetDisabledState(GLAND_START_DATE_UP,      _settings_newgame.game_creation.starting_year >= MAX_YEAR);
    00555     this->SetWidgetDisabledState(GLAND_SNOW_LEVEL_DOWN,    _settings_newgame.game_creation.snow_line_height <= MIN_SNOWLINE_HEIGHT || _settings_newgame.game_creation.landscape != LT_ARCTIC);
    00556     this->SetWidgetDisabledState(GLAND_SNOW_LEVEL_UP,      _settings_newgame.game_creation.snow_line_height >= MAX_SNOWLINE_HEIGHT_EXTENDED/*GetMaxSnowlineHeight()*/ || _settings_newgame.game_creation.landscape != LT_ARCTIC);
    00557     this->SetWidgetDisabledState(GLAND_DESERT_AMOUNT_DOWN, _settings_newgame.game_creation.desert_amount <= MIN_DESERT_AMOUNT || _settings_newgame.game_creation.landscape != LT_TROPIC);
    00558     this->SetWidgetDisabledState(GLAND_DESERT_AMOUNT_UP,   _settings_newgame.game_creation.desert_amount >= MAX_DESERT_AMOUNT || _settings_newgame.game_creation.landscape != LT_TROPIC);
    00559     this->SetWidgetDisabledState(GLAND_TREE_LEVEL_DOWN,    _settings_newgame.game_creation.tree_line_height <= MIN_TREELINE_HEIGHT);
    00560     this->SetWidgetDisabledState(GLAND_TREE_LEVEL_UP,      _settings_newgame.game_creation.tree_line_height >= MAX_TREELINE_HEIGHT_EXTENDED/*GetMaxTreelineHeight()*/);
    00561
    00562     /* Do not allow a custom sea level with the original land generator. */
    00563     if (_settings_newgame.game_creation.land_generator == 0 &&
    00564         _settings_newgame.difficulty.quantity_sea_lakes == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
    00565       _settings_newgame.difficulty.quantity_sea_lakes = CUSTOM_SEA_LEVEL_MIN_PERCENTAGE;
    00566     }
    00567
    00568   }
    00569
    00570   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
    00571   {
    00572     const StringID *strs = NULL;
    00573     switch (widget) {
    00574       case GLAND_START_DATE_TEXT:
    00575         SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
    00576         *size = GetStringBoundingBox(STR_BLACK_DATE_LONG);
    00577         break;
    00578
    00579       case GLAND_MAPSIZE_X_PULLDOWN:
    00580       case GLAND_MAPSIZE_Y_PULLDOWN:
    00581         SetDParam(0, MAX_MAP_SIZE);
    00582         *size = GetStringBoundingBox(STR_JUST_INT);
    00583         break;
    00584
    00585       case GLAND_SNOW_LEVEL_TEXT:
    00586         SetDParam(0, MAX_SNOWLINE_HEIGHT_EXTENDED/*GetMaxSnowlineHeight()*/);
    00587         *size = GetStringBoundingBox(STR_JUST_INT);
    00588         break;
    00589
    00590       case GLAND_DESERT_AMOUNT_TEXT:
    00591         SetDParam(0, MAX_DESERT_AMOUNT);
    00592         *size = GetStringBoundingBox(STR_JUST_INT);
    00593         break;
    00594
    00595       case GLAND_TREE_LEVEL_TEXT:
    00596         SetDParam(0, MAX_TREELINE_HEIGHT_EXTENDED/*GetMaxTreelineHeight()*/);
    00597         *size = GetStringBoundingBox(STR_JUST_INT);
    00598         break;
    00599
    00600       case GLAND_HEIGHTMAP_SIZE_TEXT:
    00601         SetDParam(0, this->x);
    00602         SetDParam(1, this->y);
    00603         *size = GetStringBoundingBox(STR_MAPGEN_HEIGHTMAP_SIZE);
    00604         break;
    00605
    00606       case GLAND_TOWN_PULLDOWN:
    00607         strs = _num_towns;
    00608         SetDParam(0, CUSTOM_TOWN_MAX_NUMBER);
    00609         *size = GetStringBoundingBox(STR_NUM_CUSTOM_NUMBER);
    00610         break;
    00611
    00612       case GLAND_INDUSTRY_PULLDOWN:   strs = _num_inds; break;
    00613       case GLAND_LANDSCAPE_PULLDOWN:  strs = _landscape; break;
    00614       case GLAND_TREE_PULLDOWN:       strs = _tree_placer; break;
    00615       case GLAND_TERRAIN_PULLDOWN:    strs = _elevations; break;
    00616       case GLAND_WATER_PULLDOWN:
    00617         strs = _sea_lakes;
    00618         SetDParam(0, CUSTOM_SEA_LEVEL_MAX_PERCENTAGE);
    00619         *size = GetStringBoundingBox(STR_SEA_LEVEL_CUSTOM_PERCENTAGE);
    00620         break;
    00621
    00622       case GLAND_SMOOTHNESS_PULLDOWN: strs = _smoothness; break;
    00623       case GLAND_VARIETY_PULLDOWN:    strs = _variety; break;
    00624       case GLAND_HEIGHTMAP_ROTATION_PULLDOWN: strs = _rotation; break;
    00625       case GLAND_BORDERS_RANDOM:
    00626         *size = maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_RANDOMIZE), GetStringBoundingBox(STR_MAPGEN_BORDER_MANUAL));
    00627         break;
    00628
    00629       case GLAND_WATER_NE:
    00630       case GLAND_WATER_NW:
    00631       case GLAND_WATER_SE:
    00632       case GLAND_WATER_SW:
    00633         *size = maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_RANDOM), maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_WATER), GetStringBoundingBox(STR_MAPGEN_BORDER_FREEFORM)));
    00634         break;
    00635
    00636       case GLAND_HEIGHTMAP_NAME_SPACER:
    00637       case GLAND_HEIGHTMAP_NAME_TEXT:
    00638         size->width = 0;
    00639         break;
    00640
    00641       default:
    00642         return;
    00643     }
    00644     if (strs != NULL) {
    00645       while (*strs != INVALID_STRING_ID) {
    00646         *size = maxdim(*size, GetStringBoundingBox(*strs++));
    00647       }
    00648     }
    00649     size->width += padding.width;
    00650     size->height = FONT_HEIGHT_NORMAL + WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM;
    00651   }
    00652
    00653   virtual void DrawWidget(const Rect &r, int widget) const
    00654   {
    00655     switch (widget) {
    00656       case GLAND_HEIGHTMAP_NAME_TEXT: {
    00657         /* Little bit of a hack going on here; just to get the widgets
    00658          * spaced without doing much magic. The space we can draw on is
    00659          * covered by both the spacer and text widgets, so take their
    00660          * outer most boundaries (left and right) as draw locations. */
    00661         const NWidgetBase *nwi_spacer = this->GetWidget<NWidgetBase>(GLAND_HEIGHTMAP_NAME_SPACER);
    00662         DrawString(min(r.left, nwi_spacer->pos_x), max<int>(r.right, nwi_spacer->pos_x + nwi_spacer->current_x), r.top, this->name, TC_ORANGE);
    00663         break;
    00664       }
    00665     }
    00666   }
    00667
    00668   virtual void OnPaint()
    00669   {
    00670     this->DrawWidgets();
    00671     this->DrawEditBox(GLAND_RANDOM_EDITBOX);
    00672   }
    00673
    00674   virtual void OnClick(Point pt, int widget, int click_count)
    00675   {
    00676     switch (widget) {
    00677       case GLAND_TEMPERATE:
    00678       case GLAND_ARCTIC:
    00679       case GLAND_TROPICAL:
    00680       case GLAND_TOYLAND:
    00681         SetNewLandscapeType(widget - GLAND_TEMPERATE);
    00682         break;
    00683
    00684       case GLAND_MAPSIZE_X_PULLDOWN: // Mapsize X.
    00685         ShowDropDownList(this, BuildMapsizeDropDown(_settings_newgame.game_creation.map_y), _settings_newgame.game_creation.map_x, GLAND_MAPSIZE_X_PULLDOWN);
    00686         break;
    00687
    00688       case GLAND_MAPSIZE_Y_PULLDOWN: // Mapsize Y.
    00689         ShowDropDownList(this, BuildMapsizeDropDown(_settings_newgame.game_creation.map_x), _settings_newgame.game_creation.map_y, GLAND_MAPSIZE_Y_PULLDOWN);
    00690         break;
    00691
    00692       case GLAND_TOWN_PULLDOWN: // Number of towns.
    00693         ShowDropDownMenu(this, _num_towns, _settings_newgame.difficulty.number_towns, GLAND_TOWN_PULLDOWN, 0, 0);
    00694         break;
    00695
    00696       case GLAND_INDUSTRY_PULLDOWN: // Number of industries.
    00697         ShowDropDownMenu(this, _num_inds, _settings_newgame.difficulty.industry_density, GLAND_INDUSTRY_PULLDOWN, 0, 0);
    00698         break;
    00699
    00700       case GLAND_RANDOM_BUTTON: // Random seed.
    00701         _settings_newgame.game_creation.generation_seed = InteractiveRandom();
    00702         snprintf(this->edit_str_buf, this->edit_str_size, "%u", _settings_newgame.game_creation.generation_seed);
    00703         UpdateTextBufferSize(&this->text);
    00704         this->SetDirty();
    00705         break;
    00706
    00707       case GLAND_GENERATE_BUTTON: // Generate
    00708         if (mode == GLWM_HEIGHTMAP &&
    00709             (this->x * 2 < (1U << _settings_newgame.game_creation.map_x) ||
    00710             this->x / 2 > (1U << _settings_newgame.game_creation.map_x) ||
    00711             this->y * 2 < (1U << _settings_newgame.game_creation.map_y) ||
    00712             this->y / 2 > (1U << _settings_newgame.game_creation.map_y))) {
    00713           ShowQuery(
    00714             STR_WARNING_HEIGHTMAP_SCALE_CAPTION,
    00715             STR_WARNING_HEIGHTMAP_SCALE_MESSAGE,
    00716             this,
    00717             LandscapeGenerationCallback);
    00718         } else {
    00719           StartGeneratingLandscape(mode);
    00720         }
    00721         break;
    00722
    00723       case GLAND_START_DATE_DOWN:
    00724       case GLAND_START_DATE_UP: // Year buttons.
    00725         /* Don't allow too fast scrolling. */
    00726         if ((this->flags4 & WF_TIMEOUT_MASK) <= WF_TIMEOUT_TRIGGER) {
    00727           this->HandleButtonClick(widget);
    00728
    00729           _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - GLAND_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
    00730           this->InvalidateData();
    00731         }
    00732         _left_button_clicked = false;
    00733         break;
    00734
    00735       case GLAND_START_DATE_TEXT: // Year text.
    00736         this->widget_id = GLAND_START_DATE_TEXT;
    00737         SetDParam(0, _settings_newgame.game_creation.starting_year);
    00738         ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
    00739         break;
    00740
    00741       case GLAND_SNOW_LEVEL_DOWN:
    00742       case GLAND_SNOW_LEVEL_UP: // Snow line buttons.
    00743         /* Don't allow too fast scrolling. */
    00744         if ((this->flags4 & WF_TIMEOUT_MASK) <= WF_TIMEOUT_TRIGGER) {
    00745           this->HandleButtonClick(widget);
    00746
    00747           _settings_newgame.game_creation.snow_line_height = Clamp(_settings_newgame.game_creation.snow_line_height + widget - GLAND_SNOW_LEVEL_TEXT, MIN_SNOWLINE_HEIGHT, MAX_SNOWLINE_HEIGHT_EXTENDED/*GetMaxSnowlineHeight()*/);
    00748           this->InvalidateData();
    00749         }
    00750         _left_button_clicked = false;
    00751         break;
    00752
    00753       case GLAND_SNOW_LEVEL_TEXT: // Snow line text.
    00754         this->widget_id = GLAND_SNOW_LEVEL_TEXT;
    00755         SetDParam(0, _settings_newgame.game_creation.snow_line_height);
    00756         ShowQueryString(STR_JUST_INT, STR_MAPGEN_SNOW_LINE_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
    00757         break;
    00758
    00759       case GLAND_DESERT_AMOUNT_DOWN:
    00760       case GLAND_DESERT_AMOUNT_UP: // Desert amount buttons.
    00761         /* Don't allow too fast scrolling. */
    00762         if ((this->flags4 & WF_TIMEOUT_MASK) <= WF_TIMEOUT_TRIGGER) {
    00763           this->HandleButtonClick(widget);
    00764
    00765           _settings_newgame.game_creation.desert_amount = Clamp(_settings_newgame.game_creation.desert_amount + widget - GLAND_DESERT_AMOUNT_TEXT, MIN_DESERT_AMOUNT, MAX_DESERT_AMOUNT);
    00766           this->InvalidateData();
    00767         }
    00768         _left_button_clicked = false;
    00769         break;
    00770
    00771       case GLAND_DESERT_AMOUNT_TEXT: // Desert amount text.
    00772         this->widget_id = GLAND_DESERT_AMOUNT_TEXT;
    00773         SetDParam(0, _settings_newgame.game_creation.desert_amount);
    00774         ShowQueryString(STR_JUST_INT, STR_MAPGEN_DESERT_AMOUNT_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
    00775         break;
    00776
    00777       case GLAND_TREE_LEVEL_DOWN:
    00778       case GLAND_TREE_LEVEL_UP: // Tree line buttons.
    00779         /* Don't allow too fast scrolling. */
    00780         if ((this->flags4 & WF_TIMEOUT_MASK) <= WF_TIMEOUT_TRIGGER) {
    00781           this->HandleButtonClick(widget);
    00782           this->SetDirty();
    00783
    00784           _settings_newgame.game_creation.tree_line_height = Clamp(_settings_newgame.game_creation.tree_line_height + widget - GLAND_TREE_LEVEL_TEXT, MIN_TREELINE_HEIGHT, MAX_TREELINE_HEIGHT_EXTENDED/*GetMaxTreelineHeight()*/);
    00785           this->InvalidateData();
    00786         }
    00787         _left_button_clicked = false;
    00788         break;
    00789
    00790       case GLAND_TREE_LEVEL_TEXT: // Tree line text.
    00791         this->widget_id = GLAND_TREE_LEVEL_TEXT;
    00792         SetDParam(0, _settings_newgame.game_creation.tree_line_height);
    00793         ShowQueryString(STR_JUST_INT, STR_MAPGEN_TREE_LINE_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_NONE);
    00794         break;
    00795
    00796       case GLAND_TREE_PULLDOWN: // Tree placer.
    00797         ShowDropDownMenu(this, _tree_placer, _settings_newgame.game_creation.tree_placer, GLAND_TREE_PULLDOWN, 0, 0);
    00798         break;
    00799
    00800       case GLAND_LANDSCAPE_PULLDOWN: // Landscape generator.
    00801         ShowDropDownMenu(this, _landscape, _settings_newgame.game_creation.land_generator, GLAND_LANDSCAPE_PULLDOWN, 0, 0);
    00802         break;
    00803
    00804       case GLAND_HEIGHTMAP_ROTATION_PULLDOWN: // Heightmap rotation.
    00805         ShowDropDownMenu(this, _rotation, _settings_newgame.game_creation.heightmap_rotation, GLAND_HEIGHTMAP_ROTATION_PULLDOWN, 0, 0);
    00806         break;
    00807
    00808       case GLAND_TERRAIN_PULLDOWN: // Terrain type.
    00809         ShowDropDownMenu(this, _elevations, _settings_newgame.difficulty.terrain_type, GLAND_TERRAIN_PULLDOWN, 0, 0);
    00810         break;
    00811
    00812       case GLAND_WATER_PULLDOWN: { // Water quantity.
    00813         uint32 hidden_mask = 0;
    00814         /* Disable custom water level when the original map generator is active. */
    00815         if (_settings_newgame.game_creation.land_generator == 0) {
    00816           SetBit(hidden_mask, CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY);
    00817         }
    00818         ShowDropDownMenu(this, _sea_lakes, _settings_newgame.difficulty.quantity_sea_lakes, GLAND_WATER_PULLDOWN, 0, hidden_mask);
    00819         break;
    00820       }
    00821
    00822       case GLAND_SMOOTHNESS_PULLDOWN: // Map smoothness.
    00823         ShowDropDownMenu(this, _smoothness, _settings_newgame.game_creation.tgen_smoothness, GLAND_SMOOTHNESS_PULLDOWN, 0, 0);
    00824         break;
    00825
    00826       case GLAND_VARIETY_PULLDOWN: // Map variety.
    00827         ShowDropDownMenu(this, _variety, _settings_newgame.game_creation.variety, GLAND_VARIETY_PULLDOWN, 0, 0);
    00828         break;
    00829
    00830       /* Freetype map borders. */
    00831       case GLAND_WATER_NW:
    00832         _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_NW);
    00833         this->InvalidateData();
    00834         break;
    00835
    00836       case GLAND_WATER_NE:
    00837         _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_NE);
    00838         this->InvalidateData();
    00839         break;
    00840
    00841       case GLAND_WATER_SE:
    00842         _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_SE);
    00843         this->InvalidateData();
    00844         break;
    00845
    00846       case GLAND_WATER_SW:
    00847         _settings_newgame.game_creation.water_borders = ToggleBit(_settings_newgame.game_creation.water_borders, BORDER_SW);
    00848         this->InvalidateData();
    00849         break;
    00850
    00851       case GLAND_BORDERS_RANDOM:
    00852         _settings_newgame.game_creation.water_borders = (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? 0 : BORDERS_RANDOM;
    00853         this->InvalidateData();
    00854         break;
    00855     }
    00856   }
    00857
    00858   virtual void OnTimeout()
    00859   {
    00860     static const int raise_widgets[] = {GLAND_START_DATE_DOWN, GLAND_START_DATE_UP, GLAND_SNOW_LEVEL_UP, GLAND_SNOW_LEVEL_DOWN, GLAND_DESERT_AMOUNT_UP, GLAND_DESERT_AMOUNT_DOWN, GLAND_TREE_LEVEL_UP, GLAND_TREE_LEVEL_DOWN, WIDGET_LIST_END};
    00861     for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
    00862       if (this->IsWidgetLowered(*widget)) {
    00863         this->RaiseWidget(*widget);
    00864         this->SetWidgetDirty(*widget);
    00865       }
    00866     }
    00867   }
    00868
    00869   virtual void OnMouseLoop()
    00870   {
    00871     this->HandleEditBox(GLAND_RANDOM_EDITBOX);
    00872   }
    00873
    00874   virtual EventState OnKeyPress(uint16 key, uint16 keycode)
    00875   {
    00876     EventState state = ES_NOT_HANDLED;
    00877     this->HandleEditBoxKey(GLAND_RANDOM_EDITBOX, key, keycode, state);
    00878     /* the seed is unsigned, therefore atoi cannot be used.
    00879      * As UINT32_MAX is a 'magic' value (use random seed) it
    00880      * should not be possible to be entered into the input
    00881      * field; the generate seed button can be used instead. */
    00882     _settings_newgame.game_creation.generation_seed = minu(strtoul(this->edit_str_buf, NULL, 10), UINT32_MAX - 1);
    00883     return state;
    00884   }
    00885
    00886   virtual void OnDropdownSelect(int widget, int index)
    00887   {
    00888     switch (widget) {
    00889       case GLAND_MAPSIZE_X_PULLDOWN:
    00890         _settings_newgame.game_creation.map_x = index;
    00891         SetDropDownColor();
    00892         break;
    00893
    00894       case GLAND_MAPSIZE_Y_PULLDOWN:
    00895         _settings_newgame.game_creation.map_y = index;
    00896         SetDropDownColor();
    00897         break;
    00898       case GLAND_TREE_PULLDOWN:          _settings_newgame.game_creation.tree_placer = index; break;
    00899       case GLAND_SMOOTHNESS_PULLDOWN:    _settings_newgame.game_creation.tgen_smoothness = index;  break;
    00900       case GLAND_VARIETY_PULLDOWN:       _settings_newgame.game_creation.variety = index; break;
    00901
    00902       case GLAND_LANDSCAPE_PULLDOWN:     _settings_newgame.game_creation.land_generator = index;
    00903         /* If original landgenerator is selected and mountainous or alpinist terrain_type was selected, revert to hilly. */
    00904         if ((_settings_newgame.game_creation.land_generator == 0) &&
    00905             (_settings_newgame.difficulty.terrain_type == 5 || _settings_newgame.difficulty.terrain_type == 6)) {
    00906           _settings_newgame.difficulty.terrain_type = 4;
    00907         }
    00908         break;
    00909
    00910       case GLAND_HEIGHTMAP_ROTATION_PULLDOWN: _settings_newgame.game_creation.heightmap_rotation = index; break;
    00911
    00912       case GLAND_TOWN_PULLDOWN:
    00913         if ((uint)index == CUSTOM_TOWN_NUMBER_DIFFICULTY) {
    00914           this->widget_id = widget;
    00915           SetDParam(0, _settings_newgame.game_creation.custom_town_number);
    00916           ShowQueryString(STR_JUST_INT, STR_MAPGEN_NUMBER_OF_TOWNS, 5, this, CS_NUMERAL, QSF_NONE);
    00917         }
    00918         IConsoleSetSetting("difficulty.number_towns", index);
    00919         break;
    00920
    00921       case GLAND_INDUSTRY_PULLDOWN:
    00922         IConsoleSetSetting("difficulty.industry_density", index);
    00923         break;
    00924
    00925       case GLAND_TERRAIN_PULLDOWN: {
    00926         GameMode old_gm = _game_mode;
    00927         _game_mode = GM_MENU;
    00928         IConsoleSetSetting("difficulty.terrain_type", index);
    00929         /* If landgenerator is original and mountainous or alpinist terrain_type is selected, revert to hilly. */
    00930         /*TODO: instead of reverting on selection, grey out selections or use seperate array? */
    00931         if ((_settings_newgame.game_creation.land_generator == 0) &&
    00932             (_settings_newgame.difficulty.terrain_type == 5 || _settings_newgame.difficulty.terrain_type == 6)) {
    00933           _settings_newgame.difficulty.terrain_type = 4;
    00934         }
    00935         _game_mode = old_gm;
    00936         break;
    00937       }
    00938
    00939       case GLAND_WATER_PULLDOWN: {
    00940         if ((uint)index == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
    00941           this->widget_id = widget;
    00942           SetDParam(0, _settings_newgame.game_creation.custom_sea_level);
    00943           ShowQueryString(STR_JUST_INT, STR_MAPGEN_QUANTITY_OF_SEA_LAKES, 3, this, CS_NUMERAL, QSF_NONE);
    00944         }
    00945         GameMode old_gm = _game_mode;
    00946         _game_mode = GM_MENU;
    00947         IConsoleSetSetting("difficulty.quantity_sea_lakes", index);
    00948         _game_mode = old_gm;
    00949         break;
    00950       }
    00951     }
    00952     this->InvalidateData();
    00953   }
    00954
    00955   virtual void OnQueryTextFinished(char *str)
    00956   {
    00957     /* Was 'cancel' pressed? */
    00958     if (str == NULL) return;
    00959
    00960     int32 value;
    00961     if (!StrEmpty(str)) {
    00962       value = atoi(str);
    00963     } else {
    00964       /* An empty string means revert to the default */
    00965       switch (this->widget_id) {
    00966         case GLAND_START_DATE_TEXT: value = DEF_START_YEAR; break;
    00967
    00968         case GLAND_SNOW_LEVEL_TEXT:
    00969           if(AllowMoreHeightlevels()) {
    00970             value = DEF_SNOWLINE_HEIGHT_EXTENDED;
    00971           } else {
    00972             value = DEF_SNOWLINE_HEIGHT_OLD;
    00973           }
    00974           break;
    00975
    00976         case GLAND_DESERT_AMOUNT_TEXT: value = DEF_DESERT_AMOUNT; break;
    00977
    00978         case GLAND_TREE_LEVEL_TEXT:
    00979           if (AllowMoreHeightlevels()) {
    00980             value = DEF_TREELINE_HEIGHT_EXTENDED;
    00981           }else{
    00982             value = DEF_TREELINE_HEIGHT_OLD;
    00983           }
    00984           break;
    00985
    00986         case GLAND_TOWN_PULLDOWN:   value = 1; break;
    00987         case GLAND_WATER_PULLDOWN:  value = CUSTOM_SEA_LEVEL_MIN_PERCENTAGE; break;
    00988         default: NOT_REACHED();
    00989       }
    00990     }
    00991
    00992     switch (this->widget_id) {
    00993       case GLAND_START_DATE_TEXT:
    00994         this->SetWidgetDirty(GLAND_START_DATE_TEXT);
    00995         _settings_newgame.game_creation.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
    00996         break;
    00997
    00998       case GLAND_SNOW_LEVEL_TEXT:
    00999         this->SetWidgetDirty(GLAND_SNOW_LEVEL_TEXT);
    01000         _settings_newgame.game_creation.snow_line_height = Clamp(value, MIN_SNOWLINE_HEIGHT, MAX_SNOWLINE_HEIGHT_EXTENDED/*GetMaxSnowlineHeight()*/);
    01001         break;
    01002
    01003       case GLAND_DESERT_AMOUNT_TEXT:
    01004         this->SetWidgetDirty(GLAND_DESERT_AMOUNT_TEXT);
    01005         _settings_newgame.game_creation.desert_amount = Clamp(value, MIN_DESERT_AMOUNT, MAX_DESERT_AMOUNT);
    01006         break;
    01007
    01008       case GLAND_TREE_LEVEL_TEXT:
    01009         this->SetWidgetDirty(GLAND_TREE_LEVEL_TEXT);
    01010         _settings_newgame.game_creation.tree_line_height = Clamp(value, MIN_TREELINE_HEIGHT, MAX_TREELINE_HEIGHT_EXTENDED/*GetMaxTreelineHeight()*/);
    01011         break;
    01012
    01013       case GLAND_TOWN_PULLDOWN:
    01014         _settings_newgame.game_creation.custom_town_number = Clamp(value, 1, CUSTOM_TOWN_MAX_NUMBER);
    01015         break;
    01016
    01017       case GLAND_WATER_PULLDOWN:
    01018         _settings_newgame.game_creation.custom_sea_level = Clamp(value, CUSTOM_SEA_LEVEL_MIN_PERCENTAGE, CUSTOM_SEA_LEVEL_MAX_PERCENTAGE);
    01019         break;
    01020     }
    01021
    01022     this->InvalidateData();
    01023   }
    01024 };
    01025
    01026 static const WindowDesc _generate_landscape_desc(
    01027   WDP_CENTER, 0, 0,
    01028   WC_GENERATE_LANDSCAPE, WC_NONE,
    01029   0,
    01030   _nested_generate_landscape_widgets, lengthof(_nested_generate_landscape_widgets)
    01031 );
    01032
    01033 static const WindowDesc _heightmap_load_desc(
    01034   WDP_CENTER, 0, 0,
    01035   WC_GENERATE_LANDSCAPE, WC_NONE,
    01036   0,
    01037   _nested_heightmap_load_widgets, lengthof(_nested_heightmap_load_widgets)
    01038 );
    01039
    01040 static void _ShowGenerateLandscape(GenenerateLandscapeWindowMode mode)
    01041 {
    01042   uint x = 0;
    01043   uint y = 0;
    01044
    01045   DeleteWindowByClass(WC_GENERATE_LANDSCAPE);
    01046
    01047   /* Always give a new seed if not editor */ // TODO: make this a setting in advanced settings
    01048 //  if (_game_mode != GM_EDITOR) _settings_newgame.game_creation.generation_seed = InteractiveRandom();
    01049
    01050   if (mode == GLWM_HEIGHTMAP) {
    01051     /* If the function returns negative, it means there was a problem loading the heightmap */
    01052     if (!GetHeightmapDimensions(_file_to_saveload.name, &x, &y)) return;
    01053   }
    01054
    01055   GenerateLandscapeWindow *w = AllocateWindowDescFront<GenerateLandscapeWindow>((mode == GLWM_HEIGHTMAP) ? &_heightmap_load_desc : &_generate_landscape_desc, mode);
    01056
    01057   if (mode == GLWM_HEIGHTMAP) {
    01058     w->x = x;
    01059     w->y = y;
    01060     strecpy(w->name, _file_to_saveload.title, lastof(w->name));
    01061   }
    01062
    01063   SetWindowDirty(WC_GENERATE_LANDSCAPE, mode);
    01064 }
    01065
    01067 void ShowGenerateLandscape()
    01068 {
    01069   _ShowGenerateLandscape(GLWM_GENERATE);
    01070 }
    01071
    01073 void ShowHeightmapLoad()
    01074 {
    01075   _ShowGenerateLandscape(GLWM_HEIGHTMAP);
    01076 }
    01077
    01079 void StartScenarioEditor()
    01080 {
    01081   StartGeneratingLandscape(GLWM_SCENARIO);
    01082 }
    01083
    01088 void StartNewGameWithoutGUI(uint seed)
    01089 {
    01090   /* GenerateWorld takes care of the possible GENERATE_NEW_SEED value in 'seed' */
    01091   _settings_newgame.game_creation.generation_seed = seed;
    01092
    01093   StartGeneratingLandscape(GLWM_GENERATE);
    01094 }
    01095
    01097 enum CreateScenarioWindowWidgets {
    01098   CSCEN_TEMPERATE,
    01099   CSCEN_ARCTIC,
    01100   CSCEN_TROPICAL,
    01101   CSCEN_TOYLAND,
    01102   CSCEN_EMPTY_WORLD,
    01103   CSCEN_RANDOM_WORLD,
    01104   CSCEN_MAPSIZE_X_PULLDOWN,
    01105   CSCEN_MAPSIZE_Y_PULLDOWN,
    01106   CSCEN_START_DATE_DOWN,
    01107   CSCEN_START_DATE_TEXT,
    01108   CSCEN_START_DATE_UP,
    01109   CSCEN_FLAT_LAND_HEIGHT_DOWN,
    01110   CSCEN_FLAT_LAND_HEIGHT_TEXT,
    01111   CSCEN_FLAT_LAND_HEIGHT_UP
    01112 };
    01113
    01114
    01115 struct CreateScenarioWindow : public Window
    01116 {
    01117   uint widget_id;
    01118
    01119   void SetDropDownColor()
    01120   {
    01121     /* Draw sizes in mapsize selection dropdowns in red if too large size is selected */
    01122     bool mapsize_valid = CheckMapSize(false);
    01123     this->GetWidget<NWidgetCore>(CSCEN_MAPSIZE_X_PULLDOWN)->widget_data = mapsize_valid ? STR_JUST_INT : STR_RED_INT;
    01124     this->GetWidget<NWidgetCore>(CSCEN_MAPSIZE_Y_PULLDOWN)->widget_data = mapsize_valid ? STR_JUST_INT : STR_RED_INT;
    01125   }
    01126
    01127   CreateScenarioWindow(const WindowDesc *desc, WindowNumber window_number) : Window()
    01128   {
    01129     this->InitNested(desc, window_number);
    01130     this->LowerWidget(_settings_newgame.game_creation.landscape + CSCEN_TEMPERATE);
    01131     SetDropDownColor();
    01132   }
    01133
    01134   virtual void SetStringParameters(int widget) const
    01135   {
    01136     switch (widget) {
    01137       case CSCEN_START_DATE_TEXT:
    01138         SetDParam(0, ConvertYMDToDate(_settings_newgame.game_creation.starting_year, 0, 1));
    01139         break;
    01140
    01141       case CSCEN_MAPSIZE_X_PULLDOWN:
    01142         SetDParam(0, 1 << _settings_newgame.game_creation.map_x);
    01143         break;
    01144
    01145       case CSCEN_MAPSIZE_Y_PULLDOWN:
    01146         SetDParam(0, 1 << _settings_newgame.game_creation.map_y);
    01147         break;
    01148
    01149       case CSCEN_FLAT_LAND_HEIGHT_TEXT:
    01150         SetDParam(0, _settings_newgame.game_creation.se_flat_world_height);
    01151         break;
    01152     }
    01153   }
    01154
    01155   virtual void OnPaint()
    01156   {
    01157     this->SetWidgetDisabledState(CSCEN_START_DATE_DOWN,       _settings_newgame.game_creation.starting_year <= MIN_YEAR);
    01158     this->SetWidgetDisabledState(CSCEN_START_DATE_UP,         _settings_newgame.game_creation.starting_year >= MAX_YEAR);
    01159     this->SetWidgetDisabledState(CSCEN_FLAT_LAND_HEIGHT_DOWN, _settings_newgame.game_creation.se_flat_world_height <= 0);
    01160     this->SetWidgetDisabledState(CSCEN_FLAT_LAND_HEIGHT_UP,   _settings_newgame.game_creation.se_flat_world_height >= GetMaxTileHeight());
    01161
    01162     this->SetWidgetLoweredState(CSCEN_TEMPERATE, _settings_newgame.game_creation.landscape == LT_TEMPERATE);
    01163     this->SetWidgetLoweredState(CSCEN_ARCTIC,    _settings_newgame.game_creation.landscape == LT_ARCTIC);
    01164     this->SetWidgetLoweredState(CSCEN_TROPICAL,  _settings_newgame.game_creation.landscape == LT_TROPIC);
    01165     this->SetWidgetLoweredState(CSCEN_TOYLAND,   _settings_newgame.game_creation.landscape == LT_TOYLAND);
    01166
    01167     this->DrawWidgets();
    01168   }
    01169
    01170   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
    01171   {
    01172     StringID str = STR_JUST_INT;
    01173     switch (widget) {
    01174       case CSCEN_START_DATE_TEXT:
    01175         SetDParam(0, ConvertYMDToDate(MAX_YEAR, 0, 1));
    01176         str = STR_BLACK_DATE_LONG;
    01177         break;
    01178
    01179       case CSCEN_MAPSIZE_X_PULLDOWN:
    01180       case CSCEN_MAPSIZE_Y_PULLDOWN:
    01181         SetDParam(0, MAX_MAP_SIZE);
    01182         break;
    01183
    01184       case CSCEN_FLAT_LAND_HEIGHT_TEXT:
    01185         if (AllowMoreHeightlevels()) {
    01186           SetDParam(0, MAX_TILE_HEIGHT_EXTENDED);
    01187         } else {
    01188           SetDParam(0, MAX_TILE_HEIGHT_OLD);
    01189         }
    01190         break;
    01191
    01192       default:
    01193         return;
    01194     }
    01195     *size = GetStringBoundingBox(str);
    01196     size->width += padding.width;
    01197     size->height += padding.height;
    01198   }
    01199
    01200   virtual void OnClick(Point pt, int widget, int click_count)
    01201   {
    01202     switch (widget) {
    01203       case CSCEN_TEMPERATE:
    01204       case CSCEN_ARCTIC:
    01205       case CSCEN_TROPICAL:
    01206       case CSCEN_TOYLAND:
    01207         this->RaiseWidget(_settings_newgame.game_creation.landscape + CSCEN_TEMPERATE);
    01208         SetNewLandscapeType(widget - CSCEN_TEMPERATE);
    01209         break;
    01210
    01211       case CSCEN_MAPSIZE_X_PULLDOWN: // Mapsize X
    01212         ShowDropDownList(this, BuildMapsizeDropDown(_settings_newgame.game_creation.map_y), _settings_newgame.game_creation.map_x, CSCEN_MAPSIZE_X_PULLDOWN);
    01213         break;
    01214
    01215       case CSCEN_MAPSIZE_Y_PULLDOWN: // Mapsize Y
    01216         ShowDropDownList(this, BuildMapsizeDropDown(_settings_newgame.game_creation.map_x), _settings_newgame.game_creation.map_y, CSCEN_MAPSIZE_Y_PULLDOWN);
    01217         break;
    01218
    01219       case CSCEN_EMPTY_WORLD: // Empty world / flat world
    01220         if (!CheckMapSize()) break;
    01221         StartGeneratingLandscape(GLWM_SCENARIO);
    01222         break;
    01223
    01224       case CSCEN_RANDOM_WORLD: // Generate
    01225         if (!CheckMapSize()) break;
    01226         ShowGenerateLandscape();
    01227         break;
    01228
    01229       case CSCEN_START_DATE_DOWN:
    01230       case CSCEN_START_DATE_UP: // Year buttons
    01231         /* Don't allow too fast scrolling */
    01232         if ((this->flags4 & WF_TIMEOUT_MASK) <= WF_TIMEOUT_TRIGGER) {
    01233           this->HandleButtonClick(widget);
    01234           this->SetDirty();
    01235
    01236           _settings_newgame.game_creation.starting_year = Clamp(_settings_newgame.game_creation.starting_year + widget - CSCEN_START_DATE_TEXT, MIN_YEAR, MAX_YEAR);
    01237         }
    01238         _left_button_clicked = false;
    01239         break;
    01240
    01241       case CSCEN_START_DATE_TEXT: // Year text
    01242         this->widget_id = CSCEN_START_DATE_TEXT;
    01243         SetDParam(0, _settings_newgame.game_creation.starting_year);
    01244         ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_NONE);
    01245         break;
    01246
    01247       case CSCEN_FLAT_LAND_HEIGHT_DOWN:
    01248       case CSCEN_FLAT_LAND_HEIGHT_UP: // Height level buttons
    01249         /* Don't allow too fast scrolling */
    01250         if ((this->flags4 & WF_TIMEOUT_MASK) <= WF_TIMEOUT_TRIGGER) {
    01251           this->HandleButtonClick(widget);
    01252           this->SetDirty();
    01253
    01254           _settings_newgame.game_creation.se_flat_world_height = Clamp(_settings_newgame.game_creation.se_flat_world_height + widget - CSCEN_FLAT_LAND_HEIGHT_TEXT, 0, GetMaxTileHeight());
    01255         }
    01256         _left_button_clicked = false;
    01257         break;
    01258
    01259       case CSCEN_FLAT_LAND_HEIGHT_TEXT: // Height level text
    01260         this->widget_id = CSCEN_FLAT_LAND_HEIGHT_TEXT;
    01261         SetDParam(0, _settings_newgame.game_creation.se_flat_world_height);
    01262         ShowQueryString(STR_JUST_INT, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_NONE);
    01263         break;
    01264     }
    01265   }
    01266
    01267   virtual void OnTimeout()
    01268   {
    01269     static const int raise_widgets[] = {CSCEN_START_DATE_DOWN, CSCEN_START_DATE_UP, CSCEN_FLAT_LAND_HEIGHT_DOWN, CSCEN_FLAT_LAND_HEIGHT_UP, WIDGET_LIST_END};
    01270     for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
    01271       if (this->IsWidgetLowered(*widget)) {
    01272         this->RaiseWidget(*widget);
    01273         this->SetWidgetDirty(*widget);
    01274       }
    01275     }
    01276   }
    01277
    01278   virtual void OnDropdownSelect(int widget, int index)
    01279   {
    01280     switch (widget) {
    01281       case CSCEN_MAPSIZE_X_PULLDOWN: _settings_newgame.game_creation.map_x = index; break;
    01282       case CSCEN_MAPSIZE_Y_PULLDOWN: _settings_newgame.game_creation.map_y = index; break;
    01283     }
    01284     SetDropDownColor();
    01285
    01286     this->SetDirty();
    01287   }
    01288
    01289   virtual void OnQueryTextFinished(char *str)
    01290   {
    01291     if (!StrEmpty(str)) {
    01292       int32 value = atoi(str);
    01293
    01294       switch (this->widget_id) {
    01295         case CSCEN_START_DATE_TEXT:
    01296           this->SetWidgetDirty(CSCEN_START_DATE_TEXT);
    01297           _settings_newgame.game_creation.starting_year = Clamp(value, MIN_YEAR, MAX_YEAR);
    01298           break;
    01299
    01300         case CSCEN_FLAT_LAND_HEIGHT_TEXT:
    01301           this->SetWidgetDirty(CSCEN_FLAT_LAND_HEIGHT_TEXT);
    01302           _settings_newgame.game_creation.se_flat_world_height = Clamp(value, 0, GetMaxTileHeight());
    01303           break;
    01304       }
    01305
    01306       this->SetDirty();
    01307     }
    01308   }
    01309 };
    01310
    01311 static const NWidgetPart _nested_create_scenario_widgets[] = {
    01312   NWidget(NWID_HORIZONTAL),
    01313     NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
    01314     NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_SE_MAPGEN_CAPTION, STR_NULL),
    01315   EndContainer(),
    01316   NWidget(WWT_PANEL, COLOUR_BROWN),
    01317     NWidget(NWID_SPACER), SetMinimalSize(0, 10),
    01318     /* Landscape style selection. */
    01319     NWidget(NWID_HORIZONTAL), SetPIP(10, 3, 10),
    01320       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, CSCEN_TEMPERATE), SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
    01321       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, CSCEN_ARCTIC), SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
    01322       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, CSCEN_TROPICAL), SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
    01323       NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, CSCEN_TOYLAND), SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
    01324     EndContainer(),
    01325     NWidget(NWID_HORIZONTAL), SetPIP(10, 8, 10),
    01326       /* Green generation type buttons: 'Flat land' and 'Random land'. */
    01327       NWidget(NWID_VERTICAL), SetPIP(10, 6, 10),
    01328         NWidget(WWT_TEXTBTN, COLOUR_GREEN, CSCEN_EMPTY_WORLD), SetDataTip(STR_SE_MAPGEN_FLAT_WORLD, STR_SE_MAPGEN_FLAT_WORLD_TOOLTIP), SetFill(1, 1),
    01329         NWidget(WWT_TEXTBTN, COLOUR_GREEN, CSCEN_RANDOM_WORLD), SetDataTip(STR_SE_MAPGEN_RANDOM_LAND, STR_TERRAFORM_TOOLTIP_GENERATE_RANDOM_LAND), SetFill(1, 1),
    01330       EndContainer(),
    01331       /* Labels + setting drop-downs */
    01332       NWidget(NWID_VERTICAL), SetPIP(10, 6, 10),
    01333         /* Map size. */
    01334         NWidget(NWID_HORIZONTAL),
    01335           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAPSIZE, STR_NULL), SetPadding(1, 0, 0, 0),
    01336           NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
    01337           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, CSCEN_MAPSIZE_X_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetPadding(0, 4, 0, 0),
    01338           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BY, STR_NULL), SetPadding(1, 2, 0, 0),
    01339           NWidget(WWT_DROPDOWN, COLOUR_ORANGE, CSCEN_MAPSIZE_Y_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL),
    01340         EndContainer(),
    01341         /* Date. */
    01342         NWidget(NWID_HORIZONTAL),
    01343           NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetPadding(1, 0, 0, 0),
    01344           NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
    01345           NWidget(WWT_IMGBTN, COLOUR_ORANGE, CSCEN_START_DATE_DOWN), SetFill(0, 1), SetDataTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_BACKWARD),
    01346           NWidget(WWT_TEXTBTN, COLOUR_ORANGE, CSCEN_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL),
    01347           NWidget(WWT_IMGBTN, COLOUR_ORANGE, CSCEN_START_DATE_UP), SetFill(0, 1), SetDataTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_FORWARD),
    01348         EndContainer(),
    01349         /* Flat map height. */
    01350         NWidget(NWID_HORIZONTAL),
    01351           NWidget(WWT_TEXT, COLOUR_ORANGE),
    01352                         SetDataTip(STR_SE_MAPGEN_FLAT_WORLD_HEIGHT, STR_NULL), SetPadding(1, 0, 0, 0),
    01353           NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
    01354           NWidget(WWT_IMGBTN, COLOUR_ORANGE, CSCEN_FLAT_LAND_HEIGHT_DOWN), SetFill(0, 1), SetDataTip(SPR_ARROW_DOWN, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_DOWN),
    01355           NWidget(WWT_TEXTBTN, COLOUR_ORANGE, CSCEN_FLAT_LAND_HEIGHT_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL),
    01356           NWidget(WWT_IMGBTN, COLOUR_ORANGE, CSCEN_FLAT_LAND_HEIGHT_UP), SetFill(0, 1), SetDataTip(SPR_ARROW_UP, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_UP),
    01357         EndContainer(),
    01358       EndContainer(),
    01359     EndContainer(),
    01360   EndContainer(),
    01361 };
    01362
    01363 static const WindowDesc _create_scenario_desc(
    01364   WDP_CENTER, 0, 0,
    01365   WC_GENERATE_LANDSCAPE, WC_NONE,
    01366   WDF_UNCLICK_BUTTONS,
    01367   _nested_create_scenario_widgets, lengthof(_nested_create_scenario_widgets)
    01368 );
    01369
    01371 void ShowCreateScenario()
    01372 {
    01373   DeleteWindowByClass(WC_GENERATE_LANDSCAPE);
    01374   new CreateScenarioWindow(&_create_scenario_desc, GLWM_SCENARIO);
    01375 }
    01376
    01377 enum GenerationProgressWindowWidgets {
    01378   GPWW_PROGRESS_BAR,
    01379   GPWW_PROGRESS_TEXT,
    01380   GPWW_ABORT,
    01381 };
    01382
    01383 static const NWidgetPart _nested_generate_progress_widgets[] = {
    01384   NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GENERATION_WORLD, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
    01385   NWidget(WWT_PANEL, COLOUR_GREY),
    01386     NWidget(NWID_HORIZONTAL), SetPIP(20, 0, 20),
    01387       NWidget(NWID_VERTICAL), SetPIP(11, 8, 11),
    01388         NWidget(WWT_EMPTY, INVALID_COLOUR, GPWW_PROGRESS_BAR), SetFill(1, 0),
    01389         NWidget(WWT_EMPTY, INVALID_COLOUR, GPWW_PROGRESS_TEXT), SetFill(1, 0),
    01390         NWidget(WWT_TEXTBTN, COLOUR_WHITE, GPWW_ABORT), SetDataTip(STR_GENERATION_ABORT, STR_NULL), SetFill(1, 0),
    01391       EndContainer(),
    01392     EndContainer(),
    01393   EndContainer(),
    01394 };
    01395
    01396
    01397 static const WindowDesc _generate_progress_desc(
    01398   WDP_CENTER, 0, 0,
    01399   WC_GENERATE_PROGRESS_WINDOW, WC_NONE,
    01400   WDF_UNCLICK_BUTTONS,
    01401   _nested_generate_progress_widgets, lengthof(_nested_generate_progress_widgets)
    01402 );
    01403
    01404 struct GenWorldStatus {
    01405   uint percent;
    01406   StringID cls;
    01407   uint current;
    01408   uint total;
    01409   int timer;
    01410 };
    01411
    01412 static GenWorldStatus _gws;
    01413
    01414 static const StringID _generation_class_table[]  = {
    01415   STR_GENERATION_WORLD_GENERATION,
    01416   STR_SCENEDIT_TOOLBAR_LANDSCAPE_GENERATION,
    01417   STR_GENERATION_CLEARING_TILES,
    01418   STR_SCENEDIT_TOOLBAR_TOWN_GENERATION,
    01419   STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION,
    01420   STR_GENERATION_OBJECT_GENERATION,
    01421   STR_GENERATION_TREE_GENERATION,
    01422   STR_GENERATION_SETTINGUP_GAME,
    01423   STR_GENERATION_PREPARING_TILELOOP,
    01424   STR_GENERATION_PREPARING_GAME
    01425 };
    01426 assert_compile(lengthof(_generation_class_table) == GWP_CLASS_COUNT);
    01427
    01428
    01429 static void AbortGeneratingWorldCallback(Window *w, bool confirmed)
    01430 {
    01431   if (confirmed) {
    01432     AbortGeneratingWorld();
    01433   } else if (IsGeneratingWorld() && !IsGeneratingWorldAborted()) {
    01434     SetMouseCursor(SPR_CURSOR_ZZZ, PAL_NONE);
    01435   }
    01436 }
    01437
    01438 struct GenerateProgressWindow : public Window {
    01439
    01440   GenerateProgressWindow() : Window()
    01441   {
    01442     this->InitNested(&_generate_progress_desc);
    01443   }
    01444
    01445   virtual void OnClick(Point pt, int widget, int click_count)
    01446   {
    01447     switch (widget) {
    01448       case GPWW_ABORT:
    01449         if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE);
    01450         ShowQuery(
    01451           STR_GENERATION_ABORT_CAPTION,
    01452           STR_GENERATION_ABORT_MESSAGE,
    01453           this,
    01454           AbortGeneratingWorldCallback
    01455         );
    01456         break;
    01457     }
    01458   }
    01459
    01460   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
    01461   {
    01462     switch (widget) {
    01463       case GPWW_PROGRESS_BAR: {
    01464         SetDParam(0, 100);
    01465         *size = GetStringBoundingBox(STR_GENERATION_PROGRESS);
    01466         /* We need some spacing for the 'border' */
    01467         size->height += 8;
    01468         size->width += 8;
    01469         break;
    01470       }
    01471
    01472       case GPWW_PROGRESS_TEXT:
    01473         for (uint i = 0; i < GWP_CLASS_COUNT; i++) {
    01474           size->width = max(size->width, GetStringBoundingBox(_generation_class_table[i]).width);
    01475         }
    01476         size->height = FONT_HEIGHT_NORMAL * 2 + WD_PAR_VSEP_NORMAL;
    01477         break;
    01478     }
    01479   }
    01480
    01481   virtual void DrawWidget(const Rect &r, int widget) const
    01482   {
    01483     switch (widget) {
    01484       case GPWW_PROGRESS_BAR:
    01485         /* Draw the % complete with a bar and a text */
    01486         DrawFrameRect(r.left, r.top, r.right, r.bottom, COLOUR_GREY, FR_BORDERONLY);
    01487         DrawFrameRect(r.left + 1, r.top + 1, (int)((r.right - r.left - 2) * _gws.percent / 100) + r.left + 1, r.bottom - 1, COLOUR_MAUVE, FR_NONE);
    01488         SetDParam(0, _gws.percent);
    01489         DrawString(r.left, r.right, r.top + 5, STR_GENERATION_PROGRESS, TC_FROMSTRING, SA_HOR_CENTER);
    01490         break;
    01491
    01492       case GPWW_PROGRESS_TEXT:
    01493         /* Tell which class we are generating */
    01494         DrawString(r.left, r.right, r.top, _gws.cls, TC_FROMSTRING, SA_HOR_CENTER);
    01495
    01496         /* And say where we are in that class */
    01497         SetDParam(0, _gws.current);
    01498         SetDParam(1, _gws.total);
    01499         DrawString(r.left, r.right, r.top + FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL, STR_GENERATION_PROGRESS_NUM, TC_FROMSTRING, SA_HOR_CENTER);
    01500     }
    01501   }
    01502 };
    01503
    01507 void PrepareGenerateWorldProgress()
    01508 {
    01509   _gws.cls     = STR_GENERATION_WORLD_GENERATION;
    01510   _gws.current = 0;
    01511   _gws.total   = 0;
    01512   _gws.percent = 0;
    01513   _gws.timer   = 0; // Forces to paint the progress window immediately
    01514 }
    01515
    01519 void ShowGenerateWorldProgress()
    01520 {
    01521   if (BringWindowToFrontById(WC_GENERATE_PROGRESS_WINDOW, 0)) return;
    01522   new GenerateProgressWindow();
    01523 }
    01524
    01525 static void _SetGeneratingWorldProgress(GenWorldProgress cls, uint progress, uint total)
    01526 {
    01527   static const int percent_table[GWP_CLASS_COUNT + 1] = {0, 5, 15, 20, 40, 60, 65, 80, 85, 99, 100 };
    01528
    01529   assert(cls < GWP_CLASS_COUNT);
    01530
    01531   /* Do not run this function if we aren't in a thread */
    01532   if (!IsGenerateWorldThreaded() && !_network_dedicated) return;
    01533
    01534   if (IsGeneratingWorldAborted()) HandleGeneratingWorldAbortion();
    01535
    01536   if (total == 0) {
    01537     assert(_gws.cls == _generation_class_table[cls]);
    01538     _gws.current += progress;
    01539     assert(_gws.current <= _gws.total);
    01540   } else {
    01541     _gws.cls     = _generation_class_table[cls];
    01542     _gws.current = progress;
    01543     _gws.total   = total;
    01544     _gws.percent = percent_table[cls];
    01545   }
    01546
    01547   /* Don't update the screen too often. So update it once in every once in a while... */
    01548   if (!_network_dedicated && _gws.timer != 0 && _realtime_tick - _gws.timer < GENWORLD_REDRAW_TIMEOUT) return;
    01549
    01550   /* Percentage is about the number of completed tasks, so 'current - 1' */
    01551   _gws.percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (_gws.current == 0 ? 0 : _gws.current - 1) / _gws.total;
    01552
    01553   if (_network_dedicated) {
    01554     static uint last_percent = 0;
    01555
    01556     /* Never display 0% */
    01557     if (_gws.percent == 0) return;
    01558     /* Reset if percent is lower than the last recorded */
    01559     if (_gws.percent < last_percent) last_percent = 0;
    01560     /* Display every 5%, but 6% is also very valid.. just not smaller steps than 5% */
    01561     if (_gws.percent % 5 != 0 && _gws.percent <= last_percent + 5) return;
    01562     /* Never show steps smaller than 2%, even if it is a mod 5% */
    01563     if (_gws.percent <= last_percent + 2) return;
    01564
    01565     DEBUG(net, 1, "Map generation percentage complete: %d", _gws.percent);
    01566     last_percent = _gws.percent;
    01567
    01568     /* Don't continue as dedicated never has a thread running */
    01569     return;
    01570   }
    01571
    01572   SetWindowDirty(WC_GENERATE_PROGRESS_WINDOW, 0);
    01573   MarkWholeScreenDirty();
    01574
    01575   /* Release the rights to the map generator, and acquire the rights to the
    01576    * paint thread. The 'other' thread already has the paint thread rights so
    01577    * this ensures us that we are waiting until the paint thread is done
    01578    * before we reacquire the mapgen rights */
    01579   _genworld_mapgen_mutex->EndCritical();
    01580   _genworld_paint_mutex->BeginCritical();
    01581   _genworld_mapgen_mutex->BeginCritical();
    01582   _genworld_paint_mutex->EndCritical();
    01583
    01584   _gws.timer = _realtime_tick;
    01585 }
    01586
    01595 void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
    01596 {
    01597   if (total == 0) return;
    01598
    01599   _SetGeneratingWorldProgress(cls, 0, total);
    01600 }
    01601
    01609 void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
    01610 {
    01611   /* In fact the param 'class' isn't needed.. but for some security reasons, we want it around */
    01612   _SetGeneratingWorldProgress(cls, 1, 0);
    01613 }