--- a/src/town_cmd.cpp Thu Dec 18 18:47:39 2008 +0000
+++ b/src/town_cmd.cpp Fri Dec 19 01:32:07 2008 +0200
@@ -1310,7 +1310,12 @@
_current_company = old_company;
return r != 0;
}
- tile = TILE_ADD(tile, ToTileIndexDiff(*ptr));
+
+ /* Next (valid) tile... */
+ TileIndexDiff dt = ToTileIndexDiff(*ptr);
+
+ if (IsValidTile(tile + dt))
+ tile = TILE_ADD(tile, ToTileIndexDiff(*ptr));
}
/* No road available, try to build a random road block by
@@ -1541,7 +1546,7 @@
if (p2 > TSM_CITY) return CMD_ERROR;
/* Check if too close to the edge of map */
- if (DistanceFromEdge(tile) < 12)
+ if (DistanceFromEdge(tile) < 1)
return_cmd_error(STR_0237_TOO_CLOSE_TO_EDGE_OF_MAP);
/* Can only build on clear flat areas, possibly with trees. */
@@ -1579,7 +1584,7 @@
do {
/* Generate a tile index not too close from the edge */
TileIndex tile = RandomTile();
- if (DistanceFromEdge(tile) < 20) continue;
+ if (DistanceFromEdge(tile) < 1) continue;
/* Make sure the tile is plain */
if (!IsTileType(tile, MP_CLEAR) || GetTileSlope(tile, NULL) != SLOPE_FLAT) continue;
@@ -1608,7 +1613,7 @@
bool GenerateTowns()
{
uint num = 0;
- uint n = ScaleByMapSize(_num_initial_towns[_settings_game.difficulty.number_towns] + (Random() & 7));
+ uint n = ScaleByMapSize(_num_initial_towns[_settings_game.difficulty.number_towns]) + (Random() & 7);
uint num_cities = _settings_game.economy.larger_towns == 0 ? 0 : n / _settings_game.economy.larger_towns;
SetGeneratingWorldProgress(GWP_TOWN, n);
@@ -1619,7 +1624,7 @@
TownSizeMode mode = num_cities > 0 ? TSM_CITY : TSM_RANDOM;
if (CreateRandomTown(20, mode, _settings_game.economy.initial_city_size) != NULL) num++;
if (num_cities > 0) num_cities--;
- } while (--n);
+ } while (n && --n);
/* give it a last try, but now more aggressive */
if (num == 0 && CreateRandomTown(10000, TSM_RANDOM, 0) == NULL) {
@@ -1870,7 +1875,12 @@
return true;
}
if (d == DIAGDIR_END) break;
- tile2 += TileOffsByDiagDir(ReverseDiagDir(d)); // go clockwise
+
+ // go clockwise
+ TileIndexDiff dt = TileOffsByDiagDir(ReverseDiagDir(d));
+
+ if (IsValidTile(tile2 + dt))
+ tile2 += dt;
}
return false;