OpenTTD Source: src/genworld_gui.cpp File Reference

OpenTTD Source 15.0-RC2

Data Structures | Enumerations | Functions | Variables
genworld_gui.cpp File Reference

GUI to configure and show progress during map generation. More...

`#include "stdafx.h"`
`#include "heightmap.h"`
`#include "debug.h"`
`#include "genworld.h"`
`#include "network/network.h"`
`#include "strings_func.h"`
`#include "window_func.h"`
`#include "timer/timer_game_calendar.h"`
`#include "sound_func.h"`
`#include "fios.h"`
`#include "string_func.h"`
`#include "dropdown_type.h"`
`#include "dropdown_func.h"`
`#include "querystring_gui.h"`
`#include "town.h"`
`#include "core/geometry_func.hpp"`
`#include "core/random_func.hpp"`
`#include "saveload/saveload.h"`
`#include "progress.h"`
`#include "error.h"`
`#include "newgrf_townname.h"`
`#include "townname_type.h"`
`#include "video/video_driver.hpp"`
`#include "ai/ai_gui.hpp"`
`#include "game/game_gui.hpp"`
`#include "industry.h"`
`#include "core/string_consumer.hpp"`
`#include "widgets/genworld_widget.h"`
`#include "table/strings.h"`
`#include "dropdown_common_type.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Data Structures
struct | GenerateLandscapeWindow
struct | CreateScenarioWindow
struct | GenWorldStatus
struct | GenerateProgressWindow

## Enumerations
enum | GenerateLandscapeWindowMode : uint8_t { GLWM_GENERATE , GLWM_HEIGHTMAP , GLWM_SCENARIO }
| Enum for the modes we can generate in. More...

## Functions
void | MakeNewgameSettingsLive ()
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.
static void | StartGeneratingLandscape (GenerateLandscapeWindowMode mode)
static void | LandscapeGenerationCallback (Window *w, bool confirmed)
static DropDownList | BuildMapsizeDropDown ()
static DropDownList | BuildTownNameDropDown ()
static void | _ShowGenerateLandscape (GenerateLandscapeWindowMode mode)
void | ShowGenerateLandscape ()
| Start with a normal game.
void | ShowHeightmapLoad ()
| Start with loading a heightmap.
void | StartScenarioEditor ()
| Start with a scenario editor.
void | StartNewGameWithoutGUI (uint32_t seed)
| Start a normal game without the GUI.
void | ShowCreateScenario ()
| Show the window to create a scenario.
static void | AbortGeneratingWorldCallback (Window *, bool confirmed)
void | PrepareGenerateWorldProgress ()
| Initializes the progress counters to the starting point.
void | ShowGenerateWorldProgress ()
| Show the window where a user can follow the process of the map generation.
static void | _SetGeneratingWorldProgress (GenWorldProgress cls, uint progress, uint total)
void | SetGeneratingWorldProgress (GenWorldProgress cls, uint total)
| Set the total of a stage of the world generation.
void | IncreaseGeneratingWorldProgress (GenWorldProgress cls)
| Increases the current stage of the world generation with one.

## Variables
static constexpr std::initializer_list< NWidgetPart > | _nested_generate_landscape_widgets
| Widgets of GenerateLandscapeWindow when generating world.
static constexpr std::initializer_list< NWidgetPart > | _nested_heightmap_load_widgets
| Widgets of GenerateLandscapeWindow when loading heightmap.
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, STR_TERRAIN_TYPE_CUSTOM}
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}
static const StringID | _rivers [] = {STR_RIVERS_NONE, STR_RIVERS_FEW, STR_RIVERS_MODERATE, STR_RIVERS_LOT}
static const StringID | _borders [] = {STR_MAPGEN_BORDER_RANDOMIZE, STR_MAPGEN_BORDER_MANUAL, STR_MAPGEN_BORDER_INFINITE_WATER}
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}
static const StringID | _rotation [] = {STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE, STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_CLOCKWISE}
static const StringID | _num_towns [] = {STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM}
static 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}
static const StringID | _variety [] = {STR_VARIETY_NONE, STR_VARIETY_VERY_LOW, STR_VARIETY_LOW, STR_VARIETY_MEDIUM, STR_VARIETY_HIGH, STR_VARIETY_VERY_HIGH}
static WindowDesc | _generate_landscape_desc (WDP_CENTER, {}, 0, 0, WC_GENERATE_LANDSCAPE, WC_NONE, {}, _nested_generate_landscape_widgets)
static WindowDesc | _heightmap_load_desc (WDP_CENTER, {}, 0, 0, WC_GENERATE_LANDSCAPE, WC_NONE, {}, _nested_heightmap_load_widgets)
static constexpr std::initializer_list< NWidgetPart > | _nested_create_scenario_widgets
static WindowDesc | _create_scenario_desc (WDP_CENTER, {}, 0, 0, WC_GENERATE_LANDSCAPE, WC_NONE, {}, _nested_create_scenario_widgets)
static constexpr std::initializer_list< NWidgetPart > | _nested_generate_progress_widgets
static WindowDesc | _generate_progress_desc (WDP_CENTER, {}, 0, 0, WC_MODAL_PROGRESS, WC_NONE, WindowDefaultFlag::NoClose, _nested_generate_progress_widgets)
static const StringID | _generation_class_table []

## Detailed Description

GUI to configure and show progress during map generation.

Definition in file genworld_gui.cpp.

## Enumeration Type Documentation

## ◆ GenerateLandscapeWindowMode

enum GenerateLandscapeWindowMode : uint8_t

Enum for the modes we can generate in.

Enumerator
GLWM_GENERATE | Generate new game.
GLWM_HEIGHTMAP | Load from heightmap.
GLWM_SCENARIO | Generate flat land.

Definition at line 50 of file genworld_gui.cpp.

## Function Documentation

## ◆ _SetGeneratingWorldProgress()

static void _SetGeneratingWorldProgress | ( | GenWorldProgress | cls,
|  | uint | progress,
|  | uint | total
| ) |  |
| static

Definition at line 1458 of file genworld_gui.cpp.

## ◆ _ShowGenerateLandscape()

static void _ShowGenerateLandscape | ( | GenerateLandscapeWindowMode | mode | ) |
| static

Definition at line 1013 of file genworld_gui.cpp.

## ◆ AbortGeneratingWorldCallback()

static void AbortGeneratingWorldCallback | ( | Window * | ,
|  | bool | confirmed
| ) |  |
| static

Definition at line 1364 of file genworld_gui.cpp.

## ◆ BuildMapsizeDropDown()

static DropDownList BuildMapsizeDropDown | ( |  | ) |
| static

Definition at line 340 of file genworld_gui.cpp.

## ◆ BuildTownNameDropDown()

static DropDownList BuildTownNameDropDown | ( |  | ) |
| static

Definition at line 351 of file genworld_gui.cpp.

## ◆ GetMapHeightLimit()

static uint GetMapHeightLimit | ( |  | ) |
| static

Get the map height limit, or if set to "auto", the absolute limit.

Definition at line 59 of file genworld_gui.cpp.

References _settings_newgame, GameSettings::construction, ConstructionSettings::map_height_limit, and MAX_MAP_HEIGHT_LIMIT.

Referenced by GenerateLandscapeWindow::OnClick(), CreateScenarioWindow::OnClick(), GenerateLandscapeWindow::OnInvalidateData(), CreateScenarioWindow::OnPaint(), GenerateLandscapeWindow::OnQueryTextFinished(), and CreateScenarioWindow::OnQueryTextFinished().

## ◆ IncreaseGeneratingWorldProgress()

void IncreaseGeneratingWorldProgress | ( | GenWorldProgress | cls | ) |

Increases the current stage of the world generation with one.

Parameters

  cls | the current class we are in.

Warning: this function isn't clever. Don't go from class 4 to 3. Go upwards, always. Also, progress works if total is zero, total works if progress is zero.

Definition at line 1534 of file genworld_gui.cpp.

Referenced by _GenerateWorld(), CreateRivers(), GenerateLandscape(), GenerateTerrainPerlin(), GenerateTowns(), PlaceInitialIndustry(), PlaceTreeGroups(), and PlaceTreesRandomly().

## ◆ LandscapeGenerationCallback()

static void LandscapeGenerationCallback | ( | Window * | w,
|  | bool | confirmed
| ) |  |
| static

Definition at line 335 of file genworld_gui.cpp.

## ◆ MakeNewgameSettingsLive()

void MakeNewgameSettingsLive | ( |  | ) |
| extern

Definition at line 352 of file openttd.cpp.

## ◆ PrepareGenerateWorldProgress()

void PrepareGenerateWorldProgress | ( |  | ) |

Initializes the progress counters to the starting point.

Definition at line 1441 of file genworld_gui.cpp.

Referenced by GenerateWorld().

## ◆ SetGeneratingWorldProgress()

void SetGeneratingWorldProgress | ( | GenWorldProgress | cls,
|  | uint | total
| ) |  |

Set the total of a stage of the world generation.

Parameters

  cls | the current class we are in.
  total | Set the total expected items for this class.

Warning: this function isn't clever. Don't go from class 4 to 3. Go upwards, always. Also, progress works if total is zero, total works if progress is zero.

Definition at line 1520 of file genworld_gui.cpp.

Referenced by _GenerateWorld(), CreateRivers(), GenerateIndustries(), GenerateLandscape(), GenerateTowns(), and GenerateTrees().

## ◆ SetNewLandscapeType()

void SetNewLandscapeType | ( | LandscapeType | landscape | ) |

Changes landscape type and sets genworld window dirty.

Parameters

  landscape | new landscape type

Definition at line 69 of file genworld_gui.cpp.

References _settings_newgame, GameSettings::game_creation, InvalidateWindowClassesData(), GameCreationSettings::landscape, WC_GENERATE_LANDSCAPE, and WC_SELECT_GAME.

Referenced by GenerateLandscapeWindow::OnClick(), and CreateScenarioWindow::OnClick().

## ◆ ShowCreateScenario()

void ShowCreateScenario | ( |  | ) |

Show the window to create a scenario.

Definition at line 1314 of file genworld_gui.cpp.

References CloseWindowByClass(), GLWM_SCENARIO, and WC_GENERATE_LANDSCAPE.

Referenced by ScenarioEditorLandscapeGenerationWindow::OnClick().

## ◆ ShowGenerateLandscape()

void ShowGenerateLandscape | ( |  | ) |

Start with a normal game.

Definition at line 1041 of file genworld_gui.cpp.

References GLWM_GENERATE.

Referenced by CreateScenarioWindow::OnClick(), SelectGameWindow::OnClick(), and NetworkStartServerWindow::OnClick().

## ◆ ShowGenerateWorldProgress()

void ShowGenerateWorldProgress | ( |  | ) |

Show the window where a user can follow the process of the map generation.

Definition at line 1452 of file genworld_gui.cpp.

References BringWindowToFrontById(), and WC_MODAL_PROGRESS.

Referenced by GenerateWorld().

## ◆ ShowHeightmapLoad()

void ShowHeightmapLoad | ( |  | ) |

Start with loading a heightmap.

Definition at line 1047 of file genworld_gui.cpp.

References GLWM_HEIGHTMAP.

Referenced by SaveLoadWindow::OnClick().

## ◆ StartGeneratingLandscape()

static void StartGeneratingLandscape | ( | GenerateLandscapeWindowMode | mode | ) |
| static

Definition at line 317 of file genworld_gui.cpp.

## ◆ StartNewGameWithoutGUI()

void StartNewGameWithoutGUI | ( | uint32_t | seed | ) |

Start a normal game without the GUI.

Parameters

  seed | The seed of the new game.

Definition at line 1062 of file genworld_gui.cpp.

References _settings_newgame, GameSettings::game_creation, GameCreationSettings::generation_seed, and GLWM_GENERATE.

Referenced by VideoDriver_Dedicated::MainLoop(), SelectGameWindow::OnClick(), and NetworkStartServerWindow::OnClick().

## ◆ StartScenarioEditor()

void StartScenarioEditor | ( |  | ) |

Start with a scenario editor.

Definition at line 1053 of file genworld_gui.cpp.

References GLWM_SCENARIO.

Referenced by SelectGameWindow::OnClick().

## Variable Documentation

## ◆ _borders

const StringID _borders[] = {STR_MAPGEN_BORDER_RANDOMIZE, STR_MAPGEN_BORDER_MANUAL, STR_MAPGEN_BORDER_INFINITE_WATER}
| static

Definition at line 382 of file genworld_gui.cpp.

## ◆ _elevations

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}
| static

Definition at line 379 of file genworld_gui.cpp.

## ◆ _generation_class_table

const StringID _generation_class_table[]
| static

Initial value:
= {
STR_GENERATION_WORLD_GENERATION,
STR_GENERATION_LANDSCAPE_GENERATION,
STR_GENERATION_RIVER_GENERATION,
STR_GENERATION_CLEARING_TILES,
STR_GENERATION_TOWN_GENERATION,
STR_GENERATION_LAND_INDUSTRY_GENERATION,
STR_GENERATION_WATER_INDUSTRY_GENERATION,
STR_GENERATION_OBJECT_GENERATION,
STR_GENERATION_TREE_GENERATION,
STR_GENERATION_SETTINGUP_GAME,
STR_GENERATION_PREPARING_TILELOOP,
STR_GENERATION_PREPARING_SCRIPT,
STR_GENERATION_PREPARING_GAME
}

Definition at line 1346 of file genworld_gui.cpp.

## ◆ _nested_create_scenario_widgets

constexpr std::initializer_list<NWidgetPart> _nested_create_scenario_widgets
| staticconstexpr

Definition at line 1247 of file genworld_gui.cpp.

## ◆ _nested_generate_landscape_widgets

constexpr std::initializer_list<NWidgetPart> _nested_generate_landscape_widgets
| staticconstexpr

Widgets of GenerateLandscapeWindow when generating world.

Definition at line 77 of file genworld_gui.cpp.

## ◆ _nested_generate_progress_widgets

constexpr std::initializer_list<NWidgetPart> _nested_generate_progress_widgets
| staticconstexpr

Initial value:
= {
NWidget(WWT_CAPTION, COLOUR_GREY), SetStringTip(STR_GENERATION_WORLD, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
NWidget(WWT_PANEL, COLOUR_GREY),
NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0), SetPadding(WidgetDimensions::unscaled.modalpopup),
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GP_PROGRESS_BAR), SetFill(1, 0),
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GP_PROGRESS_TEXT), SetFill(1, 0),
NWidget(WWT_TEXTBTN, COLOUR_WHITE, WID_GP_ABORT), SetStringTip(STR_GENERATION_ABORT), SetFill(1, 0),
EndContainer(),
EndContainer(),
}
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:93
WID_GP_PROGRESS_TEXT
@ WID_GP_PROGRESS_TEXT
Text with the progress bar.
Definition genworld_widget.h:92
WID_GP_PROGRESS_BAR
@ WID_GP_PROGRESS_BAR
Progress bar.
Definition genworld_widget.h:91
WID_GP_ABORT
@ WID_GP_ABORT
Abort button.
Definition genworld_widget.h:93
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1219
SetPIP
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
Definition widget_type.h:1375
SetPadding
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.
Definition widget_type.h:1332
SetStringTip
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
Definition widget_type.h:1240
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1229
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1424
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:44
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:52
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:37

Definition at line 1320 of file genworld_gui.cpp.

## ◆ _nested_heightmap_load_widgets

constexpr std::initializer_list<NWidgetPart> _nested_heightmap_load_widgets
| staticconstexpr

Widgets of GenerateLandscapeWindow when loading heightmap.

Definition at line 201 of file genworld_gui.cpp.

## ◆ _num_inds

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}
| static

Definition at line 386 of file genworld_gui.cpp.

## ◆ _num_towns

const StringID _num_towns[] = {STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM}
| static

Definition at line 385 of file genworld_gui.cpp.

## ◆ _rivers

const StringID _rivers[] = {STR_RIVERS_NONE, STR_RIVERS_FEW, STR_RIVERS_MODERATE, STR_RIVERS_LOT}
| static

Definition at line 381 of file genworld_gui.cpp.

## ◆ _rotation

const StringID _rotation[] = {STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_COUNTER_CLOCKWISE, STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_CLOCKWISE}
| static

Definition at line 384 of file genworld_gui.cpp.

## ◆ _sea_lakes

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}
| static

Definition at line 380 of file genworld_gui.cpp.

## ◆ _smoothness

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}
| static

Definition at line 383 of file genworld_gui.cpp.

## ◆ _variety

const StringID _variety[] = {STR_VARIETY_NONE, STR_VARIETY_VERY_LOW, STR_VARIETY_LOW, STR_VARIETY_MEDIUM, STR_VARIETY_HIGH, STR_VARIETY_VERY_HIGH}
| static

Definition at line 387 of file genworld_gui.cpp.