diff --git a/clear_cmd.c b/clear_cmd.c index 27942bcb6e..a3095646b4 100644 --- a/clear_cmd.c +++ b/clear_cmd.c @@ -740,7 +740,7 @@ void GenerateClearTile(void) uint32 r; /* add hills */ - i = (Random() & 0x3FF) | 0x400; + i = ScaleByMapSize((Random() & 0x3FF) + 0x400); do { tile = TILE_MASK(Random()); if (IsTileType(tile, MP_CLEAR)) @@ -748,7 +748,7 @@ void GenerateClearTile(void) } while (--i); /* add grey squares */ - i = (Random() & 0x7F) | 0x80; + i = ScaleByMapSize((Random() & 0x7F) + 0x80); do { r = Random(); tile = TILE_MASK(r); diff --git a/industry_cmd.c b/industry_cmd.c index b22ab058e0..9849e1321a 100644 --- a/industry_cmd.c +++ b/industry_cmd.c @@ -1594,7 +1594,8 @@ static const byte _numof_industry_table[4][12] = { static void PlaceInitialIndustry(byte type, int amount) { - int num = _numof_industry_table[_opt.diff.number_industries][amount]; + int num = + ScaleByMapSize(_numof_industry_table[_opt.diff.number_industries][amount]); if (_opt.diff.number_industries != 0) { diff --git a/landscape.c b/landscape.c index 18e51ebd6e..ef99846925 100644 --- a/landscape.c +++ b/landscape.c @@ -656,38 +656,38 @@ void GenerateLandscape(void) uint32 r; if (_opt.landscape == LT_HILLY) { - i = ((Random() & 0x7F) + 950) * LANDSCAPE_SIZE_FACTOR; + i = ScaleByMapSize((Random() & 0x7F) + 950); do { GenerateTerrain(2, 0); } while (--i); r = Random(); flag = (r & 3) | 4; - i = (((r >> 16) & 0x7F) + 450) * LANDSCAPE_SIZE_FACTOR; + i = ScaleByMapSize(((r >> 16) & 0x7F) + 450); do { GenerateTerrain(4, flag); } while (--i); } else if (_opt.landscape == LT_DESERT) { - i = ((Random()&0x7F) + 170) * LANDSCAPE_SIZE_FACTOR; + i = ScaleByMapSize((Random()&0x7F) + 170); do { GenerateTerrain(0, 0); } while (--i); r = Random(); flag = (r & 3) | 4; - i = (((r >> 16) & 0xFF) + 1700) * LANDSCAPE_SIZE_FACTOR; + i = ScaleByMapSize(((r >> 16) & 0xFF) + 1700); do { GenerateTerrain(0, flag); } while (--i); flag ^= 2; - i = ((Random() & 0x7F) + 410) * LANDSCAPE_SIZE_FACTOR; + i = ScaleByMapSize((Random() & 0x7F) + 410); do { GenerateTerrain(3, flag); } while (--i); } else { - i = ((Random() & 0x7F) + (3 - _opt.diff.quantity_sea_lakes)*256 + 100) * LANDSCAPE_SIZE_FACTOR; + i = ScaleByMapSize((Random() & 0x7F) + (3 - _opt.diff.quantity_sea_lakes) * 256 + 100); do { GenerateTerrain(_opt.diff.terrain_type, 0); } while (--i); diff --git a/macros.h b/macros.h index 765a4e7a63..19194ac863 100644 --- a/macros.h +++ b/macros.h @@ -68,7 +68,6 @@ static inline int64 BIGMULS(int32 a, int32 b) { //#define IS_INSIDE_1D(x, base, size) ((x) >= (base) && (x) < (base) + (size)) #define IS_INSIDE_1D(x, base, size) ( (uint)((x) - (base)) < ((uint)(size)) ) -#define LANDSCAPE_SIZE_FACTOR 1 enum { CORRECT_Z_BITS = 1 << 1 | 1 << 2 | 1 << 3 | 1 << 4 | 1 << 5 | 1 << 6 | 1 << 7 diff --git a/map.c b/map.c index 81a72b28b5..6e9721b3be 100644 --- a/map.c +++ b/map.c @@ -54,6 +54,28 @@ TileIndex TileAdd(TileIndex tile, TileIndexDiff add, #endif +uint ScaleByMapSize(uint n) +{ + int shift = (int)MapLogX() - 8 + (int)MapLogY() - 8; + + if (shift < 0) + return (n + (1 << -shift) - 1) >> -shift; + else + return n << shift; +} + + +uint ScaleByMapSize1D(uint n) +{ + int shift = ((int)MapLogX() - 8 + (int)MapLogY() - 8) / 2; + + if (shift < 0) + return (n + (1 << -shift) - 1) >> -shift; + else + return n << shift; +} + + const TileIndexDiffC _tileoffs_by_dir[] = { {-1, 0}, { 0, 1}, diff --git a/map.h b/map.h index f37610d939..f37245dfbb 100644 --- a/map.h +++ b/map.h @@ -26,6 +26,10 @@ static inline uint MapMaxY(void) { return MapSizeY() - 1; } /* The number of tiles in the map */ static inline uint MapSize(void) { return MapSizeX() * MapSizeY(); } +// Scale a number relative to the map size +uint ScaleByMapSize(uint); // Scale relative to the number of tiles +uint ScaleByMapSize1D(uint); // Scale relative to the circumference of the map + typedef uint32 TileIndex; diff --git a/town_cmd.c b/town_cmd.c index 73cab99897..836657ab6a 100644 --- a/town_cmd.c +++ b/town_cmd.c @@ -1036,8 +1036,9 @@ static const byte _num_initial_towns[3] = { void GenerateTowns(void) { - uint n; - n = _num_initial_towns[_opt.diff.number_towns] + (Random()&7); + uint n = + ScaleByMapSize(_num_initial_towns[_opt.diff.number_towns] + (Random() & 7)); + do CreateRandomTown(); while (--n); } diff --git a/tree_cmd.c b/tree_cmd.c index eb43c21f98..bf9fbdb739 100644 --- a/tree_cmd.c +++ b/tree_cmd.c @@ -90,7 +90,7 @@ static void DoPlaceMoreTrees(uint tile) static void PlaceMoreTrees(void) { - int i = (Random() & 0x1F) + 25; + int i = ScaleByMapSize((Random() & 0x1F) + 25); do { DoPlaceMoreTrees(TILE_MASK(Random())); } while (--i); @@ -102,7 +102,7 @@ void PlaceTreesRandomly(void) uint32 r; uint tile; - i = 1000; + i = ScaleByMapSize(1000); do { r = Random(); tile = TILE_MASK(r); @@ -114,7 +114,7 @@ void PlaceTreesRandomly(void) /* place extra trees at rainforest area */ if (_opt.landscape == LT_DESERT) { - i = 15000; + i = ScaleByMapSize(15000); do { r = Random(); diff --git a/unmovable_cmd.c b/unmovable_cmd.c index 9ffc4a235d..129e22c28b 100644 --- a/unmovable_cmd.c +++ b/unmovable_cmd.c @@ -258,8 +258,8 @@ void GenerateUnmovables(void) return; /* add radio tower */ - i = 1000; - j = 40; // limit of 40 radio towers per world. + i = ScaleByMapSize(1000); + j = ScaleByMapSize(40); // maximum number of radio towers on the map do { r = Random(); tile = r % MapSize(); @@ -280,7 +280,7 @@ void GenerateUnmovables(void) return; /* add lighthouses */ - i = (Random()&3) + 7; + i = ScaleByMapSize1D((Random() & 3) + 7); do { restart: r = Random();