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 
8 /** @file genworld.h Functions related to world/map generation. */
9 
10 #ifndef GENWORLD_H
11 #define GENWORLD_H
12 
13 #include "company_type.h"
14 #include <thread>
15 
16 /** Constants related to world generation */
17 enum LandscapeGenerator {
18 	/* Order of these enums has to be the same as in lang/english.txt
19 	 * Otherwise you will get inconsistent behaviour. */
20 	LG_ORIGINAL     = 0,  ///< The original landscape generator
21 	LG_TERRAGENESIS = 1,  ///< TerraGenesis Perlin landscape generator
22 };
23 
24 static const uint32 GENERATE_NEW_SEED = UINT32_MAX; ///< Create a new random seed
25 
26 /** Modes for GenerateWorld */
27 enum GenWorldMode {
28 	GWM_NEWGAME   = 0, ///< Generate a map for a new game
29 	GWM_EMPTY     = 1, ///< Generate an empty map (sea-level)
30 	GWM_RANDOM    = 2, ///< Generate a random map for SE
31 	GWM_HEIGHTMAP = 3, ///< Generate a newgame from a heightmap
32 };
33 
34 /** Smoothness presets. */
35 enum TgenSmoothness {
36 	TGEN_SMOOTHNESS_BEGIN,      ///< First smoothness value.
37 	TGEN_SMOOTHNESS_VERY_SMOOTH = TGEN_SMOOTHNESS_BEGIN, ///< Smoothness preset 'very smooth'.
38 	TGEN_SMOOTHNESS_SMOOTH,     ///< Smoothness preset 'smooth'.
39 	TGEN_SMOOTHNESS_ROUGH,      ///< Smoothness preset 'rough'.
40 	TGEN_SMOOTHNESS_VERY_ROUGH, ///< Smoothness preset 'very rough'.
41 
42 	TGEN_SMOOTHNESS_END,        ///< Used to iterate.
43 };
44 
45 static const uint CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY = 5; ///< Value for custom terrain type in difficulty settings.
46 
47 static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY = 4; ///< Value for custom sea level in difficulty settings.
48 static const uint CUSTOM_SEA_LEVEL_MIN_PERCENTAGE = 1;    ///< Minimum percentage a user can specify for custom sea level.
49 static const uint CUSTOM_SEA_LEVEL_MAX_PERCENTAGE = 90;   ///< Maximum percentage a user can specify for custom sea level.
50 
51 static const uint MAP_HEIGHT_LIMIT_AUTO_MINIMUM = 30; ///< When map height limit is auto, make this the lowest possible map height limit.
52 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.
53 
54 typedef void GWDoneProc();  ///< Procedure called when the genworld process finishes
55 typedef void GWAbortProc(); ///< Called when genworld is aborted
56 
57 /** Properties of current genworld process */
58 struct GenWorldInfo {
59 	bool abort;            ///< Whether to abort the thread ASAP
60 	GenWorldMode mode;     ///< What mode are we making a world in
61 	CompanyID lc;          ///< The local_company before generating
62 	uint size_x;           ///< X-size of the map
63 	uint size_y;           ///< Y-size of the map
64 	GWDoneProc *proc;      ///< Proc that is called when done (can be nullptr)
65 	GWAbortProc *abortp;   ///< Proc that is called when aborting (can be nullptr)
66 };
67 
68 /** Current stage of world generation process */
69 enum GenWorldProgress {
70 	GWP_MAP_INIT,    ///< Initialize/allocate the map, start economy
71 	GWP_LANDSCAPE,   ///< Create the landscape
72 	GWP_RIVER,       ///< Create the rivers
73 	GWP_ROUGH_ROCKY, ///< Make rough and rocky areas
74 	GWP_TOWN,        ///< Generate towns
75 	GWP_INDUSTRY,    ///< Generate industries
76 	GWP_OBJECT,      ///< Generate objects (radio tower, light houses)
77 	GWP_TREE,        ///< Generate trees
78 	GWP_GAME_INIT,   ///< Initialize the game
79 	GWP_RUNTILELOOP, ///< Runs the tile loop 1280 times to make snow etc
80 	GWP_RUNSCRIPT,   ///< Runs the game script at most 2500 times, or when ever the script sleeps
81 	GWP_GAME_START,  ///< Really prepare to start the game
82 	GWP_CLASS_COUNT
83 };
84 
85 /* genworld.cpp */
86 void GenerateWorldSetCallback(GWDoneProc *proc);
87 void GenerateWorldSetAbortCallback(GWAbortProc *proc);
88 void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_settings = true);
89 void AbortGeneratingWorld();
90 bool IsGeneratingWorldAborted();
91 void HandleGeneratingWorldAbortion();
92 
93 /* genworld_gui.cpp */
94 void SetNewLandscapeType(byte landscape);
95 void SetGeneratingWorldProgress(GenWorldProgress cls, uint total);
96 void IncreaseGeneratingWorldProgress(GenWorldProgress cls);
97 void PrepareGenerateWorldProgress();
98 void ShowGenerateWorldProgress();
99 void StartNewGameWithoutGUI(uint32 seed);
100 void ShowCreateScenario();
101 void StartScenarioEditor();
102 
103 extern bool _generating_world;
104 
105 #endif /* GENWORLD_H */
106