86
* Clean up the 'mess' of generation. That is show windows again, reset
87
* thread variables and delete the progress window.
89
static void CleanupGeneration()
91
_generating_world = false;
93
if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE);
94
/* Show all vital windows again, because we have hidden them */
95
if (_gw.threaded && _game_mode != GM_MENU) ShowVitalWindows();
101
DeleteWindowById(WC_GENERATE_PROGRESS_WINDOW, 0);
102
MarkWholeScreenDirty();
85
106
* The internal, real, generate function.
87
static void *_GenerateWorld(void *arg)
108
static void _GenerateWorld(void *arg)
89
_generating_world = true;
90
if (_network_dedicated) DEBUG(net, 0, "Generating map, please wait...");
91
/* Set the Random() seed to generation_seed so we produce the same map with the same seed */
92
if (_patches.generation_seed == GENERATE_NEW_SEED) _patches.generation_seed = _patches_newgame.generation_seed = InteractiveRandom();
93
_random.SetSeed(_patches.generation_seed);
94
SetGeneratingWorldProgress(GWP_MAP_INIT, 2);
95
SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, VHM_NONE, WC_MAIN_WINDOW, 0);
97
IncreaseGeneratingWorldProgress(GWP_MAP_INIT);
98
/* Must start economy early because of the costs. */
101
/* Don't generate landscape items when in the scenario editor. */
102
if (_gw.mode == GW_EMPTY) {
103
SetGeneratingWorldProgress(GWP_UNMOVABLE, 1);
105
/* Make the map the height of the patch setting */
106
if (_game_mode != GM_MENU) FlatEmptyWorld(_patches.se_flat_world_height);
108
ConvertGroundTilesIntoWaterTiles();
109
IncreaseGeneratingWorldProgress(GWP_UNMOVABLE);
111
GenerateLandscape(_gw.mode);
114
/* only generate towns, tree and industries in newgame mode. */
115
if (_game_mode != GM_EDITOR) {
117
GenerateIndustries();
118
GenerateUnmovables();
123
ClearStorageChanges(true);
125
/* These are probably pointless when inside the scenario editor. */
126
SetGeneratingWorldProgress(GWP_GAME_INIT, 3);
128
IncreaseGeneratingWorldProgress(GWP_GAME_INIT);
130
IncreaseGeneratingWorldProgress(GWP_GAME_INIT);
132
_generating_world = false;
134
/* No need to run the tile loop in the scenario editor. */
135
if (_gw.mode != GW_EMPTY) {
138
SetGeneratingWorldProgress(GWP_RUNTILELOOP, 0x500);
139
for (i = 0; i < 0x500; i++) {
141
IncreaseGeneratingWorldProgress(GWP_RUNTILELOOP);
145
ResetObjectToPlace();
146
SetLocalPlayer(_gw.lp);
148
SetGeneratingWorldProgress(GWP_GAME_START, 1);
149
/* Call any callback */
150
if (_gw.proc != NULL) _gw.proc();
151
IncreaseGeneratingWorldProgress(GWP_GAME_START);
153
if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE);
154
/* Show all vital windows again, because we have hidden them */
155
if (_gw.threaded && _game_mode != GM_MENU) ShowVitalWindows();
159
_gw.threaded = false;
161
DeleteWindowById(WC_GENERATE_PROGRESS_WINDOW, 0);
162
MarkWholeScreenDirty();
164
if (_network_dedicated) DEBUG(net, 0, "Map generated, starting game");
166
if (_patches.pause_on_newgame && _game_mode == GM_NORMAL) DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
111
_generating_world = true;
112
if (_network_dedicated) DEBUG(net, 0, "Generating map, please wait...");
113
/* Set the Random() seed to generation_seed so we produce the same map with the same seed */
114
if (_settings_game.game_creation.generation_seed == GENERATE_NEW_SEED) _settings_game.game_creation.generation_seed = _settings_newgame.game_creation.generation_seed = InteractiveRandom();
115
_random.SetSeed(_settings_game.game_creation.generation_seed);
116
SetGeneratingWorldProgress(GWP_MAP_INIT, 2);
117
SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, VHM_NONE, WC_MAIN_WINDOW, 0);
119
IncreaseGeneratingWorldProgress(GWP_MAP_INIT);
120
/* Must start economy early because of the costs. */
123
/* Don't generate landscape items when in the scenario editor. */
124
if (_gw.mode == GW_EMPTY) {
125
SetGeneratingWorldProgress(GWP_UNMOVABLE, 1);
127
/* Make sure the tiles at the north border are void tiles if needed. */
128
if (_settings_game.construction.freeform_edges) {
129
for (uint row = 0; row < MapSizeY(); row++) MakeVoid(TileXY(0, row));
130
for (uint col = 0; col < MapSizeX(); col++) MakeVoid(TileXY(col, 0));
133
/* Make the map the height of the setting */
134
if (_game_mode != GM_MENU) FlatEmptyWorld(_settings_game.game_creation.se_flat_world_height);
136
ConvertGroundTilesIntoWaterTiles();
137
IncreaseGeneratingWorldProgress(GWP_UNMOVABLE);
139
GenerateLandscape(_gw.mode);
142
/* only generate towns, tree and industries in newgame mode. */
143
if (_game_mode != GM_EDITOR) {
144
if (!GenerateTowns(_settings_game.economy.town_layout)) {
145
HandleGeneratingWorldAbortion();
148
GenerateIndustries();
149
GenerateUnmovables();
154
ClearStorageChanges(true);
156
/* These are probably pointless when inside the scenario editor. */
157
SetGeneratingWorldProgress(GWP_GAME_INIT, 3);
159
IncreaseGeneratingWorldProgress(GWP_GAME_INIT);
161
IncreaseGeneratingWorldProgress(GWP_GAME_INIT);
163
_generating_world = false;
165
/* No need to run the tile loop in the scenario editor. */
166
if (_gw.mode != GW_EMPTY) {
169
SetGeneratingWorldProgress(GWP_RUNTILELOOP, 0x500);
170
for (i = 0; i < 0x500; i++) {
172
IncreaseGeneratingWorldProgress(GWP_RUNTILELOOP);
176
ResetObjectToPlace();
177
_local_company = _gw.lc;
179
SetGeneratingWorldProgress(GWP_GAME_START, 1);
180
/* Call any callback */
181
if (_gw.proc != NULL) _gw.proc();
182
IncreaseGeneratingWorldProgress(GWP_GAME_START);
186
if (_network_dedicated) DEBUG(net, 0, "Map generated, starting game");
187
DEBUG(desync, 1, "new_map: %i\n", _settings_game.game_creation.generation_seed);
189
if (_settings_client.gui.pause_on_newgame && _game_mode == GM_NORMAL) DoCommandP(0, 1, 0, CMD_PAUSE);
190
if (_debug_desync_level > 0) {
192
snprintf(name, lengthof(name), "dmp_cmds_%08x_%08x.sav", _settings_game.game_creation.generation_seed, _date);
193
SaveOrLoad(name, SL_SAVE, AUTOSAVE_DIR);
196
_generating_world = false;
255
279
_gw.active = true;
256
280
_gw.abort = false;
257
281
_gw.abortp = NULL;
258
_gw.lp = _local_player;
282
_gw.lc = _local_company;
259
283
_gw.wait_for_draw = false;
260
284
_gw.quit_thread = false;
261
285
_gw.threaded = true;
263
287
/* This disables some commands and stuff */
264
SetLocalPlayer(PLAYER_SPECTATOR);
288
SetLocalCompany(COMPANY_SPECTATOR);
265
289
/* Make sure everything is done via OWNER_NONE */
266
_current_player = OWNER_NONE;
290
_current_company = OWNER_NONE;
268
292
/* Set the date before loading sprites as some newgrfs check it */
269
SetDate(ConvertYMDToDate(_patches.starting_year, 0, 1));
293
SetDate(ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1));
271
295
/* Load the right landscape stuff */
272
296
GfxLoadSprites();
273
297
LoadStringWidthTable();
275
InitializeGame(IG_NONE, _gw.size_x, _gw.size_y);
299
InitializeGame(_gw.size_x, _gw.size_y, false);
276
300
PrepareGenerateWorldProgress();
278
302
/* Re-init the windowing system */
279
303
ResetWindowSystem();
281
305
/* Create toolbars */
282
SetupColorsAndInitialWindow();
284
if (_network_dedicated ||
285
(_gw.thread = OTTDCreateThread(&_GenerateWorld, NULL)) == NULL) {
306
SetupColoursAndInitialWindow();
308
if (_gw.thread != NULL) {
314
if (BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 0 ||
315
!ThreadObject::New(&_GenerateWorld, NULL, &_gw.thread)) {
286
316
DEBUG(misc, 1, "Cannot create genworld thread, reverting to single-threaded mode");
287
317
_gw.threaded = false;
288
318
_GenerateWorld(NULL);