Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce snow/desert-coverage and custom terrain type, and move "maximum map height" to settings only #8891

Merged
merged 9 commits into from Mar 26, 2021
24 changes: 12 additions & 12 deletions src/cheat_gui.cpp
Expand Up @@ -125,26 +125,26 @@ static int32 ClickChangeDateCheat(int32 p1, int32 p2)
*/
static int32 ClickChangeMaxHlCheat(int32 p1, int32 p2)
{
p1 = Clamp(p1, MIN_MAX_HEIGHTLEVEL, MAX_MAX_HEIGHTLEVEL);
p1 = Clamp(p1, MIN_MAP_HEIGHT_LIMIT, MAX_MAP_HEIGHT_LIMIT);

/* Check if at least one mountain on the map is higher than the new value.
* If yes, disallow the change. */
for (TileIndex t = 0; t < MapSize(); t++) {
if ((int32)TileHeight(t) > p1) {
ShowErrorMessage(STR_CONFIG_SETTING_TOO_HIGH_MOUNTAIN, INVALID_STRING_ID, WL_ERROR);
/* Return old, unchanged value */
return _settings_game.construction.max_heightlevel;
return _settings_game.construction.map_height_limit;
}
}

/* Execute the change and reload GRF Data */
_settings_game.construction.max_heightlevel = p1;
_settings_game.construction.map_height_limit = p1;
ReloadNewGRFData();

/* The smallmap uses an index from heightlevels to colours. Trigger rebuilding it. */
InvalidateWindowClassesData(WC_SMALLMAP, 2);

return _settings_game.construction.max_heightlevel;
return _settings_game.construction.map_height_limit;
}

/** Available cheats. */
Expand Down Expand Up @@ -182,14 +182,14 @@ struct CheatEntry {
* Order matches with the values of #CheatNumbers
*/
static const CheatEntry _cheats_ui[] = {
{SLE_INT32, STR_CHEAT_MONEY, &_money_cheat_amount, &_cheats.money.been_used, &ClickMoneyCheat },
{SLE_UINT8, STR_CHEAT_CHANGE_COMPANY, &_local_company, &_cheats.switch_company.been_used, &ClickChangeCompanyCheat },
{SLE_BOOL, STR_CHEAT_EXTRA_DYNAMITE, &_cheats.magic_bulldozer.value, &_cheats.magic_bulldozer.been_used, nullptr },
{SLE_BOOL, STR_CHEAT_CROSSINGTUNNELS, &_cheats.crossing_tunnels.value, &_cheats.crossing_tunnels.been_used, nullptr },
{SLE_BOOL, STR_CHEAT_NO_JETCRASH, &_cheats.no_jetcrash.value, &_cheats.no_jetcrash.been_used, nullptr },
{SLE_BOOL, STR_CHEAT_SETUP_PROD, &_cheats.setup_prod.value, &_cheats.setup_prod.been_used, &ClickSetProdCheat },
{SLE_UINT8, STR_CHEAT_EDIT_MAX_HL, &_settings_game.construction.max_heightlevel, &_cheats.edit_max_hl.been_used, &ClickChangeMaxHlCheat },
{SLE_INT32, STR_CHEAT_CHANGE_DATE, &_cur_year, &_cheats.change_date.been_used, &ClickChangeDateCheat },
{SLE_INT32, STR_CHEAT_MONEY, &_money_cheat_amount, &_cheats.money.been_used, &ClickMoneyCheat },
{SLE_UINT8, STR_CHEAT_CHANGE_COMPANY, &_local_company, &_cheats.switch_company.been_used, &ClickChangeCompanyCheat },
{SLE_BOOL, STR_CHEAT_EXTRA_DYNAMITE, &_cheats.magic_bulldozer.value, &_cheats.magic_bulldozer.been_used, nullptr },
{SLE_BOOL, STR_CHEAT_CROSSINGTUNNELS, &_cheats.crossing_tunnels.value, &_cheats.crossing_tunnels.been_used, nullptr },
{SLE_BOOL, STR_CHEAT_NO_JETCRASH, &_cheats.no_jetcrash.value, &_cheats.no_jetcrash.been_used, nullptr },
{SLE_BOOL, STR_CHEAT_SETUP_PROD, &_cheats.setup_prod.value, &_cheats.setup_prod.been_used, &ClickSetProdCheat },
{SLE_UINT8, STR_CHEAT_EDIT_MAX_HL, &_settings_game.construction.map_height_limit, &_cheats.edit_max_hl.been_used, &ClickChangeMaxHlCheat },
{SLE_INT32, STR_CHEAT_CHANGE_DATE, &_cur_year, &_cheats.change_date.been_used, &ClickChangeDateCheat },
};

static_assert(CHT_NUM_CHEATS == lengthof(_cheats_ui));
Expand Down
19 changes: 19 additions & 0 deletions src/genworld.cpp
Expand Up @@ -33,6 +33,7 @@
#include "game/game_instance.hpp"
#include "string_func.h"
#include "thread.h"
#include "tgp.h"

#include "safeguards.h"

Expand Down Expand Up @@ -118,6 +119,8 @@ static void _GenerateWorld()

ConvertGroundTilesIntoWaterTiles();
IncreaseGeneratingWorldProgress(GWP_OBJECT);

_settings_game.game_creation.snow_line_height = DEF_SNOWLINE_HEIGHT;
} else {
GenerateLandscape(_gw.mode);
GenerateClearTile();
Expand Down Expand Up @@ -283,6 +286,22 @@ void GenerateWorld(GenWorldMode mode, uint size_x, uint size_y, bool reset_setti
InitializeGame(_gw.size_x, _gw.size_y, true, reset_settings);
PrepareGenerateWorldProgress();

if (_settings_game.construction.map_height_limit == 0) {
uint estimated_height = 0;

if (_gw.mode == GWM_EMPTY && _game_mode != GM_MENU) {
estimated_height = _settings_game.game_creation.se_flat_world_height;
} else if (_gw.mode == GWM_HEIGHTMAP) {
estimated_height = _settings_game.game_creation.heightmap_height;
} else if (_settings_game.game_creation.land_generator == LG_TERRAGENESIS) {
estimated_height = GetEstimationTGPMapHeight();
} else {
estimated_height = 0;
}

_settings_game.construction.map_height_limit = std::max(MAP_HEIGHT_LIMIT_AUTO_MINIMUM, std::min(MAX_MAP_HEIGHT_LIMIT, estimated_height + MAP_HEIGHT_LIMIT_AUTO_CEILING_ROOM));
}

/* Load the right landscape stuff, and the NewGRFs! */
GfxLoadSprites();
LoadStringWidthTable();
Expand Down
5 changes: 5 additions & 0 deletions src/genworld.h
Expand Up @@ -42,10 +42,15 @@ enum TgenSmoothness {
TGEN_SMOOTHNESS_END, ///< Used to iterate.
};

static const uint CUSTOM_TERRAIN_TYPE_NUMBER_DIFFICULTY = 5; ///< Value for custom terrain type in difficulty settings.

static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY = 4; ///< Value for custom sea level in difficulty settings.
static const uint CUSTOM_SEA_LEVEL_MIN_PERCENTAGE = 1; ///< Minimum percentage a user can specify for custom sea level.
static const uint CUSTOM_SEA_LEVEL_MAX_PERCENTAGE = 90; ///< Maximum percentage a user can specify for custom sea level.

static const uint MAP_HEIGHT_LIMIT_AUTO_MINIMUM = 30; ///< When map height limit is auto, make this the lowest possible map height limit.
static const uint MAP_HEIGHT_LIMIT_AUTO_CEILING_ROOM = 15; ///< When map height limit is auto, the map height limit will be the higest peak plus this value.

typedef void GWDoneProc(); ///< Procedure called when the genworld process finishes
typedef void GWAbortProc(); ///< Called when genworld is aborted

Expand Down