OpenTTD
genworld_gui.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of OpenTTD.
3  * 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.
4  * 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.
5  * 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/>.
6  */
7 
10 #include "stdafx.h"
11 #include "heightmap.h"
12 #include "debug.h"
13 #include "genworld.h"
14 #include "network/network.h"
15 #include "strings_func.h"
16 #include "window_func.h"
17 #include "date_func.h"
18 #include "sound_func.h"
19 #include "fios.h"
20 #include "string_func.h"
21 #include "widgets/dropdown_type.h"
22 #include "widgets/dropdown_func.h"
23 #include "querystring_gui.h"
24 #include "town.h"
25 #include "core/geometry_func.hpp"
26 #include "core/random_func.hpp"
27 #include "saveload/saveload.h"
28 #include "progress.h"
29 #include "error.h"
30 
32 
33 #include "safeguards.h"
34 
35 
36 extern void MakeNewgameSettingsLive();
37 
43 };
44 
49 void SetNewLandscapeType(byte landscape)
50 {
54 }
55 
59  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
60  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MAPGEN_WORLD_GENERATION_CAPTION, STR_NULL),
61  EndContainer(),
62  NWidget(WWT_PANEL, COLOUR_BROWN),
64  /* Landscape selection. */
65  NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 10),
66  NWidget(NWID_SPACER), SetFill(1, 0),
67  NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TEMPERATE), SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
68  NWidget(NWID_SPACER), SetFill(1, 0),
69  NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_ARCTIC), SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
70  NWidget(NWID_SPACER), SetFill(1, 0),
71  NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TROPICAL), SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
72  NWidget(NWID_SPACER), SetFill(1, 0),
73  NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TOYLAND), SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
74  NWidget(NWID_SPACER), SetFill(1, 0),
75  EndContainer(),
77  NWidget(NWID_HORIZONTAL), SetPIP(10, 5, 10),
78  NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
79  /* Left column with labels. */
81  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAPSIZE, STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1),
82  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_LAND_GENERATOR, STR_NULL), SetFill(1, 1),
83  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_TOWNS, STR_NULL), SetFill(1, 1),
84  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TERRAIN_TYPE, STR_NULL), SetFill(1, 1),
85  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_VARIETY, STR_NULL), SetFill(1, 1),
86  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_QUANTITY_OF_SEA_LAKES, STR_NULL), SetFill(1, 1),
87  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TREE_PLACER, STR_NULL), SetFill(1, 1),
88  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BORDER_TYPE, STR_NULL), SetFill(1, 1),
89  EndContainer(),
90  /* Widgets at the right of the labels. */
92  /* Mapsize X * Y. */
93  NWidget(NWID_HORIZONTAL), SetPIP(0, 4, 0),
94  NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_MAPSIZE_X_PULLDOWN), SetDataTip(STR_JUST_INT, STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 0),
95  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BY, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(1, 1),
96  NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_MAPSIZE_Y_PULLDOWN), SetDataTip(STR_JUST_INT, STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 0),
97  EndContainer(),
98  NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_LANDSCAPE_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
99  NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TOWN_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
100  NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TERRAIN_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
101  NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_VARIETY_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
102  NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_WATER_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
103  NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TREE_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
104  NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_BORDERS_RANDOM), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
105  EndContainer(),
106  EndContainer(),
107  NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
108  NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
110  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAX_HEIGHTLEVEL, STR_NULL), SetFill(1, 1),
111  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SNOW_LINE_HEIGHT, STR_NULL), SetFill(1, 1),
112  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetFill(1, 1),
113  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_INDUSTRIES, STR_NULL), SetFill(1, 1),
114  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SMOOTHNESS, STR_NULL), SetFill(1, 1),
115  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_QUANTITY_OF_RIVERS, STR_NULL), SetFill(1, 1),
116  EndContainer(),
118  /* Max. heightlevel. */
120  NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_MAX_HEIGHTLEVEL_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_MAX_HEIGHTLEVEL_DOWN), SetFill(0, 1),
121  NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_MAX_HEIGHTLEVEL_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL), SetFill(1, 0),
122  NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_MAX_HEIGHTLEVEL_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_MAX_HEIGHTLEVEL_UP), SetFill(0, 1),
123  EndContainer(),
124  /* Snow line. */
126  NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_LEVEL_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_SNOW_LINE_DOWN), SetFill(0, 1),
127  NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_SNOW_LEVEL_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL), SetFill(1, 0),
128  NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_LEVEL_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_SNOW_LINE_UP), SetFill(0, 1),
129  EndContainer(),
130  /* Starting date. */
132  NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_START_DATE_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_BACKWARD), SetFill(0, 1),
133  NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL), SetFill(1, 0),
134  NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_START_DATE_UP), SetDataTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_FORWARD), SetFill(0, 1),
135  EndContainer(),
136  NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_INDUSTRY_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
137  NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_SMOOTHNESS_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
138  NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_RIVER_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
139  EndContainer(),
140  EndContainer(),
141  NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_GL_GENERATE_BUTTON), SetMinimalSize(84, 0), SetDataTip(STR_MAPGEN_GENERATE, STR_NULL), SetFill(1, 1),
142  EndContainer(),
143  EndContainer(),
145  /* Map borders buttons for each edge. */
147  NWidget(NWID_HORIZONTAL), SetPIP(0, 0, 3),
148  NWidget(NWID_SPACER), SetFill(1, 1),
149  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NORTHWEST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
150  EndContainer(),
151  NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_NW), SetDataTip(STR_JUST_STRING, STR_MAPGEN_NORTHWEST), SetFill(1, 1),
152  NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_NE), SetDataTip(STR_JUST_STRING, STR_MAPGEN_NORTHEAST), SetFill(1, 1),
153  NWidget(NWID_HORIZONTAL), SetPIP(3, 0, 0),
154  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NORTHEAST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
155  NWidget(NWID_SPACER), SetFill(1, 1),
156  EndContainer(),
157  EndContainer(),
159  NWidget(NWID_HORIZONTAL), SetPIP(0, 0, 3),
160  NWidget(NWID_SPACER), SetFill(1, 1),
161  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SOUTHWEST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
162  EndContainer(),
163  NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_SW), SetDataTip(STR_JUST_STRING, STR_MAPGEN_SOUTHWEST), SetFill(1, 1),
164  NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_SE), SetDataTip(STR_JUST_STRING, STR_MAPGEN_SOUTHEAST), SetFill(1, 1),
165  NWidget(NWID_HORIZONTAL), SetPIP(3, 0, 0),
166  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SOUTHEAST, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(0, 1),
167  NWidget(NWID_SPACER), SetFill(1, 1),
168  EndContainer(),
169  EndContainer(),
170  NWidget(NWID_SPACER), SetMinimalSize(0, 9), SetFill(1, 1),
171  EndContainer(),
172 };
173 
176  /* Window header. */
178  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
179  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_MAPGEN_WORLD_GENERATION_CAPTION, STR_NULL),
180  EndContainer(),
181  NWidget(WWT_PANEL, COLOUR_BROWN),
183  /* Landscape selection. */
184  NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 10),
185  NWidget(NWID_SPACER), SetFill(1, 0),
186  NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TEMPERATE), SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
187  NWidget(NWID_SPACER), SetFill(1, 0),
188  NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_ARCTIC), SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
189  NWidget(NWID_SPACER), SetFill(1, 0),
190  NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TROPICAL), SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
191  NWidget(NWID_SPACER), SetFill(1, 0),
192  NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TOYLAND), SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
193  NWidget(NWID_SPACER), SetFill(1, 0),
194  EndContainer(),
195  NWidget(NWID_SPACER), SetMinimalSize(0, 11), SetFill(0, 1),
196  NWidget(NWID_HORIZONTAL), SetPIP(10, 3, 10),
197  /* Labels at the left side. */
199  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_HEIGHTMAP_NAME, STR_NULL), SetFill(1, 1),
200  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAPSIZE, STR_NULL), SetFill(1, 1),
201  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_HEIGHTMAP_ROTATION, STR_NULL), SetFill(1, 1),
202  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_TOWNS, STR_NULL), SetFill(1, 1),
203  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_NUMBER_OF_INDUSTRIES, STR_NULL), SetFill(1, 1),
204  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_QUANTITY_OF_RIVERS, STR_NULL), SetFill(1, 1),
205  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_TREE_PLACER, STR_NULL), SetFill(1, 1),
206  EndContainer(),
207  /* Widgets at the right of the labels. */
208  NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
209  NWidget(WWT_EMPTY, COLOUR_ORANGE, WID_GL_HEIGHTMAP_NAME_TEXT), SetFill(1, 0),
210  NWidget(NWID_HORIZONTAL), SetPIP(0, 5, 0),
212  /* Mapsize X * Y. */
213  NWidget(NWID_HORIZONTAL), SetPIP(0, 4, 0),
214  NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_MAPSIZE_X_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetFill(1, 0),
215  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BY, STR_NULL), SetPadding(1, 0, 0, 0), SetFill(1, 1),
216  NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_MAPSIZE_Y_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetFill(1, 0),
217  EndContainer(),
218  NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_HEIGHTMAP_ROTATION_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
219  NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TOWN_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
220  NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_INDUSTRY_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
221  NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_RIVER_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
222  NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TREE_PULLDOWN), SetDataTip(STR_JUST_STRING, STR_NULL), SetFill(1, 0),
223  EndContainer(),
224  NWidget(NWID_VERTICAL), SetPIP(0, 4, 0),
225  NWidget(NWID_HORIZONTAL), SetPIP(0, 3, 0),
227  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_HEIGHTMAP_SIZE_LABEL, STR_NULL), SetFill(1, 1),
228  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_SNOW_LINE_HEIGHT, STR_NULL), SetFill(1, 1),
229  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAX_HEIGHTLEVEL, STR_NULL), SetFill(1, 1),
230  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetFill(1, 1),
231  EndContainer(),
233  NWidget(WWT_TEXT, COLOUR_ORANGE, WID_GL_HEIGHTMAP_SIZE_TEXT), SetDataTip(STR_MAPGEN_HEIGHTMAP_SIZE, STR_NULL), SetFill(1, 0),
235  NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_LEVEL_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_SNOW_LINE_DOWN), SetFill(0, 1),
236  NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_SNOW_LEVEL_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL), SetFill(1, 0),
237  NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_LEVEL_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_SNOW_LINE_UP), SetFill(0, 1),
238  EndContainer(),
240  NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_MAX_HEIGHTLEVEL_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_MAPGEN_MAX_HEIGHTLEVEL_DOWN), SetFill(0, 1),
241  NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_MAX_HEIGHTLEVEL_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL), SetFill(1, 0),
242  NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_MAX_HEIGHTLEVEL_UP), SetDataTip(SPR_ARROW_UP, STR_MAPGEN_MAX_HEIGHTLEVEL_UP), SetFill(0, 1),
243  EndContainer(),
245  NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_START_DATE_DOWN), SetDataTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_BACKWARD), SetFill(0, 1),
246  NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL), SetFill(1, 0),
247  NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_START_DATE_UP), SetDataTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_FORWARD), SetFill(0, 1),
248  EndContainer(),
249  EndContainer(),
250  EndContainer(),
251  NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_GL_GENERATE_BUTTON), SetMinimalSize(84, 0), SetDataTip(STR_MAPGEN_GENERATE, STR_NULL), SetFill(1, 1),
252  EndContainer(),
253  EndContainer(),
254  EndContainer(),
255  EndContainer(),
256  NWidget(NWID_SPACER), SetMinimalSize(0, 9), SetFill(1, 1),
257  EndContainer(),
258 };
259 
260 static void StartGeneratingLandscape(GenerateLandscapeWindowMode mode)
261 {
264 
265  /* Copy all XXX_newgame to XXX when coming from outside the editor */
266  MakeNewgameSettingsLive();
267  ResetGRFConfig(true);
268 
269  if (_settings_client.sound.confirm) SndPlayFx(SND_15_BEEP);
270  switch (mode) {
271  case GLWM_GENERATE: _switch_mode = (_game_mode == GM_EDITOR) ? SM_GENRANDLAND : SM_NEWGAME; break;
272  case GLWM_HEIGHTMAP: _switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_HEIGHTMAP : SM_START_HEIGHTMAP; break;
273  case GLWM_SCENARIO: _switch_mode = SM_EDITOR; break;
274  default: NOT_REACHED();
275  }
276 }
277 
278 static void LandscapeGenerationCallback(Window *w, bool confirmed)
279 {
280  if (confirmed) StartGeneratingLandscape((GenerateLandscapeWindowMode)w->window_number);
281 }
282 
283 static DropDownList BuildMapsizeDropDown()
284 {
285  DropDownList list;
286 
287  for (uint i = MIN_MAP_SIZE_BITS; i <= MAX_MAP_SIZE_BITS; i++) {
288  DropDownListParamStringItem *item = new DropDownListParamStringItem(STR_JUST_INT, i, false);
289  item->SetParam(0, 1LL << i);
290  list.emplace_back(item);
291  }
292 
293  return list;
294 }
295 
296 static const StringID _elevations[] = {STR_TERRAIN_TYPE_VERY_FLAT, STR_TERRAIN_TYPE_FLAT, STR_TERRAIN_TYPE_HILLY, STR_TERRAIN_TYPE_MOUNTAINOUS, STR_TERRAIN_TYPE_ALPINIST, INVALID_STRING_ID};
297 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};
298 static const StringID _rivers[] = {STR_RIVERS_NONE, STR_RIVERS_FEW, STR_RIVERS_MODERATE, STR_RIVERS_LOT, INVALID_STRING_ID};
299 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, INVALID_STRING_ID};
300 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};
301 static const StringID _rotation[] = {STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE, STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_CLOCKWISE, INVALID_STRING_ID};
302 static const StringID _landscape[] = {STR_CONFIG_SETTING_LAND_GENERATOR_ORIGINAL, STR_CONFIG_SETTING_LAND_GENERATOR_TERRA_GENESIS, INVALID_STRING_ID};
303 static const StringID _num_towns[] = {STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM, INVALID_STRING_ID};
304 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};
305 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};
306 
307 assert_compile(lengthof(_num_inds) == ID_END + 1);
308 
310  uint widget_id;
311  uint x;
312  uint y;
313  char name[64];
315 
316  GenerateLandscapeWindow(WindowDesc *desc, WindowNumber number = 0) : Window(desc)
317  {
318  this->InitNested(number);
319 
321 
322  this->mode = (GenerateLandscapeWindowMode)this->window_number;
323 
324  /* Disable town, industry and trees in SE */
325  this->SetWidgetDisabledState(WID_GL_TOWN_PULLDOWN, _game_mode == GM_EDITOR);
326  this->SetWidgetDisabledState(WID_GL_INDUSTRY_PULLDOWN, _game_mode == GM_EDITOR);
327  this->SetWidgetDisabledState(WID_GL_TREE_PULLDOWN, _game_mode == GM_EDITOR);
328 
329  this->OnInvalidateData();
330  }
331 
332 
333  void SetStringParameters(int widget) const override
334  {
335  switch (widget) {
341 
343  if (_game_mode == GM_EDITOR) {
344  SetDParam(0, STR_CONFIG_SETTING_OFF);
346  SetDParam(0, STR_NUM_CUSTOM_NUMBER);
348  } else {
350  }
351  break;
352 
353  case WID_GL_INDUSTRY_PULLDOWN: SetDParam(0, _game_mode == GM_EDITOR ? STR_CONFIG_SETTING_OFF : _num_inds[_settings_newgame.difficulty.industry_density]); break;
357 
360  SetDParam(0, STR_SEA_LEVEL_CUSTOM_PERCENTAGE);
362  } else {
364  }
365  break;
366 
370  case WID_GL_BORDERS_RANDOM: SetDParam(0, (_settings_newgame.game_creation.water_borders == BORDERS_RANDOM) ? STR_MAPGEN_BORDER_RANDOMIZE : STR_MAPGEN_BORDER_MANUAL); break;
371  case WID_GL_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;
372  case WID_GL_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;
373  case WID_GL_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;
374  case WID_GL_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;
376 
379  SetDParam(0, this->y);
380  SetDParam(1, this->x);
381  } else {
382  SetDParam(0, this->x);
383  SetDParam(1, this->y);
384  }
385  break;
386  }
387  }
388 
394  void OnInvalidateData(int data = 0, bool gui_scope = true) override
395  {
396  if (!gui_scope) return;
397  /* Update the climate buttons */
402 
403  /* You can't select smoothness / non-water borders if not terragenesis */
404  if (mode == GLWM_GENERATE) {
410 
412 
417 
420  }
421 
422  /* Disable snowline if not arctic */
424 
425  /* Update availability of decreasing / increasing start date and snow level */
432 
433  /* Do not allow a custom sea level with the original land generator. */
437  }
438 
439  }
440 
441  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
442  {
443  const StringID *strs = nullptr;
444  switch (widget) {
447  *size = GetStringBoundingBox(STR_JUST_INT);
448  break;
449 
452  *size = maxdim(*size, GetStringBoundingBox(STR_BLACK_DATE_LONG));
453  break;
454 
458  *size = maxdim(*size, GetStringBoundingBox(STR_JUST_INT));
459  break;
460 
463  *size = maxdim(*size, GetStringBoundingBox(STR_JUST_INT));
464  break;
465 
467  SetDParam(0, this->x);
468  SetDParam(1, this->y);
469  *size = maxdim(*size, GetStringBoundingBox(STR_MAPGEN_HEIGHTMAP_SIZE));
470  break;
471 
473  strs = _num_towns;
475  *size = maxdim(*size, GetStringBoundingBox(STR_NUM_CUSTOM_NUMBER));
476  break;
477 
478  case WID_GL_INDUSTRY_PULLDOWN: strs = _num_inds; break;
479  case WID_GL_LANDSCAPE_PULLDOWN: strs = _landscape; break;
480  case WID_GL_TREE_PULLDOWN: strs = _tree_placer; break;
481  case WID_GL_TERRAIN_PULLDOWN: strs = _elevations; break;
483  strs = _sea_lakes;
485  *size = maxdim(*size, GetStringBoundingBox(STR_SEA_LEVEL_CUSTOM_PERCENTAGE));
486  break;
487 
488  case WID_GL_RIVER_PULLDOWN: strs = _rivers; break;
489  case WID_GL_SMOOTHNESS_PULLDOWN: strs = _smoothness; break;
490  case WID_GL_VARIETY_PULLDOWN: strs = _variety; break;
491  case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: strs = _rotation; break;
493  *size = maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_RANDOMIZE), GetStringBoundingBox(STR_MAPGEN_BORDER_MANUAL));
494  break;
495 
496  case WID_GL_WATER_NE:
497  case WID_GL_WATER_NW:
498  case WID_GL_WATER_SE:
499  case WID_GL_WATER_SW:
500  *size = maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_RANDOM), maxdim(GetStringBoundingBox(STR_MAPGEN_BORDER_WATER), GetStringBoundingBox(STR_MAPGEN_BORDER_FREEFORM)));
501  break;
502 
504  size->width = 0;
505  break;
506 
507  default:
508  return;
509  }
510  if (strs != nullptr) {
511  while (*strs != INVALID_STRING_ID) {
512  *size = maxdim(*size, GetStringBoundingBox(*strs++));
513  }
514  }
515  size->width += padding.width;
516  size->height = max(size->height, (uint)(FONT_HEIGHT_NORMAL + WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM));
517  }
518 
519  void DrawWidget(const Rect &r, int widget) const override
520  {
521  switch (widget) {
523  DrawString(r.left, r.right, r.top, this->name, TC_ORANGE);
524  break;
525  }
526  }
527  }
528 
529  void OnClick(Point pt, int widget, int click_count) override
530  {
531  switch (widget) {
532  case WID_GL_TEMPERATE:
533  case WID_GL_ARCTIC:
534  case WID_GL_TROPICAL:
535  case WID_GL_TOYLAND:
537  break;
538 
539  case WID_GL_MAPSIZE_X_PULLDOWN: // Mapsize X
541  break;
542 
543  case WID_GL_MAPSIZE_Y_PULLDOWN: // Mapsize Y
545  break;
546 
547  case WID_GL_TOWN_PULLDOWN: // Number of towns
549  break;
550 
551  case WID_GL_INDUSTRY_PULLDOWN: // Number of industries
553  break;
554 
555  case WID_GL_GENERATE_BUTTON: { // Generate
556  /* Get rotated map size. */
557  uint map_x;
558  uint map_y;
560  map_x = this->y;
561  map_y = this->x;
562  } else {
563  map_x = this->x;
564  map_y = this->y;
565  }
566  if (mode == GLWM_HEIGHTMAP &&
567  (map_x * 2 < (1U << _settings_newgame.game_creation.map_x) ||
568  map_x / 2 > (1U << _settings_newgame.game_creation.map_x) ||
569  map_y * 2 < (1U << _settings_newgame.game_creation.map_y) ||
570  map_y / 2 > (1U << _settings_newgame.game_creation.map_y))) {
571  ShowQuery(
572  STR_WARNING_HEIGHTMAP_SCALE_CAPTION,
573  STR_WARNING_HEIGHTMAP_SCALE_MESSAGE,
574  this,
575  LandscapeGenerationCallback);
576  } else {
577  StartGeneratingLandscape(mode);
578  }
579  break;
580  }
581 
583  case WID_GL_MAX_HEIGHTLEVEL_UP: // Height level buttons
584  /* Don't allow too fast scrolling */
585  if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
586  this->HandleButtonClick(widget);
587 
589  this->InvalidateData();
590  }
591  _left_button_clicked = false;
592  break;
593 
594  case WID_GL_MAX_HEIGHTLEVEL_TEXT: // Height level text
595  this->widget_id = WID_GL_MAX_HEIGHTLEVEL_TEXT;
597  ShowQueryString(STR_JUST_INT, STR_MAPGEN_MAX_HEIGHTLEVEL_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
598  break;
599 
600 
602  case WID_GL_START_DATE_UP: // Year buttons
603  /* Don't allow too fast scrolling */
604  if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
605  this->HandleButtonClick(widget);
606 
608  this->InvalidateData();
609  }
610  _left_button_clicked = false;
611  break;
612 
613  case WID_GL_START_DATE_TEXT: // Year text
614  this->widget_id = WID_GL_START_DATE_TEXT;
616  ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
617  break;
618 
620  case WID_GL_SNOW_LEVEL_UP: // Snow line buttons
621  /* Don't allow too fast scrolling */
622  if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
623  this->HandleButtonClick(widget);
624 
626  this->InvalidateData();
627  }
628  _left_button_clicked = false;
629  break;
630 
631  case WID_GL_SNOW_LEVEL_TEXT: // Snow line text
632  this->widget_id = WID_GL_SNOW_LEVEL_TEXT;
634  ShowQueryString(STR_JUST_INT, STR_MAPGEN_SNOW_LINE_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
635  break;
636 
637  case WID_GL_TREE_PULLDOWN: // Tree placer
639  break;
640 
641  case WID_GL_LANDSCAPE_PULLDOWN: // Landscape generator
643  break;
644 
645  case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: // Heightmap rotation
647  break;
648 
649  case WID_GL_TERRAIN_PULLDOWN: // Terrain type
650  /* For the original map generation only the first four are valid. */
652  break;
653 
654  case WID_GL_WATER_PULLDOWN: { // Water quantity
655  uint32 hidden_mask = 0;
656  /* Disable custom water level when the original map generator is active. */
659  }
661  break;
662  }
663 
664  case WID_GL_RIVER_PULLDOWN: // Amount of rivers
666  break;
667 
668  case WID_GL_SMOOTHNESS_PULLDOWN: // Map smoothness
670  break;
671 
672  case WID_GL_VARIETY_PULLDOWN: // Map variety
674  break;
675 
676  /* Freetype map borders */
677  case WID_GL_WATER_NW:
679  this->InvalidateData();
680  break;
681 
682  case WID_GL_WATER_NE:
684  this->InvalidateData();
685  break;
686 
687  case WID_GL_WATER_SE:
689  this->InvalidateData();
690  break;
691 
692  case WID_GL_WATER_SW:
694  this->InvalidateData();
695  break;
696 
699  this->InvalidateData();
700  break;
701  }
702  }
703 
704  void OnTimeout() override
705  {
707  for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
708  if (this->IsWidgetLowered(*widget)) {
709  this->RaiseWidget(*widget);
710  this->SetWidgetDirty(*widget);
711  }
712  }
713  }
714 
715  void OnDropdownSelect(int widget, int index) override
716  {
717  switch (widget) {
724 
726  /* If original landgenerator is selected and alpinist terrain_type was selected, revert to mountainous. */
729  }
730  break;
731 
733 
735  if ((uint)index == CUSTOM_TOWN_NUMBER_DIFFICULTY) {
736  this->widget_id = widget;
738  ShowQueryString(STR_JUST_INT, STR_MAPGEN_NUMBER_OF_TOWNS, 5, this, CS_NUMERAL, QSF_NONE);
739  }
741  break;
742 
745 
746  case WID_GL_WATER_PULLDOWN: {
747  if ((uint)index == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
748  this->widget_id = widget;
750  ShowQueryString(STR_JUST_INT, STR_MAPGEN_QUANTITY_OF_SEA_LAKES, 3, this, CS_NUMERAL, QSF_NONE);
751  }
753  break;
754  }
755  }
756  this->InvalidateData();
757  }
758 
759  void OnQueryTextFinished(char *str) override
760  {
761  /* Was 'cancel' pressed? */
762  if (str == nullptr) return;
763 
764  int32 value;
765  if (!StrEmpty(str)) {
766  value = atoi(str);
767  } else {
768  /* An empty string means revert to the default */
769  switch (this->widget_id) {
771  case WID_GL_START_DATE_TEXT: value = DEF_START_YEAR; break;
772  case WID_GL_SNOW_LEVEL_TEXT: value = DEF_SNOWLINE_HEIGHT; break;
773  case WID_GL_TOWN_PULLDOWN: value = 1; break;
775  default: NOT_REACHED();
776  }
777  }
778 
779  switch (this->widget_id) {
783  break;
784 
788  break;
789 
793  break;
794 
797  break;
798 
801  break;
802  }
803 
804  this->InvalidateData();
805  }
806 };
807 
808 static WindowDesc _generate_landscape_desc(
809  WDP_CENTER, nullptr, 0, 0,
811  0,
812  _nested_generate_landscape_widgets, lengthof(_nested_generate_landscape_widgets)
813 );
814 
815 static WindowDesc _heightmap_load_desc(
816  WDP_CENTER, nullptr, 0, 0,
818  0,
819  _nested_heightmap_load_widgets, lengthof(_nested_heightmap_load_widgets)
820 );
821 
822 static void _ShowGenerateLandscape(GenerateLandscapeWindowMode mode)
823 {
824  uint x = 0;
825  uint y = 0;
826 
828 
829  /* Generate a new seed when opening the window */
830  _settings_newgame.game_creation.generation_seed = InteractiveRandom();
831 
832  if (mode == GLWM_HEIGHTMAP) {
833  /* If the function returns negative, it means there was a problem loading the heightmap */
835  }
836 
837  WindowDesc *desc = (mode == GLWM_HEIGHTMAP) ? &_heightmap_load_desc : &_generate_landscape_desc;
838  GenerateLandscapeWindow *w = AllocateWindowDescFront<GenerateLandscapeWindow>(desc, mode, true);
839 
840  if (mode == GLWM_HEIGHTMAP) {
841  w->x = x;
842  w->y = y;
843  strecpy(w->name, _file_to_saveload.title, lastof(w->name));
844  }
845 
847 }
848 
851 {
852  _ShowGenerateLandscape(GLWM_GENERATE);
853 }
854 
857 {
858  _ShowGenerateLandscape(GLWM_HEIGHTMAP);
859 }
860 
863 {
864  StartGeneratingLandscape(GLWM_SCENARIO);
865 }
866 
871 void StartNewGameWithoutGUI(uint32 seed)
872 {
873  /* GenerateWorld takes care of the possible GENERATE_NEW_SEED value in 'seed' */
875 
876  StartGeneratingLandscape(GLWM_GENERATE);
877 }
878 
880 {
881  uint widget_id;
882 
884  {
885  this->InitNested(window_number);
887  }
888 
889  void SetStringParameters(int widget) const override
890  {
891  switch (widget) {
894  break;
895 
898  break;
899 
902  break;
903 
906  break;
907  }
908  }
909 
910  void OnPaint() override
911  {
916 
921 
922  this->DrawWidgets();
923  }
924 
925  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
926  {
927  StringID str = STR_JUST_INT;
928  switch (widget) {
931  str = STR_BLACK_DATE_LONG;
932  break;
933 
937  break;
938 
941  break;
942 
943  default:
944  return;
945  }
946  *size = maxdim(*size, GetStringBoundingBox(str));
947  size->width += padding.width;
948  size->height += padding.height;
949  }
950 
951  void OnClick(Point pt, int widget, int click_count) override
952  {
953  switch (widget) {
954  case WID_CS_TEMPERATE:
955  case WID_CS_ARCTIC:
956  case WID_CS_TROPICAL:
957  case WID_CS_TOYLAND:
960  break;
961 
962  case WID_CS_MAPSIZE_X_PULLDOWN: // Mapsize X
964  break;
965 
966  case WID_CS_MAPSIZE_Y_PULLDOWN: // Mapsize Y
968  break;
969 
970  case WID_CS_EMPTY_WORLD: // Empty world / flat world
971  StartGeneratingLandscape(GLWM_SCENARIO);
972  break;
973 
974  case WID_CS_RANDOM_WORLD: // Generate
976  break;
977 
979  case WID_CS_START_DATE_UP: // Year buttons
980  /* Don't allow too fast scrolling */
981  if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
982  this->HandleButtonClick(widget);
983  this->SetDirty();
984 
986  }
987  _left_button_clicked = false;
988  break;
989 
990  case WID_CS_START_DATE_TEXT: // Year text
991  this->widget_id = WID_CS_START_DATE_TEXT;
993  ShowQueryString(STR_JUST_INT, STR_MAPGEN_START_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QSF_NONE);
994  break;
995 
997  case WID_CS_FLAT_LAND_HEIGHT_UP: // Height level buttons
998  /* Don't allow too fast scrolling */
999  if (!(this->flags & WF_TIMEOUT) || this->timeout_timer <= 1) {
1000  this->HandleButtonClick(widget);
1001  this->SetDirty();
1002 
1004  }
1005  _left_button_clicked = false;
1006  break;
1007 
1008  case WID_CS_FLAT_LAND_HEIGHT_TEXT: // Height level text
1009  this->widget_id = WID_CS_FLAT_LAND_HEIGHT_TEXT;
1011  ShowQueryString(STR_JUST_INT, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_QUERY_CAPT, 4, this, CS_NUMERAL, QSF_NONE);
1012  break;
1013  }
1014  }
1015 
1016  void OnTimeout() override
1017  {
1019  for (const int *widget = raise_widgets; *widget != WIDGET_LIST_END; widget++) {
1020  if (this->IsWidgetLowered(*widget)) {
1021  this->RaiseWidget(*widget);
1022  this->SetWidgetDirty(*widget);
1023  }
1024  }
1025  }
1026 
1027  void OnDropdownSelect(int widget, int index) override
1028  {
1029  switch (widget) {
1032  }
1033  this->SetDirty();
1034  }
1035 
1036  void OnQueryTextFinished(char *str) override
1037  {
1038  if (!StrEmpty(str)) {
1039  int32 value = atoi(str);
1040 
1041  switch (this->widget_id) {
1045  break;
1046 
1050  break;
1051  }
1052 
1053  this->SetDirty();
1054  }
1055  }
1056 };
1057 
1058 static const NWidgetPart _nested_create_scenario_widgets[] = {
1060  NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1061  NWidget(WWT_CAPTION, COLOUR_BROWN), SetDataTip(STR_SE_MAPGEN_CAPTION, STR_NULL),
1062  EndContainer(),
1063  NWidget(WWT_PANEL, COLOUR_BROWN),
1065  /* Landscape style selection. */
1066  NWidget(NWID_HORIZONTAL), SetPIP(10, 3, 10),
1067  NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_TEMPERATE), SetDataTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
1068  NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_ARCTIC), SetDataTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
1069  NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_TROPICAL), SetDataTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
1070  NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_TOYLAND), SetDataTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
1071  EndContainer(),
1072  NWidget(NWID_HORIZONTAL), SetPIP(10, 8, 10),
1073  /* Green generation type buttons: 'Flat land' and 'Random land'. */
1074  NWidget(NWID_VERTICAL), SetPIP(10, 6, 10),
1075  NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_CS_EMPTY_WORLD), SetDataTip(STR_SE_MAPGEN_FLAT_WORLD, STR_SE_MAPGEN_FLAT_WORLD_TOOLTIP), SetFill(1, 1),
1076  NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_CS_RANDOM_WORLD), SetDataTip(STR_SE_MAPGEN_RANDOM_LAND, STR_TERRAFORM_TOOLTIP_GENERATE_RANDOM_LAND), SetFill(1, 1),
1077  EndContainer(),
1078  /* Labels + setting drop-downs */
1079  NWidget(NWID_VERTICAL), SetPIP(10, 6, 10),
1080  /* Map size. */
1082  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_MAPSIZE, STR_NULL), SetPadding(1, 0, 0, 0),
1083  NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
1084  NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_CS_MAPSIZE_X_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL), SetPadding(0, 4, 0, 0),
1085  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_BY, STR_NULL), SetPadding(1, 2, 0, 0),
1086  NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_CS_MAPSIZE_Y_PULLDOWN), SetDataTip(STR_JUST_INT, STR_NULL),
1087  EndContainer(),
1088  /* Date. */
1090  NWidget(WWT_TEXT, COLOUR_ORANGE), SetDataTip(STR_MAPGEN_DATE, STR_NULL), SetPadding(1, 0, 0, 0),
1091  NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
1092  NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_CS_START_DATE_DOWN), SetFill(0, 1), SetDataTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_BACKWARD),
1093  NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_CS_START_DATE_TEXT), SetDataTip(STR_BLACK_DATE_LONG, STR_NULL),
1094  NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_CS_START_DATE_UP), SetFill(0, 1), SetDataTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_TOOLTIP_MOVE_THE_STARTING_DATE_FORWARD),
1095  EndContainer(),
1096  /* Flat map height. */
1098  NWidget(WWT_TEXT, COLOUR_ORANGE),
1099  SetDataTip(STR_SE_MAPGEN_FLAT_WORLD_HEIGHT, STR_NULL), SetPadding(1, 0, 0, 0),
1100  NWidget(NWID_SPACER), SetMinimalSize(6, 0), SetFill(1, 0),
1101  NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_CS_FLAT_LAND_HEIGHT_DOWN), SetFill(0, 1), SetDataTip(SPR_ARROW_DOWN, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_DOWN),
1102  NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_CS_FLAT_LAND_HEIGHT_TEXT), SetDataTip(STR_BLACK_INT, STR_NULL),
1103  NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_CS_FLAT_LAND_HEIGHT_UP), SetFill(0, 1), SetDataTip(SPR_ARROW_UP, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_UP),
1104  EndContainer(),
1105  EndContainer(),
1106  EndContainer(),
1107  EndContainer(),
1108 };
1109 
1110 static WindowDesc _create_scenario_desc(
1111  WDP_CENTER, nullptr, 0, 0,
1113  0,
1114  _nested_create_scenario_widgets, lengthof(_nested_create_scenario_widgets)
1115 );
1116 
1119 {
1121  new CreateScenarioWindow(&_create_scenario_desc, GLWM_SCENARIO);
1122 }
1123 
1124 static const NWidgetPart _nested_generate_progress_widgets[] = {
1125  NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GENERATION_WORLD, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1126  NWidget(WWT_PANEL, COLOUR_GREY),
1127  NWidget(NWID_HORIZONTAL), SetPIP(20, 0, 20),
1128  NWidget(NWID_VERTICAL), SetPIP(11, 8, 11),
1129  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GP_PROGRESS_BAR), SetFill(1, 0),
1130  NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GP_PROGRESS_TEXT), SetFill(1, 0),
1131  NWidget(WWT_TEXTBTN, COLOUR_WHITE, WID_GP_ABORT), SetDataTip(STR_GENERATION_ABORT, STR_NULL), SetFill(1, 0),
1132  EndContainer(),
1133  EndContainer(),
1134  EndContainer(),
1135 };
1136 
1137 
1138 static WindowDesc _generate_progress_desc(
1139  WDP_CENTER, nullptr, 0, 0,
1141  0,
1142  _nested_generate_progress_widgets, lengthof(_nested_generate_progress_widgets)
1143 );
1144 
1146  uint percent;
1147  StringID cls;
1148  uint current;
1149  uint total;
1150  int timer;
1151 };
1152 
1153 static GenWorldStatus _gws;
1154 
1155 static const StringID _generation_class_table[] = {
1156  STR_GENERATION_WORLD_GENERATION,
1157  STR_SCENEDIT_TOOLBAR_LANDSCAPE_GENERATION,
1158  STR_GENERATION_RIVER_GENERATION,
1159  STR_GENERATION_CLEARING_TILES,
1160  STR_SCENEDIT_TOOLBAR_TOWN_GENERATION,
1161  STR_SCENEDIT_TOOLBAR_INDUSTRY_GENERATION,
1162  STR_GENERATION_OBJECT_GENERATION,
1163  STR_GENERATION_TREE_GENERATION,
1164  STR_GENERATION_SETTINGUP_GAME,
1165  STR_GENERATION_PREPARING_TILELOOP,
1166  STR_GENERATION_PREPARING_SCRIPT,
1167  STR_GENERATION_PREPARING_GAME
1168 };
1169 assert_compile(lengthof(_generation_class_table) == GWP_CLASS_COUNT);
1170 
1171 
1172 static void AbortGeneratingWorldCallback(Window *w, bool confirmed)
1173 {
1174  if (confirmed) {
1176  } else if (HasModalProgress() && !IsGeneratingWorldAborted()) {
1177  SetMouseCursor(SPR_CURSOR_ZZZ, PAL_NONE);
1178  }
1179 }
1180 
1182 
1183  GenerateProgressWindow() : Window(&_generate_progress_desc)
1184  {
1185  this->InitNested();
1186  }
1187 
1188  void OnClick(Point pt, int widget, int click_count) override
1189  {
1190  switch (widget) {
1191  case WID_GP_ABORT:
1192  SetMouseCursorBusy(false);
1193  ShowQuery(
1194  STR_GENERATION_ABORT_CAPTION,
1195  STR_GENERATION_ABORT_MESSAGE,
1196  this,
1197  AbortGeneratingWorldCallback
1198  );
1199  break;
1200  }
1201  }
1202 
1203  void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1204  {
1205  switch (widget) {
1206  case WID_GP_PROGRESS_BAR: {
1207  SetDParamMaxValue(0, 100);
1208  *size = GetStringBoundingBox(STR_GENERATION_PROGRESS);
1209  /* We need some spacing for the 'border' */
1210  size->height += 8;
1211  size->width += 8;
1212  break;
1213  }
1214 
1215  case WID_GP_PROGRESS_TEXT:
1216  for (uint i = 0; i < GWP_CLASS_COUNT; i++) {
1217  size->width = max(size->width, GetStringBoundingBox(_generation_class_table[i]).width);
1218  }
1219  size->height = FONT_HEIGHT_NORMAL * 2 + WD_PAR_VSEP_NORMAL;
1220  break;
1221  }
1222  }
1223 
1224  void DrawWidget(const Rect &r, int widget) const override
1225  {
1226  switch (widget) {
1227  case WID_GP_PROGRESS_BAR:
1228  /* Draw the % complete with a bar and a text */
1229  DrawFrameRect(r.left, r.top, r.right, r.bottom, COLOUR_GREY, FR_BORDERONLY);
1230  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);
1231  SetDParam(0, _gws.percent);
1232  DrawString(r.left, r.right, r.top + 5, STR_GENERATION_PROGRESS, TC_FROMSTRING, SA_HOR_CENTER);
1233  break;
1234 
1235  case WID_GP_PROGRESS_TEXT:
1236  /* Tell which class we are generating */
1237  DrawString(r.left, r.right, r.top, _gws.cls, TC_FROMSTRING, SA_HOR_CENTER);
1238 
1239  /* And say where we are in that class */
1240  SetDParam(0, _gws.current);
1241  SetDParam(1, _gws.total);
1242  DrawString(r.left, r.right, r.top + FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL, STR_GENERATION_PROGRESS_NUM, TC_FROMSTRING, SA_HOR_CENTER);
1243  }
1244  }
1245 };
1246 
1251 {
1252  _gws.cls = STR_GENERATION_WORLD_GENERATION;
1253  _gws.current = 0;
1254  _gws.total = 0;
1255  _gws.percent = 0;
1256  _gws.timer = 0; // Forces to paint the progress window immediately
1257 }
1258 
1263 {
1264  if (BringWindowToFrontById(WC_MODAL_PROGRESS, 0)) return;
1265  new GenerateProgressWindow();
1266 }
1267 
1268 static void _SetGeneratingWorldProgress(GenWorldProgress cls, uint progress, uint total)
1269 {
1270  static const int percent_table[] = {0, 5, 14, 17, 20, 40, 60, 65, 80, 85, 95, 99, 100 };
1271  assert_compile(lengthof(percent_table) == GWP_CLASS_COUNT + 1);
1272  assert(cls < GWP_CLASS_COUNT);
1273 
1274  /* Do not run this function if we aren't in a thread */
1275  if (!IsGenerateWorldThreaded() && !_network_dedicated) return;
1276 
1278 
1279  if (total == 0) {
1280  assert(_gws.cls == _generation_class_table[cls]);
1281  _gws.current += progress;
1282  assert(_gws.current <= _gws.total);
1283  } else {
1284  _gws.cls = _generation_class_table[cls];
1285  _gws.current = progress;
1286  _gws.total = total;
1287  _gws.percent = percent_table[cls];
1288  }
1289 
1290  /* Don't update the screen too often. So update it once in every once in a while... */
1291  if (!_network_dedicated && _gws.timer != 0 && _realtime_tick - _gws.timer < MODAL_PROGRESS_REDRAW_TIMEOUT) return;
1292 
1293  /* Percentage is about the number of completed tasks, so 'current - 1' */
1294  _gws.percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (_gws.current == 0 ? 0 : _gws.current - 1) / _gws.total;
1295 
1296  if (_network_dedicated) {
1297  static uint last_percent = 0;
1298 
1299  /* Never display 0% */
1300  if (_gws.percent == 0) return;
1301  /* Reset if percent is lower than the last recorded */
1302  if (_gws.percent < last_percent) last_percent = 0;
1303  /* Display every 5%, but 6% is also very valid.. just not smaller steps than 5% */
1304  if (_gws.percent % 5 != 0 && _gws.percent <= last_percent + 5) return;
1305  /* Never show steps smaller than 2%, even if it is a mod 5% */
1306  if (_gws.percent <= last_percent + 2) return;
1307 
1308  DEBUG(net, 1, "Map generation percentage complete: %d", _gws.percent);
1309  last_percent = _gws.percent;
1310 
1311  /* Don't continue as dedicated never has a thread running */
1312  return;
1313  }
1314 
1317 
1318  /* Release the rights to the map generator, and acquire the rights to the
1319  * paint thread. The 'other' thread already has the paint thread rights so
1320  * this ensures us that we are waiting until the paint thread is done
1321  * before we reacquire the mapgen rights */
1322  _modal_progress_work_mutex.unlock();
1325  _modal_progress_paint_mutex.unlock();
1326 
1327  _gws.timer = _realtime_tick;
1328 }
1329 
1339 {
1340  if (total == 0) return;
1341 
1342  _SetGeneratingWorldProgress(cls, 0, total);
1343 }
1344 
1353 {
1354  /* In fact the param 'class' isn't needed.. but for some security reasons, we want it around */
1355  _SetGeneratingWorldProgress(cls, 1, 0);
1356 }
Functions related to OTTD&#39;s strings.
Generate landscape (newgame); Window numbers:
Definition: window_type.h:449
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
uint16 custom_town_number
manually entered number of towns
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
uint8 max_heightlevel
maximum allowed heightlevel
GameSettings _settings_game
Game settings of a running game or the scenario editor.
Definition: settings.cpp:79
Horizontally center the text.
Definition: gfx_func.h:95
ResizeInfo resize
Resize information.
Definition: window_gui.h:322
void ShowCreateScenario()
Show the window to create a scenario.
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1867
uint32 _realtime_tick
The real time in the game.
Definition: debug.cpp:48
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:392
bool GetHeightmapDimensions(DetailedFileType dft, const char *filename, uint *x, uint *y)
Get the dimensions of a heightmap.
Definition: heightmap.cpp:477
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Progress bar.
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition: window.cpp:3215
byte landscape
the landscape we&#39;re currently in
static const uint CUSTOM_TOWN_MAX_NUMBER
this is the maximum number of towns a user can specify in customisation
Definition: town.h:30
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:453
GenWorldProgress
Current stage of world generation process.
Definition: genworld.h:67
static const uint MAX_TILE_HEIGHT
Maximum allowed tile height.
Definition: tile_type.h:22
Load heightmap from scenario editor.
Definition: openttd.h:36
Types related to the genworld widgets.
High level window description.
Definition: window_gui.h:166
(Toggle) Button with diff image when clicked
Definition: widget_type.h:51
byte land_generator
the landscape generator
void SetMouseCursorBusy(bool busy)
Set or unset the ZZZ cursor.
Definition: gfx.cpp:1603
Clickable start date value.
WindowFlags flags
Window flags.
Definition: window_gui.h:310
static const uint MAX_MAX_HEIGHTLEVEL
Upper bound of maximum allowed heightlevel (in the construction settings)
Definition: tile_type.h:26
byte amount_of_rivers
the amount of rivers
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:602
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Functions related to dates.
static T ToggleBit(T &x, const uint8 y)
Toggles a bit in a variable.
SE &#39;Water&#39;/&#39;Freeform&#39;.
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:597
Progress report of landscape generation; Window numbers:
Definition: window_type.h:456
Normal amount of vertical space between two paragraphs of text.
Definition: window_gui.h:137
Functions related to debugging.
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Horizontal container.
Definition: widget_type.h:73
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Number of industry density settings.
Definition: settings_type.h:49
void CDECL SetWidgetsDisabledState(bool disab_stat, int widgets,...)
Sets the enabled/disabled status of a list of widgets.
Definition: window.cpp:536
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition: misc_gui.cpp:1119
Size of heightmap.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY
Value for custom sea level in difficulty settings.
Definition: genworld.h:45
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition: saveload.cpp:58
Select toy-land landscape style.
byte tree_placer
the tree placer algorithm
char title[255]
Internal name of the game.
Definition: saveload.h:321
Button with icon "Temperate".
Dropdown &#39;Sea level&#39;.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
bool IsGenerateWorldThreaded()
Tells if the world generation is done in a thread or not.
Definition: genworld.cpp:66
DifficultySettings difficulty
settings related to the difficulty
Close box (at top-left of a window)
Definition: widget_type.h:67
Decrease flat land height.
bool IsGeneratingWorldAborted()
Is the generation being aborted?
Definition: genworld.cpp:272
Button with icon "Tropical".
#define lastof(x)
Get the last element of an fixed size array.
Definition: depend.cpp:48
Increase start year.
Functions related to world/map generation.
Button with icon "Toyland".
void ShowGenerateWorldProgress()
Show the window where a user can follow the process of the map generation.
uint8 map_x
X size of map.
void AbortGeneratingWorld()
Initializes the abortion process.
Definition: genworld.cpp:263
Dropdown &#39;Heightmap rotation&#39;.
static const uint MODAL_PROGRESS_REDRAW_TIMEOUT
Timeout between redraws.
Definition: progress.h:15
static T max(const T a, const T b)
Returns the maximum of two values.
Definition: math_func.hpp:24
void RaiseWidget(byte widget_index)
Marks a widget as raised.
Definition: window_gui.h:483
void DeleteAllNonVitalWindows()
It is possible that a stickied window gets to a position where the &#39;close&#39; button is outside the gami...
Definition: window.cpp:3391
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
byte custom_sea_level
manually entered percentage of water in the map
Pure simple text.
Definition: widget_type.h:56
byte se_flat_world_height
land height a flat world gets in SE
void StartNewGameWithoutGUI(uint32 seed)
Start a normal game without the GUI.
&#39;Generate&#39; button.
bool _left_button_clicked
Is left mouse button clicked?
Definition: gfx.cpp:39
static const Year DEF_START_YEAR
The default starting year.
Definition: date_type.h:86
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:175
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
bool _network_dedicated
are we a dedicated server?
Definition: network.cpp:55
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:908
&#39;Random&#39;/&#39;Manual&#39; borders.
Pseudo random number generator.
uint8 map_y
Y size of map.
std::mutex _modal_progress_work_mutex
Rights for the performing work.
Definition: progress.cpp:21
Base for the GUIs that have an edit box in them.
bool freeform_edges
allow terraforming the tiles at the map edges
Data structure for an opened window.
Definition: window_gui.h:276
byte tgen_smoothness
how rough is the terrain from 0-3
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1044
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Definition: window.cpp:3334
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1857
static const NWidgetPart _nested_heightmap_load_widgets[]
Widgets of GenerateLandscapeWindow when loading heightmap.
enable the &#39;Default&#39; button ("\0" is returned)
Definition: textbuf_gui.h:21
Functions related to low-level strings.
Text with the progress bar.
Only numeric ones.
Definition: string_type.h:28
Functions/types related to saving and loading games.
Invisible widget that takes some space.
Definition: widget_type.h:77
Dropdown &#39;map Y size&#39;.
Functions related to errors.
Load a heightmap and start a new game from it.
Definition: openttd.h:35
Switch to scenario editor.
Definition: openttd.h:28
byte water_borders
bitset of the borders that are water
bool IsWidgetLowered(byte widget_index) const
Gets the lowered state of a widget.
Definition: window_gui.h:493
SoundSettings sound
sound effect settings
Select tropical landscape style.
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
Show a modal confirmation window with standard &#39;yes&#39; and &#39;no&#39; buttons The window is aligned to the ce...
Definition: misc_gui.cpp:1260
Dropdown &#39;Smoothness&#39;.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:176
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1012
Dropdown &#39;Terrain type&#39;.
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:78
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:945
byte snow_line_height
the configured snow line height
Functions related to modal progress.
Definition of base types and functions in a cross-platform compatible way.
void ShowHeightmapLoad()
Start with loading a heightmap.
A number of safeguards to prevent using unsafe methods.
static const uint DEF_MAX_HEIGHTLEVEL
Default maximum allowed heightlevel (in the construction settings)
Definition: tile_type.h:25
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:102
Select temperate landscape style.
Geometry functions.
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
Definition: settings.cpp:80
Simple depressed panel.
Definition: widget_type.h:48
Window timeout counter.
Definition: window_gui.h:232
void LowerWidget(byte widget_index)
Marks a widget as lowered.
Definition: window_gui.h:474
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Dropdown &#39;No. of towns&#39;.
void ShowGenerateLandscape()
Start with a normal game.
Center the window.
Definition: window_gui.h:155
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new &#39;real&#39; widget.
Definition: widget_type.h:1112
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:498
Basic functions/variables used all over the place.
#define lengthof(x)
Return the length of an fixed size array.
Definition: depend.cpp:40
Functions related to sound.
byte number_towns
the amount of towns
Definition: settings_type.h:55
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
Load from heightmap.
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
Definition: window.cpp:1175
Decrease snow level.
byte heightmap_rotation
rotation director for the heightmap
byte variety
variety level applied to TGP
Pull-down arrow for y map size.
Draw border only, no background.
Definition: window_gui.h:28
static const int WIDGET_LIST_END
indicate the end of widgets&#39; list for vararg functions
Definition: widget_type.h:20
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:137
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:984
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:35
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:700
Generate flat land.
void SetMouseCursor(CursorID sprite, PaletteID pal)
Assign a single non-animated sprite to the cursor.
Definition: gfx.cpp:1618
Select game window; Window numbers:
Definition: window_type.h:435
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Button with icon "Arctic".
byte quantity_sea_lakes
the amount of seas/lakes
Definition: settings_type.h:65
void PrepareGenerateWorldProgress()
Initializes the progress counters to the starting point.
static const uint CUSTOM_TOWN_NUMBER_DIFFICULTY
value for custom town number in difficulty settings
Definition: town.h:29
Dropdown &#39;No. of industries&#39;.
static const uint MIN_SNOWLINE_HEIGHT
Minimum snowline height.
Definition: tile_type.h:28
Decrease max. heightlevel.
uint32 generation_seed
noise seed for world generation
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
static const uint MIN_MAX_HEIGHTLEVEL
Lower bound of maximum allowed heightlevel (in the construction settings)
Definition: tile_type.h:24
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
void ClearErrorMessages()
Clear all errors from the queue.
Definition: error_gui.cpp:338
Increase snow level.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:57
Declarations for savegames operations.
Decrease start year.
Dropdown &#39;Variety distribution&#39;.
Functions related to creating heightmaps from files.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Abort button.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Pull-down arrow for x map size.
void SetDParamMaxValue(uint n, uint64 max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Definition: strings.cpp:104
Vertical container.
Definition: widget_type.h:75
void ResetGRFConfig(bool defaults)
Reset the current GRF Config to either blank or newgame settings.
static const uint CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
Minimum percentage a user can specify for custom sea level.
Definition: genworld.h:46
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME, WWT_INSET, or WWT_PANEL).
Definition: widget_type.h:997
Generate new game.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: depend.cpp:66
SwitchMode _switch_mode
The next mainloop command.
Definition: gfx.cpp:46
bool confirm
Play sound effect on successful constructions or other actions.
NW &#39;Water&#39;/&#39;Freeform&#39;.
Bottom offset of the dropdown widget string.
Definition: window_gui.h:135
char name[MAX_PATH]
Name of the file.
Definition: saveload.h:320
Coordinates of a point in 2D.
Generate an empty flat world.
byte terrain_type
the mountainousness of the landscape
Definition: settings_type.h:64
Dropdown &#39;map X size&#39;.
Drop down list.
Definition: widget_type.h:68
The original landscape generator.
Definition: genworld.h:20
static const uint CUSTOM_SEA_LEVEL_MAX_PERCENTAGE
Maximum percentage a user can specify for custom sea level.
Definition: genworld.h:47
ConstructionSettings construction
construction of things in-game
static const Year MIN_YEAR
The absolute minimum & maximum years in OTTD.
Definition: date_type.h:83
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
Dropdown &#39;Land generator&#39;.
void HandleButtonClick(byte widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
Definition: window.cpp:635
Select arctic landscape style.
static const uint DEF_SNOWLINE_HEIGHT
Default snowline height.
Definition: tile_type.h:29
void HandleGeneratingWorldAbortion()
Really handle the abortion, i.e.
Definition: genworld.cpp:280
static const uint MAX_MAP_SIZE_BITS
Maximal size of map is equal to 2 ^ MAX_MAP_SIZE_BITS.
Definition: map_type.h:64
void OnTimeout() override
Called when this window&#39;s timeout has been reached.
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:319
Decrease start year (start earlier).
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:981
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
GenerateLandscapeWindowMode
Enum for the modes we can generate in.
static const NWidgetPart _nested_generate_landscape_widgets[]
Widgets of GenerateLandscapeWindow when generating world.
Generate random land button.
Increase max. heightlevel.
Dropdown &#39;Rivers&#39;.
Base of the town class.
std::mutex _modal_progress_paint_mutex
Rights for the painting.
Definition: progress.cpp:23
Rotate the map clockwise 45 degrees.
Definition: heightmap.h:21
static const uint MAX_MAP_SIZE
Maximal map size = 4096.
Definition: map_type.h:66
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
int32 WindowNumber
Number to differentiate different windows of the same class.
Definition: window_type.h:705
GameCreationSettings game_creation
settings used during the creation of a game (map)
Specification of a rectangle with absolute coordinates of all edges.
DetailedFileType detail_ftype
Concrete file type (PNG, BMP, old save, etc).
Definition: saveload.h:318
WindowNumber window_number
Window number within the window class.
Definition: window_gui.h:312
Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
Definition: date.cpp:147
Generate random land within scenario editor.
Definition: openttd.h:33
SW &#39;Water&#39;/&#39;Freeform&#39;.
Window functions not directly related to making/drawing windows.
void StartScenarioEditor()
Start with a scenario editor.
NE &#39;Water&#39;/&#39;Freeform&#39;.
(Toggle) Button with image
Definition: widget_type.h:50
void SetNewLandscapeType(byte landscape)
Changes landscape type and sets genworld window dirty.
byte industry_density
The industry density.
Definition: settings_type.h:56
String list item with parameters.
Definition: dropdown_type.h:56
Clickable flat land height value.
Dropdown &#39;Tree algorithm&#39;.
uint8 timeout_timer
Timer value of the WF_TIMEOUT for flags.
Definition: window_gui.h:314
Increase flat land height.
Increase start year (start later).
void OnPaint() override
The window must be repainted.
Dimensions (a width and height) of a rectangle in 2D.
void OnTimeout() override
Called when this window&#39;s timeout has been reached.
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:427
static const Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date...
Definition: date_type.h:92
Year starting_year
starting date
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition: window.cpp:1259
New Game –> &#39;Random game&#39;.
Definition: openttd.h:26
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1074
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window&#39;s data as invalid (in need of re-computing)
Definition: window.cpp:3256
static bool HasModalProgress()
Check if we are currently in a modal progress state.
Definition: progress.h:21
Top offset of the dropdown widget string.
Definition: window_gui.h:134
static const uint MIN_MAP_SIZE_BITS
Minimal and maximal map width and height.
Definition: map_type.h:63
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1462
(Toggle) Button with text
Definition: widget_type.h:53
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:199
static const uint MAX_SNOWLINE_HEIGHT
Maximum allowed snowline height.
Definition: tile_type.h:30