Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Automatically determine the value for snow line height and set it
- * @param flat_world_height value >= 0: land height a flat world gets
- * value == -1: not generating a flat world
- */
- void DetermineSnowLineHeight(int flat_world_height)
- {
- /* Determine snow line height only when snow_line_height is lower or higher than the minimum or maximum values for the setting */
- if (_settings_game.game_creation.snow_line_height != MIN_SNOWLINE_HEIGHT - 1 && _settings_game.game_creation.snow_line_height != MAX_SNOWLINE_HEIGHT + 1) return;
- if (flat_world_height >= 0) { // generating a flat world
- /* This doesn't require the extensive computations below */
- int max_value = min(MAX_SNOWLINE_HEIGHT, max((int)MIN_SNOWLINE_HEIGHT, flat_world_height - 2));
- uint half_max_value = max_value / 2 + max_value % 2;
- _settings_game.game_creation.snow_line_height = max(MIN_SNOWLINE_HEIGHT, half_max_value);
- }
- if (flat_world_height == -1) { // generating landscape
- int h0_tile_count = 0; // count tiles at sea level
- int highest_height = 0;
- for (uint y = 0; y < MapSizeY(); y++) {
- for (uint x = 0; x < MapSizeX(); x++) {
- int height = TileHeight(TileXY(x, y));
- if (height == 0) h0_tile_count++;
- if (height > highest_height) highest_height = height;
- }
- }
- /* Determine the snow line height and make it so that it's at most 50% of the land mass */
- int land_mass_size = MapSizeX() * MapSizeY() - h0_tile_count; // available tiles above sea
- int tile_count = 0, snow_line_height = 1;
- while (tile_count < land_mass_size / 2 && snow_line_height <= highest_height) {
- for (uint y = 0; y < MapSizeY(); y++) {
- for (uint x = 0; x < MapSizeX(); x++) {
- if (TileHeight(TileXY(x, y)) == snow_line_height) tile_count++;
- }
- }
- snow_line_height++;
- }
- /* Farms can only generate below 'snow_line_height - 2' which limits
- * minimum snow_line_height to 'snow_line_height - 2 > 0', thus '3'.
- * Forests can only generate at a minimum of 'snow_line_height + 2'
- * which limits maximum snow_line_height to 'highest_height - 2'.
- * @see CheckNewIndustry_Farm and CheckNewIndustry_Forest. */
- _settings_game.game_creation.snow_line_height = Clamp(snow_line_height, 3, max(3, min(MAX_SNOWLINE_HEIGHT, highest_height - 2)));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement