1
0
Fork 0

Compare commits

...

10 Commits

Author SHA1 Message Date
HyperJeanJean cd5d13a692 Change: Select snow line height by level instead of coverage
The snow coverage was too random, it could produce maps with snow
heights too low or too high with the exact same settings.

Now the snow line height is determined by choosing an aproxiamte level,
similar to the water level. A custom value can also be entered.
2025-07-14 14:41:28 +02:00
Peter Nelson 61a299bc99
Codechange: Use SpriteID as GlyphID for SpriteFontCache. (#14439)
This reduces the amount of lookups in the character map as rendering a cached layout no longer needs to do so.
2025-07-14 13:28:10 +01:00
Peter Nelson 7546c1acab
Codefix f220ed179d: GetUnicodeGlyph takes a unicode character. (#14438)
Previous change erroneously changed type to GlyphID, based on naming. It should actually be char32_t.
2025-07-14 08:01:42 +00:00
Peter Nelson a6143eea21
Codechange: Include more relevant headers for script_storage. (#14437) 2025-07-14 07:49:50 +01:00
Peter Nelson 1d38cbafcb Codechange: Use unique_ptr for ScriptInfo instances.
Replaces raw pointers, slightly.
2025-07-14 00:10:14 +01:00
Peter Nelson 992d58d799 Codechange: Pass ScriptInfo by reference to IsSameScript. 2025-07-14 00:10:14 +01:00
Peter Nelson 8f34b7a821 Codechange: Keep Squirrel engine in unique_ptr. 2025-07-14 00:10:14 +01:00
Peter Nelson bf6d0c4934
Codechange: Don't pre-fill font metrics when loading fonts. (#14436)
Each font cache implementation sets its own metrics based on the loaded font, so there is no need to pre-fill with (unscaled, invalid) default metrics.
2025-07-13 23:38:31 +01:00
Michael Lutz 3c4fb21a5e
Fix: [Win32] Link failure with newer Windows SDK version due to WinRT changes. (#14432) 2025-07-13 22:34:32 +01:00
translators baced00e9f Update: Translations from eints
spanish (mexican): 1 change by absay
english (us): 1 change by 2TallTyler
galician: 10 changes by pvillaverde
dutch: 1 change by Afoklala
portuguese: 10 changes by jcteotonio
2025-07-13 04:45:12 +00:00
30 changed files with 226 additions and 150 deletions

View File

@ -90,7 +90,7 @@ template <> SQInteger PushClassName<AIInfo, ScriptType::AI>(HSQUIRRELVM vm) { sq
/* Remove the link to the real instance, else it might get deleted by RegisterAI() */
sq_setinstanceup(vm, 2, nullptr);
/* Register the AI to the base system */
info->GetScanner()->RegisterScript(info);
info->GetScanner()->RegisterScript(std::unique_ptr<AIInfo>{info});
return 0;
}
@ -136,22 +136,21 @@ bool AIInfo::CanLoadFromVersion(int version) const
/* static */ SQInteger AILibrary::Constructor(HSQUIRRELVM vm)
{
/* Create a new library */
AILibrary *library = new AILibrary();
auto library = std::make_unique<AILibrary>();
SQInteger res = ScriptInfo::Constructor(vm, *library);
if (res != 0) {
delete library;
return res;
}
/* Cache the category */
if (!library->CheckMethod("GetCategory") || !library->engine->CallStringMethod(library->SQ_instance, "GetCategory", &library->category, MAX_GET_OPS)) {
delete library;
return SQ_ERROR;
}
/* Register the Library to the base system */
library->GetScanner()->RegisterScript(library);
ScriptScanner *scanner = library->GetScanner();
scanner->RegisterScript(std::move(library));
return 0;
}

View File

@ -29,7 +29,7 @@ void AIScannerInfo::Initialize()
{
ScriptScanner::Initialize("AIScanner");
ScriptAllocatorScope alloc_scope(this->engine);
ScriptAllocatorScope alloc_scope(this->engine.get());
/* Create the dummy AI */
this->main_script = "%_dummy";

View File

@ -22,9 +22,10 @@
#include "safeguards.h"
/** Default heights for the different sizes of fonts. */
static const int _default_font_height[FS_END] = {10, 6, 18, 10};
static const int _default_font_ascender[FS_END] = { 8, 5, 15, 8};
/** Default unscaled heights for the different sizes of fonts. */
/* static */ const int FontCache::DEFAULT_FONT_HEIGHT[FS_END] = {10, 6, 18, 10};
/** Default unscaled ascenders for the different sizes of fonts. */
/* static */ const int FontCache::DEFAULT_FONT_ASCENDER[FS_END] = {8, 5, 15, 8};
FontCacheSettings _fcsettings;
@ -32,8 +33,7 @@ FontCacheSettings _fcsettings;
* Create a new font cache.
* @param fs The size of the font.
*/
FontCache::FontCache(FontSize fs) : parent(FontCache::Get(fs)), fs(fs), height(_default_font_height[fs]),
ascender(_default_font_ascender[fs]), descender(_default_font_ascender[fs] - _default_font_height[fs])
FontCache::FontCache(FontSize fs) : parent(FontCache::Get(fs)), fs(fs)
{
assert(this->parent == nullptr || this->fs == this->parent->fs);
FontCache::caches[this->fs] = this;
@ -50,7 +50,7 @@ FontCache::~FontCache()
int FontCache::GetDefaultFontHeight(FontSize fs)
{
return _default_font_height[fs];
return FontCache::DEFAULT_FONT_HEIGHT[fs];
}
/**

View File

@ -23,9 +23,9 @@ protected:
static FontCache *caches[FS_END]; ///< All the font caches.
FontCache *parent; ///< The parent of this font cache.
const FontSize fs; ///< The size of the font.
int height; ///< The height of the font.
int ascender; ///< The ascender value of the font.
int descender; ///< The descender value of the font.
int height = 0; ///< The height of the font.
int ascender = 0; ///< The ascender value of the font.
int descender = 0; ///< The descender value of the font.
public:
FontCache(FontSize fs);
@ -33,6 +33,11 @@ public:
static void InitializeFontCaches();
/** Default unscaled font heights. */
static const int DEFAULT_FONT_HEIGHT[FS_END];
/** Default unscaled font ascenders. */
static const int DEFAULT_FONT_ASCENDER[FS_END];
static int GetDefaultFontHeight(FontSize fs);
/**

View File

@ -43,26 +43,26 @@ SpriteFontCache::SpriteFontCache(FontSize fs) : FontCache(fs)
}
/**
* Get SpriteID associated with a GlyphID.
* @param key Glyph to find.
* @return SpriteID of glyph, or 0 if not present.
* Get SpriteID associated with a character.
* @param key Character to find.
* @return SpriteID for character, or 0 if not present.
*/
SpriteID SpriteFontCache::GetUnicodeGlyph(GlyphID key)
SpriteID SpriteFontCache::GetUnicodeGlyph(char32_t key)
{
const auto found = this->glyph_to_spriteid_map.find(key & ~SPRITE_GLYPH);
if (found == std::end(this->glyph_to_spriteid_map)) return 0;
const auto found = this->char_map.find(key);
if (found == std::end(this->char_map)) return 0;
return found->second;
}
void SpriteFontCache::SetUnicodeGlyph(char32_t key, SpriteID sprite)
{
this->glyph_to_spriteid_map[key] = sprite;
this->char_map[key] = sprite;
}
void SpriteFontCache::InitializeUnicodeGlyphMap()
{
/* Clear out existing glyph map if it exists */
this->glyph_to_spriteid_map.clear();
this->char_map.clear();
SpriteID base;
switch (this->fs) {
@ -103,14 +103,14 @@ void SpriteFontCache::ClearFontCache()
const Sprite *SpriteFontCache::GetGlyph(GlyphID key)
{
SpriteID sprite = this->GetUnicodeGlyph(static_cast<char32_t>(key & ~SPRITE_GLYPH));
SpriteID sprite = static_cast<SpriteID>(key & ~SPRITE_GLYPH);
if (sprite == 0) sprite = this->GetUnicodeGlyph('?');
return GetSprite(sprite, SpriteType::Font);
}
uint SpriteFontCache::GetGlyphWidth(GlyphID key)
{
SpriteID sprite = this->GetUnicodeGlyph(static_cast<char32_t>(key & ~SPRITE_GLYPH));
SpriteID sprite = static_cast<SpriteID>(key & ~SPRITE_GLYPH);
if (sprite == 0) sprite = this->GetUnicodeGlyph('?');
return SpriteExists(sprite) ? GetSprite(sprite, SpriteType::Font)->width + ScaleFontTrad(this->fs != FS_NORMAL ? 1 : 0) : 0;
}
@ -120,7 +120,7 @@ GlyphID SpriteFontCache::MapCharToGlyph(char32_t key, [[maybe_unused]] bool allo
assert(IsPrintable(key));
SpriteID sprite = this->GetUnicodeGlyph(key);
if (sprite == 0) return 0;
return SPRITE_GLYPH | key;
return SPRITE_GLYPH | sprite;
}
bool SpriteFontCache::GetDrawGlyphShadow()

View File

@ -28,8 +28,8 @@ public:
bool IsBuiltInFont() override { return true; }
private:
std::unordered_map<GlyphID, SpriteID> glyph_to_spriteid_map{}; ///< Mapping of glyphs to sprite IDs.
SpriteID GetUnicodeGlyph(GlyphID key);
std::unordered_map<char32_t, SpriteID> char_map{}; ///< Mapping of characters to sprite IDs.
SpriteID GetUnicodeGlyph(char32_t key);
};
#endif /* SPRITEFONTCACHE_H */

View File

@ -78,7 +78,7 @@ template <> SQInteger PushClassName<GameInfo, ScriptType::GS>(HSQUIRRELVM vm) {
/* Remove the link to the real instance, else it might get deleted by RegisterGame() */
sq_setinstanceup(vm, 2, nullptr);
/* Register the Game to the base system */
info->GetScanner()->RegisterScript(info);
info->GetScanner()->RegisterScript(std::unique_ptr<GameInfo>{info});
return 0;
}
@ -106,22 +106,21 @@ bool GameInfo::CanLoadFromVersion(int version) const
/* static */ SQInteger GameLibrary::Constructor(HSQUIRRELVM vm)
{
/* Create a new library */
GameLibrary *library = new GameLibrary();
auto library = std::make_unique<GameLibrary>();
SQInteger res = ScriptInfo::Constructor(vm, *library);
if (res != 0) {
delete library;
return res;
}
/* Cache the category */
if (!library->CheckMethod("GetCategory") || !library->engine->CallStringMethod(library->SQ_instance, "GetCategory", &library->category, MAX_GET_OPS)) {
delete library;
return SQ_ERROR;
}
/* Register the Library to the base system */
library->GetScanner()->RegisterScript(library);
ScriptScanner *scanner = library->GetScanner();
scanner->RegisterScript(std::move(library));
return 0;
}

View File

@ -92,8 +92,8 @@ GameLibrary *GameScannerLibrary::FindLibrary(const std::string &library, int ver
std::string library_name = fmt::format("{}.{}", library, version);
/* Check if the library + version exists */
ScriptInfoList::iterator it = this->info_list.find(library_name);
auto it = this->info_list.find(library_name);
if (it == this->info_list.end()) return nullptr;
return static_cast<GameLibrary *>((*it).second);
return static_cast<GameLibrary *>(it->second);
}

View File

@ -49,6 +49,8 @@ static const uint CUSTOM_SEA_LEVEL_NUMBER_DIFFICULTY = 4; ///< Value for custom
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 CUSTOM_SNOW_LEVEL_NUMBER = 5; ///< Value for custom snow level in game creation settings
static constexpr uint MAP_HEIGHT_LIMIT_ORIGINAL = 15; ///< Original map height limit.
static const uint MAP_HEIGHT_LIMIT_AUTO_MINIMUM = 30; ///< When map height limit is auto, make this the lowest possible map height limit.

View File

@ -124,7 +124,7 @@ static constexpr NWidgetPart _nested_generate_landscape_widgets[] = {
/* Labels on the left side (global column 3). */
NWidget(NWID_VERTICAL, NWidContainerFlag::EqualSize), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GL_CLIMATE_SEL_LABEL),
NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_SNOW_COVERAGE, STR_CONFIG_SETTING_SNOW_COVERAGE_HELPTEXT), SetFill(1, 1),
NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_SNOW_LINE_LEVEL, STR_CONFIG_SETTING_SNOW_LINE_LEVEL_HELPTEXT), SetFill(1, 1),
NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_DESERT_COVERAGE, STR_CONFIG_SETTING_DESERT_COVERAGE_HELPTEXT), SetFill(1, 1),
NWidget(NWID_SPACER), SetFill(1, 1),
EndContainer(),
@ -139,11 +139,9 @@ static constexpr NWidgetPart _nested_generate_landscape_widgets[] = {
NWidget(NWID_VERTICAL, NWidContainerFlag::EqualSize), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
/* Climate selector. */
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GL_CLIMATE_SEL_SELECTOR),
/* Snow coverage. */
/* Snow line level. */
NWidget(NWID_HORIZONTAL),
NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_COVERAGE_DOWN), SetSpriteTip(SPR_ARROW_DOWN, STR_MAPGEN_SNOW_COVERAGE_DOWN_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_SNOW_COVERAGE_TEXT), SetToolTip(STR_CONFIG_SETTING_SNOW_COVERAGE_HELPTEXT), SetFill(1, 1),
NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_COVERAGE_UP), SetSpriteTip(SPR_ARROW_UP, STR_MAPGEN_SNOW_COVERAGE_UP_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_SNOW_LINE_LEVEL_PULLDOWN), SetToolTip(STR_CONFIG_SETTING_SNOW_LINE_LEVEL_HELPTEXT), SetFill(1, 1),
EndContainer(),
/* Desert coverage. */
NWidget(NWID_HORIZONTAL),
@ -259,7 +257,7 @@ static constexpr NWidgetPart _nested_heightmap_load_widgets[] = {
/* Right half labels (global column 3) */
NWidget(NWID_VERTICAL, NWidContainerFlag::EqualSize), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GL_CLIMATE_SEL_LABEL),
NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_SNOW_COVERAGE, STR_CONFIG_SETTING_SNOW_COVERAGE_HELPTEXT), SetFill(1, 1),
NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_SNOW_LINE_LEVEL, STR_CONFIG_SETTING_SNOW_LINE_LEVEL_HELPTEXT), SetFill(1, 1),
NWidget(WWT_TEXT, INVALID_COLOUR), SetStringTip(STR_MAPGEN_DESERT_COVERAGE, STR_CONFIG_SETTING_DESERT_COVERAGE_HELPTEXT), SetFill(1, 1),
NWidget(NWID_SPACER), SetFill(1, 1),
EndContainer(),
@ -273,11 +271,9 @@ static constexpr NWidgetPart _nested_heightmap_load_widgets[] = {
NWidget(NWID_VERTICAL, NWidContainerFlag::EqualSize), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
/* Climate selector. */
NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GL_CLIMATE_SEL_SELECTOR),
/* Snow coverage. */
/* Snow line level. */
NWidget(NWID_HORIZONTAL),
NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_COVERAGE_DOWN), SetSpriteTip(SPR_ARROW_DOWN, STR_MAPGEN_SNOW_COVERAGE_DOWN_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
NWidget(WWT_TEXTBTN, COLOUR_ORANGE, WID_GL_SNOW_COVERAGE_TEXT), SetToolTip(STR_CONFIG_SETTING_SNOW_COVERAGE_HELPTEXT), SetFill(1, 1),
NWidget(WWT_IMGBTN, COLOUR_ORANGE, WID_GL_SNOW_COVERAGE_UP), SetSpriteTip(SPR_ARROW_UP, STR_MAPGEN_SNOW_COVERAGE_UP_TOOLTIP), SetFill(0, 1), SetAspect(WidgetDimensions::ASPECT_UP_DOWN_BUTTON),
NWidget(WWT_DROPDOWN, COLOUR_ORANGE, WID_GL_SNOW_LINE_LEVEL_PULLDOWN), SetToolTip(STR_CONFIG_SETTING_SNOW_LINE_LEVEL_HELPTEXT), SetFill(1, 1),
EndContainer(),
/* Desert coverage. */
NWidget(NWID_HORIZONTAL),
@ -384,6 +380,7 @@ static const StringID _rotation[] = {STR_CONFIG_SETTING_HEIGHTMAP_ROTATION_CO
static const StringID _num_towns[] = {STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM};
static const StringID _num_inds[] = {STR_FUNDING_ONLY, STR_MINIMAL, STR_NUM_VERY_LOW, STR_NUM_LOW, STR_NUM_NORMAL, STR_NUM_HIGH, STR_NUM_CUSTOM};
static const StringID _variety[] = {STR_VARIETY_NONE, STR_VARIETY_VERY_LOW, STR_VARIETY_LOW, STR_VARIETY_MEDIUM, STR_VARIETY_HIGH, STR_VARIETY_VERY_HIGH};
static const StringID _snow_levels[] = {STR_SNOW_LINE_LEVEL_VERY_LOW, STR_SNOW_LINE_LEVEL_LOW, STR_SNOW_LINE_LEVEL_MEDIUM, STR_SNOW_LINE_LEVEL_HIGH, STR_SNOW_LINE_LEVEL_VERY_HIGH, STR_SNOW_LINE_LEVEL_CUSTOM};
static_assert(std::size(_num_inds) == ID_END);
@ -426,7 +423,12 @@ struct GenerateLandscapeWindow : public Window {
case WID_GL_MAPSIZE_X_PULLDOWN: return GetString(STR_JUST_INT, 1LL << _settings_newgame.game_creation.map_x);
case WID_GL_MAPSIZE_Y_PULLDOWN: return GetString(STR_JUST_INT, 1LL << _settings_newgame.game_creation.map_y);
case WID_GL_HEIGHTMAP_HEIGHT_TEXT: return GetString(STR_JUST_INT, _settings_newgame.game_creation.heightmap_height);
case WID_GL_SNOW_COVERAGE_TEXT: return GetString(STR_MAPGEN_SNOW_COVERAGE_TEXT, _settings_newgame.game_creation.snow_coverage);
case WID_GL_SNOW_LINE_LEVEL_PULLDOWN:
if (_settings_newgame.game_creation.snow_line_level == CUSTOM_SNOW_LEVEL_NUMBER) {
return GetString(STR_SNOW_LINE_LEVEL_CUSTOM_NUMBER, _settings_newgame.game_creation.snow_line_height);
}
return GetString(_snow_levels[_settings_newgame.game_creation.snow_line_level]);
case WID_GL_DESERT_COVERAGE_TEXT: return GetString(STR_MAPGEN_DESERT_COVERAGE_TEXT, _settings_newgame.game_creation.desert_coverage);
case WID_GL_TOWN_PULLDOWN:
@ -523,7 +525,7 @@ struct GenerateLandscapeWindow : public Window {
}
/* Disable snowline if not arctic */
this->SetWidgetDisabledState(WID_GL_SNOW_COVERAGE_TEXT, _settings_newgame.game_creation.landscape != LandscapeType::Arctic);
this->SetWidgetDisabledState(WID_GL_SNOW_LINE_LEVEL_PULLDOWN, _settings_newgame.game_creation.landscape != LandscapeType::Arctic);
/* Disable desert if not tropic */
this->SetWidgetDisabledState(WID_GL_DESERT_COVERAGE_TEXT, _settings_newgame.game_creation.landscape != LandscapeType::Tropic);
@ -545,8 +547,6 @@ struct GenerateLandscapeWindow : public Window {
}
this->SetWidgetDisabledState(WID_GL_START_DATE_DOWN, _settings_newgame.game_creation.starting_year <= CalendarTime::MIN_YEAR);
this->SetWidgetDisabledState(WID_GL_START_DATE_UP, _settings_newgame.game_creation.starting_year >= CalendarTime::MAX_YEAR);
this->SetWidgetDisabledState(WID_GL_SNOW_COVERAGE_DOWN, _settings_newgame.game_creation.snow_coverage <= 0 || _settings_newgame.game_creation.landscape != LandscapeType::Arctic);
this->SetWidgetDisabledState(WID_GL_SNOW_COVERAGE_UP, _settings_newgame.game_creation.snow_coverage >= 100 || _settings_newgame.game_creation.landscape != LandscapeType::Arctic);
this->SetWidgetDisabledState(WID_GL_DESERT_COVERAGE_DOWN, _settings_newgame.game_creation.desert_coverage <= 0 || _settings_newgame.game_creation.landscape != LandscapeType::Tropic);
this->SetWidgetDisabledState(WID_GL_DESERT_COVERAGE_UP, _settings_newgame.game_creation.desert_coverage >= 100 || _settings_newgame.game_creation.landscape != LandscapeType::Tropic);
@ -586,8 +586,8 @@ struct GenerateLandscapeWindow : public Window {
d = GetStringBoundingBox(GetString(STR_JUST_INT, GetParamMaxValue(MAX_MAP_SIZE)));
break;
case WID_GL_SNOW_COVERAGE_TEXT:
d = GetStringBoundingBox(GetString(STR_MAPGEN_SNOW_COVERAGE_TEXT, GetParamMaxValue(MAX_TILE_HEIGHT)));
case WID_GL_SNOW_LINE_LEVEL_PULLDOWN:
d = GetStringBoundingBox(GetString(STR_JUST_INT, GetParamMaxValue(MAX_SNOWLINE_HEIGHT)));
break;
case WID_GL_DESERT_COVERAGE_TEXT:
@ -738,21 +738,8 @@ struct GenerateLandscapeWindow : public Window {
ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.starting_year), STR_MAPGEN_START_DATE_QUERY_CAPT, 8, this, CS_NUMERAL, QueryStringFlag::EnableDefault);
break;
case WID_GL_SNOW_COVERAGE_DOWN:
case WID_GL_SNOW_COVERAGE_UP: // Snow coverage buttons
/* Don't allow too fast scrolling */
if (!this->flags.Test(WindowFlag::Timeout) || this->timeout_timer <= 1) {
this->HandleButtonClick(widget);
_settings_newgame.game_creation.snow_coverage = Clamp(_settings_newgame.game_creation.snow_coverage + (widget - WID_GL_SNOW_COVERAGE_TEXT) * 10, 0, 100);
this->InvalidateData();
}
_left_button_clicked = false;
break;
case WID_GL_SNOW_COVERAGE_TEXT: // Snow coverage text
this->widget_id = WID_GL_SNOW_COVERAGE_TEXT;
ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.snow_coverage), STR_MAPGEN_SNOW_COVERAGE_QUERY_CAPT, 4, this, CS_NUMERAL, QueryStringFlag::EnableDefault);
case WID_GL_SNOW_LINE_LEVEL_PULLDOWN: // Snow line level
ShowDropDownMenu(this, _snow_levels, _settings_newgame.game_creation.snow_line_level, WID_GL_SNOW_LINE_LEVEL_PULLDOWN, 0, 0);
break;
case WID_GL_DESERT_COVERAGE_DOWN:
@ -846,9 +833,9 @@ struct GenerateLandscapeWindow : public Window {
void OnTimeout() override
{
if (mode == GLWM_HEIGHTMAP) {
this->RaiseWidgetsWhenLowered(WID_GL_HEIGHTMAP_HEIGHT_DOWN, WID_GL_HEIGHTMAP_HEIGHT_UP, WID_GL_START_DATE_DOWN, WID_GL_START_DATE_UP, WID_GL_SNOW_COVERAGE_UP, WID_GL_SNOW_COVERAGE_DOWN, WID_GL_DESERT_COVERAGE_UP, WID_GL_DESERT_COVERAGE_DOWN);
this->RaiseWidgetsWhenLowered(WID_GL_HEIGHTMAP_HEIGHT_DOWN, WID_GL_HEIGHTMAP_HEIGHT_UP, WID_GL_START_DATE_DOWN, WID_GL_START_DATE_UP, WID_GL_DESERT_COVERAGE_UP, WID_GL_DESERT_COVERAGE_DOWN);
} else {
this->RaiseWidgetsWhenLowered(WID_GL_START_DATE_DOWN, WID_GL_START_DATE_UP, WID_GL_SNOW_COVERAGE_UP, WID_GL_SNOW_COVERAGE_DOWN, WID_GL_DESERT_COVERAGE_UP, WID_GL_DESERT_COVERAGE_DOWN);
this->RaiseWidgetsWhenLowered(WID_GL_START_DATE_DOWN, WID_GL_START_DATE_UP, WID_GL_DESERT_COVERAGE_UP, WID_GL_DESERT_COVERAGE_DOWN);
}
}
@ -863,6 +850,14 @@ struct GenerateLandscapeWindow : public Window {
case WID_GL_HEIGHTMAP_ROTATION_PULLDOWN: _settings_newgame.game_creation.heightmap_rotation = index; break;
case WID_GL_SNOW_LINE_LEVEL_PULLDOWN: // Snow line level
if ((uint)index == CUSTOM_SNOW_LEVEL_NUMBER) {
this->widget_id = widget;
ShowQueryString(GetString(STR_JUST_INT, _settings_newgame.game_creation.snow_line_height), STR_MAPGEN_SNOW_LINE_LEVEL_QUERY_CAPT, 4, this, CS_NUMERAL, {});
}
_settings_newgame.game_creation.snow_line_level = index;
break;
case WID_GL_TOWN_PULLDOWN:
if ((uint)index == CUSTOM_TOWN_NUMBER_DIFFICULTY) {
this->widget_id = widget;
@ -922,7 +917,7 @@ struct GenerateLandscapeWindow : public Window {
switch (this->widget_id) {
case WID_GL_HEIGHTMAP_HEIGHT_TEXT: value = MAP_HEIGHT_LIMIT_AUTO_MINIMUM; break;
case WID_GL_START_DATE_TEXT: value = CalendarTime::DEF_START_YEAR.base(); break;
case WID_GL_SNOW_COVERAGE_TEXT: value = DEF_SNOW_COVERAGE; break;
case WID_GL_SNOW_LINE_LEVEL_PULLDOWN: value = DEF_SNOWLINE_HEIGHT; break;
case WID_GL_DESERT_COVERAGE_TEXT: value = DEF_DESERT_COVERAGE; break;
case WID_GL_TOWN_PULLDOWN: value = 1; break;
case WID_GL_INDUSTRY_PULLDOWN: value = 1; break;
@ -943,9 +938,8 @@ struct GenerateLandscapeWindow : public Window {
_settings_newgame.game_creation.starting_year = Clamp(TimerGameCalendar::Year(value), CalendarTime::MIN_YEAR, CalendarTime::MAX_YEAR);
break;
case WID_GL_SNOW_COVERAGE_TEXT:
this->SetWidgetDirty(WID_GL_SNOW_COVERAGE_TEXT);
_settings_newgame.game_creation.snow_coverage = Clamp(value, 0, 100);
case WID_GL_SNOW_LINE_LEVEL_PULLDOWN:
_settings_newgame.game_creation.snow_line_height = Clamp(value, MIN_SNOWLINE_HEIGHT, MAX_SNOWLINE_HEIGHT);
break;
case WID_GL_DESERT_COVERAGE_TEXT:

View File

@ -1510,13 +1510,45 @@ static uint CalculateCoverageLine(uint coverage, uint edge_multiplier)
return best_h;
}
/**
* Get current maximum height of the map.
* @return The maximum height of the map.
*/
static uint GetMapMaxHeight()
{
uint max_height = 0;
for (const auto tile : Map::Iterate()) {
uint h = TileHeight(tile);
if (h > max_height) {
max_height = h;
}
}
return max_height;
}
/**
* Calculate the line from which snow begins.
*/
static void CalculateSnowLine()
{
/* We do not have snow sprites on coastal tiles, so never allow "1" as height. */
_settings_game.game_creation.snow_line_height = std::max(CalculateCoverageLine(_settings_game.game_creation.snow_coverage, 0), 2u);
/* If snow_line_level is custom, then snow_line_height is already set
* otherwise we have to calculate it
*/
if (_settings_game.game_creation.snow_line_level != CUSTOM_SNOW_LEVEL_NUMBER) {
uint min_snow_line_height = 4; // Not too low to make room for farms
uint max_snow_line_height = GetMapMaxHeight() - 2; // Not too high to make room for forests
uint max_height_diff = min_snow_line_height < max_snow_line_height
? max_snow_line_height - min_snow_line_height
: 0;
/* snow_line_level goes up to 4 so we divide by 5 to get a maximum ratio of 80% */
uint height_diff = RoundDivSU(max_height_diff * _settings_game.game_creation.snow_line_level, 5);
_settings_game.game_creation.snow_line_height = min_snow_line_height + height_diff;
}
}
/**

View File

@ -267,6 +267,7 @@ STR_UNITS_YEARS :{NUM}{NBSP}jaar
STR_UNITS_PERIODS :{NUM}{NBSP}period{P "" en}
STR_LIST_SEPARATOR :,{SPACE}
STR_TRUNCATION_ELLIPSIS :...
# Common window strings
STR_LIST_FILTER_TITLE :{BLACK}Filter:

View File

@ -1217,6 +1217,15 @@ STR_TERRAIN_TYPE_ALPINIST :Alpinist
STR_TERRAIN_TYPE_CUSTOM :Custom height
STR_TERRAIN_TYPE_CUSTOM_VALUE :Custom height ({NUM})
###length 7
STR_SNOW_LINE_LEVEL_VERY_LOW :Very Low
STR_SNOW_LINE_LEVEL_LOW :Low
STR_SNOW_LINE_LEVEL_MEDIUM :Medium
STR_SNOW_LINE_LEVEL_HIGH :High
STR_SNOW_LINE_LEVEL_VERY_HIGH :Very high
STR_SNOW_LINE_LEVEL_CUSTOM :Custom
STR_SNOW_LINE_LEVEL_CUSTOM_NUMBER :Custom ({NUM})
###length 4
STR_CITY_APPROVAL_LENIENT :Lenient
STR_CITY_APPROVAL_TOLERANT :Tolerant
@ -1593,9 +1602,8 @@ STR_CONFIG_SETTING_OIL_REF_EDGE_DISTANCE_HELPTEXT :Limit for how f
STR_CONFIG_SETTING_SNOWLINE_HEIGHT :Snow line height: {STRING2}
STR_CONFIG_SETTING_SNOWLINE_HEIGHT_HELPTEXT :Choose at what height snow starts in sub-arctic landscape. Snow also affects industry generation and town growth requirements. Can only be modified via Scenario Editor or is otherwise calculated via "snow coverage"
STR_CONFIG_SETTING_SNOW_COVERAGE :Snow coverage: {STRING2}
STR_CONFIG_SETTING_SNOW_COVERAGE_HELPTEXT :Choose the approximate amount of snow on the sub-arctic landscape. Snow also affects industry generation and town growth requirements. Only used during map generation. Sea level and coast tiles never have snow
STR_CONFIG_SETTING_SNOW_COVERAGE_VALUE :{NUM}%
STR_CONFIG_SETTING_SNOW_LINE_LEVEL :Snow line level: {STRING2}
STR_CONFIG_SETTING_SNOW_LINE_LEVEL_HELPTEXT :Choose the approximate height above which all tiles will be covered by snow in sub-arctic landscape. Snow also affects industry generation and town growth requirements.
STR_CONFIG_SETTING_DESERT_COVERAGE :Desert coverage: {STRING2}
STR_CONFIG_SETTING_DESERT_COVERAGE_HELPTEXT :Choose the approximate amount of desert on the tropical landscape. Desert also affects industry generation and town growth requirements. Only used during map generation
@ -3352,10 +3360,7 @@ STR_MAPGEN_HEIGHTMAP_HEIGHT :{BLACK}Highest
STR_MAPGEN_HEIGHTMAP_HEIGHT_TOOLTIP :{BLACK}Choose the highest peak that the game will attempt to create, measured in elevation above sea level
STR_MAPGEN_HEIGHTMAP_HEIGHT_UP_TOOLTIP :{BLACK}Increase the maximum height of highest peak on the map by one
STR_MAPGEN_HEIGHTMAP_HEIGHT_DOWN_TOOLTIP :{BLACK}Decrease the maximum height of highest peak on the map by one
STR_MAPGEN_SNOW_COVERAGE :{BLACK}Snow coverage:
STR_MAPGEN_SNOW_COVERAGE_UP_TOOLTIP :{BLACK}Increase snow coverage by ten percent
STR_MAPGEN_SNOW_COVERAGE_DOWN_TOOLTIP :{BLACK}Decrease snow coverage by ten percent
STR_MAPGEN_SNOW_COVERAGE_TEXT :{BLACK}{NUM}%
STR_MAPGEN_SNOW_LINE_LEVEL :{BLACK}Snow line level:
STR_MAPGEN_DESERT_COVERAGE :{BLACK}Desert coverage:
STR_MAPGEN_DESERT_COVERAGE_UP_TOOLTIP :{BLACK}Increase desert coverage by ten percent
STR_MAPGEN_DESERT_COVERAGE_DOWN_TOOLTIP :{BLACK}Decrease desert coverage by ten percent
@ -3420,7 +3425,7 @@ STR_MAPGEN_HEIGHTMAP_SIZE :{ORANGE}{NUM} x
STR_MAPGEN_TERRAIN_TYPE_QUERY_CAPT :{WHITE}Target peak height
STR_MAPGEN_HEIGHTMAP_HEIGHT_QUERY_CAPT :{WHITE}Highest peak
STR_MAPGEN_SNOW_COVERAGE_QUERY_CAPT :{WHITE}Snow coverage (in %)
STR_MAPGEN_SNOW_LINE_LEVEL_QUERY_CAPT :{WHITE}Snow line height
STR_MAPGEN_DESERT_COVERAGE_QUERY_CAPT :{WHITE}Desert coverage (in %)
STR_MAPGEN_START_DATE_QUERY_CAPT :{WHITE}Change starting year

View File

@ -267,6 +267,7 @@ STR_UNITS_YEARS :{NUM}{NBSP}year
STR_UNITS_PERIODS :{NUM}{NBSP}period{P "" s}
STR_LIST_SEPARATOR :,{SPACE}
STR_TRUNCATION_ELLIPSIS :...
# Common window strings
STR_LIST_FILTER_TITLE :{BLACK}Filter:

View File

@ -268,6 +268,7 @@ STR_UNITS_YEARS :{NUM}{NBSP}ano{
STR_UNITS_PERIODS :{NUM}{NBSP}período{P "" s}
STR_LIST_SEPARATOR :,{SPACE}
STR_TRUNCATION_ELLIPSIS :...
# Common window strings
STR_LIST_FILTER_TITLE :{BLACK}Filtrar:
@ -1302,6 +1303,9 @@ STR_CONFIG_SETTING_INTEREST_RATE_HELPTEXT :A taxa de inter
STR_CONFIG_SETTING_RUNNING_COSTS :Custos de explotación: {STRING}
STR_CONFIG_SETTING_RUNNING_COSTS_HELPTEXT :Establece o nivel de mantemento e custo de operación de vehículos e infraestrutura
###length 3
STR_CONFIG_SETTING_RUNNING_COSTS_LOW :Baixo
STR_CONFIG_SETTING_RUNNING_COSTS_MEDIUM :Medio
STR_CONFIG_SETTING_RUNNING_COSTS_HIGH :Alto
STR_CONFIG_SETTING_CONSTRUCTION_SPEED :Velocidade de construción: {STRING}
STR_CONFIG_SETTING_CONSTRUCTION_SPEED_HELPTEXT :Limita a cantidade de accións construtivas das IAs
@ -1324,6 +1328,9 @@ STR_CONFIG_SETTING_SUBSIDY_DURATION_DISABLED :Sen subvención
STR_CONFIG_SETTING_CONSTRUCTION_COSTS :Custos de construción: {STRING}
STR_CONFIG_SETTING_CONSTRUCTION_COSTS_HELPTEXT :Fixa o nivel de custos de construción e compra
###length 3
STR_CONFIG_SETTING_CONSTRUCTION_COSTS_LOW :Baixo
STR_CONFIG_SETTING_CONSTRUCTION_COSTS_MEDIUM :Medio
STR_CONFIG_SETTING_CONSTRUCTION_COSTS_HIGH :Alto
STR_CONFIG_SETTING_RECESSIONS :Recesións económicas: {STRING}
STR_CONFIG_SETTING_RECESSIONS_HELPTEXT :Se está activado, a economía pode entrar en recesión periódicamente. Durante unha recesión tódalas producións son significativamente máis baixas (volvendo ao nivel anterior cando a recesión remata)
@ -2079,9 +2086,9 @@ STR_CONFIG_SETTING_DISTRIBUTION_ARMOURED_HELPTEXT :A clase de merc
STR_CONFIG_SETTING_DISTRIBUTION_DEFAULT :Xeito de distribución para outros tipos de mercadoría: {STRING}
STR_CONFIG_SETTING_DISTRIBUTION_DEFAULT_HELPTEXT :"Asimétrico" significa que calquera cantidade de mercadorías pode ser enviada en calquera dirección. "Manual" significa que non haberá distribución automática para estas mercadorías
###length 3
STR_CONFIG_SETTING_DISTRIBUTION_MANUAL :manual
STR_CONFIG_SETTING_DISTRIBUTION_ASYMMETRIC :asimétrica
STR_CONFIG_SETTING_DISTRIBUTION_SYMMETRIC :simétrica
STR_CONFIG_SETTING_DISTRIBUTION_MANUAL :Manual
STR_CONFIG_SETTING_DISTRIBUTION_ASYMMETRIC :Asimétrica
STR_CONFIG_SETTING_DISTRIBUTION_SYMMETRIC :Simétrica
STR_CONFIG_SETTING_LINKGRAPH_ACCURACY :Precisión da distribución: {STRING}
STR_CONFIG_SETTING_LINKGRAPH_ACCURACY_HELPTEXT :Canto máis alto sexa o valor, máis tempo de CPU levará o cálculo de distribución. Se leva demasiado tempo podes experimentar retraso. Se sen embargo o fixas nun valor baixo, a distribución será imprecisa, e pode que a carga non sexa enviada aos destinos que ti queres

View File

@ -739,7 +739,7 @@ STR_PLAYLIST_TOOLTIP_CLICK_TO_ADD_TRACK :{BLACK}Clique n
STR_PLAYLIST_TOOLTIP_CLICK_TO_REMOVE_TRACK :{BLACK}Clique numa faixa para a remover da lista (apenas Personalização 1 ou Personalização 2)
# Highscore window
STR_HIGHSCORE_TOP_COMPANIES :{BIG_FONT}{BLACK}Melhores empresas
STR_HIGHSCORE_TOP_COMPANIES :{BIG_FONT}{BLACK}As melhores empresas
STR_HIGHSCORE_POSITION :{BIG_FONT}{BLACK}{COMMA}.
STR_HIGHSCORE_PERFORMANCE_TITLE_BUSINESSMAN :Negociante
STR_HIGHSCORE_PERFORMANCE_TITLE_ENTREPRENEUR :Empresário
@ -749,7 +749,7 @@ STR_HIGHSCORE_PERFORMANCE_TITLE_MAGNATE :Magnata
STR_HIGHSCORE_PERFORMANCE_TITLE_MOGUL :Grande magnata
STR_HIGHSCORE_PERFORMANCE_TITLE_TYCOON_OF_THE_CENTURY :Magnata do século
STR_HIGHSCORE_NAME :{PRESIDENT_NAME}, {COMPANY}
STR_HIGHSCORE_STATS :{BIG_FONT}'{STRING}' ({COMMA})
STR_HIGHSCORE_STATS :{BIG_FONT}"{STRING}" ({COMMA})
STR_HIGHSCORE_COMPANY_ACHIEVES_STATUS :{BIG_FONT}{BLACK}{COMPANY} conquista o estatuto de '{STRING}'!
STR_HIGHSCORE_PRESIDENT_OF_COMPANY_ACHIEVES_STATUS :{BIG_FONT}{WHITE}{PRESIDENT_NAME} de {COMPANY} conquista o estatuto de '{STRING}'!
@ -3117,8 +3117,8 @@ STR_INDUSTRY_CARGOES_SELECT_INDUSTRY_TOOLTIP :{BLACK}Selecion
# Land area window
STR_LAND_AREA_INFORMATION_CAPTION :{WHITE}Informações do Terreno
STR_LAND_AREA_INFORMATION_LOCATION_TOOLTIP :{BLACK}Centrar visualização na localização do mosaico. Ctrl+Clique para abrir uma nova janela de visualização nesse mosaico.
STR_LAND_AREA_INFORMATION_COST_TO_CLEAR_N_A :{BLACK}Custo para limpar: {LTBLUE}N/D
STR_LAND_AREA_INFORMATION_COST_TO_CLEAR :{BLACK}Custo para limpar: {RED}{CURRENCY_LONG}
STR_LAND_AREA_INFORMATION_COST_TO_CLEAR_N_A :{BLACK}Custo de desobstrução: {LTBLUE}N/D
STR_LAND_AREA_INFORMATION_COST_TO_CLEAR :{BLACK}Custo de desobstrução: {RED}{CURRENCY_LONG}
STR_LAND_AREA_INFORMATION_REVENUE_WHEN_CLEARED :{BLACK}Receitas apuradas: {LTBLUE}{CURRENCY_LONG}
STR_LAND_AREA_INFORMATION_OWNER_N_A :N/D
STR_LAND_AREA_INFORMATION_OWNER :{BLACK}Proprietário: {LTBLUE}{STRING}
@ -3126,7 +3126,7 @@ STR_LAND_AREA_INFORMATION_ROAD_OWNER :{BLACK}Dono da
STR_LAND_AREA_INFORMATION_TRAM_OWNER :{BLACK}Dono da linha de eléctrico: {LTBLUE}{STRING}
STR_LAND_AREA_INFORMATION_RAIL_OWNER :{BLACK}Dono da linha férrea: {LTBLUE}{STRING}
STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY :{BLACK}Autoridade local: {LTBLUE}{STRING}
STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY_NONE :Nenhum
STR_LAND_AREA_INFORMATION_LOCAL_AUTHORITY_NONE :Nenhuma
STR_LAND_AREA_INFORMATION_LANDINFO_COORDS :{BLACK}Coordenadas: {LTBLUE}{NUM} x {NUM} x {NUM}
STR_LAND_AREA_INFORMATION_LANDINFO_INDEX :{BLACK}Índice do mosaico: {LTBLUE}{NUM} ({HEX})
STR_LAND_AREA_INFORMATION_BUILD_DATE :{BLACK}Construído/renovado: {LTBLUE}{DATE_LONG}
@ -3685,9 +3685,9 @@ STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED_WINTER :{BLACK}No inver
STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED_GENERAL :{ORANGE}{STRING}{GREEN} fo{G 0 i i i ram ram} entregue{G 0 "" "" "" s s}
STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_REQUIRED :{ORANGE}{CARGO_TINY} / {CARGO_LONG}{RED} (ainda necessário)
STR_TOWN_VIEW_CARGO_FOR_TOWNGROWTH_DELIVERED :{ORANGE}{CARGO_TINY} / {CARGO_LONG}{GREEN} (entregue)
STR_TOWN_VIEW_TOWN_GROWS_EVERY :{BLACK}Localidade cresce a cada {ORANGE}{UNITS_DAYS_OR_SECONDS}
STR_TOWN_VIEW_TOWN_GROWS_EVERY_FUNDED :{BLACK}Localidade cresce a cada {ORANGE}{UNITS_DAYS_OR_SECONDS} (financiada)
STR_TOWN_VIEW_TOWN_GROW_STOPPED :{BLACK}Localidade {RED}não{BLACK} está a crescer
STR_TOWN_VIEW_TOWN_GROWS_EVERY :{BLACK}A localidade cresce a cada {ORANGE}{UNITS_DAYS_OR_SECONDS}
STR_TOWN_VIEW_TOWN_GROWS_EVERY_FUNDED :{BLACK}A localidade cresce a cada {ORANGE}{UNITS_DAYS_OR_SECONDS} (financiada)
STR_TOWN_VIEW_TOWN_GROW_STOPPED :{BLACK}A localidade {RED}não{BLACK} está a crescer
STR_TOWN_VIEW_NOISE_IN_TOWN :{BLACK}Limite de ruído na localidade: {ORANGE}{COMMA}{BLACK} máx: {ORANGE}{COMMA}
STR_TOWN_VIEW_CENTER_TOOLTIP :{BLACK}Centrar visualização na localização da localidade. Ctrl+Clique para abrir um novo visualizador na localização da localidade
STR_TOWN_VIEW_LOCAL_AUTHORITY_BUTTON :{BLACK}Autoridade Local
@ -3700,7 +3700,7 @@ STR_TOWN_VIEW_EXPAND_BUILDINGS_BUTTON :{BLACK}Expandir
STR_TOWN_VIEW_EXPAND_BUILDINGS_TOOLTIP :{BLACK}Aumentar os edifícios da localidade
STR_TOWN_VIEW_EXPAND_ROADS_BUTTON :{BLACK}Expandir estradas
STR_TOWN_VIEW_EXPAND_ROADS_TOOLTIP :{BLACK}Aumentar as estradas da localidade
STR_TOWN_VIEW_DELETE_BUTTON :{BLACK}Apagar
STR_TOWN_VIEW_DELETE_BUTTON :{BLACK}Remover
STR_TOWN_VIEW_DELETE_TOOLTIP :{BLACK}Remover completamente esta localidade
STR_TOWN_VIEW_RENAME_TOWN_BUTTON :Renomear Localidade
@ -3943,7 +3943,7 @@ STR_FINANCES_INFRASTRUCTURE_BUTTON :{BLACK}Infraest
STR_COMPANY_VIEW_CAPTION :{WHITE}{COMPANY} {BLACK}{COMPANY_NUM}
STR_COMPANY_VIEW_PRESIDENT_MANAGER_TITLE :{WHITE}{PRESIDENT_NAME}{}{GOLD}(Presidente)
STR_COMPANY_VIEW_INAUGURATED_TITLE :{GOLD}Inaugurado: {WHITE}{NUM}
STR_COMPANY_VIEW_INAUGURATED_TITLE :{GOLD}Inaugurada em: {WHITE}{NUM}
STR_COMPANY_VIEW_INAUGURATED_TITLE_WALLCLOCK :{GOLD}Inaugurada: {WHITE}{NUM} (período {NUM})
STR_COMPANY_VIEW_COLOUR_SCHEME_TITLE :{GOLD}Cores:
STR_COMPANY_VIEW_VEHICLES_TITLE :{GOLD}Veículos:

View File

@ -268,6 +268,7 @@ STR_UNITS_YEARS :{NUM}{NBSP}año
STR_UNITS_PERIODS :{NUM}{NBSP}período{P "" s}
STR_LIST_SEPARATOR :,{SPACE}
STR_TRUNCATION_ELLIPSIS :...
# Common window strings
STR_LIST_FILTER_TITLE :{BLACK}Filtrar:

View File

@ -66,6 +66,7 @@
#include "../timer/timer_game_economy.h"
#include "../timer/timer_game_tick.h"
#include "../picker_func.h"
#include "../genworld.h"
#include "saveload_internal.h"
@ -3397,6 +3398,11 @@ bool AfterLoadGame()
}
}
if (IsSavegameVersionBefore(SLV_SNOW_LINE_LEVEL)) {
/* The snow line level replaces the snow coverage but the two do not map very well. */
_settings_game.game_creation.snow_line_level = CUSTOM_SNOW_LEVEL_NUMBER;
}
AfterLoadLabelMaps();
AfterLoadCompanyStats();
AfterLoadStoryBook();

View File

@ -143,7 +143,7 @@ const SaveLoadCompat _settings_sl_compat[] = {
SLC_VAR("economy.fund_roads"),
SLC_VAR("economy.give_money"),
SLC_VAR("game_creation.snow_line_height"),
SLC_VAR("game_creation.snow_coverage"),
SLC_NULL(1, SLV_MAPGEN_SETTINGS_REVAMP, SLV_TABLE_CHUNKS),
SLC_VAR("game_creation.desert_coverage"),
SLC_NULL(4, SL_MIN_VERSION, SLV_144),
SLC_VAR("game_creation.starting_year"),

View File

@ -405,6 +405,7 @@ enum SaveLoadVersion : uint16_t {
SLV_FACE_STYLES, ///< 355 PR#14319 Addition of face styles, replacing gender and ethnicity.
SLV_INDUSTRY_NUM_VALID_HISTORY, ///< 356 PR#14416 Store number of valid history records for industries.
SLV_SNOW_LINE_LEVEL, ///< 357 PR#14428 Replacement of snow coverage setting with snow line level setting
SL_MAX_VERSION, ///< Highest possible saveload version
};

View File

@ -24,10 +24,12 @@
#include "api/script_event.hpp"
#include "api/script_log.hpp"
#include "../company_base.h"
#include "../company_func.h"
#include "../company_type.h"
#include "../fileio_func.h"
#include "../goal_type.h"
#include "../league_type.h"
#include "../signs_type.h"
#include "../story_type.h"
#include "../misc/endian_buffer.hpp"
#include "../safeguards.h"

View File

@ -44,10 +44,7 @@ bool ScriptScanner::AddFile(const std::string &filename, size_t, const std::stri
return true;
}
ScriptScanner::ScriptScanner() :
engine(nullptr)
{
}
ScriptScanner::ScriptScanner() = default;
void ScriptScanner::ResetEngine()
{
@ -58,7 +55,7 @@ void ScriptScanner::ResetEngine()
void ScriptScanner::Initialize(std::string_view name)
{
this->engine = new Squirrel(name);
this->engine = std::make_unique<Squirrel>(name);
this->RescanDir();
@ -68,8 +65,6 @@ void ScriptScanner::Initialize(std::string_view name)
ScriptScanner::~ScriptScanner()
{
this->Reset();
delete this->engine;
}
void ScriptScanner::RescanDir()
@ -83,15 +78,12 @@ void ScriptScanner::RescanDir()
void ScriptScanner::Reset()
{
for (const auto &item : this->info_list) {
delete item.second;
}
this->info_list.clear();
this->info_single_list.clear();
this->info_vector.clear();
}
void ScriptScanner::RegisterScript(ScriptInfo *info)
void ScriptScanner::RegisterScript(std::unique_ptr<ScriptInfo> &&info)
{
std::string script_original_name = this->GetScriptName(*info);
std::string script_name = fmt::format("{}.{}", script_original_name, info->GetVersion());
@ -99,7 +91,6 @@ void ScriptScanner::RegisterScript(ScriptInfo *info)
/* Check if GetShortName follows the rules */
if (info->GetShortName().size() != 4) {
Debug(script, 0, "The script '{}' returned a string from GetShortName() which is not four characters. Unable to load the script.", info->GetName());
delete info;
return;
}
@ -111,7 +102,6 @@ void ScriptScanner::RegisterScript(ScriptInfo *info)
#else
if (it->second->GetMainScript() == info->GetMainScript()) {
#endif
delete info;
return;
}
@ -120,20 +110,20 @@ void ScriptScanner::RegisterScript(ScriptInfo *info)
Debug(script, 1, " 2: {}", info->GetMainScript());
Debug(script, 1, "The first is taking precedence.");
delete info;
return;
}
this->info_list[script_name] = info;
ScriptInfo *script_info = this->info_vector.emplace_back(std::move(info)).get();
this->info_list[script_name] = script_info;
if (!info->IsDeveloperOnly() || _settings_client.gui.ai_developer_tools) {
if (!script_info->IsDeveloperOnly() || _settings_client.gui.ai_developer_tools) {
/* Add the script to the 'unique' script list, where only the highest version
* of the script is registered. */
auto it = this->info_single_list.find(script_original_name);
if (it == this->info_single_list.end()) {
this->info_single_list[script_original_name] = info;
} else if (it->second->GetVersion() < info->GetVersion()) {
it->second = info;
this->info_single_list[script_original_name] = script_info;
} else if (it->second->GetVersion() < script_info->GetVersion()) {
it->second = script_info;
}
}
}
@ -195,17 +185,17 @@ struct ScriptFileChecksumCreator : FileScanner {
* @param info The script to get the shortname and md5 sum from.
* @return True iff they're the same.
*/
static bool IsSameScript(const ContentInfo &ci, bool md5sum, ScriptInfo *info, Subdirectory dir)
static bool IsSameScript(const ContentInfo &ci, bool md5sum, const ScriptInfo &info, Subdirectory dir)
{
uint32_t id = 0;
auto str = std::string_view{info->GetShortName()}.substr(0, 4);
auto str = std::string_view{info.GetShortName()}.substr(0, 4);
for (size_t j = 0; j < str.size(); j++) id |= static_cast<uint8_t>(str[j]) << (8 * j);
if (id != ci.unique_id) return false;
if (!md5sum) return true;
ScriptFileChecksumCreator checksum(dir);
const auto &tar_filename = info->GetTarFile();
const auto &tar_filename = info.GetTarFile();
TarList::iterator iter;
if (!tar_filename.empty() && (iter = _tar_list[dir].find(tar_filename)) != _tar_list[dir].end()) {
/* The main script is in a tar file, so find all files that
@ -224,7 +214,7 @@ static bool IsSameScript(const ContentInfo &ci, bool md5sum, ScriptInfo *info, S
/* There'll always be at least 1 path separator character in a script
* main script name as the search algorithm requires the main script to
* be in a subdirectory of the script directory; so <dir>/<path>/main.nut. */
const std::string &main_script = info->GetMainScript();
const std::string &main_script = info.GetMainScript();
std::string path = main_script.substr(0, main_script.find_last_of(PATHSEPCHAR));
checksum.Scan(".nut", path);
}
@ -235,7 +225,7 @@ static bool IsSameScript(const ContentInfo &ci, bool md5sum, ScriptInfo *info, S
bool ScriptScanner::HasScript(const ContentInfo &ci, bool md5sum)
{
for (const auto &item : this->info_list) {
if (IsSameScript(ci, md5sum, item.second, this->GetDirectory())) return true;
if (IsSameScript(ci, md5sum, *item.second, this->GetDirectory())) return true;
}
return false;
}
@ -243,7 +233,7 @@ bool ScriptScanner::HasScript(const ContentInfo &ci, bool md5sum)
std::optional<std::string_view> ScriptScanner::FindMainScript(const ContentInfo &ci, bool md5sum)
{
for (const auto &item : this->info_list) {
if (IsSameScript(ci, md5sum, item.second, this->GetDirectory())) return item.second->GetMainScript();
if (IsSameScript(ci, md5sum, *item.second, this->GetDirectory())) return item.second->GetMainScript();
}
return std::nullopt;
}

View File

@ -13,7 +13,7 @@
#include "../fileio_func.h"
#include "../string_func.h"
typedef std::map<std::string, class ScriptInfo *, CaseInsensitiveComparator> ScriptInfoList; ///< Type for the list of scripts.
using ScriptInfoList = std::map<std::string, class ScriptInfo *, CaseInsensitiveComparator>; ///< Type for the list of scripts.
/** Scanner to help finding scripts. */
class ScriptScanner : public FileScanner {
@ -26,7 +26,7 @@ public:
/**
* Get the engine of the main squirrel handler (it indexes all available scripts).
*/
class Squirrel *GetEngine() { return this->engine; }
class Squirrel *GetEngine() { return this->engine.get(); }
/**
* Get the current main script the ScanDir is currently tracking.
@ -51,7 +51,7 @@ public:
/**
* Register a ScriptInfo to the scanner.
*/
void RegisterScript(class ScriptInfo *info);
void RegisterScript(std::unique_ptr<class ScriptInfo> &&info);
/**
* Get the list of registered scripts to print on the console.
@ -84,10 +84,12 @@ public:
void RescanDir();
protected:
class Squirrel *engine; ///< The engine we're scanning with.
std::unique_ptr<class Squirrel> engine; ///< The engine we're scanning with.
std::string main_script; ///< The full path of the script.
std::string tar_file; ///< If, which tar file the script was in.
std::vector<std::unique_ptr<ScriptInfo>> info_vector;
ScriptInfoList info_list; ///< The list of all script.
ScriptInfoList info_single_list; ///< The list of all unique script. The best script (highest version) is shown.

View File

@ -12,12 +12,10 @@
#include <queue>
#include "../signs_func.h"
#include "../vehicle_func.h"
#include "../command_type.h"
#include "../company_type.h"
#include "../rail_type.h"
#include "../road_type.h"
#include "../group.h"
#include "../goal_type.h"
#include "../story_type.h"
#include "script_types.hpp"
#include "script_log_types.hpp"

View File

@ -842,7 +842,7 @@ SettingsContainer &GetSettingsTree()
genworld->Add(new SettingEntry("difficulty.terrain_type"));
genworld->Add(new SettingEntry("game_creation.tgen_smoothness"));
genworld->Add(new SettingEntry("game_creation.variety"));
genworld->Add(new SettingEntry("game_creation.snow_coverage"));
genworld->Add(new SettingEntry("game_creation.snow_line_level"));
genworld->Add(new SettingEntry("game_creation.snow_line_height"));
genworld->Add(new SettingEntry("game_creation.desert_coverage"));
genworld->Add(new SettingEntry("game_creation.amount_of_rivers"));

View File

@ -363,8 +363,8 @@ struct GameCreationSettings {
uint8_t map_y; ///< Y size of map
uint8_t land_generator; ///< the landscape generator
uint8_t oil_refinery_limit; ///< distance oil refineries allowed from map edge
uint8_t snow_line_height; ///< the configured snow line height (deduced from "snow_coverage")
uint8_t snow_coverage; ///< the amount of snow coverage on the map
uint8_t snow_line_height; ///< the configured snow line height (deduced from "snow_line_level" unless it is set on "custom")
uint8_t snow_line_level; ///< the approximate snow line level on the map
uint8_t desert_coverage; ///< the amount of desert coverage on the map
uint8_t heightmap_height; ///< highest mountain for heightmap (towards what it scales)
uint8_t tgen_smoothness; ///< how rough is the terrain from 0-3

View File

@ -97,17 +97,17 @@ strval = STR_JUST_COMMA
cat = SC_BASIC
[SDT_VAR]
var = game_creation.snow_coverage
var = game_creation.snow_line_level
type = SLE_UINT8
from = SLV_MAPGEN_SETTINGS_REVAMP
flags = SettingFlag::NewgameOnly
def = DEF_SNOW_COVERAGE
from = SLV_SNOW_LINE_LEVEL
flags = SettingFlag::GuiDropdown, SettingFlag::NewgameOnly
def = 1
min = 0
max = 100
interval = 10
str = STR_CONFIG_SETTING_SNOW_COVERAGE
strhelp = STR_CONFIG_SETTING_SNOW_COVERAGE_HELPTEXT
strval = STR_CONFIG_SETTING_SNOW_COVERAGE_VALUE
max = 5
interval = 1
str = STR_CONFIG_SETTING_SNOW_LINE_LEVEL
strhelp = STR_CONFIG_SETTING_SNOW_LINE_LEVEL_HELPTEXT
strval = STR_SNOW_LINE_LEVEL_VERY_LOW
cat = SC_BASIC
[SDT_VAR]

View File

@ -33,7 +33,6 @@ static const uint MIN_SNOWLINE_HEIGHT = 2; ///< Minimum snow
static const uint DEF_SNOWLINE_HEIGHT = 10; ///< Default snowline height
static const uint MAX_SNOWLINE_HEIGHT = (MAX_TILE_HEIGHT - 2); ///< Maximum allowed snowline height
static const uint DEF_SNOW_COVERAGE = 40; ///< Default snow coverage.
static const uint DEF_DESERT_COVERAGE = 50; ///< Default desert coverage.

View File

@ -401,6 +401,40 @@ static void CancelIMEComposition(HWND hwnd)
HandleTextInput({}, true);
}
#if defined(_MSC_VER) && defined(NTDDI_WIN10_RS4)
/* We only use WinRT functions on Windows 10 or later. Unfortunately, newer Windows SDKs are now
* linking the two functions below directly instead of using dynamic linking as previously.
* To avoid any runtime linking errors on Windows 7 or older, we stub in our own dynamic
* linking trampoline. */
static LibraryLoader _combase("combase.dll");
extern "C" int32_t __stdcall WINRT_IMPL_RoOriginateLanguageException(int32_t error, void *message, void *languageException) noexcept
{
typedef BOOL(WINAPI *PFNRoOriginateLanguageException)(int32_t, void *, void *);
static PFNRoOriginateLanguageException RoOriginateLanguageException = _combase.GetFunction("RoOriginateLanguageException");
if (RoOriginateLanguageException != nullptr) {
return RoOriginateLanguageException(error, message, languageException);
} else {
return TRUE;
}
}
extern "C" int32_t __stdcall WINRT_IMPL_RoGetActivationFactory(void *classId, winrt::guid const &iid, void **factory) noexcept
{
typedef BOOL(WINAPI *PFNRoGetActivationFactory)(void *, winrt::guid const &, void **);
static PFNRoGetActivationFactory RoGetActivationFactory = _combase.GetFunction("RoGetActivationFactory");
if (RoGetActivationFactory != nullptr) {
return RoGetActivationFactory(classId, iid, factory);
} else {
*factory = nullptr;
return winrt::impl::error_class_not_available;
}
}
#endif
static bool IsDarkModeEnabled()
{
/* Only build if SDK is Windows 10 1803 or later. */

View File

@ -34,9 +34,7 @@ enum GenerateLandscapeWidgets : WidgetID {
WID_GL_START_DATE_TEXT, ///< Start year.
WID_GL_START_DATE_UP, ///< Increase start year.
WID_GL_SNOW_COVERAGE_DOWN, ///< Decrease snow coverage.
WID_GL_SNOW_COVERAGE_TEXT, ///< Snow coverage.
WID_GL_SNOW_COVERAGE_UP, ///< Increase snow coverage.
WID_GL_SNOW_LINE_LEVEL_PULLDOWN, ///< Snow line level.
WID_GL_DESERT_COVERAGE_DOWN, ///< Decrease desert coverage.
WID_GL_DESERT_COVERAGE_TEXT, ///< Desert coverage.