Index: src/tgp.cpp =================================================================== --- src/tgp.cpp (revision 13649) +++ src/tgp.cpp (working copy) @@ -174,6 +174,7 @@ uint size_x; //< MapSizeX() uint size_y; //< MapSizeY() + /* Height map accessor */ inline height_t &height(uint x, uint y) { return h[x + y * dim_x]; } @@ -262,7 +263,7 @@ _height_map.h = NULL; } -/** RandomHeight() generator */ +/** Generates new height in given amplitude (generated numbers will range from - amplitude to + amplitude) */ static inline height_t RandomHeight(amplitude_t rMax) { amplitude_t ra = (Random() << 16) | (Random() & 0x0000FFFF); @@ -279,13 +280,14 @@ uint step = size_min >> log_frequency; uint x, y; + /* Trying to apply noise to uninitialized height map */ assert(_height_map.h != NULL); /* Are we finished? */ if (step == 0) return false; + /* This is first round, we need to establish base heights with step = size_min */ if (log_frequency == 0) { - /* This is first round, we need to establish base heights with step = size_min */ for (y = 0; y <= _height_map.size_y; y += step) { for (x = 0; x <= _height_map.size_x; x += step) { height_t height = (amplitude > 0) ? RandomHeight(amplitude) : 0; @@ -316,11 +318,14 @@ } } + /* Add some more smaller noise */ for (y = 0; y <= _height_map.size_y; y += step) { for (x = 0; x <= _height_map.size_x; x += step) { _height_map.height(x, y) += RandomHeight(amplitude); } } + + /* Return false if we are finished (reached the minimal step size) */ return (step > 1); } @@ -338,11 +343,14 @@ for (log_size_min = 6; (1U << log_size_min) < size_min; log_size_min++) { } log_frequency_min = log_size_min - 6; + /* Keep increasing the frequence unitil we reach the step size equal to one tile */ do { log_frequency = iteration_round - log_frequency_min; if (log_frequency >= 0) { + /* Additional noise with decreasing amplitude will be applied for first several rounds */ amplitude = _amplitudes_by_smoothness_and_frequency[_settings_game.game_creation.tgen_smoothness][log_frequency]; } else { + /* Once amplitude reaches zero, we will keep smoothing the terrain */ amplitude = 0; } continue_iteration = ApplyNoise(iteration_round, amplitude); @@ -357,7 +365,7 @@ int64 h_accu = 0; h_min = h_max = _height_map.height(0, 0); - /* Get h_min, h_max and accumulate heights into h_accu */ + /* Calculate the sum of all heights in the height map */ FOR_ALL_TILES_IN_HEIGHT(h) { if (*h < h_min) h_min = *h; if (*h > h_max) h_max = *h; @@ -379,7 +387,7 @@ int *hist = hist_buf - h_min; height_t *h; - /* Fill histogram */ + /* Count the heights and fill the histogram */ FOR_ALL_TILES_IN_HEIGHT(h) { assert(*h >= h_min); assert(*h <= h_max); @@ -769,7 +777,7 @@ } -/** A small helper function */ +/** A small helper function to initialize the terrain */ static void TgenSetTileHeight(TileIndex tile, int height) { SetTileHeight(tile, height);