author | Tero Marttila <terom@fixme.fi> |
Fri, 19 Dec 2008 02:20:26 +0200 | |
changeset 10441 | d09735696a9e |
parent 10440 | 0a91ea45b0e8 |
permissions | -rw-r--r-- |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
1 |
/* $Id$ */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
2 |
|
9111
48ce04029fe4
(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
parents:
8963
diff
changeset
|
3 |
/** @file genworld.cpp Functions to generate a map. */ |
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
5893
diff
changeset
|
4 |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
5 |
#include "stdafx.h" |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
6 |
#include "openttd.h" |
6453
226bcddeba32
(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
parents:
6247
diff
changeset
|
7 |
#include "landscape.h" |
10208
72c00af5c95d
(svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents:
10207
diff
changeset
|
8 |
#include "company_func.h" |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
9 |
#include "variables.h" |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
10 |
#include "thread.h" |
8116
8da76dcb3287
(svn r11677) -Codechange: move price and command related types/functions to their respective places.
rubidium
parents:
8107
diff
changeset
|
11 |
#include "command_func.h" |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
12 |
#include "genworld.h" |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
13 |
#include "gfxinit.h" |
8107
bb7deea89175
(svn r11668) -Codechange: more refactoring aimed at reducing compile time and making it more logic where function definitions can be found.
rubidium
parents:
7889
diff
changeset
|
14 |
#include "window_func.h" |
5469
7edfc643abbc
(svn r7751) -Codechange: move network_* to a new network map. Furthermore move the low level network functions to network/core, so they can be reused by the masterserver and website-serverlist-updater.
rubidium
parents:
5380
diff
changeset
|
15 |
#include "network/network.h" |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
16 |
#include "debug.h" |
8208
3d0590aa2124
(svn r11771) -Codechange: split settings.h into better separated headers.
rubidium
parents:
8142
diff
changeset
|
17 |
#include "settings_func.h" |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
18 |
#include "heightmap.h" |
8225
cd84a95b6630
(svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents:
8208
diff
changeset
|
19 |
#include "viewport_func.h" |
cd84a95b6630
(svn r11788) -Fix (11787): makedepend doesn't mark delete files as changed...
rubidium
parents:
8208
diff
changeset
|
20 |
#include "gfx_func.h" |
8139
4e91c448c409
(svn r11701) -Codechange: removal unnecessary inclusions of map.h (and split map.h).
rubidium
parents:
8138
diff
changeset
|
21 |
#include "map_func.h" |
8140
0d0d8c94f84b
(svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents:
8139
diff
changeset
|
22 |
#include "date_func.h" |
8142
837f47089a7c
(svn r11704) -Codechange: remove another bunch of useless includes.
rubidium
parents:
8140
diff
changeset
|
23 |
#include "core/random_func.hpp" |
8786
1823ff88a054
(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
parents:
8434
diff
changeset
|
24 |
#include "engine_func.h" |
8270
e7c342f6b14c
(svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents:
8264
diff
changeset
|
25 |
#include "settings_type.h" |
8303
cbb07f7426fc
(svn r11867) -Fix: do not reset changes to persistent storages during world generation.
rubidium
parents:
8270
diff
changeset
|
26 |
#include "newgrf_storage.h" |
8380
174326093caa
(svn r11947) -Feature: Make use of new sprites added by Action5 type 0D.
frosch
parents:
8303
diff
changeset
|
27 |
#include "water.h" |
9127
14f21c5954ee
(svn r12987) -Codechange: split viewport and tile selection.
rubidium
parents:
9111
diff
changeset
|
28 |
#include "tilehighlight_func.h" |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
29 |
|
8264
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
30 |
#include "table/sprites.h" |
b1e85998c7d3
(svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents:
8254
diff
changeset
|
31 |
|
6247 | 32 |
void GenerateClearTile(); |
33 |
void GenerateIndustries(); |
|
34 |
void GenerateUnmovables(); |
|
35 |
bool GenerateTowns(); |
|
36 |
void GenerateTrees(); |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
37 |
|
6247 | 38 |
void StartupEconomy(); |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
9659
diff
changeset
|
39 |
void StartupCompanies(); |
6247 | 40 |
void StartupDisasters(); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
41 |
|
9409
a4fc0d50c588
(svn r13320) -Codechange: move some enums from openttd.h to more logical locations.
rubidium
parents:
9354
diff
changeset
|
42 |
void InitializeGame(uint size_x, uint size_y, bool reset_date); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
43 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
44 |
/* Please only use this variable in genworld.h and genworld.c and |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
45 |
* nowhere else. For speed improvements we need it to be global, but |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
46 |
* in no way the meaning of it is to use it anywhere else besides |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
47 |
* in the genworld.h and genworld.c! -- TrueLight */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
48 |
gw_info _gw; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
49 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
50 |
/** |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
51 |
* Set the status of the Paint flag. |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
52 |
* If it is true, the thread will hold with any futher generating till |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
53 |
* the drawing of the screen is done. This is handled by |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
54 |
* SetGeneratingWorldProgress(), so calling that function will stall |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
55 |
* from time to time. |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
56 |
*/ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
57 |
void SetGeneratingWorldPaintStatus(bool status) |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
58 |
{ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
59 |
_gw.wait_for_draw = status; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
60 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
61 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
62 |
/** |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
63 |
* Returns true if the thread wants the main program to do a (full) paint. |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
64 |
* If this returns false, please do not update the screen. Because we are |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
65 |
* writing in a thread, it can cause damaged data (reading and writing the |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
66 |
* same tile at the same time). |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
67 |
*/ |
6247 | 68 |
bool IsGeneratingWorldReadyForPaint() |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
69 |
{ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
70 |
/* If we are in quit_thread mode, ignore this and always return false. This |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
71 |
* forces the screen to not be drawn, and the GUI not to wait for a draw. */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
72 |
if (!_gw.active || _gw.quit_thread || !_gw.threaded) return false; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
73 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
74 |
return _gw.wait_for_draw; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
75 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
76 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
77 |
/** |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
78 |
* Tells if the world generation is done in a thread or not. |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
79 |
*/ |
6247 | 80 |
bool IsGenerateWorldThreaded() |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
81 |
{ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
82 |
return _gw.threaded && !_gw.quit_thread; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
83 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
84 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
85 |
/** |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
86 |
* The internal, real, generate function. |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
87 |
*/ |
9476
902f9cf6373f
(svn r13411) -Codechange: remove the return value from the thread procs because it is never used.
rubidium
parents:
9413
diff
changeset
|
88 |
static void _GenerateWorld(void *arg) |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
89 |
{ |
8963
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
90 |
try { |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
91 |
_generating_world = true; |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
92 |
if (_network_dedicated) DEBUG(net, 0, "Generating map, please wait..."); |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
93 |
/* Set the Random() seed to generation_seed so we produce the same map with the same seed */ |
9413
7042a8ec3fa8
(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
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(); |
7042a8ec3fa8
(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
parents:
9409
diff
changeset
|
95 |
_random.SetSeed(_settings_game.game_creation.generation_seed); |
8963
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
96 |
SetGeneratingWorldProgress(GWP_MAP_INIT, 2); |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
97 |
SetObjectToPlace(SPR_CURSOR_ZZZ, PAL_NONE, VHM_NONE, WC_MAIN_WINDOW, 0); |
8303
cbb07f7426fc
(svn r11867) -Fix: do not reset changes to persistent storages during world generation.
rubidium
parents:
8270
diff
changeset
|
98 |
|
8963
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
99 |
IncreaseGeneratingWorldProgress(GWP_MAP_INIT); |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
100 |
/* Must start economy early because of the costs. */ |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
101 |
StartupEconomy(); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
102 |
|
8963
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
103 |
/* Don't generate landscape items when in the scenario editor. */ |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
104 |
if (_gw.mode == GW_EMPTY) { |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
105 |
SetGeneratingWorldProgress(GWP_UNMOVABLE, 1); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
106 |
|
8963
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
107 |
/* Make the map the height of the patch setting */ |
9413
7042a8ec3fa8
(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
parents:
9409
diff
changeset
|
108 |
if (_game_mode != GM_MENU) FlatEmptyWorld(_settings_game.game_creation.se_flat_world_height); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
109 |
|
8963
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
110 |
ConvertGroundTilesIntoWaterTiles(); |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
111 |
IncreaseGeneratingWorldProgress(GWP_UNMOVABLE); |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
112 |
} else { |
10441
d09735696a9e
don't generate a heightmap for <64 tile maps
Tero Marttila <terom@fixme.fi>
parents:
10440
diff
changeset
|
113 |
if (MapSize() > 64) |
d09735696a9e
don't generate a heightmap for <64 tile maps
Tero Marttila <terom@fixme.fi>
parents:
10440
diff
changeset
|
114 |
GenerateLandscape(_gw.mode); |
10439
50f056aa3024
industries, unmoveables... everything but the landscape
terom@frrb.lan
parents:
10438
diff
changeset
|
115 |
GenerateClearTile(); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
116 |
|
8963
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
117 |
/* only generate towns, tree and industries in newgame mode. */ |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
118 |
if (_game_mode != GM_EDITOR) { |
10440
0a91ea45b0e8
adjust the random land gen a bit to work with mini-maps
Tero Marttila <terom@fixme.fi>
parents:
10439
diff
changeset
|
119 |
GenerateTowns(); |
10439
50f056aa3024
industries, unmoveables... everything but the landscape
terom@frrb.lan
parents:
10438
diff
changeset
|
120 |
GenerateIndustries(); |
50f056aa3024
industries, unmoveables... everything but the landscape
terom@frrb.lan
parents:
10438
diff
changeset
|
121 |
GenerateUnmovables(); |
8963
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
122 |
GenerateTrees(); |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
123 |
} |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
124 |
} |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
125 |
|
8963
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
126 |
ClearStorageChanges(true); |
6543
57dfb0d16b10
(svn r9734) -Feature: Add an option to automatically pause when starting a new game.
maedhros
parents:
6453
diff
changeset
|
127 |
|
8963
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
128 |
/* These are probably pointless when inside the scenario editor. */ |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
129 |
SetGeneratingWorldProgress(GWP_GAME_INIT, 3); |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
9659
diff
changeset
|
130 |
StartupCompanies(); |
8963
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
131 |
IncreaseGeneratingWorldProgress(GWP_GAME_INIT); |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
132 |
StartupEngines(); |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
133 |
IncreaseGeneratingWorldProgress(GWP_GAME_INIT); |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
134 |
StartupDisasters(); |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
135 |
_generating_world = false; |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
136 |
|
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
137 |
/* No need to run the tile loop in the scenario editor. */ |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
138 |
if (_gw.mode != GW_EMPTY) { |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
139 |
uint i; |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
140 |
|
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
141 |
SetGeneratingWorldProgress(GWP_RUNTILELOOP, 0x500); |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
142 |
for (i = 0; i < 0x500; i++) { |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
143 |
RunTileLoop(); |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
144 |
IncreaseGeneratingWorldProgress(GWP_RUNTILELOOP); |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
145 |
} |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
146 |
} |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
147 |
|
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
148 |
ResetObjectToPlace(); |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
9659
diff
changeset
|
149 |
_local_company = _gw.lc; |
8963
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
150 |
|
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
151 |
SetGeneratingWorldProgress(GWP_GAME_START, 1); |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
152 |
/* Call any callback */ |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
153 |
if (_gw.proc != NULL) _gw.proc(); |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
154 |
IncreaseGeneratingWorldProgress(GWP_GAME_START); |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
155 |
|
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
156 |
if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE); |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
157 |
/* Show all vital windows again, because we have hidden them */ |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
158 |
if (_gw.threaded && _game_mode != GM_MENU) ShowVitalWindows(); |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
159 |
_gw.active = false; |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
160 |
_gw.proc = NULL; |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
161 |
_gw.threaded = false; |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
162 |
|
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
163 |
DeleteWindowById(WC_GENERATE_PROGRESS_WINDOW, 0); |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
164 |
MarkWholeScreenDirty(); |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
165 |
|
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
166 |
if (_network_dedicated) DEBUG(net, 0, "Map generated, starting game"); |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
167 |
|
9413
7042a8ec3fa8
(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
parents:
9409
diff
changeset
|
168 |
if (_settings_client.gui.pause_on_newgame && _game_mode == GM_NORMAL) DoCommandP(0, 1, 0, NULL, CMD_PAUSE); |
8963
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
169 |
} catch (...) { |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
170 |
_generating_world = false; |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
171 |
throw; |
fae4125f5031
(svn r12755) -Fix (r12706): aborting map generation was not properly handled
glx
parents:
8934
diff
changeset
|
172 |
} |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
173 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
174 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
175 |
/** |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
176 |
* Set here the function, if any, that you want to be called when landscape |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
177 |
* generation is done. |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
178 |
*/ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
179 |
void GenerateWorldSetCallback(gw_done_proc *proc) |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
180 |
{ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
181 |
_gw.proc = proc; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
182 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
183 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
184 |
/** |
5145
d4a8882b32ef
(svn r7237) -Fix: TGP landscape generation could leak memory if aborted during the generation of the heightmap.
rubidium
parents:
5048
diff
changeset
|
185 |
* Set here the function, if any, that you want to be called when landscape |
d4a8882b32ef
(svn r7237) -Fix: TGP landscape generation could leak memory if aborted during the generation of the heightmap.
rubidium
parents:
5048
diff
changeset
|
186 |
* generation is aborted. |
d4a8882b32ef
(svn r7237) -Fix: TGP landscape generation could leak memory if aborted during the generation of the heightmap.
rubidium
parents:
5048
diff
changeset
|
187 |
*/ |
d4a8882b32ef
(svn r7237) -Fix: TGP landscape generation could leak memory if aborted during the generation of the heightmap.
rubidium
parents:
5048
diff
changeset
|
188 |
void GenerateWorldSetAbortCallback(gw_abort_proc *proc) |
d4a8882b32ef
(svn r7237) -Fix: TGP landscape generation could leak memory if aborted during the generation of the heightmap.
rubidium
parents:
5048
diff
changeset
|
189 |
{ |
d4a8882b32ef
(svn r7237) -Fix: TGP landscape generation could leak memory if aborted during the generation of the heightmap.
rubidium
parents:
5048
diff
changeset
|
190 |
_gw.abortp = proc; |
d4a8882b32ef
(svn r7237) -Fix: TGP landscape generation could leak memory if aborted during the generation of the heightmap.
rubidium
parents:
5048
diff
changeset
|
191 |
} |
d4a8882b32ef
(svn r7237) -Fix: TGP landscape generation could leak memory if aborted during the generation of the heightmap.
rubidium
parents:
5048
diff
changeset
|
192 |
|
d4a8882b32ef
(svn r7237) -Fix: TGP landscape generation could leak memory if aborted during the generation of the heightmap.
rubidium
parents:
5048
diff
changeset
|
193 |
/** |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
194 |
* This will wait for the thread to finish up his work. It will not continue |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
195 |
* till the work is done. |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
196 |
*/ |
6247 | 197 |
void WaitTillGeneratedWorld() |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
198 |
{ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
199 |
if (_gw.thread == NULL) return; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
200 |
_gw.quit_thread = true; |
8934
f46812d21fe6
(svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
8786
diff
changeset
|
201 |
_gw.thread->Join(); |
9479
c8ab793e4595
(svn r13417) -Fix (r12945, r13413): freeing the ThreadObjects in a manner that hopefully doesn't cause crashes.
rubidium
parents:
9477
diff
changeset
|
202 |
delete _gw.thread; |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
203 |
_gw.thread = NULL; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
204 |
_gw.threaded = false; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
205 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
206 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
207 |
/** |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
208 |
* Initializes the abortion process |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
209 |
*/ |
6247 | 210 |
void AbortGeneratingWorld() |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
211 |
{ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
212 |
_gw.abort = true; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
213 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
214 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
215 |
/** |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
216 |
* Is the generation being aborted? |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
217 |
*/ |
6247 | 218 |
bool IsGeneratingWorldAborted() |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
219 |
{ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
220 |
return _gw.abort; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
221 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
222 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
223 |
/** |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
224 |
* Really handle the abortion, i.e. clean up some of the mess |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
225 |
*/ |
6247 | 226 |
void HandleGeneratingWorldAbortion() |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
227 |
{ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
228 |
/* Clean up - in SE create an empty map, otherwise, go to intro menu */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
229 |
_switch_mode = (_game_mode == GM_EDITOR) ? SM_EDITOR : SM_MENU; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
230 |
|
5145
d4a8882b32ef
(svn r7237) -Fix: TGP landscape generation could leak memory if aborted during the generation of the heightmap.
rubidium
parents:
5048
diff
changeset
|
231 |
if (_gw.abortp != NULL) _gw.abortp(); |
d4a8882b32ef
(svn r7237) -Fix: TGP landscape generation could leak memory if aborted during the generation of the heightmap.
rubidium
parents:
5048
diff
changeset
|
232 |
|
5668
36b39f4a9032
(svn r8128) -Codechange: Split sprite and palette remap into separate 32 bit values.
peter1138
parents:
5587
diff
changeset
|
233 |
if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
234 |
/* Show all vital windows again, because we have hidden them */ |
4303
f631b9c6d4a8
(svn r5950) -Fix: don't show Vital Windows EVER if you go to GM_MENU (tnx Darkvater)
truelight
parents:
4300
diff
changeset
|
235 |
if (_gw.threaded && _game_mode != GM_MENU) ShowVitalWindows(); |
8934
f46812d21fe6
(svn r12706) -Merge: the thread rewrite from NoAI. The rewrite makes the threading we have better extendable.
rubidium
parents:
8786
diff
changeset
|
236 |
|
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
237 |
_gw.active = false; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
238 |
_gw.proc = NULL; |
5145
d4a8882b32ef
(svn r7237) -Fix: TGP landscape generation could leak memory if aborted during the generation of the heightmap.
rubidium
parents:
5048
diff
changeset
|
239 |
_gw.abortp = NULL; |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
240 |
_gw.threaded = false; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
241 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
242 |
DeleteWindowById(WC_GENERATE_PROGRESS_WINDOW, 0); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
243 |
MarkWholeScreenDirty(); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
244 |
|
9479
c8ab793e4595
(svn r13417) -Fix (r12945, r13413): freeing the ThreadObjects in a manner that hopefully doesn't cause crashes.
rubidium
parents:
9477
diff
changeset
|
245 |
_gw.thread->Exit(); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
246 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
247 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
248 |
/** |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
249 |
* Generate a world. |
6179
d19b0137d8e4
(svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents:
5893
diff
changeset
|
250 |
* @param mode The mode of world generation (see GenerateWorldModes). |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
251 |
* @param size_x The X-size of the map. |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
252 |
* @param size_y The Y-size of the map. |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
253 |
*/ |
9409
a4fc0d50c588
(svn r13320) -Codechange: move some enums from openttd.h to more logical locations.
rubidium
parents:
9354
diff
changeset
|
254 |
void GenerateWorld(GenerateWorldMode mode, uint size_x, uint size_y) |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
255 |
{ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
256 |
if (_gw.active) return; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
257 |
_gw.mode = mode; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
258 |
_gw.size_x = size_x; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
259 |
_gw.size_y = size_y; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
260 |
_gw.active = true; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
261 |
_gw.abort = false; |
5145
d4a8882b32ef
(svn r7237) -Fix: TGP landscape generation could leak memory if aborted during the generation of the heightmap.
rubidium
parents:
5048
diff
changeset
|
262 |
_gw.abortp = NULL; |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
9659
diff
changeset
|
263 |
_gw.lc = _local_company; |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
264 |
_gw.wait_for_draw = false; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
265 |
_gw.quit_thread = false; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
266 |
_gw.threaded = true; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
267 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
268 |
/* This disables some commands and stuff */ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
9659
diff
changeset
|
269 |
SetLocalCompany(COMPANY_SPECTATOR); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
270 |
/* Make sure everything is done via OWNER_NONE */ |
10207
c291a21b304e
(svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents:
9659
diff
changeset
|
271 |
_current_company = OWNER_NONE; |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
272 |
|
5340
8e534cd781cc
(svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents:
5155
diff
changeset
|
273 |
/* Set the date before loading sprites as some newgrfs check it */ |
9413
7042a8ec3fa8
(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
parents:
9409
diff
changeset
|
274 |
SetDate(ConvertYMDToDate(_settings_game.game_creation.starting_year, 0, 1)); |
5340
8e534cd781cc
(svn r7506) -Codechange: [NewGRF] Add action 7/9/D variable 0x81 (current year)
glx
parents:
5155
diff
changeset
|
275 |
|
5155
a479ef9c16a5
(svn r7250) -Codechange: Shuffle sprite loading and character width caching around a bit. This reduces the number of times the sprites are loaded from 5 to 2, just for the intro game.
peter1138
parents:
5145
diff
changeset
|
276 |
/* Load the right landscape stuff */ |
a479ef9c16a5
(svn r7250) -Codechange: Shuffle sprite loading and character width caching around a bit. This reduces the number of times the sprites are loaded from 5 to 2, just for the intro game.
peter1138
parents:
5145
diff
changeset
|
277 |
GfxLoadSprites(); |
a479ef9c16a5
(svn r7250) -Codechange: Shuffle sprite loading and character width caching around a bit. This reduces the number of times the sprites are loaded from 5 to 2, just for the intro game.
peter1138
parents:
5145
diff
changeset
|
278 |
LoadStringWidthTable(); |
a479ef9c16a5
(svn r7250) -Codechange: Shuffle sprite loading and character width caching around a bit. This reduces the number of times the sprites are loaded from 5 to 2, just for the intro game.
peter1138
parents:
5145
diff
changeset
|
279 |
|
9409
a4fc0d50c588
(svn r13320) -Codechange: move some enums from openttd.h to more logical locations.
rubidium
parents:
9354
diff
changeset
|
280 |
InitializeGame(_gw.size_x, _gw.size_y, false); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
281 |
PrepareGenerateWorldProgress(); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
282 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
283 |
/* Re-init the windowing system */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
284 |
ResetWindowSystem(); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
285 |
|
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
286 |
/* Create toolbars */ |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
287 |
SetupColorsAndInitialWindow(); |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
288 |
|
9479
c8ab793e4595
(svn r13417) -Fix (r12945, r13413): freeing the ThreadObjects in a manner that hopefully doesn't cause crashes.
rubidium
parents:
9477
diff
changeset
|
289 |
if (_gw.thread != NULL) { |
c8ab793e4595
(svn r13417) -Fix (r12945, r13413): freeing the ThreadObjects in a manner that hopefully doesn't cause crashes.
rubidium
parents:
9477
diff
changeset
|
290 |
_gw.thread->Join(); |
c8ab793e4595
(svn r13417) -Fix (r12945, r13413): freeing the ThreadObjects in a manner that hopefully doesn't cause crashes.
rubidium
parents:
9477
diff
changeset
|
291 |
delete _gw.thread; |
c8ab793e4595
(svn r13417) -Fix (r12945, r13413): freeing the ThreadObjects in a manner that hopefully doesn't cause crashes.
rubidium
parents:
9477
diff
changeset
|
292 |
_gw.thread = NULL; |
c8ab793e4595
(svn r13417) -Fix (r12945, r13413): freeing the ThreadObjects in a manner that hopefully doesn't cause crashes.
rubidium
parents:
9477
diff
changeset
|
293 |
} |
c8ab793e4595
(svn r13417) -Fix (r12945, r13413): freeing the ThreadObjects in a manner that hopefully doesn't cause crashes.
rubidium
parents:
9477
diff
changeset
|
294 |
|
5048
b784951def0a
(svn r7098) -Regression (r7094): Zoom buttons were not properly updated with a new/loaded game. The
Darkvater
parents:
5045
diff
changeset
|
295 |
if (_network_dedicated || |
9479
c8ab793e4595
(svn r13417) -Fix (r12945, r13413): freeing the ThreadObjects in a manner that hopefully doesn't cause crashes.
rubidium
parents:
9477
diff
changeset
|
296 |
(_gw.thread = ThreadObject::New(&_GenerateWorld, NULL)) == NULL) { |
5380
8ea58542b6e0
(svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents:
5376
diff
changeset
|
297 |
DEBUG(misc, 1, "Cannot create genworld thread, reverting to single-threaded mode"); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
298 |
_gw.threaded = false; |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
299 |
_GenerateWorld(NULL); |
5048
b784951def0a
(svn r7098) -Regression (r7094): Zoom buttons were not properly updated with a new/loaded game. The
Darkvater
parents:
5045
diff
changeset
|
300 |
return; |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
301 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
302 |
|
5048
b784951def0a
(svn r7098) -Regression (r7094): Zoom buttons were not properly updated with a new/loaded game. The
Darkvater
parents:
5045
diff
changeset
|
303 |
/* Remove any open window */ |
b784951def0a
(svn r7098) -Regression (r7094): Zoom buttons were not properly updated with a new/loaded game. The
Darkvater
parents:
5045
diff
changeset
|
304 |
DeleteAllNonVitalWindows(); |
5045
846098142ffe
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
4848
diff
changeset
|
305 |
/* Hide vital windows, because we don't allow to use them */ |
5048
b784951def0a
(svn r7098) -Regression (r7094): Zoom buttons were not properly updated with a new/loaded game. The
Darkvater
parents:
5045
diff
changeset
|
306 |
HideVitalWindows(); |
b784951def0a
(svn r7098) -Regression (r7094): Zoom buttons were not properly updated with a new/loaded game. The
Darkvater
parents:
5045
diff
changeset
|
307 |
|
b784951def0a
(svn r7098) -Regression (r7094): Zoom buttons were not properly updated with a new/loaded game. The
Darkvater
parents:
5045
diff
changeset
|
308 |
/* Don't show the dialog if we don't have a thread */ |
b784951def0a
(svn r7098) -Regression (r7094): Zoom buttons were not properly updated with a new/loaded game. The
Darkvater
parents:
5045
diff
changeset
|
309 |
ShowGenerateWorldProgress(); |
5045
846098142ffe
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
4848
diff
changeset
|
310 |
|
846098142ffe
(svn r7094) -Codechange: Get rid of the window-specific code in DoZoomInOutWindow (enable, disable
Darkvater
parents:
4848
diff
changeset
|
311 |
/* Centre the view on the map */ |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
312 |
if (FindWindowById(WC_MAIN_WINDOW, 0) != NULL) { |
6760
3bd13f9bc39c
(svn r9995) -Fix (r9962): Don't scroll the map at the start of a new game
peter1138
parents:
6578
diff
changeset
|
313 |
ScrollMainWindowToTile(TileXY(MapSizeX() / 2, MapSizeY() / 2), true); |
4300
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
314 |
} |
c7e43c47a2b9
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents:
diff
changeset
|
315 |
} |