From a2e1102b15cd7f5ae86ab3ea5da4a534b6b58389 Mon Sep 17 00:00:00 2001 From: dP Date: Wed, 24 Jun 2020 15:58:12 +0300 Subject: [PATCH 01/29] Feature: Increase max possible distance from border for oil refineries and rigs --- src/table/settings.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/table/settings.ini b/src/table/settings.ini index 43bd3aec32..c7dbd2128b 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -2250,7 +2250,7 @@ type = SLE_UINT8 from = SLV_30 def = 32 min = 12 -max = 48 +max = 128 str = STR_CONFIG_SETTING_OIL_REF_EDGE_DISTANCE strval = STR_CONFIG_SETTING_TILE_LENGTH strhelp = STR_CONFIG_SETTING_OIL_REF_EDGE_DISTANCE_HELPTEXT From ed6f31f601ef92e098f5555e9bb2b1492c5a7e79 Mon Sep 17 00:00:00 2001 From: TechGeekNZ Date: Thu, 18 Jun 2020 09:50:22 +1200 Subject: [PATCH 02/29] Cleanup: Remove redundant implementation of TakeScreenshot --- src/screenshot.cpp | 39 +++++++++++++++++++++++++++++++- src/screenshot.h | 1 + src/screenshot_gui.cpp | 50 +++++++----------------------------------- src/toolbar_gui.cpp | 49 +++++++---------------------------------- 4 files changed, 55 insertions(+), 84 deletions(-) diff --git a/src/screenshot.cpp b/src/screenshot.cpp index 1db7cceae0..d2bb6a1f35 100644 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -20,6 +20,7 @@ #include "company_func.h" #include "strings_func.h" #include "error.h" +#include "textbuf_gui.h" #include "window_gui.h" #include "window_func.h" #include "tile_map.h" @@ -831,11 +832,47 @@ bool MakeHeightmapScreenshot(const char *filename) return sf->proc(filename, HeightmapCallback, nullptr, MapSizeX(), MapSizeY(), 8, palette); } +static ScreenshotType _confirmed_screenshot_type; ///< Screenshot type the current query is about to confirm. + /** - * Make an actual screenshot. + * Callback on the confirmation window for huge screenshots. + * @param w Window with viewport + * @param confirmed true on confirmation + */ +static void ScreenshotConfirmationCallback(Window *w, bool confirmed) +{ + if (confirmed) MakeScreenshot(_confirmed_screenshot_type, nullptr); +} + +/** + * Take a screenshot. + * Ask for confirmation if the screenshot will be huge. Delegates to \c MakeScreenshot to perform the action. + * @param t Screenshot type: World, defaultzoom, heightmap or viewport screenshot + * @see MakeScreenshot + */ +void TakeScreenshot(ScreenshotType t) +{ + ViewPort vp; + SetupScreenshotViewport(t, &vp); + if ((uint64)vp.width * (uint64)vp.height > 8192 * 8192) { + /* Ask for confirmation */ + _confirmed_screenshot_type = t; + SetDParam(0, vp.width); + SetDParam(1, vp.height); + ShowQuery(STR_WARNING_SCREENSHOT_SIZE_CAPTION, STR_WARNING_SCREENSHOT_SIZE_MESSAGE, nullptr, ScreenshotConfirmationCallback); + } else { + /* Less than 64M pixels, just do it */ + MakeScreenshot(t, nullptr); + } +} + +/** + * Make a screenshot. + * No questions asked, just do it. * @param t the type of screenshot to make. * @param name the name to give to the screenshot. * @return true iff the screenshot was made successfully + * @see TakeScreenshot */ bool MakeScreenshot(ScreenshotType t, const char *name) { diff --git a/src/screenshot.h b/src/screenshot.h index aea08a8d5f..2f6324c222 100644 --- a/src/screenshot.h +++ b/src/screenshot.h @@ -27,6 +27,7 @@ enum ScreenshotType { void SetupScreenshotViewport(ScreenshotType t, struct ViewPort *vp); bool MakeHeightmapScreenshot(const char *filename); +void TakeScreenshot(ScreenshotType t); bool MakeScreenshot(ScreenshotType t, const char *name); bool MakeMinimapWorldScreenshot(); diff --git a/src/screenshot_gui.cpp b/src/screenshot_gui.cpp index 3230020245..ae5854fb7b 100644 --- a/src/screenshot_gui.cpp +++ b/src/screenshot_gui.cpp @@ -8,31 +8,26 @@ /** @file screenshot_gui.cpp GUI functions related to screenshots. */ #include "stdafx.h" -#include "gui.h" -#include "viewport_func.h" #include "window_func.h" #include "window_gui.h" #include "screenshot.h" -#include "textbuf_gui.h" -#include "strings_func.h" - #include "widgets/screenshot_widget.h" - #include "table/strings.h" -static ScreenshotType _screenshot_type; - struct ScreenshotWindow : Window { - ScreenshotWindow(WindowDesc *desc) : Window(desc) { + ScreenshotWindow(WindowDesc *desc) : Window(desc) + { this->CreateNestedTree(); this->FinishInitNested(); } - void OnPaint() override { + void OnPaint() override + { this->DrawWidgets(); } - void OnClick(Point pt, int widget, int click_count) override { + void OnClick(Point pt, int widget, int click_count) override + { if (widget < 0) return; ScreenshotType st; switch (widget) { @@ -46,36 +41,6 @@ struct ScreenshotWindow : Window { } TakeScreenshot(st); } - - /** - * Make a screenshot. - * Ask for confirmation if the screenshot will be huge. - * @param t Screenshot type: World, defaultzoom, heightmap or viewport screenshot - */ - static void TakeScreenshot(ScreenshotType st) { - ViewPort vp; - SetupScreenshotViewport(st, &vp); - if ((uint64)vp.width * (uint64)vp.height > 8192 * 8192) { - /* Ask for confirmation */ - _screenshot_type = st; - SetDParam(0, vp.width); - SetDParam(1, vp.height); - ShowQuery(STR_WARNING_SCREENSHOT_SIZE_CAPTION, STR_WARNING_SCREENSHOT_SIZE_MESSAGE, nullptr, ScreenshotConfirmationCallback); - } - else { - /* Less than 64M pixels, just do it */ - MakeScreenshot(st, nullptr); - } - } - - /** - * Callback on the confirmation window for huge screenshots. - * @param w Window with viewport - * @param confirmed true on confirmation - */ - static void ScreenshotConfirmationCallback(Window *w, bool confirmed) { - if (confirmed) MakeScreenshot(_screenshot_type, nullptr); - } }; static const NWidgetPart _nested_screenshot[] = { @@ -102,7 +67,8 @@ static WindowDesc _screenshot_window_desc( _nested_screenshot, lengthof(_nested_screenshot) ); -void ShowScreenshotWindow() { +void ShowScreenshotWindow() +{ DeleteWindowById(WC_SCREENSHOT, 0); new ScreenshotWindow(&_screenshot_window_desc); } diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 303e4c7293..4d97abb729 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -66,8 +66,6 @@ RailType _last_built_railtype; RoadType _last_built_roadtype; RoadType _last_built_tramtype; -static ScreenshotType _confirmed_screenshot_type; ///< Screenshot type the current query is about to confirm. - /** Toobar modes */ enum ToolbarMode { TB_NORMAL, @@ -1071,37 +1069,6 @@ static CallBackFunction ToolbarHelpClick(Window *w) return CBF_NONE; } -/** - * Callback on the confirmation window for huge screenshots. - * @param w Window with viewport - * @param confirmed true on confirmation - */ -static void ScreenshotConfirmCallback(Window *w, bool confirmed) -{ - if (confirmed) MakeScreenshot(_confirmed_screenshot_type, nullptr); -} - -/** - * Make a screenshot of the world. - * Ask for confirmation if the screenshot will be huge. - * @param t Screenshot type: World or viewport screenshot - */ -static void MenuClickScreenshot(ScreenshotType t) -{ - ViewPort vp; - SetupScreenshotViewport(t, &vp); - if ((uint64)vp.width * (uint64)vp.height > 8192 * 8192) { - /* Ask for confirmation */ - SetDParam(0, vp.width); - SetDParam(1, vp.height); - _confirmed_screenshot_type = t; - ShowQuery(STR_WARNING_SCREENSHOT_SIZE_CAPTION, STR_WARNING_SCREENSHOT_SIZE_MESSAGE, nullptr, ScreenshotConfirmCallback); - } else { - /* Less than 64M pixels, just do it */ - MakeScreenshot(t, nullptr); - } -} - /** * Toggle drawing of sprites' bounding boxes. * @note has only an effect when newgrf_developer_tools are active. @@ -2119,10 +2086,10 @@ struct MainToolbarWindow : Window { case MTHK_BUILD_TREES: ShowBuildTreesToolbar(); break; case MTHK_MUSIC: ShowMusicWindow(); break; case MTHK_AI_DEBUG: ShowAIDebugWindow(); break; - case MTHK_SMALL_SCREENSHOT: MenuClickScreenshot(SC_VIEWPORT); break; - case MTHK_ZOOMEDIN_SCREENSHOT: MenuClickScreenshot(SC_ZOOMEDIN); break; - case MTHK_DEFAULTZOOM_SCREENSHOT: MenuClickScreenshot(SC_DEFAULTZOOM); break; - case MTHK_GIANT_SCREENSHOT: MenuClickScreenshot(SC_WORLD); break; + case MTHK_SMALL_SCREENSHOT: TakeScreenshot(SC_VIEWPORT); break; + case MTHK_ZOOMEDIN_SCREENSHOT: TakeScreenshot(SC_ZOOMEDIN); break; + case MTHK_DEFAULTZOOM_SCREENSHOT: TakeScreenshot(SC_DEFAULTZOOM); break; + case MTHK_GIANT_SCREENSHOT: TakeScreenshot(SC_WORLD); break; case MTHK_CHEATS: if (!_networking) ShowCheatWindow(); break; case MTHK_TERRAFORM: ShowTerraformToolbar(); break; case MTHK_EXTRA_VIEWPORT: ShowExtraViewPortWindowForTileUnderCursor(); break; @@ -2494,10 +2461,10 @@ struct ScenarioEditorToolbarWindow : Window { case MTEHK_SIGN: cbf = ToolbarScenPlaceSign(this); break; case MTEHK_MUSIC: ShowMusicWindow(); break; case MTEHK_LANDINFO: cbf = PlaceLandBlockInfo(); break; - case MTEHK_SMALL_SCREENSHOT: MenuClickScreenshot(SC_VIEWPORT); break; - case MTEHK_ZOOMEDIN_SCREENSHOT: MenuClickScreenshot(SC_ZOOMEDIN); break; - case MTEHK_DEFAULTZOOM_SCREENSHOT: MenuClickScreenshot(SC_DEFAULTZOOM); break; - case MTEHK_GIANT_SCREENSHOT: MenuClickScreenshot(SC_WORLD); break; + case MTEHK_SMALL_SCREENSHOT: TakeScreenshot(SC_VIEWPORT); break; + case MTEHK_ZOOMEDIN_SCREENSHOT: TakeScreenshot(SC_ZOOMEDIN); break; + case MTEHK_DEFAULTZOOM_SCREENSHOT: TakeScreenshot(SC_DEFAULTZOOM); break; + case MTEHK_GIANT_SCREENSHOT: TakeScreenshot(SC_WORLD); break; case MTEHK_ZOOM_IN: ToolbarZoomInClick(this); break; case MTEHK_ZOOM_OUT: ToolbarZoomOutClick(this); break; case MTEHK_TERRAFORM: ShowEditorTerraformToolbar(); break; From 3c8d0aa3544602dd8e34ec8ffcdc12cfc7f73b3f Mon Sep 17 00:00:00 2001 From: TechGeekNZ Date: Sat, 20 Jun 2020 17:12:31 +1200 Subject: [PATCH 03/29] Cleanup: Give `TakeScreenshot` a more sensible name --- src/screenshot.cpp | 10 +++++----- src/screenshot.h | 2 +- src/screenshot_gui.cpp | 2 +- src/toolbar_gui.cpp | 16 ++++++++-------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/screenshot.cpp b/src/screenshot.cpp index d2bb6a1f35..c895862265 100644 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -845,12 +845,12 @@ static void ScreenshotConfirmationCallback(Window *w, bool confirmed) } /** - * Take a screenshot. - * Ask for confirmation if the screenshot will be huge. Delegates to \c MakeScreenshot to perform the action. + * Make a screenshot. + * Ask for confirmation first if the screenshot will be huge. * @param t Screenshot type: World, defaultzoom, heightmap or viewport screenshot * @see MakeScreenshot */ -void TakeScreenshot(ScreenshotType t) +void MakeScreenshotWithConfirm(ScreenshotType t) { ViewPort vp; SetupScreenshotViewport(t, &vp); @@ -868,11 +868,11 @@ void TakeScreenshot(ScreenshotType t) /** * Make a screenshot. - * No questions asked, just do it. + * Unconditionally take a screenshot of the requested type. * @param t the type of screenshot to make. * @param name the name to give to the screenshot. * @return true iff the screenshot was made successfully - * @see TakeScreenshot + * @see MakeScreenshotWithConfirm */ bool MakeScreenshot(ScreenshotType t, const char *name) { diff --git a/src/screenshot.h b/src/screenshot.h index 2f6324c222..b872593638 100644 --- a/src/screenshot.h +++ b/src/screenshot.h @@ -27,7 +27,7 @@ enum ScreenshotType { void SetupScreenshotViewport(ScreenshotType t, struct ViewPort *vp); bool MakeHeightmapScreenshot(const char *filename); -void TakeScreenshot(ScreenshotType t); +void MakeScreenshotWithConfirm(ScreenshotType t); bool MakeScreenshot(ScreenshotType t, const char *name); bool MakeMinimapWorldScreenshot(); diff --git a/src/screenshot_gui.cpp b/src/screenshot_gui.cpp index ae5854fb7b..c0e65f13d0 100644 --- a/src/screenshot_gui.cpp +++ b/src/screenshot_gui.cpp @@ -39,7 +39,7 @@ struct ScreenshotWindow : Window { case WID_SC_TAKE_HEIGHTMAP: st = SC_HEIGHTMAP; break; case WID_SC_TAKE_MINIMAP: st = SC_MINIMAP; break; } - TakeScreenshot(st); + MakeScreenshotWithConfirm(st); } }; diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 4d97abb729..f471ac1158 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -2086,10 +2086,10 @@ struct MainToolbarWindow : Window { case MTHK_BUILD_TREES: ShowBuildTreesToolbar(); break; case MTHK_MUSIC: ShowMusicWindow(); break; case MTHK_AI_DEBUG: ShowAIDebugWindow(); break; - case MTHK_SMALL_SCREENSHOT: TakeScreenshot(SC_VIEWPORT); break; - case MTHK_ZOOMEDIN_SCREENSHOT: TakeScreenshot(SC_ZOOMEDIN); break; - case MTHK_DEFAULTZOOM_SCREENSHOT: TakeScreenshot(SC_DEFAULTZOOM); break; - case MTHK_GIANT_SCREENSHOT: TakeScreenshot(SC_WORLD); break; + case MTHK_SMALL_SCREENSHOT: MakeScreenshotWithConfirm(SC_VIEWPORT); break; + case MTHK_ZOOMEDIN_SCREENSHOT: MakeScreenshotWithConfirm(SC_ZOOMEDIN); break; + case MTHK_DEFAULTZOOM_SCREENSHOT: MakeScreenshotWithConfirm(SC_DEFAULTZOOM); break; + case MTHK_GIANT_SCREENSHOT: MakeScreenshotWithConfirm(SC_WORLD); break; case MTHK_CHEATS: if (!_networking) ShowCheatWindow(); break; case MTHK_TERRAFORM: ShowTerraformToolbar(); break; case MTHK_EXTRA_VIEWPORT: ShowExtraViewPortWindowForTileUnderCursor(); break; @@ -2461,10 +2461,10 @@ struct ScenarioEditorToolbarWindow : Window { case MTEHK_SIGN: cbf = ToolbarScenPlaceSign(this); break; case MTEHK_MUSIC: ShowMusicWindow(); break; case MTEHK_LANDINFO: cbf = PlaceLandBlockInfo(); break; - case MTEHK_SMALL_SCREENSHOT: TakeScreenshot(SC_VIEWPORT); break; - case MTEHK_ZOOMEDIN_SCREENSHOT: TakeScreenshot(SC_ZOOMEDIN); break; - case MTEHK_DEFAULTZOOM_SCREENSHOT: TakeScreenshot(SC_DEFAULTZOOM); break; - case MTEHK_GIANT_SCREENSHOT: TakeScreenshot(SC_WORLD); break; + case MTEHK_SMALL_SCREENSHOT: MakeScreenshotWithConfirm(SC_VIEWPORT); break; + case MTEHK_ZOOMEDIN_SCREENSHOT: MakeScreenshotWithConfirm(SC_ZOOMEDIN); break; + case MTEHK_DEFAULTZOOM_SCREENSHOT: MakeScreenshotWithConfirm(SC_DEFAULTZOOM); break; + case MTEHK_GIANT_SCREENSHOT: MakeScreenshotWithConfirm(SC_WORLD); break; case MTEHK_ZOOM_IN: ToolbarZoomInClick(this); break; case MTEHK_ZOOM_OUT: ToolbarZoomOutClick(this); break; case MTEHK_TERRAFORM: ShowEditorTerraformToolbar(); break; From 8a655c7fb6375ad47b951b5011657dfa31cc76a6 Mon Sep 17 00:00:00 2001 From: Abdurrahmaan Iqbal Date: Tue, 23 Jun 2020 15:20:02 +0100 Subject: [PATCH 04/29] Fix #8232: 'Huge screenshot' warning being shown incorrectly --- src/screenshot.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/screenshot.cpp b/src/screenshot.cpp index c895862265..8cf83ae5bc 100644 --- a/src/screenshot.cpp +++ b/src/screenshot.cpp @@ -854,11 +854,16 @@ void MakeScreenshotWithConfirm(ScreenshotType t) { ViewPort vp; SetupScreenshotViewport(t, &vp); - if ((uint64)vp.width * (uint64)vp.height > 8192 * 8192) { + + bool heightmap_or_minimap = t == SC_HEIGHTMAP || t == SC_MINIMAP; + uint64_t width = (heightmap_or_minimap ? MapSizeX() : vp.width); + uint64_t height = (heightmap_or_minimap ? MapSizeY() : vp.height); + + if (width * height > 8192 * 8192) { /* Ask for confirmation */ _confirmed_screenshot_type = t; - SetDParam(0, vp.width); - SetDParam(1, vp.height); + SetDParam(0, width); + SetDParam(1, height); ShowQuery(STR_WARNING_SCREENSHOT_SIZE_CAPTION, STR_WARNING_SCREENSHOT_SIZE_MESSAGE, nullptr, ScreenshotConfirmationCallback); } else { /* Less than 64M pixels, just do it */ From 224acb78b03defd075aafec9d3340b3bc0dcedfc Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sat, 27 Jun 2020 08:29:40 +0100 Subject: [PATCH 05/29] Fix: Compiler warnings about memsetting non-trivial classes --- src/cargotype.cpp | 2 +- src/network/network_gui.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cargotype.cpp b/src/cargotype.cpp index 52dd196c84..8421c482ed 100644 --- a/src/cargotype.cpp +++ b/src/cargotype.cpp @@ -42,8 +42,8 @@ void SetupCargoForClimate(LandscapeID l) assert(l < lengthof(_default_climate_cargo)); /* Reset and disable all cargo types */ - memset(CargoSpec::array, 0, sizeof(CargoSpec::array)); for (CargoID i = 0; i < lengthof(CargoSpec::array); i++) { + *CargoSpec::Get(i) = {}; CargoSpec::Get(i)->bitnum = INVALID_CARGO; /* Set defaults for newer properties, which old GRFs do not know */ diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index ab72d9521c..c430c47e5e 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -1580,7 +1580,7 @@ struct NetworkLobbyWindow : public Window { NetworkTCPQueryServer(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port)); // company info NetworkUDPQueryServer(NetworkAddress(_settings_client.network.last_host, _settings_client.network.last_port)); // general data /* Clear the information so removed companies don't remain */ - memset(this->company_info, 0, sizeof(this->company_info)); + for (auto &company : this->company_info) company = {}; break; } } From 64b1c70fddc8b7ef2e8f629d6e5e1749f21a0e4b Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sat, 27 Jun 2020 09:01:31 +0100 Subject: [PATCH 06/29] Codechange: Add WARN_FORMAT to vseprintf and fix the cascade of warnings that followed --- src/3rdparty/squirrel/squirrel/sqcompiler.cpp | 6 +++--- src/3rdparty/squirrel/squirrel/sqvm.cpp | 2 +- src/3rdparty/squirrel/squirrel/sqvm.h | 2 +- src/misc/str.hpp | 2 +- src/saveload/saveload.h | 2 +- src/script/squirrel.hpp | 4 ++-- src/string_func.h | 2 +- 7 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/3rdparty/squirrel/squirrel/sqcompiler.cpp b/src/3rdparty/squirrel/squirrel/sqcompiler.cpp index 854d080d2b..9eb71d457f 100644 --- a/src/3rdparty/squirrel/squirrel/sqcompiler.cpp +++ b/src/3rdparty/squirrel/squirrel/sqcompiler.cpp @@ -65,9 +65,9 @@ public: } NORETURN static void ThrowError(void *ud, const SQChar *s) { SQCompiler *c = (SQCompiler *)ud; - c->Error(s); + c->Error("%s", s); } - NORETURN void Error(const SQChar *s, ...) + NORETURN void Error(const SQChar *s, ...) WARN_FORMAT(2, 3) { static SQChar temp[256]; va_list vl; @@ -122,7 +122,7 @@ public: } Error("expected '%s'", etypename); } - Error("expected '%c'", tok); + Error("expected '%c'", (char)tok); } } SQObjectPtr ret; diff --git a/src/3rdparty/squirrel/squirrel/sqvm.cpp b/src/3rdparty/squirrel/squirrel/sqvm.cpp index 03ffea2303..ee1acbf328 100644 --- a/src/3rdparty/squirrel/squirrel/sqvm.cpp +++ b/src/3rdparty/squirrel/squirrel/sqvm.cpp @@ -94,7 +94,7 @@ bool SQVM::ARITH_OP(SQUnsignedInteger op,SQObjectPtr &trg,const SQObjectPtr &o1, if(!StringCat(o1, o2, trg)) return false; } else if(!ArithMetaMethod(op,o1,o2,trg)) { - Raise_Error("arith op %c on between '%s' and '%s'",op,GetTypeName(o1),GetTypeName(o2)); return false; + Raise_Error("arith op %c on between '%s' and '%s'",(char)op,GetTypeName(o1),GetTypeName(o2)); return false; } } return true; diff --git a/src/3rdparty/squirrel/squirrel/sqvm.h b/src/3rdparty/squirrel/squirrel/sqvm.h index 97557b1332..9c8e986fbc 100644 --- a/src/3rdparty/squirrel/squirrel/sqvm.h +++ b/src/3rdparty/squirrel/squirrel/sqvm.h @@ -81,7 +81,7 @@ public: SQString *PrintObjVal(const SQObject &o); - void Raise_Error(const SQChar *s, ...); + void Raise_Error(const SQChar *s, ...) WARN_FORMAT(2, 3); void Raise_Error(SQObjectPtr &desc); void Raise_IdxError(const SQObject &o); void Raise_CompareError(const SQObject &o1, const SQObject &o2); diff --git a/src/misc/str.hpp b/src/misc/str.hpp index e93ce5efc3..9555681dfa 100644 --- a/src/misc/str.hpp +++ b/src/misc/str.hpp @@ -90,7 +90,7 @@ struct CStrA : public CBlobT } /** Add formatted string (like vsprintf) at the end of existing contents. */ - int AddFormatL(const char *format, va_list args) + int AddFormatL(const char *format, va_list args) WARN_FORMAT(2, 0) { size_t addSize = max(strlen(format), 16); addSize += addSize / 2; diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index 01a074bd80..af2de11893 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -896,7 +896,7 @@ void SlObject(void *object, const SaveLoad *sld); bool SlObjectMember(void *object, const SaveLoad *sld); void NORETURN SlError(StringID string, const char *extra_msg = nullptr); void NORETURN SlErrorCorrupt(const char *msg); -void NORETURN SlErrorCorruptFmt(const char *format, ...); +void NORETURN SlErrorCorruptFmt(const char *format, ...) WARN_FORMAT(1, 2); bool SaveloadCrashWithMissingNewGRFs(); diff --git a/src/script/squirrel.hpp b/src/script/squirrel.hpp index cfe54b36ec..412011cccc 100644 --- a/src/script/squirrel.hpp +++ b/src/script/squirrel.hpp @@ -63,12 +63,12 @@ protected: /** * If a user runs 'print' inside a script, this function gets the params. */ - static void PrintFunc(HSQUIRRELVM vm, const SQChar *s, ...); + static void PrintFunc(HSQUIRRELVM vm, const SQChar *s, ...) WARN_FORMAT(2, 3); /** * If an error has to be print, this function is called. */ - static void ErrorPrintFunc(HSQUIRRELVM vm, const SQChar *s, ...); + static void ErrorPrintFunc(HSQUIRRELVM vm, const SQChar *s, ...) WARN_FORMAT(2, 3); public: Squirrel(const char *APIName); diff --git a/src/string_func.h b/src/string_func.h index febdf7c2a4..6c226c6104 100644 --- a/src/string_func.h +++ b/src/string_func.h @@ -35,7 +35,7 @@ char *strecpy(char *dst, const char *src, const char *last); char *stredup(const char *src, const char *last = nullptr); int CDECL seprintf(char *str, const char *last, const char *format, ...) WARN_FORMAT(3, 4); -int CDECL vseprintf(char *str, const char *last, const char *format, va_list ap); +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); From e5f931ef42ca169003d2282a8a585ea208b5f943 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sat, 27 Jun 2020 11:00:53 +0100 Subject: [PATCH 07/29] Fix: Warning about using the wrong enum type --- src/script/api/script_story_page.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/script/api/script_story_page.cpp b/src/script/api/script_story_page.cpp index 8fda69e6f5..4ee90e218d 100644 --- a/src/script/api/script_story_page.cpp +++ b/src/script/api/script_story_page.cpp @@ -119,16 +119,16 @@ static inline bool StoryPageElementTypeRequiresText(StoryPageElementType type) uint32 refid = 0; TileIndex reftile = 0; switch (type) { - case SPET_LOCATION: + case ::SPET_LOCATION: reftile = reference; break; - case SPET_GOAL: - case SPET_BUTTON_PUSH: - case SPET_BUTTON_TILE: - case SPET_BUTTON_VEHICLE: + case ::SPET_GOAL: + case ::SPET_BUTTON_PUSH: + case ::SPET_BUTTON_TILE: + case ::SPET_BUTTON_VEHICLE: refid = reference; break; - case SPET_TEXT: + case ::SPET_TEXT: break; default: NOT_REACHED(); From 887b912af123b5a9bf2339a98e724afe99e6a03d Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sat, 27 Jun 2020 12:17:05 +0100 Subject: [PATCH 08/29] Codechange: Only apply FORTIFY_SOURCE in non-debug builds It requires -O1 (or greater) and GCC spews out warnings if you try using it with -O0 --- cmake/CompileFlags.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/CompileFlags.cmake b/cmake/CompileFlags.cmake index 05c19abab9..9287ca2490 100644 --- a/cmake/CompileFlags.cmake +++ b/cmake/CompileFlags.cmake @@ -31,7 +31,7 @@ macro(compile_flags) # it does not appear to support the $<> tags. add_compile_options( "$<$:-D_DEBUG>" - "$<$:-D_FORTIFY_SOURCE=2>" + "$<$>:-D_FORTIFY_SOURCE=2>" # FORTIFY_SOURCE should only be used in non-debug builds (requires -O1+) ) # Prepare a generator that checks if we are not a debug, and don't have asserts From dc8d0089e95a0fb9a77330fe890f72ac3bb430ea Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sat, 27 Jun 2020 13:59:15 +0100 Subject: [PATCH 09/29] Codechange: Make sure script enums are the same size as their normal counterparts --- src/script/api/script_company.hpp | 2 +- src/script/api/script_goal.hpp | 2 +- src/script/api/script_rail.hpp | 2 +- src/script/api/script_road.hpp | 2 +- src/script/api/script_story_page.hpp | 6 +++--- 5 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/script/api/script_company.hpp b/src/script/api/script_company.hpp index ed1d78f1e1..ea2f0cdd14 100644 --- a/src/script/api/script_company.hpp +++ b/src/script/api/script_company.hpp @@ -99,7 +99,7 @@ public: * Types of expenses. * @api -ai */ - enum ExpensesType { + enum ExpensesType : byte { EXPENSES_CONSTRUCTION = ::EXPENSES_CONSTRUCTION, ///< Construction costs. EXPENSES_NEW_VEHICLES = ::EXPENSES_NEW_VEHICLES, ///< New vehicles. EXPENSES_TRAIN_RUN = ::EXPENSES_TRAIN_RUN, ///< Running costs trains. diff --git a/src/script/api/script_goal.hpp b/src/script/api/script_goal.hpp index 372d6e8b49..2261dcc00f 100644 --- a/src/script/api/script_goal.hpp +++ b/src/script/api/script_goal.hpp @@ -36,7 +36,7 @@ public: /** * Goal types that can be given to a goal. */ - enum GoalType { + enum GoalType : byte { /* Note: these values represent part of the in-game GoalType enum */ GT_NONE = ::GT_NONE, ///< Destination is not linked. GT_TILE = ::GT_TILE, ///< Destination is a tile. diff --git a/src/script/api/script_rail.hpp b/src/script/api/script_rail.hpp index f82765a706..ec056dacb5 100644 --- a/src/script/api/script_rail.hpp +++ b/src/script/api/script_rail.hpp @@ -40,7 +40,7 @@ public: /** * Types of rail known to the game. */ - enum RailType { + enum RailType : byte { /* Note: these values represent part of the in-game static values */ RAILTYPE_INVALID = ::INVALID_RAILTYPE, ///< Invalid RailType. }; diff --git a/src/script/api/script_road.hpp b/src/script/api/script_road.hpp index 5a952d91a2..64b7833862 100644 --- a/src/script/api/script_road.hpp +++ b/src/script/api/script_road.hpp @@ -60,7 +60,7 @@ public: /** * Road/tram types */ - enum RoadTramTypes { + enum RoadTramTypes : uint8 { ROADTRAMTYPES_ROAD = ::RTTB_ROAD, ///< Road road types. ROADTRAMTYPES_TRAM = ::RTTB_TRAM, ///< Tram road types. }; diff --git a/src/script/api/script_story_page.hpp b/src/script/api/script_story_page.hpp index 23e4e03b14..c87ef7cb37 100644 --- a/src/script/api/script_story_page.hpp +++ b/src/script/api/script_story_page.hpp @@ -57,7 +57,7 @@ public: /** * Story page element types. */ - enum StoryPageElementType { + enum StoryPageElementType : byte { SPET_TEXT = ::SPET_TEXT, ///< An element that displays a block of text. SPET_LOCATION = ::SPET_LOCATION, ///< An element that displays a single line of text along with a button to view the referenced location. SPET_GOAL = ::SPET_GOAL, ///< An element that displays a goal. @@ -75,7 +75,7 @@ public: * Formatting and layout flags for story page buttons. * The SPBF_FLOAT_LEFT and SPBF_FLOAT_RIGHT flags can not be combined. */ - enum StoryPageButtonFlags { + enum StoryPageButtonFlags : byte { SPBF_NONE = ::SPBF_NONE, ///< No special formatting for button. SPBF_FLOAT_LEFT = ::SPBF_FLOAT_LEFT, ///< Button is placed to the left of the following paragraph. SPBF_FLOAT_RIGHT = ::SPBF_FLOAT_RIGHT, ///< Button is placed to the right of the following paragraph. @@ -84,7 +84,7 @@ public: /** * Mouse cursors usable by story page buttons. */ - enum StoryPageButtonCursor { + enum StoryPageButtonCursor : byte { SPBC_MOUSE = ::SPBC_MOUSE, SPBC_ZZZ = ::SPBC_ZZZ, SPBC_BUOY = ::SPBC_BUOY, From 4c45448fa9d9bc7dabe7e971bf4b56ba7e595693 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sat, 27 Jun 2020 14:14:21 +0100 Subject: [PATCH 10/29] Fix #8129: Crash if a news message expires while viewing the endgame screen --- src/news_gui.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/news_gui.cpp b/src/news_gui.cpp index 9993645c43..0b4c41a2a9 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -671,6 +671,11 @@ static bool ReadyForNextNewsItem() /** Move to the next ticker item */ static void MoveToNextTickerItem() { + /* There is no status bar, so no reason to show news; + * especially important with the end game screen when + * there is no status bar but possible news. */ + if (FindWindowById(WC_STATUS_BAR, 0) == nullptr) return; + InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); // invalidate the statusbar /* if we're not at the last item, then move on */ @@ -702,6 +707,11 @@ static void MoveToNextTickerItem() /** Move to the next news item */ static void MoveToNextNewsItem() { + /* There is no status bar, so no reason to show news; + * especially important with the end game screen when + * there is no status bar but possible news. */ + if (FindWindowById(WC_STATUS_BAR, 0) == nullptr) return; + DeleteWindowById(WC_NEWS_WINDOW, 0); // close the newspapers window if shown _forced_news = nullptr; @@ -995,11 +1005,6 @@ void NewsLoop() /* no news item yet */ if (_total_news == 0) return; - /* There is no status bar, so no reason to show news; - * especially important with the end game screen when - * there is no status bar but possible news. */ - if (FindWindowById(WC_STATUS_BAR, 0) == nullptr) return; - static byte _last_clean_month = 0; if (_last_clean_month != _cur_month) { From 75a2ae2f48a88a7496f135b020aeb5cf1c2924bb Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sat, 27 Jun 2020 15:30:22 +0100 Subject: [PATCH 11/29] Change: Also make roadside trees match the tree transparency option --- src/road_cmd.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/road_cmd.cpp b/src/road_cmd.cpp index 5a9efb8567..29d7f69bd7 100644 --- a/src/road_cmd.cpp +++ b/src/road_cmd.cpp @@ -1474,14 +1474,15 @@ void DrawRoadCatenary(const TileInfo *ti) * @param dx the offset from the top of the BB of the tile * @param dy the offset from the top of the BB of the tile * @param h the height of the sprite to draw + * @param transparent whether the sprite should be transparent (used for roadside trees) */ -static void DrawRoadDetail(SpriteID img, const TileInfo *ti, int dx, int dy, int h) +static void DrawRoadDetail(SpriteID img, const TileInfo *ti, int dx, int dy, int h, bool transparent) { int x = ti->x | dx; int y = ti->y | dy; int z = ti->z; if (ti->tileh != SLOPE_FLAT) z = GetSlopePixelZ(x, y); - AddSortableSpriteToDraw(img, PAL_NONE, x, y, 2, 2, h, z); + AddSortableSpriteToDraw(img, PAL_NONE, x, y, 2, 2, h, z, transparent); } /** @@ -1634,9 +1635,12 @@ static void DrawRoadBits(TileInfo *ti) /* If there are no road bits, return, as there is nothing left to do */ if (HasAtMostOneBit(road)) return; + if (roadside == ROADSIDE_TREES && IsInvisibilitySet(TO_TREES)) return; + bool is_transparent = roadside == ROADSIDE_TREES && IsTransparencySet(TO_TREES); + /* Draw extra details. */ for (const DrawRoadTileStruct *drts = _road_display_table[roadside][road | tram]; drts->image != 0; drts++) { - DrawRoadDetail(drts->image, ti, drts->subcoord_x, drts->subcoord_y, 0x10); + DrawRoadDetail(drts->image, ti, drts->subcoord_x, drts->subcoord_y, 0x10, is_transparent); } } From 1bc7047af724f9d6282f7cc79289ecdffe084d1c Mon Sep 17 00:00:00 2001 From: duck Date: Sat, 27 Jun 2020 16:21:17 +0000 Subject: [PATCH 12/29] Doc: Acknowledge integer type mismatch in certain admin packets using AdminUpdateType (#8238) --- docs/admin_network.md | 14 ++++++++++++++ src/network/core/tcp_admin.h | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/docs/admin_network.md b/docs/admin_network.md index ff5ea7c27a..4703df322a 100644 --- a/docs/admin_network.md +++ b/docs/admin_network.md @@ -86,6 +86,9 @@ Last updated: 2011-01-20 Note: not every update type supports every frequency. If in doubt, you can verify against the data received in `ADMIN_PACKET_SERVER_PROTOCOL`. + Please note the potential gotcha in the "Certain packet information" section below + when using the `ADMIN_UPDATE_FREQUENCY` packet. + The server will not confirm your registered update. However, asking for an invalid `AdminUpdateType` or a not supported `AdminUpdateFrequency` you will be disconnected from the server with `NETWORK_ERROR_ILLEGAL_PACKET`. @@ -143,6 +146,9 @@ Last updated: 2011-01-20 - ADMIN_UPDATE_COMPANY_STATS - ADMIN_UPDATE_CMD_NAMES + Please note the potential gotcha in the "Certain packet information" section below + when using the `ADMIN_POLL` packet. + `ADMIN_UPDATE_CLIENT_INFO` and `ADMIN_UPDATE_COMPANY_INFO` accept an additional parameter. This parameter is used to specify a certain client or company. Setting this parameter to `UINT32_MAX (0xFFFFFFFF)` will tell the server you @@ -213,6 +219,14 @@ Last updated: 2011-01-20 ## 7.0) Certain packet information + `ADMIN_PACKET_ADMIN_UPDATE_FREQUENCY` and `ADMIN_PACKET_ADMIN_POLL` + + Potential gotcha: the AdminUpdateType integer type used is a + uint16 for `UPDATE_FREQUENCY`, and a uint8 for `POLL`. + This is due to boring legacy reasons. + It is safe to cast between the two when sending + (i.e cast from a uint8 to a uint16). + All `ADMIN_PACKET_SERVER_*` packets have an enum value greater 100. `ADMIN_PACKET_SERVER_WELCOME` diff --git a/src/network/core/tcp_admin.h b/src/network/core/tcp_admin.h index 979e5963f0..dc9753e89f 100644 --- a/src/network/core/tcp_admin.h +++ b/src/network/core/tcp_admin.h @@ -134,7 +134,7 @@ protected: /** * Register updates to be sent at certain frequencies (as announced in the PROTOCOL packet): - * uint16 Update type (see #AdminUpdateType). + * uint16 Update type (see #AdminUpdateType). Note integer type - see "Certain Packet Information" in docs/admin_network.md. * uint16 Update frequency (see #AdminUpdateFrequency), setting #ADMIN_FREQUENCY_POLL is always ignored. * @param p The packet that was just received. * @return The state the network should have. @@ -143,7 +143,7 @@ protected: /** * Poll the server for certain updates, an invalid poll (e.g. not existent id) gets silently dropped: - * uint8 #AdminUpdateType the server should answer for, only if #AdminUpdateFrequency #ADMIN_FREQUENCY_POLL is advertised in the PROTOCOL packet. + * uint8 #AdminUpdateType the server should answer for, only if #AdminUpdateFrequency #ADMIN_FREQUENCY_POLL is advertised in the PROTOCOL packet. Note integer type - see "Certain Packet Information" in docs/admin_network.md. * uint32 ID relevant to the packet type, e.g. * - the client ID for #ADMIN_UPDATE_CLIENT_INFO. Use UINT32_MAX to show all clients. * - the company ID for #ADMIN_UPDATE_COMPANY_INFO. Use UINT32_MAX to show all companies. From 218db00c4c75d0452dd76996a1925775ebdc4e70 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sat, 27 Jun 2020 15:13:13 +0100 Subject: [PATCH 13/29] Fix #8216: Don't show floating text on autoreplace if cost is 0 --- src/vehicle.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vehicle.cpp b/src/vehicle.cpp index 72ef5a31ad..30ac096b4a 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1045,7 +1045,7 @@ void CallVehicleTicks() if (!IsLocalCompany()) continue; - if (res.Succeeded()) { + if (res.Succeeded() && res.GetCost() != 0) { ShowCostOrIncomeAnimation(x, y, z, res.GetCost()); continue; } From 63d20c029bd283e03a93d3ab93e1565ac427cdce Mon Sep 17 00:00:00 2001 From: glx22 Date: Sun, 28 Jun 2020 01:18:28 +0200 Subject: [PATCH 14/29] Fix 887b912af: MinGW requires an extra link flag with _FORTIFY_SOURCE (#8246) see #7860 --- cmake/CompileFlags.cmake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cmake/CompileFlags.cmake b/cmake/CompileFlags.cmake index 9287ca2490..e7d470c7d3 100644 --- a/cmake/CompileFlags.cmake +++ b/cmake/CompileFlags.cmake @@ -33,6 +33,11 @@ macro(compile_flags) "$<$:-D_DEBUG>" "$<$>:-D_FORTIFY_SOURCE=2>" # FORTIFY_SOURCE should only be used in non-debug builds (requires -O1+) ) + if (MINGW) + add_link_options( + "$<$>:-fstack-protector>" # Prevent undefined references when _FORTIFY_SOURCE > 0 + ) + endif (MINGW) # Prepare a generator that checks if we are not a debug, and don't have asserts # on. We need this later on to set some compile options for stable releases. From a4a9908a51a00277eae764148b33095ffbf0699d Mon Sep 17 00:00:00 2001 From: TrevorShelton <54145769+TrevorShelton@users.noreply.github.com> Date: Sun, 28 Jun 2020 04:53:56 -0700 Subject: [PATCH 15/29] Fix #8221: Missing specific error message for bridge too long (#8240) --- src/bridge_gui.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/bridge_gui.cpp b/src/bridge_gui.cpp index f10b52f66b..44cc99ba3e 100644 --- a/src/bridge_gui.cpp +++ b/src/bridge_gui.cpp @@ -426,9 +426,12 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo default: break; } + bool any_available = false; + CommandCost type_check; /* loop for all bridgetypes */ for (BridgeType brd_type = 0; brd_type != MAX_BRIDGES; brd_type++) { - if (CheckBridgeAvailability(brd_type, bridge_len).Succeeded()) { + type_check = CheckBridgeAvailability(brd_type, bridge_len); + if (type_check.Succeeded()) { /* bridge is accepted, add to list */ /*C++17: BuildBridgeData &item = */ bl->emplace_back(); BuildBridgeData &item = bl->back(); @@ -437,8 +440,14 @@ void ShowBuildBridgeWindow(TileIndex start, TileIndex end, TransportType transpo /* Add to terraforming & bulldozing costs the cost of the * bridge itself (not computed with DC_QUERY_COST) */ item.cost = ret.GetCost() + (((int64)tot_bridgedata_len * _price[PR_BUILD_BRIDGE] * item.spec->price) >> 8) + infra_cost; + any_available = true; } } + /* give error cause if no bridges available here*/ + if (!any_available) + { + errmsg = type_check.GetErrorMessage(); + } } if (bl != nullptr && bl->size() != 0) { From cf8ccf4b08a0ad27079b91cacd8af01112646aa4 Mon Sep 17 00:00:00 2001 From: ilayaraja97 Date: Sat, 16 May 2020 20:35:37 +0530 Subject: [PATCH 16/29] Fix #8131: small bridges also have pillars drawn --- src/tunnelbridge_cmd.cpp | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/src/tunnelbridge_cmd.cpp b/src/tunnelbridge_cmd.cpp index c5e2f8d9bb..1a66d530f0 100644 --- a/src/tunnelbridge_cmd.cpp +++ b/src/tunnelbridge_cmd.cpp @@ -1623,22 +1623,7 @@ void DrawBridgeMiddle(const TileInfo *ti) if (IsInvisibilitySet(TO_BRIDGES)) return; psid++; - if (ti->z + 5 == z) { - /* draw poles below for small bridges */ - if (psid->sprite != 0) { - SpriteID image = psid->sprite; - SpriteID pal = psid->pal; - if (IsTransparencySet(TO_BRIDGES)) { - SetBit(image, PALETTE_MODIFIER_TRANSPARENT); - pal = PALETTE_TO_TRANSPARENT; - } - - DrawGroundSpriteAt(image, pal, x - ti->x, y - ti->y, z - ti->z); - } - } else { - /* draw pillars below for high bridges */ - DrawBridgePillars(psid, ti, axis, drawfarpillar, x, y, z); - } + DrawBridgePillars(psid, ti, axis, drawfarpillar, x, y, z); } From 54237b0e98894008168285109634479dddb1bc16 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 17 May 2020 22:24:59 +0100 Subject: [PATCH 17/29] Codechange: Move SlSkipBytes to saveload.h --- src/saveload/saveload.cpp | 10 ---------- src/saveload/saveload.h | 10 ++++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index 4da89aa847..8cf6a39238 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -467,16 +467,6 @@ static inline void SlWriteUint64(uint64 x) SlWriteUint32((uint32)x); } -/** - * Read in bytes from the file/data structure but don't do - * anything with them, discarding them in effect - * @param length The amount of bytes that is being treated this way - */ -static inline void SlSkipBytes(size_t length) -{ - for (; length != 0; length--) SlReadByte(); -} - /** * Read in the header descriptor of an object or an array. * If the highest bit is set (7), then the index is bigger than 127 diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index af2de11893..26462cdaa4 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -900,6 +900,16 @@ void NORETURN SlErrorCorruptFmt(const char *format, ...) WARN_FORMAT(1, 2); bool SaveloadCrashWithMissingNewGRFs(); +/** + * Read in bytes from the file/data structure but don't do + * anything with them, discarding them in effect + * @param length The amount of bytes that is being treated this way + */ +static inline void SlSkipBytes(size_t length) +{ + for (; length != 0; length--) SlReadByte(); +} + extern char _savegame_format[8]; extern bool _do_autosave; From 7a09413a1aabc934c201c19bcae3ad03d7b801c7 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Sun, 17 May 2020 22:13:08 +0100 Subject: [PATCH 18/29] Fix: Incorrect save/load array size of Town::cargo_accepted In 11ab3c4e the number of cargo types was changed from 32 to 64. The save/load of Town::cargo_accepted was not updated, such that only half of the data structure is saved/loaded in savegame versions 199 to 218. Discard and regenerate data from all savegame versions prior to 219. --- src/saveload/afterload.cpp | 2 +- src/saveload/saveload.h | 1 + src/saveload/town_sl.cpp | 27 +++++++++++++++++---------- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index cc2a671a2f..e9c1cdb90c 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2830,7 +2830,7 @@ bool AfterLoadGame() * which is done by StartupEngines(). */ if (gcf_res != GLC_ALL_GOOD) StartupEngines(); - if (IsSavegameVersionBefore(SLV_166)) { + if (IsSavegameVersionBefore(SLV_FIX_TOWN_ACCEPTANCE)) { /* Update cargo acceptance map of towns. */ for (TileIndex t = 0; t < map_size; t++) { if (!IsTileType(t, MP_HOUSE)) continue; diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index 26462cdaa4..dcf8a41d85 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -302,6 +302,7 @@ enum SaveLoadVersion : uint16 { SLV_MULTITILE_DOCKS, ///< 216 PR#7380 Multiple docks per station. SLV_TRADING_AGE, ///< 217 PR#7780 Configurable company trading age. SLV_ENDING_YEAR, ///< 218 PR#7747 v1.10 Configurable ending year. + SLV_FIX_TOWN_ACCEPTANCE, ///< 219 PR#8157 Fix Town::cargo_accepted savegame format. SL_MAX_VERSION, ///< Highest possible saveload version }; diff --git a/src/saveload/town_sl.cpp b/src/saveload/town_sl.cpp index cbf7205d07..7e41ef6cc3 100644 --- a/src/saveload/town_sl.cpp +++ b/src/saveload/town_sl.cpp @@ -256,7 +256,7 @@ static void RealSave_Town(Town *t) SlObject(&t->cargo_accepted, GetTileMatrixDesc()); if (t->cargo_accepted.area.w != 0) { uint arr_len = t->cargo_accepted.area.w / AcceptanceMatrix::GRID * t->cargo_accepted.area.h / AcceptanceMatrix::GRID; - SlArray(t->cargo_accepted.data, arr_len, SLE_UINT32); + SlArray(t->cargo_accepted.data, arr_len, SLE_UINT64); } } @@ -288,16 +288,23 @@ static void Load_TOWN() SlErrorCorrupt("Invalid town name generator"); } - if (IsSavegameVersionBefore(SLV_166)) continue; + if (!IsSavegameVersionBefore(SLV_FIX_TOWN_ACCEPTANCE)) { + SlObject(&t->cargo_accepted, GetTileMatrixDesc()); + if (t->cargo_accepted.area.w != 0) { + uint arr_len = t->cargo_accepted.area.w / AcceptanceMatrix::GRID * t->cargo_accepted.area.h / AcceptanceMatrix::GRID; + t->cargo_accepted.data = MallocT(arr_len); + SlArray(t->cargo_accepted.data, arr_len, SLE_UINT64); - SlObject(&t->cargo_accepted, GetTileMatrixDesc()); - if (t->cargo_accepted.area.w != 0) { - uint arr_len = t->cargo_accepted.area.w / AcceptanceMatrix::GRID * t->cargo_accepted.area.h / AcceptanceMatrix::GRID; - t->cargo_accepted.data = MallocT(arr_len); - SlArray(t->cargo_accepted.data, arr_len, SLE_UINT32); - - /* Rebuild total cargo acceptance. */ - UpdateTownCargoTotal(t); + /* Rebuild total cargo acceptance. */ + UpdateTownCargoTotal(t); + } + } else if (!IsSavegameVersionBefore(SLV_166)) { + AcceptanceMatrix cargo_accepted; + SlObject(&cargo_accepted, GetTileMatrixDesc()); + if (cargo_accepted.area.w != 0) { + uint arr_len = cargo_accepted.area.w / AcceptanceMatrix::GRID * cargo_accepted.area.h / AcceptanceMatrix::GRID; + SlSkipBytes(4 * arr_len); + } } } } From 6d3c2edc599c3f74cf1aa3e69ddb6d301af62fa0 Mon Sep 17 00:00:00 2001 From: Michael Lutz Date: Sat, 11 Apr 2020 17:12:26 +0200 Subject: [PATCH 19/29] Add: [NewGRF] Industry behaviour flag to override second cargo production clamping for water industries when using smooth economy. Smooth economy is only used when the corresponding setting is enabled and the industries does not use the production callback. --- src/industry_cmd.cpp | 2 +- src/industrytype.h | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 35def46098..bd1d28ef6c 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -2677,7 +2677,7 @@ static void ChangeIndustryProduction(Industry *i, bool monthly) /* Prevent production to overflow or Oil Rig passengers to be over-"produced" */ new_prod = Clamp(new_prod, 1, 255); - if (((indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) != 0) && j == 1) { + if (((indspec->behaviour & INDUSTRYBEH_BUILT_ONWATER) != 0) && j == 1 && !(indspec->behaviour & INDUSTRYBEH_WATER_NO_CLAMP_PROD)) { new_prod = Clamp(new_prod, 0, 16); } diff --git a/src/industrytype.h b/src/industrytype.h index ec4f8f85df..8af486c210 100644 --- a/src/industrytype.h +++ b/src/industrytype.h @@ -80,6 +80,7 @@ enum IndustryBehaviour { INDUSTRYBEH_NOBUILT_MAPCREATION = 1 << 16, ///< Do not force one instance of this type to appear on map generation INDUSTRYBEH_CANCLOSE_LASTINSTANCE = 1 << 17, ///< Allow closing down the last instance of this type INDUSTRYBEH_CARGOTYPES_UNLIMITED = 1 << 18, ///< Allow produced/accepted cargoes callbacks to supply more than 2 and 3 types + INDUSTRYBEH_WATER_NO_CLAMP_PROD = 1 << 19, ///< Do not clamp production of second cargo for water industries }; DECLARE_ENUM_AS_BIT_SET(IndustryBehaviour) From ca2604c4e2cc972c2081db91a5e7b0bcdd092203 Mon Sep 17 00:00:00 2001 From: dP Date: Sun, 28 Jun 2020 19:04:55 +0300 Subject: [PATCH 20/29] Revert #8157: Redundant change --- src/saveload/afterload.cpp | 2 +- src/saveload/saveload.h | 1 - src/saveload/town_sl.cpp | 27 ++++++++++----------------- 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index e9c1cdb90c..cc2a671a2f 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2830,7 +2830,7 @@ bool AfterLoadGame() * which is done by StartupEngines(). */ if (gcf_res != GLC_ALL_GOOD) StartupEngines(); - if (IsSavegameVersionBefore(SLV_FIX_TOWN_ACCEPTANCE)) { + if (IsSavegameVersionBefore(SLV_166)) { /* Update cargo acceptance map of towns. */ for (TileIndex t = 0; t < map_size; t++) { if (!IsTileType(t, MP_HOUSE)) continue; diff --git a/src/saveload/saveload.h b/src/saveload/saveload.h index dcf8a41d85..26462cdaa4 100644 --- a/src/saveload/saveload.h +++ b/src/saveload/saveload.h @@ -302,7 +302,6 @@ enum SaveLoadVersion : uint16 { SLV_MULTITILE_DOCKS, ///< 216 PR#7380 Multiple docks per station. SLV_TRADING_AGE, ///< 217 PR#7780 Configurable company trading age. SLV_ENDING_YEAR, ///< 218 PR#7747 v1.10 Configurable ending year. - SLV_FIX_TOWN_ACCEPTANCE, ///< 219 PR#8157 Fix Town::cargo_accepted savegame format. SL_MAX_VERSION, ///< Highest possible saveload version }; diff --git a/src/saveload/town_sl.cpp b/src/saveload/town_sl.cpp index 7e41ef6cc3..cbf7205d07 100644 --- a/src/saveload/town_sl.cpp +++ b/src/saveload/town_sl.cpp @@ -256,7 +256,7 @@ static void RealSave_Town(Town *t) SlObject(&t->cargo_accepted, GetTileMatrixDesc()); if (t->cargo_accepted.area.w != 0) { uint arr_len = t->cargo_accepted.area.w / AcceptanceMatrix::GRID * t->cargo_accepted.area.h / AcceptanceMatrix::GRID; - SlArray(t->cargo_accepted.data, arr_len, SLE_UINT64); + SlArray(t->cargo_accepted.data, arr_len, SLE_UINT32); } } @@ -288,23 +288,16 @@ static void Load_TOWN() SlErrorCorrupt("Invalid town name generator"); } - if (!IsSavegameVersionBefore(SLV_FIX_TOWN_ACCEPTANCE)) { - SlObject(&t->cargo_accepted, GetTileMatrixDesc()); - if (t->cargo_accepted.area.w != 0) { - uint arr_len = t->cargo_accepted.area.w / AcceptanceMatrix::GRID * t->cargo_accepted.area.h / AcceptanceMatrix::GRID; - t->cargo_accepted.data = MallocT(arr_len); - SlArray(t->cargo_accepted.data, arr_len, SLE_UINT64); + if (IsSavegameVersionBefore(SLV_166)) continue; - /* Rebuild total cargo acceptance. */ - UpdateTownCargoTotal(t); - } - } else if (!IsSavegameVersionBefore(SLV_166)) { - AcceptanceMatrix cargo_accepted; - SlObject(&cargo_accepted, GetTileMatrixDesc()); - if (cargo_accepted.area.w != 0) { - uint arr_len = cargo_accepted.area.w / AcceptanceMatrix::GRID * cargo_accepted.area.h / AcceptanceMatrix::GRID; - SlSkipBytes(4 * arr_len); - } + SlObject(&t->cargo_accepted, GetTileMatrixDesc()); + if (t->cargo_accepted.area.w != 0) { + uint arr_len = t->cargo_accepted.area.w / AcceptanceMatrix::GRID * t->cargo_accepted.area.h / AcceptanceMatrix::GRID; + t->cargo_accepted.data = MallocT(arr_len); + SlArray(t->cargo_accepted.data, arr_len, SLE_UINT32); + + /* Rebuild total cargo acceptance. */ + UpdateTownCargoTotal(t); } } } From 380fd8cab41bce0954bcd38eba5befe7057c8fa2 Mon Sep 17 00:00:00 2001 From: dP Date: Mon, 18 May 2020 16:12:20 +0300 Subject: [PATCH 21/29] Fix: Make subsidies scan tiles for town acceptance and production instead of using desync-prone town caches --- src/subsidy.cpp | 28 ++++++++++++++++++---------- src/subsidy_base.h | 1 + 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/subsidy.cpp b/src/subsidy.cpp index e3913a2891..25651a91ef 100644 --- a/src/subsidy.cpp +++ b/src/subsidy.cpp @@ -328,20 +328,27 @@ bool FindSubsidyTownCargoRoute() const Town *src_town = Town::GetRandom(); if (src_town->cache.population < SUBSIDY_CARGO_MIN_POPULATION) return false; - CargoTypes town_cargo_produced = src_town->cargo_produced; + CargoArray town_cargo_produced = GetProductionAroundTiles(src_town->xy, 1, 1, SUBSIDY_TOWN_CARGO_RADIUS); /* Passenger subsidies are not handled here. */ - ClrBit(town_cargo_produced, CT_PASSENGERS); + town_cargo_produced[CT_PASSENGERS] = 0; + + uint8 cargo_count = 0; + for (CargoID i = 0; i < NUM_CARGO; i++) { + if (town_cargo_produced[i] > 0) cargo_count++; + } /* No cargo produced at all? */ - if (town_cargo_produced == 0) return false; + if (cargo_count == 0) return false; /* Choose a random cargo that is produced in the town. */ - uint8 cargo_number = RandomRange(CountBits(town_cargo_produced)); + uint8 cargo_number = RandomRange(cargo_count); CargoID cid; - FOR_EACH_SET_CARGO_ID(cid, town_cargo_produced) { - if (cargo_number == 0) break; - cargo_number--; + for (cid = 0; cid < NUM_CARGO; cid++) { + if (town_cargo_produced[cid] > 0) { + if (cargo_number == 0) break; + cargo_number--; + } } /* Avoid using invalid NewGRF cargoes. */ @@ -416,17 +423,18 @@ bool FindSubsidyIndustryCargoRoute() */ bool FindSubsidyCargoDestination(CargoID cid, SourceType src_type, SourceID src) { - /* Choose a random destination. Only consider towns if they can accept the cargo. */ - SourceType dst_type = (HasBit(_town_cargoes_accepted, cid) && Chance16(1, 2)) ? ST_TOWN : ST_INDUSTRY; + /* Choose a random destination. */ + SourceType dst_type = Chance16(1, 2) ? ST_TOWN : ST_INDUSTRY; SourceID dst; switch (dst_type) { case ST_TOWN: { /* Select a random town. */ const Town *dst_town = Town::GetRandom(); + CargoArray town_cargo_accepted = GetAcceptanceAroundTiles(dst_town->xy, 1, 1, SUBSIDY_TOWN_CARGO_RADIUS); /* Check if the town can accept this cargo. */ - if (!HasBit(dst_town->cargo_accepted_total, cid)) return false; + if (town_cargo_accepted[cid] >= 8) return false; dst = dst_town->index; break; diff --git a/src/subsidy_base.h b/src/subsidy_base.h index ef26f64167..ef9276433f 100644 --- a/src/subsidy_base.h +++ b/src/subsidy_base.h @@ -57,5 +57,6 @@ static const uint SUBSIDY_PAX_MIN_POPULATION = 400; ///< Min. population of to static const uint SUBSIDY_CARGO_MIN_POPULATION = 900; ///< Min. population of destination town for cargo route static const uint SUBSIDY_MAX_PCT_TRANSPORTED = 42; ///< Subsidy will be created only for towns/industries with less % transported static const uint SUBSIDY_MAX_DISTANCE = 70; ///< Max. length of subsidised route (DistanceManhattan) +static const uint SUBSIDY_TOWN_CARGO_RADIUS = 6; ///< Extent of a tile area around town center when scanning for town cargo acceptance and production (6 ~= min catchmement + min station / 2) #endif /* SUBSIDY_BASE_H */ From 7045186594d947b53312a0e72c901f3889757437 Mon Sep 17 00:00:00 2001 From: dP Date: Mon, 18 May 2020 17:32:05 +0300 Subject: [PATCH 22/29] Change #8159: Remove now unused town cargo caches without bumping the savegame version --- src/saveload/afterload.cpp | 12 ------ src/saveload/town_sl.cpp | 32 +++++++------- src/subsidy.cpp | 2 +- src/town.h | 12 ------ src/town_cmd.cpp | 86 -------------------------------------- 5 files changed, 16 insertions(+), 128 deletions(-) diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index cc2a671a2f..163ded73cd 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2830,18 +2830,6 @@ bool AfterLoadGame() * which is done by StartupEngines(). */ if (gcf_res != GLC_ALL_GOOD) StartupEngines(); - if (IsSavegameVersionBefore(SLV_166)) { - /* Update cargo acceptance map of towns. */ - for (TileIndex t = 0; t < map_size; t++) { - if (!IsTileType(t, MP_HOUSE)) continue; - Town::Get(GetTownIndex(t))->cargo_accepted.Add(t); - } - - for (Town *town : Town::Iterate()) { - UpdateTownCargoes(town); - } - } - /* The road owner of standard road stops was not properly accounted for. */ if (IsSavegameVersionBefore(SLV_172)) { for (TileIndex t = 0; t < map_size; t++) { diff --git a/src/saveload/town_sl.cpp b/src/saveload/town_sl.cpp index cbf7205d07..78765dbdaf 100644 --- a/src/saveload/town_sl.cpp +++ b/src/saveload/town_sl.cpp @@ -13,12 +13,16 @@ #include "../landscape.h" #include "../subsidy_func.h" #include "../strings_func.h" +#include "../tilematrix_type.hpp" #include "saveload.h" #include "newgrf_sl.h" #include "../safeguards.h" +/* TODO: Remove acceptance matrix from the savegame completely. */ +typedef TileMatrix AcceptanceMatrix; + /** * Rebuild all the cached variables of towns. */ @@ -48,9 +52,7 @@ void RebuildTownCaches() /* Update the population and num_house dependent values */ for (Town *town : Town::Iterate()) { UpdateTownRadius(town); - UpdateTownCargoes(town); } - UpdateTownCargoBitmap(); } /** @@ -190,8 +192,8 @@ static const SaveLoad _town_desc[] = { SLE_CONDLST(Town, psa_list, REF_STORAGE, SLV_161, SL_MAX_VERSION), - SLE_CONDVAR(Town, cargo_produced, SLE_FILE_U32 | SLE_VAR_U64, SLV_166, SLV_EXTEND_CARGOTYPES), - SLE_CONDVAR(Town, cargo_produced, SLE_UINT64, SLV_EXTEND_CARGOTYPES, SL_MAX_VERSION), + SLE_CONDNULL(4, SLV_166, SLV_EXTEND_CARGOTYPES), ///< cargo_produced, no longer in use + SLE_CONDNULL(8, SLV_EXTEND_CARGOTYPES, SL_MAX_VERSION), ///< cargo_produced, no longer in use /* reserve extra space in savegame here. (currently 30 bytes) */ SLE_CONDNULL(30, SLV_2, SL_MAX_VERSION), @@ -253,11 +255,9 @@ static void RealSave_Town(Town *t) if (IsSavegameVersionBefore(SLV_166)) return; - SlObject(&t->cargo_accepted, GetTileMatrixDesc()); - if (t->cargo_accepted.area.w != 0) { - uint arr_len = t->cargo_accepted.area.w / AcceptanceMatrix::GRID * t->cargo_accepted.area.h / AcceptanceMatrix::GRID; - SlArray(t->cargo_accepted.data, arr_len, SLE_UINT32); - } + /* Write an empty matrix to avoid bumping savegame version. */ + AcceptanceMatrix dummy; + SlObject(&dummy, GetTileMatrixDesc()); } static void Save_TOWN() @@ -290,14 +290,12 @@ static void Load_TOWN() if (IsSavegameVersionBefore(SLV_166)) continue; - SlObject(&t->cargo_accepted, GetTileMatrixDesc()); - if (t->cargo_accepted.area.w != 0) { - uint arr_len = t->cargo_accepted.area.w / AcceptanceMatrix::GRID * t->cargo_accepted.area.h / AcceptanceMatrix::GRID; - t->cargo_accepted.data = MallocT(arr_len); - SlArray(t->cargo_accepted.data, arr_len, SLE_UINT32); - - /* Rebuild total cargo acceptance. */ - UpdateTownCargoTotal(t); + /* Discard acceptance matrix to avoid bumping savegame version. */ + AcceptanceMatrix dummy; + SlObject(&dummy, GetTileMatrixDesc()); + if (dummy.area.w != 0) { + uint arr_len = dummy.area.w / AcceptanceMatrix::GRID * dummy.area.h / AcceptanceMatrix::GRID; + for (arr_len *= 4; arr_len != 0; arr_len--) SlReadByte(); } } } diff --git a/src/subsidy.cpp b/src/subsidy.cpp index 25651a91ef..0a1af3c666 100644 --- a/src/subsidy.cpp +++ b/src/subsidy.cpp @@ -434,7 +434,7 @@ bool FindSubsidyCargoDestination(CargoID cid, SourceType src_type, SourceID src) CargoArray town_cargo_accepted = GetAcceptanceAroundTiles(dst_town->xy, 1, 1, SUBSIDY_TOWN_CARGO_RADIUS); /* Check if the town can accept this cargo. */ - if (town_cargo_accepted[cid] >= 8) return false; + if (town_cargo_accepted[cid] < 8) return false; dst = dst_town->index; break; diff --git a/src/town.h b/src/town.h index af06fa03c3..3bb9e10d66 100644 --- a/src/town.h +++ b/src/town.h @@ -15,7 +15,6 @@ #include "subsidy_type.h" #include "newgrf_storage.h" #include "cargotype.h" -#include "tilematrix_type.hpp" #include template @@ -24,8 +23,6 @@ struct BuildingCounts { T class_count[HOUSE_CLASS_MAX]; }; -typedef TileMatrix AcceptanceMatrix; - static const uint CUSTOM_TOWN_NUMBER_DIFFICULTY = 4; ///< value for custom town number in difficulty settings static const uint CUSTOM_TOWN_MAX_NUMBER = 5000; ///< this is the maximum number of towns a user can specify in customisation @@ -83,10 +80,6 @@ struct Town : TownPool::PoolItem<&_town_pool> { inline byte GetPercentTransported(CargoID cid) const { return this->supplied[cid].old_act * 256 / (this->supplied[cid].old_max + 1); } - /* Cargo production and acceptance stats. */ - CargoTypes cargo_produced; ///< Bitmap of all cargoes produced by houses in this town. - AcceptanceMatrix cargo_accepted; ///< Bitmap of cargoes accepted by houses for each 4*4 map square of the town. - CargoTypes cargo_accepted_total; ///< NOSAVE: Bitmap of all cargoes accepted by houses in this town. StationList stations_near; ///< NOSAVE: List of nearby stations. uint16 time_until_rebuild; ///< time until we rebuild a house @@ -203,9 +196,6 @@ void ResetHouses(); void ClearTownHouse(Town *t, TileIndex tile); void UpdateTownMaxPass(Town *t); void UpdateTownRadius(Town *t); -void UpdateTownCargoes(Town *t); -void UpdateTownCargoTotal(Town *t); -void UpdateTownCargoBitmap(); CommandCost CheckIfAuthorityAllowsNewStation(TileIndex tile, DoCommandFlag flags); Town *ClosestTownFromTile(TileIndex tile, uint threshold); void ChangeTownRating(Town *t, int add, int max, DoCommandFlag flags); @@ -313,8 +303,6 @@ static inline uint16 TownTicksToGameTicks(uint16 ticks) { } -extern CargoTypes _town_cargoes_accepted; - RoadType GetTownRoadType(const Town *t); #endif /* TOWN_H */ diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 39dfa7db17..374601cad2 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -55,7 +55,6 @@ #include "safeguards.h" TownID _new_town_id; -CargoTypes _town_cargoes_accepted; ///< Bitmap of all cargoes accepted by houses. /* Initialize the town-pool */ TownPool _town_pool("Town"); @@ -782,85 +781,6 @@ static void ChangeTileOwner_Town(TileIndex tile, Owner old_owner, Owner new_owne /* not used */ } -/** Update the total cargo acceptance of the whole town. - * @param t The town to update. - */ -void UpdateTownCargoTotal(Town *t) -{ - t->cargo_accepted_total = 0; - - const TileArea &area = t->cargo_accepted.GetArea(); - TILE_AREA_LOOP(tile, area) { - if (TileX(tile) % AcceptanceMatrix::GRID == 0 && TileY(tile) % AcceptanceMatrix::GRID == 0) { - t->cargo_accepted_total |= t->cargo_accepted[tile]; - } - } -} - -/** - * Update accepted town cargoes around a specific tile. - * @param t The town to update. - * @param start Update the values around this tile. - * @param update_total Set to true if the total cargo acceptance should be updated. - */ -static void UpdateTownCargoes(Town *t, TileIndex start, bool update_total = true) -{ - CargoArray accepted, produced; - CargoTypes dummy = 0; - - /* Gather acceptance for all houses in an area around the start tile. - * The area is composed of the square the tile is in, extended one square in all - * directions as the coverage area of a single station is bigger than just one square. */ - TileArea area = AcceptanceMatrix::GetAreaForTile(start, 1); - TILE_AREA_LOOP(tile, area) { - if (!IsTileType(tile, MP_HOUSE) || GetTownIndex(tile) != t->index) continue; - - AddAcceptedCargo_Town(tile, accepted, &dummy); - AddProducedCargo_Town(tile, produced); - } - - /* Create bitmap of produced and accepted cargoes. */ - CargoTypes acc = 0; - for (uint cid = 0; cid < NUM_CARGO; cid++) { - if (accepted[cid] >= 8) SetBit(acc, cid); - if (produced[cid] > 0) SetBit(t->cargo_produced, cid); - } - t->cargo_accepted[start] = acc; - - if (update_total) UpdateTownCargoTotal(t); -} - -/** Update cargo acceptance for the complete town. - * @param t The town to update. - */ -void UpdateTownCargoes(Town *t) -{ - t->cargo_produced = 0; - - const TileArea &area = t->cargo_accepted.GetArea(); - if (area.tile == INVALID_TILE) return; - - /* Update acceptance for each grid square. */ - TILE_AREA_LOOP(tile, area) { - if (TileX(tile) % AcceptanceMatrix::GRID == 0 && TileY(tile) % AcceptanceMatrix::GRID == 0) { - UpdateTownCargoes(t, tile, false); - } - } - - /* Update the total acceptance. */ - UpdateTownCargoTotal(t); -} - -/** Updates the bitmap of all cargoes accepted by houses. */ -void UpdateTownCargoBitmap() -{ - _town_cargoes_accepted = 0; - - for (const Town *town : Town::Iterate()) { - _town_cargoes_accepted |= town->cargo_accepted_total; - } -} - static bool GrowTown(Town *t); static void TownTickHandler(Town *t) @@ -2588,7 +2508,6 @@ static bool BuildTownHouse(Town *t, TileIndex tile) MakeTownHouse(tile, t, construction_counter, construction_stage, house, random_bits); UpdateTownRadius(t); UpdateTownGrowthRate(t); - UpdateTownCargoes(t, tile); return true; } @@ -2673,9 +2592,6 @@ void ClearTownHouse(Town *t, TileIndex tile) RemoveNearbyStations(t, tile, hs->building_flags); UpdateTownRadius(t); - - /* Update cargo acceptance. */ - UpdateTownCargoes(t, tile); } /** @@ -3698,10 +3614,8 @@ void TownsMonthlyLoop() UpdateTownGrowth(t); UpdateTownRating(t); UpdateTownUnwanted(t); - UpdateTownCargoes(t); } - UpdateTownCargoBitmap(); } void TownsYearlyLoop() From 04c050f93ed1ea60409f53bea96a1790245851e0 Mon Sep 17 00:00:00 2001 From: Dan Villiom Podlaski Christiansen Date: Thu, 4 Jun 2020 09:48:59 +0200 Subject: [PATCH 23/29] Fix: don't use ICU on macOS --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 825ba3dcd4..675246f5ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,7 +40,9 @@ if (NOT WIN32) find_package(Fluidsynth) find_package(Freetype) find_package(Fontconfig) - find_package(ICU OPTIONAL_COMPONENTS i18n lx) + if (NOT APPLE) + find_package(ICU OPTIONAL_COMPONENTS i18n lx) + endif (NOT APPLE) find_package(XDG_basedir) endif (NOT WIN32) if (APPLE) From 0d46e20bd4ab4e66e5801b731e0d2b4cb9014ad2 Mon Sep 17 00:00:00 2001 From: Dan Villiom Podlaski Christiansen Date: Thu, 4 Jun 2020 14:38:56 +0200 Subject: [PATCH 24/29] Add: add option for forcing coloured compiler output (useful for Ninja) --- cmake/CompileFlags.cmake | 13 +++++++++++++ cmake/Options.cmake | 2 ++ 2 files changed, 15 insertions(+) diff --git a/cmake/CompileFlags.cmake b/cmake/CompileFlags.cmake index e7d470c7d3..d200b3f500 100644 --- a/cmake/CompileFlags.cmake +++ b/cmake/CompileFlags.cmake @@ -82,6 +82,19 @@ macro(compile_flags) "$<${IS_STABLE_RELEASE}:-Wno-unused-but-set-variable>" ) + # Ninja processes the output so the output from the compiler + # isn't directly to a terminal; hence, the default is + # non-coloured output. We can override this to get nicely + # coloured output, but since that might yield odd results with + # IDEs, we extract it to an option. + if (OPTION_FORCE_COLORED_OUTPUT) + if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + add_compile_options (-fdiagnostics-color=always) + elseif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang") + add_compile_options (-fcolor-diagnostics) + endif ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + endif (OPTION_FORCE_COLORED_OUTPUT) + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") include(CheckCXXCompilerFlag) check_cxx_compiler_flag("-flifetime-dse=1" LIFETIME_DSE_FOUND) diff --git a/cmake/Options.cmake b/cmake/Options.cmake index 478f1b2b24..4210c5b490 100644 --- a/cmake/Options.cmake +++ b/cmake/Options.cmake @@ -48,6 +48,8 @@ function(set_options) set(DEFAULT_OPTION_INSTALL_FHS OFF) endif (UNIX AND NOT APPLE) + option(OPTION_FORCE_COLORED_OUTPUT "Always produce ANSI-colored output (GNU/Clang only)." OFF) + option(OPTION_DEDICATED "Build dedicated server only (no GUI)" OFF) option(OPTION_INSTALL_FHS "Install with Filesstem Hierarchy Standard folders" ${DEFAULT_OPTION_INSTALL_FHS}) option(OPTION_USE_ASSERTS "Use assertions; leave enabled for nightlies, betas, and RCs" ON) From 241e3adae8d387618fb52a75273feed9830de64a Mon Sep 17 00:00:00 2001 From: Dan Villiom Podlaski Christiansen Date: Thu, 4 Jun 2020 20:44:57 +0200 Subject: [PATCH 25/29] Fix: use proper flags for suppressing warnings in Clang --- cmake/CompileFlags.cmake | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/cmake/CompileFlags.cmake b/cmake/CompileFlags.cmake index d200b3f500..6fe185df85 100644 --- a/cmake/CompileFlags.cmake +++ b/cmake/CompileFlags.cmake @@ -73,14 +73,21 @@ macro(compile_flags) -fno-strict-aliasing ) - add_compile_options( - # When we are a stable release (Release build + USE_ASSERTS not set), - # assertations are off, which trigger a lot of warnings. We disable - # these warnings for these releases. - "$<${IS_STABLE_RELEASE}:-Wno-unused-variable>" - "$<${IS_STABLE_RELEASE}:-Wno-unused-but-set-parameter>" - "$<${IS_STABLE_RELEASE}:-Wno-unused-but-set-variable>" - ) + # When we are a stable release (Release build + USE_ASSERTS not set), + # assertations are off, which trigger a lot of warnings. We disable + # these warnings for these releases. + if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + add_compile_options( + "$<${IS_STABLE_RELEASE}:-Wno-unused-variable>" + "$<${IS_STABLE_RELEASE}:-Wno-unused-but-set-parameter>" + "$<${IS_STABLE_RELEASE}:-Wno-unused-but-set-variable>" + ) + else (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") + add_compile_options( + "$<${IS_STABLE_RELEASE}:-Wno-unused-variable>" + "$<${IS_STABLE_RELEASE}:-Wno-unused-parameter>" + ) + endif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU") # Ninja processes the output so the output from the compiler # isn't directly to a terminal; hence, the default is From c593893b56f310055c39c1d3c110a0843fc5ba8e Mon Sep 17 00:00:00 2001 From: Dan Villiom Podlaski Christiansen Date: Thu, 4 Jun 2020 21:59:30 +0200 Subject: [PATCH 26/29] Fix: set Mac deployment target This silences an awful lot of warnings. --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 675246f5ee..bd2111e53f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) endif (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake") +set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9) # Use GNUInstallDirs to allow customisation # but set our own default data dir From 70905ee82e4c341cbc0efb0ddb2d9508a6806b8c Mon Sep 17 00:00:00 2001 From: Dan Villiom Podlaski Christiansen Date: Fri, 5 Jun 2020 03:42:31 +0200 Subject: [PATCH 27/29] Fix: fix building release tags I tried building a tag, and got this error: CMake Error at cmake/scripts/FindVersion.cmake:85 (string): string sub-command REGEX, mode REPLACE: regex "^[0-9.]*$" matched an empty string. --- cmake/scripts/FindVersion.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/scripts/FindVersion.cmake b/cmake/scripts/FindVersion.cmake index d48664fc89..b53f77032f 100644 --- a/cmake/scripts/FindVersion.cmake +++ b/cmake/scripts/FindVersion.cmake @@ -82,7 +82,7 @@ if (GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git") set(REV_VERSION "${TAG}") set(REV_ISTAG 1) - string(REGEX REPLACE "^[0-9.]*$" "" STABLETAG "${TAG}") + string(REGEX REPLACE "^[0-9.]+$" "" STABLETAG "${TAG}") if (NOT STABLETAG STREQUAL "") set(REV_ISSTABLETAG 1) else () From e6be8be19d5b9b2b21175bad0d8bb22c64e596a4 Mon Sep 17 00:00:00 2001 From: Dan Villiom Podlaski Christiansen Date: Fri, 5 Jun 2020 20:26:47 +0200 Subject: [PATCH 28/29] Fix: remove remainining usages of FALSE in CMake files --- cmake/FindIconv.cmake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmake/FindIconv.cmake b/cmake/FindIconv.cmake index 5185601ab7..23c7a86f91 100644 --- a/cmake/FindIconv.cmake +++ b/cmake/FindIconv.cmake @@ -58,7 +58,7 @@ elseif(CMAKE_CXX_COMPILER_LOADED) include(CheckCXXSourceCompiles) else() # If neither C nor CXX are loaded, implicit iconv makes no sense. - set(Iconv_IS_BUILT_IN FALSE) + set(Iconv_IS_BUILT_IN NO) endif() # iconv can only be provided in libc on a POSIX system. @@ -94,7 +94,7 @@ if(NOT DEFINED Iconv_IS_BUILT_IN) endif() cmake_pop_check_state() else() - set(Iconv_IS_BUILT_IN FALSE) + set(Iconv_IS_BUILT_IN NO) endif() endif() From 7fd7b515933b85a0b78da4e5e30db957f90aaec5 Mon Sep 17 00:00:00 2001 From: Dan Villiom Podlaski Christiansen Date: Thu, 18 Jun 2020 14:24:29 +0200 Subject: [PATCH 29/29] Fix: don't search for SDL, etc., on macOS --- CMakeLists.txt | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bd2111e53f..06cd71c3a2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,27 +32,27 @@ find_package(ZLIB) find_package(LibLZMA) find_package(LZO) find_package(PNG) -if (NOT WIN32) - find_package(SDL2) - if (NOT SDL2_FOUND) - find_package(SDL) - endif( NOT SDL2_FOUND) - find_package(Allegro) - find_package(Fluidsynth) - find_package(Freetype) - find_package(Fontconfig) - if (NOT APPLE) - find_package(ICU OPTIONAL_COMPONENTS i18n lx) - endif (NOT APPLE) - find_package(XDG_basedir) -endif (NOT WIN32) -if (APPLE) - find_package(Iconv) - find_library(AUDIOTOOLBOX_LIBRARY AudioToolbox) - find_library(AUDIOUNIT_LIBRARY AudioUnit) - find_library(COCOA_LIBRARY Cocoa) -endif (APPLE) +if (NOT WIN32) + find_package(Allegro) + if (NOT APPLE) + find_package(SDL2) + if (NOT SDL2_FOUND) + find_package(SDL) + endif( NOT SDL2_FOUND) + find_package(Fluidsynth) + find_package(Freetype) + find_package(Fontconfig) + find_package(ICU OPTIONAL_COMPONENTS i18n lx) + find_package(XDG_basedir) + else (NOT APPLE) + find_package(Iconv) + + find_library(AUDIOTOOLBOX_LIBRARY AudioToolbox) + find_library(AUDIOUNIT_LIBRARY AudioUnit) + find_library(COCOA_LIBRARY Cocoa) + endif (NOT APPLE) +endif (NOT WIN32) if (MSVC) find_package(Editbin REQUIRED)