--- a/src/clear_cmd.cpp Thu Dec 18 18:47:39 2008 +0000
+++ b/src/clear_cmd.cpp Fri Dec 19 01:32:07 2008 +0200
@@ -284,7 +284,7 @@
IncreaseGeneratingWorldProgress(GWP_ROUGH_ROCKY);
tile = RandomTile();
if (IsTileType(tile, MP_CLEAR) && !IsClearGround(tile, CLEAR_DESERT)) SetClearGroundDensity(tile, CLEAR_ROUGH, 3);
- } while (--i);
+ } while (i && --i);
/* add rocky tiles */
i = gi;
@@ -307,7 +307,7 @@
}
get_out:;
}
- } while (--i);
+ } while (i && --i);
}
static void ClickTile_Clear(TileIndex tile)
--- a/src/genworld.cpp Thu Dec 18 18:47:39 2008 +0000
+++ b/src/genworld.cpp Fri Dec 19 01:32:07 2008 +0200
@@ -110,14 +110,14 @@
ConvertGroundTilesIntoWaterTiles();
IncreaseGeneratingWorldProgress(GWP_UNMOVABLE);
} else {
- GenerateLandscape(_gw.mode);
- GenerateClearTile();
+ //GenerateLandscape(_gw.mode);
+ //GenerateClearTile();
/* only generate towns, tree and industries in newgame mode. */
if (_game_mode != GM_EDITOR) {
GenerateTowns();
- GenerateIndustries();
- GenerateUnmovables();
+ //GenerateIndustries();
+ //GenerateUnmovables();
GenerateTrees();
}
}
--- a/src/genworld_gui.cpp Thu Dec 18 18:47:39 2008 +0000
+++ b/src/genworld_gui.cpp Fri Dec 19 01:32:07 2008 +0200
@@ -937,7 +937,8 @@
if (IsGeneratingWorldAborted()) HandleGeneratingWorldAbortion();
if (total == 0) {
- assert(_tp.cls == class_table[cls]);
+ //assert(_tp.cls == class_table[cls]);
+ _tp.cls = class_table[cls];
_tp.current += progress;
} else {
_tp.cls = class_table[cls];
--- a/src/landscape.cpp Thu Dec 18 18:47:39 2008 +0000
+++ b/src/landscape.cpp Fri Dec 19 01:32:07 2008 +0200
@@ -654,7 +654,7 @@
TileIndex _cur_tileloop_tile;
-#define TILELOOP_BITS 4
+#define TILELOOP_BITS 1
#define TILELOOP_SIZE (1 << TILELOOP_BITS)
#define TILELOOP_ASSERTMASK ((TILELOOP_SIZE - 1) + ((TILELOOP_SIZE - 1) << MapLogX()))
#define TILELOOP_CHKMASK (((1 << (MapLogX() - TILELOOP_BITS))-1) << TILELOOP_BITS)
@@ -665,6 +665,7 @@
assert((tile & ~TILELOOP_ASSERTMASK) == 0);
uint count = (MapSizeX() / TILELOOP_SIZE) * (MapSizeY() / TILELOOP_SIZE);
+
do {
_tile_type_procs[GetTileType(tile)]->tile_loop_proc(tile);
@@ -673,11 +674,12 @@
} else {
tile = TILE_MASK(tile - TILELOOP_SIZE * (MapSizeX() / TILELOOP_SIZE - 1) + TileDiffXY(0, TILELOOP_SIZE)); /* x would overflow, also increase y */
}
- } while (--count != 0);
+ } while (count && --count != 0);
+
assert((tile & ~TILELOOP_ASSERTMASK) == 0);
tile += 9;
- if (tile & TILELOOP_CHKMASK) {
+ if (tile & ~TILELOOP_ASSERTMASK) {
tile = (tile + MapSizeX()) & TILELOOP_ASSERTMASK;
}
_cur_tileloop_tile = tile;
--- a/src/main_gui.cpp Thu Dec 18 18:47:39 2008 +0000
+++ b/src/main_gui.cpp Fri Dec 19 01:32:07 2008 +0200
@@ -195,7 +195,7 @@
{
MainWindow(int width, int height) : Window(0, 0, width, height, WC_MAIN_WINDOW, NULL)
{
- InitializeWindowViewport(this, 0, 0, width, height, TileXY(32, 32), ZOOM_LVL_VIEWPORT);
+ InitializeWindowViewport(this, 0, 0, width, height, TileXY(1, 1), ZOOM_LVL_VIEWPORT);
}
virtual void OnPaint()
--- a/src/map.cpp Thu Dec 18 18:47:39 2008 +0000
+++ b/src/map.cpp Fri Dec 19 01:32:07 2008 +0200
@@ -35,8 +35,8 @@
{
/* Make sure that the map size is within the limits and that
* the x axis size is a power of 2. */
- if (size_x < 64 || size_x > 2048 ||
- size_y < 64 || size_y > 2048 ||
+ if (size_x < 4 || size_x > 2048 ||
+ size_y < 4 || size_y > 2048 ||
(size_x & (size_x - 1)) != 0 ||
(size_y & (size_y - 1)) != 0)
error("Invalid map size");
--- a/src/misc.cpp Thu Dec 18 18:47:39 2008 +0000
+++ b/src/misc.cpp Fri Dec 19 01:32:07 2008 +0200
@@ -214,7 +214,7 @@
for (TileIndex i = 0; i != size;) {
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
- for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].type_height = buf[j];
+ for (uint j = 0; j != MAP_SL_BUF_SIZE && i != size; j++) _m[i++].type_height = buf[j];
}
}
@@ -225,7 +225,7 @@
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
- for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].type_height;
+ for (uint j = 0; j != MAP_SL_BUF_SIZE && i != size; j++) buf[j] = _m[i++].type_height;
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
}
}
@@ -237,7 +237,7 @@
for (TileIndex i = 0; i != size;) {
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
- for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m1 = buf[j];
+ for (uint j = 0; j != MAP_SL_BUF_SIZE && i != size; j++) _m[i++].m1 = buf[j];
}
}
@@ -248,7 +248,7 @@
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
- for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m1;
+ for (uint j = 0; j != MAP_SL_BUF_SIZE && i != size; j++) buf[j] = _m[i++].m1;
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
}
}
@@ -263,7 +263,7 @@
/* In those versions the m2 was 8 bits */
CheckSavegameVersion(5) ? SLE_FILE_U8 | SLE_VAR_U16 : SLE_UINT16
);
- for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m2 = buf[j];
+ for (uint j = 0; j != MAP_SL_BUF_SIZE && i != size; j++) _m[i++].m2 = buf[j];
}
}
@@ -274,7 +274,7 @@
SlSetLength(size * sizeof(uint16));
for (TileIndex i = 0; i != size;) {
- for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m2;
+ for (uint j = 0; j != MAP_SL_BUF_SIZE && i != size; j++) buf[j] = _m[i++].m2;
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT16);
}
}
@@ -286,7 +286,7 @@
for (TileIndex i = 0; i != size;) {
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
- for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m3 = buf[j];
+ for (uint j = 0; j != MAP_SL_BUF_SIZE && i != size; j++) _m[i++].m3 = buf[j];
}
}
@@ -297,7 +297,7 @@
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
- for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m3;
+ for (uint j = 0; j != MAP_SL_BUF_SIZE && i != size; j++) buf[j] = _m[i++].m3;
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
}
}
@@ -309,7 +309,7 @@
for (TileIndex i = 0; i != size;) {
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
- for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m4 = buf[j];
+ for (uint j = 0; j != MAP_SL_BUF_SIZE && i != size; j++) _m[i++].m4 = buf[j];
}
}
@@ -320,7 +320,7 @@
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
- for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m4;
+ for (uint j = 0; j != MAP_SL_BUF_SIZE && i != size; j++) buf[j] = _m[i++].m4;
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
}
}
@@ -332,7 +332,7 @@
for (TileIndex i = 0; i != size;) {
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
- for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m5 = buf[j];
+ for (uint j = 0; j != MAP_SL_BUF_SIZE && i != size; j++) _m[i++].m5 = buf[j];
}
}
@@ -343,7 +343,7 @@
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
- for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m5;
+ for (uint j = 0; j != MAP_SL_BUF_SIZE && i != size; j++) buf[j] = _m[i++].m5;
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
}
}
@@ -356,8 +356,9 @@
if (CheckSavegameVersion(42)) {
for (TileIndex i = 0; i != size;) {
/* 1024, otherwise we overflow on 64x64 maps! */
+ /* XXX: fail */
SlArray(buf, 1024, SLE_UINT8);
- for (uint j = 0; j != 1024; j++) {
+ for (uint j = 0; j != 1024 && i < size - 4; j++) {
_m[i++].m6 = GB(buf[j], 0, 2);
_m[i++].m6 = GB(buf[j], 2, 2);
_m[i++].m6 = GB(buf[j], 4, 2);
@@ -367,7 +368,7 @@
} else {
for (TileIndex i = 0; i != size;) {
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
- for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _m[i++].m6 = buf[j];
+ for (uint j = 0; j != MAP_SL_BUF_SIZE && i != size; j++) _m[i++].m6 = buf[j];
}
}
}
@@ -379,7 +380,7 @@
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
- for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _m[i++].m6;
+ for (uint j = 0; j != MAP_SL_BUF_SIZE && i != size; j++) buf[j] = _m[i++].m6;
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
}
}
@@ -391,7 +392,7 @@
for (TileIndex i = 0; i != size;) {
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
- for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) _me[i++].m7 = buf[j];
+ for (uint j = 0; j != MAP_SL_BUF_SIZE && i != size; j++) _me[i++].m7 = buf[j];
}
}
@@ -402,7 +403,7 @@
SlSetLength(size);
for (TileIndex i = 0; i != size;) {
- for (uint j = 0; j != MAP_SL_BUF_SIZE; j++) buf[j] = _me[i++].m7;
+ for (uint j = 0; j != MAP_SL_BUF_SIZE && i != size; j++) buf[j] = _me[i++].m7;
SlArray(buf, MAP_SL_BUF_SIZE, SLE_UINT8);
}
}
--- a/src/settings.cpp Thu Dec 18 18:47:39 2008 +0000
+++ b/src/settings.cpp Fri Dec 19 01:32:07 2008 +0200
@@ -1408,8 +1408,8 @@
SDT_VAR(GameSettings, game_creation.heightmap_rotation, SLE_UINT8, S,MS, 0, 0, 1, 0, STR_CONFIG_PATCHES_HEIGHTMAP_ROTATION, NULL),
SDT_VAR(GameSettings, game_creation.se_flat_world_height, SLE_UINT8, S, 0, 0, 0, 15, 0, STR_CONFIG_PATCHES_SE_FLAT_WORLD_HEIGHT, NULL),
- SDT_VAR(GameSettings, game_creation.map_x, SLE_UINT8, S, 0, 8, 6, 11, 0, STR_CONFIG_PATCHES_MAP_X, NULL),
- SDT_VAR(GameSettings, game_creation.map_y, SLE_UINT8, S, 0, 8, 6, 11, 0, STR_CONFIG_PATCHES_MAP_Y, NULL),
+ SDT_VAR(GameSettings, game_creation.map_x, SLE_UINT8, S, 0, 8, 2, 11, 0, STR_CONFIG_PATCHES_MAP_X, NULL),
+ SDT_VAR(GameSettings, game_creation.map_y, SLE_UINT8, S, 0, 8, 2, 11, 0, STR_CONFIG_PATCHES_MAP_Y, NULL),
SDT_CONDOMANY(GameSettings, locale.currency, SLE_UINT8, 97, SL_MAX_VERSION, N, 0, 0, CUSTOM_CURRENCY_ID, "GBP|USD|EUR|YEN|ATS|BEF|CHF|CZK|DEM|DKK|ESP|FIM|FRF|GRD|HUF|ISK|ITL|NLG|NOK|PLN|ROL|RUR|SIT|SEK|YTL|SKK|BRR|custom", STR_NULL, NULL, NULL),
SDT_CONDOMANY(GameSettings, locale.units, SLE_UINT8, 97, SL_MAX_VERSION, N, 0, 1, 2, "imperial|metric|si", STR_NULL, NULL, NULL),
--- a/src/tgp.cpp Thu Dec 18 18:47:39 2008 +0000
+++ b/src/tgp.cpp Fri Dec 19 01:32:07 2008 +0200
@@ -711,10 +711,10 @@
HeightMapAdjustWaterLevel(water_percent, h_max_new);
- HeightMapCoastLines();
+ //HeightMapCoastLines();
HeightMapSmoothSlopes(roughness);
- HeightMapSmoothCoasts();
+ //HeightMapSmoothCoasts();
HeightMapSmoothSlopes(roughness);
HeightMapSineTransform(12, h_max_new);
--- 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;
--- a/src/tree_cmd.cpp Thu Dec 18 18:47:39 2008 +0000
+++ b/src/tree_cmd.cpp Fri Dec 19 01:32:07 2008 +0200
@@ -193,9 +193,10 @@
static void PlaceMoreTrees()
{
uint i = ScaleByMapSize(GB(Random(), 0, 5) + 25);
+
do {
DoPlaceMoreTrees(RandomTile());
- } while (--i);
+ } while (i && --i);
}
/**
@@ -268,7 +269,7 @@
PlaceTreeAtSameHeight(tile, ht);
}
}
- } while (--i);
+ } while (i && --i);
/* place extra trees at rainforest area */
if (_settings_game.game_creation.landscape == LT_TROPIC) {
@@ -283,7 +284,7 @@
if (GetTropicZone(tile) == TROPICZONE_RAINFOREST && CanPlantTreesOnTile(tile, false)) {
PlaceTree(tile, r);
}
- } while (--i);
+ } while (i && --i);
}
}
@@ -673,8 +674,13 @@
case 2: { /* add a neighbouring tree */
TreeType treetype = GetTreeType(tile);
+
+ TileIndexDiff dt = TileOffsByDir((Direction)(Random() & 7));
+
+ /* Don't plant trees in the void */
+ if (!IsValidTile(tile + dt)) return;
- tile += TileOffsByDir((Direction)(Random() & 7));
+ tile += dt;
/* Cacti don't spread */
if (!CanPlantTreesOnTile(tile, false)) return;
--- a/src/window.cpp Thu Dec 18 18:47:39 2008 +0000
+++ b/src/window.cpp Fri Dec 19 01:32:07 2008 +0200
@@ -2052,7 +2052,7 @@
FOR_ALL_WINDOWS(wz) {
const Window *w = *wz;
- if (w->window_class == cls && w->window_number == number) w->SetDirty();
+ if (w && w->window_class == cls && w->window_number == number) w->SetDirty();
}
}