summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-01-17 18:46:09 +0000
committerfrosch <frosch@openttd.org>2012-01-17 18:46:09 +0000
commit2458a29fd0287259522e3a7c642efe22d646c43f (patch)
treec5f3c437e1ea07f682624cc1432927a83b7a650b /src
parent3dcf19fd07ab50469f4a1efa59829369c3b48807 (diff)
downloadopenttd-2458a29fd0287259522e3a7c642efe22d646c43f.tar.xz
(svn r23819) -Fix [FS#4951]: Removal of towns with 0 population failed during map generation.
Diffstat (limited to 'src')
-rw-r--r--src/town_cmd.cpp9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp
index 5b0494f91..986000b2d 100644
--- a/src/town_cmd.cpp
+++ b/src/town_cmd.cpp
@@ -1820,6 +1820,8 @@ static TileIndex FindNearestGoodCoastalTownSpot(TileIndex tile, TownLayout layou
static Town *CreateRandomTown(uint attempts, uint32 townnameparts, TownSize size, bool city, TownLayout layout)
{
+ assert(_game_mode == GM_EDITOR || _generating_world); // These are the preconditions for CMD_DELETE_TOWN
+
if (!Town::CanAllocateItem()) return NULL;
do {
@@ -1844,7 +1846,8 @@ static Town *CreateRandomTown(uint attempts, uint32 townnameparts, TownSize size
/* if the population is still 0 at the point, then the
* placement is so bad it couldn't grow at all */
if (t->population > 0) return t;
- DoCommand(t->xy, t->index, 0, DC_EXEC, CMD_DELETE_TOWN);
+ CommandCost rc = DoCommand(t->xy, t->index, 0, DC_EXEC, CMD_DELETE_TOWN);
+ assert(rc.Succeeded());
/* We already know that we can allocate a single town when
* entering this function. However, we create and delete
@@ -2564,7 +2567,7 @@ CommandCost CmdExpandTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
}
/**
- * Delete a town (scenario editor only).
+ * Delete a town (scenario editor or worldgen only).
* @param tile Unused.
* @param flags Type of operation.
* @param p1 Town ID to delete.
@@ -2574,7 +2577,7 @@ CommandCost CmdExpandTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32
*/
CommandCost CmdDeleteTown(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, const char *text)
{
- if (_game_mode != GM_EDITOR) return CMD_ERROR;
+ if (_game_mode != GM_EDITOR && !_generating_world) return CMD_ERROR;
Town *t = Town::GetIfValid(p1);
if (t == NULL) return CMD_ERROR;