From 6936fe4f6e46d34b4ecf8b23d0bc2b860bccd354 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 10 Jun 2021 21:23:32 +0100 Subject: [PATCH 1/7] Settings GUI: Move day length factor to environment section --- src/settings_gui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index 06c43c1fb2..fc31a8303a 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -1904,7 +1904,6 @@ static SettingsContainer &GetSettingsTree() { accounting->Add(new SettingEntry("economy.inflation")); accounting->Add(new SettingEntry("economy.inflation_fixed_dates")); - accounting->Add(new SettingEntry("economy.day_length_factor")); accounting->Add(new SettingEntry("difficulty.initial_interest")); accounting->Add(new SettingEntry("difficulty.max_loan")); accounting->Add(new SettingEntry("difficulty.subsidy_multiplier")); @@ -2122,6 +2121,7 @@ static SettingsContainer &GetSettingsTree() treedist->Add(new SettingEntry("construction.tree_growth_rate")); } + environment->Add(new SettingEntry("economy.day_length_factor")); environment->Add(new SettingEntry("station.modified_catchment")); environment->Add(new SettingEntry("station.catchment_increase")); environment->Add(new SettingEntry("station.cargo_class_rating_wait_time")); From 704eac82203df14876d01f4f54d1349b8d0378de Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 10 Jun 2021 21:37:27 +0100 Subject: [PATCH 2/7] Fix changing font zoom level not updating font height cache --- src/gfx.cpp | 6 ++++++ src/settings_gui.cpp | 1 - 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/gfx.cpp b/src/gfx.cpp index 5a30964c3a..fc9d1455cd 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -2185,6 +2185,8 @@ void UpdateGUIZoom() _gui_zoom = static_cast(_gui_zoom_cfg); } + ZoomLevel old_font_zoom = _font_zoom; + /* Determine real font zoom to use. */ if (_font_zoom_cfg == ZOOM_LVL_CFG_AUTO) { _font_zoom = static_cast(VideoDriver::GetInstance()->GetSuggestedUIZoom()); @@ -2192,6 +2194,10 @@ void UpdateGUIZoom() _font_zoom = static_cast(_font_zoom_cfg); } + if (old_font_zoom != _font_zoom) { + ClearFontCache(); + } + UpdateFontHeightCache(); } diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index fc31a8303a..7dc7f9ec70 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -580,7 +580,6 @@ struct GameOptionsWindow : Window { GfxClearSpriteCache(); _font_zoom_cfg = new_zoom; UpdateGUIZoom(); - ClearFontCache(); LoadStringWidthTable(); UpdateAllVirtCoords(); ReInitAllWindows(true); From 8450f0a248c1c1bd48b19e928a86b4ab4cb7a5f5 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 10 Jun 2021 22:05:15 +0100 Subject: [PATCH 3/7] Fix width of status bar time/date section --- src/statusbar_gui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/statusbar_gui.cpp b/src/statusbar_gui.cpp index f6100d94be..e45b7b5abc 100644 --- a/src/statusbar_gui.cpp +++ b/src/statusbar_gui.cpp @@ -115,8 +115,8 @@ struct StatusBarWindow : Window { Dimension d; switch (widget) { case WID_S_LEFT: - SetDParamMaxValue(0, MAX_YEAR * DAYS_IN_YEAR); - d = GetStringBoundingBox(STR_WHITE_DATE_LONG); + SetDParam(0, (uint64)MAX_YEAR * (uint64)DAYS_IN_YEAR * (uint64)DAY_TICKS * (uint64)_settings_game.economy.day_length_factor); + d = GetStringBoundingBox(STR_WHITE_DATE_WALLCLOCK_LONG); break; case WID_S_RIGHT: { From 7aa63e9726cce0af169e55dc4d2c720150d74871 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 10 Jun 2021 22:12:10 +0100 Subject: [PATCH 4/7] Update status bar sizing when changing date/time display settings --- src/settings.cpp | 2 ++ src/statusbar_gui.cpp | 3 +++ src/statusbar_gui.h | 1 + src/table/settings.ini | 2 +- 4 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/settings.cpp b/src/settings.cpp index 4884c5b3f5..da23129f1f 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -72,6 +72,7 @@ #include "scope_info.h" #include "viewport_func.h" #include "gui.h" +#include "statusbar_gui.h" #include "void_map.h" #include "station_base.h" @@ -1306,6 +1307,7 @@ static bool UpdateTimeSettings(int32 p1) { SetupTimeSettings(); InvalidateVehTimetableWindow(p1); + InvalidateWindowData(WC_STATUS_BAR, 0, SBI_REINIT); MarkWholeScreenDirty(); return true; } diff --git a/src/statusbar_gui.cpp b/src/statusbar_gui.cpp index e45b7b5abc..6767f6205c 100644 --- a/src/statusbar_gui.cpp +++ b/src/statusbar_gui.cpp @@ -210,6 +210,9 @@ struct StatusBarWindow : Window { this->ticker_scroll = TICKER_STOP; // reset ticker ... this->reminder_timeout.SetInterval(REMINDER_STOP); // ... and reminder break; + case SBI_REINIT: + this->ReInit(); + break; } } diff --git a/src/statusbar_gui.h b/src/statusbar_gui.h index 26503dbff1..b4828788ce 100644 --- a/src/statusbar_gui.h +++ b/src/statusbar_gui.h @@ -17,6 +17,7 @@ enum StatusBarInvalidate { SBI_SHOW_TICKER, ///< start scrolling news SBI_SHOW_REMINDER, ///< show a reminder (dot on the right side of the statusbar) SBI_NEWS_DELETED, ///< abort current news display (active news were deleted) + SBI_REINIT, ///< reinit status bar SBI_END }; diff --git a/src/table/settings.ini b/src/table/settings.ini index b1000f307f..5a5c85f268 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -4794,7 +4794,7 @@ max = 3 str = STR_CONFIG_SETTING_DATE_WITH_TIME strval = STR_CONFIG_SETTING_DATE_WITH_TIME_NONE strhelp = STR_CONFIG_SETTING_DATE_WITH_TIME_HELPTEXT -proc = RedrawScreen +proc = UpdateTimeSettings [SDTC_BOOL] var = gui.timetable_start_text_entry From 5b50ae72f88e3dfda5b18a37b0f683fbe5ce3cb4 Mon Sep 17 00:00:00 2001 From: Patric Stout Date: Fri, 11 Jun 2021 00:18:20 +0200 Subject: [PATCH 5/7] Fix #9348, 4d74e51: don't try to sell shares of spectators (#9349) "new_owner" can be INVALID_OWNER, and as INVALID_OWNER == COMPANY_SPECTATORS, we could end up trying to sell shares of nobody. (cherry picked from commit ef25afd55ab868a4322d0c241b5c4898966ac919) --- src/company_cmd.cpp | 2 +- src/economy.cpp | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index b1d7bfdff9..51bc4f95cf 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -71,7 +71,7 @@ Company::Company(uint16 name_1, bool is_ai) this->purchase_land_limit = (uint32)_settings_game.construction.purchase_land_frame_burst << 16; this->build_object_limit = (uint32)_settings_game.construction.build_object_frame_burst << 16; - for (uint j = 0; j < 4; j++) this->share_owners[j] = COMPANY_SPECTATOR; + for (uint j = 0; j < 4; j++) this->share_owners[j] = INVALID_OWNER; InvalidateWindowData(WC_PERFORMANCE_DETAIL, 0, INVALID_COMPANY); } diff --git a/src/economy.cpp b/src/economy.cpp index bda48ad208..15949f4015 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -333,10 +333,12 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner) Backup cur_company2(_current_company, FILE_LINE); const Company *c = Company::Get(old_owner); for (i = 0; i < 4; i++) { + if (c->share_owners[i] == INVALID_OWNER) continue; + if (c->bankrupt_value == 0 && c->share_owners[i] == new_owner) { /* You are the one buying the company; so don't sell the shares back to you. */ - Company::Get(new_owner)->share_owners[i] = COMPANY_SPECTATOR; - } else if (c->share_owners[i] != INVALID_OWNER) { + Company::Get(new_owner)->share_owners[i] = INVALID_OWNER; + } else { cur_company2.Change(c->share_owners[i]); /* Sell the shares */ CommandCost res = DoCommand(0, old_owner, 0, DC_EXEC | DC_BANKRUPT, CMD_SELL_SHARE_IN_COMPANY); From 24783c3d2668c6645709b53c035fce4d5bdc201e Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 10 Jun 2021 23:59:19 +0100 Subject: [PATCH 6/7] Tracerestrict: Fix speed unit conversions in GUI --- src/tracerestrict_gui.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/tracerestrict_gui.cpp b/src/tracerestrict_gui.cpp index aa4cd76530..42d2cd6804 100644 --- a/src/tracerestrict_gui.cpp +++ b/src/tracerestrict_gui.cpp @@ -874,8 +874,8 @@ static uint ConvertIntegerValue(TraceRestrictValueType type, uint in, bool to_di case TRVT_SPEED: return to_display - ? ConvertSpeedToDisplaySpeed(in) * 10 / 16 - : ConvertDisplaySpeedToSpeed(in) * 16 / 10; + ? ConvertKmhishSpeedToDisplaySpeed(in) + : ConvertDisplaySpeedToKmhishSpeed(in); case TRVT_WEIGHT: return to_display From 97d5982cb532dd69bb18a11b4957c63010bfc2e3 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Thu, 10 Jun 2021 23:43:41 +0100 Subject: [PATCH 7/7] Fix various compiler warnings See: #267 --- src/company_gui.cpp | 2 +- src/core/pool_func.hpp | 8 ++++---- src/fontcache.cpp | 18 +++++++++--------- src/gfxinit.cpp | 2 ++ src/network/core/tcp_game.h | 2 +- src/newgrf_spritegroup.h | 6 +++--- src/order_cmd.cpp | 1 - src/string_func.h | 4 ++-- 8 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 2112beeae3..bac4d59a3d 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -495,7 +495,7 @@ struct CompanyFinancesWindow : Window { } } - bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) + bool OnTooltip(Point pt, int widget, TooltipCloseCondition close_cond) override { switch (widget) { case WID_CF_INCREASE_LOAN: { diff --git a/src/core/pool_func.hpp b/src/core/pool_func.hpp index ffcea87651..f2a31d5178 100644 --- a/src/core/pool_func.hpp +++ b/src/core/pool_func.hpp @@ -60,8 +60,8 @@ DEFINE_POOL_METHOD(inline void)::ResizeFor(size_t index) this->data = ReallocT(this->data, new_size); MemSetT(this->data + this->size, 0, new_size - this->size); - this->free_bitmap = ReallocT(this->free_bitmap, CeilDiv(new_size, 64)); - MemSetT(this->free_bitmap + CeilDiv(this->size, 64), 0, CeilDiv(new_size, 64) - CeilDiv(this->size, 64)); + this->free_bitmap = ReallocT(this->free_bitmap, CeilDivT(new_size, 64)); + MemSetT(this->free_bitmap + CeilDivT(this->size, 64), 0, CeilDivT(new_size, 64) - CeilDivT(this->size, 64)); if (new_size % 64 != 0) { this->free_bitmap[new_size / 64] |= (~((uint64) 0)) << (new_size % 64); } @@ -75,8 +75,8 @@ DEFINE_POOL_METHOD(inline void)::ResizeFor(size_t index) */ DEFINE_POOL_METHOD(inline size_t)::FindFirstFree() { - uint bitmap_index = this->first_free / 64; - uint bitmap_end = CeilDiv(this->first_unused, 64); + size_t bitmap_index = this->first_free / 64; + size_t bitmap_end = CeilDivT(this->first_unused, 64); for (; bitmap_index < bitmap_end; bitmap_index++) { uint64 available = ~this->free_bitmap[bitmap_index]; diff --git a/src/fontcache.cpp b/src/fontcache.cpp index 16bded36e4..3b67b8bac5 100644 --- a/src/fontcache.cpp +++ b/src/fontcache.cpp @@ -70,17 +70,17 @@ private: public: SpriteFontCache(FontSize fs); ~SpriteFontCache(); - virtual SpriteID GetUnicodeGlyph(WChar key); - virtual void SetUnicodeGlyph(WChar key, SpriteID sprite); + virtual SpriteID GetUnicodeGlyph(WChar key) override; + virtual void SetUnicodeGlyph(WChar key, SpriteID sprite) override; virtual void InitializeUnicodeGlyphMap() override; - virtual void ClearFontCache(); - virtual const Sprite *GetGlyph(GlyphID key); - virtual uint GetGlyphWidth(GlyphID key); - virtual bool GetDrawGlyphShadow(); - virtual GlyphID MapCharToGlyph(WChar key) { assert(IsPrintable(key)); return SPRITE_GLYPH | key; } - virtual const void *GetFontTable(uint32 tag, size_t &length) { length = 0; return nullptr; } + virtual void ClearFontCache() override; + virtual const Sprite *GetGlyph(GlyphID key) override; + virtual uint GetGlyphWidth(GlyphID key) override; + virtual bool GetDrawGlyphShadow() override; + virtual GlyphID MapCharToGlyph(WChar key) override { assert(IsPrintable(key)); return SPRITE_GLYPH | key; } + virtual const void *GetFontTable(uint32 tag, size_t &length) override { length = 0; return nullptr; } virtual const char *GetFontName() { return "sprite"; } - virtual bool IsBuiltInFont() { return true; } + virtual bool IsBuiltInFont() override { return true; } }; /** diff --git a/src/gfxinit.cpp b/src/gfxinit.cpp index 9149ee915e..1c4ee94f8b 100644 --- a/src/gfxinit.cpp +++ b/src/gfxinit.cpp @@ -397,6 +397,7 @@ static void UpdateRouteStepSpriteSize() _vp_route_step_subsprite.top = 0; } +#if !defined(DEDICATED) /* multi can be density, field type, ... */ static SpriteID GetSpriteIDForClearGround(const ClearGround cg, const Slope slope, const uint multi) { @@ -415,6 +416,7 @@ static SpriteID GetSpriteIDForClearGround(const ClearGround cg, const Slope slop default: NOT_REACHED(); } } +#endif /* !DEDICATED */ /** Once the sprites are loaded, we can determine main colours of ground/water/... */ void GfxDetermineMainColours() diff --git a/src/network/core/tcp_game.h b/src/network/core/tcp_game.h index da44d3eead..c14a9efdbe 100644 --- a/src/network/core/tcp_game.h +++ b/src/network/core/tcp_game.h @@ -586,7 +586,7 @@ public: void SendCommand(Packet *p, const CommandPacket *cp); virtual std::string GetDebugInfo() const; - virtual void LogSentPacket(const Packet &pkt); + virtual void LogSentPacket(const Packet &pkt) override; }; #endif /* NETWORK_CORE_TCP_GAME_H */ diff --git a/src/newgrf_spritegroup.h b/src/newgrf_spritegroup.h index 5350cc35a3..6706389e4f 100644 --- a/src/newgrf_spritegroup.h +++ b/src/newgrf_spritegroup.h @@ -200,7 +200,7 @@ struct DeterministicSpriteGroup : SpriteGroup { void AnalyseCallbacks(AnalyseCallbackOperation &op) const override; protected: - const SpriteGroup *Resolve(ResolverObject &object) const; + const SpriteGroup *Resolve(ResolverObject &object) const override; }; enum RandomizedSpriteGroupCompareMode { @@ -224,7 +224,7 @@ struct RandomizedSpriteGroup : SpriteGroup { void AnalyseCallbacks(AnalyseCallbackOperation &op) const override; protected: - const SpriteGroup *Resolve(ResolverObject &object) const; + const SpriteGroup *Resolve(ResolverObject &object) const override; }; @@ -250,7 +250,7 @@ struct CallbackResultSpriteGroup : SpriteGroup { } uint16 result; - uint16 GetCallbackResult() const { return this->result; } + uint16 GetCallbackResult() const override { return this->result; } void AnalyseCallbacks(AnalyseCallbackOperation &op) const override; }; diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 706a33c13a..996d5cb9fa 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -1820,7 +1820,6 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 case OCV_COUNTER_VALUE: case OCV_TIME_DATE: case OCV_TIMETABLE: - if (data >= (1 << 16)) return CMD_ERROR; break; default: diff --git a/src/string_func.h b/src/string_func.h index 0184deea18..c022155c1a 100644 --- a/src/string_func.h +++ b/src/string_func.h @@ -38,9 +38,9 @@ int CDECL seprintf(char *str, const char *last, const char *format, ...) WARN_FO int CDECL vseprintf(char *str, const char *last, const char *format, va_list ap) WARN_FORMAT(3, 0); char *CDECL str_fmt(const char *str, ...) WARN_FORMAT(1, 2); -char *str_vfmt(const char *str, va_list ap); +char *str_vfmt(const char *str, va_list ap) WARN_FORMAT(1, 0); std::string CDECL stdstr_fmt(const char *str, ...) WARN_FORMAT(1, 2); -std::string stdstr_vfmt(const char *str, va_list va); +std::string stdstr_vfmt(const char *str, va_list va) WARN_FORMAT(1, 0); char *str_validate(char *str, const char *last, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK); std::string str_validate(const std::string &str, StringValidationSettings settings = SVS_REPLACE_WITH_QUESTION_MARK);