summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-03-12 15:14:22 +0000
committerrubidium <rubidium@openttd.org>2009-03-12 15:14:22 +0000
commitd5a2dc1d0bf5af3b09965cbe11e8238432af05c1 (patch)
tree749827fe49c1c25840ad4c242c3dbc62d2922c2a /src
parent9dbf8a163f20e8d77dc97703dbfc180b91359873 (diff)
downloadopenttd-d5a2dc1d0bf5af3b09965cbe11e8238432af05c1.tar.xz
(svn r15689) -Fix [FS#2720]: do not crash when the generate map doesn't contain a suitable location for a town.
Diffstat (limited to 'src')
-rw-r--r--src/genworld.cpp10
-rw-r--r--src/lang/english.txt1
-rw-r--r--src/town_cmd.cpp6
3 files changed, 13 insertions, 4 deletions
diff --git a/src/genworld.cpp b/src/genworld.cpp
index f8a865397..dfae4822e 100644
--- a/src/genworld.cpp
+++ b/src/genworld.cpp
@@ -141,7 +141,10 @@ static void _GenerateWorld(void *arg)
/* only generate towns, tree and industries in newgame mode. */
if (_game_mode != GM_EDITOR) {
- GenerateTowns(_settings_game.economy.town_layout);
+ if (!GenerateTowns(_settings_game.economy.town_layout)) {
+ HandleGeneratingWorldAbortion();
+ return;
+ }
GenerateIndustries();
GenerateUnmovables();
GenerateTrees();
@@ -255,7 +258,10 @@ void HandleGeneratingWorldAbortion()
CleanupGeneration();
- _gw.thread->Exit();
+ if (_gw.thread != NULL) _gw.thread->Exit();
+
+ extern void SwitchToMode(SwitchMode new_mode);
+ SwitchToMode(_switch_mode);
}
/**
diff --git a/src/lang/english.txt b/src/lang/english.txt
index 4eee41026..f5075d9a9 100644
--- a/src/lang/english.txt
+++ b/src/lang/english.txt
@@ -1197,6 +1197,7 @@ STR_CANT_REMOVE_TRAIN_WAYPOINT :{WHITE}Can't re
STR_BUILD_AUTORAIL_TIP :{BLACK}Build railway track using the Autorail mode
STR_NO_TOWN_IN_SCENARIO :{WHITE}...there is no town in this scenario
+STR_COULD_NOT_CREATE_TOWN :{WHITE}Map generation aborted...{}...no suitable town locations
STR_MANY_RANDOM_TOWNS :{BLACK}Many random towns
STR_RANDOM_TOWNS_TIP :{BLACK}Cover the map with randomly placed towns
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index c8cdf6af4..f656fe76b 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -1648,8 +1648,10 @@ bool GenerateTowns(TownLayout layout)
/* give it a last try, but now more aggressive */
if (num == 0 && CreateRandomTown(10000, TS_RANDOM, false, layout) == NULL) {
if (GetNumTowns() == 0) {
- /* XXX - can we handle that more gracefully? */
- if (_game_mode != GM_EDITOR) usererror("Could not generate any town");
+ if (_game_mode != GM_EDITOR) {
+ extern StringID _switch_mode_errorstr;
+ _switch_mode_errorstr = STR_COULD_NOT_CREATE_TOWN;
+ }
return false;
}