changeset 9413 | 7042a8ec3fa8 |
parent 9358 | 2e1e4d2f71dd |
child 9603 | 40a8d2079ebe |
9412:163c465bf250 | 9413:7042a8ec3fa8 |
---|---|
209 {1000, 1200, 800, 500, 200, 16, 4, 0, 0, 0, 0, 0}, |
209 {1000, 1200, 800, 500, 200, 16, 4, 0, 0, 0, 0, 0}, |
210 /* Very Rough */ |
210 /* Very Rough */ |
211 {1500, 1000, 1200, 1000, 500, 32, 20, 0, 0, 0, 0, 0}, |
211 {1500, 1000, 1200, 1000, 500, 32, 20, 0, 0, 0, 0, 0}, |
212 }; |
212 }; |
213 |
213 |
214 /** Desired water percentage (100% == 1024) - indexed by _settings.difficulty.quantity_sea_lakes */ |
214 /** Desired water percentage (100% == 1024) - indexed by _settings_game.difficulty.quantity_sea_lakes */ |
215 static const amplitude_t _water_percent[4] = {20, 80, 250, 400}; |
215 static const amplitude_t _water_percent[4] = {20, 80, 250, 400}; |
216 |
216 |
217 /** Desired maximum height - indexed by _settings.difficulty.terrain_type */ |
217 /** Desired maximum height - indexed by _settings_game.difficulty.terrain_type */ |
218 static const int8 _max_height[4] = { |
218 static const int8 _max_height[4] = { |
219 6, ///< Very flat |
219 6, ///< Very flat |
220 9, ///< Flat |
220 9, ///< Flat |
221 12, ///< Hilly |
221 12, ///< Hilly |
222 15 ///< Mountainous |
222 15 ///< Mountainous |
340 log_frequency_min = log_size_min - 6; |
340 log_frequency_min = log_size_min - 6; |
341 |
341 |
342 do { |
342 do { |
343 log_frequency = iteration_round - log_frequency_min; |
343 log_frequency = iteration_round - log_frequency_min; |
344 if (log_frequency >= 0) { |
344 if (log_frequency >= 0) { |
345 amplitude = _amplitudes_by_smoothness_and_frequency[_settings.game_creation.tgen_smoothness][log_frequency]; |
345 amplitude = _amplitudes_by_smoothness_and_frequency[_settings_game.game_creation.tgen_smoothness][log_frequency]; |
346 } else { |
346 } else { |
347 amplitude = 0; |
347 amplitude = 0; |
348 } |
348 } |
349 continue_iteration = ApplyNoise(iteration_round, amplitude); |
349 continue_iteration = ApplyNoise(iteration_round, amplitude); |
350 iteration_round++; |
350 iteration_round++; |
400 if (*h < h_min) continue; |
400 if (*h < h_min) continue; |
401 |
401 |
402 /* Transform height into 0..1 space */ |
402 /* Transform height into 0..1 space */ |
403 fheight = (double)(*h - h_min) / (double)(h_max - h_min); |
403 fheight = (double)(*h - h_min) / (double)(h_max - h_min); |
404 /* Apply sine transform depending on landscape type */ |
404 /* Apply sine transform depending on landscape type */ |
405 switch(_settings.game_creation.landscape) { |
405 switch(_settings_game.game_creation.landscape) { |
406 case LT_TOYLAND: |
406 case LT_TOYLAND: |
407 case LT_TEMPERATE: |
407 case LT_TEMPERATE: |
408 /* Move and scale 0..1 into -1..+1 */ |
408 /* Move and scale 0..1 into -1..+1 */ |
409 fheight = 2 * fheight - 1; |
409 fheight = 2 * fheight - 1; |
410 /* Sine transform */ |
410 /* Sine transform */ |
529 * Please note that all the small numbers; 53, 101, 167, etc. are small primes |
529 * Please note that all the small numbers; 53, 101, 167, etc. are small primes |
530 * to help give the perlin noise a bit more of a random feel. |
530 * to help give the perlin noise a bit more of a random feel. |
531 */ |
531 */ |
532 static void HeightMapCoastLines() |
532 static void HeightMapCoastLines() |
533 { |
533 { |
534 int smallest_size = min(_settings.game_creation.map_x, _settings.game_creation.map_y); |
534 int smallest_size = min(_settings_game.game_creation.map_x, _settings_game.game_creation.map_y); |
535 const int margin = 4; |
535 const int margin = 4; |
536 uint y, x; |
536 uint y, x; |
537 double max_x; |
537 double max_x; |
538 double max_y; |
538 double max_y; |
539 |
539 |
659 * - coast Smoothing |
659 * - coast Smoothing |
660 * - slope Smoothing |
660 * - slope Smoothing |
661 * - height histogram redistribution by sine wave transform */ |
661 * - height histogram redistribution by sine wave transform */ |
662 static void HeightMapNormalize() |
662 static void HeightMapNormalize() |
663 { |
663 { |
664 const amplitude_t water_percent = _water_percent[_settings.difficulty.quantity_sea_lakes]; |
664 const amplitude_t water_percent = _water_percent[_settings_game.difficulty.quantity_sea_lakes]; |
665 const height_t h_max_new = I2H(_max_height[_settings.difficulty.terrain_type]); |
665 const height_t h_max_new = I2H(_max_height[_settings_game.difficulty.terrain_type]); |
666 const height_t roughness = 7 + 3 * _settings.game_creation.tgen_smoothness; |
666 const height_t roughness = 7 + 3 * _settings_game.game_creation.tgen_smoothness; |
667 |
667 |
668 HeightMapAdjustWaterLevel(water_percent, h_max_new); |
668 HeightMapAdjustWaterLevel(water_percent, h_max_new); |
669 |
669 |
670 HeightMapCoastLines(); |
670 HeightMapCoastLines(); |
671 HeightMapSmoothSlopes(roughness); |
671 HeightMapSmoothSlopes(roughness); |
690 * prime is used to allow the perlin noise generator to create useful random |
690 * prime is used to allow the perlin noise generator to create useful random |
691 * numbers from slightly different series. |
691 * numbers from slightly different series. |
692 */ |
692 */ |
693 static double int_noise(const long x, const long y, const int prime) |
693 static double int_noise(const long x, const long y, const int prime) |
694 { |
694 { |
695 long n = x + y * prime + _settings.game_creation.generation_seed; |
695 long n = x + y * prime + _settings_game.game_creation.generation_seed; |
696 |
696 |
697 n = (n << 13) ^ n; |
697 n = (n << 13) ^ n; |
698 |
698 |
699 /* Pseudo-random number generator, using several large primes */ |
699 /* Pseudo-random number generator, using several large primes */ |
700 return 1.0 - (double)((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0; |
700 return 1.0 - (double)((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0; |