Mercurial > hg > openttd
annotate src/genworld.cpp @ 10123:57aa34285d05 draft
(svn r14307) -Fix: when deleting a station, remove news items regarding it
author | smatz <smatz@openttd.org> |
---|---|
date | Sat, 13 Sep 2008 10:19:51 +0000 |
parents | 14e241fadc66 |
children | c54d140df948 |
rev | line source |
---|---|
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
1 /* $Id$ */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
2 |
9111
d48433370037
(svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium <rubidium@openttd.org>
parents:
8963
diff
changeset
|
3 /** @file genworld.cpp Functions to generate a map. */ |
6179
e3e61b92574b
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
5893
diff
changeset
|
4 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
5 #include "stdafx.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
6 #include "openttd.h" |
6453
666fc3ef3174
(svn r9609) -Codechange: Move some function prototypes out of functions.h and into landscape.h, and add a few where they didn't exist.
maedhros <maedhros@openttd.org>
parents:
6247
diff
changeset
|
7 #include "landscape.h" |
8254
7d580c9c41fb
(svn r11818) -Codechange: split player.h into smaller pieces.
rubidium <rubidium@openttd.org>
parents:
8225
diff
changeset
|
8 #include "player_func.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
9 #include "variables.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
10 #include "thread.h" |
8116
9cc845deddfe
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium <rubidium@openttd.org>
parents:
8107
diff
changeset
|
11 #include "command_func.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
12 #include "genworld.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
13 #include "gfxinit.h" |
8107
f65cf2bc3255
(svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium <rubidium@openttd.org>
parents:
7889
diff
changeset
|
14 #include "window_func.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
15 #include "network/network.h" |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
16 #include "debug.h" |
8208
ddc34919158f
(svn r11771) -Codechange: split settings.h into better separated headers.
rubidium <rubidium@openttd.org>
parents:
8142
diff
changeset
|
17 #include "settings_func.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
18 #include "heightmap.h" |
8225
0e48dd14a0d8
(svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium <rubidium@openttd.org>
parents:
8208
diff
changeset
|
19 #include "viewport_func.h" |
0e48dd14a0d8
(svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium <rubidium@openttd.org>
parents:
8208
diff
changeset
|
20 #include "gfx_func.h" |
8139
db99ba38abc0
(svn r11701) -Codechange: removal unnecessary inclusions of map.h (and split map.h).
rubidium <rubidium@openttd.org>
parents:
8138
diff
changeset
|
21 #include "map_func.h" |
8140
fb8a05d579da
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium <rubidium@openttd.org>
parents:
8139
diff
changeset
|
22 #include "date_func.h" |
8142
31f5d2fa3bb7
(svn r11704) -Codechange: remove another bunch of useless includes.
rubidium <rubidium@openttd.org>
parents:
8140
diff
changeset
|
23 #include "core/random_func.hpp" |
8786
e2d4956b7251
(svn r12490) -Codechange: rename engine.h to engine_func.h and remove unneeded inclusions of engine.h and/or replace them with engine_type.h.
rubidium <rubidium@openttd.org>
parents:
8434
diff
changeset
|
24 #include "engine_func.h" |
8270
5613b863190d
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium <rubidium@openttd.org>
parents:
8264
diff
changeset
|
25 #include "settings_type.h" |
8303
0ab35f1b5949
(svn r11867) -Fix: do not reset changes to persistent storages during world generation.
rubidium <rubidium@openttd.org>
parents:
8270
diff
changeset
|
26 #include "newgrf_storage.h" |
8380
ccf4087c045f
(svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch <frosch@openttd.org>
parents:
8303
diff
changeset
|
27 #include "water.h" |
9127
428852b86d4d
(svn r12987) -Codechange: split viewport and tile selection.
rubidium <rubidium@openttd.org>
parents:
9111
diff
changeset
|
28 #include "tilehighlight_func.h" |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
29 |
8264
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8254
diff
changeset
|
30 #include "table/sprites.h" |
2495310e220f
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium <rubidium@openttd.org>
parents:
8254
diff
changeset
|
31 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6179
diff
changeset
|
32 void GenerateClearTile(); |
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6179
diff
changeset
|
33 void GenerateIndustries(); |
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6179
diff
changeset
|
34 void GenerateUnmovables(); |
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6179
diff
changeset
|
35 bool GenerateTowns(); |
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6179
diff
changeset
|
36 void GenerateTrees(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
37 |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6179
diff
changeset
|
38 void StartupEconomy(); |
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6179
diff
changeset
|
39 void StartupPlayers(); |
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6179
diff
changeset
|
40 void StartupDisasters(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
41 |
9409
bfbde09b4346
(svn r13320) -Codechange: move some enums from openttd.h to more logical locations.
rubidium <rubidium@openttd.org>
parents:
9354
diff
changeset
|
42 void InitializeGame(uint size_x, uint size_y, bool reset_date); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
43 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
44 /* Please only use this variable in genworld.h and genworld.c and |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
45 * nowhere else. For speed improvements we need it to be global, but |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
46 * in no way the meaning of it is to use it anywhere else besides |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
47 * in the genworld.h and genworld.c! -- TrueLight */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
48 gw_info _gw; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
49 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
50 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
51 * Set the status of the Paint flag. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
52 * If it is true, the thread will hold with any futher generating till |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
53 * the drawing of the screen is done. This is handled by |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
54 * SetGeneratingWorldProgress(), so calling that function will stall |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
55 * from time to time. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
56 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
57 void SetGeneratingWorldPaintStatus(bool status) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
58 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
59 _gw.wait_for_draw = status; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
60 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
61 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
62 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
63 * Returns true if the thread wants the main program to do a (full) paint. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
64 * If this returns false, please do not update the screen. Because we are |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
65 * writing in a thread, it can cause damaged data (reading and writing the |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
66 * same tile at the same time). |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
67 */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6179
diff
changeset
|
68 bool IsGeneratingWorldReadyForPaint() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
69 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
70 /* If we are in quit_thread mode, ignore this and always return false. This |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
71 * forces the screen to not be drawn, and the GUI not to wait for a draw. */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
72 if (!_gw.active || _gw.quit_thread || !_gw.threaded) return false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
73 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
74 return _gw.wait_for_draw; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
75 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
76 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
77 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
78 * Tells if the world generation is done in a thread or not. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
79 */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6179
diff
changeset
|
80 bool IsGenerateWorldThreaded() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
81 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
82 return _gw.threaded && !_gw.quit_thread; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
83 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
84 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
85 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
86 * The internal, real, generate function. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
87 */ |
9476
bba7a506af6d
(svn r13411) -Codechange: remove the return value from the thread procs because it is never used.
rubidium <rubidium@openttd.org>
parents:
9413
diff
changeset
|
88 static void _GenerateWorld(void *arg) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
89 { |
8963
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
90 try { |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
91 _generating_world = true; |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
92 if (_network_dedicated) DEBUG(net, 0, "Generating map, please wait..."); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
93 /* Set the Random() seed to generation_seed so we produce the same map with the same seed */ |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9409
diff
changeset
|
94 if (_settings_game.game_creation.generation_seed == GENERATE_NEW_SEED) _settings_game.game_creation.generation_seed = _settings_newgame.game_creation.generation_seed = InteractiveRandom(); |
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9409
diff
changeset
|
95 _random.SetSeed(_settings_game.game_creation.generation_seed); |
8963
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
96 SetGeneratingWorldProgress(GWP_MAP_INIT, 2); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
97 SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, VHM_NONE, WC_MAIN_WINDOW, 0); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
98 |
8963
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
99 IncreaseGeneratingWorldProgress(GWP_MAP_INIT); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
100 /* Must start economy early because of the costs. */ |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
101 StartupEconomy(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
102 |
8963
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
103 /* Don't generate landscape items when in the scenario editor. */ |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
104 if (_gw.mode == GW_EMPTY) { |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
105 SetGeneratingWorldProgress(GWP_UNMOVABLE, 1); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
106 |
8963
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
107 /* Make the map the height of the patch setting */ |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9409
diff
changeset
|
108 if (_game_mode != GM_MENU) FlatEmptyWorld(_settings_game.game_creation.se_flat_world_height); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
109 |
8963
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
110 ConvertGroundTilesIntoWaterTiles(); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
111 IncreaseGeneratingWorldProgress(GWP_UNMOVABLE); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
112 } else { |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
113 GenerateLandscape(_gw.mode); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
114 GenerateClearTile(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
115 |
8963
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
116 /* only generate towns, tree and industries in newgame mode. */ |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
117 if (_game_mode != GM_EDITOR) { |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
118 GenerateTowns(); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
119 GenerateIndustries(); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
120 GenerateUnmovables(); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
121 GenerateTrees(); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
122 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
123 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
124 |
8963
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
125 ClearStorageChanges(true); |
8303
0ab35f1b5949
(svn r11867) -Fix: do not reset changes to persistent storages during world generation.
rubidium <rubidium@openttd.org>
parents:
8270
diff
changeset
|
126 |
8963
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
127 /* These are probably pointless when inside the scenario editor. */ |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
128 SetGeneratingWorldProgress(GWP_GAME_INIT, 3); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
129 StartupPlayers(); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
130 IncreaseGeneratingWorldProgress(GWP_GAME_INIT); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
131 StartupEngines(); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
132 IncreaseGeneratingWorldProgress(GWP_GAME_INIT); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
133 StartupDisasters(); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
134 _generating_world = false; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
135 |
8963
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
136 /* No need to run the tile loop in the scenario editor. */ |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
137 if (_gw.mode != GW_EMPTY) { |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
138 uint i; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
139 |
8963
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
140 SetGeneratingWorldProgress(GWP_RUNTILELOOP, 0x500); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
141 for (i = 0; i < 0x500; i++) { |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
142 RunTileLoop(); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
143 IncreaseGeneratingWorldProgress(GWP_RUNTILELOOP); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
144 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
145 } |
8963
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
146 |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
147 ResetObjectToPlace(); |
9659
14e241fadc66
(svn r13731) -Codechange: make a pool of the array of players.
rubidium <rubidium@openttd.org>
parents:
9479
diff
changeset
|
148 _local_player = _gw.lp; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
149 |
8963
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
150 SetGeneratingWorldProgress(GWP_GAME_START, 1); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
151 /* Call any callback */ |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
152 if (_gw.proc != NULL) _gw.proc(); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
153 IncreaseGeneratingWorldProgress(GWP_GAME_START); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
154 |
8963
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
155 if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
156 /* Show all vital windows again, because we have hidden them */ |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
157 if (_gw.threaded && _game_mode != GM_MENU) ShowVitalWindows(); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
158 _gw.active = false; |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
159 _gw.proc = NULL; |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
160 _gw.threaded = false; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
161 |
8963
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
162 DeleteWindowById(WC_GENERATE_PROGRESS_WINDOW, 0); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
163 MarkWholeScreenDirty(); |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
164 |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
165 if (_network_dedicated) DEBUG(net, 0, "Map generated, starting game"); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
166 |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9409
diff
changeset
|
167 if (_settings_client.gui.pause_on_newgame && _game_mode == GM_NORMAL) DoCommandP(0, 1, 0, NULL, CMD_PAUSE); |
8963
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
168 } catch (...) { |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
169 _generating_world = false; |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
170 throw; |
49d5494c14cc
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx <glx@openttd.org>
parents:
8934
diff
changeset
|
171 } |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
172 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
173 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
174 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
175 * Set here the function, if any, that you want to be called when landscape |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
176 * generation is done. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
177 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
178 void GenerateWorldSetCallback(gw_done_proc *proc) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
179 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
180 _gw.proc = proc; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
181 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
182 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
183 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
184 * Set here the function, if any, that you want to be called when landscape |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
185 * generation is aborted. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
186 */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
187 void GenerateWorldSetAbortCallback(gw_abort_proc *proc) |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
188 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
189 _gw.abortp = proc; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
190 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
191 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
192 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
193 * This will wait for the thread to finish up his work. It will not continue |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
194 * till the work is done. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
195 */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6179
diff
changeset
|
196 void WaitTillGeneratedWorld() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
197 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
198 if (_gw.thread == NULL) return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
199 _gw.quit_thread = true; |
8934
a56c5ca0f396
(svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium <rubidium@openttd.org>
parents:
8786
diff
changeset
|
200 _gw.thread->Join(); |
9479
8d2de7234320
(svn r13417) -Fix (r12945, r13413): freeing the ThreadObjects in a manner that hopefully doesn't cause crashes.
rubidium <rubidium@openttd.org>
parents:
9477
diff
changeset
|
201 delete _gw.thread; |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
202 _gw.thread = NULL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
203 _gw.threaded = false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
204 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
205 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
206 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
207 * Initializes the abortion process |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
208 */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6179
diff
changeset
|
209 void AbortGeneratingWorld() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
210 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
211 _gw.abort = true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
212 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
213 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
214 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
215 * Is the generation being aborted? |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
216 */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6179
diff
changeset
|
217 bool IsGeneratingWorldAborted() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
218 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
219 return _gw.abort; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
220 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
221 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
222 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
223 * Really handle the abortion, i.e. clean up some of the mess |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
224 */ |
6247
57363e064324
(svn r9050) -Codechange: Foo(void) -> Foo()
rubidium <rubidium@openttd.org>
parents:
6179
diff
changeset
|
225 void HandleGeneratingWorldAbortion() |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
226 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
227 /* Clean up - in SE create an empty map, otherwise, go to intro menu */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
228 _switch_mode = (_game_mode == GM_EDITOR) ? SM_EDITOR : SM_MENU; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
229 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
230 if (_gw.abortp != NULL) _gw.abortp(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
231 |
5668
3d6d9bff3dd8
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138 <peter1138@openttd.org>
parents:
5587
diff
changeset
|
232 if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
233 /* Show all vital windows again, because we have hidden them */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
234 if (_gw.threaded && _game_mode != GM_MENU) ShowVitalWindows(); |
8934
a56c5ca0f396
(svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium <rubidium@openttd.org>
parents:
8786
diff
changeset
|
235 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
236 _gw.active = false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
237 _gw.proc = NULL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
238 _gw.abortp = NULL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
239 _gw.threaded = false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
240 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
241 DeleteWindowById(WC_GENERATE_PROGRESS_WINDOW, 0); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
242 MarkWholeScreenDirty(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
243 |
9479
8d2de7234320
(svn r13417) -Fix (r12945, r13413): freeing the ThreadObjects in a manner that hopefully doesn't cause crashes.
rubidium <rubidium@openttd.org>
parents:
9477
diff
changeset
|
244 _gw.thread->Exit(); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
245 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
246 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
247 /** |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
248 * Generate a world. |
6179
e3e61b92574b
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas <belugas@openttd.org>
parents:
5893
diff
changeset
|
249 * @param mode The mode of world generation (see GenerateWorldModes). |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
250 * @param size_x The X-size of the map. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
251 * @param size_y The Y-size of the map. |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
252 */ |
9409
bfbde09b4346
(svn r13320) -Codechange: move some enums from openttd.h to more logical locations.
rubidium <rubidium@openttd.org>
parents:
9354
diff
changeset
|
253 void GenerateWorld(GenerateWorldMode mode, uint size_x, uint size_y) |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
254 { |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
255 if (_gw.active) return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
256 _gw.mode = mode; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
257 _gw.size_x = size_x; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
258 _gw.size_y = size_y; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
259 _gw.active = true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
260 _gw.abort = false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
261 _gw.abortp = NULL; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
262 _gw.lp = _local_player; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
263 _gw.wait_for_draw = false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
264 _gw.quit_thread = false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
265 _gw.threaded = true; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
266 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
267 /* This disables some commands and stuff */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
268 SetLocalPlayer(PLAYER_SPECTATOR); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
269 /* Make sure everything is done via OWNER_NONE */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
270 _current_player = OWNER_NONE; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
271 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
272 /* Set the date before loading sprites as some newgrfs check it */ |
9413
512ea64da840
(svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium <rubidium@openttd.org>
parents:
9409
diff
changeset
|
273 SetDate(ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1)); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
274 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
275 /* Load the right landscape stuff */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
276 GfxLoadSprites(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
277 LoadStringWidthTable(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
278 |
9409
bfbde09b4346
(svn r13320) -Codechange: move some enums from openttd.h to more logical locations.
rubidium <rubidium@openttd.org>
parents:
9354
diff
changeset
|
279 InitializeGame(_gw.size_x, _gw.size_y, false); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
280 PrepareGenerateWorldProgress(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
281 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
282 /* Re-init the windowing system */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
283 ResetWindowSystem(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
284 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
285 /* Create toolbars */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
286 SetupColorsAndInitialWindow(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
287 |
9479
8d2de7234320
(svn r13417) -Fix (r12945, r13413): freeing the ThreadObjects in a manner that hopefully doesn't cause crashes.
rubidium <rubidium@openttd.org>
parents:
9477
diff
changeset
|
288 if (_gw.thread != NULL) { |
8d2de7234320
(svn r13417) -Fix (r12945, r13413): freeing the ThreadObjects in a manner that hopefully doesn't cause crashes.
rubidium <rubidium@openttd.org>
parents:
9477
diff
changeset
|
289 _gw.thread->Join(); |
8d2de7234320
(svn r13417) -Fix (r12945, r13413): freeing the ThreadObjects in a manner that hopefully doesn't cause crashes.
rubidium <rubidium@openttd.org>
parents:
9477
diff
changeset
|
290 delete _gw.thread; |
8d2de7234320
(svn r13417) -Fix (r12945, r13413): freeing the ThreadObjects in a manner that hopefully doesn't cause crashes.
rubidium <rubidium@openttd.org>
parents:
9477
diff
changeset
|
291 _gw.thread = NULL; |
8d2de7234320
(svn r13417) -Fix (r12945, r13413): freeing the ThreadObjects in a manner that hopefully doesn't cause crashes.
rubidium <rubidium@openttd.org>
parents:
9477
diff
changeset
|
292 } |
8d2de7234320
(svn r13417) -Fix (r12945, r13413): freeing the ThreadObjects in a manner that hopefully doesn't cause crashes.
rubidium <rubidium@openttd.org>
parents:
9477
diff
changeset
|
293 |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
294 if (_network_dedicated || |
9479
8d2de7234320
(svn r13417) -Fix (r12945, r13413): freeing the ThreadObjects in a manner that hopefully doesn't cause crashes.
rubidium <rubidium@openttd.org>
parents:
9477
diff
changeset
|
295 (_gw.thread = ThreadObject::New(&_GenerateWorld, NULL)) == NULL) { |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
296 DEBUG(misc, 1, "Cannot create genworld thread, reverting to single-threaded mode"); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
297 _gw.threaded = false; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
298 _GenerateWorld(NULL); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
299 return; |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
300 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
301 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
302 /* Remove any open window */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
303 DeleteAllNonVitalWindows(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
304 /* Hide vital windows, because we don't allow to use them */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
305 HideVitalWindows(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
306 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
307 /* Don't show the dialog if we don't have a thread */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
308 ShowGenerateWorldProgress(); |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
309 |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
310 /* Centre the view on the map */ |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
311 if (FindWindowById(WC_MAIN_WINDOW, 0) != NULL) { |
6760
90fd4a119369
(svn r9995) -Fix (r9962): Don't scroll the map at the start of a new game
peter1138 <peter1138@openttd.org>
parents:
6578
diff
changeset
|
312 ScrollMainWindowToTile(TileXY(MapSizeX() / 2, MapSizeY() / 2), true); |
5584
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
313 } |
4b26bd55bd24
(svn r8033) [cpp] - Prepare for merge from branches/cpp (all .c files renamed to .cpp)
KUDr <KUDr@openttd.org>
parents:
diff
changeset
|
314 } |