summaryrefslogtreecommitdiff
path: root/town_cmd.c
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2005-09-16 00:33:33 +0000
committerDarkvater <darkvater@openttd.org>2005-09-16 00:33:33 +0000
commit180997534c08d1ffa0d153ee50c3a369b66d0cd6 (patch)
treea457fd89edc14bd8597031996ddfaca339bfc74f /town_cmd.c
parent141924455193275572e8b43fd6702ff05120656e (diff)
downloadopenttd-180997534c08d1ffa0d153ee50c3a369b66d0cd6.tar.xz
(svn r2956) - Fix: [ 1253736 ] creating many town crash to desktop. Now it 'dies' with an ingame error message informing the gamer if it couldn't generate any towns in user-space. Still if it happens during new-game generation it crashes since we don't yet have actions to do in such a circumstance.
Diffstat (limited to 'town_cmd.c')
-rw-r--r--town_cmd.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/town_cmd.c b/town_cmd.c
index 2ba9e5fa0..2a4ca21e0 100644
--- a/town_cmd.c
+++ b/town_cmd.c
@@ -1107,25 +1107,29 @@ Town *CreateRandomTown(uint attempts)
return NULL;
}
-static const byte _num_initial_towns[3] = {
- 11, 23, 46
-};
+static const byte _num_initial_towns[3] = {11, 23, 46};
-void GenerateTowns(void)
+bool GenerateTowns(void)
{
uint num = 0;
- uint n =
- ScaleByMapSize(_num_initial_towns[_opt.diff.number_towns] + (Random() & 7));
+ uint n = ScaleByMapSize(_num_initial_towns[_opt.diff.number_towns] + (Random() & 7));
do {
if (CreateRandomTown(20) != NULL) //try 20 times for the first loop
num++;
} while (--n);
+ // give it a last try, but now more aggressive
if (num == 0 && CreateRandomTown(10000) == NULL) {
+ Town *t;
+ FOR_ALL_TOWNS(t) { if (IsValidTown(t)) {num = 1; break;}}
+
//XXX can we handle that more gracefully?
- error("Could not generate any town");
+ if (num == 0) error("Could not generate any town");
+ return false;
}
+
+ return true;
}
static bool CheckBuildHouseMode(Town *t1, TileIndex tile, uint tileh, int mode)