2009-08-21 21:21:05 +01:00
|
|
|
/*
|
|
|
|
* 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 <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2007-12-21 19:49:27 +00:00
|
|
|
/** @file strings_type.h Types related to strings. */
|
|
|
|
|
|
|
|
#ifndef STRINGS_TYPE_H
|
|
|
|
#define STRINGS_TYPE_H
|
|
|
|
|
2024-12-06 22:16:00 +00:00
|
|
|
#include "core/convertible_through_base.hpp"
|
2025-01-02 08:03:38 +00:00
|
|
|
#include "core/strong_typedef_type.hpp"
|
|
|
|
|
2008-08-01 10:34:34 +01:00
|
|
|
/**
|
|
|
|
* Numeric value that represents a string, independent of the selected language.
|
|
|
|
*/
|
2023-05-08 18:01:06 +01:00
|
|
|
typedef uint32_t StringID;
|
2017-02-26 19:41:14 +00:00
|
|
|
static const StringID INVALID_STRING_ID = 0xFFFF; ///< Constant representing an invalid string (16bit in case it is used in savegames)
|
2010-05-13 10:44:44 +01:00
|
|
|
static const int MAX_CHAR_LENGTH = 4; ///< Max. length of UTF-8 encoded unicode character
|
2010-11-10 16:25:20 +00:00
|
|
|
static const uint MAX_LANG = 0x7F; ///< Maximum number of languages supported by the game, and the NewGRF specs
|
2007-12-21 19:49:27 +00:00
|
|
|
|
2008-10-17 18:42:51 +01:00
|
|
|
/** Directions a text can go to */
|
2025-01-28 22:17:34 +00:00
|
|
|
enum TextDirection : uint8_t {
|
2008-10-17 18:42:51 +01:00
|
|
|
TD_LTR, ///< Text is written left-to-right by default
|
|
|
|
TD_RTL, ///< Text is written right-to-left by default
|
|
|
|
};
|
|
|
|
|
2017-02-26 19:40:53 +00:00
|
|
|
/** StringTabs to group StringIDs */
|
2025-01-28 22:17:34 +00:00
|
|
|
enum StringTab : uint8_t {
|
2017-02-26 19:40:53 +00:00
|
|
|
/* Tabs 0..1 for regular strings */
|
|
|
|
TEXT_TAB_TOWN = 4,
|
|
|
|
TEXT_TAB_INDUSTRY = 9,
|
|
|
|
TEXT_TAB_STATION = 12,
|
|
|
|
TEXT_TAB_SPECIAL = 14,
|
|
|
|
TEXT_TAB_OLD_CUSTOM = 15,
|
|
|
|
TEXT_TAB_VEHICLE = 16,
|
|
|
|
/* Tab 17 for regular strings */
|
|
|
|
TEXT_TAB_OLD_NEWGRF = 26,
|
2017-02-26 19:41:30 +00:00
|
|
|
TEXT_TAB_END = 32, ///< End of language files.
|
|
|
|
TEXT_TAB_GAMESCRIPT_START = 32, ///< Start of GameScript supplied strings.
|
|
|
|
TEXT_TAB_NEWGRF_START = 64, ///< Start of NewGRF supplied strings.
|
2017-02-26 19:40:53 +00:00
|
|
|
};
|
|
|
|
|
2025-01-02 08:03:38 +00:00
|
|
|
/** The index/offset of a string within a #StringTab. */
|
|
|
|
using StringIndexInTab = StrongType::Typedef<uint32_t, struct StringIndexInTabTag, StrongType::Compare, StrongType::Integer>;
|
|
|
|
|
2017-02-26 19:40:32 +00:00
|
|
|
/** Number of bits for the StringIndex within a StringTab */
|
|
|
|
static const uint TAB_SIZE_BITS = 11;
|
|
|
|
/** Number of strings per StringTab */
|
|
|
|
static const uint TAB_SIZE = 1 << TAB_SIZE_BITS;
|
|
|
|
|
2017-02-26 19:41:30 +00:00
|
|
|
/** Number of strings for GameScripts */
|
|
|
|
static const uint TAB_SIZE_GAMESCRIPT = TAB_SIZE * 32;
|
|
|
|
|
|
|
|
/** Number of strings for NewGRFs */
|
|
|
|
static const uint TAB_SIZE_NEWGRF = TAB_SIZE * 256;
|
|
|
|
|
2025-01-04 09:56:17 +00:00
|
|
|
/** The number of builtin generators for town names. */
|
|
|
|
static constexpr uint32_t BUILTIN_TOWNNAME_GENERATOR_COUNT = 21;
|
|
|
|
|
|
|
|
/** Special strings for town names. The town name is generated dynamically on request. */
|
|
|
|
static constexpr StringID SPECSTR_TOWNNAME_START = 0x20C0;
|
|
|
|
static constexpr StringID SPECSTR_TOWNNAME_END = SPECSTR_TOWNNAME_START + BUILTIN_TOWNNAME_GENERATOR_COUNT;
|
|
|
|
|
|
|
|
/** Special strings for company names on the form "TownName transport". */
|
|
|
|
static constexpr StringID SPECSTR_COMPANY_NAME_START = 0x70EA;
|
|
|
|
static constexpr StringID SPECSTR_COMPANY_NAME_END = SPECSTR_COMPANY_NAME_START + BUILTIN_TOWNNAME_GENERATOR_COUNT;
|
|
|
|
|
|
|
|
static constexpr StringID SPECSTR_SILLY_NAME = 0x70E5; ///< Special string for silly company names.
|
|
|
|
static constexpr StringID SPECSTR_ANDCO_NAME = 0x70E6; ///< Special string for Surname & Co company names.
|
|
|
|
static constexpr StringID SPECSTR_PRESIDENT_NAME = 0x70E7; ///< Special string for the president's name.
|
2007-12-21 19:49:27 +00:00
|
|
|
|
2024-07-29 17:58:32 +01:00
|
|
|
using StringParameterData = std::variant<uint64_t, std::string>;
|
2023-06-21 05:35:06 +01:00
|
|
|
|
2024-12-06 22:16:00 +00:00
|
|
|
/** The data required to format and validate a single parameter of a string. */
|
|
|
|
struct StringParameter {
|
|
|
|
StringParameterData data; ///< The data of the parameter.
|
|
|
|
char32_t type; ///< The #StringControlCode to interpret this data with when it's the first parameter, otherwise '\0'.
|
|
|
|
|
|
|
|
StringParameter() = default;
|
|
|
|
inline StringParameter(StringParameterData &&data) : data(std::move(data)), type(0) {}
|
|
|
|
|
|
|
|
inline StringParameter(uint64_t data) : data(data), type(0) {}
|
|
|
|
|
|
|
|
inline StringParameter(const char *data) : data(std::string{data}), type(0) {}
|
|
|
|
inline StringParameter(std::string &&data) : data(std::move(data)), type(0) {}
|
|
|
|
inline StringParameter(const std::string &data) : data(data), type(0) {}
|
|
|
|
|
|
|
|
inline StringParameter(const ConvertibleThroughBase auto &data) : data(static_cast<uint64_t>(data.base())), type(0) {}
|
|
|
|
};
|
|
|
|
|
2007-12-21 19:49:27 +00:00
|
|
|
#endif /* STRINGS_TYPE_H */
|