From dcb2571888f58aee2e5aa3512f36707a3adde472 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sat, 12 Jan 2019 22:27:19 +0100 Subject: [PATCH 01/56] Add: Warn players that company passwords are not truly secure --- src/lang/english.txt | 1 + src/misc_gui.cpp | 20 ++++++++++++++++++++ src/network/network_gui.cpp | 13 ++++++++++++- src/script/api/game/game_window.hpp.sq | 3 +++ src/script/api/script_window.hpp | 3 +++ src/textbuf_gui.h | 1 + src/widgets/misc_widget.h | 12 +++++++----- src/widgets/network_widget.h | 1 + 8 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index 61fa2a91ba..4f648a4825 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -265,6 +265,7 @@ STR_SHOW_HIDDEN_ENGINES_VEHICLE_AIRCRAFT_TOOLTIP :{BLACK}By enabl STR_BUTTON_DEFAULT :{BLACK}Default STR_BUTTON_CANCEL :{BLACK}Cancel STR_BUTTON_OK :{BLACK}OK +STR_WARNING_PASSWORD_SECURITY :{YELLOW}Warning: Server administrators may be{}able to read any text entered here. # On screen keyboard window STR_OSK_KEYBOARD_LAYOUT :`1234567890-=\qwertyuiop[]asdfghjkl;' zxcvbnm,./ . diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 4c7557c36f..8a86f0c578 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -981,6 +981,23 @@ struct QueryStringWindow : public Window resize->width = 0; size->width = 0; } + + if (widget == WID_QS_WARNINGBOX && (this->flags & QSF_PASSWORD) == 0) { + /* We don't want this widget to show! */ + fill->width = 0; + resize->width = 0; + size->width = 0; + } + if (widget == WID_QS_WARNING) { + *size = GetStringBoundingBox(STR_WARNING_PASSWORD_SECURITY); + } + } + + virtual void DrawWidget(const Rect &r, int widget) const + { + if (widget != WID_QS_WARNING) return; + + DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_WARNING_PASSWORD_SECURITY, TC_FROMSTRING, SA_CENTER); } void SetStringParameters(int widget) const override @@ -1037,6 +1054,9 @@ static const NWidgetPart _nested_query_string_widgets[] = { NWidget(WWT_PANEL, COLOUR_GREY), NWidget(WWT_EDITBOX, COLOUR_GREY, WID_QS_TEXT), SetMinimalSize(256, 12), SetFill(1, 1), SetPadding(2, 2, 2, 2), EndContainer(), + NWidget(WWT_PANEL, COLOUR_GREY, WID_QS_WARNINGBOX), + NWidget(WWT_LABEL, COLOUR_GREY, WID_QS_WARNING), SetPadding(WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM, WD_FRAMETEXT_LEFT), SetFill(0, 1), + EndContainer(), NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_DEFAULT), SetMinimalSize(87, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_DEFAULT, STR_NULL), NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_CANCEL), SetMinimalSize(86, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_CANCEL, STR_NULL), diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 29bc88959a..42fea015c0 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -2157,7 +2157,7 @@ void ShowNetworkNeedPassword(NetworkPasswordType npt) case NETWORK_GAME_PASSWORD: caption = STR_NETWORK_NEED_GAME_PASSWORD_CAPTION; break; case NETWORK_COMPANY_PASSWORD: caption = STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION; break; } - ShowQueryString(STR_EMPTY, caption, NETWORK_PASSWORD_LENGTH, w, CS_ALPHANUMERAL, QSF_NONE); + ShowQueryString(STR_EMPTY, caption, NETWORK_PASSWORD_LENGTH, w, CS_ALPHANUMERAL, QSF_PASSWORD); } struct NetworkCompanyPasswordWindow : public Window { @@ -2174,6 +2174,14 @@ struct NetworkCompanyPasswordWindow : public Window { this->SetFocusedWidget(WID_NCP_PASSWORD); } + virtual void DrawWidget(const Rect &r, int widget) const + { + if (widget != WID_NCP_WARNING) return; + + DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM, + STR_WARNING_PASSWORD_SECURITY, TC_FROMSTRING, SA_CENTER); + } + void OnOk() { if (this->IsWidgetLowered(WID_NCP_SAVE_AS_DEFAULT_PASSWORD)) { @@ -2220,6 +2228,9 @@ static const NWidgetPart _nested_network_company_password_window_widgets[] = { EndContainer(), EndContainer(), EndContainer(), + NWidget(WWT_PANEL, COLOUR_GREY, WID_NCP_WARNING), + NWidget(WWT_LABEL, COLOUR_GREY), SetFill(0, 1), SetPadding(2, 2, 2, 2), SetDataTip(STR_WARNING_PASSWORD_SECURITY, STR_NULL), + EndContainer(), NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NCP_CANCEL), SetFill(1, 0), SetDataTip(STR_BUTTON_CANCEL, STR_COMPANY_PASSWORD_CANCEL), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NCP_OK), SetFill(1, 0), SetDataTip(STR_BUTTON_OK, STR_COMPANY_PASSWORD_OK), diff --git a/src/script/api/game/game_window.hpp.sq b/src/script/api/game/game_window.hpp.sq index ce2b37bb53..90fd2f5ac2 100644 --- a/src/script/api/game/game_window.hpp.sq +++ b/src/script/api/game/game_window.hpp.sq @@ -636,6 +636,8 @@ void SQGSWindow_Register(Squirrel *engine) SQGSWindow.DefSQConst(engine, ScriptWindow::WID_A_WEBSITE, "WID_A_WEBSITE"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QS_CAPTION, "WID_QS_CAPTION"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QS_TEXT, "WID_QS_TEXT"); + SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QS_WARNING, "WID_QS_WARNING"); + SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QS_WARNINGBOX, "WID_QS_WARNINGBOX"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QS_DEFAULT, "WID_QS_DEFAULT"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QS_CANCEL, "WID_QS_CANCEL"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QS_OK, "WID_QS_OK"); @@ -780,6 +782,7 @@ void SQGSWindow_Register(Squirrel *engine) SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NCP_LABEL, "WID_NCP_LABEL"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NCP_PASSWORD, "WID_NCP_PASSWORD"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NCP_SAVE_AS_DEFAULT_PASSWORD, "WID_NCP_SAVE_AS_DEFAULT_PASSWORD"); + SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NCP_WARNING, "WID_NCP_WARNING"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NCP_CANCEL, "WID_NCP_CANCEL"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NCP_OK, "WID_NCP_OK"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_NGRFI_CAPTION, "WID_NGRFI_CAPTION"); diff --git a/src/script/api/script_window.hpp b/src/script/api/script_window.hpp index fa584693af..4275fba542 100644 --- a/src/script/api/script_window.hpp +++ b/src/script/api/script_window.hpp @@ -1598,6 +1598,8 @@ public: enum QueryStringWidgets { WID_QS_CAPTION = ::WID_QS_CAPTION, ///< Caption of the window. WID_QS_TEXT = ::WID_QS_TEXT, ///< Text of the query. + WID_QS_WARNING = ::WID_QS_WARNING, ///< Warning label about password security + WID_QS_WARNINGBOX = ::WID_QS_WARNINGBOX, ///< Container for warning label WID_QS_DEFAULT = ::WID_QS_DEFAULT, ///< Default button. WID_QS_CANCEL = ::WID_QS_CANCEL, ///< Cancel button. WID_QS_OK = ::WID_QS_OK, ///< OK button. @@ -1817,6 +1819,7 @@ public: WID_NCP_LABEL = ::WID_NCP_LABEL, ///< Label in front of the password field. WID_NCP_PASSWORD = ::WID_NCP_PASSWORD, ///< Input field for the password. WID_NCP_SAVE_AS_DEFAULT_PASSWORD = ::WID_NCP_SAVE_AS_DEFAULT_PASSWORD, ///< Toggle 'button' for saving the current password as default password. + WID_NCP_WARNING = ::WID_NCP_WARNING, ///< Warning text about password security WID_NCP_CANCEL = ::WID_NCP_CANCEL, ///< Close the window without changing anything. WID_NCP_OK = ::WID_NCP_OK, ///< Safe the password etc. }; diff --git a/src/textbuf_gui.h b/src/textbuf_gui.h index ec134c11c6..e8f5159f94 100644 --- a/src/textbuf_gui.h +++ b/src/textbuf_gui.h @@ -22,6 +22,7 @@ enum QueryStringFlags { QSF_ACCEPT_UNCHANGED = 0x01, ///< return success even when the text didn't change QSF_ENABLE_DEFAULT = 0x02, ///< enable the 'Default' button ("\0" is returned) QSF_LEN_IN_CHARS = 0x04, ///< the length of the string is counted in characters + QSF_PASSWORD = 0x08, ///< password entry box, show warning about password security }; DECLARE_ENUM_AS_BIT_SET(QueryStringFlags) diff --git a/src/widgets/misc_widget.h b/src/widgets/misc_widget.h index a6dd081a9d..9fbd9f2f1e 100644 --- a/src/widgets/misc_widget.h +++ b/src/widgets/misc_widget.h @@ -30,11 +30,13 @@ enum AboutWidgets { /** Widgets of the #QueryStringWindow class. */ enum QueryStringWidgets { - WID_QS_CAPTION, ///< Caption of the window. - WID_QS_TEXT, ///< Text of the query. - WID_QS_DEFAULT, ///< Default button. - WID_QS_CANCEL, ///< Cancel button. - WID_QS_OK, ///< OK button. + WID_QS_CAPTION, ///< Caption of the window. + WID_QS_TEXT, ///< Text of the query. + WID_QS_WARNING, ///< Warning label about password security + WID_QS_WARNINGBOX, ///< Container for warning label + WID_QS_DEFAULT, ///< Default button. + WID_QS_CANCEL, ///< Cancel button. + WID_QS_OK, ///< OK button. }; /** Widgets of the #QueryWindow class. */ diff --git a/src/widgets/network_widget.h b/src/widgets/network_widget.h index f5773b8ea8..4cb5cc92c2 100644 --- a/src/widgets/network_widget.h +++ b/src/widgets/network_widget.h @@ -122,6 +122,7 @@ enum NetworkCompanyPasswordWidgets { WID_NCP_LABEL, ///< Label in front of the password field. WID_NCP_PASSWORD, ///< Input field for the password. WID_NCP_SAVE_AS_DEFAULT_PASSWORD, ///< Toggle 'button' for saving the current password as default password. + WID_NCP_WARNING, ///< Warning text about password security WID_NCP_CANCEL, ///< Close the window without changing anything. WID_NCP_OK, ///< Safe the password etc. }; From 08284e005d129ffefa7e6f54a44b514a541e288d Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sun, 31 Mar 2019 16:08:00 +0200 Subject: [PATCH 02/56] Fix: Automatic line breaking of the warning --- src/company_gui.cpp | 2 +- src/lang/english.txt | 2 +- src/misc_gui.cpp | 36 ++++++++++++++++++-------- src/script/api/game/game_window.hpp.sq | 1 - src/script/api/script_window.hpp | 1 - src/widgets/misc_widget.h | 1 - 6 files changed, 27 insertions(+), 16 deletions(-) diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 8891393e69..b36ab959e3 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -2602,7 +2602,7 @@ struct CompanyWindow : Window MarkWholeScreenDirty(); } else if (NetworkCompanyIsPassworded(company)) { /* ask for the password */ - ShowQueryString(STR_EMPTY, STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION, NETWORK_PASSWORD_LENGTH, this, CS_ALPHANUMERAL, QSF_NONE); + ShowQueryString(STR_EMPTY, STR_NETWORK_NEED_COMPANY_PASSWORD_CAPTION, NETWORK_PASSWORD_LENGTH, this, CS_ALPHANUMERAL, QSF_PASSWORD); } else { /* just send the join command */ NetworkClientRequestMove(company); diff --git a/src/lang/english.txt b/src/lang/english.txt index 4f648a4825..fc50711692 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -265,7 +265,7 @@ STR_SHOW_HIDDEN_ENGINES_VEHICLE_AIRCRAFT_TOOLTIP :{BLACK}By enabl STR_BUTTON_DEFAULT :{BLACK}Default STR_BUTTON_CANCEL :{BLACK}Cancel STR_BUTTON_OK :{BLACK}OK -STR_WARNING_PASSWORD_SECURITY :{YELLOW}Warning: Server administrators may be{}able to read any text entered here. +STR_WARNING_PASSWORD_SECURITY :{YELLOW}Warning: Server administrators may be able to read any text entered here. # On screen keyboard window STR_OSK_KEYBOARD_LAYOUT :`1234567890-=\qwertyuiop[]asdfghjkl;' zxcvbnm,./ . diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 8a86f0c578..702d5b7ec5 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -941,6 +941,7 @@ struct QueryStringWindow : public Window { QueryString editbox; ///< Editbox. QueryStringFlags flags; ///< Flags controlling behaviour of the window. + Dimension warning_size; ///< How much space to use for the warning text QueryStringWindow(StringID str, StringID caption, uint max_bytes, uint max_chars, WindowDesc *desc, Window *parent, CharSetFilter afilter, QueryStringFlags flags) : Window(desc), editbox(max_bytes, max_chars) @@ -967,12 +968,29 @@ struct QueryStringWindow : public Window this->flags = flags; this->InitNested(WN_QUERY_STRING); + this->UpdateWarningStringSize(); this->parent = parent; this->SetFocusedWidget(WID_QS_TEXT); } + void UpdateWarningStringSize() + { + NWidgetBase *text_wid = this->GetWidget(WID_QS_WARNING); + + if (this->flags & QSF_PASSWORD) { + assert(this->nested_root->smallest_x > 0); + this->warning_size.width = this->nested_root->current_x - (WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT); + this->warning_size.height = GetStringHeight(STR_WARNING_PASSWORD_SECURITY, this->warning_size.width); + this->warning_size.height += WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM; + } else { + this->warning_size = Dimension{ 0, 0 }; + } + + this->ReInit(); + } + void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override { if (widget == WID_QS_DEFAULT && (this->flags & QSF_ENABLE_DEFAULT) == 0) { @@ -982,14 +1000,8 @@ struct QueryStringWindow : public Window size->width = 0; } - if (widget == WID_QS_WARNINGBOX && (this->flags & QSF_PASSWORD) == 0) { - /* We don't want this widget to show! */ - fill->width = 0; - resize->width = 0; - size->width = 0; - } if (widget == WID_QS_WARNING) { - *size = GetStringBoundingBox(STR_WARNING_PASSWORD_SECURITY); + *size = this->warning_size; } } @@ -997,7 +1009,11 @@ struct QueryStringWindow : public Window { if (widget != WID_QS_WARNING) return; - DrawStringMultiLine(r.left, r.right, r.top, r.bottom, STR_WARNING_PASSWORD_SECURITY, TC_FROMSTRING, SA_CENTER); + if (this->flags & QSF_PASSWORD) { + DrawStringMultiLine(r.left + WD_FRAMERECT_LEFT + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT - WD_FRAMERECT_RIGHT, + r.top + WD_FRAMERECT_TOP + WD_FRAMETEXT_TOP, r.bottom - WD_FRAMERECT_BOTTOM - WD_FRAMETEXT_BOTTOM, + STR_WARNING_PASSWORD_SECURITY, TC_FROMSTRING, SA_CENTER); + } } void SetStringParameters(int widget) const override @@ -1054,9 +1070,7 @@ static const NWidgetPart _nested_query_string_widgets[] = { NWidget(WWT_PANEL, COLOUR_GREY), NWidget(WWT_EDITBOX, COLOUR_GREY, WID_QS_TEXT), SetMinimalSize(256, 12), SetFill(1, 1), SetPadding(2, 2, 2, 2), EndContainer(), - NWidget(WWT_PANEL, COLOUR_GREY, WID_QS_WARNINGBOX), - NWidget(WWT_LABEL, COLOUR_GREY, WID_QS_WARNING), SetPadding(WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM, WD_FRAMETEXT_LEFT), SetFill(0, 1), - EndContainer(), + NWidget(WWT_PANEL, COLOUR_GREY, WID_QS_WARNING), EndContainer(), NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_DEFAULT), SetMinimalSize(87, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_DEFAULT, STR_NULL), NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_QS_CANCEL), SetMinimalSize(86, 12), SetFill(1, 1), SetDataTip(STR_BUTTON_CANCEL, STR_NULL), diff --git a/src/script/api/game/game_window.hpp.sq b/src/script/api/game/game_window.hpp.sq index 90fd2f5ac2..162c0bf0c1 100644 --- a/src/script/api/game/game_window.hpp.sq +++ b/src/script/api/game/game_window.hpp.sq @@ -637,7 +637,6 @@ void SQGSWindow_Register(Squirrel *engine) SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QS_CAPTION, "WID_QS_CAPTION"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QS_TEXT, "WID_QS_TEXT"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QS_WARNING, "WID_QS_WARNING"); - SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QS_WARNINGBOX, "WID_QS_WARNINGBOX"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QS_DEFAULT, "WID_QS_DEFAULT"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QS_CANCEL, "WID_QS_CANCEL"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_QS_OK, "WID_QS_OK"); diff --git a/src/script/api/script_window.hpp b/src/script/api/script_window.hpp index 4275fba542..a56307cb0e 100644 --- a/src/script/api/script_window.hpp +++ b/src/script/api/script_window.hpp @@ -1599,7 +1599,6 @@ public: WID_QS_CAPTION = ::WID_QS_CAPTION, ///< Caption of the window. WID_QS_TEXT = ::WID_QS_TEXT, ///< Text of the query. WID_QS_WARNING = ::WID_QS_WARNING, ///< Warning label about password security - WID_QS_WARNINGBOX = ::WID_QS_WARNINGBOX, ///< Container for warning label WID_QS_DEFAULT = ::WID_QS_DEFAULT, ///< Default button. WID_QS_CANCEL = ::WID_QS_CANCEL, ///< Cancel button. WID_QS_OK = ::WID_QS_OK, ///< OK button. diff --git a/src/widgets/misc_widget.h b/src/widgets/misc_widget.h index 9fbd9f2f1e..9f6a7e5f5e 100644 --- a/src/widgets/misc_widget.h +++ b/src/widgets/misc_widget.h @@ -33,7 +33,6 @@ enum QueryStringWidgets { WID_QS_CAPTION, ///< Caption of the window. WID_QS_TEXT, ///< Text of the query. WID_QS_WARNING, ///< Warning label about password security - WID_QS_WARNINGBOX, ///< Container for warning label WID_QS_DEFAULT, ///< Default button. WID_QS_CANCEL, ///< Cancel button. WID_QS_OK, ///< OK button. From a64bd6e22c747f082f6167926b50e5eb16f4fdf0 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sun, 31 Mar 2019 16:15:09 +0200 Subject: [PATCH 03/56] Fix: Also breaking for warning text in set company password --- src/misc_gui.cpp | 2 -- src/network/network_gui.cpp | 26 ++++++++++++++++++++++---- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 702d5b7ec5..0566fffc3d 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -977,8 +977,6 @@ struct QueryStringWindow : public Window void UpdateWarningStringSize() { - NWidgetBase *text_wid = this->GetWidget(WID_QS_WARNING); - if (this->flags & QSF_PASSWORD) { assert(this->nested_root->smallest_x > 0); this->warning_size.width = this->nested_root->current_x - (WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT); diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index 42fea015c0..d39b61dbf0 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -2162,10 +2162,12 @@ void ShowNetworkNeedPassword(NetworkPasswordType npt) struct NetworkCompanyPasswordWindow : public Window { QueryString password_editbox; ///< Password editbox. + Dimension warning_size; ///< How much space to use for the warning text NetworkCompanyPasswordWindow(WindowDesc *desc, Window *parent) : Window(desc), password_editbox(lengthof(_settings_client.network.default_company_pass)) { this->InitNested(0); + this->UpdateWarningStringSize(); this->parent = parent; this->querystrings[WID_NCP_PASSWORD] = &this->password_editbox; @@ -2174,11 +2176,29 @@ struct NetworkCompanyPasswordWindow : public Window { this->SetFocusedWidget(WID_NCP_PASSWORD); } + void UpdateWarningStringSize() + { + assert(this->nested_root->smallest_x > 0); + this->warning_size.width = this->nested_root->current_x - (WD_FRAMETEXT_LEFT + WD_FRAMETEXT_RIGHT + WD_FRAMERECT_LEFT + WD_FRAMERECT_RIGHT); + this->warning_size.height = GetStringHeight(STR_WARNING_PASSWORD_SECURITY, this->warning_size.width); + this->warning_size.height += WD_FRAMETEXT_TOP + WD_FRAMETEXT_BOTTOM + WD_FRAMERECT_TOP + WD_FRAMERECT_BOTTOM; + + this->ReInit(); + } + + void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override + { + if (widget == WID_NCP_WARNING) { + *size = this->warning_size; + } + } + virtual void DrawWidget(const Rect &r, int widget) const { if (widget != WID_NCP_WARNING) return; - DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM, + DrawStringMultiLine(r.left + WD_FRAMETEXT_LEFT, r.right - WD_FRAMETEXT_RIGHT, + r.top + WD_FRAMERECT_TOP, r.bottom - WD_FRAMERECT_BOTTOM, STR_WARNING_PASSWORD_SECURITY, TC_FROMSTRING, SA_CENTER); } @@ -2228,9 +2248,7 @@ static const NWidgetPart _nested_network_company_password_window_widgets[] = { EndContainer(), EndContainer(), EndContainer(), - NWidget(WWT_PANEL, COLOUR_GREY, WID_NCP_WARNING), - NWidget(WWT_LABEL, COLOUR_GREY), SetFill(0, 1), SetPadding(2, 2, 2, 2), SetDataTip(STR_WARNING_PASSWORD_SECURITY, STR_NULL), - EndContainer(), + NWidget(WWT_PANEL, COLOUR_GREY, WID_NCP_WARNING), EndContainer(), NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NCP_CANCEL), SetFill(1, 0), SetDataTip(STR_BUTTON_CANCEL, STR_COMPANY_PASSWORD_CANCEL), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_NCP_OK), SetFill(1, 0), SetDataTip(STR_BUTTON_OK, STR_COMPANY_PASSWORD_OK), From dd35a437039b48c384057e1d3cac18681497f58e Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sun, 31 Mar 2019 16:21:55 +0200 Subject: [PATCH 04/56] Codechange: Revert unnecessary indentation change --- src/widgets/misc_widget.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/widgets/misc_widget.h b/src/widgets/misc_widget.h index 9f6a7e5f5e..806f889bbf 100644 --- a/src/widgets/misc_widget.h +++ b/src/widgets/misc_widget.h @@ -30,12 +30,12 @@ enum AboutWidgets { /** Widgets of the #QueryStringWindow class. */ enum QueryStringWidgets { - WID_QS_CAPTION, ///< Caption of the window. - WID_QS_TEXT, ///< Text of the query. - WID_QS_WARNING, ///< Warning label about password security - WID_QS_DEFAULT, ///< Default button. - WID_QS_CANCEL, ///< Cancel button. - WID_QS_OK, ///< OK button. + WID_QS_CAPTION, ///< Caption of the window. + WID_QS_TEXT, ///< Text of the query. + WID_QS_WARNING, ///< Warning label about password security + WID_QS_DEFAULT, ///< Default button. + WID_QS_CANCEL, ///< Cancel button. + WID_QS_OK, ///< OK button. }; /** Widgets of the #QueryWindow class. */ From 62dec9f174aaf003a114a55600bc4f201d2841b9 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Tue, 23 Apr 2019 21:22:15 +0200 Subject: [PATCH 05/56] Fix: Scale all min size and padding by UI scale --- src/widget.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/widget.cpp b/src/widget.cpp index dcdf75c17b..71c874a529 100644 --- a/src/widget.cpp +++ b/src/widget.cpp @@ -2634,7 +2634,7 @@ static int MakeNWidget(const NWidgetPart *parts, int count, NWidgetBase **dest, NWidgetResizeBase *nwrb = dynamic_cast(*dest); if (nwrb != nullptr) { assert(parts->u.xy.x >= 0 && parts->u.xy.y >= 0); - nwrb->SetMinimalSize(parts->u.xy.x, parts->u.xy.y); + nwrb->SetMinimalSize(ScaleGUITrad(parts->u.xy.x), ScaleGUITrad(parts->u.xy.y)); } break; } @@ -2664,7 +2664,7 @@ static int MakeNWidget(const NWidgetPart *parts, int count, NWidgetBase **dest, } case WPT_PADDING: - if (*dest != nullptr) (*dest)->SetPadding(parts->u.padding.top, parts->u.padding.right, parts->u.padding.bottom, parts->u.padding.left); + if (*dest != nullptr) (*dest)->SetPadding(ScaleGUITrad(parts->u.padding.top), ScaleGUITrad(parts->u.padding.right), ScaleGUITrad(parts->u.padding.bottom), ScaleGUITrad(parts->u.padding.left)); break; case WPT_PIPSPACE: { From 2c67af391bfc3e8dea75a7832ae0588d6b455d28 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Tue, 23 Apr 2019 21:25:40 +0200 Subject: [PATCH 06/56] Fix: Scale news ticker scroll speed by UI scale --- src/statusbar_gui.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/statusbar_gui.cpp b/src/statusbar_gui.cpp index 548fad5f1c..a3a9e2c424 100644 --- a/src/statusbar_gui.cpp +++ b/src/statusbar_gui.cpp @@ -27,6 +27,7 @@ #include "toolbar_gui.h" #include "core/geometry_func.hpp" #include "guitimer_func.h" +#include "zoom_func.h" #include "widgets/statusbar_widget.h" @@ -166,7 +167,7 @@ struct StatusBarWindow : Window { DrawString(r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, STR_STATUSBAR_PAUSED, TC_FROMSTRING, SA_HOR_CENTER); } else if (this->ticker_scroll < TICKER_STOP && FindWindowById(WC_NEWS_WINDOW, 0) == nullptr && _statusbar_news_item != nullptr && _statusbar_news_item->string_id != 0) { /* Draw the scrolling news text */ - if (!DrawScrollingStatusText(_statusbar_news_item, this->ticker_scroll, r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom)) { + if (!DrawScrollingStatusText(_statusbar_news_item, ScaleGUITrad(this->ticker_scroll), r.left + WD_FRAMERECT_LEFT, r.right - WD_FRAMERECT_RIGHT, r.top + WD_FRAMERECT_TOP, r.bottom)) { InvalidateWindowData(WC_STATUS_BAR, 0, SBI_NEWS_DELETED); if (Company::IsValidID(_local_company)) { /* This is the default text */ From 58609e8fa699a82b6619021119bce5e550eb6188 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Tue, 23 Apr 2019 21:39:41 +0200 Subject: [PATCH 07/56] Fix: Manager name in company news was being clipped --- src/news_gui.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/news_gui.cpp b/src/news_gui.cpp index 7aee32cacb..be83b374c6 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -331,6 +331,11 @@ struct NewsWindow : Window { *size = maxdim(*size, GetSpriteSize(SPR_GRADIENT)); break; + case WID_N_MGR_NAME: + SetDParamStr(0, static_cast(this->ni->free_data)->president_name); + str = STR_JUST_RAW_STRING; + break; + case WID_N_MESSAGE: CopyInDParam(0, this->ni->params, lengthof(this->ni->params)); str = this->ni->string_id; From 37daf430379610536b5725fabd07847907499d41 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Tue, 23 Apr 2019 22:55:27 +0200 Subject: [PATCH 08/56] Change: Zoom title game by UI zoom level --- src/main_gui.cpp | 10 ++++++++++ src/openttd.cpp | 2 ++ src/settings_gui.cpp | 2 ++ src/viewport_func.h | 1 + 4 files changed, 15 insertions(+) diff --git a/src/main_gui.cpp b/src/main_gui.cpp index d4559c216e..b6cf616d17 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -199,6 +199,16 @@ void ZoomInOrOutToCursorWindow(bool in, Window *w) } } +void FixTitleGameZoom() +{ + if (_game_mode != GM_MENU) return; + + ViewPort *vp = FindWindowByClass(WC_MAIN_WINDOW)->viewport; + vp->zoom = _gui_zoom; + vp->virtual_width = ScaleByZoom(vp->width, vp->zoom); + vp->virtual_height = ScaleByZoom(vp->height, vp->zoom); +} + static const struct NWidgetPart _nested_main_window_widgets[] = { NWidget(NWID_VIEWPORT, INVALID_COLOUR, WID_M_VIEWPORT), SetResize(1, 1), }; diff --git a/src/openttd.cpp b/src/openttd.cpp index 4f629c1184..b9bc7c9854 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -62,6 +62,7 @@ #include "town.h" #include "subsidy_func.h" #include "gfx_layout.h" +#include "viewport_func.h" #include "viewport_sprite_sorter.h" #include "framerate_type.h" @@ -336,6 +337,7 @@ static void LoadIntroGame(bool load_newgrfs = true) SetLocalCompany(COMPANY_FIRST); } + FixTitleGameZoom(); _pause_mode = PM_UNPAUSED; _cursor.fix_at = false; diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index f4c7e466c4..a6993cbf6a 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -37,6 +37,7 @@ #include "stringfilter_type.h" #include "querystring_gui.h" #include "fontcache.h" +#include "zoom_func.h" #include @@ -542,6 +543,7 @@ struct GameOptionsWindow : Window { _gui_zoom = (ZoomLevel)(ZOOM_LVL_OUT_4X - index); UpdateCursorSize(); UpdateAllVirtCoords(); + FixTitleGameZoom(); ReInitAllWindows(); break; diff --git a/src/viewport_func.h b/src/viewport_func.h index 49ad4b2e83..9bfb428900 100644 --- a/src/viewport_func.h +++ b/src/viewport_func.h @@ -34,6 +34,7 @@ void MarkAllViewportsDirty(int left, int top, int right, int bottom); bool DoZoomInOutWindow(ZoomStateChange how, Window *w); void ZoomInOrOutToCursorWindow(bool in, Window * w); Point GetTileZoomCenterWindow(bool in, Window * w); +void FixTitleGameZoom(); void HandleZoomMessage(Window *w, const ViewPort *vp, byte widget_zoom_in, byte widget_zoom_out); /** From b6733edd172cb8488f81245addf613152f8a8015 Mon Sep 17 00:00:00 2001 From: peter1138 Date: Fri, 22 Feb 2019 18:14:06 +0000 Subject: [PATCH 09/56] Feature: Add coverage area display for existing stations. --- src/lang/english.txt | 2 + src/script/api/game/game_window.hpp.sq | 1 + src/script/api/script_window.hpp | 1 + src/settings.cpp | 1 + src/station_gui.cpp | 16 ++++++ src/viewport.cpp | 77 +++++++++++++++++++++++++- src/viewport_func.h | 4 ++ src/widgets/station_widget.h | 1 + 8 files changed, 102 insertions(+), 1 deletion(-) diff --git a/src/lang/english.txt b/src/lang/english.txt index fc50711692..83a28d8cdc 100644 --- a/src/lang/english.txt +++ b/src/lang/english.txt @@ -237,6 +237,8 @@ STR_TOOLTIP_FILTER_CRITERIA :{BLACK}Select f STR_BUTTON_SORT_BY :{BLACK}Sort by STR_BUTTON_LOCATION :{BLACK}Location STR_BUTTON_RENAME :{BLACK}Rename +STR_BUTTON_CATCHMENT :{BLACK}Coverage +STR_TOOLTIP_CATCHMENT :{BLACK}Toggle coverage area display STR_TOOLTIP_CLOSE_WINDOW :{BLACK}Close window STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS :{BLACK}Window title - drag this to move window diff --git a/src/script/api/game/game_window.hpp.sq b/src/script/api/game/game_window.hpp.sq index 162c0bf0c1..d1966e3d8d 100644 --- a/src/script/api/game/game_window.hpp.sq +++ b/src/script/api/game/game_window.hpp.sq @@ -1117,6 +1117,7 @@ void SQGSWindow_Register(Squirrel *engine) SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SV_ROADVEHS, "WID_SV_ROADVEHS"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SV_SHIPS, "WID_SV_SHIPS"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SV_PLANES, "WID_SV_PLANES"); + SQGSWindow.DefSQConst(engine, ScriptWindow::WID_SV_CATCHMENT, "WID_SV_CATCHMENT"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_STL_CAPTION, "WID_STL_CAPTION"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_STL_LIST, "WID_STL_LIST"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_STL_SCROLLBAR, "WID_STL_SCROLLBAR"); diff --git a/src/script/api/script_window.hpp b/src/script/api/script_window.hpp index a56307cb0e..8c133e9983 100644 --- a/src/script/api/script_window.hpp +++ b/src/script/api/script_window.hpp @@ -2289,6 +2289,7 @@ public: WID_SV_ROADVEHS = ::WID_SV_ROADVEHS, ///< List of scheduled road vehs button. WID_SV_SHIPS = ::WID_SV_SHIPS, ///< List of scheduled ships button. WID_SV_PLANES = ::WID_SV_PLANES, ///< List of scheduled planes button. + WID_SV_CATCHMENT = ::WID_SV_CATCHMENT, ///< Toggle catchment area highlight. }; /** Widgets of the #CompanyStationsWindow class. */ diff --git a/src/settings.cpp b/src/settings.cpp index b111f87282..5c0dc4a984 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -1320,6 +1320,7 @@ static bool ChangeMaxHeightLevel(int32 p1) static bool StationCatchmentChanged(int32 p1) { Station::RecomputeCatchmentForAll(); + MarkWholeScreenDirty(); return true; } diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 4e6b94caf6..1cc6a126ff 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -785,6 +785,7 @@ static const NWidgetPart _nested_station_view_widgets[] = { EndContainer(), NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SV_CLOSE_AIRPORT), SetMinimalSize(45, 12), SetResize(1, 0), SetFill(1, 1), SetDataTip(STR_STATION_VIEW_CLOSE_AIRPORT, STR_STATION_VIEW_CLOSE_AIRPORT_TOOLTIP), + NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_SV_CATCHMENT), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_TRAINS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_TRAIN, STR_STATION_VIEW_SCHEDULED_TRAINS_TOOLTIP), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_ROADVEHS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_LORRY, STR_STATION_VIEW_SCHEDULED_ROAD_VEHICLES_TOOLTIP), NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_SV_SHIPS), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_SHIP, STR_STATION_VIEW_SCHEDULED_SHIPS_TOOLTIP), @@ -1313,6 +1314,8 @@ struct StationViewWindow : public Window { DeleteWindowById(WC_ROADVEH_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_ROAD, this->owner, this->window_number).Pack(), false); DeleteWindowById(WC_SHIPS_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_SHIP, this->owner, this->window_number).Pack(), false); DeleteWindowById(WC_AIRCRAFT_LIST, VehicleListIdentifier(VL_STATION_LIST, VEH_AIRCRAFT, this->owner, this->window_number).Pack(), false); + + SetViewportCatchmentStation(Station::Get(this->window_number), false); } /** @@ -1402,6 +1405,10 @@ struct StationViewWindow : public Window { this->SetWidgetDisabledState(WID_SV_CLOSE_AIRPORT, !(st->facilities & FACIL_AIRPORT) || st->owner != _local_company || st->owner == OWNER_NONE); // Also consider SE, where _local_company == OWNER_NONE this->SetWidgetLoweredState(WID_SV_CLOSE_AIRPORT, (st->facilities & FACIL_AIRPORT) && (st->airport.flags & AIRPORT_CLOSED_block) != 0); + extern const Station *_viewport_highlight_station; + this->SetWidgetDisabledState(WID_SV_CATCHMENT, st->facilities == FACIL_NONE); + this->SetWidgetLoweredState(WID_SV_CATCHMENT, _viewport_highlight_station == st); + this->DrawWidgets(); if (!this->IsShaded()) { @@ -1883,6 +1890,10 @@ struct StationViewWindow : public Window { this->HandleCargoWaitingClick(this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_SV_WAITING, WD_FRAMERECT_TOP, FONT_HEIGHT_NORMAL) - this->vscroll->GetPosition()); break; + case WID_SV_CATCHMENT: + SetViewportCatchmentStation(Station::Get(this->window_number), !this->IsWidgetLowered(WID_SV_CATCHMENT)); + break; + case WID_SV_LOCATION: if (_ctrl_pressed) { ShowExtraViewPortWindow(Station::Get(this->window_number)->xy); @@ -2247,6 +2258,11 @@ struct SelectStationWindow : Window { this->OnInvalidateData(0); } + ~SelectStationWindow() + { + if (_settings_client.gui.station_show_coverage) SetViewportCatchmentStation(nullptr, true); + } + void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override { if (widget != WID_JS_PANEL) return; diff --git a/src/viewport.cpp b/src/viewport.cpp index b3865f7639..c8ae46abdb 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -979,6 +979,44 @@ static void DrawAutorailSelection(const TileInfo *ti, uint autorail_type) DrawSelectionSprite(image, _thd.make_square_red ? PALETTE_SEL_TILE_RED : pal, ti, 7, foundation_part); } +enum TileHighlightType { + THT_NONE, + THT_WHITE, + THT_BLUE, +}; + +const Station *_viewport_highlight_station; ///< Currently selected station for coverage area highlight + +/** + * Get tile highlight type of coverage area for a given tile. + * @param t Tile that is being drawn + * @return Tile highlight type to draw + */ +static TileHighlightType GetTileHighlightType(TileIndex t) +{ + if (_viewport_highlight_station != nullptr) { + if (IsTileType(t, MP_STATION) && GetStationIndex(t) == _viewport_highlight_station->index) return THT_WHITE; + if (_viewport_highlight_station->TileIsInCatchment(t)) return THT_BLUE; + } + + return THT_NONE; +} + +/** + * Draw tile highlight for coverage area highlight. + * @param *ti TileInfo Tile that is being drawn + * @param tht Highlight type to draw. + */ +static void DrawTileHighlightType(const TileInfo *ti, TileHighlightType tht) +{ + switch (tht) { + default: + case THT_NONE: break; + case THT_WHITE: DrawTileSelectionRect(ti, PAL_NONE); break; + case THT_BLUE: DrawTileSelectionRect(ti, PALETTE_SEL_TILE_BLUE); break; + } +} + /** * Checks if the specified tile is selected and if so draws selection using correct selectionstyle. * @param *ti TileInfo Tile that is being drawn @@ -989,6 +1027,9 @@ static void DrawTileSelection(const TileInfo *ti) bool is_redsq = _thd.redsq == ti->tile; if (is_redsq) DrawTileSelectionRect(ti, PALETTE_TILE_RED_PULSATING); + TileHighlightType tht = GetTileHighlightType(ti->tile); + DrawTileHighlightType(ti, tht); + /* No tile selection active? */ if ((_thd.drawstyle & HT_DRAG_MASK) == HT_NONE) return; @@ -1043,7 +1084,7 @@ draw_inner: } /* Check if it's inside the outer area? */ - if (!is_redsq && _thd.outersize.x > 0 && + if (!is_redsq && tht == THT_NONE && _thd.outersize.x > 0 && IsInsideBS(ti->x, _thd.pos.x + _thd.offs.x, _thd.size.x + _thd.outersize.x) && IsInsideBS(ti->y, _thd.pos.y + _thd.offs.y, _thd.size.y + _thd.outersize.y)) { /* Draw a blue rect. */ @@ -3342,3 +3383,37 @@ CommandCost CmdScrollViewport(TileIndex tile, DoCommandFlag flags, uint32 p1, ui } return CommandCost(); } + +static void MarkCatchmentTilesDirty() +{ + if (_viewport_highlight_station != nullptr) { + if (_viewport_highlight_station->catchment_tiles.tile == INVALID_TILE) { + MarkWholeScreenDirty(); + _viewport_highlight_station = nullptr; + } else { + BitmapTileIterator it(_viewport_highlight_station->catchment_tiles); + for (TileIndex tile = it; tile != INVALID_TILE; tile = ++it) { + MarkTileDirtyByTile(tile); + } + } + } +} + +/** + * Select or deselect station for coverage area highlight. + * @param *st Station in question + * @param sel Select or deselect given station + */ +void SetViewportCatchmentStation(const Station *st, bool sel) +{ + if (_viewport_highlight_station != nullptr) SetWindowDirty(WC_STATION_VIEW, _viewport_highlight_station->index); + if (sel && _viewport_highlight_station != st) { + MarkCatchmentTilesDirty(); + _viewport_highlight_station = st; + MarkCatchmentTilesDirty(); + } else if (!sel && _viewport_highlight_station == st) { + MarkCatchmentTilesDirty(); + _viewport_highlight_station = nullptr; + } + if (_viewport_highlight_station != nullptr) SetWindowDirty(WC_STATION_VIEW, _viewport_highlight_station->index); +} diff --git a/src/viewport_func.h b/src/viewport_func.h index 9bfb428900..12d59d5c0c 100644 --- a/src/viewport_func.h +++ b/src/viewport_func.h @@ -94,4 +94,8 @@ static inline void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset = Point GetViewportStationMiddle(const ViewPort *vp, const Station *st); +struct Station; + +void SetViewportCatchmentStation(const Station *st, bool sel); + #endif /* VIEWPORT_FUNC_H */ diff --git a/src/widgets/station_widget.h b/src/widgets/station_widget.h index 82fe392e33..f9b5b266ab 100644 --- a/src/widgets/station_widget.h +++ b/src/widgets/station_widget.h @@ -30,6 +30,7 @@ enum StationViewWidgets { WID_SV_ROADVEHS, ///< List of scheduled road vehs button. WID_SV_SHIPS, ///< List of scheduled ships button. WID_SV_PLANES, ///< List of scheduled planes button. + WID_SV_CATCHMENT, ///< Toggle catchment area highlight. }; /** Widgets of the #CompanyStationsWindow class. */ From 81f0f9740690d0f3307d946d848375e269c8d2ee Mon Sep 17 00:00:00 2001 From: peter1138 Date: Sat, 30 Mar 2019 16:58:40 +0000 Subject: [PATCH 10/56] Feature: Add existing station coverage area display when placing new station parts. --- src/airport_gui.cpp | 3 ++ src/dock_gui.cpp | 3 ++ src/rail_gui.cpp | 3 ++ src/road_gui.cpp | 3 ++ src/station_gui.cpp | 72 ++++++++++++++++++++++++++++++++++++++++ src/tilehighlight_type.h | 2 ++ src/viewport.cpp | 2 ++ 7 files changed, 88 insertions(+) diff --git a/src/airport_gui.cpp b/src/airport_gui.cpp index 8e436f1cb5..0fff03a3cf 100644 --- a/src/airport_gui.cpp +++ b/src/airport_gui.cpp @@ -79,6 +79,7 @@ struct BuildAirToolbarWindow : Window { ~BuildAirToolbarWindow() { + if (this->IsWidgetLowered(WID_AT_AIRPORT)) SetViewportCatchmentStation(nullptr, true); if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false); } @@ -143,6 +144,8 @@ struct BuildAirToolbarWindow : Window { void OnPlaceObjectAbort() override { + if (this->IsWidgetLowered(WID_AT_AIRPORT)) SetViewportCatchmentStation(nullptr, true); + this->RaiseButtons(); DeleteWindowById(WC_BUILD_STATION, TRANSPORT_AIR); diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp index 95989dc035..d74c6d2caf 100644 --- a/src/dock_gui.cpp +++ b/src/dock_gui.cpp @@ -105,6 +105,7 @@ struct BuildDocksToolbarWindow : Window { ~BuildDocksToolbarWindow() { + if (this->IsWidgetLowered(WID_DT_STATION)) SetViewportCatchmentStation(nullptr, true); if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false); } @@ -248,6 +249,8 @@ struct BuildDocksToolbarWindow : Window { void OnPlaceObjectAbort() override { + if (this->IsWidgetLowered(WID_DT_STATION)) SetViewportCatchmentStation(nullptr, true); + this->RaiseButtons(); DeleteWindowById(WC_BUILD_STATION, TRANSPORT_WATER); diff --git a/src/rail_gui.cpp b/src/rail_gui.cpp index 54aaf61f62..6d70686fde 100644 --- a/src/rail_gui.cpp +++ b/src/rail_gui.cpp @@ -432,6 +432,7 @@ struct BuildRailToolbarWindow : Window { ~BuildRailToolbarWindow() { + if (this->IsWidgetLowered(WID_RAT_BUILD_STATION)) SetViewportCatchmentStation(nullptr, true); if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false); } @@ -743,6 +744,8 @@ struct BuildRailToolbarWindow : Window { void OnPlaceObjectAbort() override { + if (this->IsWidgetLowered(WID_RAT_BUILD_STATION)) SetViewportCatchmentStation(nullptr, true); + this->RaiseButtons(); this->DisableWidget(WID_RAT_REMOVE); this->SetWidgetDirty(WID_RAT_REMOVE); diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 27c8fe8e7f..78f5377dae 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -327,6 +327,7 @@ struct BuildRoadToolbarWindow : Window { ~BuildRoadToolbarWindow() { + if (this->IsWidgetLowered(WID_ROT_BUS_STATION) || this->IsWidgetLowered(WID_ROT_TRUCK_STATION)) SetViewportCatchmentStation(nullptr, true); if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false); } @@ -545,6 +546,8 @@ struct BuildRoadToolbarWindow : Window { void OnPlaceObjectAbort() override { + if (this->IsWidgetLowered(WID_ROT_BUS_STATION) || this->IsWidgetLowered(WID_ROT_TRUCK_STATION)) SetViewportCatchmentStation(nullptr, true); + this->RaiseButtons(); this->SetWidgetsDisabledState(true, WID_ROT_REMOVE, diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 1cc6a126ff..31da16238e 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -80,6 +80,46 @@ int DrawStationCoverageAreaText(int left, int right, int top, StationCoverageTyp return DrawStringMultiLine(left, right, top, INT32_MAX, supplies ? STR_STATION_BUILD_SUPPLIES_CARGO : STR_STATION_BUILD_ACCEPTS_CARGO); } +/** + * Find stations adjacent to the current tile highlight area, so that existing coverage + * area can be drawn. + */ +static void FindStationsAroundSelection() +{ + /* With distant join we don't know which station will be selected, so don't show any */ + if (_ctrl_pressed) { + SetViewportCatchmentStation(nullptr, true); + return; + } + + /* Tile area for TileHighlightData */ + TileArea location(TileVirtXY(_thd.pos.x, _thd.pos.y), _thd.size.x / TILE_SIZE - 1, _thd.size.y / TILE_SIZE - 1); + + /* Extended area by one tile */ + uint x = TileX(location.tile); + uint y = TileY(location.tile); + + int max_c = 1; + TileArea ta(TileXY(max(0, x - max_c), max(0, y - max_c)), TileXY(min(MapMaxX(), x + location.w + max_c), min(MapMaxY(), y + location.h + max_c))); + + Station *adjacent = nullptr; + + /* Direct loop instead of FindStationsAroundTiles as we are not interested in catchment area */ + TILE_AREA_LOOP(tile, ta) { + if (IsTileType(tile, MP_STATION) && GetTileOwner(tile) == _local_company) { + Station *st = Station::GetByTile(tile); + if (st == nullptr) continue; + if (adjacent != nullptr && st != adjacent) { + /* Multiple nearby, distant join is required. */ + adjacent = nullptr; + break; + } + adjacent = st; + } + } + SetViewportCatchmentStation(adjacent, true); +} + /** * Check whether we need to redraw the station coverage text. * If it is needed actually make the window for redrawing. @@ -87,9 +127,20 @@ int DrawStationCoverageAreaText(int left, int right, int top, StationCoverageTyp */ void CheckRedrawStationCoverage(const Window *w) { + /* Test if ctrl state changed */ + static bool _last_ctrl_pressed; + if (_ctrl_pressed != _last_ctrl_pressed) { + _thd.dirty = 0xff; + _last_ctrl_pressed = _ctrl_pressed; + } + if (_thd.dirty & 1) { _thd.dirty &= ~1; w->SetDirty(); + + if (_settings_client.gui.station_show_coverage && _thd.drawstyle == HT_RECT) { + FindStationsAroundSelection(); + } } } @@ -2256,11 +2307,15 @@ struct SelectStationWindow : Window { this->GetWidget(WID_JS_CAPTION)->widget_data = T::EXPECTED_FACIL == FACIL_WAYPOINT ? STR_JOIN_WAYPOINT_CAPTION : STR_JOIN_STATION_CAPTION; this->FinishInitNested(0); this->OnInvalidateData(0); + + _thd.freeze = true; } ~SelectStationWindow() { if (_settings_client.gui.station_show_coverage) SetViewportCatchmentStation(nullptr, true); + + _thd.freeze = false; } void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override @@ -2350,6 +2405,23 @@ struct SelectStationWindow : Window { this->vscroll->SetCount((uint)_stations_nearby_list.size() + 1); this->SetDirty(); } + + void OnMouseOver(Point pt, int widget) override + { + if (widget != WID_JS_PANEL) { + SetViewportCatchmentStation(nullptr, true); + return; + } + + /* Show coverage area of station under cursor */ + uint st_index = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_JS_PANEL, WD_FRAMERECT_TOP); + if (st_index == 0 || st_index > _stations_nearby_list.size()) { + SetViewportCatchmentStation(nullptr, true); + } else { + st_index--; + SetViewportCatchmentStation(Station::Get(_stations_nearby_list[st_index]), true); + } + } }; static WindowDesc _select_station_desc( diff --git a/src/tilehighlight_type.h b/src/tilehighlight_type.h index 3d64248dff..f1109bf2e5 100644 --- a/src/tilehighlight_type.h +++ b/src/tilehighlight_type.h @@ -52,6 +52,8 @@ struct TileHighlightData { Point outersize; ///< Size, in tile "units", of the blue coverage area excluding the side of the selected area. bool diagonal; ///< Whether the dragged area is a 45 degrees rotated rectangle. + bool freeze; ///< Freeze highlight in place. + Point new_pos; ///< New value for \a pos; used to determine whether to redraw the selection. Point new_size; ///< New value for \a size; used to determine whether to redraw the selection. Point new_outersize; ///< New value for \a outersize; used to determine whether to redraw the selection. diff --git a/src/viewport.cpp b/src/viewport.cpp index c8ae46abdb..27e8f2eca9 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -2445,6 +2445,8 @@ void UpdateTileSelection() int x1; int y1; + if (_thd.freeze) return; + HighLightStyle new_drawstyle = HT_NONE; bool new_diagonal = false; From 81d335b081db006ddb883e2452f73984442f9823 Mon Sep 17 00:00:00 2001 From: peter1138 Date: Sat, 30 Mar 2019 16:59:43 +0000 Subject: [PATCH 11/56] Feature: Add station coverage area display for towns. --- src/script/api/game/game_window.hpp.sq | 1 + src/script/api/script_window.hpp | 1 + src/town_gui.cpp | 18 +++++++++ src/viewport.cpp | 51 +++++++++++++++++++++++++- src/viewport_func.h | 2 + src/widgets/town_widget.h | 1 + 6 files changed, 73 insertions(+), 1 deletion(-) diff --git a/src/script/api/game/game_window.hpp.sq b/src/script/api/game/game_window.hpp.sq index d1966e3d8d..3d190f44f1 100644 --- a/src/script/api/game/game_window.hpp.sq +++ b/src/script/api/game/game_window.hpp.sq @@ -1261,6 +1261,7 @@ void SQGSWindow_Register(Squirrel *engine) SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TV_CENTER_VIEW, "WID_TV_CENTER_VIEW"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TV_SHOW_AUTHORITY, "WID_TV_SHOW_AUTHORITY"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TV_CHANGE_NAME, "WID_TV_CHANGE_NAME"); + SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TV_CATCHMENT, "WID_TV_CATCHMENT"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TV_EXPAND, "WID_TV_EXPAND"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TV_DELETE, "WID_TV_DELETE"); SQGSWindow.DefSQConst(engine, ScriptWindow::WID_TF_NEW_TOWN, "WID_TF_NEW_TOWN"); diff --git a/src/script/api/script_window.hpp b/src/script/api/script_window.hpp index 8c133e9983..47c8488889 100644 --- a/src/script/api/script_window.hpp +++ b/src/script/api/script_window.hpp @@ -2500,6 +2500,7 @@ public: WID_TV_CENTER_VIEW = ::WID_TV_CENTER_VIEW, ///< Center the main view on this town. WID_TV_SHOW_AUTHORITY = ::WID_TV_SHOW_AUTHORITY, ///< Show the town authority window. WID_TV_CHANGE_NAME = ::WID_TV_CHANGE_NAME, ///< Change the name of this town. + WID_TV_CATCHMENT = ::WID_TV_CATCHMENT, ///< Toggle catchment area highlight. WID_TV_EXPAND = ::WID_TV_EXPAND, ///< Expand this town (scenario editor only). WID_TV_DELETE = ::WID_TV_DELETE, ///< Delete this town (scenario editor only). }; diff --git a/src/town_gui.cpp b/src/town_gui.cpp index 07f0d638dd..ebc6969946 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -321,11 +321,24 @@ public: this->SetWidgetDisabledState(WID_TV_CHANGE_NAME, _networking && !_network_server); } + ~TownViewWindow() + { + SetViewportCatchmentTown(Town::Get(this->window_number), false); + } + void SetStringParameters(int widget) const override { if (widget == WID_TV_CAPTION) SetDParam(0, this->town->index); } + void OnPaint() override + { + extern const Town *_viewport_highlight_town; + this->SetWidgetLoweredState(WID_TV_CATCHMENT, _viewport_highlight_town == this->town); + + this->DrawWidgets(); + } + void DrawWidget(const Rect &r, int widget) const override { if (widget != WID_TV_INFO) return; @@ -432,6 +445,10 @@ public: ShowQueryString(STR_TOWN_NAME, STR_TOWN_VIEW_RENAME_TOWN_BUTTON, MAX_LENGTH_TOWN_NAME_CHARS, this, CS_ALPHANUMERAL, QSF_ENABLE_DEFAULT | QSF_LEN_IN_CHARS); break; + case WID_TV_CATCHMENT: + SetViewportCatchmentTown(Town::Get(this->window_number), !this->IsWidgetLowered(WID_TV_CATCHMENT)); + break; + case WID_TV_EXPAND: { // expand town - only available on Scenario editor /* Warn the user if towns are not allowed to build roads, but do this only once per OpenTTD run. */ static bool _warn_town_no_roads = false; @@ -552,6 +569,7 @@ static const NWidgetPart _nested_town_game_view_widgets[] = { NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_TV_SHOW_AUTHORITY), SetMinimalSize(80, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_TOWN_VIEW_LOCAL_AUTHORITY_BUTTON, STR_TOWN_VIEW_LOCAL_AUTHORITY_TOOLTIP), NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_TV_CHANGE_NAME), SetMinimalSize(80, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_BUTTON_RENAME, STR_TOWN_VIEW_RENAME_TOOLTIP), EndContainer(), + NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TV_CATCHMENT), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT), NWidget(WWT_RESIZEBOX, COLOUR_BROWN), EndContainer(), }; diff --git a/src/viewport.cpp b/src/viewport.cpp index 27e8f2eca9..8ec315b16d 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -983,9 +983,11 @@ enum TileHighlightType { THT_NONE, THT_WHITE, THT_BLUE, + THT_RED, }; const Station *_viewport_highlight_station; ///< Currently selected station for coverage area highlight +const Town *_viewport_highlight_town; ///< Currently selected town for coverage area highlight /** * Get tile highlight type of coverage area for a given tile. @@ -999,6 +1001,24 @@ static TileHighlightType GetTileHighlightType(TileIndex t) if (_viewport_highlight_station->TileIsInCatchment(t)) return THT_BLUE; } + if (_viewport_highlight_town != nullptr) { + if (IsTileType(t, MP_HOUSE)) { + if (GetTownIndex(t) == _viewport_highlight_town->index) { + TileHighlightType type = THT_RED; + for (const Station *st : _viewport_highlight_town->stations_near) { + if (st->owner != _current_company) continue; + if (st->TileIsInCatchment(t)) return THT_BLUE; + } + return type; + } + } else if (IsTileType(t, MP_STATION)) { + for (const Station *st : _viewport_highlight_town->stations_near) { + if (st->owner != _current_company) continue; + if (GetStationIndex(t) == st->index) return THT_WHITE; + } + } + } + return THT_NONE; } @@ -1014,6 +1034,7 @@ static void DrawTileHighlightType(const TileInfo *ti, TileHighlightType tht) case THT_NONE: break; case THT_WHITE: DrawTileSelectionRect(ti, PAL_NONE); break; case THT_BLUE: DrawTileSelectionRect(ti, PALETTE_SEL_TILE_BLUE); break; + case THT_RED: DrawTileSelectionRect(ti, PALETTE_TILE_RED_PULSATING); break; } } @@ -1084,7 +1105,7 @@ draw_inner: } /* Check if it's inside the outer area? */ - if (!is_redsq && tht == THT_NONE && _thd.outersize.x > 0 && + if (!is_redsq && (tht == THT_NONE || tht == THT_RED) && _thd.outersize.x > 0 && IsInsideBS(ti->x, _thd.pos.x + _thd.offs.x, _thd.size.x + _thd.outersize.x) && IsInsideBS(ti->y, _thd.pos.y + _thd.offs.y, _thd.size.y + _thd.outersize.y)) { /* Draw a blue rect. */ @@ -3388,6 +3409,10 @@ CommandCost CmdScrollViewport(TileIndex tile, DoCommandFlag flags, uint32 p1, ui static void MarkCatchmentTilesDirty() { + if (_viewport_highlight_town != nullptr) { + MarkWholeScreenDirty(); + return; + } if (_viewport_highlight_station != nullptr) { if (_viewport_highlight_station->catchment_tiles.tile == INVALID_TILE) { MarkWholeScreenDirty(); @@ -3403,15 +3428,18 @@ static void MarkCatchmentTilesDirty() /** * Select or deselect station for coverage area highlight. + * Selecting a station will deselect a town. * @param *st Station in question * @param sel Select or deselect given station */ void SetViewportCatchmentStation(const Station *st, bool sel) { if (_viewport_highlight_station != nullptr) SetWindowDirty(WC_STATION_VIEW, _viewport_highlight_station->index); + if (_viewport_highlight_town != nullptr) SetWindowDirty(WC_TOWN_VIEW, _viewport_highlight_town->index); if (sel && _viewport_highlight_station != st) { MarkCatchmentTilesDirty(); _viewport_highlight_station = st; + _viewport_highlight_town = nullptr; MarkCatchmentTilesDirty(); } else if (!sel && _viewport_highlight_station == st) { MarkCatchmentTilesDirty(); @@ -3419,3 +3447,24 @@ void SetViewportCatchmentStation(const Station *st, bool sel) } if (_viewport_highlight_station != nullptr) SetWindowDirty(WC_STATION_VIEW, _viewport_highlight_station->index); } + +/** + * Select or deselect town for coverage area highlight. + * Selecting a town will deselect a station. + * @param *t Town in question + * @param sel Select or deselect given town + */ +void SetViewportCatchmentTown(const Town *t, bool sel) +{ + if (_viewport_highlight_town != nullptr) SetWindowDirty(WC_TOWN_VIEW, _viewport_highlight_town->index); + if (_viewport_highlight_station != nullptr) SetWindowDirty(WC_STATION_VIEW, _viewport_highlight_station->index); + if (sel && _viewport_highlight_town != t) { + _viewport_highlight_station = nullptr; + _viewport_highlight_town = t; + MarkWholeScreenDirty(); + } else if (!sel && _viewport_highlight_town == t) { + _viewport_highlight_town = nullptr; + MarkWholeScreenDirty(); + } + if (_viewport_highlight_town != nullptr) SetWindowDirty(WC_TOWN_VIEW, _viewport_highlight_town->index); +} diff --git a/src/viewport_func.h b/src/viewport_func.h index 12d59d5c0c..8b23cc02a9 100644 --- a/src/viewport_func.h +++ b/src/viewport_func.h @@ -95,7 +95,9 @@ static inline void MarkTileDirtyByTile(TileIndex tile, int bridge_level_offset = Point GetViewportStationMiddle(const ViewPort *vp, const Station *st); struct Station; +struct Town; void SetViewportCatchmentStation(const Station *st, bool sel); +void SetViewportCatchmentTown(const Town *t, bool sel); #endif /* VIEWPORT_FUNC_H */ diff --git a/src/widgets/town_widget.h b/src/widgets/town_widget.h index 4f5443c36e..2559423cea 100644 --- a/src/widgets/town_widget.h +++ b/src/widgets/town_widget.h @@ -39,6 +39,7 @@ enum TownViewWidgets { WID_TV_CENTER_VIEW, ///< Center the main view on this town. WID_TV_SHOW_AUTHORITY, ///< Show the town authority window. WID_TV_CHANGE_NAME, ///< Change the name of this town. + WID_TV_CATCHMENT, ///< Toggle catchment area highlight. WID_TV_EXPAND, ///< Expand this town (scenario editor only). WID_TV_DELETE, ///< Delete this town (scenario editor only). }; From d5841109f0e2986739dd120ec5252b4e230418a5 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Thu, 25 Apr 2019 17:28:59 +0200 Subject: [PATCH 12/56] Fix dcb2571: Missing override keywords --- src/misc_gui.cpp | 2 +- src/network/network_gui.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/misc_gui.cpp b/src/misc_gui.cpp index 0566fffc3d..86c17cdccd 100644 --- a/src/misc_gui.cpp +++ b/src/misc_gui.cpp @@ -1003,7 +1003,7 @@ struct QueryStringWindow : public Window } } - virtual void DrawWidget(const Rect &r, int widget) const + void DrawWidget(const Rect &r, int widget) const override { if (widget != WID_QS_WARNING) return; diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp index d39b61dbf0..6486f45317 100644 --- a/src/network/network_gui.cpp +++ b/src/network/network_gui.cpp @@ -2193,7 +2193,7 @@ struct NetworkCompanyPasswordWindow : public Window { } } - virtual void DrawWidget(const Rect &r, int widget) const + void DrawWidget(const Rect &r, int widget) const override { if (widget != WID_NCP_WARNING) return; From 5b0ce8c214648c6278968ab458d6247a69e01ba6 Mon Sep 17 00:00:00 2001 From: translators Date: Thu, 25 Apr 2019 19:45:45 +0200 Subject: [PATCH 13/56] Update: Translations from eints finnish: 3 changes by hpiirai italian: 3 changes by lorenzodv --- src/lang/finnish.txt | 3 +++ src/lang/italian.txt | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/lang/finnish.txt b/src/lang/finnish.txt index 86ba45386a..d1bf5e0731 100644 --- a/src/lang/finnish.txt +++ b/src/lang/finnish.txt @@ -237,6 +237,8 @@ STR_TOOLTIP_FILTER_CRITERIA :{BLACK}Valitse STR_BUTTON_SORT_BY :{BLACK}Lajittele STR_BUTTON_LOCATION :{BLACK}Sijainti STR_BUTTON_RENAME :{BLACK}Nimeä uudelleen +STR_BUTTON_CATCHMENT :{BLACK}Vaikutusalue +STR_TOOLTIP_CATCHMENT :{BLACK}Valitse, näytetäänkö vaikutusalue STR_TOOLTIP_CLOSE_WINDOW :{BLACK}Sulje ikkuna STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS :{BLACK}Ikkunan otsake – siirrä ikkunaa vetämällä tästä @@ -265,6 +267,7 @@ STR_SHOW_HIDDEN_ENGINES_VEHICLE_AIRCRAFT_TOOLTIP :{BLACK}Kun otat STR_BUTTON_DEFAULT :{BLACK}Oletus STR_BUTTON_CANCEL :{BLACK}Peruuta STR_BUTTON_OK :{BLACK}OK +STR_WARNING_PASSWORD_SECURITY :{YELLOW}Varoitus: Palvelimen ylläpitäjät saattavat nähdä kaiken tähän kirjoittamasi. # On screen keyboard window STR_OSK_KEYBOARD_LAYOUT :§1234567890+´ qwertyuiopå¨asdfghjklöä' zxcvbnm,.- . diff --git a/src/lang/italian.txt b/src/lang/italian.txt index 4631a1934b..696504b5a4 100644 --- a/src/lang/italian.txt +++ b/src/lang/italian.txt @@ -239,6 +239,8 @@ STR_TOOLTIP_FILTER_CRITERIA :{BLACK}Selezion STR_BUTTON_SORT_BY :{BLACK}Ordina per STR_BUTTON_LOCATION :{BLACK}Posizione STR_BUTTON_RENAME :{BLACK}Rinomina +STR_BUTTON_CATCHMENT :{BLACK}Copertura +STR_TOOLTIP_CATCHMENT :{BLACK}Attiva/disattiva la visualizzazione dell'area di copertura STR_TOOLTIP_CLOSE_WINDOW :{BLACK}Chiude la finestra STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS :{BLACK}Titolo della finestra - trascinarlo per muovere la finestra @@ -267,6 +269,7 @@ STR_SHOW_HIDDEN_ENGINES_VEHICLE_AIRCRAFT_TOOLTIP :{BLACK}Mostra a STR_BUTTON_DEFAULT :{BLACK}Predefinito STR_BUTTON_CANCEL :{BLACK}Annulla STR_BUTTON_OK :{BLACK}OK +STR_WARNING_PASSWORD_SECURITY :{YELLOW}Attenzione: gli amministratori del server potrebbero leggere il testo inserito qui. # On screen keyboard window STR_OSK_KEYBOARD_LAYOUT :\1234567890'ì qwertyuiopè+asdfghjklòàù Date: Fri, 26 Apr 2019 19:45:41 +0200 Subject: [PATCH 14/56] Update: Translations from eints indonesian: 3 changes by fanioz croatian: 3 changes by VoyagerOne --- src/lang/croatian.txt | 3 +++ src/lang/indonesian.txt | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/lang/croatian.txt b/src/lang/croatian.txt index ba1ea05aa6..aa1a5bcb3a 100644 --- a/src/lang/croatian.txt +++ b/src/lang/croatian.txt @@ -333,6 +333,8 @@ STR_TOOLTIP_FILTER_CRITERIA :{BLACK}Odaberi STR_BUTTON_SORT_BY :{BLACK}Sortiraj prema STR_BUTTON_LOCATION :{BLACK}Lokacija STR_BUTTON_RENAME :{BLACK}Preimenuj +STR_BUTTON_CATCHMENT :{BLACK}Područje pokrivanja +STR_TOOLTIP_CATCHMENT :{BLACK}Uključi prikaz područja pokrivanja STR_TOOLTIP_CLOSE_WINDOW :{BLACK}Zatvori prozor STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS :{BLACK}Naslov prozora - povuci ovo za micanje prozora @@ -361,6 +363,7 @@ STR_SHOW_HIDDEN_ENGINES_VEHICLE_AIRCRAFT_TOOLTIP :{BLACK}Uključi STR_BUTTON_DEFAULT :{BLACK}Zadano STR_BUTTON_CANCEL :{BLACK}Odustani STR_BUTTON_OK :{BLACK}OK +STR_WARNING_PASSWORD_SECURITY :{YELLOW}Upozorenje: Administratori servera mogu pročitati bilo koji tekst upisan ovdje. # On screen keyboard window STR_OSK_KEYBOARD_LAYOUT :`1234567890-=\qwertyuiop[]asdfghjkl;' zxcvbnm,./ . diff --git a/src/lang/indonesian.txt b/src/lang/indonesian.txt index ca6c968166..5152a89e5f 100644 --- a/src/lang/indonesian.txt +++ b/src/lang/indonesian.txt @@ -476,6 +476,7 @@ STR_ABOUT_MENU_SCREENSHOT :Ambil gambar STR_ABOUT_MENU_ZOOMIN_SCREENSHOT :Ambil gambar dengan diperbesar STR_ABOUT_MENU_DEFAULTZOOM_SCREENSHOT :Ambil gambar dengan perbesaran normal STR_ABOUT_MENU_GIANT_SCREENSHOT :Ambil gambar keseluruhan peta +STR_ABOUT_MENU_SHOW_FRAMERATE :Tampilkan laju bingkai STR_ABOUT_MENU_ABOUT_OPENTTD :Tentang 'OpenTTD' STR_ABOUT_MENU_SPRITE_ALIGNER :Penjajar Sprite STR_ABOUT_MENU_TOGGLE_BOUNDING_BOXES :Hidup/Matikan kotak batas @@ -1572,6 +1573,7 @@ STR_CONFIG_SETTING_TOWN_FOUNDING_HELPTEXT :Mengaktifkan se STR_CONFIG_SETTING_TOWN_FOUNDING_FORBIDDEN :Dilarang STR_CONFIG_SETTING_TOWN_FOUNDING_ALLOWED :Diijinkan STR_CONFIG_SETTING_TOWN_FOUNDING_ALLOWED_CUSTOM_LAYOUT :Diijinkan, layout kota sendiri +STR_CONFIG_SETTING_TOWN_CARGOGENMODE_HELPTEXT :Seberapa banyak kargo dihasilkan oleh rumah di kota , relatif terhadap keseluruhan populasi kota.{}Pertumbuhan kuadrat: Kota yang membesar dua kali menghasilkan penumpang empat kali lipat.{}Pertumbuhan linier: Kota yang membesar dua kali menghasilkan penumpang dua kali lipat. STR_CONFIG_SETTING_TOWN_CARGOGENMODE_BITCOUNT :Linier STR_CONFIG_SETTING_EXTRA_TREE_PLACEMENT :Penempatan pohon dalam permainan: {STRING} @@ -3377,6 +3379,7 @@ STR_GROUP_DEFAULT_ROAD_VEHICLES :Kendaraan tanpa STR_GROUP_DEFAULT_SHIPS :Kapal tanpa kelompok STR_GROUP_DEFAULT_AIRCRAFTS :Pesawat tanpa kelompok +STR_GROUP_COUNT_WITH_SUBGROUP :{TINY_FONT}{COMMA} (+{COMMA}) STR_GROUPS_CLICK_ON_GROUP_FOR_TOOLTIP :{BLACK}Kelompok - Klik salah satu untuk melihat daftar kendaraan pada kelompok tersebut STR_GROUP_CREATE_TOOLTIP :{BLACK}Klik untuk membuat kelompok From b454ca711054f9df7147afd8ffeae8639fb51cab Mon Sep 17 00:00:00 2001 From: peter1138 Date: Sat, 27 Apr 2019 09:00:22 +0100 Subject: [PATCH 15/56] Fix 81d335b: Coverage button missing from town window in scenario editor. --- src/town_gui.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/town_gui.cpp b/src/town_gui.cpp index ebc6969946..5cb589d31f 100644 --- a/src/town_gui.cpp +++ b/src/town_gui.cpp @@ -602,6 +602,7 @@ static const NWidgetPart _nested_town_editor_view_widgets[] = { NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_TV_EXPAND), SetMinimalSize(80, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_TOWN_VIEW_EXPAND_BUTTON, STR_TOWN_VIEW_EXPAND_TOOLTIP), NWidget(WWT_PUSHTXTBTN, COLOUR_BROWN, WID_TV_DELETE), SetMinimalSize(80, 12), SetFill(1, 1), SetResize(1, 0), SetDataTip(STR_TOWN_VIEW_DELETE_BUTTON, STR_TOWN_VIEW_DELETE_TOOLTIP), EndContainer(), + NWidget(WWT_TEXTBTN, COLOUR_BROWN, WID_TV_CATCHMENT), SetMinimalSize(14, 12), SetFill(0, 1), SetDataTip(STR_BUTTON_CATCHMENT, STR_TOOLTIP_CATCHMENT), NWidget(WWT_RESIZEBOX, COLOUR_BROWN), EndContainer(), }; From ead5b5511998d23942c84644f13dc7f30601cc08 Mon Sep 17 00:00:00 2001 From: translators Date: Sat, 27 Apr 2019 19:45:42 +0200 Subject: [PATCH 16/56] Update: Translations from eints spanish (mexican): 3 changes by Absay russian: 3 changes by Lone_Wolf --- src/lang/russian.txt | 3 +++ src/lang/spanish_MX.txt | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/lang/russian.txt b/src/lang/russian.txt index 22476579be..926420e850 100644 --- a/src/lang/russian.txt +++ b/src/lang/russian.txt @@ -363,6 +363,8 @@ STR_TOOLTIP_FILTER_CRITERIA :{BLACK}Выбе STR_BUTTON_SORT_BY :{BLACK}Сортировка STR_BUTTON_LOCATION :{BLACK}Обзор STR_BUTTON_RENAME :{BLACK}Переименовать +STR_BUTTON_CATCHMENT :{BLACK}Покрытие +STR_TOOLTIP_CATCHMENT :{BLACK}Переключить видимость области покрытия STR_TOOLTIP_CLOSE_WINDOW :{BLACK}Закрыть окно STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS :{BLACK}Окна можно перетаскивать, схватив за заголовок @@ -391,6 +393,7 @@ STR_SHOW_HIDDEN_ENGINES_VEHICLE_AIRCRAFT_TOOLTIP :{BLACK}Если STR_BUTTON_DEFAULT :{BLACK}По умолчанию STR_BUTTON_CANCEL :{BLACK}Отмена STR_BUTTON_OK :{BLACK}OK +STR_WARNING_PASSWORD_SECURITY :{YELLOW}Внимание: администраторы сервера могут увидеть ваш пароль. # On screen keyboard window STR_OSK_KEYBOARD_LAYOUT :`1234567890-=\qwertyuiop[]asdfghjkl;' zxcvbnm,./ . diff --git a/src/lang/spanish_MX.txt b/src/lang/spanish_MX.txt index ca0b6f0785..335bbdba8c 100644 --- a/src/lang/spanish_MX.txt +++ b/src/lang/spanish_MX.txt @@ -238,6 +238,8 @@ STR_TOOLTIP_FILTER_CRITERIA :{BLACK}Elegir c STR_BUTTON_SORT_BY :{BLACK}Ordenar por STR_BUTTON_LOCATION :{BLACK}Ubicación STR_BUTTON_RENAME :{BLACK}Cambiar nombre +STR_BUTTON_CATCHMENT :{BLACK}Cobertura +STR_TOOLTIP_CATCHMENT :{BLACK}Mostrar u ocultar área de cobertura STR_TOOLTIP_CLOSE_WINDOW :{BLACK}Cerrar ventana STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS :{BLACK}Título de la ventana (arrastrar para mover) @@ -266,6 +268,7 @@ STR_SHOW_HIDDEN_ENGINES_VEHICLE_AIRCRAFT_TOOLTIP :{BLACK}Activar STR_BUTTON_DEFAULT :{BLACK}Predeterminado STR_BUTTON_CANCEL :{BLACK}Cancelar STR_BUTTON_OK :{BLACK}Aceptar +STR_WARNING_PASSWORD_SECURITY :{YELLOW}Advertencia: los administradores del servidor tienen acceso al texto escrito aquí # On screen keyboard window STR_OSK_KEYBOARD_LAYOUT :|1234567890'¿\qwertyuiop´+asdfghjklñ{} Date: Sat, 27 Apr 2019 20:47:32 +0100 Subject: [PATCH 17/56] Fix #7165: Missed another 'Append() --> push_back()' replacement (#7548) --- src/network/core/host.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/network/core/host.cpp b/src/network/core/host.cpp index 98a706e2f5..04247d99c9 100644 --- a/src/network/core/host.cpp +++ b/src/network/core/host.cpp @@ -174,7 +174,7 @@ static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // !G (r.ifr_flags & IFF_BROADCAST) && ioctl(sock, SIOCGIFBRDADDR, &r) != -1) { NetworkAddress addr(&r.ifr_broadaddr, sizeof(sockaddr)); - if (std::none_of(broadcast->begin(), broadcast->end(), [&addr](NetworkAddress const& elem) -> bool { return elem == addr; })) *broadcast->Append() = addr; + if (std::none_of(broadcast->begin(), broadcast->end(), [&addr](NetworkAddress const& elem) -> bool { return elem == addr; })) broadcast->push_back(addr); } } From aa220b2375efecf831ead0794e6de7b621e3c7a2 Mon Sep 17 00:00:00 2001 From: translators Date: Sun, 28 Apr 2019 19:45:44 +0200 Subject: [PATCH 18/56] Update: Translations from eints indonesian: 2 changes by fanioz dutch: 3 changes by JanWillem korean: 3 changes by telk5093 --- src/lang/dutch.txt | 3 +++ src/lang/indonesian.txt | 4 ++-- src/lang/korean.txt | 3 +++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/lang/dutch.txt b/src/lang/dutch.txt index a4c5e772fd..c28321141f 100644 --- a/src/lang/dutch.txt +++ b/src/lang/dutch.txt @@ -237,6 +237,8 @@ STR_TOOLTIP_FILTER_CRITERIA :{BLACK}Selectee STR_BUTTON_SORT_BY :{BLACK}Sorteren op STR_BUTTON_LOCATION :{BLACK}Locatie STR_BUTTON_RENAME :{BLACK}Hernoemen +STR_BUTTON_CATCHMENT :{BLACK}Dekking +STR_TOOLTIP_CATCHMENT :{BLACK}Schakelt weergave van dekkingsgebied om STR_TOOLTIP_CLOSE_WINDOW :{BLACK}Venster sluiten STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS :{BLACK}Vensternaam - sleep om venster te verplaatsen @@ -265,6 +267,7 @@ STR_SHOW_HIDDEN_ENGINES_VEHICLE_AIRCRAFT_TOOLTIP :{BLACK}Wanneer STR_BUTTON_DEFAULT :{BLACK}Standaard STR_BUTTON_CANCEL :{BLACK}Annuleren STR_BUTTON_OK :{BLACK}OK +STR_WARNING_PASSWORD_SECURITY :{YELLOW}Waarschuwing: het kan zijn dat serverbeheerders tekst niet kunnen lezen die hier wordt ingevoerd. # On screen keyboard window STR_OSK_KEYBOARD_LAYOUT :`1234567890-=\qwertyuiop[]asdfghjkl;' zxcvbnm,./ . diff --git a/src/lang/indonesian.txt b/src/lang/indonesian.txt index 5152a89e5f..3a66b6eb15 100644 --- a/src/lang/indonesian.txt +++ b/src/lang/indonesian.txt @@ -3154,11 +3154,11 @@ STR_STATION_VIEW_ACCEPTS_TOOLTIP :{BLACK}Tampilka STR_STATION_VIEW_ACCEPTS_CARGO :{BLACK}Menerima: {WHITE}{CARGO_LIST} STR_STATION_VIEW_EXCLUSIVE_RIGHTS_SELF :{BLACK}Stasiun memiliki hak transportasi eksklusif di kota ini -STR_STATION_VIEW_EXCLUSIVE_RIGHTS_COMPANY :{YELLOW}{COMPANY}{BLACK} beli hak transportasi eksklusif di kota ini +STR_STATION_VIEW_EXCLUSIVE_RIGHTS_COMPANY :{YELLOW}{COMPANY}{BLACK} memiliki hak transportasi eksklusif di kota ini STR_STATION_VIEW_RATINGS_BUTTON :{BLACK}Peringkat STR_STATION_VIEW_RATINGS_TOOLTIP :{BLACK}Tampilkna peringkat dari stasiun -STR_STATION_VIEW_SUPPLY_RATINGS_TITLE :{BLACK}Asupan bulanan dan penilaian tempatan: +STR_STATION_VIEW_SUPPLY_RATINGS_TITLE :{BLACK}Asupan bulanan dan peringkat layanan: STR_STATION_VIEW_CARGO_SUPPLY_RATING :{WHITE}{STRING}: {YELLOW}{COMMA} / {STRING} ({COMMA}%) STR_STATION_VIEW_GROUP :{BLACK}Pengelompokkan diff --git a/src/lang/korean.txt b/src/lang/korean.txt index 9e53f801da..3aff4a4ae0 100644 --- a/src/lang/korean.txt +++ b/src/lang/korean.txt @@ -238,6 +238,8 @@ STR_TOOLTIP_FILTER_CRITERIA :{BLACK}검색 STR_BUTTON_SORT_BY :{BLACK}정렬 STR_BUTTON_LOCATION :{BLACK}위치 STR_BUTTON_RENAME :{BLACK}이름 바꾸기 +STR_BUTTON_CATCHMENT :{BLACK}역세권 +STR_TOOLTIP_CATCHMENT :{BLACK}이 역의 역세권을 표시하거나 끕니다. STR_TOOLTIP_CLOSE_WINDOW :{BLACK}창을 닫습니다. STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS :{BLACK}창 제목 - 창을 움직이려면 여기를 드래그하세요. @@ -266,6 +268,7 @@ STR_SHOW_HIDDEN_ENGINES_VEHICLE_AIRCRAFT_TOOLTIP :{BLACK}이 버 STR_BUTTON_DEFAULT :{BLACK}기본값 STR_BUTTON_CANCEL :{BLACK}취소 STR_BUTTON_OK :{BLACK}확인 +STR_WARNING_PASSWORD_SECURITY :{YELLOW}경고: 서버 관리자가 여기에 입력되는 모든 텍스트를 읽을 수 있습니다. # On screen keyboard window STR_OSK_KEYBOARD_LAYOUT :`1234567890-=\ㅂㅈㄷㄱㅅㅛㅕㅑㅐㅔ[]ㅁㄴㅇㄹㅎㅗㅓㅏㅣ;' ㅋㅌㅊㅍㅠㅜㅡ,./ . From 96a47877104d99e117b9fd97e43908f9e9567ec5 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sun, 21 Apr 2019 20:15:55 +0100 Subject: [PATCH 19/56] Codechange: Set ZoomLevel's base type to byte instead of using ZoomLevelByte --- src/gfx.cpp | 4 ++-- src/saveload/afterload.cpp | 2 +- src/saveload/misc_sl.cpp | 2 +- src/saveload/saveload_internal.h | 2 +- src/settings_type.h | 4 ++-- src/viewport.cpp | 2 +- src/zoom_func.h | 4 ---- src/zoom_type.h | 14 ++++++-------- 8 files changed, 14 insertions(+), 20 deletions(-) diff --git a/src/gfx.cpp b/src/gfx.cpp index 97ae0f510e..5165fe01c4 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -58,8 +58,8 @@ static void GfxMainBlitter(const Sprite *sprite, int x, int y, BlitterMode mode, static ReusableBuffer _cursor_backup; -ZoomLevelByte _gui_zoom; ///< GUI Zoom level -ZoomLevelByte _font_zoom; ///< Font Zoom level +ZoomLevel _gui_zoom; ///< GUI Zoom level +ZoomLevel _font_zoom; ///< Font Zoom level /** * The rect for repaint. diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 8d9b0ffa6c..b5095c521f 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2834,7 +2834,7 @@ bool AfterLoadGame() if (IsSavegameVersionBefore(SLV_165)) { /* Adjust zoom level to account for new levels */ - _saved_scrollpos_zoom = _saved_scrollpos_zoom + ZOOM_LVL_SHIFT; + _saved_scrollpos_zoom = static_cast(_saved_scrollpos_zoom + ZOOM_LVL_SHIFT); _saved_scrollpos_x *= ZOOM_LVL_BASE; _saved_scrollpos_y *= ZOOM_LVL_BASE; } diff --git a/src/saveload/misc_sl.cpp b/src/saveload/misc_sl.cpp index f0b1309527..4a9b05a461 100644 --- a/src/saveload/misc_sl.cpp +++ b/src/saveload/misc_sl.cpp @@ -30,7 +30,7 @@ extern byte _trees_tick_ctr; /* Keep track of current game position */ int _saved_scrollpos_x; int _saved_scrollpos_y; -ZoomLevelByte _saved_scrollpos_zoom; +ZoomLevel _saved_scrollpos_zoom; void SaveViewportBeforeSaveGame() { diff --git a/src/saveload/saveload_internal.h b/src/saveload/saveload_internal.h index 74e5b9936d..e7a9e7bf5e 100644 --- a/src/saveload/saveload_internal.h +++ b/src/saveload/saveload_internal.h @@ -49,7 +49,7 @@ void CopyTempEngineData(); extern int32 _saved_scrollpos_x; extern int32 _saved_scrollpos_y; -extern ZoomLevelByte _saved_scrollpos_zoom; +extern ZoomLevel _saved_scrollpos_zoom; extern SavegameType _savegame_type; extern uint32 _ttdp_version; diff --git a/src/settings_type.h b/src/settings_type.h index 2459058979..d164be431d 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -107,8 +107,8 @@ struct GUISettings { uint8 statusbar_pos; ///< position of statusbar, 0=left, 1=center, 2=right uint8 window_snap_radius; ///< windows snap at each other if closer than this uint8 window_soft_limit; ///< soft limit of maximum number of non-stickied non-vital windows (0 = no limit) - ZoomLevelByte zoom_min; ///< minimum zoom out level - ZoomLevelByte zoom_max; ///< maximum zoom out level + ZoomLevel zoom_min; ///< minimum zoom out level + ZoomLevel zoom_max; ///< maximum zoom out level bool disable_unsuitable_building; ///< disable infrastructure building when no suitable vehicles are available byte autosave; ///< how often should we do autosaves? bool threaded_saves; ///< should we do threaded saves? diff --git a/src/viewport.cpp b/src/viewport.cpp index 8ec315b16d..8a1319072c 100644 --- a/src/viewport.cpp +++ b/src/viewport.cpp @@ -1692,7 +1692,7 @@ void ViewportDoDraw(const ViewPort *vp, int left, int top, int right, int bottom */ static void ViewportDrawChk(const ViewPort *vp, int left, int top, int right, int bottom) { - if (ScaleByZoom(bottom - top, vp->zoom) * ScaleByZoom(right - left, vp->zoom) > 180000 * ZOOM_LVL_BASE * ZOOM_LVL_BASE) { + if (ScaleByZoom(bottom - top, vp->zoom) * ScaleByZoom(right - left, vp->zoom) > (int)(180000 * ZOOM_LVL_BASE * ZOOM_LVL_BASE)) { if ((bottom - top) > (right - left)) { int t = (top + bottom) >> 1; ViewportDrawChk(vp, left, top, right, t); diff --git a/src/zoom_func.h b/src/zoom_func.h index 0e8fa8c9ef..dff7322a03 100644 --- a/src/zoom_func.h +++ b/src/zoom_func.h @@ -23,7 +23,6 @@ */ static inline int ScaleByZoom(int value, ZoomLevel zoom) { - assert(zoom >= 0); return value << zoom; } @@ -36,7 +35,6 @@ static inline int ScaleByZoom(int value, ZoomLevel zoom) */ static inline int UnScaleByZoom(int value, ZoomLevel zoom) { - assert(zoom >= 0); return (value + (1 << zoom) - 1) >> zoom; } @@ -48,7 +46,6 @@ static inline int UnScaleByZoom(int value, ZoomLevel zoom) */ static inline int ScaleByZoomLower(int value, ZoomLevel zoom) { - assert(zoom >= 0); return value << zoom; } @@ -60,7 +57,6 @@ static inline int ScaleByZoomLower(int value, ZoomLevel zoom) */ static inline int UnScaleByZoomLower(int value, ZoomLevel zoom) { - assert(zoom >= 0); return value >> zoom; } diff --git a/src/zoom_type.h b/src/zoom_type.h index ea8302761f..47a725df2b 100644 --- a/src/zoom_type.h +++ b/src/zoom_type.h @@ -14,11 +14,11 @@ #include "core/enum_type.hpp" -static int const ZOOM_LVL_SHIFT = 2; -static int const ZOOM_LVL_BASE = 1 << ZOOM_LVL_SHIFT; +static uint const ZOOM_LVL_SHIFT = 2; +static uint const ZOOM_LVL_BASE = 1 << ZOOM_LVL_SHIFT; /** All zoom levels we know. */ -enum ZoomLevel { +enum ZoomLevel : byte { /* Our possible zoom-levels */ ZOOM_LVL_BEGIN = 0, ///< Begin for iteration. ZOOM_LVL_NORMAL = 0, ///< The normal zoom level. @@ -46,14 +46,12 @@ enum ZoomLevel { ZOOM_LVL_MIN = ZOOM_LVL_NORMAL, ///< Minimum zoom level. ZOOM_LVL_MAX = ZOOM_LVL_OUT_32X, ///< Maximum zoom level. + }; DECLARE_POSTFIX_INCREMENT(ZoomLevel) -/** Type for storing the zoom level in a byte. */ -typedef SimpleTinyEnumT ZoomLevelByte; - -extern ZoomLevelByte _gui_zoom; -extern ZoomLevelByte _font_zoom; +extern ZoomLevel _gui_zoom; +extern ZoomLevel _font_zoom; #define ZOOM_LVL_GUI (_gui_zoom) #define ZOOM_LVL_FONT (_font_zoom) From 69a6c494bfb81e332e63376f4577a104a5a8e679 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sun, 21 Apr 2019 22:25:54 +0100 Subject: [PATCH 20/56] Codechange: Set VehicleType's base type to byte instead of using VehicleTypeByte --- src/engine_base.h | 2 +- src/group.h | 16 ++++++++-------- src/newgrf.cpp | 2 +- src/smallmap_gui.cpp | 2 +- src/vehicle_type.h | 8 +++----- 5 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/engine_base.h b/src/engine_base.h index ad41f52f20..32c5c9bf6d 100644 --- a/src/engine_base.h +++ b/src/engine_base.h @@ -148,7 +148,7 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> { struct EngineIDMapping { uint32 grfid; ///< The GRF ID of the file the entity belongs to uint16 internal_id; ///< The internal ID within the GRF file - VehicleTypeByte type; ///< The engine type + VehicleType type; ///< The engine type uint8 substitute_id; ///< The (original) entity ID to use if this GRF is not available (currently not used) }; diff --git a/src/group.h b/src/group.h index 4c51e6ebd3..6672cff673 100644 --- a/src/group.h +++ b/src/group.h @@ -65,17 +65,17 @@ struct GroupStatistics { /** Group data. */ struct Group : GroupPool::PoolItem<&_group_pool> { - char *name; ///< Group Name - OwnerByte owner; ///< Group Owner - VehicleTypeByte vehicle_type; ///< Vehicle type of the group + char *name; ///< Group Name + OwnerByte owner; ///< Group Owner + VehicleType vehicle_type; ///< Vehicle type of the group - bool replace_protection; ///< If set to true, the global autoreplace have no effect on the group - Livery livery; ///< Custom colour scheme for vehicles in this group - GroupStatistics statistics; ///< NOSAVE: Statistics and caches on the vehicles in the group. + bool replace_protection; ///< If set to true, the global autoreplace have no effect on the group + Livery livery; ///< Custom colour scheme for vehicles in this group + GroupStatistics statistics; ///< NOSAVE: Statistics and caches on the vehicles in the group. - bool folded; ///< NOSAVE: Is this group folded in the group view? + bool folded; ///< NOSAVE: Is this group folded in the group view? - GroupID parent; ///< Parent group + GroupID parent; ///< Parent group Group(CompanyID owner = INVALID_COMPANY); ~Group(); diff --git a/src/newgrf.cpp b/src/newgrf.cpp index 20408394ee..759c556a79 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -657,7 +657,7 @@ static Engine *GetNewEngine(const GRFFile *file, VehicleType type, uint16 intern _engine_mngr.push_back({ scope_grfid, // Note: this is INVALID_GRFID if dynamic_engines is disabled, so no reservation internal_id, - {static_cast(type)}, + type, static_cast(min(internal_id, _engine_counts[type])) // substitute_id == _engine_counts[subtype] means "no substitute" }); diff --git a/src/smallmap_gui.cpp b/src/smallmap_gui.cpp index 58e89c57fc..aa1e048155 100644 --- a/src/smallmap_gui.cpp +++ b/src/smallmap_gui.cpp @@ -566,7 +566,7 @@ static inline uint32 GetSmallMapOwnerPixels(TileIndex tile, TileType t) return MKCOLOUR_XXXX(_legend_land_owners[_company_to_list_pos[o]].colour); } -/** Vehicle colours in #SMT_VEHICLES mode. Indexed by #VehicleTypeByte. */ +/** Vehicle colours in #SMT_VEHICLES mode. Indexed by #VehicleType. */ static const byte _vehicle_type_colours[6] = { PC_RED, PC_YELLOW, PC_LIGHT_BLUE, PC_WHITE, PC_BLACK, PC_RED }; diff --git a/src/vehicle_type.h b/src/vehicle_type.h index 1bc5bcef41..74bd5660d3 100644 --- a/src/vehicle_type.h +++ b/src/vehicle_type.h @@ -19,8 +19,8 @@ typedef uint32 VehicleID; static const int GROUND_ACCELERATION = 9800; ///< Acceleration due to gravity, 9.8 m/s^2 -/** Available vehicle types. */ -enum VehicleType { +/** Available vehicle types. It needs to be 8bits, because we save and load it as such */ +enum VehicleType : byte { VEH_BEGIN, VEH_TRAIN = VEH_BEGIN, ///< %Train vehicle type. @@ -39,8 +39,6 @@ enum VehicleType { DECLARE_POSTFIX_INCREMENT(VehicleType) /** Helper information for extract tool. */ template <> struct EnumPropsT : MakeEnumPropsT {}; -/** It needs to be 8bits, because we save and load it as such */ -typedef SimpleTinyEnumT VehicleTypeByte; struct Vehicle; struct Train; @@ -53,7 +51,7 @@ struct DisasterVehicle; /** Base vehicle class. */ struct BaseVehicle { - VehicleTypeByte type; ///< Type of vehicle + VehicleType type; ///< Type of vehicle }; static const VehicleID INVALID_VEHICLE = 0xFFFFF; ///< Constant representing a non-existing vehicle. From 0a57db01aff22e9afa368b370d48659854ca4bdd Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sun, 21 Apr 2019 22:30:13 +0100 Subject: [PATCH 21/56] Codechange: Remove TrainForceProceedingByte type --- src/train.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/train.h b/src/train.h index 3bbb6cafbe..b50a9d87b5 100644 --- a/src/train.h +++ b/src/train.h @@ -36,12 +36,11 @@ enum VehicleRailFlags { }; /** Modes for ignoring signals. */ -enum TrainForceProceeding { +enum TrainForceProceeding : byte { TFP_NONE = 0, ///< Normal operation. TFP_STUCK = 1, ///< Proceed till next signal, but ignore being stuck till then. This includes force leaving depots. TFP_SIGNAL = 2, ///< Ignore next signal, after the signal ignore being stuck. }; -typedef SimpleTinyEnumT TrainForceProceedingByte; /** Flags for Train::ConsistChanged */ enum ConsistChangeFlags { @@ -95,7 +94,7 @@ struct Train FINAL : public GroundVehicle { uint16 flags; TrackBitsByte track; - TrainForceProceedingByte force_proceed; + TrainForceProceeding force_proceed; RailTypeByte railtype; RailTypes compatible_railtypes; From 0e439aeab7a564c0673464f6a701463a60d46ed5 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sun, 21 Apr 2019 22:39:32 +0100 Subject: [PATCH 22/56] Codechange: Remove TownFoundingByte type --- src/settings_type.h | 2 +- src/town_type.h | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/settings_type.h b/src/settings_type.h index d164be431d..054f2a7be1 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -485,7 +485,7 @@ struct EconomySettings { TownLayoutByte town_layout; ///< select town layout, @see TownLayout TownCargoGenMode town_cargogen_mode; ///< algorithm for generating cargo from houses, @see TownCargoGenMode bool allow_town_roads; ///< towns are allowed to build roads (always allowed when generating world / in SE) - TownFoundingByte found_town; ///< town founding, @see TownFounding + TownFounding found_town; ///< town founding. bool station_noise_level; ///< build new airports when the town noise level is still within accepted limits uint16 town_noise_population[3]; ///< population to base decision on noise evaluation (@see town_council_tolerance) bool allow_town_level_crossings; ///< towns are allowed to build level crossings diff --git a/src/town_type.h b/src/town_type.h index 608530106e..53df4a0e72 100644 --- a/src/town_type.h +++ b/src/town_type.h @@ -94,16 +94,14 @@ template <> struct EnumPropsT : MakeEnumPropsT TownLayoutByte; // typedefing-enumification of TownLayout -/** Town founding setting values */ -enum TownFounding { +/** Town founding setting values. It needs to be 8bits, because we save and load it as such */ +enum TownFounding : byte { TF_BEGIN = 0, ///< Used for iterations and limit testing TF_FORBIDDEN = 0, ///< Forbidden TF_ALLOWED, ///< Allowed TF_CUSTOM_LAYOUT, ///< Allowed, with custom town layout TF_END, ///< Used for iterations and limit testing }; -/** It needs to be 8bits, because we save and load it as such */ -typedef SimpleTinyEnumT TownFoundingByte; /** Town cargo generation modes */ enum TownCargoGenMode : byte { From f20b75d712c377c1ec639080e38fddb93b83883c Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sun, 21 Apr 2019 22:56:35 +0100 Subject: [PATCH 23/56] Codechange: Remove TownLayoutByte type --- src/saveload/afterload.cpp | 4 ++-- src/settings_type.h | 2 +- src/town.h | 14 +++++++------- src/town_cmd.cpp | 2 +- src/town_type.h | 8 ++------ 5 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index b5095c521f..5e7521d26e 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2110,7 +2110,7 @@ bool AfterLoadGame() _settings_game.economy.town_layout = TL_BETTER_ROADS; } else { _settings_game.economy.allow_town_roads = true; - _settings_game.economy.town_layout = _settings_game.economy.town_layout - 1; + _settings_game.economy.town_layout = static_cast(_settings_game.economy.town_layout - 1); } /* Initialize layout of all towns. Older versions were using different @@ -2129,7 +2129,7 @@ bool AfterLoadGame() case 5: layout = 1; break; case 0: layout = 2; break; } - t->layout = layout - 1; + t->layout = static_cast(layout - 1); } } diff --git a/src/settings_type.h b/src/settings_type.h index 054f2a7be1..83d9091301 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -482,7 +482,7 @@ struct EconomySettings { uint8 town_growth_rate; ///< town growth rate uint8 larger_towns; ///< the number of cities to build. These start off larger and grow twice as fast uint8 initial_city_size; ///< multiplier for the initial size of the cities compared to towns - TownLayoutByte town_layout; ///< select town layout, @see TownLayout + TownLayout town_layout; ///< select town layout, @see TownLayout TownCargoGenMode town_cargogen_mode; ///< algorithm for generating cargo from houses, @see TownCargoGenMode bool allow_town_roads; ///< towns are allowed to build roads (always allowed when generating world / in SE) TownFounding found_town; ///< town founding. diff --git a/src/town.h b/src/town.h index 3d7d00b751..310b4c439d 100644 --- a/src/town.h +++ b/src/town.h @@ -90,16 +90,16 @@ struct Town : TownPool::PoolItem<&_town_pool> { 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 + uint16 time_until_rebuild; ///< time until we rebuild a house - uint16 grow_counter; ///< counter to count when to grow, value is smaller than or equal to growth_rate - uint16 growth_rate; ///< town growth rate + uint16 grow_counter; ///< counter to count when to grow, value is smaller than or equal to growth_rate + uint16 growth_rate; ///< town growth rate - byte fund_buildings_months; ///< fund buildings program in action? - byte road_build_months; ///< fund road reconstruction in action? + byte fund_buildings_months; ///< fund buildings program in action? + byte road_build_months; ///< fund road reconstruction in action? - bool larger_town; ///< if this is a larger town and should grow more quickly - TownLayoutByte layout; ///< town specific road layout + bool larger_town; ///< if this is a larger town and should grow more quickly + TownLayout layout; ///< town specific road layout std::list psa_list; diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index 367eba45f9..ef87d82c5a 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -177,7 +177,7 @@ void Town::InitializeLayout(TownLayout layout) return; } - this->layout = TileHash(TileX(this->xy), TileY(this->xy)) % (NUM_TLS - 1); + this->layout = static_cast(TileHash(TileX(this->xy), TileY(this->xy)) % (NUM_TLS - 1)); } /** diff --git a/src/town_type.h b/src/town_type.h index 53df4a0e72..8204083608 100644 --- a/src/town_type.h +++ b/src/town_type.h @@ -76,10 +76,8 @@ enum Ratings { RATING_BRIBE_DOWN_TO = -50 // XXX SHOULD BE SOMETHING LOWER? }; -/** - * Town Layouts - */ -enum TownLayout { +/** Town Layouts. It needs to be 8bits, because we save and load it as such */ +enum TownLayout : byte { TL_BEGIN = 0, TL_ORIGINAL = 0, ///< Original algorithm (min. 1 distance between roads) TL_BETTER_ROADS, ///< Extended original algorithm (min. 2 distance between roads) @@ -91,8 +89,6 @@ enum TownLayout { NUM_TLS, ///< Number of town layouts }; template <> struct EnumPropsT : MakeEnumPropsT {}; -/** It needs to be 8bits, because we save and load it as such */ -typedef SimpleTinyEnumT TownLayoutByte; // typedefing-enumification of TownLayout /** Town founding setting values. It needs to be 8bits, because we save and load it as such */ enum TownFounding : byte { From 09567bf0b3c6b4e07bdf6ca68286fc302cdcdf69 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sun, 21 Apr 2019 22:59:26 +0100 Subject: [PATCH 24/56] Codechange: Remove StoryPageElementTypeByte type --- src/story_base.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/story_base.h b/src/story_base.h index 139c41dab7..221dcafdf6 100644 --- a/src/story_base.h +++ b/src/story_base.h @@ -27,7 +27,7 @@ extern uint32 _story_page_next_sort_value; /* * Each story page element is one of these types. */ -enum StoryPageElementType { +enum StoryPageElementType : byte { SPET_TEXT = 0, ///< A text element. SPET_LOCATION, ///< An element that references a tile along with a one-line text. SPET_GOAL, ///< An element that references a goal. @@ -37,7 +37,6 @@ enum StoryPageElementType { /** Define basic enum properties */ template <> struct EnumPropsT : MakeEnumPropsT {}; -typedef TinyEnumT StoryPageElementTypeByte; ///< typedefing-enumification of Direction /** * Struct about story page elements. @@ -47,7 +46,7 @@ typedef TinyEnumT StoryPageElementTypeByte; ///< typedefin struct StoryPageElement : StoryPageElementPool::PoolItem<&_story_page_element_pool> { uint32 sort_value; ///< A number that increases for every created story page element. Used for sorting. The id of a story page element is the pool index. StoryPageID page; ///< Id of the page which the page element belongs to - StoryPageElementTypeByte type; ///< Type of page element + StoryPageElementType type; ///< Type of page element uint32 referenced_id; ///< Id of referenced object (location, goal etc.) char *text; ///< Static content text of page element From fb6ae81415f5e8dab48f09cd5cfde994a90c950f Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sun, 21 Apr 2019 23:01:29 +0100 Subject: [PATCH 25/56] Codechange: Remove StationFacilityByte type --- src/base_station_base.h | 2 +- src/station_type.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/base_station_base.h b/src/base_station_base.h index d7a67bd657..70164b1935 100644 --- a/src/base_station_base.h +++ b/src/base_station_base.h @@ -61,7 +61,7 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> { Town *town; ///< The town this station is associated with OwnerByte owner; ///< The owner of this station - StationFacilityByte facilities; ///< The facilities that this station has + StationFacility facilities; ///< The facilities that this station has uint8 num_specs; ///< Number of specs in the speclist StationSpecList *speclist; ///< List of station specs of this station diff --git a/src/station_type.h b/src/station_type.h index 42d64fcf89..48c1c343c9 100644 --- a/src/station_type.h +++ b/src/station_type.h @@ -49,7 +49,7 @@ enum RoadStopType { }; /** The facilities a station might be having */ -enum StationFacility { +enum StationFacility : byte { FACIL_NONE = 0, ///< The station has no facilities at all FACIL_TRAIN = 1 << 0, ///< Station with train station FACIL_TRUCK_STOP = 1 << 1, ///< Station with truck stops @@ -59,7 +59,6 @@ enum StationFacility { FACIL_WAYPOINT = 1 << 7, ///< Station is a waypoint }; DECLARE_ENUM_AS_BIT_SET(StationFacility) -typedef SimpleTinyEnumT StationFacilityByte; /** The vehicles that may have visited a station */ enum StationHadVehicleOfType { From 119ea7a1959835f242daf988e5a0aabf7a2f41dd Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sun, 21 Apr 2019 23:13:27 +0100 Subject: [PATCH 26/56] Codechange: Remove StationHadVehicleOfTypeByte type --- src/station_base.h | 2 +- src/station_type.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/station_base.h b/src/station_base.h index 794fbdfdfc..b211e2bd48 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -470,7 +470,7 @@ public: BitmapTileArea catchment_tiles; ///< NOSAVE: Set of individual tiles covered by catchment area - StationHadVehicleOfTypeByte had_vehicle_of_type; + StationHadVehicleOfType had_vehicle_of_type; byte time_since_load; byte time_since_unload; diff --git a/src/station_type.h b/src/station_type.h index 48c1c343c9..9afbc22056 100644 --- a/src/station_type.h +++ b/src/station_type.h @@ -61,7 +61,7 @@ enum StationFacility : byte { DECLARE_ENUM_AS_BIT_SET(StationFacility) /** The vehicles that may have visited a station */ -enum StationHadVehicleOfType { +enum StationHadVehicleOfType : byte { HVOT_NONE = 0, ///< Station has seen no vehicles HVOT_TRAIN = 1 << 1, ///< Station has seen a train HVOT_BUS = 1 << 2, ///< Station has seen a bus @@ -72,7 +72,6 @@ enum StationHadVehicleOfType { HVOT_WAYPOINT = 1 << 6, ///< Station is a waypoint (NewGRF only!) }; DECLARE_ENUM_AS_BIT_SET(StationHadVehicleOfType) -typedef SimpleTinyEnumT StationHadVehicleOfTypeByte; /** The different catchment areas used */ enum CatchmentArea { From 10ba431d21f58c707398f95b99faf3c2aac77e77 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Mon, 22 Apr 2019 07:22:06 +0100 Subject: [PATCH 27/56] Codechange: Remove SpriteTypeByte type --- src/gfx_type.h | 2 +- src/spritecache.cpp | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/gfx_type.h b/src/gfx_type.h index 7eeddb4078..cc884b06df 100644 --- a/src/gfx_type.h +++ b/src/gfx_type.h @@ -294,7 +294,7 @@ enum PaletteType { }; /** Types of sprites that might be loaded */ -enum SpriteType { +enum SpriteType : byte { ST_NORMAL = 0, ///< The most basic (normal) sprite ST_MAPGEN = 1, ///< Special sprite for the map generator ST_FONT = 2, ///< A sprite used for fonts diff --git a/src/spritecache.cpp b/src/spritecache.cpp index bed8c42e31..bcc0048278 100644 --- a/src/spritecache.cpp +++ b/src/spritecache.cpp @@ -29,15 +29,13 @@ /* Default of 4MB spritecache */ uint _sprite_cache_size = 4; -typedef SimpleTinyEnumT SpriteTypeByte; - struct SpriteCache { void *ptr; size_t file_pos; uint32 id; uint16 file_slot; int16 lru; - SpriteTypeByte type; ///< In some cases a single sprite is misused by two NewGRFs. Once as real sprite and once as recolour sprite. If the recolour sprite gets into the cache it might be drawn as real sprite which causes enormous trouble. + SpriteType type; ///< In some cases a single sprite is misused by two NewGRFs. Once as real sprite and once as recolour sprite. If the recolour sprite gets into the cache it might be drawn as real sprite which causes enormous trouble. bool warned; ///< True iff the user has been warned about incorrect use of this sprite byte container_ver; ///< Container version of the GRF the sprite is from. }; From 931d32f4145e36ef08b432314353ff9f058f6a08 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Mon, 22 Apr 2019 07:39:52 +0100 Subject: [PATCH 28/56] Codechange: Remove RailTypeByte type --- src/build_vehicle_gui.cpp | 4 ++-- src/engine_type.h | 2 +- src/newgrf.h | 2 +- src/rail_type.h | 3 +-- src/saveload/oldloader_sl.cpp | 3 ++- src/script/api/script_rail.cpp | 2 +- src/table/engines.h | 2 +- src/train.h | 2 +- 8 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/build_vehicle_gui.cpp b/src/build_vehicle_gui.cpp index b528d6fedd..32310b9c35 100644 --- a/src/build_vehicle_gui.cpp +++ b/src/build_vehicle_gui.cpp @@ -1014,8 +1014,8 @@ void DisplayVehicleSortDropDown(Window *w, VehicleType vehicle_type, int selecte struct BuildVehicleWindow : Window { VehicleType vehicle_type; ///< Type of vehicles shown in the window. union { - RailTypeByte railtype; ///< Rail type to show, or #RAILTYPE_END. - RoadTypes roadtypes; ///< Road type to show, or #ROADTYPES_ALL. + RailType railtype; ///< Rail type to show, or #RAILTYPE_END. + RoadTypes roadtypes; ///< Road type to show, or #ROADTYPES_ALL. } filter; ///< Filter to apply. bool descending_sort_order; ///< Sort direction, @see _engine_sort_direction byte sort_criteria; ///< Current sort criterium. diff --git a/src/engine_type.h b/src/engine_type.h index 82f10d9d87..1cc0452a5f 100644 --- a/src/engine_type.h +++ b/src/engine_type.h @@ -44,7 +44,7 @@ struct RailVehicleInfo { byte image_index; RailVehicleTypes railveh_type; byte cost_factor; ///< Purchase cost factor; For multiheaded engines the sum of both engine prices. - RailTypeByte railtype; + RailType railtype; uint16 max_speed; ///< Maximum speed (1 unit = 1/1.6 mph = 1 km-ish/h) uint16 power; ///< Power of engine (hp); For multiheaded engines the sum of both engine powers. uint16 weight; ///< Weight of vehicle (tons); For multiheaded engines the weight of each single engine. diff --git a/src/newgrf.h b/src/newgrf.h index e5140d4eeb..c36005b0f2 100644 --- a/src/newgrf.h +++ b/src/newgrf.h @@ -126,7 +126,7 @@ struct GRFFile : ZeroedMemoryAllocator { uint8 cargo_map[NUM_CARGO]; ///< Inverse cargo translation table (CargoID -> local ID) std::vector railtype_list; ///< Railtype translation table - RailTypeByte railtype_map[RAILTYPE_END]; + RailType railtype_map[RAILTYPE_END]; CanalProperties canal_local_properties[CF_END]; ///< Canal properties as set by this NewGRF diff --git a/src/rail_type.h b/src/rail_type.h index 2bd602a37e..7e465866cf 100644 --- a/src/rail_type.h +++ b/src/rail_type.h @@ -26,7 +26,7 @@ static const RailTypeLabel RAILTYPE_MAGLEV_LABEL = 'MGLV'; * * This enumeration defines all 4 possible railtypes. */ -enum RailType { +enum RailType : byte { RAILTYPE_BEGIN = 0, ///< Used for iterations RAILTYPE_RAIL = 0, ///< Standard non-electric rails RAILTYPE_ELECTRIC = 1, ///< Electric rails @@ -44,7 +44,6 @@ enum RailType { DECLARE_POSTFIX_INCREMENT(RailType) /** Define basic enum properties */ template <> struct EnumPropsT : MakeEnumPropsT {}; -typedef TinyEnumT RailTypeByte; /** * The different railtypes we support, but then a bitmask of them. diff --git a/src/saveload/oldloader_sl.cpp b/src/saveload/oldloader_sl.cpp index 1590cb655e..f7309a474e 100644 --- a/src/saveload/oldloader_sl.cpp +++ b/src/saveload/oldloader_sl.cpp @@ -1277,7 +1277,8 @@ bool LoadOldVehicle(LoadgameState *ls, int num) }; if (v->spritenum / 2 >= lengthof(spriteset_rail)) return false; v->spritenum = spriteset_rail[v->spritenum / 2]; // adjust railway sprite set offset - Train::From(v)->railtype = type == 0x25 ? 1 : 0; // monorail / rail + /* Should be the original values for monorail / rail, can't use RailType constants */ + Train::From(v)->railtype = static_cast(type == 0x25 ? 1 : 0); break; } diff --git a/src/script/api/script_rail.cpp b/src/script/api/script_rail.cpp index d4580fc322..f9495ac2d1 100644 --- a/src/script/api/script_rail.cpp +++ b/src/script/api/script_rail.cpp @@ -68,7 +68,7 @@ /* static */ bool ScriptRail::IsRailTypeAvailable(RailType rail_type) { - if ((::RailType)rail_type < RAILTYPE_BEGIN || (::RailType)rail_type >= RAILTYPE_END) return false; + if ((::RailType)rail_type >= RAILTYPE_END) return false; return ScriptObject::GetCompany() == OWNER_DEITY || ::HasRailtypeAvail(ScriptObject::GetCompany(), (::RailType)rail_type); } diff --git a/src/table/engines.h b/src/table/engines.h index 3b29a8dc17..a5acd28439 100644 --- a/src/table/engines.h +++ b/src/table/engines.h @@ -388,7 +388,7 @@ static const EngineInfo _orig_engine_info[] = { * Tractive effort coefficient by default is the same as TTDPatch, 0.30*256=76 * Air drag value depends on the top speed of the vehicle. */ -#define RVI(a, b, c, d, e, f, g, h, i, j, k) { a, b, c, {j}, d, e, f, g, h, k, i, 0, 0, 0, VE_DEFAULT, 0, 76, 0, 0 } +#define RVI(a, b, c, d, e, f, g, h, i, j, k) { a, b, c, j, d, e, f, g, h, k, i, 0, 0, 0, VE_DEFAULT, 0, 76, 0, 0 } #define M RAILVEH_MULTIHEAD #define W RAILVEH_WAGON #define G RAILVEH_SINGLEHEAD diff --git a/src/train.h b/src/train.h index b50a9d87b5..0256f63521 100644 --- a/src/train.h +++ b/src/train.h @@ -95,7 +95,7 @@ struct Train FINAL : public GroundVehicle { uint16 flags; TrackBitsByte track; TrainForceProceeding force_proceed; - RailTypeByte railtype; + RailType railtype; RailTypes compatible_railtypes; /** Ticks waiting in front of a signal, ticks being stuck or a counter for forced proceeding through signals. */ From 9f3928658bb3f8aaf21b17e0144cb09722474fff Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Mon, 22 Apr 2019 08:03:04 +0100 Subject: [PATCH 29/56] Codechange: Remove Track{dir,}{Bits,}Byte types --- src/pathfinder/yapf/yapf_road.cpp | 4 +--- src/pathfinder/yapf/yapf_ship.cpp | 4 +--- src/roadveh.h | 2 +- src/ship.h | 4 ++-- src/track_type.h | 12 ++++-------- src/train.h | 2 +- 6 files changed, 10 insertions(+), 18 deletions(-) diff --git a/src/pathfinder/yapf/yapf_road.cpp b/src/pathfinder/yapf/yapf_road.cpp index 3122dd1114..9e206115f9 100644 --- a/src/pathfinder/yapf/yapf_road.cpp +++ b/src/pathfinder/yapf/yapf_road.cpp @@ -390,9 +390,7 @@ public: while (pNode->m_parent != nullptr) { steps--; if (pNode->GetIsChoice() && steps < YAPF_ROADVEH_PATH_CACHE_SEGMENTS) { - TrackdirByte td; - td = pNode->GetTrackdir(); - path_cache.td.push_front(td); + path_cache.td.push_front(pNode->GetTrackdir()); path_cache.tile.push_front(pNode->GetTile()); } pNode = pNode->m_parent; diff --git a/src/pathfinder/yapf/yapf_ship.cpp b/src/pathfinder/yapf/yapf_ship.cpp index e7391d6869..09a4fc76a8 100644 --- a/src/pathfinder/yapf/yapf_ship.cpp +++ b/src/pathfinder/yapf/yapf_ship.cpp @@ -98,9 +98,7 @@ public: while (pNode->m_parent != nullptr) { steps--; if (steps > 0 && steps < YAPF_SHIP_PATH_CACHE_LENGTH) { - TrackdirByte td; - td = pNode->GetTrackdir(); - path_cache.push_front(td); + path_cache.push_front(pNode->GetTrackdir()); } pPrevNode = pNode; pNode = pNode->m_parent; diff --git a/src/roadveh.h b/src/roadveh.h index 22f827b1de..7c8f32d0f8 100644 --- a/src/roadveh.h +++ b/src/roadveh.h @@ -84,7 +84,7 @@ void RoadVehUpdateCache(RoadVehicle *v, bool same_length = false); void GetRoadVehSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type); struct RoadVehPathCache { - std::deque td; + std::deque td; std::deque tile; inline bool empty() const { return this->td.empty(); } diff --git a/src/ship.h b/src/ship.h index 6f818efb2c..807e69c5e6 100644 --- a/src/ship.h +++ b/src/ship.h @@ -20,13 +20,13 @@ void GetShipSpriteSize(EngineID engine, uint &width, uint &height, int &xoffs, int &yoffs, EngineImageType image_type); WaterClass GetEffectiveWaterClass(TileIndex tile); -typedef std::deque ShipPathCache; +typedef std::deque ShipPathCache; /** * All ships have this type. */ struct Ship FINAL : public SpecializedVehicle { - TrackBitsByte state; ///< The "track" the ship is following. + TrackBits state; ///< The "track" the ship is following. ShipPathCache path; ///< Cached path. DirectionByte rotation; ///< Visible direction. int16 rotation_x_pos; ///< NOSAVE: X Position before rotation. diff --git a/src/track_type.h b/src/track_type.h index 2982288bba..233376b006 100644 --- a/src/track_type.h +++ b/src/track_type.h @@ -18,7 +18,7 @@ * These are used to specify a single track. * Can be translated to a trackbit with TrackToTrackbit */ -enum Track { +enum Track : byte { TRACK_BEGIN = 0, ///< Used for iterations TRACK_X = 0, ///< Track along the x-axis (north-east to south-west) TRACK_Y = 1, ///< Track along the y-axis (north-west to south-east) @@ -34,11 +34,10 @@ enum Track { DECLARE_POSTFIX_INCREMENT(Track) /** Define basic enum properties */ template <> struct EnumPropsT : MakeEnumPropsT {}; -typedef TinyEnumT TrackByte; /** Bitfield corresponding to Track */ -enum TrackBits { +enum TrackBits : byte { TRACK_BIT_NONE = 0U, ///< No track TRACK_BIT_X = 1U << TRACK_X, ///< X-axis track TRACK_BIT_Y = 1U << TRACK_Y, ///< Y-axis track @@ -60,7 +59,6 @@ enum TrackBits { INVALID_TRACK_BIT = 0xFF, ///< Flag for an invalid trackbits value }; DECLARE_ENUM_AS_BIT_SET(TrackBits) -typedef SimpleTinyEnumT TrackBitsByte; /** * Enumeration for tracks and directions. @@ -71,7 +69,7 @@ typedef SimpleTinyEnumT TrackBitsByte; * reversing track dirs are not considered to be 'valid' except in a small * corner in the road vehicle controller. */ -enum Trackdir { +enum Trackdir : byte { TRACKDIR_BEGIN = 0, ///< Used for iterations TRACKDIR_X_NE = 0, ///< X-axis and direction to north-east TRACKDIR_Y_SE = 1, ///< Y-axis and direction to south-east @@ -95,7 +93,6 @@ enum Trackdir { /** Define basic enum properties */ template <> struct EnumPropsT : MakeEnumPropsT {}; -typedef TinyEnumT TrackdirByte; /** * Enumeration of bitmasks for the TrackDirs @@ -103,7 +100,7 @@ typedef TinyEnumT TrackdirByte; * These are a combination of tracks and directions. Values are 0-5 in one * direction (corresponding to the Track enum) and 8-13 in the other direction. */ -enum TrackdirBits { +enum TrackdirBits : uint16 { TRACKDIR_BIT_NONE = 0U, ///< No track build TRACKDIR_BIT_X_NE = 1U << TRACKDIR_X_NE, ///< Track x-axis, direction north-east TRACKDIR_BIT_Y_SE = 1U << TRACKDIR_Y_SE, ///< Track y-axis, direction south-east @@ -122,7 +119,6 @@ enum TrackdirBits { INVALID_TRACKDIR_BIT = 0xFFFF, ///< Flag for an invalid trackdirbit value }; DECLARE_ENUM_AS_BIT_SET(TrackdirBits) -typedef SimpleTinyEnumT TrackdirBitsShort; typedef uint32 TrackStatus; diff --git a/src/train.h b/src/train.h index 0256f63521..e122fcf2f9 100644 --- a/src/train.h +++ b/src/train.h @@ -93,7 +93,7 @@ struct Train FINAL : public GroundVehicle { uint16 crash_anim_pos; ///< Crash animation counter. uint16 flags; - TrackBitsByte track; + TrackBits track; TrainForceProceeding force_proceed; RailType railtype; RailTypes compatible_railtypes; From 96097b34a57feb7547c789b352e9b650fb2a9fea Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Mon, 22 Apr 2019 08:11:28 +0100 Subject: [PATCH 30/56] Codechange: Remove Direction*Byte types --- src/aircraft.h | 2 +- src/airport.h | 8 ++++---- src/direction_type.h | 6 ++---- src/ship.h | 10 +++++----- src/station_base.h | 2 +- src/table/airport_movement.h | 2 +- src/vehicle_base.h | 2 +- 7 files changed, 15 insertions(+), 17 deletions(-) diff --git a/src/aircraft.h b/src/aircraft.h index f4fce09be1..3abb86b4f0 100644 --- a/src/aircraft.h +++ b/src/aircraft.h @@ -79,7 +79,7 @@ struct Aircraft FINAL : public SpecializedVehicle { byte previous_pos; ///< Previous desired position of the aircraft. StationID targetairport; ///< Airport to go to next. byte state; ///< State of the airport. @see AirportMovementStates - DirectionByte last_direction; + Direction last_direction; byte number_consecutive_turns; ///< Protection to prevent the aircraft of making a lot of turns in order to reach a specific point. byte turn_counter; ///< Ticks between each turn to prevent > 45 degree turns. byte flags; ///< Aircraft flags. @see AirVehicleFlags diff --git a/src/airport.h b/src/airport.h index 31c68ef002..9e9eee8703 100644 --- a/src/airport.h +++ b/src/airport.h @@ -130,10 +130,10 @@ static const uint64 /** A single location on an airport where aircraft can move to. */ struct AirportMovingData { - int16 x; ///< x-coordinate of the destination. - int16 y; ///< y-coordinate of the destination. - uint16 flag; ///< special flags when moving towards the destination. - DirectionByte direction; ///< Direction to turn the aircraft after reaching the destination. + int16 x; ///< x-coordinate of the destination. + int16 y; ///< y-coordinate of the destination. + uint16 flag; ///< special flags when moving towards the destination. + Direction direction; ///< Direction to turn the aircraft after reaching the destination. }; AirportMovingData RotateAirportMovingData(const AirportMovingData *orig, Direction rotation, uint num_tiles_x, uint num_tiles_y); diff --git a/src/direction_type.h b/src/direction_type.h index e6e08a182f..cf6b9f5cf1 100644 --- a/src/direction_type.h +++ b/src/direction_type.h @@ -23,7 +23,7 @@ * your viewport and not rotated by 45 degrees left or right to get * a "north" used in you games. */ -enum Direction { +enum Direction : byte { DIR_BEGIN = 0, ///< Used to iterate DIR_N = 0, ///< North DIR_NE = 1, ///< Northeast @@ -42,7 +42,6 @@ DECLARE_POSTFIX_INCREMENT(Direction) /** Define basic enum properties */ template <> struct EnumPropsT : MakeEnumPropsT {}; -typedef TinyEnumT DirectionByte; ///< typedefing-enumification of Direction /** @@ -77,7 +76,7 @@ enum DirDiff { * * This enumeration is used for the 4 direction of the tile-edges. */ -enum DiagDirection { +enum DiagDirection : byte { DIAGDIR_BEGIN = 0, ///< Used for iterations DIAGDIR_NE = 0, ///< Northeast, upper right on your monitor DIAGDIR_SE = 1, ///< Southeast @@ -92,7 +91,6 @@ DECLARE_POSTFIX_INCREMENT(DiagDirection) /** Define basic enum properties */ template <> struct EnumPropsT : MakeEnumPropsT {}; -typedef TinyEnumT DiagDirectionByte; ///< typedefing-enumification of DiagDirection /** diff --git a/src/ship.h b/src/ship.h index 807e69c5e6..fff0aee5cb 100644 --- a/src/ship.h +++ b/src/ship.h @@ -26,11 +26,11 @@ typedef std::deque ShipPathCache; * All ships have this type. */ struct Ship FINAL : public SpecializedVehicle { - TrackBits state; ///< The "track" the ship is following. - ShipPathCache path; ///< Cached path. - DirectionByte rotation; ///< Visible direction. - int16 rotation_x_pos; ///< NOSAVE: X Position before rotation. - int16 rotation_y_pos; ///< NOSAVE: Y Position before rotation. + TrackBits state; ///< The "track" the ship is following. + ShipPathCache path; ///< Cached path. + Direction rotation; ///< Visible direction. + int16 rotation_x_pos; ///< NOSAVE: X Position before rotation. + int16 rotation_y_pos; ///< NOSAVE: Y Position before rotation. /** We don't want GCC to zero our struct! It already is zeroed and has an index! */ Ship() : SpecializedVehicleBase() {} diff --git a/src/station_base.h b/src/station_base.h index b211e2bd48..a0cb2c015f 100644 --- a/src/station_base.h +++ b/src/station_base.h @@ -310,7 +310,7 @@ struct Airport : public TileArea { uint64 flags; ///< stores which blocks on the airport are taken. was 16 bit earlier on, then 32 byte type; ///< Type of this airport, @see AirportTypes byte layout; ///< Airport layout number. - DirectionByte rotation; ///< How this airport is rotated. + Direction rotation; ///< How this airport is rotated. PersistentStorage *psa; ///< Persistent storage for NewGRF airports. diff --git a/src/table/airport_movement.h b/src/table/airport_movement.h index d9030f652c..df368de892 100644 --- a/src/table/airport_movement.h +++ b/src/table/airport_movement.h @@ -34,7 +34,7 @@ struct AirportFTAbuildup { * @param flags Movement flags. * @param dir Direction. */ -#define AMD(x, y, flags, dir) { x, y, flags, {dir} } +#define AMD(x, y, flags, dir) { x, y, flags, dir } /** Dummy airport. */ static const AirportMovingData _airport_moving_data_dummy[] = { diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 523f1c2638..9ccb671138 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -268,7 +268,7 @@ public: int32 x_pos; ///< x coordinate. int32 y_pos; ///< y coordinate. int32 z_pos; ///< z coordinate. - DirectionByte direction; ///< facing + Direction direction; ///< facing OwnerByte owner; ///< Which company owns the vehicle? /** From 60e31c7cfa2a79afa37a0f2e76b592920e5388fe Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Mon, 22 Apr 2019 08:16:45 +0100 Subject: [PATCH 31/56] Codechange: Remove OrderTypeByte --- src/order_cmd.cpp | 2 +- src/order_type.h | 10 +++------- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/src/order_cmd.cpp b/src/order_cmd.cpp index 1a9d648c6d..26b999af72 100644 --- a/src/order_cmd.cpp +++ b/src/order_cmd.cpp @@ -1465,7 +1465,7 @@ CommandCost CmdModifyOrder(TileIndex tile, DoCommandFlag flags, uint32 p1, uint3 * whether we are not going to a depot as there are three * cases where the full load flag can be active and only * one case where the flag is used for depot orders. In the - * other cases for the OrderTypeByte the flags are not used, + * other cases for the OrderType the flags are not used, * so do not care and those orders should not be active * when this function is called. */ diff --git a/src/order_type.h b/src/order_type.h index b1e0fad539..c150bc273b 100644 --- a/src/order_type.h +++ b/src/order_type.h @@ -33,8 +33,8 @@ static const OrderID INVALID_ORDER = 0xFFFFFF; */ static const uint IMPLICIT_ORDER_ONLY_CAP = 32; -/** Order types */ -enum OrderType { +/** Order types. It needs to be 8bits, because we save and load it as such */ +enum OrderType : byte { OT_BEGIN = 0, OT_NOTHING = 0, OT_GOTO_STATION = 1, @@ -44,14 +44,10 @@ enum OrderType { OT_DUMMY = 5, OT_GOTO_WAYPOINT = 6, OT_CONDITIONAL = 7, - OT_IMPLICIT = 8, + OT_IMPLICIT = 8, OT_END }; -/** It needs to be 8bits, because we save and load it as such */ -typedef SimpleTinyEnumT OrderTypeByte; - - /** * Flags related to the unloading order. */ From fcf06ba4c43bb9b7ac0b8541377a5240b3e01126 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Mon, 22 Apr 2019 08:19:04 +0100 Subject: [PATCH 32/56] Codechange: Remove StationClassIDByte, and drop STAT_CLASS_MAX by one --- src/newgrf_station.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/newgrf_station.h b/src/newgrf_station.h index 8f3bb6dcec..eff76e57df 100644 --- a/src/newgrf_station.h +++ b/src/newgrf_station.h @@ -79,13 +79,12 @@ struct StationResolverObject : public ResolverObject { const SpriteGroup *ResolveReal(const RealSpriteGroup *group) const override; }; -enum StationClassID { +enum StationClassID : byte { STAT_CLASS_BEGIN = 0, ///< the lowest valid value STAT_CLASS_DFLT = 0, ///< Default station class. STAT_CLASS_WAYP, ///< Waypoint class. - STAT_CLASS_MAX = 256, ///< Maximum number of classes. + STAT_CLASS_MAX = 255, ///< Maximum number of classes. }; -typedef SimpleTinyEnumT StationClassIDByte; template <> struct EnumPropsT : MakeEnumPropsT {}; /** Allow incrementing of StationClassID variables */ From 5b34c8019f135afd9f20d043a489ab96f286038a Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Mon, 22 Apr 2019 09:10:04 +0100 Subject: [PATCH 33/56] Codechange: Remove Company/OwnerByte types --- src/ai/ai_core.cpp | 18 +++++++++--------- src/ai/ai_gui.cpp | 2 +- src/aircraft_cmd.cpp | 6 +++--- src/base_station_base.h | 2 +- src/command.cpp | 2 +- src/company_base.h | 2 +- src/company_cmd.cpp | 4 ++-- src/company_func.h | 4 ++-- src/company_type.h | 4 +--- src/console_cmds.cpp | 3 +-- src/disaster_vehicle.cpp | 4 ++-- src/economy.cpp | 18 +++++++++--------- src/engine_base.h | 4 ++-- src/game/game_core.cpp | 12 ++++++------ src/genworld.cpp | 2 +- src/goal.cpp | 2 +- src/goal_base.h | 12 ++++++------ src/group.h | 2 +- src/industry.h | 4 ++-- src/industry_cmd.cpp | 14 +++++++------- src/industry_gui.cpp | 2 +- src/misc_cmd.cpp | 4 ++-- src/network/network_client.cpp | 2 +- src/openttd.cpp | 2 +- src/rail_cmd.cpp | 2 +- src/roadveh_cmd.cpp | 2 +- src/saveload/afterload.cpp | 2 +- src/saveload/waypoint_sl.cpp | 2 +- src/script/api/script_cargomonitor.cpp | 8 ++++---- src/signs_base.h | 2 +- src/story_base.h | 2 +- src/subsidy_base.h | 2 +- src/town.h | 2 +- src/town_cmd.cpp | 10 +++++----- src/vehicle.cpp | 4 ++-- src/vehicle_base.h | 2 +- src/water_cmd.cpp | 4 ++-- 37 files changed, 86 insertions(+), 89 deletions(-) diff --git a/src/ai/ai_core.cpp b/src/ai/ai_core.cpp index cc2eb42c8b..23ee16c83f 100644 --- a/src/ai/ai_core.cpp +++ b/src/ai/ai_core.cpp @@ -52,7 +52,7 @@ } config->AnchorUnchangeableSettings(); - Backup cur_company(_current_company, company, FILE_LINE); + Backup cur_company(_current_company, company, FILE_LINE); Company *c = Company::Get(company); c->ai_info = info; @@ -76,7 +76,7 @@ assert(_settings_game.difficulty.competitor_speed <= 4); if ((AI::frame_counter & ((1 << (4 - _settings_game.difficulty.competitor_speed)) - 1)) != 0) return; - Backup cur_company(_current_company, FILE_LINE); + Backup cur_company(_current_company, FILE_LINE); const Company *c; FOR_ALL_COMPANIES(c) { if (c->is_ai) { @@ -107,7 +107,7 @@ if (_networking && !_network_server) return; PerformanceMeasurer::SetInactive((PerformanceElement)(PFE_AI0 + company)); - Backup cur_company(_current_company, company, FILE_LINE); + Backup cur_company(_current_company, company, FILE_LINE); Company *c = Company::Get(company); delete c->ai_instance; @@ -127,7 +127,7 @@ * for the server owner to unpause the script again. */ if (_network_dedicated) return; - Backup cur_company(_current_company, company, FILE_LINE); + Backup cur_company(_current_company, company, FILE_LINE); Company::Get(company)->ai_instance->Pause(); cur_company.Restore(); @@ -135,7 +135,7 @@ /* static */ void AI::Unpause(CompanyID company) { - Backup cur_company(_current_company, company, FILE_LINE); + Backup cur_company(_current_company, company, FILE_LINE); Company::Get(company)->ai_instance->Unpause(); cur_company.Restore(); @@ -143,7 +143,7 @@ /* static */ bool AI::IsPaused(CompanyID company) { - Backup cur_company(_current_company, company, FILE_LINE); + Backup cur_company(_current_company, company, FILE_LINE); bool paused = Company::Get(company)->ai_instance->IsPaused(); cur_company.Restore(); @@ -253,7 +253,7 @@ } /* Queue the event */ - Backup cur_company(_current_company, company, FILE_LINE); + Backup cur_company(_current_company, company, FILE_LINE); Company::Get(_current_company)->ai_instance->InsertEvent(event); cur_company.Restore(); @@ -285,7 +285,7 @@ Company *c = Company::GetIfValid(company); assert(c != nullptr && c->ai_instance != nullptr); - Backup cur_company(_current_company, company, FILE_LINE); + Backup cur_company(_current_company, company, FILE_LINE); c->ai_instance->Save(); cur_company.Restore(); } else { @@ -299,7 +299,7 @@ Company *c = Company::GetIfValid(company); assert(c != nullptr && c->ai_instance != nullptr); - Backup cur_company(_current_company, company, FILE_LINE); + Backup cur_company(_current_company, company, FILE_LINE); c->ai_instance->Load(version); cur_company.Restore(); } else { diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp index 4932c0f612..91f8969046 100644 --- a/src/ai/ai_gui.cpp +++ b/src/ai/ai_gui.cpp @@ -810,7 +810,7 @@ struct AIConfigWindow : public Window { if (_game_mode != GM_NORMAL) { return slot > 0 && slot <= GetGameSettings().difficulty.max_no_competitors; } - if (Company::IsValidID(slot) || slot < 0) return false; + if (Company::IsValidID(slot)) return false; int max_slot = GetGameSettings().difficulty.max_no_competitors; for (CompanyID cid = COMPANY_FIRST; cid < (CompanyID)max_slot && cid < MAX_COMPANIES; cid++) { diff --git a/src/aircraft_cmd.cpp b/src/aircraft_cmd.cpp index 409daf7893..5cb3504040 100644 --- a/src/aircraft_cmd.cpp +++ b/src/aircraft_cmd.cpp @@ -1233,7 +1233,7 @@ void HandleMissingAircraftOrders(Aircraft *v) */ const Station *st = GetTargetAirportIfValid(v); if (st == nullptr) { - Backup cur_company(_current_company, v->owner, FILE_LINE); + Backup cur_company(_current_company, v->owner, FILE_LINE); CommandCost ret = DoCommand(v->tile, v->index, 0, DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT); cur_company.Restore(); @@ -1588,7 +1588,7 @@ static void AircraftEventHandler_HeliTakeOff(Aircraft *v, const AirportFTAClass /* Send the helicopter to a hangar if needed for replacement */ if (v->NeedsAutomaticServicing()) { - Backup cur_company(_current_company, v->owner, FILE_LINE); + Backup cur_company(_current_company, v->owner, FILE_LINE); DoCommand(v->tile, v->index | DEPOT_SERVICE | DEPOT_LOCATE_HANGAR, 0, DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT); cur_company.Restore(); } @@ -1639,7 +1639,7 @@ static void AircraftEventHandler_Landing(Aircraft *v, const AirportFTAClass *apc /* check if the aircraft needs to be replaced or renewed and send it to a hangar if needed */ if (v->NeedsAutomaticServicing()) { - Backup cur_company(_current_company, v->owner, FILE_LINE); + Backup cur_company(_current_company, v->owner, FILE_LINE); DoCommand(v->tile, v->index | DEPOT_SERVICE, 0, DC_EXEC, CMD_SEND_VEHICLE_TO_DEPOT); cur_company.Restore(); } diff --git a/src/base_station_base.h b/src/base_station_base.h index 70164b1935..eaeb246ef1 100644 --- a/src/base_station_base.h +++ b/src/base_station_base.h @@ -60,7 +60,7 @@ struct BaseStation : StationPool::PoolItem<&_station_pool> { StringID string_id; ///< Default name (town area) of station Town *town; ///< The town this station is associated with - OwnerByte owner; ///< The owner of this station + Owner owner; ///< The owner of this station StationFacility facilities; ///< The facilities that this station has uint8 num_specs; ///< Number of specs in the speclist diff --git a/src/command.cpp b/src/command.cpp index 7f5dd4309b..8a92c3478c 100644 --- a/src/command.cpp +++ b/src/command.cpp @@ -660,7 +660,7 @@ CommandCost DoCommandPInternal(TileIndex tile, uint32 p1, uint32 p2, uint32 cmd, return_dcpi(CMD_ERROR); } - Backup cur_company(_current_company, FILE_LINE); + Backup cur_company(_current_company, FILE_LINE); if (exec_as_spectator) cur_company.Change(COMPANY_SPECTATOR); bool test_and_exec_can_differ = (cmd_flags & CMD_NO_TEST) != 0; diff --git a/src/company_base.h b/src/company_base.h index 309130f591..27ae96fce2 100644 --- a/src/company_base.h +++ b/src/company_base.h @@ -72,7 +72,7 @@ struct CompanyProperties { TileIndex location_of_HQ; ///< Northern tile of HQ; #INVALID_TILE when there is none. TileIndex last_build_coordinate; ///< Coordinate of the last build thing by this company. - OwnerByte share_owners[4]; ///< Owners of the 4 shares of the company. #INVALID_OWNER if nobody has bought them yet. + Owner share_owners[4]; ///< Owners of the 4 shares of the company. #INVALID_OWNER if nobody has bought them yet. Year inaugurated_year; ///< Year of starting the company. diff --git a/src/company_cmd.cpp b/src/company_cmd.cpp index 3cf55cf1e9..fe4163acd8 100644 --- a/src/company_cmd.cpp +++ b/src/company_cmd.cpp @@ -43,8 +43,8 @@ void ClearEnginesHiddenFlagOfCompany(CompanyID cid); -CompanyByte _local_company; ///< Company controlled by the human player at this client. Can also be #COMPANY_SPECTATOR. -CompanyByte _current_company; ///< Company currently doing an action. +CompanyID _local_company; ///< Company controlled by the human player at this client. Can also be #COMPANY_SPECTATOR. +CompanyID _current_company; ///< Company currently doing an action. Colours _company_colours[MAX_COMPANIES]; ///< NOSAVE: can be determined from company structs. CompanyManagerFace _company_manager_face; ///< for company manager face storage in openttd.cfg uint _next_competitor_start; ///< the number of ticks before the next AI is started diff --git a/src/company_func.h b/src/company_func.h index 29650d78cd..99041b6d42 100644 --- a/src/company_func.h +++ b/src/company_func.h @@ -32,8 +32,8 @@ void SubtractMoneyFromCompanyFract(CompanyID company, CommandCost cost); CommandCost CheckOwnership(Owner owner, TileIndex tile = 0); CommandCost CheckTileOwnership(TileIndex tile); -extern CompanyByte _local_company; -extern CompanyByte _current_company; +extern CompanyID _local_company; +extern CompanyID _current_company; extern Colours _company_colours[MAX_COMPANIES]; extern CompanyManagerFace _company_manager_face; diff --git a/src/company_type.h b/src/company_type.h index 771e6d8b93..576a57bf16 100644 --- a/src/company_type.h +++ b/src/company_type.h @@ -17,7 +17,7 @@ /** * Enum for all companies/owners. */ -enum Owner { +enum Owner : byte { /* All companies below MAX_COMPANIES are playable * companies, above, they are special, computer controlled 'companies' */ OWNER_BEGIN = 0x00, ///< First owner @@ -45,10 +45,8 @@ static const uint MAX_HISTORY_QUARTERS = 24; ///< The maximum number /** Define basic enum properties */ template <> struct EnumPropsT : MakeEnumPropsT {}; -typedef TinyEnumT OwnerByte; typedef Owner CompanyID; -typedef OwnerByte CompanyByte; typedef uint16 CompanyMask; diff --git a/src/console_cmds.cpp b/src/console_cmds.cpp index 2b74f1d000..740bbdde88 100644 --- a/src/console_cmds.cpp +++ b/src/console_cmds.cpp @@ -858,8 +858,7 @@ DEF_CONSOLE_CMD(ConNetworkReconnect) default: /* From a user pov 0 is a new company, internally it's different and all * companies are offset by one to ease up on users (eg companies 1-8 not 0-7) */ - playas--; - if (playas < COMPANY_FIRST || playas >= MAX_COMPANIES) return false; + if (playas < COMPANY_FIRST + 1 || playas > MAX_COMPANIES + 1) return false; break; } diff --git a/src/disaster_vehicle.cpp b/src/disaster_vehicle.cpp index f934ca3e68..57ca0e9f8b 100644 --- a/src/disaster_vehicle.cpp +++ b/src/disaster_vehicle.cpp @@ -62,7 +62,7 @@ static void DisasterClearSquare(TileIndex tile) switch (GetTileType(tile)) { case MP_RAILWAY: if (Company::IsHumanID(GetTileOwner(tile)) && !IsRailDepot(tile)) { - Backup cur_company(_current_company, OWNER_WATER, FILE_LINE); + Backup cur_company(_current_company, OWNER_WATER, FILE_LINE); DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); cur_company.Restore(); @@ -72,7 +72,7 @@ static void DisasterClearSquare(TileIndex tile) break; case MP_HOUSE: { - Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); + Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); DoCommand(tile, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); cur_company.Restore(); break; diff --git a/src/economy.cpp b/src/economy.cpp index b4b2988366..ad48ce25ef 100644 --- a/src/economy.cpp +++ b/src/economy.cpp @@ -291,14 +291,14 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner) /* We need to set _current_company to old_owner before we try to move * the client. This is needed as it needs to know whether "you" really * are the current local company. */ - Backup cur_company(_current_company, old_owner, FILE_LINE); + Backup cur_company(_current_company, old_owner, FILE_LINE); /* In all cases, make spectators of clients connected to that company */ if (_networking) NetworkClientsToSpectators(old_owner); if (old_owner == _local_company) { /* Single player cheated to AI company. * There are no spectators in single player, so we must pick some other company. */ assert(!_networking); - Backup cur_company2(_current_company, FILE_LINE); + Backup cur_company2(_current_company, FILE_LINE); Company *c; FOR_ALL_COMPANIES(c) { if (c->index != old_owner) { @@ -332,7 +332,7 @@ void ChangeOwnershipOfCompanyItems(Owner old_owner, Owner new_owner) } /* Sell all the shares that people have on this company */ - Backup cur_company2(_current_company, FILE_LINE); + Backup cur_company2(_current_company, FILE_LINE); c = Company::Get(old_owner); for (i = 0; i < 4; i++) { cur_company2.Change(c->share_owners[i]); @@ -665,7 +665,7 @@ static void CompaniesGenStatistics() CompanyCheckBankrupt(c); } - Backup cur_company(_current_company, FILE_LINE); + Backup cur_company(_current_company, FILE_LINE); if (!_settings_game.economy.infrastructure_maintenance) { Station *st; @@ -835,7 +835,7 @@ static void CompaniesPayInterest() { const Company *c; - Backup cur_company(_current_company, FILE_LINE); + Backup cur_company(_current_company, FILE_LINE); FOR_ALL_COMPANIES(c) { cur_company.Change(c->index); @@ -1191,7 +1191,7 @@ CargoPayment::~CargoPayment() if (this->visual_profit == 0 && this->visual_transfer == 0) return; - Backup cur_company(_current_company, this->front->owner, FILE_LINE); + Backup cur_company(_current_company, this->front->owner, FILE_LINE); SubtractMoneyFromCompany(CommandCost(this->front->GetExpenseType(true), -this->route_profit)); this->front->profit_this_year += (this->visual_profit + this->visual_transfer) << 8; @@ -1478,7 +1478,7 @@ static void HandleStationRefit(Vehicle *v, CargoArray &consist_capleft, Station Vehicle *v_start = v->GetFirstEnginePart(); if (!IterateVehicleParts(v_start, IsEmptyAction())) return; - Backup cur_company(_current_company, v->owner, FILE_LINE); + Backup cur_company(_current_company, v->owner, FILE_LINE); CargoTypes refit_mask = v->GetEngine()->info.refit_mask; @@ -2042,7 +2042,7 @@ CommandCost CmdBuyShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1, cost.AddCost(CalculateCompanyValue(c) >> 2); if (flags & DC_EXEC) { - OwnerByte *b = c->share_owners; + Owner *b = c->share_owners; while (*b != COMPANY_SPECTATOR) b++; // share owners is guaranteed to contain at least one COMPANY_SPECTATOR *b = _current_company; @@ -2089,7 +2089,7 @@ CommandCost CmdSellShareInCompany(TileIndex tile, DoCommandFlag flags, uint32 p1 cost = -(cost - (cost >> 7)); if (flags & DC_EXEC) { - OwnerByte *b = c->share_owners; + Owner *b = c->share_owners; while (*b != _current_company) b++; // share owners is guaranteed to contain company *b = COMPANY_SPECTATOR; InvalidateWindowData(WC_COMPANY, target_company); diff --git a/src/engine_base.h b/src/engine_base.h index 32c5c9bf6d..a8dbb873c1 100644 --- a/src/engine_base.h +++ b/src/engine_base.h @@ -34,7 +34,7 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> { uint16 duration_phase_3; ///< Third reliability phase on months, decaying to #reliability_final. byte flags; ///< Flags of the engine. @see EngineFlags CompanyMask preview_asked; ///< Bit for each company which has already been offered a preview. - CompanyByte preview_company;///< Company which is currently being offered a preview \c INVALID_COMPANY means no company. + CompanyID preview_company; ///< Company which is currently being offered a preview \c INVALID_COMPANY means no company. byte preview_wait; ///< Daily countdown timer for timeout of offering the engine to the #preview_company company. CompanyMask company_avail; ///< Bit for each company whether the engine is available for that company. CompanyMask company_hidden; ///< Bit for each company whether the engine is normally hidden in the build gui for that company. @@ -118,7 +118,7 @@ struct Engine : EnginePool::PoolItem<&_engine_pool> { * @param c Company to check. * @return \c true iff the engine is hidden in the GUI for the given company. */ - inline bool IsHidden(CompanyByte c) const + inline bool IsHidden(CompanyID c) const { return c < MAX_COMPANIES && HasBit(this->company_hidden, c); } diff --git a/src/game/game_core.cpp b/src/game/game_core.cpp index 181e8b6bbc..394b77fb83 100644 --- a/src/game/game_core.cpp +++ b/src/game/game_core.cpp @@ -45,7 +45,7 @@ Game::frame_counter++; - Backup cur_company(_current_company, FILE_LINE); + Backup cur_company(_current_company, FILE_LINE); cur_company.Change(OWNER_DEITY); Game::instance->GameLoop(); cur_company.Restore(); @@ -84,7 +84,7 @@ config->AnchorUnchangeableSettings(); - Backup cur_company(_current_company, FILE_LINE); + Backup cur_company(_current_company, FILE_LINE); cur_company.Change(OWNER_DEITY); Game::info = info; @@ -98,7 +98,7 @@ /* static */ void Game::Uninitialize(bool keepConfig) { - Backup cur_company(_current_company, FILE_LINE); + Backup cur_company(_current_company, FILE_LINE); delete Game::instance; Game::instance = nullptr; @@ -158,7 +158,7 @@ } /* Queue the event */ - Backup cur_company(_current_company, OWNER_DEITY, FILE_LINE); + Backup cur_company(_current_company, OWNER_DEITY, FILE_LINE); Game::instance->InsertEvent(event); cur_company.Restore(); @@ -207,7 +207,7 @@ /* static */ void Game::Save() { if (Game::instance != nullptr && (!_networking || _network_server)) { - Backup cur_company(_current_company, OWNER_DEITY, FILE_LINE); + Backup cur_company(_current_company, OWNER_DEITY, FILE_LINE); Game::instance->Save(); cur_company.Restore(); } else { @@ -218,7 +218,7 @@ /* static */ void Game::Load(int version) { if (Game::instance != nullptr && (!_networking || _network_server)) { - Backup cur_company(_current_company, OWNER_DEITY, FILE_LINE); + Backup cur_company(_current_company, OWNER_DEITY, FILE_LINE); Game::instance->Load(version); cur_company.Restore(); } else { diff --git a/src/genworld.cpp b/src/genworld.cpp index f09b183e97..6aaf1a6fe0 100644 --- a/src/genworld.cpp +++ b/src/genworld.cpp @@ -97,7 +97,7 @@ static void CleanupGeneration() static void _GenerateWorld() { /* Make sure everything is done via OWNER_NONE. */ - Backup _cur_company(_current_company, OWNER_NONE, FILE_LINE); + Backup _cur_company(_current_company, OWNER_NONE, FILE_LINE); std::unique_lock lock(_modal_progress_work_mutex, std::defer_lock); try { diff --git a/src/goal.cpp b/src/goal.cpp index b545c84d25..30f640b4ce 100644 --- a/src/goal.cpp +++ b/src/goal.cpp @@ -79,7 +79,7 @@ CommandCost CmdCreateGoal(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 case GT_STORY_PAGE: { if (!StoryPage::IsValidID(p2)) return CMD_ERROR; - CompanyByte story_company = StoryPage::Get(p2)->company; + CompanyID story_company = StoryPage::Get(p2)->company; if (company == INVALID_COMPANY ? story_company != INVALID_COMPANY : story_company != INVALID_COMPANY && story_company != company) return CMD_ERROR; break; } diff --git a/src/goal_base.h b/src/goal_base.h index f82afa5be9..532c47ea3b 100644 --- a/src/goal_base.h +++ b/src/goal_base.h @@ -21,12 +21,12 @@ extern GoalPool _goal_pool; /** Struct about goals, current and completed */ struct Goal : GoalPool::PoolItem<&_goal_pool> { - CompanyByte company; ///< Goal is for a specific company; INVALID_COMPANY if it is global - GoalTypeByte type; ///< Type of the goal - GoalTypeID dst; ///< Index of type - char *text; ///< Text of the goal. - char *progress; ///< Progress text of the goal. - bool completed; ///< Is the goal completed or not? + CompanyID company; ///< Goal is for a specific company; INVALID_COMPANY if it is global + GoalTypeByte type; ///< Type of the goal + GoalTypeID dst; ///< Index of type + char *text; ///< Text of the goal. + char *progress; ///< Progress text of the goal. + bool completed; ///< Is the goal completed or not? /** * We need an (empty) constructor so struct isn't zeroed (as C++ standard states) diff --git a/src/group.h b/src/group.h index 6672cff673..57488d394b 100644 --- a/src/group.h +++ b/src/group.h @@ -66,7 +66,7 @@ struct GroupStatistics { /** Group data. */ struct Group : GroupPool::PoolItem<&_group_pool> { char *name; ///< Group Name - OwnerByte owner; ///< Group Owner + Owner owner; ///< Group Owner VehicleType vehicle_type; ///< Vehicle type of the group bool replace_protection; ///< If set to true, the global autoreplace have no effect on the group diff --git a/src/industry.h b/src/industry.h index 4822976f24..2816729590 100644 --- a/src/industry.h +++ b/src/industry.h @@ -57,7 +57,7 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> { uint16 counter; ///< used for animation and/or production (if available cargo) IndustryType type; ///< type of industry. - OwnerByte owner; ///< owner of the industry. Which SHOULD always be (imho) OWNER_NONE + Owner owner; ///< owner of the industry. Which SHOULD always be (imho) OWNER_NONE byte random_colour; ///< randomized colour of the industry, for display purpose Year last_prod_year; ///< last year of production byte was_cargo_delivered; ///< flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry @@ -65,7 +65,7 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> { PartOfSubsidyByte part_of_subsidy; ///< NOSAVE: is this industry a source/destination of a subsidy? StationList stations_near; ///< NOSAVE: List of nearby stations. - OwnerByte founder; ///< Founder of the industry + Owner founder; ///< Founder of the industry Date construction_date; ///< Date of the construction of the industry uint8 construction_type; ///< Way the industry was constructed (@see IndustryConstructionType) Date last_cargo_accepted_at[INDUSTRY_NUM_INPUTS]; ///< Last day each cargo type was accepted by this industry diff --git a/src/industry_cmd.cpp b/src/industry_cmd.cpp index 9978145fac..06c6cde567 100644 --- a/src/industry_cmd.cpp +++ b/src/industry_cmd.cpp @@ -1077,7 +1077,7 @@ static bool SearchLumberMillTrees(TileIndex tile, void *user_data) if (IsTileType(tile, MP_TREES) && GetTreeGrowth(tile) > 2) { ///< 3 and up means all fully grown trees /* found a tree */ - Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); + Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); _industry_sound_ctr = 1; _industry_sound_tile = tile; @@ -1436,7 +1436,7 @@ static CommandCost CheckIfIndustryTilesAreFree(TileIndex tile, const IndustryTil } /* Clear the tiles as OWNER_TOWN to not affect town rating, and to not clear protected buildings */ - Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); + Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); CommandCost ret = DoCommand(cur_tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR); cur_company.Restore(); @@ -1541,7 +1541,7 @@ static bool CheckIfCanLevelIndustryPlatform(TileIndex tile, DoCommandFlag flags, /* _current_company is OWNER_NONE for randomly generated industries and in editor, or the company who funded or prospected the industry. * Perform terraforming as OWNER_TOWN to disable autoslope and town ratings. */ - Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); + Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); TILE_AREA_LOOP(tile_walk, ta) { uint curh = TileHeight(tile_walk); @@ -1966,7 +1966,7 @@ CommandCost CmdBuildIndustry(TileIndex tile, DoCommandFlag flags, uint32 p1, uin if (deity_prospect || (_game_mode != GM_EDITOR && _current_company != OWNER_DEITY && _settings_game.construction.raw_industry_construction == 2 && indspec->IsRawIndustry())) { if (flags & DC_EXEC) { /* Prospected industries are build as OWNER_TOWN to not e.g. be build on owned land of the founder */ - Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); + Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); /* Prospecting has a chance to fail, however we cannot guarantee that something can * be built on the map, so the chance gets lower when the map is fuller, but there * is nothing we can really do about that. */ @@ -2128,7 +2128,7 @@ static Industry *PlaceIndustry(IndustryType type, IndustryAvailabilityCallType c */ static void PlaceInitialIndustry(IndustryType type, bool try_hard) { - Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); + Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); IncreaseGeneratingWorldProgress(GWP_INDUSTRY); PlaceIndustry(type, IACT_MAPGENERATION, try_hard); @@ -2760,7 +2760,7 @@ void IndustryDailyLoop() return; // Nothing to do? get out } - Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); + Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); /* perform the required industry changes for the day */ @@ -2788,7 +2788,7 @@ void IndustryDailyLoop() void IndustryMonthlyLoop() { - Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); + Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); _industry_builder.MonthlyLoop(); diff --git a/src/industry_gui.cpp b/src/industry_gui.cpp index f698ace570..f341f76d62 100644 --- a/src/industry_gui.cpp +++ b/src/industry_gui.cpp @@ -655,7 +655,7 @@ public: return; } - Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); + Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); _generating_world = true; _ignore_restrictions = true; diff --git a/src/misc_cmd.cpp b/src/misc_cmd.cpp index b78ec948be..f0ccfbd744 100644 --- a/src/misc_cmd.cpp +++ b/src/misc_cmd.cpp @@ -223,7 +223,7 @@ CommandCost CmdChangeBankBalance(TileIndex tile, DoCommandFlag flags, uint32 p1, if (flags & DC_EXEC) { /* Change company bank balance of company. */ - Backup cur_company(_current_company, company, FILE_LINE); + Backup cur_company(_current_company, company, FILE_LINE); SubtractMoneyFromCompany(CommandCost(expenses_type, -delta)); cur_company.Restore(); } @@ -259,7 +259,7 @@ CommandCost CmdGiveMoney(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 if (flags & DC_EXEC) { /* Add money to company */ - Backup cur_company(_current_company, dest_company, FILE_LINE); + Backup cur_company(_current_company, dest_company, FILE_LINE); SubtractMoneyFromCompany(CommandCost(EXPENSES_OTHER, -amount.GetCost())); cur_company.Restore(); } diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 7ebbdef51a..717e41b836 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -1232,7 +1232,7 @@ void NetworkClientRequestMove(CompanyID company_id, const char *pass) */ void NetworkClientsToSpectators(CompanyID cid) { - Backup cur_company(_current_company, FILE_LINE); + Backup cur_company(_current_company, FILE_LINE); /* If our company is changing owner, go to spectators */ if (cid == _local_company) SetLocalCompany(COMPANY_SPECTATOR); diff --git a/src/openttd.cpp b/src/openttd.cpp index b9bc7c9854..243302d619 100644 --- a/src/openttd.cpp +++ b/src/openttd.cpp @@ -1377,7 +1377,7 @@ void StateGameLoop() /* All these actions has to be done from OWNER_NONE * for multiplayer compatibility */ - Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); + Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); BasePersistentStorageArray::SwitchMode(PSM_ENTER_GAMELOOP); AnimateAnimatedTiles(); diff --git a/src/rail_cmd.cpp b/src/rail_cmd.cpp index 6964a5aaf0..0804a4d14a 100644 --- a/src/rail_cmd.cpp +++ b/src/rail_cmd.cpp @@ -764,7 +764,7 @@ bool FloodHalftile(TileIndex t) TrackBits to_remove = lower_track & rail_bits; if (to_remove != 0) { - Backup cur_company(_current_company, OWNER_WATER, FILE_LINE); + Backup cur_company(_current_company, OWNER_WATER, FILE_LINE); flooded = DoCommand(t, 0, FIND_FIRST_BIT(to_remove), DC_EXEC, CMD_REMOVE_SINGLE_RAIL).Succeeded(); cur_company.Restore(); if (!flooded) return flooded; // not yet floodable diff --git a/src/roadveh_cmd.cpp b/src/roadveh_cmd.cpp index 7086d151d0..9f98c3e885 100644 --- a/src/roadveh_cmd.cpp +++ b/src/roadveh_cmd.cpp @@ -1126,7 +1126,7 @@ static Trackdir FollowPreviousRoadVehicle(const RoadVehicle *v, const RoadVehicl static bool CanBuildTramTrackOnTile(CompanyID c, TileIndex t, RoadBits r) { /* The 'current' company is not necessarily the owner of the vehicle. */ - Backup cur_company(_current_company, c, FILE_LINE); + Backup cur_company(_current_company, c, FILE_LINE); CommandCost ret = DoCommand(t, ROADTYPE_TRAM << 4 | r, 0, DC_NO_WATER, CMD_BUILD_ROAD); diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 5e7521d26e..9bdfa6b34c 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -1835,7 +1835,7 @@ bool AfterLoadGame() if (IsBuoyTile(t) || IsDriveThroughStopTile(t) || IsTileType(t, MP_WATER)) { Owner o = GetTileOwner(t); if (o < MAX_COMPANIES && !Company::IsValidID(o)) { - Backup cur_company(_current_company, o, FILE_LINE); + Backup cur_company(_current_company, o, FILE_LINE); ChangeTileOwner(t, o, INVALID_OWNER); cur_company.Restore(); } diff --git a/src/saveload/waypoint_sl.cpp b/src/saveload/waypoint_sl.cpp index 66ef145fc2..70a1a27394 100644 --- a/src/saveload/waypoint_sl.cpp +++ b/src/saveload/waypoint_sl.cpp @@ -36,7 +36,7 @@ struct OldWaypoint { uint8 localidx; uint32 grfid; const StationSpec *spec; - OwnerByte owner; + Owner owner; size_t new_index; }; diff --git a/src/script/api/script_cargomonitor.cpp b/src/script/api/script_cargomonitor.cpp index 3cb9b4a8e7..e862fed3e6 100644 --- a/src/script/api/script_cargomonitor.cpp +++ b/src/script/api/script_cargomonitor.cpp @@ -20,7 +20,7 @@ /* static */ int32 ScriptCargoMonitor::GetTownDeliveryAmount(ScriptCompany::CompanyID company, CargoID cargo, TownID town_id, bool keep_monitoring) { CompanyID cid = static_cast(company); - if (cid < OWNER_BEGIN || cid >= MAX_COMPANIES) return -1; + if (cid >= MAX_COMPANIES) return -1; if (!ScriptCargo::IsValidCargo(cargo)) return -1; if (!::Town::IsValidID(town_id)) return -1; @@ -31,7 +31,7 @@ /* static */ int32 ScriptCargoMonitor::GetIndustryDeliveryAmount(ScriptCompany::CompanyID company, CargoID cargo, IndustryID industry_id, bool keep_monitoring) { CompanyID cid = static_cast(company); - if (cid < OWNER_BEGIN || cid >= MAX_COMPANIES) return -1; + if (cid >= MAX_COMPANIES) return -1; if (!ScriptCargo::IsValidCargo(cargo)) return -1; if (!::Industry::IsValidID(industry_id)) return -1; @@ -42,7 +42,7 @@ /* static */ int32 ScriptCargoMonitor::GetTownPickupAmount(ScriptCompany::CompanyID company, CargoID cargo, TownID town_id, bool keep_monitoring) { CompanyID cid = static_cast(company); - if (cid < OWNER_BEGIN || cid >= MAX_COMPANIES) return -1; + if (cid >= MAX_COMPANIES) return -1; if (!ScriptCargo::IsValidCargo(cargo)) return -1; if (!::Town::IsValidID(town_id)) return -1; @@ -53,7 +53,7 @@ /* static */ int32 ScriptCargoMonitor::GetIndustryPickupAmount(ScriptCompany::CompanyID company, CargoID cargo, IndustryID industry_id, bool keep_monitoring) { CompanyID cid = static_cast(company); - if (cid < OWNER_BEGIN || cid >= MAX_COMPANIES) return -1; + if (cid >= MAX_COMPANIES) return -1; if (!ScriptCargo::IsValidCargo(cargo)) return -1; if (!::Industry::IsValidID(industry_id)) return -1; diff --git a/src/signs_base.h b/src/signs_base.h index 3e7b4c4651..a4ee0718b7 100644 --- a/src/signs_base.h +++ b/src/signs_base.h @@ -26,7 +26,7 @@ struct Sign : SignPool::PoolItem<&_sign_pool> { int32 x; int32 y; int32 z; - OwnerByte owner; // placed by this company. Anyone can delete them though. OWNER_NONE for gray signs from old games. + Owner owner; // placed by this company. Anyone can delete them though. OWNER_NONE for gray signs from old games. Sign(Owner owner = INVALID_OWNER); ~Sign(); diff --git a/src/story_base.h b/src/story_base.h index 221dcafdf6..4cc857b8d3 100644 --- a/src/story_base.h +++ b/src/story_base.h @@ -69,7 +69,7 @@ struct StoryPageElement : StoryPageElementPool::PoolItem<&_story_page_element_po struct StoryPage : StoryPagePool::PoolItem<&_story_page_pool> { uint32 sort_value; ///< A number that increases for every created story page. Used for sorting. The id of a story page is the pool index. Date date; ///< Date when the page was created. - CompanyByte company; ///< StoryPage is for a specific company; INVALID_COMPANY if it is global + CompanyID company; ///< StoryPage is for a specific company; INVALID_COMPANY if it is global char *title; ///< Title of story page diff --git a/src/subsidy_base.h b/src/subsidy_base.h index 780302e0a2..6370a77e63 100644 --- a/src/subsidy_base.h +++ b/src/subsidy_base.h @@ -24,7 +24,7 @@ extern SubsidyPool _subsidy_pool; struct Subsidy : SubsidyPool::PoolItem<&_subsidy_pool> { CargoID cargo_type; ///< Cargo type involved in this subsidy, CT_INVALID for invalid subsidy byte remaining; ///< Remaining months when this subsidy is valid - CompanyByte awarded; ///< Subsidy is awarded to this company; INVALID_COMPANY if it's not awarded to anyone + CompanyID awarded; ///< Subsidy is awarded to this company; INVALID_COMPANY if it's not awarded to anyone SourceTypeByte src_type; ///< Source of subsidised path (ST_INDUSTRY or ST_TOWN) SourceTypeByte dst_type; ///< Destination of subsidised path (ST_INDUSTRY or ST_TOWN) SourceID src; ///< Index of source. Either TownID or IndustryID diff --git a/src/town.h b/src/town.h index 310b4c439d..8e8a6551d5 100644 --- a/src/town.h +++ b/src/town.h @@ -72,7 +72,7 @@ struct Town : TownPool::PoolItem<&_town_pool> { /* Company ratings. */ CompanyMask have_ratings; ///< which companies have a rating uint8 unwanted[MAX_COMPANIES]; ///< how many months companies aren't wanted by towns (bribe) - CompanyByte exclusivity; ///< which company has exclusivity + CompanyID exclusivity; ///< which company has exclusivity uint8 exclusive_counter; ///< months till the exclusivity expires int16 ratings[MAX_COMPANIES]; ///< ratings of each company for this town diff --git a/src/town_cmd.cpp b/src/town_cmd.cpp index ef87d82c5a..f3acfb4a38 100644 --- a/src/town_cmd.cpp +++ b/src/town_cmd.cpp @@ -599,7 +599,7 @@ static void TileLoop_Town(TileIndex tile) } } - Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); + Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); if ((hs->building_flags & BUILDING_HAS_1_TILE) && HasBit(t->flags, TOWN_IS_GROWING) && @@ -1566,7 +1566,7 @@ static bool GrowTown(Town *t) }; /* Current "company" is a town */ - Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); + Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); TileIndex tile = t->xy; // The tile we are working with ATM @@ -2042,7 +2042,7 @@ static Town *CreateRandomTown(uint attempts, uint32 townnameparts, TownSize size * placement is so bad it couldn't grow at all */ if (t->cache.population > 0) return t; - Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); + Backup cur_company(_current_company, OWNER_TOWN, FILE_LINE); CommandCost rc = DoCommand(t->xy, t->index, 0, DC_EXEC, CMD_DELETE_TOWN); cur_company.Restore(); assert(rc.Succeeded()); @@ -2940,7 +2940,7 @@ static CommandCost TownActionRoadRebuild(Town *t, DoCommandFlag flags) */ static bool TryClearTile(TileIndex tile) { - Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); + Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); CommandCost r = DoCommand(tile, 0, 0, DC_NONE, CMD_LANDSCAPE_CLEAR); cur_company.Restore(); return r.Succeeded(); @@ -3012,7 +3012,7 @@ static CommandCost TownActionBuildStatue(Town *t, DoCommandFlag flags) if (!CircularTileSearch(&tile, 9, SearchTileForStatue, &statue_data)) return_cmd_error(STR_ERROR_STATUE_NO_SUITABLE_PLACE); if (flags & DC_EXEC) { - Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); + Backup cur_company(_current_company, OWNER_NONE, FILE_LINE); DoCommand(statue_data.best_position, 0, 0, DC_EXEC, CMD_LANDSCAPE_CLEAR); cur_company.Restore(); BuildObject(OBJECT_STATUE, statue_data.best_position, _current_company, t); diff --git a/src/vehicle.cpp b/src/vehicle.cpp index e6df365b05..031b6f95e3 100644 --- a/src/vehicle.cpp +++ b/src/vehicle.cpp @@ -1027,7 +1027,7 @@ void CallVehicleTicks() } } - Backup cur_company(_current_company, FILE_LINE); + Backup cur_company(_current_company, FILE_LINE); for (auto &it : _vehicles_to_autoreplace) { v = it.first; /* Autoreplace needs the current company set as the vehicle owner */ @@ -1514,7 +1514,7 @@ void VehicleEnterDepot(Vehicle *v) } if (v->current_order.IsRefit()) { - Backup cur_company(_current_company, v->owner, FILE_LINE); + Backup cur_company(_current_company, v->owner, FILE_LINE); CommandCost cost = DoCommand(v->tile, v->index, v->current_order.GetRefitCargo() | 0xFF << 8, DC_EXEC, GetCmdRefitVeh(v)); cur_company.Restore(); diff --git a/src/vehicle_base.h b/src/vehicle_base.h index 9ccb671138..2b091c340f 100644 --- a/src/vehicle_base.h +++ b/src/vehicle_base.h @@ -270,7 +270,7 @@ public: int32 z_pos; ///< z coordinate. Direction direction; ///< facing - OwnerByte owner; ///< Which company owns the vehicle? + Owner owner; ///< Which company owns the vehicle? /** * currently displayed sprite index * 0xfd == custom sprite, 0xfe == custom second head sprite diff --git a/src/water_cmd.cpp b/src/water_cmd.cpp index e3247ec665..b603d7411b 100644 --- a/src/water_cmd.cpp +++ b/src/water_cmd.cpp @@ -1044,7 +1044,7 @@ void DoFloodTile(TileIndex target) bool flooded = false; // Will be set to true if something is changed. - Backup cur_company(_current_company, OWNER_WATER, FILE_LINE); + Backup cur_company(_current_company, OWNER_WATER, FILE_LINE); Slope tileh = GetTileSlope(target); if (tileh != SLOPE_FLAT) { @@ -1105,7 +1105,7 @@ void DoFloodTile(TileIndex target) */ static void DoDryUp(TileIndex tile) { - Backup cur_company(_current_company, OWNER_WATER, FILE_LINE); + Backup cur_company(_current_company, OWNER_WATER, FILE_LINE); switch (GetTileType(tile)) { case MP_RAILWAY: From 2e1936da6453265758d6830e5664474a319fd8a7 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Mon, 22 Apr 2019 09:28:09 +0100 Subject: [PATCH 34/56] Codechange: Remove SourceTypeByte type --- src/cargo_type.h | 3 +-- src/cargopacket.h | 14 +++++++------- src/subsidy_base.h | 14 +++++++------- 3 files changed, 15 insertions(+), 16 deletions(-) diff --git a/src/cargo_type.h b/src/cargo_type.h index 79d1c84f46..78c04ae727 100644 --- a/src/cargo_type.h +++ b/src/cargo_type.h @@ -145,12 +145,11 @@ public: /** Types of cargo source and destination */ -enum SourceType { +enum SourceType : byte { ST_INDUSTRY, ///< Source/destination is an industry ST_TOWN, ///< Source/destination is a town ST_HEADQUARTERS, ///< Source/destination are company headquarters }; -typedef SimpleTinyEnumT SourceTypeByte; ///< The SourceType packed into a byte for savegame purposes. typedef uint16 SourceID; ///< Contains either industry ID, town ID or company ID (or INVALID_SOURCE) static const SourceID INVALID_SOURCE = 0xFFFF; ///< Invalid/unknown index of source diff --git a/src/cargopacket.h b/src/cargopacket.h index 4354327970..0e2a1bc976 100644 --- a/src/cargopacket.h +++ b/src/cargopacket.h @@ -43,13 +43,13 @@ typedef uint32 TileOrStationID; */ struct CargoPacket : CargoPacketPool::PoolItem<&_cargopacket_pool> { private: - Money feeder_share; ///< Value of feeder pickup to be paid for on delivery of cargo. - uint16 count; ///< The amount of cargo in this packet. - byte days_in_transit; ///< Amount of days this packet has been in transit. - SourceTypeByte source_type; ///< Type of \c source_id. - SourceID source_id; ///< Index of source, INVALID_SOURCE if unknown/invalid. - StationID source; ///< The station where the cargo came from first. - TileIndex source_xy; ///< The origin of the cargo (first station in feeder chain). + Money feeder_share; ///< Value of feeder pickup to be paid for on delivery of cargo. + uint16 count; ///< The amount of cargo in this packet. + byte days_in_transit; ///< Amount of days this packet has been in transit. + SourceType source_type; ///< Type of \c source_id. + SourceID source_id; ///< Index of source, INVALID_SOURCE if unknown/invalid. + StationID source; ///< The station where the cargo came from first. + TileIndex source_xy; ///< The origin of the cargo (first station in feeder chain). union { TileOrStationID loaded_at_xy; ///< Location where this cargo has been loaded into the vehicle. TileOrStationID next_station; ///< Station where the cargo wants to go next. diff --git a/src/subsidy_base.h b/src/subsidy_base.h index 6370a77e63..a7f6f4f3ee 100644 --- a/src/subsidy_base.h +++ b/src/subsidy_base.h @@ -22,13 +22,13 @@ extern SubsidyPool _subsidy_pool; /** Struct about subsidies, offered and awarded */ struct Subsidy : SubsidyPool::PoolItem<&_subsidy_pool> { - CargoID cargo_type; ///< Cargo type involved in this subsidy, CT_INVALID for invalid subsidy - byte remaining; ///< Remaining months when this subsidy is valid - CompanyID awarded; ///< Subsidy is awarded to this company; INVALID_COMPANY if it's not awarded to anyone - SourceTypeByte src_type; ///< Source of subsidised path (ST_INDUSTRY or ST_TOWN) - SourceTypeByte dst_type; ///< Destination of subsidised path (ST_INDUSTRY or ST_TOWN) - SourceID src; ///< Index of source. Either TownID or IndustryID - SourceID dst; ///< Index of destination. Either TownID or IndustryID + CargoID cargo_type; ///< Cargo type involved in this subsidy, CT_INVALID for invalid subsidy + byte remaining; ///< Remaining months when this subsidy is valid + CompanyID awarded; ///< Subsidy is awarded to this company; INVALID_COMPANY if it's not awarded to anyone + SourceType src_type; ///< Source of subsidised path (ST_INDUSTRY or ST_TOWN) + SourceType dst_type; ///< Destination of subsidised path (ST_INDUSTRY or ST_TOWN) + SourceID src; ///< Index of source. Either TownID or IndustryID + SourceID dst; ///< Index of destination. Either TownID or IndustryID /** * We need an (empty) constructor so struct isn't zeroed (as C++ standard states) From 5d66d8fd7dc6e684108887770c11aee4c356c5e7 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Mon, 22 Apr 2019 09:51:06 +0100 Subject: [PATCH 35/56] Codechange: Remove ExpensesTypeByte --- src/economy_type.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/economy_type.h b/src/economy_type.h index 31f74aacc7..aa5ab5daeb 100644 --- a/src/economy_type.h +++ b/src/economy_type.h @@ -147,7 +147,7 @@ typedef Money Prices[PR_END]; ///< Prices of everything. @see Price typedef int8 PriceMultipliers[PR_END]; /** Types of expenses. */ -enum ExpensesType { +enum ExpensesType : byte { EXPENSES_CONSTRUCTION = 0, ///< Construction costs. EXPENSES_NEW_VEHICLES, ///< New vehicles. EXPENSES_TRAIN_RUN, ///< Running costs trains. @@ -167,7 +167,6 @@ enum ExpensesType { /** Define basic enum properties for ExpensesType */ template <> struct EnumPropsT : MakeEnumPropsT {}; -typedef TinyEnumT ExpensesTypeByte; ///< typedefing-enumification of ExpensesType /** * Categories of a price bases. From 0a53ee8cfe3d02aa1e7abb6c8cf67ef1d7e5ab58 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Mon, 22 Apr 2019 10:53:40 +0100 Subject: [PATCH 36/56] Codechange: Remove PartOfSubsidyByte --- src/industry.h | 30 +++++++++++++++--------------- src/subsidy_type.h | 5 +---- src/town.h | 2 +- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/src/industry.h b/src/industry.h index 2816729590..b03b696549 100644 --- a/src/industry.h +++ b/src/industry.h @@ -56,24 +56,24 @@ struct Industry : IndustryPool::PoolItem<&_industry_pool> { uint16 last_month_transported[INDUSTRY_NUM_OUTPUTS]; ///< total units transported per cargo in the last full month uint16 counter; ///< used for animation and/or production (if available cargo) - IndustryType type; ///< type of industry. - Owner owner; ///< owner of the industry. Which SHOULD always be (imho) OWNER_NONE - byte random_colour; ///< randomized colour of the industry, for display purpose - Year last_prod_year; ///< last year of production - byte was_cargo_delivered; ///< flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry - - PartOfSubsidyByte part_of_subsidy; ///< NOSAVE: is this industry a source/destination of a subsidy? - StationList stations_near; ///< NOSAVE: List of nearby stations. - - Owner founder; ///< Founder of the industry - Date construction_date; ///< Date of the construction of the industry - uint8 construction_type; ///< Way the industry was constructed (@see IndustryConstructionType) + IndustryType type; ///< type of industry. + Owner owner; ///< owner of the industry. Which SHOULD always be (imho) OWNER_NONE + byte random_colour; ///< randomized colour of the industry, for display purpose + Year last_prod_year; ///< last year of production + byte was_cargo_delivered; ///< flag that indicate this has been the closest industry chosen for cargo delivery by a station. see DeliverGoodsToIndustry + + PartOfSubsidy part_of_subsidy; ///< NOSAVE: is this industry a source/destination of a subsidy? + StationList stations_near; ///< NOSAVE: List of nearby stations. + + Owner founder; ///< Founder of the industry + Date construction_date; ///< Date of the construction of the industry + uint8 construction_type; ///< Way the industry was constructed (@see IndustryConstructionType) Date last_cargo_accepted_at[INDUSTRY_NUM_INPUTS]; ///< Last day each cargo type was accepted by this industry - byte selected_layout; ///< Which tile layout was used when creating the industry + byte selected_layout; ///< Which tile layout was used when creating the industry - uint16 random; ///< Random value used for randomisation of all kinds of things + uint16 random; ///< Random value used for randomisation of all kinds of things - PersistentStorage *psa; ///< Persistent storage for NewGRF industries. + PersistentStorage *psa; ///< Persistent storage for NewGRF industries. Industry(TileIndex tile = INVALID_TILE) : location(tile, 0, 0) {} ~Industry(); diff --git a/src/subsidy_type.h b/src/subsidy_type.h index 83c33a00a9..968351ffb3 100644 --- a/src/subsidy_type.h +++ b/src/subsidy_type.h @@ -15,14 +15,11 @@ #include "core/enum_type.hpp" /** What part of a subsidy is something? */ -enum PartOfSubsidy { +enum PartOfSubsidy : byte { POS_NONE = 0, ///< nothing POS_SRC = 1 << 0, ///< bit 0 set -> town/industry is source of subsidised path POS_DST = 1 << 1, ///< bit 1 set -> town/industry is destination of subsidised path }; -/** Helper to store the PartOfSubsidy data in a single byte. */ -typedef SimpleTinyEnumT PartOfSubsidyByte; - DECLARE_ENUM_AS_BIT_SET(PartOfSubsidy) typedef uint16 SubsidyID; ///< ID of a subsidy diff --git a/src/town.h b/src/town.h index 8e8a6551d5..5f0f4992f5 100644 --- a/src/town.h +++ b/src/town.h @@ -46,7 +46,7 @@ struct TownCache { uint32 num_houses; ///< Amount of houses uint32 population; ///< Current population of people ViewportSign sign; ///< Location of name sign, UpdateVirtCoord updates this - PartOfSubsidyByte part_of_subsidy; ///< Is this town a source/destination of a subsidy? + PartOfSubsidy part_of_subsidy; ///< Is this town a source/destination of a subsidy? uint32 squared_town_zone_radius[HZB_END]; ///< UpdateTownRadius updates this given the house count BuildingCounts building_counts; ///< The number of each type of building in the town }; From 644f4c3547a312d53c1014639df3dc2f55ab4de8 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Mon, 22 Apr 2019 11:10:44 +0100 Subject: [PATCH 37/56] Codechange: Set size of SettingGuiFlag & SettingDescType enums, and use them properly --- src/settings_internal.h | 8 +++----- src/table/currency_settings.ini | 2 +- src/table/gameopt_settings.ini | 2 +- src/table/misc_settings.ini | 2 +- src/table/settings.h.preamble | 10 +++++----- src/table/settings.ini | 2 +- src/table/win32_settings.ini | 2 +- src/table/window_settings.ini | 2 +- 8 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/settings_internal.h b/src/settings_internal.h index 028e977e48..0f1d3c1923 100644 --- a/src/settings_internal.h +++ b/src/settings_internal.h @@ -20,7 +20,7 @@ * @see VarTypes * @see SettingDescBase */ -enum SettingDescTypeLong { +enum SettingDescType : byte { /* 4 bytes allocated a maximum of 16 types for GenericType */ SDT_BEGIN = 0, SDT_NUMX = 0, ///< any number-type @@ -32,10 +32,9 @@ enum SettingDescTypeLong { SDT_END, /* 10 more possible primitives */ }; -typedef SimpleTinyEnumT SettingDescType; -enum SettingGuiFlagLong { +enum SettingGuiFlag : uint16 { /* 1 byte allocated for a maximum of 8 flags * Flags directing saving/loading of a variable */ SGF_NONE = 0, @@ -49,8 +48,7 @@ enum SettingGuiFlagLong { SGF_SCENEDIT_TOO = 1 << 7, ///< this setting can be changed in the scenario editor (only makes sense when SGF_NEWGAME_ONLY is set) SGF_PER_COMPANY = 1 << 8, ///< this setting can be different for each company (saved in company struct) }; -DECLARE_ENUM_AS_BIT_SET(SettingGuiFlagLong) -typedef SimpleTinyEnumT SettingGuiFlag; +DECLARE_ENUM_AS_BIT_SET(SettingGuiFlag) /** * A SettingCategory defines a grouping of the settings. diff --git a/src/table/currency_settings.ini b/src/table/currency_settings.ini index 02777d2aec..d68f4bfc28 100644 --- a/src/table/currency_settings.ini +++ b/src/table/currency_settings.ini @@ -18,7 +18,7 @@ SDT_END = SDT_END() [defaults] flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC -guiflags = 0 +guiflags = SGF_NONE interval = 0 str = STR_NULL strhelp = STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT diff --git a/src/table/gameopt_settings.ini b/src/table/gameopt_settings.ini index 247bfbed2b..9bacb80c70 100644 --- a/src/table/gameopt_settings.ini +++ b/src/table/gameopt_settings.ini @@ -50,7 +50,7 @@ SDT_END = SDT_END() [defaults] flags = 0 -guiflags = 0 +guiflags = SGF_NONE interval = 0 str = STR_NULL strhelp = STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT diff --git a/src/table/misc_settings.ini b/src/table/misc_settings.ini index 6d974a0056..a1159aee08 100644 --- a/src/table/misc_settings.ini +++ b/src/table/misc_settings.ini @@ -25,7 +25,7 @@ SDTG_END = SDTG_END() [defaults] flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC -guiflags = 0 +guiflags = SGF_NONE interval = 0 str = STR_NULL strhelp = STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT diff --git a/src/table/settings.h.preamble b/src/table/settings.h.preamble index b6992764dc..08380cbf1b 100644 --- a/src/table/settings.h.preamble +++ b/src/table/settings.h.preamble @@ -57,7 +57,7 @@ static size_t ConvertLandscape(const char *value); */ #define NSD_GENERAL(name, def, cmd, guiflags, min, max, interval, many, str, strhelp, strval, proc, load, cat)\ - {name, (const void*)(size_t)(def), {(byte)cmd}, {(uint16)guiflags}, min, max, interval, many, str, strhelp, strval, proc, load, cat} + {name, (const void*)(size_t)(def), cmd, guiflags, min, max, interval, many, str, strhelp, strval, proc, load, cat} /* Macros for various objects to go in the configuration file. * This section is for global variables */ @@ -83,9 +83,9 @@ static size_t ConvertLandscape(const char *value); SDTG_GENERAL(name, SDT_MANYOFMANY, SL_VAR, type, flags, guiflags, var, 0, def, 0, 0, 0, full, str, strhelp, strval, proc, from, to, cat) #define SDTG_NULL(length, from, to)\ - {{"", nullptr, {0}, {0}, 0, 0, 0, nullptr, STR_NULL, STR_NULL, STR_NULL, nullptr, nullptr, SC_NONE}, SLEG_NULL(length, from, to)} + {{"", nullptr, SDT_NUMX, SGF_NONE, 0, 0, 0, nullptr, STR_NULL, STR_NULL, STR_NULL, nullptr, nullptr, SC_NONE}, SLEG_NULL(length, from, to)} -#define SDTG_END() {{nullptr, nullptr, {0}, {0}, 0, 0, 0, nullptr, STR_NULL, STR_NULL, STR_NULL, nullptr, nullptr, SC_NONE}, SLEG_END()} +#define SDTG_END() {{nullptr, nullptr, SDT_NUMX, SGF_NONE, 0, 0, 0, nullptr, STR_NULL, STR_NULL, STR_NULL, nullptr, nullptr, SC_NONE}, SLEG_END()} /* Macros for various objects to go in the configuration file. * This section is for structures where their various members are saved */ @@ -114,7 +114,7 @@ static size_t ConvertLandscape(const char *value); SDT_GENERAL(#var, SDT_MANYOFMANY, SL_VAR, type, flags, guiflags, base, var, 1, def, 0, 0, 0, full, str, strhelp, strval, proc, nullptr, from, to, cat) #define SDT_NULL(length, from, to)\ - {{"", nullptr, {0}, {0}, 0, 0, 0, nullptr, STR_NULL, STR_NULL, STR_NULL, nullptr, nullptr, SC_NONE}, SLE_CONDNULL(length, from, to)} + {{"", nullptr, SDT_NUMX, SGF_NONE, 0, 0, 0, nullptr, STR_NULL, STR_NULL, STR_NULL, nullptr, nullptr, SC_NONE}, SLE_CONDNULL(length, from, to)} #define SDTC_VAR(var, type, flags, guiflags, def, min, max, interval, str, strhelp, strval, proc, from, to, cat)\ @@ -132,5 +132,5 @@ static size_t ConvertLandscape(const char *value); #define SDTC_OMANY(var, type, flags, guiflags, def, max, full, str, strhelp, strval, proc, from, to, cat)\ SDTG_GENERAL(#var, SDT_ONEOFMANY, SL_VAR, type, flags, guiflags, _settings_client.var, 1, def, 0, max, 0, full, str, strhelp, strval, proc, from, to, cat) -#define SDT_END() {{nullptr, nullptr, {0}, {0}, 0, 0, 0, nullptr, STR_NULL, STR_NULL, STR_NULL, nullptr, nullptr, SC_NONE}, SLE_END()} +#define SDT_END() {{nullptr, nullptr, SDT_NUMX, SGF_NONE, 0, 0, 0, nullptr, STR_NULL, STR_NULL, STR_NULL, nullptr, nullptr, SC_NONE}, SLE_END()} diff --git a/src/table/settings.ini b/src/table/settings.ini index 1aacb76349..5e57e5216c 100644 --- a/src/table/settings.ini +++ b/src/table/settings.ini @@ -81,7 +81,7 @@ SDT_END = SDT_END() [defaults] flags = 0 -guiflags = 0 +guiflags = SGF_NONE interval = 0 str = STR_NULL strhelp = STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT diff --git a/src/table/win32_settings.ini b/src/table/win32_settings.ini index 7d9821475e..4b3d6f5598 100644 --- a/src/table/win32_settings.ini +++ b/src/table/win32_settings.ini @@ -23,7 +23,7 @@ SDTG_END = SDTG_END() [defaults] flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC -guiflags = 0 +guiflags = SGF_NONE interval = 0 str = STR_NULL strhelp = STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT diff --git a/src/table/window_settings.ini b/src/table/window_settings.ini index 67d1edb35f..998afc8dbb 100644 --- a/src/table/window_settings.ini +++ b/src/table/window_settings.ini @@ -19,7 +19,7 @@ SDT_END = SDT_END() [defaults] base = WindowDesc flags = SLF_NOT_IN_SAVE | SLF_NO_NETWORK_SYNC -guiflags = 0 +guiflags = SGF_NONE interval = 0 str = STR_NULL strhelp = STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT From e18c8c30be2bb20271c4c5f65441513b591f416d Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Mon, 22 Apr 2019 11:14:42 +0100 Subject: [PATCH 38/56] Codechange: Remove RoadTypesByte --- src/road_type.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/road_type.h b/src/road_type.h index 5251a53923..7056f6d62c 100644 --- a/src/road_type.h +++ b/src/road_type.h @@ -33,7 +33,7 @@ template <> struct EnumPropsT : MakeEnumPropsT struct EnumPropsT : MakeEnumPropsT {}; -typedef SimpleTinyEnumT RoadTypesByte; /** From 327ff898080d94ab129f6e7ae3c268dcf10d6a08 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Mon, 22 Apr 2019 13:14:46 +0100 Subject: [PATCH 39/56] Codechange: Remove PauseModeByte --- src/gfx.cpp | 2 +- src/misc_cmd.cpp | 4 ++-- src/openttd.h | 5 ++--- src/saveload/oldloader.cpp | 2 +- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/gfx.cpp b/src/gfx.cpp index 5165fe01c4..4fd705b9f1 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -46,7 +46,7 @@ bool _screen_disable_anim = false; ///< Disable palette animation (important f bool _exit_game; GameMode _game_mode; SwitchMode _switch_mode; ///< The next mainloop command. -PauseModeByte _pause_mode; +PauseMode _pause_mode; Palette _cur_palette; static byte _stringwidth_table[FS_END][224]; ///< Cache containing width of often used characters. @see GetCharacterWidth() diff --git a/src/misc_cmd.cpp b/src/misc_cmd.cpp index f0ccfbd744..4271f57581 100644 --- a/src/misc_cmd.cpp +++ b/src/misc_cmd.cpp @@ -173,9 +173,9 @@ CommandCost CmdPause(TileIndex tile, DoCommandFlag flags, uint32 p1, uint32 p2, PauseMode prev_mode = _pause_mode; if (p2 == 0) { - _pause_mode = _pause_mode & ~p1; + _pause_mode = static_cast(_pause_mode & (byte)~p1); } else { - _pause_mode = _pause_mode | p1; + _pause_mode = static_cast(_pause_mode | (byte)p1); } NetworkHandlePauseChange(prev_mode, (PauseMode)p1); diff --git a/src/openttd.h b/src/openttd.h index 5e360d6fcd..539b7e14f1 100644 --- a/src/openttd.h +++ b/src/openttd.h @@ -54,7 +54,7 @@ extern SwitchMode _switch_mode; extern bool _exit_game; /** Modes of pausing we've got */ -enum PauseMode { +enum PauseMode : byte { PM_UNPAUSED = 0, ///< A normal unpaused game PM_PAUSED_NORMAL = 1 << 0, ///< A game normally paused PM_PAUSED_SAVELOAD = 1 << 1, ///< A game paused for saving/loading @@ -67,10 +67,9 @@ enum PauseMode { PMB_PAUSED_NETWORK = PM_PAUSED_ACTIVE_CLIENTS | PM_PAUSED_JOIN, }; DECLARE_ENUM_AS_BIT_SET(PauseMode) -typedef SimpleTinyEnumT PauseModeByte; /** The current pause mode */ -extern PauseModeByte _pause_mode; +extern PauseMode _pause_mode; void AskExitGame(); void AskExitToGameMenu(); diff --git a/src/saveload/oldloader.cpp b/src/saveload/oldloader.cpp index 9b24750d29..11eb058fad 100644 --- a/src/saveload/oldloader.cpp +++ b/src/saveload/oldloader.cpp @@ -314,7 +314,7 @@ bool LoadOldSaveGame(const char *file) return false; } - _pause_mode = 2; + _pause_mode = PM_PAUSED_SAVELOAD; return true; } From a5681d3ebac3c791c230bffb5eceac00222b2e01 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Mon, 22 Apr 2019 13:20:24 +0100 Subject: [PATCH 40/56] Codechange: Remove GoalTypeByte --- src/goal_base.h | 2 +- src/goal_type.h | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/goal_base.h b/src/goal_base.h index 532c47ea3b..fee4ddce7b 100644 --- a/src/goal_base.h +++ b/src/goal_base.h @@ -22,7 +22,7 @@ extern GoalPool _goal_pool; /** Struct about goals, current and completed */ struct Goal : GoalPool::PoolItem<&_goal_pool> { CompanyID company; ///< Goal is for a specific company; INVALID_COMPANY if it is global - GoalTypeByte type; ///< Type of the goal + GoalType type; ///< Type of the goal GoalTypeID dst; ///< Index of type char *text; ///< Text of the goal. char *progress; ///< Progress text of the goal. diff --git a/src/goal_type.h b/src/goal_type.h index aa9dee349d..4321a42b7a 100644 --- a/src/goal_type.h +++ b/src/goal_type.h @@ -18,7 +18,7 @@ static const uint32 GOAL_QUESTION_BUTTON_COUNT = 18; ///< Amount of buttons avai static const byte GOAL_QUESTION_TYPE_COUNT = 4; ///< Amount of question types. /** Types of goal destinations */ -enum GoalType { +enum GoalType : byte { GT_NONE, ///< Destination is not linked GT_TILE, ///< Destination is a tile GT_INDUSTRY, ///< Destination is an industry @@ -26,7 +26,6 @@ enum GoalType { GT_COMPANY, ///< Destination is a company GT_STORY_PAGE, ///< Destination is a story page }; -typedef SimpleTinyEnumT GoalTypeByte; ///< The GoalType packed into a byte for savegame purposes. typedef uint32 GoalTypeID; ///< Contains either tile, industry ID, town ID or company ID (or INVALID_GOALTYPE) static const GoalTypeID INVALID_GOALTYPE = 0xFFFFFFFF; ///< Invalid/unknown index of GoalType From bd87f113555f2b0f9a70d14fd67fd2e6b1e8809d Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Mon, 22 Apr 2019 22:57:37 +0100 Subject: [PATCH 41/56] Codechange: Remove DistributionTypeByte --- src/linkgraph/linkgraph_type.h | 3 +-- src/settings_type.h | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/linkgraph/linkgraph_type.h b/src/linkgraph/linkgraph_type.h index 6a3239b089..1e3a0ff661 100644 --- a/src/linkgraph/linkgraph_type.h +++ b/src/linkgraph/linkgraph_type.h @@ -21,7 +21,7 @@ static const LinkGraphID INVALID_LINK_GRAPH_JOB = UINT16_MAX; typedef uint16 NodeID; static const NodeID INVALID_NODE = UINT16_MAX; -enum DistributionType { +enum DistributionType : byte { DT_BEGIN = 0, DT_MIN = 0, DT_MANUAL = 0, ///< Manual distribution. No link graph calculations are run. @@ -37,7 +37,6 @@ enum DistributionType { * Define basic enum properties */ template <> struct EnumPropsT : MakeEnumPropsT {}; -typedef TinyEnumT DistributionTypeByte; // typedefing-enumification of DistributionType /** * Special modes for updating links. 'Restricted' means that vehicles with diff --git a/src/settings_type.h b/src/settings_type.h index 83d9091301..f2fbd283cd 100644 --- a/src/settings_type.h +++ b/src/settings_type.h @@ -493,16 +493,16 @@ struct EconomySettings { }; struct LinkGraphSettings { - uint16 recalc_time; ///< time (in days) for recalculating each link graph component. - uint16 recalc_interval; ///< time (in days) between subsequent checks for link graphs to be calculated. - DistributionTypeByte distribution_pax; ///< distribution type for passengers - DistributionTypeByte distribution_mail; ///< distribution type for mail - DistributionTypeByte distribution_armoured; ///< distribution type for armoured cargo class - DistributionTypeByte distribution_default; ///< distribution type for all other goods - uint8 accuracy; ///< accuracy when calculating things on the link graph. low accuracy => low running time - uint8 demand_size; ///< influence of supply ("station size") on the demand function - uint8 demand_distance; ///< influence of distance between stations on the demand function - uint8 short_path_saturation; ///< percentage up to which short paths are saturated before saturating most capacious paths + uint16 recalc_time; ///< time (in days) for recalculating each link graph component. + uint16 recalc_interval; ///< time (in days) between subsequent checks for link graphs to be calculated. + DistributionType distribution_pax; ///< distribution type for passengers + DistributionType distribution_mail; ///< distribution type for mail + DistributionType distribution_armoured; ///< distribution type for armoured cargo class + DistributionType distribution_default; ///< distribution type for all other goods + uint8 accuracy; ///< accuracy when calculating things on the link graph. low accuracy => low running time + uint8 demand_size; ///< influence of supply ("station size") on the demand function + uint8 demand_distance; ///< influence of distance between stations on the demand function + uint8 short_path_saturation; ///< percentage up to which short paths are saturated before saturating most capacious paths inline DistributionType GetDistributionType(CargoID cargo) const { if (IsCargoInClass(cargo, CC_PASSENGERS)) return this->distribution_pax; From 9e19a5f93e3d79ac30bec14b6e0ba673b7073863 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Mon, 22 Apr 2019 22:57:55 +0100 Subject: [PATCH 42/56] Remove: (Simple)TinyEnumT --- src/core/enum_type.hpp | 104 ----------------------------------------- 1 file changed, 104 deletions(-) diff --git a/src/core/enum_type.hpp b/src/core/enum_type.hpp index d5bcf6dbe1..8526a91a56 100644 --- a/src/core/enum_type.hpp +++ b/src/core/enum_type.hpp @@ -46,8 +46,6 @@ * we will create specialization derived from MakeEnumPropsT<>. * i.e.: * template <> struct EnumPropsT : MakeEnumPropsT {}; - * followed by: - * typedef TinyEnumT TrackByte; */ template struct EnumPropsT; @@ -72,106 +70,4 @@ struct MakeEnumPropsT { static const uint num_bits = Tnum_bits; ///< Number of bits for storing the enum in command parameters }; - - -/** - * In some cases we use byte or uint16 to store values that are defined as enum. It is - * necessary in order to control the sizeof() such values. Some compilers make enum - * the same size as int (4 or 8 bytes instead of 1 or 2). As a consequence the strict - * compiler type - checking causes errors like: - * 'HasPowerOnRail' : cannot convert parameter 1 from 'byte' to 'RailType' when - * u->u.rail.railtype is passed as argument or type RailType. In such cases it is better - * to teach the compiler that u->u.rail.railtype is to be treated as RailType. - */ -template struct TinyEnumT; - -/** The general declaration of TinyEnumT<> (above) */ -template -struct TinyEnumT { - typedef Tenum_t enum_type; ///< expose our enumeration type (i.e. Trackdir) to outside - typedef EnumPropsT Props; ///< make easier access to our enumeration properties - typedef typename Props::storage storage_type; ///< small storage type - static const enum_type begin = Props::begin; ///< enum beginning (i.e. TRACKDIR_BEGIN) - static const enum_type end = Props::end; ///< enum end (i.e. TRACKDIR_END) - static const enum_type invalid = Props::invalid;///< invalid value (i.e. INVALID_TRACKDIR) - - storage_type m_val; ///< here we hold the actual value in small (i.e. byte) form - - /** Cast operator - invoked then the value is assigned to the Tenum_t type */ - inline operator enum_type () const - { - return (enum_type)m_val; - } - - /** Assignment operator (from Tenum_t type) */ - inline TinyEnumT& operator = (enum_type e) - { - m_val = (storage_type)e; - return *this; - } - - /** Assignment operator (from Tenum_t type) */ - inline TinyEnumT& operator = (uint u) - { - m_val = (storage_type)u; - return *this; - } - - /** postfix ++ operator on tiny type */ - inline TinyEnumT operator ++ (int) - { - TinyEnumT org = *this; - if (++m_val >= end) m_val -= (storage_type)(end - begin); - return org; - } - - /** prefix ++ operator on tiny type */ - inline TinyEnumT& operator ++ () - { - if (++m_val >= end) m_val -= (storage_type)(end - begin); - return *this; - } -}; - - -/** Template of struct holding enum types (on most archs, enums are stored in an int32). No math operators are provided. */ -template -struct SimpleTinyEnumT { - storage_type m_val; ///< here we hold the actual value in small (i.e. byte) form - - /** Cast operator - invoked then the value is assigned to the storage_type */ - inline operator enum_type () const - { - return (enum_type)this->m_val; - } - - /** Assignment operator (from enum_type) */ - inline SimpleTinyEnumT &operator = (enum_type e) - { - this->m_val = (storage_type)e; - return *this; - } - - /** Assignment operator (from general uint) */ - inline SimpleTinyEnumT &operator = (uint u) - { - this->m_val = (storage_type)u; - return *this; - } - - /** Bit math (or) assignment operator (from enum_type) */ - inline SimpleTinyEnumT &operator |= (enum_type e) - { - this->m_val = (storage_type)((enum_type)this->m_val | e); - return *this; - } - - /** Bit math (and) assignment operator (from enum_type) */ - inline SimpleTinyEnumT &operator &= (enum_type e) - { - this->m_val = (storage_type)((enum_type)this->m_val & e); - return *this; - } -}; - #endif /* ENUM_TYPE_HPP */ From 47d0d86a3c31c3b9ae71e5bed5007d0ba0a1337d Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Thu, 25 Apr 2019 22:55:16 +0100 Subject: [PATCH 43/56] Fix #7255: Prevent crashlog corruption by only printing the 32 most recent news messages --- src/crashlog.cpp | 5 +++-- src/news_gui.cpp | 10 +++++----- src/news_gui.h | 2 +- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/crashlog.cpp b/src/crashlog.cpp index 531b5c64c9..bcad5e35f7 100644 --- a/src/crashlog.cpp +++ b/src/crashlog.cpp @@ -303,7 +303,7 @@ char *CrashLog::LogGamelog(char *buffer, const char *last) const } /** - * Writes any recent news messages to the buffer. + * Writes up to 32 recent news messages to the buffer, with the most recent first. * @param buffer The begin where to write at. * @param last The last position in the buffer to write to. * @return the position of the \c '\0' character after the buffer. @@ -312,7 +312,8 @@ char *CrashLog::LogRecentNews(char *buffer, const char *last) const { buffer += seprintf(buffer, last, "Recent news messages:\n"); - for (NewsItem *news = _oldest_news; news != nullptr; news = news->next) { + int i = 0; + for (NewsItem *news = _latest_news; i < 32 && news != nullptr; news = news->prev, i++) { YearMonthDay ymd; ConvertDateToYMD(news->date, &ymd); buffer += seprintf(buffer, last, "(%i-%02i-%02i) StringID: %u, Type: %u, Ref1: %u, %u, Ref2: %u, %u\n", diff --git a/src/news_gui.cpp b/src/news_gui.cpp index be83b374c6..7e99939b17 100644 --- a/src/news_gui.cpp +++ b/src/news_gui.cpp @@ -43,10 +43,10 @@ const NewsItem *_statusbar_news_item = nullptr; -static uint MIN_NEWS_AMOUNT = 30; ///< preferred minimum amount of news messages -static uint _total_news = 0; ///< current number of news items -NewsItem *_oldest_news = nullptr; ///< head of news items queue -static NewsItem *_latest_news = nullptr; ///< tail of news items queue +static uint MIN_NEWS_AMOUNT = 30; ///< preferred minimum amount of news messages +static uint _total_news = 0; ///< current number of news items +static NewsItem *_oldest_news = nullptr; ///< head of news items queue +NewsItem *_latest_news = nullptr; ///< tail of news items queue /** * Forced news item. @@ -54,7 +54,7 @@ static NewsItem *_latest_news = nullptr; ///< tail of news items queue * If the message being shown was forced by the user, a pointer is stored * in _forced_news. Otherwise, \a _forced_news variable is nullptr. */ -static const NewsItem *_forced_news = nullptr; ///< item the user has asked for +static const NewsItem *_forced_news = nullptr; /** Current news item (last item shown regularly). */ static const NewsItem *_current_news = nullptr; diff --git a/src/news_gui.h b/src/news_gui.h index 0f42c68c6c..569a8b8a74 100644 --- a/src/news_gui.h +++ b/src/news_gui.h @@ -17,6 +17,6 @@ void ShowLastNewsMessage(); void ShowMessageHistory(); -extern NewsItem *_oldest_news; +extern NewsItem *_latest_news; #endif /* NEWS_GUI_H */ From 9da1c5bb0bdb9e09fb0bd5ed69ffa1db85ab5c09 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Fri, 26 Apr 2019 19:09:55 +0100 Subject: [PATCH 44/56] Fix: Crash when attempting to load old save game with GRFs set GroupStatistics pool was not initialised before trying to delete vehicles (specifically, trams with no tram track) --- src/saveload/afterload.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 9bdfa6b34c..eea896dd75 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -1900,6 +1900,7 @@ bool AfterLoadGame() } if (IsSavegameVersionBefore(SLV_62)) { + GroupStatistics::UpdateAfterLoad(); // Ensure statistics pool is initialised before trying to delete vehicles /* Remove all trams from savegames without tram support. * There would be trams without tram track under causing crashes sooner or later. */ RoadVehicle *v; From 3299d6540be33449d3a4eebc7de69c1f57993d98 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Fri, 26 Apr 2019 20:22:06 +0100 Subject: [PATCH 45/56] Cleanup: Delete GetSavegameType function since it's been commented out since 2005 --- src/saveload/saveload.cpp | 33 --------------------------------- 1 file changed, 33 deletions(-) diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp index d7ec59d6fe..83685b46b6 100644 --- a/src/saveload/saveload.cpp +++ b/src/saveload/saveload.cpp @@ -2887,36 +2887,3 @@ void FileToSaveLoad::SetTitle(const char *title) { strecpy(this->title, title, lastof(this->title)); } - -#if 0 -/** - * Function to get the type of the savegame by looking at the file header. - * NOTICE: Not used right now, but could be used if extensions of savegames are garbled - * @param file Savegame to be checked - * @return SL_OLD_LOAD or SL_LOAD of the file - */ -int GetSavegameType(char *file) -{ - const SaveLoadFormat *fmt; - uint32 hdr; - FILE *f; - int mode = SL_OLD_LOAD; - - f = fopen(file, "rb"); - if (fread(&hdr, sizeof(hdr), 1, f) != 1) { - DEBUG(sl, 0, "Savegame is obsolete or invalid format"); - mode = SL_LOAD; // don't try to get filename, just show name as it is written - } else { - /* see if we have any loader for this type. */ - for (fmt = _saveload_formats; fmt != endof(_saveload_formats); fmt++) { - if (fmt->tag == hdr) { - mode = SL_LOAD; // new type of savegame - break; - } - } - } - - fclose(f); - return mode; -} -#endif From d9f9a64389ebe66b2dfa7b16cd66ed463ab2cec7 Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sat, 27 Apr 2019 09:59:45 +0100 Subject: [PATCH 46/56] Fix #6507: Don't try to load invalid depots from older savegames --- src/saveload/afterload.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index eea896dd75..06cbbd17d6 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -2312,6 +2312,14 @@ bool AfterLoadGame() if (IsSavegameVersionBefore(SLV_128)) { const Depot *d; FOR_ALL_DEPOTS(d) { + /* At some point, invalid depots were saved into the game (possibly those removed in the past?) + * Remove them here, so they don't cause issues further down the line */ + if (!IsDepotTile(d->xy)) { + DEBUG(sl, 0, "Removing invalid depot %d at %d, %d", d->index, TileX(d->xy), TileY(d->xy)); + delete d; + d = nullptr; + continue; + } _m[d->xy].m2 = d->index; if (IsTileType(d->xy, MP_WATER)) _m[GetOtherShipDepotTile(d->xy)].m2 = d->index; } From 63a7df027df0aa5655cabf32e88fe2ee44422c1d Mon Sep 17 00:00:00 2001 From: Charles Pigott Date: Sat, 27 Apr 2019 14:30:06 +0100 Subject: [PATCH 47/56] Fix 5db883f: Railtype bits were moved too late, leading to rails under bridges losing their type --- src/saveload/afterload.cpp | 64 +++++++++++++++++++------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/src/saveload/afterload.cpp b/src/saveload/afterload.cpp index 06cbbd17d6..6b273e026d 100644 --- a/src/saveload/afterload.cpp +++ b/src/saveload/afterload.cpp @@ -1139,6 +1139,38 @@ bool AfterLoadGame() } } + /* Railtype moved from m3 to m8 in version SLV_EXTEND_RAILTYPES. */ + if (IsSavegameVersionBefore(SLV_EXTEND_RAILTYPES)) { + for (TileIndex t = 0; t < map_size; t++) { + switch (GetTileType(t)) { + case MP_RAILWAY: + SetRailType(t, (RailType)GB(_m[t].m3, 0, 4)); + break; + + case MP_ROAD: + if (IsLevelCrossing(t)) { + SetRailType(t, (RailType)GB(_m[t].m3, 0, 4)); + } + break; + + case MP_STATION: + if (HasStationRail(t)) { + SetRailType(t, (RailType)GB(_m[t].m3, 0, 4)); + } + break; + + case MP_TUNNELBRIDGE: + if (GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL) { + SetRailType(t, (RailType)GB(_m[t].m3, 0, 4)); + } + break; + + default: + break; + } + } + } + if (IsSavegameVersionBefore(SLV_42)) { Vehicle *v; @@ -1220,38 +1252,6 @@ bool AfterLoadGame() } } - /* Railtype moved from m3 to m8 in version SLV_EXTEND_RAILTYPES. */ - if (IsSavegameVersionBefore(SLV_EXTEND_RAILTYPES)) { - for (TileIndex t = 0; t < map_size; t++) { - switch (GetTileType(t)) { - case MP_RAILWAY: - SetRailType(t, (RailType)GB(_m[t].m3, 0, 4)); - break; - - case MP_ROAD: - if (IsLevelCrossing(t)) { - SetRailType(t, (RailType)GB(_m[t].m3, 0, 4)); - } - break; - - case MP_STATION: - if (HasStationRail(t)) { - SetRailType(t, (RailType)GB(_m[t].m3, 0, 4)); - } - break; - - case MP_TUNNELBRIDGE: - if (GetTunnelBridgeTransportType(t) == TRANSPORT_RAIL) { - SetRailType(t, (RailType)GB(_m[t].m3, 0, 4)); - } - break; - - default: - break; - } - } - } - /* Elrails got added in rev 24 */ if (IsSavegameVersionBefore(SLV_24)) { RailType min_rail = RAILTYPE_ELECTRIC; From 8cc6ee60eddd2585140a8ad7eba512e87b1fc894 Mon Sep 17 00:00:00 2001 From: pnda <43609023+spnda@users.noreply.github.com> Date: Mon, 29 Apr 2019 19:42:00 +0200 Subject: [PATCH 48/56] Add: Icons on air/water/landscape construction menus (#7485) --- src/toolbar_gui.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index bd7472ecdc..8b5f79df21 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -930,7 +930,9 @@ static CallBackFunction MenuClickBuildRoad(int index) static CallBackFunction ToolbarBuildWaterClick(Window *w) { - PopupMainToolbMenu(w, WID_TN_WATER, STR_WATERWAYS_MENU_WATERWAYS_CONSTRUCTION, 1); + DropDownList list; + list.emplace_back(new DropDownListIconItem(SPR_IMG_BUILD_CANAL, PAL_NONE, STR_WATERWAYS_MENU_WATERWAYS_CONSTRUCTION, 0, false)); + ShowDropDownList(w, std::move(list), 0, WID_TN_WATER, 140, true, true); return CBF_NONE; } @@ -950,7 +952,9 @@ static CallBackFunction MenuClickBuildWater(int index) static CallBackFunction ToolbarBuildAirClick(Window *w) { - PopupMainToolbMenu(w, WID_TN_AIR, STR_AIRCRAFT_MENU_AIRPORT_CONSTRUCTION, 1); + DropDownList list; + list.emplace_back(new DropDownListIconItem(SPR_IMG_AIRPORT, PAL_NONE, STR_AIRCRAFT_MENU_AIRPORT_CONSTRUCTION, 0, false)); + ShowDropDownList(w, std::move(list), 0, WID_TN_AIR, 140, true, true); return CBF_NONE; } @@ -970,7 +974,11 @@ static CallBackFunction MenuClickBuildAir(int index) static CallBackFunction ToolbarForestClick(Window *w) { - PopupMainToolbMenu(w, WID_TN_LANDSCAPE, STR_LANDSCAPING_MENU_LANDSCAPING, 3); + DropDownList list; + list.emplace_back(new DropDownListIconItem(SPR_IMG_LANDSCAPING, PAL_NONE, STR_LANDSCAPING_MENU_LANDSCAPING, 0, false)); + list.emplace_back(new DropDownListIconItem(SPR_IMG_PLANTTREES, PAL_NONE, STR_LANDSCAPING_MENU_PLANT_TREES, 1, false)); + list.emplace_back(new DropDownListIconItem(SPR_IMG_SIGN, PAL_NONE, STR_LANDSCAPING_MENU_PLACE_SIGN, 2, false)); + ShowDropDownList(w, std::move(list), 0, WID_TN_LANDSCAPE, 100, true, true); return CBF_NONE; } From 14dc8dd619b28d63d11cfd7411886e41b692b753 Mon Sep 17 00:00:00 2001 From: PeterN Date: Mon, 29 Apr 2019 19:09:11 +0100 Subject: [PATCH 49/56] Fix 81d335b: Don't check state of widget not present in scenario editor. (#7551) --- src/dock_gui.cpp | 4 ++-- src/road_gui.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/dock_gui.cpp b/src/dock_gui.cpp index d74c6d2caf..e99d456765 100644 --- a/src/dock_gui.cpp +++ b/src/dock_gui.cpp @@ -105,7 +105,7 @@ struct BuildDocksToolbarWindow : Window { ~BuildDocksToolbarWindow() { - if (this->IsWidgetLowered(WID_DT_STATION)) SetViewportCatchmentStation(nullptr, true); + if (_game_mode != GM_EDITOR && this->IsWidgetLowered(WID_DT_STATION)) SetViewportCatchmentStation(nullptr, true); if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false); } @@ -249,7 +249,7 @@ struct BuildDocksToolbarWindow : Window { void OnPlaceObjectAbort() override { - if (this->IsWidgetLowered(WID_DT_STATION)) SetViewportCatchmentStation(nullptr, true); + if (_game_mode != GM_EDITOR && this->IsWidgetLowered(WID_DT_STATION)) SetViewportCatchmentStation(nullptr, true); this->RaiseButtons(); diff --git a/src/road_gui.cpp b/src/road_gui.cpp index 78f5377dae..ca3bd6d08b 100644 --- a/src/road_gui.cpp +++ b/src/road_gui.cpp @@ -327,7 +327,7 @@ struct BuildRoadToolbarWindow : Window { ~BuildRoadToolbarWindow() { - if (this->IsWidgetLowered(WID_ROT_BUS_STATION) || this->IsWidgetLowered(WID_ROT_TRUCK_STATION)) SetViewportCatchmentStation(nullptr, true); + if (_game_mode != GM_EDITOR && (this->IsWidgetLowered(WID_ROT_BUS_STATION) || this->IsWidgetLowered(WID_ROT_TRUCK_STATION))) SetViewportCatchmentStation(nullptr, true); if (_settings_client.gui.link_terraform_toolbar) DeleteWindowById(WC_SCEN_LAND_GEN, 0, false); } @@ -546,7 +546,7 @@ struct BuildRoadToolbarWindow : Window { void OnPlaceObjectAbort() override { - if (this->IsWidgetLowered(WID_ROT_BUS_STATION) || this->IsWidgetLowered(WID_ROT_TRUCK_STATION)) SetViewportCatchmentStation(nullptr, true); + if (_game_mode != GM_EDITOR && (this->IsWidgetLowered(WID_ROT_BUS_STATION) || this->IsWidgetLowered(WID_ROT_TRUCK_STATION))) SetViewportCatchmentStation(nullptr, true); this->RaiseButtons(); this->SetWidgetsDisabledState(true, From 28b23a66437f5897841c7d9ccf6157c30ac9313a Mon Sep 17 00:00:00 2001 From: kiwitree Date: Tue, 30 Apr 2019 21:03:18 +0900 Subject: [PATCH 50/56] Fix: Crash on waypoint selection window --- src/station_gui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/station_gui.cpp b/src/station_gui.cpp index 31da16238e..2bee2d80fb 100644 --- a/src/station_gui.cpp +++ b/src/station_gui.cpp @@ -2408,7 +2408,7 @@ struct SelectStationWindow : Window { void OnMouseOver(Point pt, int widget) override { - if (widget != WID_JS_PANEL) { + if (widget != WID_JS_PANEL || T::EXPECTED_FACIL == FACIL_WAYPOINT) { SetViewportCatchmentStation(nullptr, true); return; } From cef9a76c3ffaaf42bd9b85ff41afb0d9d45d05bc Mon Sep 17 00:00:00 2001 From: glx22 Date: Wed, 1 May 2019 19:12:37 +0200 Subject: [PATCH 51/56] Fix #7553: check bounds when loading strings (#7554) --- src/stdafx.h | 14 ++++++++------ src/strgen/strgen.h | 10 +++++----- src/strgen/strgen_base.cpp | 16 ++++++++++------ 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/stdafx.h b/src/stdafx.h index f85d68aa04..123dffa138 100644 --- a/src/stdafx.h +++ b/src/stdafx.h @@ -284,13 +284,15 @@ /* MSVCRT of course has to have a different syntax for long long *sigh* */ #if defined(_MSC_VER) || defined(__MINGW32__) - #define OTTD_PRINTF64 "%I64d" - #define OTTD_PRINTFHEX64 "%I64x" - #define PRINTF_SIZE "%Iu" +# define OTTD_PRINTF64 "%I64d" +# define OTTD_PRINTFHEX64 "%I64x" +# define PRINTF_SIZE "%Iu" +# define PRINTF_SIZEX "%IX" #else - #define OTTD_PRINTF64 "%lld" - #define OTTD_PRINTFHEX64 "%llx" - #define PRINTF_SIZE "%zu" +# define OTTD_PRINTF64 "%lld" +# define OTTD_PRINTFHEX64 "%llx" +# define PRINTF_SIZE "%zu" +# define PRINTF_SIZEX "%zX" #endif typedef unsigned char byte; diff --git a/src/strgen/strgen.h b/src/strgen/strgen.h index fd527203b3..69b8732f17 100644 --- a/src/strgen/strgen.h +++ b/src/strgen/strgen.h @@ -29,12 +29,12 @@ struct LangString { char *name; ///< Name of the string. char *english; ///< English text. char *translated; ///< Translated text. - uint16 hash_next; ///< Next hash entry. - uint16 index; ///< The index in the language file. + size_t hash_next; ///< Next hash entry. + size_t index; ///< The index in the language file. int line; ///< Line of string in source-file. Case *translated_case; ///< Cases of the translation. - LangString(const char *name, const char *english, int index, int line); + LangString(const char *name, const char *english, size_t index, int line); ~LangString(); void FreeTranslation(); }; @@ -42,10 +42,10 @@ struct LangString { /** Information about the currently known strings. */ struct StringData { LangString **strings; ///< Array of all known strings. - uint16 *hash_heads; ///< Hash table for the strings. + size_t *hash_heads; ///< Hash table for the strings. size_t tabs; ///< The number of 'tabs' of strings. size_t max_strings; ///< The maximum number of strings. - int next_string_id; ///< The next string ID to allocate. + size_t next_string_id;///< The next string ID to allocate. StringData(size_t tabs); ~StringData(); diff --git a/src/strgen/strgen_base.cpp b/src/strgen/strgen_base.cpp index 804ce6498c..84fc3537be 100644 --- a/src/strgen/strgen_base.cpp +++ b/src/strgen/strgen_base.cpp @@ -58,7 +58,7 @@ Case::~Case() * @param index The index in the string table. * @param line The line this string was found on. */ -LangString::LangString(const char *name, const char *english, int index, int line) : +LangString::LangString(const char *name, const char *english, size_t index, int line) : name(stredup(name)), english(stredup(english)), translated(nullptr), hash_next(0), index(index), line(line), translated_case(nullptr) { @@ -90,7 +90,7 @@ void LangString::FreeTranslation() StringData::StringData(size_t tabs) : tabs(tabs), max_strings(tabs * TAB_SIZE) { this->strings = CallocT(max_strings); - this->hash_heads = CallocT(max_strings); + this->hash_heads = CallocT(max_strings); this->next_string_id = 0; } @@ -144,9 +144,9 @@ void StringData::Add(const char *s, LangString *ls) */ LangString *StringData::Find(const char *s) { - int idx = this->hash_heads[this->HashStr(s)]; + size_t idx = this->hash_heads[this->HashStr(s)]; - while (--idx >= 0) { + while (idx-- > 0) { LangString *ls = this->strings[idx]; if (strcmp(ls->name, s) == 0) return ls; @@ -764,7 +764,7 @@ void StringReader::HandleString(char *str) } if (this->data.strings[this->data.next_string_id] != nullptr) { - strgen_error("String ID 0x%X for '%s' already in use by '%s'", this->data.next_string_id, str, this->data.strings[this->data.next_string_id]->name); + strgen_error("String ID 0x" PRINTF_SIZEX " for '%s' already in use by '%s'", this->data.next_string_id, str, this->data.strings[this->data.next_string_id]->name); return; } @@ -830,11 +830,15 @@ void StringReader::ParseFile() strecpy(_lang.digit_decimal_separator, ".", lastof(_lang.digit_decimal_separator)); _cur_line = 1; - while (this->ReadLine(buf, lastof(buf)) != nullptr) { + while (this->data.next_string_id < this->data.max_strings && this->ReadLine(buf, lastof(buf)) != nullptr) { rstrip(buf); this->HandleString(buf); _cur_line++; } + + if (this->data.next_string_id == this->data.max_strings) { + strgen_error("Too many strings, maximum allowed is " PRINTF_SIZE, this->data.max_strings); + } } /** From 76788a1eb39366323abc07161684ba94953987c6 Mon Sep 17 00:00:00 2001 From: glx22 Date: Wed, 1 May 2019 19:31:30 +0200 Subject: [PATCH 52/56] Fix 2bb80d2: really increase the maximum number of GameScript texts to 64k (#7555) --- src/game/game_text.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/game/game_text.cpp b/src/game/game_text.cpp index bde2a5a695..412f2804f9 100644 --- a/src/game/game_text.cpp +++ b/src/game/game_text.cpp @@ -304,7 +304,7 @@ GameStrings *LoadTranslations() /** Compile the language. */ void GameStrings::Compile() { - StringData data(1); + StringData data(32); StringListReader master_reader(data, *this->raw_strings[0], true, false); master_reader.ParseFile(); if (_errors != 0) throw std::exception(); From 04c74355ba4ffd931b32d2b4248ef9c522ef0a84 Mon Sep 17 00:00:00 2001 From: Berbe <4251220+Berbe@users.noreply.github.com> Date: Wed, 1 May 2019 19:57:23 +0200 Subject: [PATCH 53/56] Fix: IniLoadFile::LoadFromDisk expects filename but BaseMedia::AddFile provided full path (#7348) --- src/base_media_func.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/base_media_func.h b/src/base_media_func.h index 42d5cad2f0..98f8552173 100644 --- a/src/base_media_func.h +++ b/src/base_media_func.h @@ -159,9 +159,9 @@ bool BaseMedia::AddFile(const char *filename, size_t basepath_length, Tbase_set *set = new Tbase_set(); IniFile *ini = new IniFile(); - ini->LoadFromDisk(filename, BASESET_DIR); - char *path = stredup(filename + basepath_length); + ini->LoadFromDisk(path, BASESET_DIR); + char *psep = strrchr(path, PATHSEPCHAR); if (psep != nullptr) { psep[1] = '\0'; From bcdb28249c0031026eaebe3afbc1309c343d3ded Mon Sep 17 00:00:00 2001 From: peter1138 Date: Mon, 8 Apr 2019 09:30:49 +0100 Subject: [PATCH 54/56] Codechange: Use RAILTYPES_NONE instead of INVALID_RAILTYPES when not using rail. INVALID_RAILTYPES, if it was accidentally tested, would match any railtype. --- src/pathfinder/npf/npf.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pathfinder/npf/npf.cpp b/src/pathfinder/npf/npf.cpp index 2863e7881b..36f66b5a93 100644 --- a/src/pathfinder/npf/npf.cpp +++ b/src/pathfinder/npf/npf.cpp @@ -1120,7 +1120,7 @@ FindDepotData NPFRoadVehicleFindNearestDepot(const RoadVehicle *v, int max_penal { Trackdir trackdir = v->GetVehicleTrackdir(); - AyStarUserData user = { v->owner, TRANSPORT_ROAD, INVALID_RAILTYPES, v->compatible_roadtypes }; + AyStarUserData user = { v->owner, TRANSPORT_ROAD, RAILTYPES_NONE, v->compatible_roadtypes }; NPFFoundTargetData ftd = NPFRouteToDepotBreadthFirstTwoWay(v->tile, trackdir, false, INVALID_TILE, INVALID_TRACKDIR, false, nullptr, &user, 0, max_penalty); if (ftd.best_bird_dist != 0) return FindDepotData(); @@ -1140,7 +1140,7 @@ Trackdir NPFRoadVehicleChooseTrack(const RoadVehicle *v, TileIndex tile, DiagDir NPFFillWithOrderData(&fstd, v); Trackdir trackdir = DiagDirToDiagTrackdir(enterdir); - AyStarUserData user = { v->owner, TRANSPORT_ROAD, INVALID_RAILTYPES, v->compatible_roadtypes }; + AyStarUserData user = { v->owner, TRANSPORT_ROAD, RAILTYPES_NONE, v->compatible_roadtypes }; NPFFoundTargetData ftd = NPFRouteToStationOrTile(tile - TileOffsByDiagDir(enterdir), trackdir, true, &fstd, &user); assert(ftd.best_trackdir != INVALID_TRACKDIR); @@ -1163,7 +1163,7 @@ Track NPFShipChooseTrack(const Ship *v, bool &path_found) NPFFillWithOrderData(&fstd, v); - AyStarUserData user = { v->owner, TRANSPORT_WATER, INVALID_RAILTYPES, ROADTYPES_NONE }; + AyStarUserData user = { v->owner, TRANSPORT_WATER, RAILTYPES_NONE, ROADTYPES_NONE }; NPFFoundTargetData ftd = NPFRouteToStationOrTile(v->tile, trackdir, true, &fstd, &user); assert(ftd.best_trackdir != INVALID_TRACKDIR); @@ -1188,7 +1188,7 @@ bool NPFShipCheckReverse(const Ship *v) assert(trackdir != INVALID_TRACKDIR); assert(trackdir_rev != INVALID_TRACKDIR); - AyStarUserData user = { v->owner, TRANSPORT_WATER, INVALID_RAILTYPES, ROADTYPES_NONE }; + AyStarUserData user = { v->owner, TRANSPORT_WATER, RAILTYPES_NONE, ROADTYPES_NONE }; ftd = NPFRouteToStationOrTileTwoWay(v->tile, trackdir, false, v->tile, trackdir_rev, false, &fstd, &user); /* If we didn't find anything, just keep on going straight ahead, otherwise take the reverse flag */ return ftd.best_bird_dist == 0 && NPFGetFlag(&ftd.node, NPF_FLAG_REVERSE); From 08f00151f1009e9c430b5623c65f0eb1c158592c Mon Sep 17 00:00:00 2001 From: peter1138 Date: Sun, 7 Apr 2019 22:22:27 +0100 Subject: [PATCH 55/56] Codechange: MakeBridgeRamp()'s road-or-rail-type parameter does not make sense. Road type and rail type are stored in separate locations, so this parameter does not make make sense as it is only used for rail bridges. Instead explicitly set the rail type in MakeRailBridgeRamp(). --- src/bridge_map.h | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/bridge_map.h b/src/bridge_map.h index 75b20498d1..4e70238c27 100644 --- a/src/bridge_map.h +++ b/src/bridge_map.h @@ -12,6 +12,7 @@ #ifndef BRIDGE_MAP_H #define BRIDGE_MAP_H +#include "rail_map.h" #include "road_map.h" #include "bridge.h" @@ -123,10 +124,9 @@ static inline void SetBridgeMiddle(TileIndex t, Axis a) * @param bridgetype the type of bridge this bridge ramp belongs to * @param d the direction this ramp must be facing * @param tt the transport type of the bridge - * @param rt the road or rail type * @note this function should not be called directly. */ -static inline void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, TransportType tt, uint rt) +static inline void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, TransportType tt) { SetTileType(t, MP_TUNNELBRIDGE); SetTileOwner(t, o); @@ -136,7 +136,7 @@ static inline void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, D _m[t].m5 = 1 << 7 | tt << 2 | d; SB(_me[t].m6, 2, 4, bridgetype); _me[t].m7 = 0; - _me[t].m8 = rt; + _me[t].m8 = 0; } /** @@ -147,14 +147,14 @@ static inline void MakeBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, D * @param owner_tram the new owner of the tram on the bridge * @param bridgetype the type of bridge this bridge ramp belongs to * @param d the direction this ramp must be facing - * @param r the road type of the bridge + * @param rts the road types of the bridge */ -static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, Owner owner_road, Owner owner_tram, BridgeType bridgetype, DiagDirection d, RoadTypes r) +static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, Owner owner_road, Owner owner_tram, BridgeType bridgetype, DiagDirection d, RoadTypes rts) { - MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD, 0); + MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_ROAD); SetRoadOwner(t, ROADTYPE_ROAD, owner_road); if (owner_tram != OWNER_TOWN) SetRoadOwner(t, ROADTYPE_TRAM, owner_tram); - SetRoadTypes(t, r); + SetRoadTypes(t, rts); } /** @@ -163,11 +163,12 @@ static inline void MakeRoadBridgeRamp(TileIndex t, Owner o, Owner owner_road, Ow * @param o the new owner of the bridge ramp * @param bridgetype the type of bridge this bridge ramp belongs to * @param d the direction this ramp must be facing - * @param r the rail type of the bridge + * @param rt the rail type of the bridge */ -static inline void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType r) +static inline void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetype, DiagDirection d, RailType rt) { - MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL, r); + MakeBridgeRamp(t, o, bridgetype, d, TRANSPORT_RAIL); + SetRailType(t, rt); } /** @@ -178,7 +179,7 @@ static inline void MakeRailBridgeRamp(TileIndex t, Owner o, BridgeType bridgetyp */ static inline void MakeAqueductBridgeRamp(TileIndex t, Owner o, DiagDirection d) { - MakeBridgeRamp(t, o, 0, d, TRANSPORT_WATER, 0); + MakeBridgeRamp(t, o, 0, d, TRANSPORT_WATER); } #endif /* BRIDGE_MAP_H */ From 21edf67f89c60351d5a0d84625455aa296b6b950 Mon Sep 17 00:00:00 2001 From: Peter Nelson Date: Fri, 13 Apr 2018 21:03:11 +0100 Subject: [PATCH 56/56] Codechange: Untangle game and scenario toolbars. --- src/toolbar_gui.cpp | 54 +++++++++++++++++++++++------------- src/widgets/toolbar_widget.h | 7 ++--- 2 files changed, 38 insertions(+), 23 deletions(-) diff --git a/src/toolbar_gui.cpp b/src/toolbar_gui.cpp index 8b5f79df21..7cd5facf1d 100644 --- a/src/toolbar_gui.cpp +++ b/src/toolbar_gui.cpp @@ -1002,7 +1002,7 @@ static CallBackFunction MenuClickForest(int index) static CallBackFunction ToolbarMusicClick(Window *w) { - PopupMainToolbMenu(w, WID_TN_MUSIC_SOUND, STR_TOOLBAR_SOUND_MUSIC, 1); + PopupMainToolbMenu(w, _game_mode == GM_EDITOR ? (int)WID_TE_MUSIC_SOUND : (int)WID_TN_MUSIC_SOUND, STR_TOOLBAR_SOUND_MUSIC, 1); return CBF_NONE; } @@ -1057,7 +1057,7 @@ static CallBackFunction PlaceLandBlockInfo() static CallBackFunction ToolbarHelpClick(Window *w) { - PopupMainToolbMenu(w, WID_TN_HELP, STR_ABOUT_MENU_LAND_BLOCK_INFO, _settings_client.gui.newgrf_developer_tools ? 13 : 10); + PopupMainToolbMenu(w, _game_mode == GM_EDITOR ? (int)WID_TE_HELP : (int)WID_TN_HELP, STR_ABOUT_MENU_LAND_BLOCK_INFO, _settings_client.gui.newgrf_developer_tools ? 13 : 10); return CBF_NONE; } @@ -1179,7 +1179,7 @@ static CallBackFunction ToolbarSwitchClick(Window *w) } w->ReInit(); - w->SetWidgetLoweredState(WID_TN_SWITCH_BAR, _toolbar_mode == TB_LOWER); + w->SetWidgetLoweredState(_game_mode == GM_EDITOR ? (uint)WID_TE_SWITCH_BAR : (uint)WID_TN_SWITCH_BAR, _toolbar_mode == TB_LOWER); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); return CBF_NONE; } @@ -1249,7 +1249,7 @@ static CallBackFunction ToolbarScenGenIndustry(Window *w) return CBF_NONE; } -static CallBackFunction ToolbarScenBuildRoad(Window *w) +static CallBackFunction ToolbarScenBuildRoadClick(Window *w) { w->HandleButtonClick(WID_TE_ROADS); if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); @@ -1874,10 +1874,12 @@ class NWidgetScenarioToolbarContainer : public NWidgetToolbarContainer { WID_TE_SETTINGS, WID_TE_SAVE, WID_TE_DATE_PANEL, + WID_TE_SMALL_MAP, WID_TE_ZOOM_IN, WID_TE_ZOOM_OUT, WID_TE_MUSIC_SOUND, - WID_TE_HELP, WID_TE_SWITCH_BAR, + WID_TE_HELP, + WID_TE_SWITCH_BAR, }; /* If we can place all buttons *and* the panels, show them. */ @@ -2265,6 +2267,31 @@ static WindowDesc _toolb_normal_desc( /* --- Toolbar handling for the scenario editor */ +static MenuClickedProc * const _scen_toolbar_dropdown_procs[] = { + nullptr, // 0 + nullptr, // 1 + MenuClickSettings, // 2 + MenuClickSaveLoad, // 3 + nullptr, // 4 + nullptr, // 5 + nullptr, // 6 + nullptr, // 7 + MenuClickMap, // 8 + nullptr, // 9 + nullptr, // 10 + nullptr, // 11 + nullptr, // 12 + nullptr, // 13 + nullptr, // 14 + nullptr, // 15 + nullptr, // 16 + nullptr, // 17 + nullptr, // 18 + MenuClickMusicWindow, // 19 + MenuClickHelp, // 20 + nullptr, // 21 +}; + static ToolbarButtonProc * const _scen_toolbar_button_procs[] = { ToolbarPauseClick, ToolbarFastForwardClick, @@ -2280,20 +2307,12 @@ static ToolbarButtonProc * const _scen_toolbar_button_procs[] = { ToolbarScenGenLand, ToolbarScenGenTown, ToolbarScenGenIndustry, - ToolbarScenBuildRoad, + ToolbarScenBuildRoadClick, ToolbarScenBuildDocks, ToolbarScenPlantTrees, ToolbarScenPlaceSign, ToolbarBtn_NULL, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr, ToolbarMusicClick, - nullptr, ToolbarHelpClick, ToolbarSwitchClick, }; @@ -2396,10 +2415,7 @@ struct ScenarioEditorToolbarWindow : Window { void OnDropdownSelect(int widget, int index) override { - /* The map button is in a different location on the scenario - * editor toolbar, so we need to adjust for it. */ - if (widget == WID_TE_SMALL_MAP) widget = WID_TN_SMALL_MAP; - CallBackFunction cbf = _menu_clicked_procs[widget](index); + CallBackFunction cbf = _scen_toolbar_dropdown_procs[widget](index); if (cbf != CBF_NONE) _last_started_action = cbf; if (_settings_client.sound.click_beep) SndPlayFx(SND_15_BEEP); } @@ -2415,7 +2431,7 @@ struct ScenarioEditorToolbarWindow : Window { case MTEHK_GENLAND: ToolbarScenGenLand(this); break; case MTEHK_GENTOWN: ToolbarScenGenTown(this); break; case MTEHK_GENINDUSTRY: ToolbarScenGenIndustry(this); break; - case MTEHK_BUILD_ROAD: ToolbarScenBuildRoad(this); break; + case MTEHK_BUILD_ROAD: ToolbarScenBuildRoadClick(this); break; case MTEHK_BUILD_DOCKS: ToolbarScenBuildDocks(this); break; case MTEHK_BUILD_TREES: ToolbarScenPlantTrees(this); break; case MTEHK_SIGN: cbf = ToolbarScenPlaceSign(this); break; diff --git a/src/widgets/toolbar_widget.h b/src/widgets/toolbar_widget.h index c317fc9574..5f0c1b5a4f 100644 --- a/src/widgets/toolbar_widget.h +++ b/src/widgets/toolbar_widget.h @@ -70,10 +70,9 @@ enum ToolbarEditorWidgets { WID_TE_TREES, ///< Tree building toolbar. WID_TE_SIGNS, ///< Sign building. WID_TE_DATE_PANEL, ///< Container for the date widgets. - /* The following three need to have the same actual widget number as the normal toolbar due to shared code. */ - WID_TE_MUSIC_SOUND = WID_TN_MUSIC_SOUND, ///< Music/sound configuration menu. - WID_TE_HELP = WID_TN_HELP, ///< Help menu. - WID_TE_SWITCH_BAR = WID_TN_SWITCH_BAR, ///< Only available when toolbar has been split to switch between different subsets. + WID_TE_MUSIC_SOUND, ///< Music/sound configuration menu. + WID_TE_HELP, ///< Help menu. + WID_TE_SWITCH_BAR, ///< Only available when toolbar has been split to switch between different subsets. }; #endif /* WIDGETS_TOOLBAR_WIDGET_H */