mirror of
https://github.com/JGRennison/OpenTTD-patches.git
synced 2024-11-11 13:10:45 +00:00
(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.
This commit is contained in:
parent
58c46bed40
commit
77d26759e3
@ -1444,7 +1444,7 @@ static void ScenEditTownGenWndProc(Window *w, WindowEvent *e)
|
|||||||
|
|
||||||
HandleButtonClick(w, 4);
|
HandleButtonClick(w, 4);
|
||||||
_generating_world = true;
|
_generating_world = true;
|
||||||
t = CreateRandomTown();
|
t = CreateRandomTown(20);
|
||||||
_generating_world = false;
|
_generating_world = false;
|
||||||
if (t != NULL)
|
if (t != NULL)
|
||||||
ScrollMainWindowToTile(t->xy);
|
ScrollMainWindowToTile(t->xy);
|
||||||
|
2
town.h
2
town.h
@ -82,7 +82,7 @@ void ShowTownViewWindow(uint town);
|
|||||||
void DeleteTown(Town *t);
|
void DeleteTown(Town *t);
|
||||||
void ExpandTown(Town *t);
|
void ExpandTown(Town *t);
|
||||||
bool GrowTown(Town *t);
|
bool GrowTown(Town *t);
|
||||||
Town *CreateRandomTown(void);
|
Town *CreateRandomTown(uint attempts);
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
ROAD_REMOVE = 0,
|
ROAD_REMOVE = 0,
|
||||||
|
18
town_cmd.c
18
town_cmd.c
@ -1027,15 +1027,12 @@ int32 CmdBuildTown(int x, int y, uint32 flags, uint32 p1, uint32 p2)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Town *CreateRandomTown(void)
|
Town *CreateRandomTown(uint attempts)
|
||||||
{
|
{
|
||||||
uint tile;
|
uint tile;
|
||||||
TileInfo ti;
|
TileInfo ti;
|
||||||
Town *t;
|
Town *t;
|
||||||
int n;
|
|
||||||
|
|
||||||
// Try 20 times.
|
|
||||||
n = 20;
|
|
||||||
do {
|
do {
|
||||||
// Generate a tile index not too close from the edge
|
// Generate a tile index not too close from the edge
|
||||||
tile = TILE_MASK(Random());
|
tile = TILE_MASK(Random());
|
||||||
@ -1058,7 +1055,7 @@ Town *CreateRandomTown(void)
|
|||||||
|
|
||||||
DoCreateTown(t, tile);
|
DoCreateTown(t, tile);
|
||||||
return t;
|
return t;
|
||||||
} while (--n);
|
} while (--attempts);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1068,10 +1065,19 @@ static const byte _num_initial_towns[3] = {
|
|||||||
|
|
||||||
void GenerateTowns(void)
|
void GenerateTowns(void)
|
||||||
{
|
{
|
||||||
|
uint num = 0;
|
||||||
uint n =
|
uint n =
|
||||||
ScaleByMapSize(_num_initial_towns[_opt.diff.number_towns] + (Random() & 7));
|
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) {
|
static bool CheckBuildHouseMode(Town *t1, uint tile, uint tileh, int mode) {
|
||||||
|
Loading…
Reference in New Issue
Block a user