mirror of https://github.com/OpenTTD/OpenTTD.git
(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.
This commit is contained in:
parent
4e6d6578e4
commit
3617d24318
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
{
|
||||
|
|
12
landscape.c
12
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);
|
||||
|
|
1
macros.h
1
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
|
||||
|
|
22
map.c
22
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},
|
||||
|
|
4
map.h
4
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;
|
||||
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue