OpenTTD Source 20250312-master-gcdcc6b491d
strings_type.h File Reference

Types related to strings. More...

Go to the source code of this file.

Data Structures

struct  StringParameter
 The data required to format and validate a single parameter of a string. More...
 
class  EncodedString
 Container for an encoded string, created by GetEncodedString. More...
 

Typedefs

typedef uint32_t StringID
 Numeric value that represents a string, independent of the selected language.
 
using StringIndexInTab = StrongType::Typedef< uint32_t, struct StringIndexInTabTag, StrongType::Compare, StrongType::Integer >
 The index/offset of a string within a StringTab.
 
using StringParameterData = std::variant< std::monostate, uint64_t, std::string >
 

Enumerations

enum  TextDirection : uint8_t { TD_LTR , TD_RTL }
 Directions a text can go to. More...
 
enum  StringTab : uint8_t {
  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 , TEXT_TAB_OLD_NEWGRF = 26 , TEXT_TAB_END = 32 ,
  TEXT_TAB_GAMESCRIPT_START = 32 , TEXT_TAB_NEWGRF_START = 64
}
 StringTabs to group StringIDs. More...
 

Variables

static const StringID INVALID_STRING_ID = 0xFFFF
 Constant representing an invalid string (16bit in case it is used in savegames)
 
static const int MAX_CHAR_LENGTH = 4
 Max. length of UTF-8 encoded unicode character.
 
static const uint MAX_LANG = 0x7F
 Maximum number of languages supported by the game, and the NewGRF specs.
 
static const uint TAB_SIZE_BITS = 11
 Number of bits for the StringIndex within a StringTab.
 
static const uint TAB_SIZE = 1 << TAB_SIZE_BITS
 Number of strings per StringTab.
 
static const uint TAB_SIZE_GAMESCRIPT = TAB_SIZE * 32
 Number of strings for GameScripts.
 
static const uint TAB_SIZE_NEWGRF = TAB_SIZE * 256
 Number of strings for NewGRFs.
 
static constexpr uint32_t BUILTIN_TOWNNAME_GENERATOR_COUNT = 21
 The number of builtin generators for town names.
 
static constexpr StringID SPECSTR_TOWNNAME_START = 0x20C0
 Special strings for town names.
 
static constexpr StringID SPECSTR_TOWNNAME_END = SPECSTR_TOWNNAME_START + BUILTIN_TOWNNAME_GENERATOR_COUNT
 
static constexpr StringID SPECSTR_COMPANY_NAME_START = 0x70EA
 Special strings for company names on the form "TownName transport".
 
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.
 

Detailed Description

Types related to strings.

Definition in file strings_type.h.

Typedef Documentation

◆ StringID

typedef uint32_t StringID

Numeric value that represents a string, independent of the selected language.

Definition at line 19 of file strings_type.h.

◆ StringIndexInTab

using StringIndexInTab = StrongType::Typedef<uint32_t, struct StringIndexInTabTag, StrongType::Compare, StrongType::Integer>

The index/offset of a string within a StringTab.

Definition at line 47 of file strings_type.h.

◆ StringParameterData

using StringParameterData = std::variant<std::monostate, uint64_t, std::string>

Definition at line 75 of file strings_type.h.

Enumeration Type Documentation

◆ StringTab

enum StringTab : uint8_t

StringTabs to group StringIDs.

Enumerator
TEXT_TAB_END 

End of language files.

TEXT_TAB_GAMESCRIPT_START 

Start of GameScript supplied strings.

TEXT_TAB_NEWGRF_START 

Start of NewGRF supplied strings.

Definition at line 31 of file strings_type.h.

◆ TextDirection

enum TextDirection : uint8_t

Directions a text can go to.

Enumerator
TD_LTR 

Text is written left-to-right by default.

TD_RTL 

Text is written right-to-left by default.

Definition at line 25 of file strings_type.h.

Variable Documentation

◆ BUILTIN_TOWNNAME_GENERATOR_COUNT

constexpr uint32_t BUILTIN_TOWNNAME_GENERATOR_COUNT = 21
staticconstexpr

The number of builtin generators for town names.

Definition at line 61 of file strings_type.h.

Referenced by GenerateLandscapeWindow::GetWidgetString(), and TownNameParams::TownNameParams().

◆ INVALID_STRING_ID

◆ MAX_CHAR_LENGTH

const int MAX_CHAR_LENGTH = 4
static

Max. length of UTF-8 encoded unicode character.

Definition at line 21 of file strings_type.h.

Referenced by ShowQueryString().

◆ MAX_LANG

const uint MAX_LANG = 0x7F
static

Maximum number of languages supported by the game, and the NewGRF specs.

Definition at line 22 of file strings_type.h.

Referenced by GlobalVarChangeInfo(), and LanguagePackHeader::IsValid().

◆ SPECSTR_ANDCO_NAME

constexpr StringID SPECSTR_ANDCO_NAME = 0x70E6
staticconstexpr

Special string for Surname & Co company names.

Definition at line 72 of file strings_type.h.

Referenced by GenerateCompanyName(), and PLYRChunkHandler::LoadCheck().

◆ SPECSTR_COMPANY_NAME_END

constexpr StringID SPECSTR_COMPANY_NAME_END = SPECSTR_COMPANY_NAME_START + BUILTIN_TOWNNAME_GENERATOR_COUNT
staticconstexpr

Definition at line 69 of file strings_type.h.

◆ SPECSTR_COMPANY_NAME_START

constexpr StringID SPECSTR_COMPANY_NAME_START = 0x70EA
staticconstexpr

Special strings for company names on the form "TownName transport".

Definition at line 68 of file strings_type.h.

Referenced by GenerateCompanyName(), PLYRChunkHandler::LoadCheck(), and RemapOldStringID().

◆ SPECSTR_PRESIDENT_NAME

constexpr StringID SPECSTR_PRESIDENT_NAME = 0x70E7
staticconstexpr

Special string for the president's name.

Definition at line 73 of file strings_type.h.

Referenced by AfterLoadGame(), GenerateCompanyName(), GeneratePresidentName(), and PLYRChunkHandler::LoadCheck().

◆ SPECSTR_SILLY_NAME

constexpr StringID SPECSTR_SILLY_NAME = 0x70E5
staticconstexpr

Special string for silly company names.

Definition at line 71 of file strings_type.h.

Referenced by PLYRChunkHandler::LoadCheck().

◆ SPECSTR_TOWNNAME_END

constexpr StringID SPECSTR_TOWNNAME_END = SPECSTR_TOWNNAME_START + BUILTIN_TOWNNAME_GENERATOR_COUNT
staticconstexpr

Definition at line 65 of file strings_type.h.

◆ SPECSTR_TOWNNAME_START

constexpr StringID SPECSTR_TOWNNAME_START = 0x20C0
staticconstexpr

Special strings for town names.

The town name is generated dynamically on request.

Definition at line 64 of file strings_type.h.

Referenced by AfterLoadGame(), GenerateCompanyName(), GetStringWithArgs(), CITYChunkHandler::Load(), TownNameParams::TownNameParams(), and TownNameParams::TownNameParams().

◆ TAB_SIZE

const uint TAB_SIZE = 1 << TAB_SIZE_BITS
static

Number of strings per StringTab.

Definition at line 52 of file strings_type.h.

Referenced by StringData::CountInUse(), MakeStringID(), ReadLanguagePack(), and LanguageWriter::WriteLang().

◆ TAB_SIZE_BITS

const uint TAB_SIZE_BITS = 11
static

Number of bits for the StringIndex within a StringTab.

Definition at line 50 of file strings_type.h.

Referenced by GetStringIndex(), GetStringTab(), and MakeStringID().

◆ TAB_SIZE_GAMESCRIPT

const uint TAB_SIZE_GAMESCRIPT = TAB_SIZE * 32
static

Number of strings for GameScripts.

Definition at line 55 of file strings_type.h.

Referenced by DecodeEncodedString(), and MakeStringID().

◆ TAB_SIZE_NEWGRF

const uint TAB_SIZE_NEWGRF = TAB_SIZE * 256
static

Number of strings for NewGRFs.

Definition at line 58 of file strings_type.h.

Referenced by AddGRFString(), and MakeStringID().