SHARE
TWEET

Untitled

a guest Dec 29th, 2019 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**
  2.  * Automatically determine the value for snow line height and set it
  3.  * @param flat_world_height value >= 0: land height a flat world gets
  4.  *                          value == -1: not generating a flat world
  5.  */
  6. void DetermineSnowLineHeight(int flat_world_height)
  7. {
  8.     /* Determine snow line height only when snow_line_height is lower or higher than the minimum or maximum values for the setting */
  9.     if (_settings_game.game_creation.snow_line_height != MIN_SNOWLINE_HEIGHT - 1 && _settings_game.game_creation.snow_line_height != MAX_SNOWLINE_HEIGHT + 1) return;
  10.  
  11.     if (flat_world_height >= 0) { // generating a flat world
  12.         /* This doesn't require the extensive computations below */
  13.         int max_value = min(MAX_SNOWLINE_HEIGHT, max((int)MIN_SNOWLINE_HEIGHT, flat_world_height - 2));
  14.         uint half_max_value = max_value / 2 + max_value % 2;
  15.         _settings_game.game_creation.snow_line_height = max(MIN_SNOWLINE_HEIGHT, half_max_value);
  16.     }
  17.  
  18.     if (flat_world_height == -1) { // generating landscape
  19.         int h0_tile_count = 0; // count tiles at sea level
  20.         int highest_height = 0;
  21.         for (uint y = 0; y < MapSizeY(); y++) {
  22.             for (uint x = 0; x < MapSizeX(); x++) {
  23.                 int height = TileHeight(TileXY(x, y));
  24.                 if (height == 0) h0_tile_count++;
  25.                 if (height > highest_height) highest_height = height;
  26.             }
  27.         }
  28.  
  29.         /* Determine the snow line height and make it so that it's at most 50% of the land mass */
  30.         int land_mass_size = MapSizeX() * MapSizeY() - h0_tile_count; // available tiles above sea
  31.         int tile_count = 0, snow_line_height = 1;
  32.         while (tile_count < land_mass_size / 2 && snow_line_height <= highest_height) {
  33.             for (uint y = 0; y < MapSizeY(); y++) {
  34.                 for (uint x = 0; x < MapSizeX(); x++) {
  35.                     if (TileHeight(TileXY(x, y)) == snow_line_height) tile_count++;
  36.                 }
  37.             }
  38.             snow_line_height++;
  39.         }
  40.  
  41.         /* Farms can only generate below 'snow_line_height - 2' which limits
  42.          * minimum snow_line_height to 'snow_line_height - 2 > 0', thus '3'.
  43.          * Forests can only generate at a minimum of 'snow_line_height + 2'
  44.          * which limits maximum snow_line_height to 'highest_height - 2'.
  45.          * @see CheckNewIndustry_Farm and CheckNewIndustry_Forest. */
  46.         _settings_game.game_creation.snow_line_height = Clamp(snow_line_height, 3, max(3, min(MAX_SNOWLINE_HEIGHT, highest_height - 2)));
  47.     }
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top