diff options
author | celestar <celestar@openttd.org> | 2005-02-13 09:42:49 +0000 |
---|---|---|
committer | celestar <celestar@openttd.org> | 2005-02-13 09:42:49 +0000 |
commit | 77d26759e3e4f0ada2298d8e89e64380592537d1 (patch) | |
tree | 822211e1a18fb70fe4220e3dc0f3c2f08de03141 /town_cmd.c | |
parent | 58c46bed4072a563f037278d5f023c0bbf3c83a7 (diff) | |
download | openttd-77d26759e3e4f0ada2298d8e89e64380592537d1.tar.xz |
(svn r1866) -Fix: Intercepted generated maps with 0 towns on it. Currently just an
error() is called, some more graceful handling should be implemented
later.
Diffstat (limited to 'town_cmd.c')
-rw-r--r-- | town_cmd.c | 18 |
1 files changed, 12 insertions, 6 deletions
diff --git a/town_cmd.c b/town_cmd.c index d0daaf146..43cdd61f5 100644 --- a/town_cmd.c +++ b/town_cmd.c @@ -1027,15 +1027,12 @@ int32 CmdBuildTown(int x, int y, uint32 flags, uint32 p1, uint32 p2) return 0; } -Town *CreateRandomTown(void) +Town *CreateRandomTown(uint attempts) { uint tile; TileInfo ti; Town *t; - int n; - // Try 20 times. - n = 20; do { // Generate a tile index not too close from the edge tile = TILE_MASK(Random()); @@ -1058,7 +1055,7 @@ Town *CreateRandomTown(void) DoCreateTown(t, tile); return t; - } while (--n); + } while (--attempts); return NULL; } @@ -1068,10 +1065,19 @@ static const byte _num_initial_towns[3] = { void GenerateTowns(void) { + uint num = 0; uint n = ScaleByMapSize(_num_initial_towns[_opt.diff.number_towns] + (Random() & 7)); - do CreateRandomTown(); while (--n); + do { + if (CreateRandomTown(20) != NULL) //try 20 times for the first loop + num++; + } while (--n); + + if (num == 0 && CreateRandomTown(10000) == NULL) { + //XXX can we handle that more gracefully? + error("Could not generate any town"); + } } static bool CheckBuildHouseMode(Town *t1, uint tile, uint tileh, int mode) { |