Skip to content

Commit e771484

Browse files
committed
Change: Use noise map to place desert and tropic zones.
Zones are no longer tied to terrain height.
1 parent cb06ca6 commit e771484

File tree

3 files changed

+19
-25
lines changed

3 files changed

+19
-25
lines changed

src/landscape.cpp

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -971,18 +971,21 @@ static void GenerateTerrain(int type, uint flag)
971971

972972
#include "table/genland.h"
973973

974-
static void CreateDesertOrRainForest(uint desert_tropic_line)
974+
static void CreateDesertOrRainForest()
975975
{
976976
uint update_freq = Map::Size() / 4;
977+
int desert_tropic_line = _settings_game.game_creation.desert_coverage * 2 - 100;
977978

978979
for (const auto tile : Map::Iterate()) {
979980
if ((tile % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
980981

981982
if (!IsValidTile(tile)) continue;
983+
if (IsTileType(tile, MP_WATER)) continue;
984+
if (PerlinNoise2D(TileX(tile), TileY(tile), 0.35, 37) * 100 > desert_tropic_line) continue;
982985

983-
auto allows_desert = [tile, desert_tropic_line](auto &offset) {
986+
auto allows_desert = [tile](const auto &offset) {
984987
TileIndex t = AddTileIndexDiffCWrap(tile, offset);
985-
return t == INVALID_TILE || (TileHeight(t) < desert_tropic_line && !IsTileType(t, MP_WATER));
988+
return t == INVALID_TILE || !IsTileType(t, MP_WATER);
986989
};
987990
if (std::all_of(std::begin(_make_desert_or_rainforest_data), std::end(_make_desert_or_rainforest_data), allows_desert)) {
988991
SetTropicZone(tile, TROPICZONE_DESERT);
@@ -999,8 +1002,10 @@ static void CreateDesertOrRainForest(uint desert_tropic_line)
9991002
if ((tile % update_freq) == 0) IncreaseGeneratingWorldProgress(GWP_LANDSCAPE);
10001003

10011004
if (!IsValidTile(tile)) continue;
1005+
if (GetTropicZone(tile) != TROPICZONE_NORMAL) continue;
1006+
if (PerlinNoise2D(TileX(tile), TileY(tile), 0.5, 179) * 100 < desert_tropic_line) continue;
10021007

1003-
auto allows_rainforest = [tile](auto &offset) {
1008+
auto allows_rainforest = [tile](const auto &offset) {
10041009
TileIndex t = AddTileIndexDiffCWrap(tile, offset);
10051010
return t == INVALID_TILE || !IsTileType(t, MP_CLEAR) || !IsClearGround(t, CLEAR_DESERT);
10061011
};
@@ -1589,16 +1594,6 @@ static void CalculateSnowLine()
15891594
_settings_game.game_creation.snow_line_height = std::max(CalculateCoverageLine(_settings_game.game_creation.snow_coverage, 0), 2u);
15901595
}
15911596

1592-
/**
1593-
* Calculate the line (in height) between desert and tropic.
1594-
* @return The height of the line between desert and tropic.
1595-
*/
1596-
static uint8_t CalculateDesertLine()
1597-
{
1598-
/* CalculateCoverageLine() runs from top to bottom, so we need to invert the coverage. */
1599-
return CalculateCoverageLine(100 - _settings_game.game_creation.desert_coverage, 4);
1600-
}
1601-
16021597
bool GenerateLandscape(uint8_t mode)
16031598
{
16041599
/* Number of steps of landscape generation */
@@ -1688,11 +1683,9 @@ bool GenerateLandscape(uint8_t mode)
16881683
CalculateSnowLine();
16891684
break;
16901685

1691-
case LandscapeType::Tropic: {
1692-
uint desert_tropic_line = CalculateDesertLine();
1693-
CreateDesertOrRainForest(desert_tropic_line);
1686+
case LandscapeType::Tropic:
1687+
CreateDesertOrRainForest();
16941688
break;
1695-
}
16961689

16971690
default:
16981691
break;

src/tgp.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@
145145
#include "genworld.h"
146146
#include "core/random_func.hpp"
147147
#include "landscape_type.h"
148+
#include "tgp.h"
148149

149150
#include "safeguards.h"
150151

@@ -701,8 +702,6 @@ static void HeightMapAdjustWaterLevel(int64_t water_percent, Height h_max_new)
701702
}
702703
}
703704

704-
static double perlin_coast_noise_2D(const double x, const double y, const double p, const int prime);
705-
706705
/**
707706
* This routine sculpts in from the edge a random amount, again a Perlin
708707
* sequence, to avoid the rigid flat-edge slopes that were present before. The
@@ -735,7 +734,7 @@ static void HeightMapCoastLines(BorderFlags water_borders)
735734
for (y = 0; y <= _height_map.size_y; y++) {
736735
if (water_borders.Test(BorderFlag::NorthEast)) {
737736
/* Top right */
738-
max_x = abs((perlin_coast_noise_2D(_height_map.size_y - y, y, 0.9, 53) + 0.25) * 5 + (perlin_coast_noise_2D(y, y, 0.35, 179) + 1) * 12);
737+
max_x = abs((PerlinNoise2D(_height_map.size_y - y, y, 0.9, 53) + 0.25) * 5 + (PerlinNoise2D(y, y, 0.35, 179) + 1) * 12);
739738
max_x = std::max((smallest_size * smallest_size / 64) + max_x, (smallest_size * smallest_size / 64) + margin - max_x);
740739
if (smallest_size < 8 && max_x > 5) max_x /= 1.5;
741740
for (x = 0; x < max_x; x++) {
@@ -745,7 +744,7 @@ static void HeightMapCoastLines(BorderFlags water_borders)
745744

746745
if (water_borders.Test(BorderFlag::SouthWest)) {
747746
/* Bottom left */
748-
max_x = abs((perlin_coast_noise_2D(_height_map.size_y - y, y, 0.85, 101) + 0.3) * 6 + (perlin_coast_noise_2D(y, y, 0.45, 67) + 0.75) * 8);
747+
max_x = abs((PerlinNoise2D(_height_map.size_y - y, y, 0.85, 101) + 0.3) * 6 + (PerlinNoise2D(y, y, 0.45, 67) + 0.75) * 8);
749748
max_x = std::max((smallest_size * smallest_size / 64) + max_x, (smallest_size * smallest_size / 64) + margin - max_x);
750749
if (smallest_size < 8 && max_x > 5) max_x /= 1.5;
751750
for (x = _height_map.size_x; x > (_height_map.size_x - 1 - max_x); x--) {
@@ -758,7 +757,7 @@ static void HeightMapCoastLines(BorderFlags water_borders)
758757
for (x = 0; x <= _height_map.size_x; x++) {
759758
if (water_borders.Test(BorderFlag::NorthWest)) {
760759
/* Top left */
761-
max_y = abs((perlin_coast_noise_2D(x, _height_map.size_y / 2, 0.9, 167) + 0.4) * 5 + (perlin_coast_noise_2D(x, _height_map.size_y / 3, 0.4, 211) + 0.7) * 9);
760+
max_y = abs((PerlinNoise2D(x, _height_map.size_y / 2, 0.9, 167) + 0.4) * 5 + (PerlinNoise2D(x, _height_map.size_y / 3, 0.4, 211) + 0.7) * 9);
762761
max_y = std::max((smallest_size * smallest_size / 64) + max_y, (smallest_size * smallest_size / 64) + margin - max_y);
763762
if (smallest_size < 8 && max_y > 5) max_y /= 1.5;
764763
for (y = 0; y < max_y; y++) {
@@ -768,7 +767,7 @@ static void HeightMapCoastLines(BorderFlags water_borders)
768767

769768
if (water_borders.Test(BorderFlag::SouthEast)) {
770769
/* Bottom right */
771-
max_y = abs((perlin_coast_noise_2D(x, _height_map.size_y / 3, 0.85, 71) + 0.25) * 6 + (perlin_coast_noise_2D(x, _height_map.size_y / 3, 0.35, 193) + 0.75) * 12);
770+
max_y = abs((PerlinNoise2D(x, _height_map.size_y / 3, 0.85, 71) + 0.25) * 6 + (PerlinNoise2D(x, _height_map.size_y / 3, 0.35, 193) + 0.75) * 12);
772771
max_y = std::max((smallest_size * smallest_size / 64) + max_y, (smallest_size * smallest_size / 64) + margin - max_y);
773772
if (smallest_size < 8 && max_y > 5) max_y /= 1.5;
774773
for (y = _height_map.size_y; y > (_height_map.size_y - 1 - max_y); y--) {
@@ -942,7 +941,7 @@ static double interpolated_noise(const double x, const double y, const int prime
942941
* sequences. as you can guess by its title, i use this to create the indented
943942
* coastline, which is just another perlin sequence.
944943
*/
945-
static double perlin_coast_noise_2D(const double x, const double y, const double p, const int prime)
944+
double PerlinNoise2D(const double x, const double y, const double p, const int prime)
946945
{
947946
double total = 0.0;
948947

src/tgp.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@
1313
void GenerateTerrainPerlin();
1414
uint GetEstimationTGPMapHeight();
1515

16+
double PerlinNoise2D(const double x, const double y, const double p, const int prime);
17+
1618
#endif /* TGP_H */

0 commit comments

Comments
 (0)