OpenTTD Source  1.11.0-beta2
genworld.h
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 #ifndef GENWORLD_H
11 #define GENWORLD_H
12 
13 #include "company_type.h"
14 #include <thread>
15 
18  /* Order of these enums has to be the same as in lang/english.txt
19  * Otherwise you will get inconsistent behaviour. */
22 };
23 
24 static const uint32 GENERATE_NEW_SEED = UINT32_MAX;
25 
29  GWM_EMPTY = 1,
30  GWM_RANDOM = 2,
32 };
33 
41 
43 };
44 
45 static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY = 4;
46 static const uint CUSTOM_SEA_LEVEL_MIN_PERCENTAGE = 1;
47 static const uint CUSTOM_SEA_LEVEL_MAX_PERCENTAGE = 90;
48 
49 typedef void GWDoneProc();
50 typedef void GWAbortProc();
51 
53 struct GenWorldInfo {
54  bool abort;
55  bool quit_thread;
56  bool threaded;
59  uint size_x;
60  uint size_y;
63  std::thread thread;
64 };
65 
80  GWP_CLASS_COUNT
81 };
82 
83 /* genworld.cpp */
88 void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_settings = true);
92 
93 /* genworld_gui.cpp */
94 void SetNewLandscapeType(byte landscape);
95 void SetGeneratingWorldProgress(GenWorldProgress cls, uint total);
99 void StartNewGameWithoutGUI(uint32 seed);
100 void ShowCreateScenario();
101 void StartScenarioEditor();
102 
103 extern bool _generating_world;
104 
105 #endif /* GENWORLD_H */
GenWorldInfo::size_y
uint size_y
Y-size of the map.
Definition: genworld.h:60
GWP_GAME_INIT
@ GWP_GAME_INIT
Initialize the game.
Definition: genworld.h:76
ShowGenerateWorldProgress
void ShowGenerateWorldProgress()
Show the window where a user can follow the process of the map generation.
Definition: genworld_gui.cpp:1303
GWP_RUNTILELOOP
@ GWP_RUNTILELOOP
Runs the tile loop 1280 times to make snow etc.
Definition: genworld.h:77
GenWorldInfo::abort
bool abort
Whether to abort the thread ASAP.
Definition: genworld.h:54
GenWorldInfo::lc
CompanyID lc
The local_company before generating.
Definition: genworld.h:58
GenerateWorld
void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_settings=true)
Generate a world.
Definition: genworld.cpp:301
GenWorldInfo::abortp
GWAbortProc * abortp
Proc that is called when aborting (can be nullptr)
Definition: genworld.h:62
WaitTillGeneratedWorld
void WaitTillGeneratedWorld()
This will wait for the thread to finish up his work.
Definition: genworld.cpp:247
CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
static const uint CUSTOM_SEA_LEVEL_MIN_PERCENTAGE
Minimum percentage a user can specify for custom sea level.
Definition: genworld.h:46
LandscapeGenerator
LandscapeGenerator
Constants related to world generation.
Definition: genworld.h:17
_generating_world
bool _generating_world
Whether we are generating the map or not.
Definition: genworld.cpp:60
GenWorldInfo::mode
GenWorldMode mode
What mode are we making a world in.
Definition: genworld.h:57
GenerateWorldSetCallback
void GenerateWorldSetCallback(GWDoneProc *proc)
Set here the function, if any, that you want to be called when landscape generation is done.
Definition: genworld.cpp:228
LG_ORIGINAL
@ LG_ORIGINAL
The original landscape generator.
Definition: genworld.h:20
GenWorldInfo::threaded
bool threaded
Whether we run _GenerateWorld threaded.
Definition: genworld.h:56
GWAbortProc
void GWAbortProc()
Called when genworld is aborted.
Definition: genworld.h:50
GWP_INDUSTRY
@ GWP_INDUSTRY
Generate industries.
Definition: genworld.h:73
GenWorldInfo::thread
std::thread thread
The thread we are in (joinable if a thread was created)
Definition: genworld.h:63
Owner
Owner
Enum for all companies/owners.
Definition: company_type.h:18
StartScenarioEditor
void StartScenarioEditor()
Start with a scenario editor.
Definition: genworld_gui.cpp:903
TGEN_SMOOTHNESS_BEGIN
@ TGEN_SMOOTHNESS_BEGIN
First smoothness value.
Definition: genworld.h:36
GENERATE_NEW_SEED
static const uint32 GENERATE_NEW_SEED
Create a new random seed.
Definition: genworld.h:24
IncreaseGeneratingWorldProgress
void IncreaseGeneratingWorldProgress(GenWorldProgress cls)
Increases the current stage of the world generation with one.
Definition: genworld_gui.cpp:1392
GWP_LANDSCAPE
@ GWP_LANDSCAPE
Create the landscape.
Definition: genworld.h:69
GenWorldInfo::proc
GWDoneProc * proc
Proc that is called when done (can be nullptr)
Definition: genworld.h:61
TGEN_SMOOTHNESS_ROUGH
@ TGEN_SMOOTHNESS_ROUGH
Smoothness preset 'rough'.
Definition: genworld.h:39
GWM_HEIGHTMAP
@ GWM_HEIGHTMAP
Generate a newgame from a heightmap.
Definition: genworld.h:31
ShowCreateScenario
void ShowCreateScenario()
Show the window to create a scenario.
Definition: genworld_gui.cpp:1159
GWM_RANDOM
@ GWM_RANDOM
Generate a random map for SE.
Definition: genworld.h:30
CUSTOM_SEA_LEVEL_MAX_PERCENTAGE
static const uint CUSTOM_SEA_LEVEL_MAX_PERCENTAGE
Maximum percentage a user can specify for custom sea level.
Definition: genworld.h:47
GWP_ROUGH_ROCKY
@ GWP_ROUGH_ROCKY
Make rough and rocky areas.
Definition: genworld.h:71
GWP_GAME_START
@ GWP_GAME_START
Really prepare to start the game.
Definition: genworld.h:79
GWP_OBJECT
@ GWP_OBJECT
Generate objects (radio tower, light houses)
Definition: genworld.h:74
TGEN_SMOOTHNESS_VERY_SMOOTH
@ TGEN_SMOOTHNESS_VERY_SMOOTH
Smoothness preset 'very smooth'.
Definition: genworld.h:37
GWP_MAP_INIT
@ GWP_MAP_INIT
Initialize/allocate the map, start economy.
Definition: genworld.h:68
StartNewGameWithoutGUI
void StartNewGameWithoutGUI(uint32 seed)
Start a normal game without the GUI.
Definition: genworld_gui.cpp:912
GenWorldInfo
Properties of current genworld process.
Definition: genworld.h:53
GenWorldProgress
GenWorldProgress
Current stage of world generation process.
Definition: genworld.h:67
TgenSmoothness
TgenSmoothness
Smoothness presets.
Definition: genworld.h:35
TGEN_SMOOTHNESS_END
@ TGEN_SMOOTHNESS_END
Used to iterate.
Definition: genworld.h:42
PrepareGenerateWorldProgress
void PrepareGenerateWorldProgress()
Initializes the progress counters to the starting point.
Definition: genworld_gui.cpp:1291
TGEN_SMOOTHNESS_VERY_ROUGH
@ TGEN_SMOOTHNESS_VERY_ROUGH
Smoothness preset 'very rough'.
Definition: genworld.h:40
SetGeneratingWorldProgress
void SetGeneratingWorldProgress(GenWorldProgress cls, uint total)
Set the total of a stage of the world generation.
Definition: genworld_gui.cpp:1378
SetNewLandscapeType
void SetNewLandscapeType(byte landscape)
Changes landscape type and sets genworld window dirty.
Definition: genworld_gui.cpp:51
GenWorldInfo::quit_thread
bool quit_thread
Do we want to quit the active thread.
Definition: genworld.h:55
GWM_EMPTY
@ GWM_EMPTY
Generate an empty map (sea-level)
Definition: genworld.h:29
LG_TERRAGENESIS
@ LG_TERRAGENESIS
TerraGenesis Perlin landscape generator.
Definition: genworld.h:21
IsGeneratingWorldAborted
bool IsGeneratingWorldAborted()
Is the generation being aborted?
Definition: genworld.cpp:272
GWM_NEWGAME
@ GWM_NEWGAME
Generate a map for a new game.
Definition: genworld.h:28
GenWorldInfo::size_x
uint size_x
X-size of the map.
Definition: genworld.h:59
GWP_RIVER
@ GWP_RIVER
Create the rivers.
Definition: genworld.h:70
IsGenerateWorldThreaded
bool IsGenerateWorldThreaded()
Tells if the world generation is done in a thread or not.
Definition: genworld.cpp:66
GenWorldMode
GenWorldMode
Modes for GenerateWorld.
Definition: genworld.h:27
GWDoneProc
void GWDoneProc()
Procedure called when the genworld process finishes.
Definition: genworld.h:49
HandleGeneratingWorldAbortion
void HandleGeneratingWorldAbortion()
Really handle the abortion, i.e.
Definition: genworld.cpp:280
CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY
static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY
Value for custom sea level in difficulty settings.
Definition: genworld.h:45
GenerateWorldSetAbortCallback
void GenerateWorldSetAbortCallback(GWAbortProc *proc)
Set here the function, if any, that you want to be called when landscape generation is aborted.
Definition: genworld.cpp:238
GWP_TOWN
@ GWP_TOWN
Generate towns.
Definition: genworld.h:72
company_type.h
AbortGeneratingWorld
void AbortGeneratingWorld()
Initializes the abortion process.
Definition: genworld.cpp:263
TGEN_SMOOTHNESS_SMOOTH
@ TGEN_SMOOTHNESS_SMOOTH
Smoothness preset 'smooth'.
Definition: genworld.h:38
GWP_RUNSCRIPT
@ GWP_RUNSCRIPT
Runs the game script at most 2500 times, or when ever the script sleeps.
Definition: genworld.h:78
GWP_TREE
@ GWP_TREE
Generate trees.
Definition: genworld.h:75