OpenTTD
Data Structures | Typedefs | Enumerations | Functions | Variables
genworld.h File Reference

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

#include "company_type.h"

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

bool IsGenerateWorldThreaded ()
 Tells if the world generation is done in a thread or not. More...
 
void GenerateWorldSetCallback (GWDoneProc *proc)
 Set here the function, if any, that you want to be called when landscape generation is done. More...
 
void GenerateWorldSetAbortCallback (GWAbortProc *proc)
 Set here the function, if any, that you want to be called when landscape generation is aborted. More...
 
void WaitTillGeneratedWorld ()
 This will wait for the thread to finish up his work. More...
 
void GenerateWorld (GenWorldMode mode, uint size_x, uint size_y, bool reset_settings=true)
 Generate a world. More...
 
void AbortGeneratingWorld ()
 Initializes the abortion process.
 
bool IsGeneratingWorldAborted ()
 Is the generation being aborted? More...
 
void HandleGeneratingWorldAbortion ()
 Really handle the abortion, i.e. More...
 
void SetNewLandscapeType (byte landscape)
 Changes landscape type and sets genworld window dirty. More...
 
void SetGeneratingWorldProgress (GenWorldProgress cls, uint total)
 Set the total of a stage of the world generation. More...
 
void IncreaseGeneratingWorldProgress (GenWorldProgress cls)
 Increases the current stage of the world generation with one. More...
 
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 (uint seed)
 Start a normal game without the GUI. More...
 
void ShowCreateScenario ()
 Show the window to create a scenario. More...
 
void StartScenarioEditor ()
 Start with a scenario editor. More...
 

Variables

static const uint GENERATE_NEW_SEED = UINT_MAX
 Create a new random seed.
 
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.
 
bool _generating_world
 Whether we are generating the map or not. More...
 

Detailed Description

Functions related to world/map generation.

Definition in 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 28 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 68 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 18 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 36 of file genworld.h.

Function Documentation

◆ GenerateWorld()

void GenerateWorld ( GenWorldMode  mode,
uint  size_x,
uint  size_y,
bool  reset_settings 
)

Generate a world.

Parameters
modeThe mode of world generation (see GenWorldMode).
size_xThe X-size of the map.
size_yThe Y-size of the map.
reset_settingsWhether to reset the game configuration (used for restart)

Definition at line 298 of file genworld.cpp.

References _local_company, GenWorldInfo::abort, GenWorldInfo::abortp, COMPANY_SPECTATOR, HasModalProgress(), GenWorldInfo::lc, GenWorldInfo::mode, GenWorldInfo::quit_thread, SetLocalCompany(), SetModalProgress(), GenWorldInfo::size_x, GenWorldInfo::size_y, and GenWorldInfo::threaded.

◆ 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 233 of file genworld.cpp.

References 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 223 of file genworld.cpp.

References GenWorldInfo::proc.

◆ HandleGeneratingWorldAbortion()

void HandleGeneratingWorldAbortion ( )

Really handle the abortion, i.e.

clean up some of the mess

Definition at line 277 of file genworld.cpp.

References _switch_mode.

◆ 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 1354 of file genworld_gui.cpp.

Referenced by CreateRivers(), and GenerateTerrainPerlin().

◆ IsGenerateWorldThreaded()

bool IsGenerateWorldThreaded ( )

Tells if the world generation is done in a thread or not.

Returns
the 'threaded' status

Definition at line 67 of file genworld.cpp.

References GenWorldInfo::quit_thread, and GenWorldInfo::threaded.

◆ IsGeneratingWorldAborted()

bool IsGeneratingWorldAborted ( )

Is the generation being aborted?

Returns
the 'aborted' status

Definition at line 269 of file genworld.cpp.

References GenWorldInfo::abort.

◆ 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 1340 of file genworld_gui.cpp.

Referenced by CreateRivers().

◆ SetNewLandscapeType()

void SetNewLandscapeType ( byte  landscape)

Changes landscape type and sets genworld window dirty.

Parameters
landscapenew landscape type

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

References DeleteWindowByClass(), GLWM_SCENARIO, and WC_GENERATE_LANDSCAPE.

◆ StartNewGameWithoutGUI()

void StartNewGameWithoutGUI ( uint  seed)

Start a normal game without the GUI.

Parameters
seedThe seed of the new game.

Definition at line 873 of file genworld_gui.cpp.

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

Referenced by NetworkCheckRestartMap(), and SelectGameWindow::OnClick().

◆ StartScenarioEditor()

void StartScenarioEditor ( )

Start with a scenario editor.

Definition at line 864 of file genworld_gui.cpp.

Referenced by SelectGameWindow::OnClick().

◆ WaitTillGeneratedWorld()

void WaitTillGeneratedWorld ( )

This will wait for the thread to finish up his work.

It will not continue till the work is done.

Definition at line 242 of file genworld.cpp.

References _modal_progress_paint_mutex, _modal_progress_work_mutex, ThreadMutex::BeginCritical(), ThreadMutex::EndCritical(), ThreadObject::Join(), GenWorldInfo::quit_thread, GenWorldInfo::thread, and GenWorldInfo::threaded.

Variable Documentation

◆ _generating_world

bool _generating_world