1
0
Fork 0

(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.
release/0.4.5
tron 2005-01-28 15:31:04 +00:00
parent 4e6d6578e4
commit 3617d24318
9 changed files with 45 additions and 18 deletions

View File

@ -740,7 +740,7 @@ void GenerateClearTile(void)
uint32 r; uint32 r;
/* add hills */ /* add hills */
i = (Random() & 0x3FF) | 0x400; i = ScaleByMapSize((Random() & 0x3FF) + 0x400);
do { do {
tile = TILE_MASK(Random()); tile = TILE_MASK(Random());
if (IsTileType(tile, MP_CLEAR)) if (IsTileType(tile, MP_CLEAR))
@ -748,7 +748,7 @@ void GenerateClearTile(void)
} while (--i); } while (--i);
/* add grey squares */ /* add grey squares */
i = (Random() & 0x7F) | 0x80; i = ScaleByMapSize((Random() & 0x7F) + 0x80);
do { do {
r = Random(); r = Random();
tile = TILE_MASK(r); tile = TILE_MASK(r);

View File

@ -1594,7 +1594,8 @@ static const byte _numof_industry_table[4][12] = {
static void PlaceInitialIndustry(byte type, int amount) 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) if (_opt.diff.number_industries != 0)
{ {

View File

@ -656,38 +656,38 @@ void GenerateLandscape(void)
uint32 r; uint32 r;
if (_opt.landscape == LT_HILLY) { if (_opt.landscape == LT_HILLY) {
i = ((Random() & 0x7F) + 950) * LANDSCAPE_SIZE_FACTOR; i = ScaleByMapSize((Random() & 0x7F) + 950);
do { do {
GenerateTerrain(2, 0); GenerateTerrain(2, 0);
} while (--i); } while (--i);
r = Random(); r = Random();
flag = (r & 3) | 4; flag = (r & 3) | 4;
i = (((r >> 16) & 0x7F) + 450) * LANDSCAPE_SIZE_FACTOR; i = ScaleByMapSize(((r >> 16) & 0x7F) + 450);
do { do {
GenerateTerrain(4, flag); GenerateTerrain(4, flag);
} while (--i); } while (--i);
} else if (_opt.landscape == LT_DESERT) { } else if (_opt.landscape == LT_DESERT) {
i = ((Random()&0x7F) + 170) * LANDSCAPE_SIZE_FACTOR; i = ScaleByMapSize((Random()&0x7F) + 170);
do { do {
GenerateTerrain(0, 0); GenerateTerrain(0, 0);
} while (--i); } while (--i);
r = Random(); r = Random();
flag = (r & 3) | 4; flag = (r & 3) | 4;
i = (((r >> 16) & 0xFF) + 1700) * LANDSCAPE_SIZE_FACTOR; i = ScaleByMapSize(((r >> 16) & 0xFF) + 1700);
do { do {
GenerateTerrain(0, flag); GenerateTerrain(0, flag);
} while (--i); } while (--i);
flag ^= 2; flag ^= 2;
i = ((Random() & 0x7F) + 410) * LANDSCAPE_SIZE_FACTOR; i = ScaleByMapSize((Random() & 0x7F) + 410);
do { do {
GenerateTerrain(3, flag); GenerateTerrain(3, flag);
} while (--i); } while (--i);
} else { } 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 { do {
GenerateTerrain(_opt.diff.terrain_type, 0); GenerateTerrain(_opt.diff.terrain_type, 0);
} while (--i); } while (--i);

View File

@ -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) ((x) >= (base) && (x) < (base) + (size))
#define IS_INSIDE_1D(x, base, size) ( (uint)((x) - (base)) < ((uint)(size)) ) #define IS_INSIDE_1D(x, base, size) ( (uint)((x) - (base)) < ((uint)(size)) )
#define LANDSCAPE_SIZE_FACTOR 1
enum { enum {
CORRECT_Z_BITS = 1 << 1 | 1 << 2 | 1 << 3 | 1 << 4 | 1 << 5 | 1 << 6 | 1 << 7 CORRECT_Z_BITS = 1 << 1 | 1 << 2 | 1 << 3 | 1 << 4 | 1 << 5 | 1 << 6 | 1 << 7

22
map.c
View File

@ -54,6 +54,28 @@ TileIndex TileAdd(TileIndex tile, TileIndexDiff add,
#endif #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[] = { const TileIndexDiffC _tileoffs_by_dir[] = {
{-1, 0}, {-1, 0},
{ 0, 1}, { 0, 1},

4
map.h
View File

@ -26,6 +26,10 @@ static inline uint MapMaxY(void) { return MapSizeY() - 1; }
/* The number of tiles in the map */ /* The number of tiles in the map */
static inline uint MapSize(void) { return MapSizeX() * MapSizeY(); } 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; typedef uint32 TileIndex;

View File

@ -1036,8 +1036,9 @@ static const byte _num_initial_towns[3] = {
void GenerateTowns(void) void GenerateTowns(void)
{ {
uint n; uint n =
n = _num_initial_towns[_opt.diff.number_towns] + (Random()&7); ScaleByMapSize(_num_initial_towns[_opt.diff.number_towns] + (Random() & 7));
do CreateRandomTown(); while (--n); do CreateRandomTown(); while (--n);
} }

View File

@ -90,7 +90,7 @@ static void DoPlaceMoreTrees(uint tile)
static void PlaceMoreTrees(void) static void PlaceMoreTrees(void)
{ {
int i = (Random() & 0x1F) + 25; int i = ScaleByMapSize((Random() & 0x1F) + 25);
do { do {
DoPlaceMoreTrees(TILE_MASK(Random())); DoPlaceMoreTrees(TILE_MASK(Random()));
} while (--i); } while (--i);
@ -102,7 +102,7 @@ void PlaceTreesRandomly(void)
uint32 r; uint32 r;
uint tile; uint tile;
i = 1000; i = ScaleByMapSize(1000);
do { do {
r = Random(); r = Random();
tile = TILE_MASK(r); tile = TILE_MASK(r);
@ -114,7 +114,7 @@ void PlaceTreesRandomly(void)
/* place extra trees at rainforest area */ /* place extra trees at rainforest area */
if (_opt.landscape == LT_DESERT) { if (_opt.landscape == LT_DESERT) {
i = 15000; i = ScaleByMapSize(15000);
do { do {
r = Random(); r = Random();

View File

@ -258,8 +258,8 @@ void GenerateUnmovables(void)
return; return;
/* add radio tower */ /* add radio tower */
i = 1000; i = ScaleByMapSize(1000);
j = 40; // limit of 40 radio towers per world. j = ScaleByMapSize(40); // maximum number of radio towers on the map
do { do {
r = Random(); r = Random();
tile = r % MapSize(); tile = r % MapSize();
@ -280,7 +280,7 @@ void GenerateUnmovables(void)
return; return;
/* add lighthouses */ /* add lighthouses */
i = (Random()&3) + 7; i = ScaleByMapSize1D((Random() & 3) + 7);
do { do {
restart: restart:
r = Random(); r = Random();