OpenTTD Source: src/strings_type.h Source File

OpenTTD Source 14.1

strings_type.h
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
7
10 #ifndef STRINGS_TYPE_H
11 #define STRINGS_TYPE_H
12
16 typedef uint32_t StringID;
17 static const StringID INVALID_STRING_ID = 0xFFFF;
18 static const int MAX_CHAR_LENGTH = 4;
19 static const uint MAX_LANG = 0x7F;
20
22 enum TextDirection {
23 TD_LTR,
24 TD_RTL,
25 };
26
28 enum StringTab {
29 /* Tabs 0..1 for regular strings */
30 TEXT_TAB_TOWN = 4,
31 TEXT_TAB_INDUSTRY = 9,
32 TEXT_TAB_STATION = 12,
33 TEXT_TAB_SPECIAL = 14,
34 TEXT_TAB_OLD_CUSTOM = 15,
35 TEXT_TAB_VEHICLE = 16,
36 /* Tab 17 for regular strings */
37 TEXT_TAB_OLD_NEWGRF = 26,
38 TEXT_TAB_END = 32,
39 TEXT_TAB_GAMESCRIPT_START = 32,
40 TEXT_TAB_NEWGRF_START = 64,
41 };
42
44 static const uint TAB_SIZE_BITS = 11;
46 static const uint TAB_SIZE = 1 << TAB_SIZE_BITS;
47
49 static const uint TAB_SIZE_GAMESCRIPT = TAB_SIZE * 32;
50
52 static const uint TAB_SIZE_NEWGRF = TAB_SIZE * 256;
53
55 enum SpecialStrings {
56
57 /* special strings for town names. the town name is generated dynamically on request. */
58 SPECSTR_TOWNNAME_START = 0x20C0,
59 SPECSTR_TOWNNAME_ENGLISH = SPECSTR_TOWNNAME_START,
60 SPECSTR_TOWNNAME_FRENCH,
61 SPECSTR_TOWNNAME_GERMAN,
62 SPECSTR_TOWNNAME_AMERICAN,
63 SPECSTR_TOWNNAME_LATIN,
64 SPECSTR_TOWNNAME_SILLY,
65 SPECSTR_TOWNNAME_SWEDISH,
66 SPECSTR_TOWNNAME_DUTCH,
67 SPECSTR_TOWNNAME_FINNISH,
68 SPECSTR_TOWNNAME_POLISH,
69 SPECSTR_TOWNNAME_SLOVAK,
70 SPECSTR_TOWNNAME_NORWEGIAN,
71 SPECSTR_TOWNNAME_HUNGARIAN,
72 SPECSTR_TOWNNAME_AUSTRIAN,
73 SPECSTR_TOWNNAME_ROMANIAN,
74 SPECSTR_TOWNNAME_CZECH,
75 SPECSTR_TOWNNAME_SWISS,
76 SPECSTR_TOWNNAME_DANISH,
77 SPECSTR_TOWNNAME_TURKISH,
78 SPECSTR_TOWNNAME_ITALIAN,
79 SPECSTR_TOWNNAME_CATALAN,
80 SPECSTR_TOWNNAME_LAST = SPECSTR_TOWNNAME_CATALAN,
81
82 /* special strings for company names on the form "TownName transport". */
83 SPECSTR_COMPANY_NAME_START = 0x70EA,
84 SPECSTR_COMPANY_NAME_LAST = SPECSTR_COMPANY_NAME_START + SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START,
85
86 SPECSTR_SILLY_NAME = 0x70E5,
87 SPECSTR_ANDCO_NAME = 0x70E6,
88 SPECSTR_PRESIDENT_NAME = 0x70E7,
89 };
90
92 struct StringParameterBackup {
93 uint64_t data;
94 std::optional<std::string> string;
95
101 StringParameterBackup &operator=(uint64_t data)
102 {
103 this->string.reset();
104 this->data = data;
105 return *this;
106 }
107
113 StringParameterBackup &operator=(const std::string_view string)
114 {
115 this->data = 0;
116 this->string.emplace(string);
117 return *this;
118 }
119 };
120
121 #endif /* STRINGS_TYPE_H */
StringParameterBackup
Data that is to be stored when backing up StringParameters.
Definition: strings_type.h:92
TEXT_TAB_END
@ TEXT_TAB_END
End of language files.
Definition: strings_type.h:38
TEXT_TAB_NEWGRF_START
@ TEXT_TAB_NEWGRF_START
Start of NewGRF supplied strings.
Definition: strings_type.h:40
TD_LTR
@ TD_LTR
Text is written left-to-right by default.
Definition: strings_type.h:23
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
StringTab
StringTab
StringTabs to group StringIDs.
Definition: strings_type.h:28
TAB_SIZE_NEWGRF
static const uint TAB_SIZE_NEWGRF
Number of strings for NewGRFs.
Definition: strings_type.h:52
MAX_CHAR_LENGTH
static const int MAX_CHAR_LENGTH
Max. length of UTF-8 encoded unicode character.
Definition: strings_type.h:18
TAB_SIZE
static const uint TAB_SIZE
Number of strings per StringTab.
Definition: strings_type.h:46
StringParameterBackup::operator=
StringParameterBackup & operator=(uint64_t data)
Assign the numeric data with the given value, while clearing the stored string.
Definition: strings_type.h:101
TAB_SIZE_GAMESCRIPT
static const uint TAB_SIZE_GAMESCRIPT
Number of strings for GameScripts.
Definition: strings_type.h:49
MAX_LANG
static const uint MAX_LANG
Maximum number of languages supported by the game, and the NewGRF specs.
Definition: strings_type.h:19
SpecialStrings
SpecialStrings
Special string constants.
Definition: strings_type.h:55
TextDirection
TextDirection
Directions a text can go to.
Definition: strings_type.h:22
TEXT_TAB_GAMESCRIPT_START
@ TEXT_TAB_GAMESCRIPT_START
Start of GameScript supplied strings.
Definition: strings_type.h:39
StringParameterBackup::string
std::optional< std::string > string
The string value.
Definition: strings_type.h:94
StringParameterBackup::operator=
StringParameterBackup & operator=(const std::string_view string)
Assign a copy of the given string to the string field, while clearing the data field.
Definition: strings_type.h:113
StringParameterBackup::data
uint64_t data
The data field; valid when string has no value.
Definition: strings_type.h:93
TAB_SIZE_BITS
static const uint TAB_SIZE_BITS
Number of bits for the StringIndex within a StringTab.
Definition: strings_type.h:44
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17