OpenTTD Source 20250328-master-gc3457cd4c0
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"
18#include "sound_func.h"
19#include "fios.h"
20#include "string_func.h"
21#include "dropdown_type.h"
22#include "dropdown_func.h"
23#include "querystring_gui.h"
24#include "town.h"
26#include "core/random_func.hpp"
27#include "saveload/saveload.h"
28#include "progress.h"
29#include "error.h"
30#include "newgrf_townname.h"
31#include "townname_type.h"
33#include "ai/ai_gui.hpp"
34#include "game/game_gui.hpp"
35#include "industry.h"
36
38
39#include "table/strings.h"
40
42
43#include "safeguards.h"
44
45
46extern void MakeNewgameSettingsLive();
47
54
63
74
78 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
79 NWidget(WWT_CAPTION, COLOUR_BROWN), SetStringTip(STR_MAPGEN_WORLD_GENERATION_CAPTION),
81 NWidget(WWT_PANEL, COLOUR_BROWN),
83 /* Landscape selection. */
85 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TEMPERATE), SetSpriteTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
86 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_ARCTIC), SetSpriteTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
87 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TROPICAL), SetSpriteTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
88 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TOYLAND), SetSpriteTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
90
91 /* Generation options. */
93 /* Left half (land generation options) */
95 /* Labels on the left side (global column 1). */
97 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_MAPSIZE, STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1),
98 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_TERRAIN_TYPE, STR_CONFIG_SETTING_TERRAIN_TYPE_HELPTEXT), SetFill(1, 1),
99 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_VARIETY, STR_CONFIG_SETTING_VARIETY_HELPTEXT), SetFill(1, 1),
100 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_SMOOTHNESS, STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_HELPTEXT), SetFill(1, 1),
101 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_QUANTITY_OF_RIVERS, STR_CONFIG_SETTING_RIVER_AMOUNT_HELPTEXT), SetFill(1, 1),
102 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_BORDER_TYPE, STR_MAPGEN_BORDER_TYPE_TOOLTIP), SetFill(1, 1),
103 EndContainer(),
104
105 /* Widgets on the right side (global column 2). */
107 /* Mapsize X * Y. */
109 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_MAPSIZE_X_PULLDOWN), SetToolTip(STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1),
110 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_BY), SetFill(0, 1), SetAlignment(SA_CENTER),
111 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_MAPSIZE_Y_PULLDOWN), SetToolTip(STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1),
112 EndContainer(),
113 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TERRAIN_PULLDOWN), SetToolTip(STR_CONFIG_SETTING_TERRAIN_TYPE_HELPTEXT), SetFill(1, 1),
114 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_VARIETY_PULLDOWN), SetToolTip(STR_CONFIG_SETTING_VARIETY_HELPTEXT), SetFill(1, 1),
115 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_SMOOTHNESS_PULLDOWN), SetToolTip(STR_CONFIG_SETTING_ROUGHNESS_OF_TERRAIN_HELPTEXT), SetFill(1, 1),
116 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_RIVER_PULLDOWN), SetToolTip(STR_CONFIG_SETTING_RIVER_AMOUNT_HELPTEXT), SetFill(1, 1),
117 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_BORDERS_RANDOM), SetToolTip(STR_MAPGEN_BORDER_TYPE_TOOLTIP), SetFill(1, 1),
118 EndContainer(),
119 EndContainer(),
120
121 /* Right half (all other options) */
123 /* Labels on the left side (global column 3). */
126 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_SNOW_COVERAGE, STR_CONFIG_SETTING_SNOW_COVERAGE_HELPTEXT), SetFill(1, 1),
127 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_DESERT_COVERAGE, STR_CONFIG_SETTING_DESERT_COVERAGE_HELPTEXT), SetFill(1, 1),
129 EndContainer(),
130 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_DATE, STR_MAPGEN_DATE_TOOLTIP), SetFill(1, 1),
131 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_TOWN_NAME_LABEL, STR_MAPGEN_TOWN_NAME_DROPDOWN_TOOLTIP), SetFill(1, 1),
132 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_NUMBER_OF_TOWNS, STR_MAPGEN_NUMBER_OF_TOWNS_TOOLTIP), SetFill(1, 1),
133 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_NUMBER_OF_INDUSTRIES, STR_MAPGEN_NUMBER_OF_INDUSTRIES_TOOLTIP), SetFill(1, 1),
134 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_SEA_LEVEL, STR_MAPGEN_SEA_LEVEL_TOOLTIP), SetFill(1, 1),
135 EndContainer(),
136
137 /* Widgets on the right side (global column 4). */
139 /* Climate selector. */
141 /* Snow coverage. */
143 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_COVERAGE_DOWN), SetSpriteTip(SPR_ARROW_DOWN, STR_MAPGEN_SNOW_COVERAGE_DOWN_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
144 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_SNOW_COVERAGE_TEXT), SetToolTip(STR_CONFIG_SETTING_SNOW_COVERAGE_HELPTEXT), SetFill(1, 1),
145 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_COVERAGE_UP), SetSpriteTip(SPR_ARROW_UP, STR_MAPGEN_SNOW_COVERAGE_UP_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
146 EndContainer(),
147 /* Desert coverage. */
149 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_DESERT_COVERAGE_DOWN), SetSpriteTip(SPR_ARROW_DOWN, STR_MAPGEN_DESERT_COVERAGE_DOWN_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
150 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_DESERT_COVERAGE_TEXT), SetToolTip(STR_CONFIG_SETTING_DESERT_COVERAGE_HELPTEXT), SetFill(1, 1),
151 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_DESERT_COVERAGE_UP), SetSpriteTip(SPR_ARROW_UP, STR_MAPGEN_DESERT_COVERAGE_UP_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
152 EndContainer(),
153 /* Temperate/Toyland spacer. */
155 EndContainer(),
156 /* Starting date. */
158 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_START_DATE_DOWN), SetSpriteTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_MOVE_THE_STARTING_DATE_BACKWARD_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
159 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_START_DATE_TEXT), SetToolTip(STR_MAPGEN_DATE_TOOLTIP), SetFill(1, 1),
160 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_START_DATE_UP), SetSpriteTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_MOVE_THE_STARTING_DATE_FORWARD_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
161 EndContainer(),
162 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TOWNNAME_DROPDOWN), SetToolTip(STR_MAPGEN_TOWN_NAME_DROPDOWN_TOOLTIP), SetFill(1, 1),
163 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TOWN_PULLDOWN), SetToolTip(STR_MAPGEN_NUMBER_OF_TOWNS_TOOLTIP), SetFill(1, 1),
164 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_INDUSTRY_PULLDOWN), SetToolTip(STR_MAPGEN_NUMBER_OF_INDUSTRIES_TOOLTIP), SetFill(1, 1),
165 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_WATER_PULLDOWN), SetToolTip(STR_MAPGEN_SEA_LEVEL_TOOLTIP), SetFill(1, 1),
166 EndContainer(),
167 EndContainer(),
168 EndContainer(),
169
170 /* Map borders buttons for each edge. */
173 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_NORTHWEST), SetPadding(0, WidgetDimensions::unscaled.hsep_normal, 0, 0), SetFill(1, 1), SetAlignment(SA_RIGHT | SA_VERT_CENTER),
174 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_NW), SetToolTip(STR_MAPGEN_NORTHWEST), SetFill(1, 1),
175 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_NE), SetToolTip(STR_MAPGEN_NORTHEAST), SetFill(1, 1),
176 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_NORTHEAST), SetPadding(0, 0, 0, WidgetDimensions::unscaled.hsep_normal), SetFill(1, 1),
177 EndContainer(),
179 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_SOUTHWEST), SetPadding(0, WidgetDimensions::unscaled.hsep_normal, 0, 0), SetFill(1, 1), SetAlignment(SA_RIGHT | SA_VERT_CENTER),
180 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_SW), SetToolTip(STR_MAPGEN_SOUTHWEST), SetFill(1, 1),
181 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_WATER_SE), SetToolTip(STR_MAPGEN_SOUTHEAST), SetFill(1, 1),
182 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_SOUTHEAST), SetPadding(0, 0, 0, WidgetDimensions::unscaled.hsep_normal), SetFill(1, 1),
183 EndContainer(),
184 EndContainer(),
185
186 /* AI, GS, and NewGRF settings */
188 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_AI_BUTTON), SetMinimalTextLines(2, 0), SetStringTip(STR_MAPGEN_AI_SETTINGS, STR_MAPGEN_AI_SETTINGS_TOOLTIP), SetFill(1, 0),
189 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_GS_BUTTON), SetMinimalTextLines(2, 0), SetStringTip(STR_MAPGEN_GS_SETTINGS, STR_MAPGEN_GS_SETTINGS_TOOLTIP), SetFill(1, 0),
190 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_NEWGRF_BUTTON), SetMinimalTextLines(2, 0), SetStringTip(STR_MAPGEN_NEWGRF_SETTINGS, STR_MAPGEN_NEWGRF_SETTINGS_TOOLTIP), SetFill(1, 0),
191 EndContainer(),
192
193 /* Generate */
194 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_GL_GENERATE_BUTTON), SetMinimalTextLines(3, 0), SetStringTip(STR_MAPGEN_GENERATE, STR_MAPGEN_GENERATE_TOOLTIP), SetFill(1, 1),
195 EndContainer(),
196 EndContainer(),
197};
198
201 /* Window header. */
203 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
204 NWidget(WWT_CAPTION, COLOUR_BROWN), SetStringTip(STR_MAPGEN_WORLD_GENERATION_CAPTION),
205 EndContainer(),
206 NWidget(WWT_PANEL, COLOUR_BROWN),
208 /* Landscape selection. */
210 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TEMPERATE), SetSpriteTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
211 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_ARCTIC), SetSpriteTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
212 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TROPICAL), SetSpriteTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
213 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_GL_TOYLAND), SetSpriteTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
214 EndContainer(),
215
217 /* Heightmap name label. */
218 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_HEIGHTMAP_NAME, STR_MAPGEN_HEIGHTMAP_NAME_TOOLTIP),
219 NWidget(WWT_TEXT, INVALID_COLOUR, WID_GL_HEIGHTMAP_NAME_TEXT), SetTextStyle(TC_ORANGE), SetToolTip(STR_MAPGEN_HEIGHTMAP_NAME_TOOLTIP), SetFill(1, 0),
220 EndContainer(),
221
222 /* Generation options. */
224 /* Left half (land generation options) */
226 /* Labels on the left side (global column 1). */
228 /* Land generation option labels. */
229 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_HEIGHTMAP_SIZE_LABEL, STR_MAPGEN_HEIGHTMAP_SIZE_LABEL_TOOLTIP), SetFill(1, 1),
230 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_MAPSIZE, STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1),
231 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_HEIGHTMAP_ROTATION, STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_TOOLTIP), SetFill(1, 1),
232 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_HEIGHTMAP_HEIGHT, STR_MAPGEN_HEIGHTMAP_HEIGHT_TOOLTIP), SetFill(1, 1),
233 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_QUANTITY_OF_RIVERS, STR_CONFIG_SETTING_RIVER_AMOUNT_HELPTEXT), SetFill(1, 1),
234 EndContainer(),
235
236 /* Left half widgets (global column 2) */
238 NWidget(WWT_TEXT, INVALID_COLOUR, WID_GL_HEIGHTMAP_SIZE_TEXT), SetStringTip(STR_MAPGEN_HEIGHTMAP_SIZE, STR_MAPGEN_HEIGHTMAP_SIZE_LABEL_TOOLTIP), SetFill(1, 1),
239 /* Mapsize X * Y. */
241 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_MAPSIZE_X_PULLDOWN), SetToolTip(STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1),
242 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_BY), SetFill(0, 1), SetAlignment(SA_CENTER),
243 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_MAPSIZE_Y_PULLDOWN), SetToolTip(STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1),
244 EndContainer(),
245 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_HEIGHTMAP_ROTATION_PULLDOWN), SetToolTip(STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_TOOLTIP), SetFill(1, 1),
246 /* Heightmap highest peak. */
248 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_HEIGHTMAP_HEIGHT_DOWN), SetSpriteTip(SPR_ARROW_DOWN, STR_MAPGEN_HEIGHTMAP_HEIGHT_DOWN_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
249 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_HEIGHTMAP_HEIGHT_TEXT), SetToolTip(STR_MAPGEN_HEIGHTMAP_HEIGHT_TOOLTIP), SetFill(1, 1),
250 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_HEIGHTMAP_HEIGHT_UP), SetSpriteTip(SPR_ARROW_UP, STR_MAPGEN_HEIGHTMAP_HEIGHT_UP_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
251 EndContainer(),
252 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_RIVER_PULLDOWN), SetToolTip(STR_CONFIG_SETTING_RIVER_AMOUNT_HELPTEXT), SetFill(1, 1),
253 EndContainer(),
254 EndContainer(),
255
256 /* Right half (all other options) */
258 /* Right half labels (global column 3) */
261 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_SNOW_COVERAGE, STR_CONFIG_SETTING_SNOW_COVERAGE_HELPTEXT), SetFill(1, 1),
262 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_DESERT_COVERAGE, STR_CONFIG_SETTING_DESERT_COVERAGE_HELPTEXT), SetFill(1, 1),
264 EndContainer(),
265 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_DATE, STR_MAPGEN_DATE_TOOLTIP), SetFill(1, 1),
266 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_TOWN_NAME_LABEL, STR_MAPGEN_TOWN_NAME_DROPDOWN_TOOLTIP), SetFill(1, 1),
267 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_NUMBER_OF_TOWNS, STR_MAPGEN_NUMBER_OF_TOWNS_TOOLTIP), SetFill(1, 1),
268 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_NUMBER_OF_INDUSTRIES, STR_MAPGEN_NUMBER_OF_INDUSTRIES_TOOLTIP), SetFill(1, 1),
269 EndContainer(),
270
271 /* Right half widgets (global column 4) */
273 /* Climate selector. */
275 /* Snow coverage. */
277 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_COVERAGE_DOWN), SetSpriteTip(SPR_ARROW_DOWN, STR_MAPGEN_SNOW_COVERAGE_DOWN_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
278 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_SNOW_COVERAGE_TEXT), SetToolTip(STR_CONFIG_SETTING_SNOW_COVERAGE_HELPTEXT), SetFill(1, 1),
279 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_COVERAGE_UP), SetSpriteTip(SPR_ARROW_UP, STR_MAPGEN_SNOW_COVERAGE_UP_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
280 EndContainer(),
281 /* Desert coverage. */
283 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_DESERT_COVERAGE_DOWN), SetSpriteTip(SPR_ARROW_DOWN, STR_MAPGEN_DESERT_COVERAGE_DOWN_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
284 NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_DESERT_COVERAGE_TEXT), SetToolTip(STR_CONFIG_SETTING_DESERT_COVERAGE_HELPTEXT), SetFill(1, 1),
285 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_DESERT_COVERAGE_UP), SetSpriteTip(SPR_ARROW_UP, STR_MAPGEN_DESERT_COVERAGE_UP_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
286 EndContainer(),
287 /* Temperate/Toyland spacer. */
289 EndContainer(),
290 /* Starting date. */
292 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_START_DATE_DOWN), SetSpriteTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_MOVE_THE_STARTING_DATE_BACKWARD_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
293 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_START_DATE_TEXT), SetToolTip(STR_MAPGEN_DATE_TOOLTIP), SetFill(1, 1),
294 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_START_DATE_UP), SetSpriteTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_MOVE_THE_STARTING_DATE_FORWARD_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
295 EndContainer(),
296 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TOWNNAME_DROPDOWN), SetToolTip(STR_MAPGEN_TOWN_NAME_DROPDOWN_TOOLTIP), SetFill(1, 1),
297 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_TOWN_PULLDOWN), SetToolTip(STR_MAPGEN_NUMBER_OF_TOWNS_TOOLTIP), SetFill(1, 1),
298 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_INDUSTRY_PULLDOWN), SetToolTip(STR_MAPGEN_NUMBER_OF_INDUSTRIES_TOOLTIP), SetFill(1, 1),
299 EndContainer(),
300 EndContainer(),
301 EndContainer(),
302
303 /* AI, GS, and NewGRF settings */
305 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_AI_BUTTON), SetMinimalTextLines(2, 0), SetStringTip(STR_MAPGEN_AI_SETTINGS, STR_MAPGEN_AI_SETTINGS_TOOLTIP), SetFill(1, 0),
306 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_GS_BUTTON), SetMinimalTextLines(2, 0), SetStringTip(STR_MAPGEN_GS_SETTINGS, STR_MAPGEN_GS_SETTINGS_TOOLTIP), SetFill(1, 0),
307 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_GL_NEWGRF_BUTTON), SetMinimalTextLines(2, 0), SetStringTip(STR_MAPGEN_NEWGRF_SETTINGS, STR_MAPGEN_NEWGRF_SETTINGS_TOOLTIP), SetFill(1, 0),
308 EndContainer(),
309
310 /* Generate */
311 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_GL_GENERATE_BUTTON), SetMinimalTextLines(3, 0), SetStringTip(STR_MAPGEN_GENERATE, STR_MAPGEN_GENERATE_TOOLTIP), SetFill(1, 1),
312 EndContainer(),
313 EndContainer(),
314};
315
316static void StartGeneratingLandscape(GenerateLandscapeWindowMode mode)
317{
320
321 /* Copy all XXX_newgame to XXX when coming from outside the editor */
322 MakeNewgameSettingsLive();
323 ResetGRFConfig(true);
324
326 switch (mode) {
327 case GLWM_GENERATE: _switch_mode = (_game_mode == GM_EDITOR) ? SM_GENRANDLAND : SM_NEWGAME; break;
328 case GLWM_HEIGHTMAP: _switch_mode = (_game_mode == GM_EDITOR) ? SM_LOAD_HEIGHTMAP : SM_START_HEIGHTMAP; break;
329 case GLWM_SCENARIO: _switch_mode = SM_EDITOR; break;
330 default: NOT_REACHED();
331 }
332}
333
334static void LandscapeGenerationCallback(Window *w, bool confirmed)
335{
336 if (confirmed) StartGeneratingLandscape(w->window_number);
337}
338
339static DropDownList BuildMapsizeDropDown()
340{
341 DropDownList list;
342
343 for (uint i = MIN_MAP_SIZE_BITS; i <= MAX_MAP_SIZE_BITS; i++) {
344 list.push_back(MakeDropDownListStringItem(GetString(STR_JUST_INT, 1ULL << i), i));
345 }
346
347 return list;
348}
349
350static DropDownList BuildTownNameDropDown()
351{
352 DropDownList list;
353
354 /* Add and sort newgrf townnames generators */
355 const auto &grf_names = GetGRFTownNameList();
356 for (uint i = 0; i < grf_names.size(); i++) {
357 list.push_back(MakeDropDownListStringItem(grf_names[i], BUILTIN_TOWNNAME_GENERATOR_COUNT + i));
358 }
359 std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc);
360
361 size_t newgrf_size = list.size();
362 /* Insert newgrf_names at the top of the list */
363 if (newgrf_size > 0) {
364 list.push_back(MakeDropDownListDividerItem()); // separator line
365 newgrf_size++;
366 }
367
368 /* Add and sort original townnames generators */
369 for (uint i = 0; i < BUILTIN_TOWNNAME_GENERATOR_COUNT; i++) {
370 list.push_back(MakeDropDownListStringItem(STR_MAPGEN_TOWN_NAME_ORIGINAL_ENGLISH + i, i));
371 }
372 std::sort(list.begin() + newgrf_size, list.end(), DropDownListStringItem::NatSortFunc);
373
374 return list;
375}
376
377
378static const StringID _elevations[] = {STR_TERRAIN_TYPE_VERY_FLAT, STR_TERRAIN_TYPE_FLAT, STR_TERRAIN_TYPE_HILLY, STR_TERRAIN_TYPE_MOUNTAINOUS, STR_TERRAIN_TYPE_ALPINIST, STR_TERRAIN_TYPE_CUSTOM};
379static 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};
380static const StringID _rivers[] = {STR_RIVERS_NONE, STR_RIVERS_FEW, STR_RIVERS_MODERATE, STR_RIVERS_LOT};
381static 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};
382static const StringID _rotation[] = {STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE, STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_CLOCKWISE};
383static const StringID _num_towns[] = {STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM};
384static const StringID _num_inds[] = {STR_FUNDING_ONLY, STR_MINIMAL, STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM};
385static const StringID _variety[] = {STR_VARIETY_NONE, STR_VARIETY_VERY_LOW, STR_VARIETY_LOW, STR_VARIETY_MEDIUM, STR_VARIETY_HIGH, STR_VARIETY_VERY_HIGH};
386
387static_assert(std::size(_num_inds) == ID_END);
388
390 WidgetID widget_id{};
391 uint x = 0;
392 uint y = 0;
393 std::string name{};
395
396 GenerateLandscapeWindow(WindowDesc &desc, WindowNumber number = 0) : Window(desc)
397 {
398 this->InitNested(number);
399
401
402 this->mode = this->window_number;
403
404 /* Disable town and industry in SE */
405 this->SetWidgetDisabledState(WID_GL_TOWN_PULLDOWN, _game_mode == GM_EDITOR);
406 this->SetWidgetDisabledState(WID_GL_INDUSTRY_PULLDOWN, _game_mode == GM_EDITOR);
407
408 /* In case the map_height_limit is changed, clamp heightmap_height and custom_terrain_type. */
411
412 /* If original landgenerator is selected and alpinist terrain_type was selected, revert to mountainous. */
415 }
416
417 this->OnInvalidateData();
418 }
419
420
421 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
422 {
423 switch (widget) {
430
432 if (_game_mode == GM_EDITOR) {
434 }
437 }
439
444 GetGRFTownNameName(gen - BUILTIN_TOWNNAME_GENERATOR_COUNT);
445 return GetString(name);
446 }
447
449 if (_game_mode == GM_EDITOR) {
451 }
454 }
456
460 }
462
466 }
468
469 case WID_GL_HEIGHTMAP_NAME_TEXT: return this->name;
479
482 return GetString(STR_MAPGEN_HEIGHTMAP_SIZE, this->y, this->x);
483 }
484 return GetString(STR_MAPGEN_HEIGHTMAP_SIZE, this->x, this->y);
485
486 default:
487 return this->Window::GetWidgetString(widget, stringid);
488 }
489 }
490
496 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
497 {
498 if (!gui_scope) return;
499 /* Update the climate buttons */
504
505 /* You can't select smoothness / non-water borders if not terragenesis */
506 if (mode == GLWM_GENERATE) {
512
514
519
522 }
523
524 /* Disable snowline if not arctic */
526 /* Disable desert if not tropic */
528
529 /* Set snow/rainforest selections */
530 int climate_plane = 0;
532 case LandscapeType::Temperate: climate_plane = 2; break;
533 case LandscapeType::Arctic: climate_plane = 0; break;
534 case LandscapeType::Tropic: climate_plane = 1; break;
535 case LandscapeType::Toyland: climate_plane = 2; break;
536 }
537 this->GetWidget<NWidgetStacked>(WID_GL_CLIMATE_SEL_LABEL)->SetDisplayedPlane(climate_plane);
538 this->GetWidget<NWidgetStacked>(WID_GL_CLIMATE_SEL_SELECTOR)->SetDisplayedPlane(climate_plane);
539
540 /* Update availability of decreasing / increasing start date and snow level */
541 if (mode == GLWM_HEIGHTMAP) {
544 }
551
552 /* Do not allow a custom sea level or terrain type with the original land generator. */
556 }
559 }
560 }
561
562 }
563
565 {
567 std::span<const StringID> strs;
568 switch (widget) {
573 break;
574
577 break;
578
581 break;
582
586 break;
587
590 break;
591
594 break;
595
598 break;
599
601 strs = _num_towns;
603 break;
604
606 strs = _num_inds;
608 break;
609
611 strs = _elevations;
613 break;
614
616 strs = _sea_lakes;
618 break;
619
620 case WID_GL_RIVER_PULLDOWN: strs = _rivers; break;
621 case WID_GL_SMOOTHNESS_PULLDOWN: strs = _smoothness; break;
622 case WID_GL_VARIETY_PULLDOWN: strs = _variety; break;
623 case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: strs = _rotation; break;
626 break;
627
628 case WID_GL_WATER_NE:
629 case WID_GL_WATER_NW:
630 case WID_GL_WATER_SE:
631 case WID_GL_WATER_SW:
633 break;
634
636 size.width = 0;
637 break;
638
639 default:
640 return;
641 }
643 d.width += padding.width;
644 d.height += padding.height;
645 size = maxdim(size, d);
646 }
647
648 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
649 {
650 switch (widget) {
651 case WID_GL_TEMPERATE:
652 case WID_GL_ARCTIC:
653 case WID_GL_TROPICAL:
654 case WID_GL_TOYLAND:
656 break;
657
658 case WID_GL_MAPSIZE_X_PULLDOWN: // Mapsize X
660 break;
661
662 case WID_GL_MAPSIZE_Y_PULLDOWN: // Mapsize Y
664 break;
665
666 case WID_GL_TOWN_PULLDOWN: // Number of towns
668 break;
669
670 case WID_GL_TOWNNAME_DROPDOWN: // Townname generator
672 break;
673
674 case WID_GL_INDUSTRY_PULLDOWN: // Number of industries
676 break;
677
678 case WID_GL_GENERATE_BUTTON: { // Generate
679 /* Get rotated map size. */
680 uint map_x;
681 uint map_y;
683 map_x = this->y;
684 map_y = this->x;
685 } else {
686 map_x = this->x;
687 map_y = this->y;
688 }
689 if (mode == GLWM_HEIGHTMAP &&
690 (map_x * 2 < (1U << _settings_newgame.game_creation.map_x) ||
691 map_x / 2 > (1U << _settings_newgame.game_creation.map_x) ||
692 map_y * 2 < (1U << _settings_newgame.game_creation.map_y) ||
693 map_y / 2 > (1U << _settings_newgame.game_creation.map_y))) {
694 ShowQuery(
697 this,
698 LandscapeGenerationCallback);
699 } else {
700 StartGeneratingLandscape(mode);
701 }
702 break;
703 }
704
706 case WID_GL_HEIGHTMAP_HEIGHT_UP: // Height level buttons
707 /* Don't allow too fast scrolling */
708 if (!this->flags.Test(WindowFlag::Timeout) || this->timeout_timer <= 1) {
709 this->HandleButtonClick(widget);
710
712 this->InvalidateData();
713 }
714 _left_button_clicked = false;
715 break;
716
717 case WID_GL_HEIGHTMAP_HEIGHT_TEXT: // Height level text
718 this->widget_id = WID_GL_HEIGHTMAP_HEIGHT_TEXT;
720 break;
721
722
724 case WID_GL_START_DATE_UP: // Year buttons
725 /* Don't allow too fast scrolling */
726 if (!this->flags.Test(WindowFlag::Timeout) || this->timeout_timer <= 1) {
727 this->HandleButtonClick(widget);
728
730 this->InvalidateData();
731 }
732 _left_button_clicked = false;
733 break;
734
735 case WID_GL_START_DATE_TEXT: // Year text
736 this->widget_id = WID_GL_START_DATE_TEXT;
738 break;
739
741 case WID_GL_SNOW_COVERAGE_UP: // Snow coverage buttons
742 /* Don't allow too fast scrolling */
743 if (!this->flags.Test(WindowFlag::Timeout) || this->timeout_timer <= 1) {
744 this->HandleButtonClick(widget);
745
747 this->InvalidateData();
748 }
749 _left_button_clicked = false;
750 break;
751
752 case WID_GL_SNOW_COVERAGE_TEXT: // Snow coverage text
753 this->widget_id = WID_GL_SNOW_COVERAGE_TEXT;
755 break;
756
758 case WID_GL_DESERT_COVERAGE_UP: // Desert coverage buttons
759 /* Don't allow too fast scrolling */
760 if (!this->flags.Test(WindowFlag::Timeout) || this->timeout_timer <= 1) {
761 this->HandleButtonClick(widget);
762
764 this->InvalidateData();
765 }
766 _left_button_clicked = false;
767 break;
768
769 case WID_GL_DESERT_COVERAGE_TEXT: // Desert line text
770 this->widget_id = WID_GL_DESERT_COVERAGE_TEXT;
772 break;
773
774 case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: // Heightmap rotation
776 break;
777
778 case WID_GL_TERRAIN_PULLDOWN: // Terrain type
779 /* For the original map generation only the first four are valid. */
781 break;
782
783 case WID_GL_WATER_PULLDOWN: { // Water quantity
785 /* Disable custom water level when the original map generator is active. */
788 }
790 break;
791 }
792
793 case WID_GL_RIVER_PULLDOWN: // Amount of rivers
795 break;
796
797 case WID_GL_SMOOTHNESS_PULLDOWN: // Map smoothness
799 break;
800
801 case WID_GL_VARIETY_PULLDOWN: // Map variety
803 break;
804
805 /* Freetype map borders */
806 case WID_GL_WATER_NW:
808 this->InvalidateData();
809 break;
810
811 case WID_GL_WATER_NE:
813 this->InvalidateData();
814 break;
815
816 case WID_GL_WATER_SE:
818 this->InvalidateData();
819 break;
820
821 case WID_GL_WATER_SW:
823 this->InvalidateData();
824 break;
825
828 this->InvalidateData();
829 break;
830
831 case WID_GL_AI_BUTTON:
833 break;
834
835 case WID_GL_GS_BUTTON:
837 break;
838
840 ShowNewGRFSettings(true, true, false, _grfconfig_newgame);
841 break;
842 }
843 }
844
853
854 void OnDropdownSelect(WidgetID widget, int index) override
855 {
856 switch (widget) {
862
864
866 if ((uint)index == CUSTOM_TOWN_NUMBER_DIFFICULTY) {
867 this->widget_id = widget;
869 }
871 break;
872
873 case WID_GL_TOWNNAME_DROPDOWN: // Town names
874 if (_game_mode == GM_MENU || Town::GetNumItems() == 0) {
877 }
878 break;
879
881 if ((uint)index == ID_CUSTOM) {
882 this->widget_id = widget;
884 }
886 break;
887
889 if ((uint)index == CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY) {
890 this->widget_id = widget;
892 }
894 break;
895 }
896
898 if ((uint)index == CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY) {
899 this->widget_id = widget;
901 }
903 break;
904 }
905 }
906 this->InvalidateData();
907 }
908
909 void OnQueryTextFinished(std::optional<std::string> str) override
910 {
911 /* Was 'cancel' pressed? */
912 if (!str.has_value()) return;
913
914 int32_t value;
915 if (!str->empty()) {
916 value = atoi(str->c_str());
917 } else {
918 /* An empty string means revert to the default */
919 switch (this->widget_id) {
921 case WID_GL_START_DATE_TEXT: value = CalendarTime::DEF_START_YEAR.base(); break;
922 case WID_GL_SNOW_COVERAGE_TEXT: value = DEF_SNOW_COVERAGE; break;
924 case WID_GL_TOWN_PULLDOWN: value = 1; break;
925 case WID_GL_INDUSTRY_PULLDOWN: value = 1; break;
928 default: NOT_REACHED();
929 }
930 }
931
932 switch (this->widget_id) {
936 break;
937
941 break;
942
946 break;
947
951 break;
952
955 break;
956
959 break;
960
963 break;
964
967 break;
968 }
969
970 this->InvalidateData();
971 }
972};
973
974static WindowDesc _generate_landscape_desc(
975 WDP_CENTER, nullptr, 0, 0,
977 {},
979);
980
981static WindowDesc _heightmap_load_desc(
982 WDP_CENTER, nullptr, 0, 0,
984 {},
986);
987
988static void _ShowGenerateLandscape(GenerateLandscapeWindowMode mode)
989{
990 uint x = 0;
991 uint y = 0;
992
994
995 /* Generate a new seed when opening the window */
996 _settings_newgame.game_creation.generation_seed = InteractiveRandom();
997
998 if (mode == GLWM_HEIGHTMAP) {
999 /* If the function returns negative, it means there was a problem loading the heightmap */
1001 }
1002
1003 WindowDesc &desc = (mode == GLWM_HEIGHTMAP) ? _heightmap_load_desc : _generate_landscape_desc;
1004 GenerateLandscapeWindow *w = AllocateWindowDescFront<GenerateLandscapeWindow, true>(desc, mode);
1005
1006 if (mode == GLWM_HEIGHTMAP) {
1007 w->x = x;
1008 w->y = y;
1009 w->name = _file_to_saveload.title;
1010 }
1011
1013}
1014
1017{
1018 _ShowGenerateLandscape(GLWM_GENERATE);
1019}
1020
1023{
1024 _ShowGenerateLandscape(GLWM_HEIGHTMAP);
1025}
1026
1029{
1030 StartGeneratingLandscape(GLWM_SCENARIO);
1031}
1032
1037void StartNewGameWithoutGUI(uint32_t seed)
1038{
1039 /* GenerateWorld takes care of the possible GENERATE_NEW_SEED value in 'seed' */
1041
1042 StartGeneratingLandscape(GLWM_GENERATE);
1043}
1044
1046{
1047 WidgetID widget_id{};
1048
1050 {
1051 this->InitNested(window_number);
1053 }
1054
1055 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
1056 {
1057 switch (widget) {
1060
1063
1066
1069
1070 default:
1071 return this->Window::GetWidgetString(widget, stringid);
1072 }
1073 }
1074
1089
1091 {
1092 std::string str;
1093 switch (widget) {
1098 return;
1099
1102 break;
1103
1107 break;
1108
1111 break;
1112
1113 default:
1114 return;
1115 }
1117 d.width += padding.width;
1118 d.height += padding.height;
1119 size = maxdim(size, d);
1120 }
1121
1122 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1123 {
1124 switch (widget) {
1125 case WID_CS_TEMPERATE:
1126 case WID_CS_ARCTIC:
1127 case WID_CS_TROPICAL:
1128 case WID_CS_TOYLAND:
1131 break;
1132
1133 case WID_CS_MAPSIZE_X_PULLDOWN: // Mapsize X
1135 break;
1136
1137 case WID_CS_MAPSIZE_Y_PULLDOWN: // Mapsize Y
1139 break;
1140
1141 case WID_CS_EMPTY_WORLD: // Empty world / flat world
1142 StartGeneratingLandscape(GLWM_SCENARIO);
1143 break;
1144
1145 case WID_CS_RANDOM_WORLD: // Generate
1147 break;
1148
1150 case WID_CS_START_DATE_UP: // Year buttons
1151 /* Don't allow too fast scrolling */
1152 if (!this->flags.Test(WindowFlag::Timeout) || this->timeout_timer <= 1) {
1153 this->HandleButtonClick(widget);
1154 this->SetDirty();
1155
1157 }
1158 _left_button_clicked = false;
1159 break;
1160
1161 case WID_CS_START_DATE_TEXT: // Year text
1162 this->widget_id = WID_CS_START_DATE_TEXT;
1164 break;
1165
1167 case WID_CS_FLAT_LAND_HEIGHT_UP: // Height level buttons
1168 /* Don't allow too fast scrolling */
1169 if (!this->flags.Test(WindowFlag::Timeout) || this->timeout_timer <= 1) {
1170 this->HandleButtonClick(widget);
1171 this->SetDirty();
1172
1174 }
1175 _left_button_clicked = false;
1176 break;
1177
1178 case WID_CS_FLAT_LAND_HEIGHT_TEXT: // Height level text
1179 this->widget_id = WID_CS_FLAT_LAND_HEIGHT_TEXT;
1181 break;
1182 }
1183 }
1184
1189
1190 void OnDropdownSelect(WidgetID widget, int index) override
1191 {
1192 switch (widget) {
1195 }
1196 this->SetDirty();
1197 }
1198
1199 void OnQueryTextFinished(std::optional<std::string> str) override
1200 {
1201 if (!str.has_value() || str->empty()) return;
1202
1203 int32_t value = atoi(str->c_str());
1204
1205 switch (this->widget_id) {
1209 break;
1210
1214 break;
1215 }
1216
1217 this->SetDirty();
1218 }
1219};
1220
1221static constexpr NWidgetPart _nested_create_scenario_widgets[] = {
1223 NWidget(WWT_CLOSEBOX, COLOUR_BROWN),
1224 NWidget(WWT_CAPTION, COLOUR_BROWN), SetStringTip(STR_SE_MAPGEN_CAPTION),
1225 EndContainer(),
1226 NWidget(WWT_PANEL, COLOUR_BROWN),
1228 /* Landscape style selection. */
1230 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_TEMPERATE), SetSpriteTip(SPR_SELECT_TEMPERATE, STR_INTRO_TOOLTIP_TEMPERATE),
1231 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_ARCTIC), SetSpriteTip(SPR_SELECT_SUB_ARCTIC, STR_INTRO_TOOLTIP_SUB_ARCTIC_LANDSCAPE),
1232 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_TROPICAL), SetSpriteTip(SPR_SELECT_SUB_TROPICAL, STR_INTRO_TOOLTIP_SUB_TROPICAL_LANDSCAPE),
1233 NWidget(WWT_IMGBTN_2, COLOUR_ORANGE, WID_CS_TOYLAND), SetSpriteTip(SPR_SELECT_TOYLAND, STR_INTRO_TOOLTIP_TOYLAND_LANDSCAPE),
1234 EndContainer(),
1235
1237 /* Green generation type buttons: 'Flat land' and 'Random land'. */
1239 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_CS_EMPTY_WORLD), SetStringTip(STR_SE_MAPGEN_FLAT_WORLD, STR_SE_MAPGEN_FLAT_WORLD_TOOLTIP), SetFill(1, 1),
1240 NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_CS_RANDOM_WORLD), SetStringTip(STR_SE_MAPGEN_RANDOM_LAND, STR_TERRAFORM_TOOLTIP_GENERATE_RANDOM_LAND), SetFill(1, 1),
1241 EndContainer(),
1242
1243 /* Labels + setting drop-downs */
1245 /* Labels. */
1247 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_MAPSIZE, STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(0, 1),
1248 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_DATE, STR_MAPGEN_DATE_TOOLTIP), SetFill(0, 1),
1249 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_SE_MAPGEN_FLAT_WORLD_HEIGHT, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_TOOLTIP), SetFill(0, 1),
1250 EndContainer(),
1251
1253 /* Map size. */
1255 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_CS_MAPSIZE_X_PULLDOWN), SetToolTip(STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1),
1256 NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_BY), SetFill(0, 1), SetAlignment(SA_CENTER),
1257 NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_CS_MAPSIZE_Y_PULLDOWN), SetToolTip(STR_MAPGEN_MAPSIZE_TOOLTIP), SetFill(1, 1),
1258 EndContainer(),
1259
1260 /* Date. */
1262 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_CS_START_DATE_DOWN), SetFill(0, 1), SetSpriteTip(SPR_ARROW_DOWN, STR_SCENEDIT_TOOLBAR_MOVE_THE_STARTING_DATE_BACKWARD_TOOLTIP), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
1263 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_CS_START_DATE_TEXT), SetFill(1, 1), SetToolTip(STR_MAPGEN_DATE_TOOLTIP),
1264 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_CS_START_DATE_UP), SetFill(0, 1), SetSpriteTip(SPR_ARROW_UP, STR_SCENEDIT_TOOLBAR_MOVE_THE_STARTING_DATE_FORWARD_TOOLTIP), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
1265 EndContainer(),
1266
1267 /* Flat map height. */
1269 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_CS_FLAT_LAND_HEIGHT_DOWN), SetFill(0, 1), SetSpriteTip(SPR_ARROW_DOWN, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_DOWN_TOOLTIP), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
1270 NWidget(WWT_PUSHTXTBTN, COLOUR_ORANGE, WID_CS_FLAT_LAND_HEIGHT_TEXT), SetFill(1, 1), SetToolTip(STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_TOOLTIP),
1271 NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_CS_FLAT_LAND_HEIGHT_UP), SetFill(0, 1), SetSpriteTip(SPR_ARROW_UP, STR_SE_MAPGEN_FLAT_WORLD_HEIGHT_UP_TOOLTIP), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
1272 EndContainer(),
1273 EndContainer(),
1274 EndContainer(),
1275 EndContainer(),
1276 EndContainer(),
1277 EndContainer(),
1278};
1279
1280static WindowDesc _create_scenario_desc(
1281 WDP_CENTER, nullptr, 0, 0,
1283 {},
1284 _nested_create_scenario_widgets
1285);
1286
1289{
1291 new CreateScenarioWindow(_create_scenario_desc, GLWM_SCENARIO);
1292}
1293
1294static constexpr NWidgetPart _nested_generate_progress_widgets[] = {
1295 NWidget(WWT_CAPTION, COLOUR_GREY), SetStringTip(STR_GENERATION_WORLD, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1296 NWidget(WWT_PANEL, COLOUR_GREY),
1298 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GP_PROGRESS_BAR), SetFill(1, 0),
1299 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GP_PROGRESS_TEXT), SetFill(1, 0),
1300 NWidget(WWT_TEXTBTN, COLOUR_WHITE, WID_GP_ABORT), SetStringTip(STR_GENERATION_ABORT), SetFill(1, 0),
1301 EndContainer(),
1302 EndContainer(),
1303};
1304
1305
1306static WindowDesc _generate_progress_desc(
1307 WDP_CENTER, nullptr, 0, 0,
1310 _nested_generate_progress_widgets
1311);
1312
1314 static inline uint percent;
1315 static inline StringID cls;
1316 static inline uint current;
1317 static inline uint total;
1318};
1319
1320static const StringID _generation_class_table[] = {
1321 STR_GENERATION_WORLD_GENERATION,
1322 STR_GENERATION_LANDSCAPE_GENERATION,
1323 STR_GENERATION_RIVER_GENERATION,
1324 STR_GENERATION_CLEARING_TILES,
1325 STR_GENERATION_TOWN_GENERATION,
1326 STR_GENERATION_INDUSTRY_GENERATION,
1327 STR_GENERATION_OBJECT_GENERATION,
1328 STR_GENERATION_TREE_GENERATION,
1329 STR_GENERATION_SETTINGUP_GAME,
1330 STR_GENERATION_PREPARING_TILELOOP,
1331 STR_GENERATION_PREPARING_SCRIPT,
1332 STR_GENERATION_PREPARING_GAME
1333};
1334static_assert(lengthof(_generation_class_table) == GWP_CLASS_COUNT);
1335
1336
1337static void AbortGeneratingWorldCallback(Window *, bool confirmed)
1338{
1339 if (confirmed) {
1341 } else if (HasModalProgress() && !IsGeneratingWorldAborted()) {
1342 SetMouseCursor(SPR_CURSOR_ZZZ, PAL_NONE);
1343 }
1344}
1345
1347
1348 GenerateProgressWindow() : Window(_generate_progress_desc)
1349 {
1350 this->InitNested();
1351 }
1352
1353 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
1354 {
1355 switch (widget) {
1356 case WID_GP_ABORT:
1357 SetMouseCursorBusy(false);
1358 ShowQuery(
1361 this,
1362 AbortGeneratingWorldCallback
1363 );
1364 break;
1365 }
1366 }
1367
1369 {
1370 switch (widget) {
1371 case WID_GP_PROGRESS_BAR: {
1373 /* We need some spacing for the 'border' */
1376 break;
1377 }
1378
1380 for (uint i = 0; i < GWP_CLASS_COUNT; i++) {
1381 size.width = std::max(size.width, GetStringBoundingBox(_generation_class_table[i]).width + padding.width);
1382 }
1384 break;
1385 }
1386 }
1387
1388 void DrawWidget(const Rect &r, WidgetID widget) const override
1389 {
1390 switch (widget) {
1391 case WID_GP_PROGRESS_BAR: {
1392 /* Draw the % complete with a bar and a text */
1395 DrawFrameRect(br.WithWidth(br.Width() * GenWorldStatus::percent / 100, _current_text_dir == TD_RTL), COLOUR_MAUVE, {});
1396 DrawString(br.left, br.right, CenterBounds(br.top, br.bottom, GetCharacterHeight(FS_NORMAL)),
1397 GetString(STR_GENERATION_PROGRESS, GenWorldStatus::percent), TC_FROMSTRING, SA_HOR_CENTER);
1398 break;
1399 }
1400
1402 /* Tell which class we are generating */
1403 DrawString(r.left, r.right, r.top, GenWorldStatus::cls, TC_FROMSTRING, SA_HOR_CENTER);
1404
1405 /* And say where we are in that class */
1406 DrawString(r.left, r.right, r.top + GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal,
1407 GetString(STR_GENERATION_PROGRESS_NUM, GenWorldStatus::current, GenWorldStatus::total), TC_FROMSTRING, SA_HOR_CENTER);
1408 }
1409 }
1410};
1411
1416{
1417 GenWorldStatus::cls = STR_GENERATION_WORLD_GENERATION;
1418 GenWorldStatus::current = 0;
1419 GenWorldStatus::total = 0;
1420 GenWorldStatus::percent = 0;
1421}
1422
1431
1432static void _SetGeneratingWorldProgress(GenWorldProgress cls, uint progress, uint total)
1433{
1434 static const int percent_table[] = {0, 5, 14, 17, 20, 40, 60, 65, 80, 85, 95, 99, 100 };
1435 static_assert(lengthof(percent_table) == GWP_CLASS_COUNT + 1);
1436 assert(cls < GWP_CLASS_COUNT);
1437
1438 /* Check if we really are generating the world.
1439 * For example, placing trees via the SE also calls this function, but
1440 * shouldn't try to update the progress.
1441 */
1442 if (!HasModalProgress()) return;
1443
1446 return;
1447 }
1448
1449 if (total == 0) {
1450 assert(GenWorldStatus::cls == _generation_class_table[cls]);
1451 GenWorldStatus::current += progress;
1452 assert(GenWorldStatus::current <= GenWorldStatus::total);
1453 } else {
1454 GenWorldStatus::cls = _generation_class_table[cls];
1455 GenWorldStatus::current = progress;
1456 GenWorldStatus::total = total;
1457 GenWorldStatus::percent = percent_table[cls];
1458 }
1459
1460 /* Percentage is about the number of completed tasks, so 'current - 1' */
1461 GenWorldStatus::percent = percent_table[cls] + (percent_table[cls + 1] - percent_table[cls]) * (GenWorldStatus::current == 0 ? 0 : GenWorldStatus::current - 1) / GenWorldStatus::total;
1462
1463 if (_network_dedicated) {
1464 static uint last_percent = 0;
1465
1466 /* Never display 0% */
1467 if (GenWorldStatus::percent == 0) return;
1468 /* Reset if percent is lower than the last recorded */
1469 if (GenWorldStatus::percent < last_percent) last_percent = 0;
1470 /* Display every 5%, but 6% is also very valid.. just not smaller steps than 5% */
1471 if (GenWorldStatus::percent % 5 != 0 && GenWorldStatus::percent <= last_percent + 5) return;
1472 /* Never show steps smaller than 2%, even if it is a mod 5% */
1473 if (GenWorldStatus::percent <= last_percent + 2) return;
1474
1475 Debug(net, 3, "Map generation percentage complete: {}", GenWorldStatus::percent);
1476 last_percent = GenWorldStatus::percent;
1477
1478 return;
1479 }
1480
1482
1484}
1485
1495{
1496 if (total == 0) return;
1497
1498 _SetGeneratingWorldProgress(cls, 0, total);
1499}
1500
1509{
1510 /* In fact the param 'class' isn't needed.. but for some security reasons, we want it around */
1511 _SetGeneratingWorldProgress(cls, 1, 0);
1512}
void ShowAIConfigWindow()
Open the AI config window.
Definition ai_gui.cpp:334
Window for configuring the AIs
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Flip(Tvalue_type value)
Flip the value-th bit.
static bool NatSortFunc(std::unique_ptr< const DropDownListItem > const &first, std::unique_ptr< const DropDownListItem > const &second)
Natural sorting comparator function for DropDownList::sort().
static Date ConvertYMDToDate(Year year, Month month, Day day)
Converts a tuple of Year, Month and Day to a Date.
static constexpr TimerGame< struct Calendar >::Year DEF_START_YEAR
The default starting year.
static constexpr TimerGame< struct Calendar >::Year MIN_YEAR
The absolute minimum year in OTTD.
static constexpr TimerGame< struct Calendar >::Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date,...
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
void GameLoopPause()
Pause the game-loop for a bit, releasing the game-state lock.
RectPadding frametext
Padding inside frame with text.
Definition window_gui.h:41
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:29
int vsep_normal
Normal vertical spacing.
Definition window_gui.h:58
RectPadding fullbevel
Always-scaled bevel thickness.
Definition window_gui.h:39
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:94
Functions related to debugging.
#define Debug(category, level, format_string,...)
Output a line of debugging information.
Definition debug.h:37
void ShowDropDownMenu(Window *w, std::span< const StringID > strings, int selected, WidgetID button, uint32_t disabled_mask, uint32_t hidden_mask, uint width)
Show a dropdown menu window near a widget of the parent window.
Definition dropdown.cpp:444
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, bool instant_close, bool persist)
Show a drop down list.
Definition dropdown.cpp:407
Common drop down list components.
Functions related to the drop down widget.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23)
Definition enum_type.hpp:17
Functions related to errors.
void ClearErrorMessages()
Clear all errors from the queue.
Declarations for savegames operations.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:77
void ShowGSConfigWindow()
Open the GS config window.
Definition game_gui.cpp:423
Window for configuring the Games
void HandleGeneratingWorldAbortion()
Really handle the abortion, i.e.
Definition genworld.cpp:276
void AbortGeneratingWorld()
Initializes the abortion process.
Definition genworld.cpp:259
bool IsGeneratingWorldAborted()
Is the generation being aborted?
Definition genworld.cpp:268
Functions related to world/map generation.
static const uint MAP_HEIGHT_LIMIT_AUTO_MINIMUM
When map height limit is auto, make this the lowest possible map height limit.
Definition genworld.h:54
@ LG_ORIGINAL
The original landscape generator.
Definition genworld.h:21
static const uint CUSTOM_SEA_LEVEL_MAX_PERCENTAGE
Maximum percentage a user can specify for custom sea level.
Definition genworld.h:50
static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY
Value for custom sea level in difficulty settings.
Definition genworld.h:48
GenWorldProgress
Current stage of world generation process.
Definition genworld.h:61
static const uint CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
Minimum percentage a user can specify for custom sea level.
Definition genworld.h:49
static const uint CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY
Value for custom terrain type in difficulty settings.
Definition genworld.h:46
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
void ShowGenerateWorldProgress()
Show the window where a user can follow the process of the map generation.
void ShowGenerateLandscape()
Start with a normal game.
static constexpr NWidgetPart _nested_heightmap_load_widgets[]
Widgets of GenerateLandscapeWindow when loading heightmap.
void ShowCreateScenario()
Show the window to create a scenario.
static constexpr NWidgetPart _nested_generate_landscape_widgets[]
Widgets of GenerateLandscapeWindow when generating world.
static uint GetMapHeightLimit()
Get the map height limit, or if set to "auto", the absolute limit.
void SetNewLandscapeType(LandscapeType landscape)
Changes landscape type and sets genworld window dirty.
void StartScenarioEditor()
Start with a scenario editor.
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
void PrepareGenerateWorldProgress()
Initializes the progress counters to the starting point.
GenerateLandscapeWindowMode
Enum for the modes we can generate in.
@ GLWM_GENERATE
Generate new game.
@ GLWM_HEIGHTMAP
Load from heightmap.
@ GLWM_SCENARIO
Generate flat land.
void ShowHeightmapLoad()
Start with loading a heightmap.
void StartNewGameWithoutGUI(uint32_t seed)
Start a normal game without the GUI.
Types related to the genworld widgets.
@ WID_CS_TROPICAL
Select tropical landscape style.
@ WID_CS_TEMPERATE
Select temperate landscape style.
@ WID_CS_MAPSIZE_X_PULLDOWN
Pull-down arrow for x map size.
@ WID_CS_TOYLAND
Select toy-land landscape style.
@ WID_CS_FLAT_LAND_HEIGHT_TEXT
Clickable flat land height value.
@ WID_CS_START_DATE_TEXT
Clickable start date value.
@ WID_CS_START_DATE_DOWN
Decrease start year (start earlier).
@ WID_CS_EMPTY_WORLD
Generate an empty flat world.
@ WID_CS_ARCTIC
Select arctic landscape style.
@ WID_CS_MAPSIZE_Y_PULLDOWN
Pull-down arrow for y map size.
@ WID_CS_FLAT_LAND_HEIGHT_DOWN
Decrease flat land height.
@ WID_CS_FLAT_LAND_HEIGHT_UP
Increase flat land height.
@ WID_CS_RANDOM_WORLD
Generate random land button.
@ WID_CS_START_DATE_UP
Increase start year (start later).
@ WID_GL_TOWNNAME_DROPDOWN
Dropdown 'Townnames'.
@ WID_GL_WATER_SE
SE 'Water'/'Freeform'.
@ WID_GL_WATER_PULLDOWN
Dropdown 'Sea level'.
@ WID_GL_MAPSIZE_X_PULLDOWN
Dropdown 'map X size'.
@ WID_GL_SNOW_COVERAGE_TEXT
Snow coverage.
@ WID_GL_WATER_NE
NE 'Water'/'Freeform'.
@ WID_GL_VARIETY_PULLDOWN
Dropdown 'Variety distribution'.
@ WID_GL_TOYLAND
Button with icon "Toyland".
@ WID_GL_GENERATE_BUTTON
'Generate' button.
@ WID_GL_ARCTIC
Button with icon "Arctic".
@ WID_GL_HEIGHTMAP_HEIGHT_TEXT
Max. heightmap highest mountain.
@ WID_GL_HEIGHTMAP_ROTATION_PULLDOWN
Dropdown 'Heightmap rotation'.
@ WID_GL_MAPSIZE_Y_PULLDOWN
Dropdown 'map Y size'.
@ WID_GL_TROPICAL
Button with icon "Tropical".
@ WID_GL_HEIGHTMAP_NAME_TEXT
Heightmap name.
@ WID_GL_RIVER_PULLDOWN
Dropdown 'Rivers'.
@ WID_GL_DESERT_COVERAGE_TEXT
Desert coverage.
@ WID_GL_AI_BUTTON
'AI Settings' button.
@ WID_GL_SNOW_COVERAGE_DOWN
Decrease snow coverage.
@ WID_GL_HEIGHTMAP_HEIGHT_UP
Increase max. heightmap highest mountain.
@ WID_GL_NEWGRF_BUTTON
'NewGRF Settings' button.
@ WID_GL_CLIMATE_SEL_LABEL
NWID_SELECTION for snow or desert coverage label.
@ WID_GL_BORDERS_RANDOM
'Random'/'Manual' borders.
@ WID_GL_HEIGHTMAP_SIZE_TEXT
Size of heightmap.
@ WID_GL_WATER_NW
NW 'Water'/'Freeform'.
@ WID_GL_TEMPERATE
Button with icon "Temperate".
@ WID_GL_SMOOTHNESS_PULLDOWN
Dropdown 'Smoothness'.
@ WID_GL_GS_BUTTON
'Game Script Settings' button.
@ WID_GL_START_DATE_DOWN
Decrease start year.
@ WID_GL_START_DATE_TEXT
Start year.
@ WID_GL_CLIMATE_SEL_SELECTOR
NWID_SELECTION for snow or desert coverage selector.
@ WID_GL_DESERT_COVERAGE_UP
Increase desert coverage.
@ WID_GL_TOWN_PULLDOWN
Dropdown 'No. of towns'.
@ WID_GL_HEIGHTMAP_HEIGHT_DOWN
Decrease heightmap highest mountain.
@ WID_GL_WATER_SW
SW 'Water'/'Freeform'.
@ WID_GL_SNOW_COVERAGE_UP
Increase snow coverage.
@ WID_GL_INDUSTRY_PULLDOWN
Dropdown 'No. of industries'.
@ WID_GL_DESERT_COVERAGE_DOWN
Decrease desert coverage.
@ WID_GL_TERRAIN_PULLDOWN
Dropdown 'Terrain type'.
@ WID_GL_START_DATE_UP
Increase start year.
@ WID_GP_PROGRESS_TEXT
Text with the progress bar.
@ WID_GP_PROGRESS_BAR
Progress bar.
@ WID_GP_ABORT
Abort button.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Geometry functions.
void SetMouseCursor(CursorID sprite, PaletteID pal)
Assign a single non-animated sprite to the cursor.
Definition gfx.cpp:1657
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:852
Dimension GetStringListBoundingBox(std::span< const StringID > list, FontSize fontsize)
Get maximum dimension of a list of strings.
Definition gfx.cpp:890
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:658
bool _left_button_clicked
Is left mouse button clicked?
Definition gfx.cpp:42
void SetMouseCursorBusy(bool busy)
Set or unset the ZZZ cursor.
Definition gfx.cpp:1641
SwitchMode _switch_mode
The next mainloop command.
Definition gfx.cpp:49
int CenterBounds(int min, int max, int size)
Determine where to draw a centred object inside a widget.
Definition gfx_func.h:166
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:245
@ SA_RIGHT
Right align the text (must be a single bit).
Definition gfx_type.h:379
@ SA_HOR_CENTER
Horizontally center the text.
Definition gfx_type.h:378
@ SA_CENTER
Center both horizontally and vertically.
Definition gfx_type.h:387
@ SA_VERT_CENTER
Vertically center the text.
Definition gfx_type.h:383
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetAspect(float ratio, AspectFlags flags=AspectFlag::ResizeX)
Widget part function for setting the aspect ratio.
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FS_NORMAL)
Widget part function for setting the minimal text lines.
constexpr NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
constexpr NWidgetPart SetPIPRatio(uint8_t ratio_pre, uint8_t ratio_inter, uint8_t ratio_post)
Widget part function for setting a pre/inter/post ratio.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:945
bool GetHeightmapDimensions(DetailedFileType dft, const char *filename, uint *x, uint *y)
Get the dimensions of a heightmap.
Functions related to creating heightmaps from files.
@ HM_CLOCKWISE
Rotate the map clockwise 45 degrees.
Definition heightmap.h:21
Base of all industries.
LandscapeType
Landscape types.
BorderFlag
For storing the water borders which shall be retained.
@ NorthWest
Border on North West.
@ Random
Randomise borders.
@ NorthEast
Border on North East.
@ SouthEast
Border on South East.
@ SouthWest
Border on South West.
static const uint MIN_MAP_SIZE_BITS
Minimal and maximal map width and height.
Definition map_type.h:37
static const uint MAX_MAP_SIZE
Maximal map size = 4096.
Definition map_type.h:40
static const uint MAX_MAP_SIZE_BITS
Maximal size of map is equal to 2 ^ MAX_MAP_SIZE_BITS.
Definition map_type.h:38
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition math_func.hpp:79
void ShowQuery(EncodedString &&caption, EncodedString &&message, Window *parent, QueryCallbackProc *callback, bool focus)
Show a confirmation window with standard 'yes' and 'no' buttons The window is aligned to the centre o...
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
bool _network_dedicated
are we a dedicated server?
Definition network.cpp:70
Basic functions/variables used all over the place.
void ResetGRFConfig(bool defaults)
Reset the current GRF Config to either blank or newgame settings.
GRFConfigList _grfconfig_newgame
First item in list of default GRF set up.
void ShowNewGRFSettings(bool editable, bool show_params, bool exec_changes, GRFConfigList &config)
Setup the NewGRF gui.
Header of Action 0F "universal holder" structure and functions.
@ SM_START_HEIGHTMAP
Load a heightmap and start a new game from it.
Definition openttd.h:38
@ SM_GENRANDLAND
Generate random land within scenario editor.
Definition openttd.h:36
@ SM_LOAD_HEIGHTMAP
Load heightmap from scenario editor.
Definition openttd.h:39
@ SM_EDITOR
Switch to scenario editor.
Definition openttd.h:31
@ SM_NEWGAME
New Game --> 'Random game'.
Definition openttd.h:28
Functions related to modal progress.
bool HasModalProgress()
Check if we are currently in a modal progress state.
Definition progress.h:17
Base for the GUIs that have an edit box in them.
Pseudo random number generator.
A number of safeguards to prevent using unsafe methods.
FileToSaveLoad _file_to_saveload
File to save or load in the openttd loop.
Definition saveload.cpp:64
Functions/types related to saving and loading games.
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
Definition settings.cpp:60
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:58
@ ID_CUSTOM
Custom number of industries.
@ ID_END
Number of industry density settings.
Functions related to sound.
@ SND_15_BEEP
19 == 0x13 GUI button click
Definition sound_type.h:66
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
Definition stdafx.h:277
Functions related to low-level strings.
@ CS_NUMERAL
Only numeric ones.
Definition string_type.h:26
uint64_t GetParamMaxValue(uint64_t max_value, uint min_count, FontSize size)
Get some number that is suitable for string size computations.
Definition strings.cpp:248
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:90
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:426
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:56
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static constexpr uint32_t BUILTIN_TOWNNAME_GENERATOR_COUNT
The number of builtin generators for town names.
@ TD_RTL
Text is written right-to-left by default.
SoundSettings sound
sound effect settings
bool freeform_edges
allow terraforming the tiles at the map edges
uint8_t map_height_limit
the maximum allowed heightlevel
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnDropdownSelect(WidgetID widget, int index) override
A dropdown option associated to this window has been selected.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void OnPaint() override
The window must be repainted.
void OnTimeout() override
Called when this window's timeout has been reached.
uint8_t number_towns
the amount of towns
uint8_t terrain_type
the mountainousness of the landscape
uint8_t industry_density
The industry density.
uint8_t quantity_sea_lakes
the amount of seas/lakes
Dimensions (a width and height) of a rectangle in 2D.
DetailedFileType detail_ftype
Concrete file type (PNG, BMP, old save, etc).
Definition saveload.h:417
std::string title
Internal name of the game.
Definition saveload.h:420
std::string name
Name of the file.
Definition saveload.h:419
uint8_t custom_sea_level
manually entered percentage of water in the map
uint8_t amount_of_rivers
the amount of rivers
uint16_t custom_town_number
manually entered number of towns
uint16_t custom_industry_number
manually entered number of industries
uint8_t variety
variety level applied to TGP
uint8_t snow_coverage
the amount of snow coverage on the map
uint8_t desert_coverage
the amount of desert coverage on the map
uint8_t custom_terrain_type
manually entered height for TGP to aim for
LandscapeType landscape
the landscape we're currently in
uint8_t map_x
X size of map.
uint8_t land_generator
the landscape generator
uint8_t tgen_smoothness
how rough is the terrain from 0-3
uint8_t se_flat_world_height
land height a flat world gets in SE
uint8_t town_name
the town name generator used for town names
uint8_t map_y
Y size of map.
TimerGameCalendar::Year starting_year
starting date
uint8_t heightmap_rotation
rotation director for the heightmap
BorderFlags water_borders
bitset of the borders that are water
uint32_t generation_seed
noise seed for world generation
uint8_t heightmap_height
highest mountain for heightmap (towards what it scales)
ConstructionSettings construction
construction of things in-game
DifficultySettings difficulty
settings related to the difficulty
GameCreationSettings game_creation
settings used during the creation of a game (map)
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void OnTimeout() override
Called when this window's timeout has been reached.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void OnDropdownSelect(WidgetID widget, int index) override
A dropdown option associated to this window has been selected.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Partial widget specification to allow NWidgets to be written nested.
Coordinates of a point in 2D.
static size_t GetNumItems()
Returns number of valid items in the pool.
static constexpr size_t MAX_SIZE
Make template parameter accessible from outside.
constexpr uint Horizontal() const
Get total horizontal padding of RectPadding.
constexpr uint Vertical() const
Get total vertical padding of RectPadding.
Specification of a rectangle with absolute coordinates of all edges.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
bool confirm
Play sound effect on successful constructions or other actions.
Templated helper to make a type-safe 'typedef' representing a single POD value.
High level window description.
Definition window_gui.h:168
Number to differentiate different windows of the same class.
Data structure for an opened window.
Definition window_gui.h:274
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:744
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition window.cpp:3166
void RaiseWidget(WidgetID widget_index)
Marks a widget as raised.
Definition window_gui.h:470
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:556
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:504
ResizeInfo resize
Resize information.
Definition window_gui.h:315
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition window_gui.h:516
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:442
void RaiseWidgetsWhenLowered(Args... widgets)
Raises the widgets and sets widgets dirty that are lowered.
Definition window_gui.h:537
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:973
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition window_gui.h:461
void HandleButtonClick(WidgetID widget)
Do all things to make a button look clicked and mark it to be unclicked in a few ticks.
Definition window.cpp:595
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1751
WindowFlags flags
Window flags.
Definition window_gui.h:301
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:382
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:312
WindowNumber window_number
Window number within the window class.
Definition window_gui.h:303
@ EnableDefault
enable the 'Default' button ("\0" is returned)
static const uint MIN_MAP_HEIGHT_LIMIT
Lower bound of maximum allowed heightlevel (in the construction settings)
Definition tile_type.h:29
static const uint MIN_CUSTOM_TERRAIN_TYPE
Lowest possible peak value for world generation.
Definition tile_type.h:27
static const uint DEF_DESERT_COVERAGE
Default desert coverage.
Definition tile_type.h:37
static const uint MAX_TILE_HEIGHT
Maximum allowed tile height.
Definition tile_type.h:24
static const uint MIN_HEIGHTMAP_HEIGHT
Lowest possible peak value for heightmap creation.
Definition tile_type.h:26
static const uint MAX_MAP_HEIGHT_LIMIT
Upper bound of maximum allowed heightlevel (in the construction settings)
Definition tile_type.h:30
static const uint DEF_SNOW_COVERAGE
Default snow coverage.
Definition tile_type.h:36
Definition of the game-calendar-timer.
Base of the town class.
static const uint CUSTOM_TOWN_MAX_NUMBER
this is the maximum number of towns a user can specify in customisation
Definition town.h:29
static const uint CUSTOM_TOWN_NUMBER_DIFFICULTY
value for custom town number in difficulty settings
Definition town.h:28
Definition of structures used for generating town names.
Base of all video drivers.
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition widget.cpp:296
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:42
@ WWT_IMGBTN_2
(Toggle) Button with diff image when clicked
Definition widget_type.h:43
@ NWID_SPACER
Invisible widget that takes some space.
Definition widget_type.h:69
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:65
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:45
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:40
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:51
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:67
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition widget_type.h:59
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:38
@ WWT_DROPDOWN
Drop down list.
Definition widget_type.h:60
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:48
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:70
@ EqualSize
Containers should keep all their (resizing) children equally large.
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1157
Window * BringWindowToFrontById(WindowClass cls, WindowNumber number)
Find a window and make it the relative top-window on the screen.
Definition window.cpp:1228
void CloseAllNonVitalWindows()
It is possible that a stickied window gets to a position where the 'close' button is outside the gami...
Definition window.cpp:3287
void SetWindowDirty(WindowClass cls, WindowNumber number)
Mark window as dirty (in need of repainting)
Definition window.cpp:3108
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:3243
Window functions not directly related to making/drawing windows.
@ NoClose
This window can't be interactively closed.
@ BorderOnly
Draw border only, no background.
@ Lowered
If set the frame is lowered and the background colour brighter (ie. buttons when pressed)
@ Timeout
Window timeout counter.
@ WDP_CENTER
Center the window.
Definition window_gui.h:146
int WidgetID
Widget ID.
Definition window_type.h:20
@ WN_GAME_OPTIONS_GAME_OPTIONS
Game options.
Definition window_type.h:28
@ WC_SELECT_GAME
Select game window; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:47
@ WC_GENERATE_LANDSCAPE
Generate landscape (newgame); Window numbers:
@ WC_GAME_OPTIONS
Game options window; Window numbers:
@ WC_MODAL_PROGRESS
Progress report of landscape generation; Window numbers: