370 bool continue_iteration; |
370 bool continue_iteration; |
371 int log_size_min, log_frequency_min; |
371 int log_size_min, log_frequency_min; |
372 int log_frequency; |
372 int log_frequency; |
373 |
373 |
374 /* Find first power of two that fits, so that later log_frequency == TGP_FREQUENCY_MAX in the last iteration */ |
374 /* Find first power of two that fits, so that later log_frequency == TGP_FREQUENCY_MAX in the last iteration */ |
375 for (log_size_min = TGP_FREQUENCY_MAX; (1U << log_size_min) < size_min; log_size_min++) { } |
375 for (log_size_min = 2; (1U << log_size_min) < size_min; log_size_min++) { } |
376 log_frequency_min = log_size_min - TGP_FREQUENCY_MAX; |
376 log_frequency_min = log_size_min - 2; |
377 |
377 |
378 /* Zero must be part of the iteration, else initialization will fail. */ |
378 /* Zero must be part of the iteration, else initialization will fail. */ |
379 assert(log_frequency_min >= 0); |
379 assert(log_frequency_min >= 0); |
380 |
380 |
381 /* Keep increasing the frequency until we reach the step size equal to one tile */ |
381 /* Keep increasing the frequency until we reach the step size equal to one tile */ |
382 do { |
382 do { |
383 log_frequency = iteration_round - log_frequency_min; |
383 log_frequency = iteration_round - log_frequency_min; |
384 if (log_frequency >= 0) { |
384 if (log_frequency >= 0) { |
385 /* Apply noise for the next frequency */ |
385 /* Apply noise for the next frequency */ |
386 assert(log_frequency <= TGP_FREQUENCY_MAX); |
386 assert(log_frequency <= 2); |
387 amplitude = _amplitudes_by_smoothness_and_frequency[_settings_game.game_creation.tgen_smoothness][log_frequency]; |
387 amplitude = _amplitudes_by_smoothness_and_frequency[_settings_game.game_creation.tgen_smoothness][log_frequency]; |
388 } else { |
388 } else { |
389 /* Amplitude for the low frequencies on big maps is 0, i.e. initialise with zero height */ |
389 /* Amplitude for the low frequencies on big maps is 0, i.e. initialise with zero height */ |
390 amplitude = 0; |
390 amplitude = 0; |
391 } |
391 } |
392 continue_iteration = ApplyNoise(iteration_round, amplitude); |
392 continue_iteration = ApplyNoise(iteration_round, amplitude); |
393 iteration_round++; |
393 iteration_round++; |
394 } while (continue_iteration); |
394 } while (continue_iteration); |
395 assert(log_frequency == TGP_FREQUENCY_MAX); |
395 |
|
396 assert(log_frequency == 2); |
396 } |
397 } |
397 |
398 |
398 /** Returns min, max and average height from height map */ |
399 /** Returns min, max and average height from height map */ |
399 static void HeightMapGetMinMaxAvg(height_t *min_ptr, height_t *max_ptr, height_t *avg_ptr) |
400 static void HeightMapGetMinMaxAvg(height_t *min_ptr, height_t *max_ptr, height_t *avg_ptr) |
400 { |
401 { |
579 const int margin = 4; |
580 const int margin = 4; |
580 uint y, x; |
581 uint y, x; |
581 double max_x; |
582 double max_x; |
582 double max_y; |
583 double max_y; |
583 |
584 |
|
585 int factor = smallest_size * smallest_size / 16; |
|
586 |
584 /* Lower to sea level */ |
587 /* Lower to sea level */ |
585 for (y = 0; y <= _height_map.size_y; y++) { |
588 for (y = 0; y <= _height_map.size_y; y++) { |
586 /* Top right */ |
589 /* Top right */ |
587 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); |
590 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); |
588 max_x = max((smallest_size * smallest_size / 16) + max_x, (smallest_size * smallest_size / 16) + margin - max_x); |
591 max_x = max(factor + max_x, factor + margin - max_x); |
589 if (smallest_size < 8 && max_x > 5) max_x /= 1.5; |
592 if (smallest_size < 8 && max_x > 5) max_x /= 1.5; |
|
593 if (smallest_size < 6 && max_x > 4) max_x /= 4.0; |
590 for (x = 0; x < max_x; x++) { |
594 for (x = 0; x < max_x; x++) { |
591 _height_map.height(x, y) = 0; |
595 _height_map.height(x, y) = 0; |
592 } |
596 } |
593 |
597 |
594 /* Bottom left */ |
598 /* Bottom left */ |
595 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); |
599 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); |
596 max_x = max((smallest_size * smallest_size / 16) + max_x, (smallest_size * smallest_size / 16) + margin - max_x); |
600 max_x = max(factor + max_x, factor + margin - max_x); |
597 if (smallest_size < 8 && max_x > 5) max_x /= 1.5; |
601 if (smallest_size < 8 && max_x > 5) max_x /= 1.5; |
598 for (x = _height_map.size_x; x > (_height_map.size_x - 1 - max_x); x--) { |
602 if (smallest_size < 6 && max_x > 4) max_x /= 4.0; |
|
603 for (x = _height_map.size_x; x > (_height_map.size_x - 1 - max_x) && x > 0; x--) { |
599 _height_map.height(x, y) = 0; |
604 _height_map.height(x, y) = 0; |
600 } |
605 } |
601 } |
606 } |
602 |
607 |
603 /* Lower to sea level */ |
608 /* Lower to sea level */ |
604 for (x = 0; x <= _height_map.size_x; x++) { |
609 for (x = 0; x <= _height_map.size_x; x++) { |
605 /* Top left */ |
610 /* Top left */ |
606 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); |
611 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); |
607 max_y = max((smallest_size * smallest_size / 16) + max_y, (smallest_size * smallest_size / 16) + margin - max_y); |
612 max_y = max(factor + max_y, factor + margin - max_y); |
608 if (smallest_size < 8 && max_y > 5) max_y /= 1.5; |
613 if (smallest_size < 8 && max_y > 5) max_y /= 1.5; |
|
614 if (smallest_size < 6 && max_y > 4) max_y /= 4.0; |
609 for (y = 0; y < max_y; y++) { |
615 for (y = 0; y < max_y; y++) { |
610 _height_map.height(x, y) = 0; |
616 _height_map.height(x, y) = 0; |
611 } |
617 } |
612 |
618 |
613 |
619 |
614 /* Bottom right */ |
620 /* Bottom right */ |
615 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); |
621 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); |
616 max_y = max((smallest_size * smallest_size / 16) + max_y, (smallest_size * smallest_size / 16) + margin - max_y); |
622 max_y = max(factor + max_y, factor + margin - max_y); |
617 if (smallest_size < 8 && max_y > 5) max_y /= 1.5; |
623 if (smallest_size < 8 && max_y > 5) max_y /= 1.5; |
618 for (y = _height_map.size_y; y > (_height_map.size_y - 1 - max_y); y--) { |
624 if (smallest_size < 6 && max_y > 4) max_y /= 4.0; |
|
625 for (y = _height_map.size_y; y > (_height_map.size_y - 1 - max_y) && y > 0; y--) { |
619 _height_map.height(x, y) = 0; |
626 _height_map.height(x, y) = 0; |
620 } |
627 } |
621 } |
628 } |
622 } |
629 } |
623 |
630 |
709 const height_t h_max_new = I2H(_max_height[_settings_game.difficulty.terrain_type]); |
716 const height_t h_max_new = I2H(_max_height[_settings_game.difficulty.terrain_type]); |
710 const height_t roughness = 7 + 3 * _settings_game.game_creation.tgen_smoothness; |
717 const height_t roughness = 7 + 3 * _settings_game.game_creation.tgen_smoothness; |
711 |
718 |
712 HeightMapAdjustWaterLevel(water_percent, h_max_new); |
719 HeightMapAdjustWaterLevel(water_percent, h_max_new); |
713 |
720 |
714 //HeightMapCoastLines(); |
721 HeightMapCoastLines(); |
715 HeightMapSmoothSlopes(roughness); |
722 HeightMapSmoothSlopes(roughness); |
716 |
723 |
717 //HeightMapSmoothCoasts(); |
724 HeightMapSmoothCoasts(); |
718 HeightMapSmoothSlopes(roughness); |
725 HeightMapSmoothSlopes(roughness); |
719 |
726 |
720 HeightMapSineTransform(12, h_max_new); |
727 HeightMapSineTransform(12, h_max_new); |
721 HeightMapSmoothSlopes(16); |
728 HeightMapSmoothSlopes(16); |
722 } |
729 } |