From 3b8b089dd42dac0e62868db429eb1777f262c1cc Mon Sep 17 00:00:00 2001 From: Rubidium Date: Thu, 18 Jun 2026 17:53:12 +0200 Subject: [PATCH] Codechange: split currency.h to _type.h and _func.h --- src/CMakeLists.txt | 3 +- src/cheat_gui.cpp | 2 +- src/company_gui.cpp | 2 +- src/currency.cpp | 2 +- src/currency_func.h | 40 +++++++++++++++++++++++ src/{currency.h => currency_type.h} | 48 +++++----------------------- src/graph_gui.cpp | 2 +- src/main_gui.cpp | 2 +- src/newgrf.cpp | 2 +- src/newgrf/newgrf_act0_globalvar.cpp | 2 +- src/settings.cpp | 2 +- src/settings_gui.cpp | 2 +- src/settings_table.cpp | 2 +- src/strings.cpp | 2 +- src/survey.cpp | 2 +- 15 files changed, 62 insertions(+), 53 deletions(-) create mode 100644 src/currency_func.h rename src/{currency.h => currency_type.h} (73%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b4af2a32ec..d2af5f7b62 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -133,7 +133,8 @@ add_files( crashlog.cpp crashlog.h currency.cpp - currency.h + currency_func.h + currency_type.h date_gui.cpp date_gui.h debug.cpp diff --git a/src/cheat_gui.cpp b/src/cheat_gui.cpp index f2fc496450..fab3f7d547 100644 --- a/src/cheat_gui.cpp +++ b/src/cheat_gui.cpp @@ -12,7 +12,7 @@ #include "cheat_type.h" #include "company_base.h" #include "company_func.h" -#include "currency.h" +#include "currency_func.h" #include "saveload/saveload.h" #include "vehicle_base.h" #include "textbuf_gui.h" diff --git a/src/company_gui.cpp b/src/company_gui.cpp index 80f231ce4b..7e75d9a6ba 100644 --- a/src/company_gui.cpp +++ b/src/company_gui.cpp @@ -8,7 +8,7 @@ /** @file company_gui.cpp %Company related GUIs. */ #include "stdafx.h" -#include "currency.h" +#include "currency_func.h" #include "error.h" #include "gui.h" #include "settings_gui.h" diff --git a/src/currency.cpp b/src/currency.cpp index c86ba78802..5c7164449b 100644 --- a/src/currency.cpp +++ b/src/currency.cpp @@ -10,7 +10,7 @@ #include "stdafx.h" #include "core/bitmath_func.hpp" -#include "currency.h" +#include "currency_func.h" #include "news_func.h" #include "settings_type.h" #include "string_type.h" diff --git a/src/currency_func.h b/src/currency_func.h new file mode 100644 index 0000000000..d9cde36ab9 --- /dev/null +++ b/src/currency_func.h @@ -0,0 +1,40 @@ +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . + */ + +/** @file currency_func.h Functions to handle different currencies. */ + +#ifndef CURRENCY_FUNC_H +#define CURRENCY_FUNC_H + +#include "currency_type.h" +#include "settings_type.h" + +extern std::array _currency_specs; + +/** + * Get the custom currency. + * @return Reference to custom currency. + */ +inline CurrencySpec &GetCustomCurrency() +{ + return _currency_specs[CURRENCY_CUSTOM]; +} + +/** + * Get the currently selected currency. + * @return Read-only reference to the current currency. + */ +inline const CurrencySpec &GetCurrency() +{ + return _currency_specs[GetGameSettings().locale.currency]; +} + +uint64_t GetMaskOfAllowedCurrencies(); +void ResetCurrencies(bool preserve_custom = true); +uint8_t GetNewgrfCurrencyIdConverted(uint8_t grfcurr_id); + +#endif /* CURRENCY_FUNC_H */ diff --git a/src/currency.h b/src/currency_type.h similarity index 73% rename from src/currency.h rename to src/currency_type.h index 88488160b1..6b0af20754 100644 --- a/src/currency.h +++ b/src/currency_type.h @@ -5,13 +5,12 @@ * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see . */ -/** @file currency.h Functions to handle different currencies. */ +/** @file currency_type.h Types related to currencies. */ -#ifndef CURRENCY_H -#define CURRENCY_H +#ifndef CURRENCY_TYPE_H +#define CURRENCY_TYPE_H #include "timer/timer_game_calendar.h" -#include "settings_type.h" #include "strings_type.h" static constexpr TimerGameCalendar::Year CF_NOEURO{0}; ///< Currency never switches to the Euro (as far as known). @@ -75,11 +74,11 @@ enum Currencies : uint8_t { /** Specification of a currency. */ struct CurrencySpec { - uint16_t rate; ///< The conversion rate compared to the base currency. + uint16_t rate; ///< The conversion rate compared to the base currency. std::string separator; ///< The thousands separator for this currency. TimerGameCalendar::Year to_euro; ///< Year of switching to the Euro. May also be #CF_NOEURO or #CF_ISEURO. - std::string prefix; ///< Prefix to apply when formatting money in this currency. - std::string suffix; ///< Suffix to apply when formatting money in this currency. + std::string prefix; ///< Prefix to apply when formatting money in this currency. + std::string suffix; ///< Suffix to apply when formatting money in this currency. std::string code; ///< 3 letter untranslated code to identify the currency. /** * The currency symbol is represented by two possible values, prefix and suffix @@ -91,38 +90,7 @@ struct CurrencySpec { * rather a way to let users do what they want with custom currency */ uint8_t symbol_pos; - StringID name; - - CurrencySpec() = default; - - CurrencySpec(uint16_t rate, std::string_view separator, TimerGameCalendar::Year to_euro, std::string_view prefix, std::string_view suffix, std::string_view code, uint8_t symbol_pos, StringID name) : - rate(rate), separator(separator), to_euro(to_euro), prefix(prefix), suffix(suffix), code(code), symbol_pos(symbol_pos), name(name) - { - } + StringID name; ///< Translated name of this currency. }; -extern std::array _currency_specs; - -/** - * Get the custom currency. - * @return Reference to custom currency. - */ -inline CurrencySpec &GetCustomCurrency() -{ - return _currency_specs[CURRENCY_CUSTOM]; -} - -/** - * Get the currently selected currency. - * @return Read-only reference to the current currency. - */ -inline const CurrencySpec &GetCurrency() -{ - return _currency_specs[GetGameSettings().locale.currency]; -} - -uint64_t GetMaskOfAllowedCurrencies(); -void ResetCurrencies(bool preserve_custom = true); -uint8_t GetNewgrfCurrencyIdConverted(uint8_t grfcurr_id); - -#endif /* CURRENCY_H */ +#endif /* CURRENCY_TYPE_H */ diff --git a/src/graph_gui.cpp b/src/graph_gui.cpp index 307cbb91e7..fc2d1ea024 100644 --- a/src/graph_gui.cpp +++ b/src/graph_gui.cpp @@ -21,7 +21,7 @@ #include "sound_func.h" #include "gfx_func.h" #include "core/geometry_func.hpp" -#include "currency.h" +#include "currency_func.h" #include "timer/timer.h" #include "timer/timer_window.h" #include "timer/timer_game_tick.h" diff --git a/src/main_gui.cpp b/src/main_gui.cpp index 9b4018d041..6e79ae4c46 100644 --- a/src/main_gui.cpp +++ b/src/main_gui.cpp @@ -8,7 +8,7 @@ /** @file main_gui.cpp Handling of the main viewport. */ #include "stdafx.h" -#include "currency.h" +#include "currency_type.h" #include "spritecache.h" #include "window_gui.h" #include "window_func.h" diff --git a/src/newgrf.cpp b/src/newgrf.cpp index c7384ee161..4a2edd30db 100644 --- a/src/newgrf.cpp +++ b/src/newgrf.cpp @@ -20,7 +20,7 @@ #include "newgrf_engine.h" #include "newgrf_text.h" #include "spritecache.h" -#include "currency.h" +#include "currency_func.h" #include "landscape.h" #include "newgrf_badge.h" #include "newgrf_badge_config.h" diff --git a/src/newgrf/newgrf_act0_globalvar.cpp b/src/newgrf/newgrf_act0_globalvar.cpp index 8269988c0a..5e5dee41f0 100644 --- a/src/newgrf/newgrf_act0_globalvar.cpp +++ b/src/newgrf/newgrf_act0_globalvar.cpp @@ -9,7 +9,7 @@ #include "../stdafx.h" #include "../debug.h" -#include "../currency.h" +#include "../currency_func.h" #include "../landscape.h" #include "../language.h" #include "../rev.h" diff --git a/src/settings.cpp b/src/settings.cpp index 851bbfea93..fde611a04e 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -26,7 +26,7 @@ #include "core/string_consumer.hpp" #include "settings_table.h" #include "debug.h" -#include "currency.h" +#include "currency_func.h" #include "network/network.h" #include "network/network_func.h" #include "network/core/config.h" diff --git a/src/settings_gui.cpp b/src/settings_gui.cpp index cf574fa756..d213e15aea 100644 --- a/src/settings_gui.cpp +++ b/src/settings_gui.cpp @@ -8,7 +8,7 @@ /** @file settings_gui.cpp GUI for settings. */ #include "stdafx.h" -#include "currency.h" +#include "currency_func.h" #include "error.h" #include "settings_gui.h" #include "textbuf_gui.h" diff --git a/src/settings_table.cpp b/src/settings_table.cpp index dd7f55b8f9..a99704dee9 100644 --- a/src/settings_table.cpp +++ b/src/settings_table.cpp @@ -9,7 +9,7 @@ #include "stdafx.h" #include "settings_table.h" -#include "currency.h" +#include "currency_type.h" #include "screenshot.h" #include "network/network.h" #include "network/network_func.h" diff --git a/src/strings.cpp b/src/strings.cpp index 4561aa0d71..0e6d079a1f 100644 --- a/src/strings.cpp +++ b/src/strings.cpp @@ -8,7 +8,7 @@ /** @file strings.cpp Handling of translated strings. */ #include "stdafx.h" -#include "currency.h" +#include "currency_func.h" #include "station_base.h" #include "town.h" #include "waypoint_base.h" diff --git a/src/survey.cpp b/src/survey.cpp index 427dd2b6a3..ff5cd3ea4e 100644 --- a/src/survey.cpp +++ b/src/survey.cpp @@ -20,7 +20,7 @@ #include "timer/timer_game_economy.h" #include "3rdparty/fmt/ranges.h" -#include "currency.h" +#include "currency_func.h" #include "fontcache.h" #include "language.h"