OpenTTD Source 20241224-master-gf74b0cf984
genworld.h File Reference

Functions related to world/map generation. More...

#include "company_type.h"
#include <thread>

Go to the source code of this file.

Data Structures

struct  GenWorldInfo
 Properties of current genworld process. More...
 

Typedefs

typedef void GWDoneProc()
 Procedure called when the genworld process finishes.
 
typedef void GWAbortProc()
 Called when genworld is aborted.
 

Enumerations

enum  LandscapeGenerator { LG_ORIGINAL = 0 , LG_TERRAGENESIS = 1 }
 Constants related to world generation. More...
 
enum  GenWorldMode { GWM_NEWGAME = 0 , GWM_EMPTY = 1 , GWM_RANDOM = 2 , GWM_HEIGHTMAP = 3 }
 Modes for GenerateWorld. More...
 
enum  TgenSmoothness {
  TGEN_SMOOTHNESS_BEGIN , TGEN_SMOOTHNESS_VERY_SMOOTH = TGEN_SMOOTHNESS_BEGIN , TGEN_SMOOTHNESS_SMOOTH , TGEN_SMOOTHNESS_ROUGH ,
  TGEN_SMOOTHNESS_VERY_ROUGH , TGEN_SMOOTHNESS_END
}
 Smoothness presets. More...
 
enum  GenWorldProgress {
  GWP_MAP_INIT , GWP_LANDSCAPE , GWP_RIVER , GWP_ROUGH_ROCKY ,
  GWP_TOWN , GWP_INDUSTRY , GWP_OBJECT , GWP_TREE ,
  GWP_GAME_INIT , GWP_RUNTILELOOP , GWP_RUNSCRIPT , GWP_GAME_START ,
  GWP_CLASS_COUNT
}
 Current stage of world generation process. More...
 

Functions

void GenerateWorldSetCallback (GWDoneProc *proc)
 Set here the function, if any, that you want to be called when landscape generation is done.
 
void GenerateWorldSetAbortCallback (GWAbortProc *proc)
 Set here the function, if any, that you want to be called when landscape generation is aborted.
 
void GenerateWorld (GenWorldMode mode, uint size_x, uint size_y, bool reset_settings=true)
 Generate a world.
 
void AbortGeneratingWorld ()
 Initializes the abortion process.
 
bool IsGeneratingWorldAborted ()
 Is the generation being aborted?
 
void HandleGeneratingWorldAbortion ()
 Really handle the abortion, i.e.
 
void LoadTownData ()
 Load town data from _file_to_saveload, place towns at the appropriate locations, and expand them to their target populations.
 
void SetNewLandscapeType (uint8_t landscape)
 Changes landscape type and sets genworld window dirty.
 
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.
 
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.
 
void StartNewGameWithoutGUI (uint32_t seed)
 Start a normal game without the GUI.
 
void ShowCreateScenario ()
 Show the window to create a scenario.
 
void StartScenarioEditor ()
 Start with a scenario editor.
 

Variables

static const uint32_t GENERATE_NEW_SEED = UINT32_MAX
 Create a new random seed.
 
static const uint CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY = 5
 Value for custom terrain type in difficulty settings.
 
static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY = 4
 Value for custom sea level in difficulty settings.
 
static const uint CUSTOM_SEA_LEVEL_MIN_PERCENTAGE = 1
 Minimum percentage a user can specify for custom sea level.
 
static const uint CUSTOM_SEA_LEVEL_MAX_PERCENTAGE = 90
 Maximum percentage a user can specify for custom sea level.
 
static const uint MAP_HEIGHT_LIMIT_AUTO_MINIMUM = 30
 When map height limit is auto, make this the lowest possible map height limit.
 
static const uint MAP_HEIGHT_LIMIT_AUTO_CEILING_ROOM = 15
 When map height limit is auto, the map height limit will be the higest peak plus this value.
 
bool _generating_world
 Whether we are generating the map or not.
 

Detailed Description

Functions related to world/map generation.

Definition in file genworld.h.

Typedef Documentation

◆ GWAbortProc

typedef void GWAbortProc()

Called when genworld is aborted.

Definition at line 55 of file genworld.h.

◆ GWDoneProc

typedef void GWDoneProc()

Procedure called when the genworld process finishes.

Definition at line 54 of file genworld.h.

Enumeration Type Documentation

◆ GenWorldMode

Modes for GenerateWorld.

Enumerator
GWM_NEWGAME 

Generate a map for a new game.

GWM_EMPTY 

Generate an empty map (sea-level)

GWM_RANDOM 

Generate a random map for SE.

GWM_HEIGHTMAP 

Generate a newgame from a heightmap.

Definition at line 27 of file genworld.h.

◆ GenWorldProgress

Current stage of world generation process.

Enumerator
GWP_MAP_INIT 

Initialize/allocate the map, start economy.

GWP_LANDSCAPE 

Create the landscape.

GWP_RIVER 

Create the rivers.

GWP_ROUGH_ROCKY 

Make rough and rocky areas.

GWP_TOWN 

Generate towns.

GWP_INDUSTRY 

Generate industries.

GWP_OBJECT 

Generate objects (radio tower, light houses)

GWP_TREE 

Generate trees.

GWP_GAME_INIT 

Initialize the game.

GWP_RUNTILELOOP 

Runs the tile loop 1280 times to make snow etc.

GWP_RUNSCRIPT 

Runs the game script at most 2500 times, or when ever the script sleeps.

GWP_GAME_START 

Really prepare to start the game.

Definition at line 69 of file genworld.h.

◆ LandscapeGenerator

Constants related to world generation.

Enumerator
LG_ORIGINAL 

The original landscape generator.

LG_TERRAGENESIS 

TerraGenesis Perlin landscape generator.

Definition at line 17 of file genworld.h.

◆ TgenSmoothness

Smoothness presets.

Enumerator
TGEN_SMOOTHNESS_BEGIN 

First smoothness value.

TGEN_SMOOTHNESS_VERY_SMOOTH 

Smoothness preset 'very smooth'.

TGEN_SMOOTHNESS_SMOOTH 

Smoothness preset 'smooth'.

TGEN_SMOOTHNESS_ROUGH 

Smoothness preset 'rough'.

TGEN_SMOOTHNESS_VERY_ROUGH 

Smoothness preset 'very rough'.

TGEN_SMOOTHNESS_END 

Used to iterate.

Definition at line 35 of file genworld.h.

Function Documentation

◆ AbortGeneratingWorld()

void AbortGeneratingWorld ( )

Initializes the abortion process.

Definition at line 252 of file genworld.cpp.

References _gw, and GenWorldInfo::abort.

◆ GenerateWorld()

◆ GenerateWorldSetAbortCallback()

void GenerateWorldSetAbortCallback ( GWAbortProc proc)

Set here the function, if any, that you want to be called when landscape generation is aborted.

Parameters
proccallback procedure

Definition at line 244 of file genworld.cpp.

References _gw, and GenWorldInfo::abortp.

Referenced by GenerateTerrainPerlin().

◆ GenerateWorldSetCallback()

void GenerateWorldSetCallback ( GWDoneProc proc)

Set here the function, if any, that you want to be called when landscape generation is done.

Parameters
proccallback procedure

Definition at line 234 of file genworld.cpp.

References _gw, and GenWorldInfo::proc.

◆ HandleGeneratingWorldAbortion()

void HandleGeneratingWorldAbortion ( )

Really handle the abortion, i.e.

clean up some of the mess

Definition at line 269 of file genworld.cpp.

References _gw, _switch_mode, GenWorldInfo::abortp, SM_EDITOR, and SM_MENU.

Referenced by _GenerateWorld().

◆ IncreaseGeneratingWorldProgress()

void IncreaseGeneratingWorldProgress ( GenWorldProgress  cls)

Increases the current stage of the world generation with one.

Parameters
clsthe 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 1547 of file genworld_gui.cpp.

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

◆ IsGeneratingWorldAborted()

bool IsGeneratingWorldAborted ( )

Is the generation being aborted?

Returns
the 'aborted' status

Definition at line 261 of file genworld.cpp.

References _gw, and GenWorldInfo::abort.

◆ LoadTownData()

◆ PrepareGenerateWorldProgress()

void PrepareGenerateWorldProgress ( )

Initializes the progress counters to the starting point.

Definition at line 1453 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
clsthe current class we are in.
totalSet 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 1533 of file genworld_gui.cpp.

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

◆ SetNewLandscapeType()

void SetNewLandscapeType ( uint8_t  landscape)

Changes landscape type and sets genworld window dirty.

Parameters
landscapenew landscape type

Definition at line 65 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(), CreateScenarioWindow::OnClick(), and SelectGameWindow::OnClick().

◆ ShowCreateScenario()

void ShowCreateScenario ( )

Show the window to create a scenario.

Definition at line 1321 of file genworld_gui.cpp.

References CloseWindowByClass(), GLWM_SCENARIO, and WC_GENERATE_LANDSCAPE.

Referenced by ScenarioEditorLandscapeGenerationWindow::OnClick().

◆ ShowGenerateWorldProgress()

void ShowGenerateWorldProgress ( )

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

Definition at line 1465 of file genworld_gui.cpp.

References BringWindowToFrontById(), and WC_MODAL_PROGRESS.

Referenced by GenerateWorld().

◆ StartNewGameWithoutGUI()

void StartNewGameWithoutGUI ( uint32_t  seed)

Start a normal game without the GUI.

Parameters
seedThe seed of the new game.

Definition at line 1066 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 1057 of file genworld_gui.cpp.

References GLWM_SCENARIO.

Referenced by SelectGameWindow::OnClick().

Variable Documentation

◆ _generating_world

◆ CUSTOM_SEA_LEVEL_MAX_PERCENTAGE

const uint CUSTOM_SEA_LEVEL_MAX_PERCENTAGE = 90
static

Maximum percentage a user can specify for custom sea level.

Definition at line 49 of file genworld.h.

Referenced by GenerateLandscapeWindow::OnQueryTextFinished(), and GenerateLandscapeWindow::UpdateWidgetSize().

◆ CUSTOM_SEA_LEVEL_MIN_PERCENTAGE

const uint CUSTOM_SEA_LEVEL_MIN_PERCENTAGE = 1
static

Minimum percentage a user can specify for custom sea level.

Definition at line 48 of file genworld.h.

Referenced by GenerateLandscapeWindow::OnQueryTextFinished(), and ValidateSettings().

◆ CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY

const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY = 4
static

◆ CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY

const uint CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY = 5
static

Value for custom terrain type in difficulty settings.

Definition at line 45 of file genworld.h.

Referenced by GenerateLandscapeWindow::OnDropdownSelect(), GenerateLandscapeWindow::OnInvalidateData(), GenerateLandscapeWindow::SetStringParameters(), and TGPGetMaxHeight().

◆ GENERATE_NEW_SEED

const uint32_t GENERATE_NEW_SEED = UINT32_MAX
static

◆ MAP_HEIGHT_LIMIT_AUTO_CEILING_ROOM

const uint MAP_HEIGHT_LIMIT_AUTO_CEILING_ROOM = 15
static

When map height limit is auto, the map height limit will be the higest peak plus this value.

Definition at line 52 of file genworld.h.

Referenced by GenerateWorld().

◆ MAP_HEIGHT_LIMIT_AUTO_MINIMUM

const uint MAP_HEIGHT_LIMIT_AUTO_MINIMUM = 30
static

When map height limit is auto, make this the lowest possible map height limit.

Definition at line 51 of file genworld.h.

Referenced by GenerateWorld(), and GenerateLandscapeWindow::OnQueryTextFinished().