(svn r14933) -Codechange: check the whether a pool item can be constructed instead of trying to make it and check for NULL.

This commit is contained in:
rubidium
2009-01-09 14:59:02 +00:00
parent 331b8dd7d4
commit f0b0691bfe
7 changed files with 88 additions and 115 deletions

View File

@@ -1576,6 +1576,8 @@ CommandCost CmdBuildTown(TileIndex tile, uint32 flags, uint32 p1, uint32 p2, con
Town *CreateRandomTown(uint attempts, TownSizeMode mode, uint size)
{
if (!Town::CanAllocateItem()) return NULL;
do {
/* Generate a tile index not too close from the edge */
TileIndex tile = RandomTile();
@@ -1603,7 +1605,6 @@ Town *CreateRandomTown(uint attempts, TownSizeMode mode, uint size)
/* Allocate a town struct */
Town *t = new Town(tile);
if (t == NULL) break;
DoCreateTown(t, tile, townnameparts, mode, size);
return t;