Loading

Paste #pye3rjafc

  1. +/**
  2. + * Gets the maximum allowed height while generating a map based on
  3. + * mapsize, terraintype, and the maximum height level.
  4. + * @return The maximum height for the map generation.
  5. + */
  6. +static height_t TGPGetMaxHeight()
  7. +{
  8. +   /**
  9. +    * Desired maximum height - indexed by:
  10. +    *  - _settings_game.difficulty.terrain_type
  11. +    *  - min(MapLogX(), MapLogY()) - MIN_MAP_SIZE_BITS
  12. +    *
  13. +    * It is indexed by map size as well as terrain type since the map size limits the height of
  14. +    * a usable mountain. For example, on a 64x64 map a 24 high single peak mountain (as if you
  15. +    * raised land 24 times in the center of the map) will leave only a ring of about 10 tiles
  16. +    * around the mountain to build on. On a 4096x4096 map it will just be a small annoyance that
  17. +    * you can easily build around; it's not really a mountain.
  18. +    */
  19. +   static const int max_height_divisor[4][MAX_MAP_SIZE_BITS - MIN_MAP_SIZE_BITS + 1] = {
  20. +       {21, 40, 50,  64, 128, 380,  760 }, ///< Very flat
  21. +       {16, 27, 38,  51, 102, 204,  408 }, ///< Flat
  22. +       {10, 13, 17,  20,  33,  66,  132 }, ///< Hilly
  23. +       {9,  10, 11,  12,  13,  24,   48 }, ///< Mountainous
  24. +   };
  25. +
  26. +   int divisor = max_height_divisor[_settings_game.difficulty.terrain_type][min(MapLogX(), MapLogY()) - MIN_MAP_SIZE_BITS];
  27. +   int map_size_max_height = min(_height_map.size_x + 1, _height_map.size_y + 1) / divisor;
  28. +   return I2H(min(map_size_max_height, _settings_game.construction.max_heightlevel));
  29. +}

Comments