summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortron <tron@openttd.org>2005-01-28 15:31:04 +0000
committertron <tron@openttd.org>2005-01-28 15:31:04 +0000
commit3617d243189ec7076bec045d04e4a96ff55a8de8 (patch)
treeefbaeb3426c01178731116a7fca722dc190ac78f
parent4e6d6578e4e4d17712acff4b0c1f749f405a815d (diff)
downloadopenttd-3617d243189ec7076bec045d04e4a96ff55a8de8.tar.xz
(svn r1706) Implement ScaleByMapSize() and ScaleByMapSize1D()
These scale a number relative to the map size/circumference. Use them to scale the amount of map objects. Of course at the moment they return just the input, because there are no bigger/smaller maps yet.
-rw-r--r--clear_cmd.c4
-rw-r--r--industry_cmd.c3
-rw-r--r--landscape.c12
-rw-r--r--macros.h1
-rw-r--r--map.c22
-rw-r--r--map.h4
-rw-r--r--town_cmd.c5
-rw-r--r--tree_cmd.c6
-rw-r--r--unmovable_cmd.c6
9 files changed, 45 insertions, 18 deletions
diff --git a/clear_cmd.c b/clear_cmd.c
index 27942bcb6..a3095646b 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 b22ab058e..9849e1321 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 18e51ebd6..ef9984692 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 765a4e7a6..19194ac86 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 81a72b28b..6e9721b3b 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 f37610d93..f37245dfb 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 73cab9989..836657ab6 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 eb43c21f9..bf9fbdb73 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 9ffc4a235..129e22c28 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();