43#include "table/strings.h"
45#include "3rdparty/fmt/std.h"
71 throw std::out_of_range(
"Trying to read invalid string parameter");
75 if (param.type != 0 && param.type != this->next_type) {
77 throw std::out_of_range(
"Trying to read string parameter with wrong type");
111 void operator()(
const std::monostate &) {}
113 void operator()(
const uint64_t &arg)
119 void operator()(
const std::string &value)
129 this->builder += value;
134 for (
const auto ¶m : params) {
135 builder.
PutUtf8(SCC_RECORD_SEPARATOR);
136 std::visit(v, param.data);
151 if (this->empty())
return {};
153 std::vector<StringParameter> params;
171 params.emplace_back(std::monostate{});
176 char32_t parameter_type = record.
ReadUtf8();
177 switch (parameter_type) {
181 params.emplace_back(value);
192 params.emplace_back(std::monostate{});
197 if (param >= std::size(params))
return {};
198 params[param] = data;
208 return GetString(STR_JUST_RAW_STRING, this->
string);
220 uint64_t val = count > 1 ? front : next;
221 for (; count > 1; count--) {
222 val = 10 * val + next;
238 while (max_value >= 10) {
260static void FormatString(
StringBuilder &builder, std::string_view str, std::span<StringParameter> params, uint case_index = 0,
bool game_script =
false,
bool dry_run =
false)
263 FormatString(builder, str, tmp_params, case_index, game_script, dry_run);
274 delete[]
reinterpret_cast<char *
>(langpack);
279 std::unique_ptr<LanguagePack, LanguagePackDeleter> langpack;
281 std::vector<std::string_view> strings;
300 return _langpack.list_separator;
309 return _langpack.ellipsis;
312std::string_view GetStringPtr(
StringID string)
317 case TEXT_TAB_OLD_NEWGRF: NOT_REACHED();
321 if (offset < _langpack.strings.size())
return _langpack.strings[offset];
322 return "(undefined string)";
350 }
catch (
const std::runtime_error &e) {
352 builder +=
"(invalid string parameter)";
358 case TEXT_TAB_SPECIAL:
361 if (GetSpecialNameString(builder,
string, args))
return;
362 }
catch (
const std::runtime_error &e) {
364 builder +=
"(invalid string parameter)";
370 case TEXT_TAB_OLD_CUSTOM:
373 FatalError(
"Incorrect conversion of custom name string.");
382 case TEXT_TAB_OLD_NEWGRF:
394 if (index >= _langpack.langtab_num[tab]) {
398 FatalError(
"String 0x{:X} is invalid. You are probably using an old version of the .lng file.\n",
string);
401 FormatString(builder, GetStringPtr(
string), args, case_index);
439void AppendStringWithArgsInPlace(std::string &result,
StringID string, std::span<StringParameter> params)
468static std::string_view GetDecimalSeparator()
470 std::string_view decimal_separator =
_settings_game.locale.digit_decimal_separator;
471 if (decimal_separator.empty()) decimal_separator = _langpack.langpack->digit_decimal_separator;
472 return decimal_separator;
483 static const int max_digits = 20;
484 uint64_t divisor = 10000000000000000000ULL;
485 int thousands_offset = (max_digits - 1) % 3;
492 uint64_t num = number;
494 for (
int i = 0; i < max_digits; i++) {
496 if (num >= divisor) {
497 quot = num / divisor;
500 if ((tot |= quot) || i == max_digits - 1) {
502 if ((i % 3) == thousands_offset && i < max_digits - 1) builder += separator;
509static void FormatCommaNumber(
StringBuilder &builder, int64_t number)
511 std::string_view separator =
_settings_game.locale.digit_group_separator;
512 if (separator.empty()) separator = _langpack.langpack->digit_group_separator;
516static void FormatNoCommaNumber(
StringBuilder &builder, int64_t number)
521static void FormatZerofillNumber(
StringBuilder &builder, int64_t number,
int count)
523 fmt::format_to(builder.
back_inserter(),
"{:0{}d}", number, count);
526static void FormatHexNumber(
StringBuilder &builder, uint64_t number)
541 static const std::string_view iec_prefixes[] = {
"",
"Ki",
"Mi",
"Gi",
"Ti",
"Pi",
"Ei"};
543 while (number >= 1024 * 1024) {
551 }
else if (number < 1024 * 10) {
552 fmt::format_to(builder.
back_inserter(),
"{}{}{:02}", number / 1024, GetDecimalSeparator(), (number % 1024) * 100 / 1024);
553 }
else if (number < 1024 * 100) {
554 fmt::format_to(builder.
back_inserter(),
"{}{}{:01}", number / 1024, GetDecimalSeparator(), (number % 1024) * 10 / 1024);
556 assert(number < 1024 * 1024);
557 fmt::format_to(builder.
back_inserter(),
"{}", number / 1024);
560 assert(
id <
lengthof(iec_prefixes));
568 auto tmp_params =
MakeParameters(STR_DAY_NUMBER_1ST + ymd.day - 1, STR_MONTH_ABBREV_JAN + ymd.month, ymd.year);
569 FormatString(builder, GetStringPtr(STR_FORMAT_DATE_LONG), tmp_params, case_index);
576 auto tmp_params =
MakeParameters(STR_MONTH_JAN + ymd.month, ymd.year);
577 FormatString(builder, GetStringPtr(STR_FORMAT_DATE_SHORT), tmp_params, case_index);
585 auto tmp_params =
MakeParameters(ymd.day, 2, ymd.month + 1, 2, ymd.year);
593 bool negative = number < 0;
595 number *= spec->
rate;
599 builder.
PutUtf8(SCC_PUSH_COLOUR);
614 if (number >= Money(1'000'000'000'000'000) - 500'000'000) {
615 number = (number + Money(500'000'000'000)) / Money(1'000'000'000'000);
616 number_str = STR_CURRENCY_SHORT_TERA;
617 }
else if (number >= Money(1'000'000'000'000) - 500'000) {
618 number = (number + 500'000'000) / 1'000'000'000;
619 number_str = STR_CURRENCY_SHORT_GIGA;
620 }
else if (number >= 1'000'000'000 - 500) {
621 number = (number + 500'000) / 1'000'000;
622 number_str = STR_CURRENCY_SHORT_MEGA;
623 }
else if (number >= 1'000'000) {
624 number = (number + 500) / 1'000;
625 number_str = STR_CURRENCY_SHORT_KILO;
629 std::string_view separator =
_settings_game.locale.digit_group_separator_currency;
631 if (separator.empty()) separator = _langpack.langpack->digit_group_separator_currency;
633 if (number_str != STR_NULL) {
641 builder.
PutUtf8(SCC_POP_COLOUR);
654 uint64_t n =
abs(count);
656 switch (plural_form) {
665 return n != 1 ? 1 : 0;
677 return n > 1 ? 1 : 0;
684 return n % 10 == 1 && n % 100 != 11 ? 0 : n != 0 ? 1 : 2;
690 return n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4;
696 return n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
702 return n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
708 return n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
714 return n % 100 == 1 ? 0 : n % 100 == 2 ? 1 : n % 100 == 3 || n % 100 == 4 ? 2 : 3;
720 return n % 10 == 1 && n % 100 != 11 ? 0 : 1;
726 return n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2;
757 return (n == 1 ? 0 : n == 0 || (n % 100 > 1 && n % 100 < 11) ? 1 : (n % 100 > 10 && n % 100 < 20) ? 2 : 3);
762 return ((n == 1 || n == 11) ? 0 : (n == 2 || n == 12) ? 1 : ((n > 2 && n < 11) || (n > 12 && n < 20)) ? 2 : 3);
768 return n == 1 ? 0 : (n == 0 || (n % 100 > 0 && n % 100 < 20)) ? 1 : 2;
776 for (uint i = 0; i != n; i++) {
786 size_t form_pre = 0, form_len = 0, form_post = 0;
787 for (uint i = 0; i != n; i++) {
791 }
else if (i > form) {
798 consumer.
Skip(form_pre);
799 builder += consumer.
Read(form_len);
800 consumer.
Skip(form_post);
813 int64_t
ToDisplay(int64_t input,
bool round =
true)
const
816 ? (int64_t)std::round(input * this->factor)
817 : (int64_t)(input * this->factor);
827 int64_t
FromDisplay(int64_t input,
bool round =
true, int64_t divider = 1)
const
830 ? (int64_t)std::round(input / this->factor / divider)
831 : (int64_t)(input / this->factor / divider);
852 { { 1.0 }, STR_UNITS_VELOCITY_IMPERIAL, 0 },
853 { { 1.609344 }, STR_UNITS_VELOCITY_METRIC, 0 },
854 { { 0.44704 }, STR_UNITS_VELOCITY_SI, 0 },
855 { { 0.578125 }, STR_UNITS_VELOCITY_GAMEUNITS_DAY, 1 },
856 { { 0.868976 }, STR_UNITS_VELOCITY_KNOTS, 0 },
861 { { 1.0 }, STR_UNITS_VELOCITY_IMPERIAL, 0 },
862 { { 1.609344 }, STR_UNITS_VELOCITY_METRIC, 0 },
863 { { 0.44704 }, STR_UNITS_VELOCITY_SI, 0 },
864 { { 0.289352 }, STR_UNITS_VELOCITY_GAMEUNITS_SEC, 1 },
865 { { 0.868976 }, STR_UNITS_VELOCITY_KNOTS, 0 },
870 { { 1.0 }, STR_UNITS_POWER_IMPERIAL, 0 },
871 { { 1.01387 }, STR_UNITS_POWER_METRIC, 0 },
872 { { 0.745699 }, STR_UNITS_POWER_SI, 0 },
877 { { 0.907185 }, STR_UNITS_POWER_IMPERIAL_TO_WEIGHT_IMPERIAL, 1 },
878 { { 1.0 }, STR_UNITS_POWER_IMPERIAL_TO_WEIGHT_METRIC, 1 },
879 { { 1.0 }, STR_UNITS_POWER_IMPERIAL_TO_WEIGHT_SI, 1 },
880 { { 0.919768 }, STR_UNITS_POWER_METRIC_TO_WEIGHT_IMPERIAL, 1 },
881 { { 1.01387 }, STR_UNITS_POWER_METRIC_TO_WEIGHT_METRIC, 1 },
882 { { 1.01387 }, STR_UNITS_POWER_METRIC_TO_WEIGHT_SI, 1 },
883 { { 0.676487 }, STR_UNITS_POWER_SI_TO_WEIGHT_IMPERIAL, 1 },
884 { { 0.745699 }, STR_UNITS_POWER_SI_TO_WEIGHT_METRIC, 1 },
885 { { 0.745699 }, STR_UNITS_POWER_SI_TO_WEIGHT_SI, 1 },
890 { { 1.102311 }, STR_UNITS_WEIGHT_SHORT_IMPERIAL, STR_UNITS_WEIGHT_LONG_IMPERIAL, 0 },
891 { { 1.0 }, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC, 0 },
892 { { 1000.0 }, STR_UNITS_WEIGHT_SHORT_SI, STR_UNITS_WEIGHT_LONG_SI, 0 },
897 { { 264.172 }, STR_UNITS_VOLUME_SHORT_IMPERIAL, STR_UNITS_VOLUME_LONG_IMPERIAL, 0 },
898 { { 1000.0 }, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC, 0 },
899 { { 1.0 }, STR_UNITS_VOLUME_SHORT_SI, STR_UNITS_VOLUME_LONG_SI, 0 },
904 { { 0.224809 }, STR_UNITS_FORCE_IMPERIAL, 0 },
905 { { 0.101972 }, STR_UNITS_FORCE_METRIC, 0 },
906 { { 0.001 }, STR_UNITS_FORCE_SI, 0 },
911 { { 3.0 }, STR_UNITS_HEIGHT_IMPERIAL, 0 },
912 { { 1.0 }, STR_UNITS_HEIGHT_METRIC, 0 },
913 { { 1.0 }, STR_UNITS_HEIGHT_SI, 0 },
914 { { .02 }, STR_UNITS_HEIGHT_GAMEUNITS,0 },
919 { { 1 }, STR_UNITS_DAYS, 0 },
920 { { 2 }, STR_UNITS_SECONDS, 0 },
925 { { 1 }, STR_UNITS_MONTHS, 0 },
926 { { 1 }, STR_UNITS_MINUTES, 0 },
931 { { 1 }, STR_UNITS_YEARS, 0 },
932 { { 1 }, STR_UNITS_PERIODS, 0 },
937 { { 1 }, STR_UNITS_YEARS, 0 },
938 { { 12 }, STR_UNITS_MINUTES, 0 },
1013 std::vector<StringParameter> sub_args;
1018 builder +=
"(invalid SCC_ENCODED)";
1023 builder +=
"(invalid StringID)";
1033 sub_args.emplace_back(std::monostate{});
1038 char32_t parameter_type = record.
ReadUtf8();
1039 switch (parameter_type) {
1043 builder +=
"(invalid sub-StringID)";
1048 sub_args.emplace_back(param);
1055 sub_args.emplace_back(param);
1066 sub_args.emplace_back(std::monostate{});
1083 for (
char32_t ch :
Utf8View(buffer)) {
1084 if (ch == SCC_PUSH_COLOUR) {
1086 }
else if (ch == SCC_POP_COLOUR) {
1088 if (safety < 0)
return false;
1089 }
else if ((ch >= SCC_BLUE && ch <= SCC_BLACK) || ch == SCC_COLOUR) {
1090 if (safety == 0)
return false;
1107 size_t orig_first_param_offset = args.
GetOffset();
1108 bool emit_automatic_push_pop =
false;
1121 FormatString(dry_run_builder, str_arg, args, orig_case_index, game_script,
true);
1124 args.
SetOffset(orig_first_param_offset);
1126 uint next_substr_case_index = 0;
1127 struct StrStackItem {
1129 size_t first_param_offset;
1132 StrStackItem(std::string_view view,
size_t first_param_offset, uint case_index)
1133 : consumer(view), first_param_offset(first_param_offset), case_index(case_index)
1136 std::stack<StrStackItem, std::vector<StrStackItem>> str_stack;
1137 str_stack.emplace(str_arg, orig_first_param_offset, orig_case_index);
1139 if (emit_automatic_push_pop) builder.
PutUtf8(SCC_PUSH_COLOUR);
1143 while (!str_stack.empty() && !str_stack.top().consumer.AnyBytesLeft()) {
1146 if (str_stack.empty())
break;
1148 const size_t ref_param_offset = str_stack.top().first_param_offset;
1149 const uint case_index = str_stack.top().case_index;
1154 builder +=
"(unexpected NUL)";
1161 if (b == 0)
continue;
1164 if (b < SCC_CONTROL_START || b > SCC_CONTROL_END) {
1169 args.SetTypeOfNextParameter(b);
1178 std::string_view ptr = GetStringPtr(substr);
1179 str_stack.emplace(ptr, args.
GetOffset(), next_substr_case_index);
1180 next_substr_case_index = 0;
1186 std::string_view ptr = GetStringPtr(substr);
1187 str_stack.emplace(ptr, args.
GetOffset(), next_substr_case_index);
1188 next_substr_case_index = 0;
1192 case SCC_GENDER_LIST: {
1194 size_t offset = ref_param_offset + consumer.
ReadUint8();
1198 builder +=
"(invalid GENDER parameter)";
1220 if (gender_consumer.
ReadUtf8If(SCC_GENDER_INDEX)) {
1224 ParseStringChoice(consumer, gender, builder);
1230 case SCC_GENDER_INDEX: {
1233 builder.
PutUtf8(SCC_GENDER_INDEX);
1239 case SCC_PLURAL_LIST: {
1240 uint8_t plural_form = consumer.
ReadUint8();
1241 size_t offset = ref_param_offset + consumer.
ReadUint8();
1242 const uint64_t *v =
nullptr;
1245 v = std::get_if<uint64_t>(&args.GetParam(offset));
1248 ParseStringChoice(consumer,
DeterminePluralForm(
static_cast<int64_t
>(*v), plural_form), builder);
1250 SkipStringChoice(consumer);
1251 builder +=
"(invalid PLURAL parameter)";
1256 case SCC_ARG_INDEX: {
1261 case SCC_SET_CASE: {
1264 next_substr_case_index = consumer.
ReadUint8();
1268 case SCC_SWITCH_CASE: {
1272 std::optional<std::string_view> found;
1273 for (; num > 0; --num) {
1276 auto case_str = consumer.
Read(len);
1277 if (index == case_index) {
1283 auto default_str = consumer.
Read(default_len);
1284 if (!found.has_value()) found = default_str;
1285 str_stack.emplace(*found, ref_param_offset, case_index);
1290 builder += _openttd_revision;
1293 case SCC_RAW_STRING_POINTER:
1302 GetStringWithArgs(builder, string_id, tmp_params, next_substr_case_index, game_script);
1303 next_substr_case_index = 0;
1317 uint size = b - SCC_STRING1 + 1;
1319 builder +=
"(consumed too many parameters)";
1322 GetStringWithArgs(builder, string_id, sub_args, next_substr_case_index, game_script);
1325 next_substr_case_index = 0;
1337 FormatCommaNumber(builder, number);
1342 int64_t fractional = number % divisor;
1344 FormatCommaNumber(builder, number);
1345 fmt::format_to(builder.
back_inserter(),
"{}{:0{}d}", GetDecimalSeparator(), fractional, digits);
1353 case SCC_ZEROFILL_NUM: {
1367 case SCC_CARGO_TINY: {
1375 builder +=
"(invalid cargo type)";
1380 case STR_TONS.base():
1384 case STR_LITERS.base():
1392 FormatCommaNumber(builder, amount);
1396 case SCC_CARGO_SHORT: {
1404 builder +=
"(invalid cargo type)";
1409 switch (cargo_str.base()) {
1410 case STR_TONS.base(): {
1413 auto tmp_params =
MakeParameters(x.c.ToDisplay(amount), x.decimal_places);
1418 case STR_LITERS.base(): {
1421 auto tmp_params =
MakeParameters(x.c.ToDisplay(amount), x.decimal_places);
1435 case SCC_CARGO_LONG: {
1445 builder +=
"(invalid cargo type)";
1450 case SCC_CARGO_LIST: {
1456 if (!cmask.
Test(cs->Index()))
continue;
1462 builder += list_separator;
1465 GetStringWithArgs(builder, cs->name, args, next_substr_case_index, game_script);
1469 if (first)
GetStringWithArgs(builder, STR_JUST_NOTHING, args, next_substr_case_index, game_script);
1471 next_substr_case_index = 0;
1475 case SCC_CURRENCY_SHORT:
1479 case SCC_CURRENCY_LONG:
1487 case SCC_DATE_SHORT:
1489 next_substr_case_index = 0;
1494 next_substr_case_index = 0;
1525 case SCC_POWER_TO_WEIGHT: {
1534 case SCC_VELOCITY: {
1544 case SCC_VOLUME_SHORT: {
1552 case SCC_VOLUME_LONG: {
1560 case SCC_WEIGHT_SHORT: {
1568 case SCC_WEIGHT_LONG: {
1576 case SCC_UNITS_DAYS_OR_SECONDS: {
1584 case SCC_UNITS_MONTHS_OR_MINUTES: {
1592 case SCC_UNITS_YEARS_OR_PERIODS: {
1600 case SCC_UNITS_YEARS_OR_MINUTES: {
1608 case SCC_COMPANY_NAME: {
1610 if (c ==
nullptr)
break;
1612 if (!c->
name.empty()) {
1622 case SCC_COMPANY_NUM: {
1633 case SCC_DEPOT_NAME: {
1642 if (!d->name.empty()) {
1652 case SCC_ENGINE_NAME: {
1655 if (e ==
nullptr)
break;
1657 if (!e->name.empty() && e->IsEnabled()) {
1664 std::array<int32_t, 16> regs100;
1667 if (callback == 0x40F) {
1668 const GRFFile *grffile = e->GetGRF();
1669 assert(grffile !=
nullptr);
1673 }
else if (callback < 0x400) {
1674 const GRFFile *grffile = e->GetGRF();
1675 assert(grffile !=
nullptr);
1686 case SCC_GROUP_NAME: {
1688 if (g ==
nullptr)
break;
1690 if (!g->
name.empty()) {
1700 case SCC_INDUSTRY_NAME: {
1702 if (i ==
nullptr)
break;
1704 static bool use_cache =
true;
1709 }
else if (use_cache) {
1711 builder += i->GetCachedName();
1715 FormatString(builder, GetStringPtr(STR_FORMAT_INDUSTRY_NAME), tmp_params, next_substr_case_index);
1717 next_substr_case_index = 0;
1721 case SCC_PRESIDENT_NAME: {
1723 if (c ==
nullptr)
break;
1735 case SCC_STATION_NAME: {
1739 if (st ==
nullptr) {
1747 static bool use_cache =
true;
1750 builder += st->GetCachedName();
1751 }
else if (!st->name.empty()) {
1755 StringID string_id = st->string_id;
1756 if (st->indtype != IT_INVALID) {
1768 auto tmp_params =
MakeParameters(STR_TOWN_NAME, st->town->index, st->index);
1774 case SCC_TOWN_NAME: {
1776 if (t ==
nullptr)
break;
1778 static bool use_cache =
true;
1781 builder += t->GetCachedName();
1782 }
else if (!t->
name.empty()) {
1786 GetTownName(builder, t);
1791 case SCC_WAYPOINT_NAME: {
1793 if (wp ==
nullptr)
break;
1795 if (!wp->
name.empty()) {
1800 StringID string_id = ((wp->
string_id == STR_SV_STNAME_BUOY) ? STR_FORMAT_BUOY_NAME : STR_FORMAT_WAYPOINT_NAME);
1801 if (wp->
town_cn != 0) string_id++;
1807 case SCC_VEHICLE_NAME: {
1809 if (v ==
nullptr)
break;
1811 if (!v->
name.empty()) {
1823 default: string_id = STR_INVALID_VEHICLE;
break;
1835 case SCC_SIGN_NAME: {
1837 if (si ==
nullptr)
break;
1839 if (!si->name.empty()) {
1848 case SCC_STATION_FEATURES: {
1863 }
catch (std::out_of_range &e) {
1865 builder +=
"(invalid parameter)";
1869 if (emit_automatic_push_pop) builder.
PutUtf8(SCC_POP_COLOUR);
1882static const std::string_view _silly_company_names[] = {
1884 "Tiny Transport Ltd.",
1886 "Comfy-Coach & Co.",
1887 "Crush & Bump Ltd.",
1888 "Broken & Late Ltd.",
1890 "Supersonic Travel",
1892 "Lightning International",
1893 "Pannik & Loozit Ltd.",
1894 "Inter-City Transport",
1895 "Getout & Pushit Ltd."
1898static const std::string_view _surname_list[] = {
1930static const std::string_view _silly_surname_list[] = {
1945static const char _initial_name_letters[] = {
1946 'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
1947 'K',
'L',
'M',
'N',
'P',
'R',
'S',
'T',
'W',
1950static std::span<const std::string_view> GetSurnameOptions()
1953 return _surname_list;
1963 auto surname_options = GetSurnameOptions();
1964 return surname_options[surname_options.size() *
GB(seed, 16, 8) >> 8];
1967static void GenAndCoName(
StringBuilder &builder, uint32_t seed)
1970 builder +=
" & Co.";
1973static void GenPresidentName(
StringBuilder &builder, uint32_t seed)
1975 builder.
PutChar(_initial_name_letters[std::size(_initial_name_letters) *
GB(seed, 0, 8) >> 8]);
1979 size_t index = (std::size(_initial_name_letters) + 35) *
GB(seed, 8, 8) >> 8;
1980 if (index < std::size(_initial_name_letters)) {
1981 builder.
PutChar(_initial_name_letters[index]);
1990 switch (
string.base()) {
1992 builder += _silly_company_names[std::min<size_t>(args.
GetNextParameter<uint16_t>(), std::size(_silly_company_names) - 1)];
2007 builder +=
" Transport";
2021 this->
version == TO_LE32(LANGUAGE_PACK_VERSION) &&
2042 return 4 * this->
missing < LANGUAGE_TOTAL_STRINGS;
2053 size_t total_len = 0;
2055 if (!lang_pack)
return false;
2058 const char *end = (
char *)lang_pack.get() + total_len + 1;
2061 if (end <= lang_pack->data || !lang_pack->IsValid()) {
2065 std::array<uint, TEXT_TAB_END> tab_start, tab_num;
2069 uint16_t num = FROM_LE16(lang_pack->offsets[i]);
2072 tab_start[i] = count;
2078 std::vector<std::string_view> strings;
2081 char *s = lang_pack->data;
2082 for (uint i = 0; i < count; i++) {
2083 size_t len =
static_cast<uint8_t
>(*s++);
2084 if (s + len >= end)
return false;
2087 len = ((len & 0x3F) << 8) +
static_cast<uint8_t
>(*s++);
2088 if (s + len >= end)
return false;
2090 strings.emplace_back(s, len);
2093 assert(strings.size() == count);
2095 _langpack.langpack = std::move(lang_pack);
2096 _langpack.strings = std::move(strings);
2097 _langpack.langtab_num = tab_num;
2098 _langpack.langtab_start = tab_start;
2103 _langpack.list_separator =
GetString(STR_LIST_SEPARATOR);
2104 _langpack.ellipsis =
GetString(STR_TRUNCATION_ELLIPSIS);
2107 extern void Win32SetCurrentLocaleName(std::string iso_code);
2118 UErrorCode status = U_ZERO_ERROR;
2123 if (U_FAILURE(status)) {
2149#if !(defined(_WIN32) || defined(__APPLE__))
2160 auto env =
GetEnv(
"LANGUAGE");
2161 if (env.has_value())
return std::string{*env};
2164 if (env.has_value())
return std::string{*env};
2166 if (param !=
nullptr) {
2168 if (env.has_value())
return std::string{*env};
2172 if (env.has_value())
return std::string{*env};
2174 return std::nullopt;
2188 if (newgrflangid == lang.newgrflangid)
return ⟨
2203 if (!f.has_value())
return false;
2205 size_t read = fread(hdr,
sizeof(*hdr), 1, *f);
2207 bool ret = read == 1 && hdr->
IsValid();
2223 std::error_code error_code;
2224 for (
const auto &dir_entry : std::filesystem::directory_iterator(
OTTD2FS(path), error_code)) {
2225 if (!dir_entry.is_regular_file())
continue;
2226 if (dir_entry.path().extension() !=
".lng")
continue;
2229 lmd.
file = dir_entry.path();
2255 if (
_languages.empty()) UserError(
"No available language packs (invalid versions?)");
2259 std::string_view lang = str_lang.has_value() ? std::string_view{*str_lang} :
"en_GB";
2271 chosen_language = &lng;
2275 std::string_view iso_code = lng.isocode;
2276 if (iso_code ==
"en_GB") en_GB_fallback = &lng;
2279 if (!lng.IsReasonablyFinished())
continue;
2281 if (iso_code.starts_with(lang.substr(0, 5))) chosen_language = &lng;
2282 if (iso_code.starts_with(lang.substr(0, 2))) language_fallback = &lng;
2287 if (chosen_language ==
nullptr) {
2288 chosen_language = (language_fallback !=
nullptr) ? language_fallback : en_GB_fallback;
2300 return _langpack.langpack->isocode;
2313 for (
char32_t c :
Utf8View(*text)) {
2314 if (c >= SCC_FIRST_FONT && c <= SCC_LAST_FONT) {
2315 fs = (
FontSize)(c - SCC_FIRST_FONT);
2320 if (!fontsizes.
Test(fs))
continue;
2323 if (
IsInsideMM(c, SCC_SPRITE_START, SCC_SPRITE_END))
continue;
2356 std::string_view ret = _langpack.strings[_langpack.langtab_start[this->i] + this->j];
2384 if (searcher ==
nullptr) searcher = &pack_searcher;
2400#if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
2404 bool any_font_configured = !_fcsettings.medium.font.empty();
2408 std::string isocode = _langpack.langpack->isocode;
2409 std::ranges::replace(isocode,
'_',
'-');
2416 _fcsettings = std::move(backup);
2418 if (!bad_font && any_font_configured) {
2422 std::string err_str;
2425 builder.
Put(
"The current font is missing some of the characters used in the texts for this language. Using system fallback font instead.");
2439 std::string err_str;
2442 builder.
Put(
"The current font is missing some of the characters used in the texts for this language. Go to Help & Manuals > Fonts, or read the file docs/fonts.md in your OpenTTD directory, to see how to solve this.");
2447#if !(defined(WITH_ICU_I18N) && defined(WITH_HARFBUZZ)) && !defined(WITH_UNISCRIBE) && !defined(WITH_COCOA)
2458 std::string err_str;
2461 builder.
Put(
"This version of OpenTTD does not support right-to-left languages. Recompile with ICU + Harfbuzz enabled.");
Class for backupping variables and making sure they are restored later.
static constexpr uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
bool IsValidCargoType(CargoType cargo)
Test whether cargo type is not INVALID_CARGO.
EnumBitSet< CargoType, uint64_t > CargoTypes
Bitset of CargoType elements.
CargoType
Cargo slots to indicate a cargo type within a game.
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
void InitializeSortedCargoSpecs()
Initialize the list of sorted cargo specifications.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr bool Any(const Timpl &other) const
Test if any of the given values are set.
void PutUtf8(char32_t c)
Append UTF-8 char.
void Put(std::string_view str)
Append string.
void PutIntegerBase(T value, int base)
Append integer 'value' in given number 'base'.
void PutChar(char c)
Append 8-bit char.
void PutUint8(uint8_t value)
Append binary uint8.
Base for missing glyph searchers that look for missing glyphs in strings.
virtual FontSize DefaultSize()=0
Get the default (font) size of the string.
virtual void Reset()=0
Reset the search, i.e.
virtual std::optional< std::string_view > NextString()=0
Get the next string to search through.
void DetermineRequiredGlyphs(FontSizes fontsizes) override
Determine set of glyphs required for the current language.
Container for an encoded string, created by GetEncodedString.
friend EncodedString GetEncodedStringWithArgs(StringID str, std::span< const StringParameter > params)
Encode a string with its parameters into an encoded string.
std::string GetDecodedString() const
Decode the encoded string.
EncodedString ReplaceParam(size_t param, StringParameter &&value) const
Replace a parameter of this EncodedString.
Iterate a range of enum values.
static std::optional< FileHandle > Open(const std::string &filename, std::string_view mode)
Open an RAII file handle if possible.
Font cache for basic fonts.
virtual GlyphID MapCharToGlyph(char32_t key, bool fallback=true)=0
Map a character into a glyph.
static void LoadFontCaches(FontSizes fontsizes)
(Re)initialize the font cache related things, i.e.
static FontCache * Get(FontSize fs)
Get the font cache of a given font size.
static bool FindFallbackFont(const std::string &language_isocode, MissingGlyphSearcher *callback)
We would like to have a fallback font as the current one doesn't contain all characters we need.
Helper for searching through the language pack.
uint j
Iterator for the secondary language tables.
std::optional< std::string_view > NextString() override
Get the next string to search through.
FontSize DefaultSize() override
Get the default (font) size of the string.
uint i
Iterator for the primary language tables.
void Reset() override
Reset the search, i.e.
static void Initialize()
Perform initialization of layout engine.
A searcher for missing glyphs.
virtual void DetermineRequiredGlyphs(FontSizes fontsizes)=0
Determine set of glyphs required for the current language.
std::set< char32_t > missing_glyphs
Glyphs that are missing in the current font.
FontSizes missing_fontsizes
Font sizes to actually search for.
std::set< char32_t > required_glyphs
Glyphs that are required.
Compose data into a growing std::string.
back_insert_iterator back_inserter()
Create a back-insert-iterator.
Parse data from a string / buffer.
std::optional< T > TryReadIntegerBase(int base, bool clamp=false)
Try to read and parse an integer in number 'base', and then advance the reader.
bool PeekUtf8If(char32_t c) const
Check whether the next UTF-8 char matches 'c'.
char32_t ReadUtf8(char32_t def='?')
Read UTF-8 character, and advance reader.
@ SKIP_ONE_SEPARATOR
Read and discard one separator, do not include it in the result.
@ KEEP_SEPARATOR
Keep the separator in the data as next value to be read.
bool AnyBytesLeft() const noexcept
Check whether any bytes left to read.
uint8_t ReadUint8(uint8_t def=0)
Read binary uint8, and advance reader.
uint16_t ReadUint16LE(uint16_t def=0)
Read binary uint16 using little endian, and advance reader.
void SkipAll()
Discard all remaining data.
T ReadIntegerBase(int base, T def=0, bool clamp=false)
Read and parse an integer in number 'base', and advance the reader.
std::string_view Read(size_type len)
Read the next 'len' bytes, and advance reader.
bool ReadUtf8If(char32_t c)
Check whether the next UTF-8 char matches 'c', and skip it.
static constexpr size_type npos
Special value for "end of data".
void Skip(size_type len)
Discard some bytes.
void SkipUtf8If(char32_t c)
If the next data matches the UTF-8 char 'c', then skip it.
std::string_view ReadUntilUtf8(char32_t c, SeparatorUsage sep)
Read data until the first occurrence of UTF-8 char 'c', and advance reader.
void SetOffset(size_t offset)
Set the offset within the string from where to return the next result of GetInt64 or GetInt32.
std::string_view GetNextParameterString()
Get the next string parameter from our parameters.
StringParameters GetRemainingParameters()
Get a new instance of StringParameters that is a "range" into the remaining existing parameters.
std::span< StringParameter > parameters
Array with the actual parameters.
const StringParameter & GetNextParameterReference()
Get the next parameter from our parameters.
void AdvanceOffset(size_t advance)
Advance the offset within the string from where to return the next result of GetInt64 or GetInt32.
uint64_t GetNextParameter()
Get the next parameter from our parameters.
size_t offset
Current offset in the parameters span.
char32_t next_type
The type of the next data that is retrieved.
size_t GetOffset()
Get the current offset, so it can be backed up for certain processing steps, or be used to offset the...
size_t GetNumParameters() const
Return the number of parameters.
size_t GetDataLeft() const
Return the amount of elements which can still be read.
char32_t GetTypeAtOffset(size_t offset) const
Get the type of a specific element.
static YearMonthDay ConvertDateToYMD(Date date)
Converts a Date to a Year, Month & Day.
static bool UsingWallclockUnits(bool newgame=false)
Check if we are using wallclock units.
StrongType::Typedef< int32_t, DateTag< struct Calendar >, StrongType::Compare, StrongType::Integer > Date
Constant span of UTF-8 encoded data.
Definition of stuff that is very close to a company, like the company struct itself.
Control codes that are embedded in the translation strings.
StringControlCode
List of string control codes used for string formatting, displaying, and by strgen to generate the la...
@ SCC_ENCODED
Encoded string marker and sub-string parameter.
@ SCC_ENCODED_NUMERIC
Encoded numeric parameter.
@ SCC_ENCODED_STRING
Encoded string parameter.
@ SCC_NEWGRF_STRINL
Inline another string at the current position, StringID is encoded in the string.
@ SCC_NEWGRF_FIRST
The next variables are part of a NewGRF subsystem for creating text strings.
@ SCC_NEWGRF_PRINT_WORD_STRING_ID
81: Read 2 bytes from the stack as String ID
@ SCC_ENCODED_INTERNAL
Encoded text from OpenTTD.
Functions to handle different currencies.
const CurrencySpec & GetCurrency()
Get the currently selected currency.
@ Suffix
Show the suffix value.
@ Prefix
Show the prefix value.
Functions related to debugging.
bool IsVisibleSeverity(Facility facility, Severity severity)
Test if debug severity is visible for the given facility.
#define Debug(facility, severity, format_string,...)
Output a line of debugging information.
@ Misc
Misc message facility.
@ Fontcache
Fontcache message facility.
@ Critical
Critical, user should know about this.
@ Error
Error, but we are recovering.
@ Trace3
Trace information #3.
Base for all depots (except hangars).
PoolID< uint16_t, struct DepotIDTag, 64000, 0xFFFF > DepotID
Type for the unique identifier of depots.
Function to handling different endian machines.
PoolID< uint16_t, struct EngineIDTag, 64000, 0xFFFF > EngineID
Unique identification number of an engine.
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Functions related to errors.
@ Warning
Other information.
@ Error
Errors (eg. saving/loading failed).
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
Error reporting related functions.
std::unique_ptr< char[]> ReadFileToMem(const std::string &filename, size_t &lenp, size_t maxsize)
Load a file into memory.
Functions for standard in/out file operations.
Searchpath
Types of searchpaths OpenTTD might use.
@ Lang
Subdirectory for all translation files.
void ReconsiderGameScriptLanguage()
Reconsider the game script language, so we use the right one.
std::string_view GetGameStringPtr(StringIndexInTab id)
Get the string pointer of a particular game string.
Base functions regarding game texts.
std::pair< uint8_t, uint8_t > GetBroadestDigit(FontSize size)
Determine the broadest digits for guessing the maximum width of a n-digit number.
void LoadStringWidthTable(FontSizes fontsizes)
Initialize _stringwidth_table cache for the specified font sizes.
Functions related to laying out the texts.
FontSize
Available font sizes.
@ Normal
Index of the normal font in the font tables.
Colours
One of 16 base colours used for companies and windows/widgets.
EnumBitSet< FontSize, uint8_t > FontSizes
Bitset of FontSize elements.
static constexpr GroupID DEFAULT_GROUP
Ungrouped vehicles are in this group.
const IndustrySpec * GetIndustrySpec(IndustryType thistype)
Accessor for array _industry_specs.
void SortIndustryTypes()
Initialize the list of sorted industry types.
@ Toyland
Landscape with funky industries and vehicles.
Information about languages and their files.
LanguageList _languages
The actual list of language meta data.
const LanguageMetadata * _current_language
The currently loaded language.
static const uint8_t MAX_NUM_GENDERS
Maximum number of supported genders.
std::unique_ptr< icu::Collator > _current_collator
Collator for the language currently in use.
std::vector< LanguageMetadata > LanguageList
Type for the list of language meta data.
static const uint8_t MAX_NUM_CASES
Maximum number of supported cases.
constexpr bool IsInsideMM(const size_t x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
constexpr T abs(const T a)
Returns the absolute value of (scalar) variable.
constexpr uint64_t PowerOfTen(int power)
Computes ten to the given power.
void BuildContentTypeStringList()
Build array of all strings corresponding to the content types.
User interface for downloading files.
@ CBID_VEHICLE_NAME
Called to determine the engine name to show.
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v, std::span< int32_t > regs100)
Evaluate a newgrf callback for vehicles.
Functions for NewGRF engines.
std::string_view GetGRFStringPtr(StringIndexInTab stringid)
Get a C-string from a stringid set by a newgrf.
std::string GetGRFStringWithTextStack(const struct GRFFile *grffile, GRFStringID grfstringid, std::span< const int32_t > textstack)
Format a GRF string using the text ref stack for parameters.
char32_t RemapNewGRFStringControlCode(char32_t scc, StringConsumer &consumer)
Emit OpenTTD's internal string code for the different NewGRF string codes.
Header of Action 04 "universal holder" structure and functions.
GRFLanguage
Incomplete enumeration of the (New)GRF languages.
@ End
End marker of the valid languages.
StrongType::Typedef< uint32_t, struct GRFStringIDTag, StrongType::Compare, StrongType::Integer > GRFStringID
Type for GRF-internal string IDs.
static constexpr GRFStringID GRFSTR_MISC_GRF_TEXT
Miscellaneous GRF text range.
Declaration of OTTD revision dependent variables.
A number of safeguards to prevent using unsafe methods.
GameSettings _settings_game
Game settings of a running game or the scenario editor.
PoolID< uint16_t, struct SignIDTag, 64000, 0xFFFF > SignID
The type of the IDs of signs.
void BuildIndustriesLegend()
Fills an array for the industries legends.
Base classes/functions for stations.
@ Dock
Station with a dock.
@ TruckStop
Station with truck stops.
@ Train
Station with train station.
@ Airport
Station with an airport.
@ BusStop
Station with bus stops.
EnumBitSet< StationFacility, uint8_t > StationFacilities
Bitset of StationFacility elements.
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
std::optional< std::string_view > GetEnv(const char *variable)
Get the environment variable using std::getenv and when it is an empty string (or nullptr),...
bool StrValid(std::span< const char > str)
Checks whether the given string is valid, i.e.
Functions related to low-level strings.
bool IsWhitespace(char32_t c)
Check whether UNICODE character is whitespace or not, i.e.
bool IsNonbreakingWhitespace(char32_t c)
Check wheather a character is non-breaking whitespace.
bool IsTextDirectionChar(char32_t c)
Is the given character a text direction character.
void MacOSSetCurrentLocaleName(std::string_view iso_code)
Store current language locale as a CoreFoundation locale.
#define NBSP
A non-breaking space.
uint64_t GetParamMaxValue(uint64_t max_value, uint min_count, FontSize size)
Get some number that is suitable for string size computations.
void CheckForMissingGlyphs(FontSizes fontsizes, MissingGlyphSearcher *searcher)
Check whether the currently loaded language pack uses characters that the currently loaded font does ...
static void FormatNumber(StringBuilder &builder, int64_t number, std::string_view separator)
Format a number into a string.
EncodedString GetEncodedStringWithArgs(StringID str, std::span< const StringParameter > params)
Encode a string with its parameters into an encoded string.
void GetStringWithArgs(StringBuilder &builder, StringID string, StringParameters &args, uint case_index, bool game_script)
Get a parsed string with most special stringcodes replaced by the string parameters.
std::optional< std::string > GetCurrentLocale(const char *param)
Determine the current charset based on the environment First check some default values,...
std::string_view GetListSeparator()
Get the list separator string for the current language.
static const Units _units_height[]
Unit conversions for height.
static void FormatBytes(StringBuilder &builder, int64_t number)
Format a given number as a number of bytes with the SI prefix.
void AppendStringInPlace(std::string &result, StringID string)
Resolve the given StringID and append in place into an existing std::string with formatting but no pa...
uint ConvertSpeedToDisplaySpeed(uint speed, VehicleType type)
Convert the given (internal) speed to the display speed.
std::string _config_language_file
The file (name) stored in the configuration.
static const Units GetVelocityUnits(VehicleType type)
Get the correct velocity units depending on the vehicle type and whether we're using real-time units.
static int DeterminePluralForm(int64_t count, uint plural_form)
Determine the "plural" index given a plural form and a number.
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
uint ConvertDisplaySpeedToKmhishSpeed(uint speed, VehicleType type)
Convert the given display speed to the km/h-ish speed.
static const Units _units_power[]
Unit conversions for power.
static std::string_view GetSurname(uint32_t seed)
Get the surname of the president with the given seed.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
std::string_view GetCurrentLanguageIsoCode()
Get the ISO language code of the currently loaded language.
static bool _scan_for_gender_data
Are we scanning for the gender of the current string? (instead of formatting it).
static const UnitsLong _units_volume[]
Unit conversions for volume.
static void DecodeEncodedString(StringConsumer &consumer, bool game_script, StringBuilder &builder)
Decodes an encoded string during FormatString.
static const UnitsLong _units_weight[]
Unit conversions for weight.
static const Units _units_velocity_calendar[]
Unit conversions for velocity.
static void FillLanguageList(const std::string &path)
Search for the languages in the given directory and add them to the _languages list.
uint ConvertKmhishSpeedToDisplaySpeed(uint speed, VehicleType type)
Convert the given km/h-ish speed to the display speed.
static const Units _units_force[]
Unit conversions for force.
void InitializeLanguagePacks()
Make a list of the available language packs.
static bool IsColourSafe(std::string_view buffer)
Test if a string contains colour codes, and is not wrapped by push/pop codes.
static const Units _units_time_days_or_seconds[]
Unit conversions for time in calendar days or wallclock seconds.
uint ConvertDisplaySpeedToSpeed(uint speed, VehicleType type)
Convert the given display speed to the (internal) speed.
TextDirection _current_text_dir
Text direction of the currently selected language.
static const Units _units_velocity_realtime[]
Unit conversions for velocity.
bool ReadLanguagePack(const LanguageMetadata *lang)
Read a particular language.
static bool GetLanguageFileHeader(const std::string &file, LanguagePackHeader *hdr)
Reads the language file header and checks compatibility.
static const Units _units_time_months_or_minutes[]
Unit conversions for time in calendar months or wallclock minutes.
static void FormatString(StringBuilder &builder, std::string_view str, StringParameters &args, uint case_index=0, bool game_script=false, bool dry_run=false)
Parse most format codes within a string and write the result to a buffer.
static const Units _units_time_years_or_minutes[]
Unit conversions for time in calendar years or wallclock minutes.
static const Units _units_power_to_weight[]
Unit conversions for power to weight.
uint64_t GetParamMaxDigits(uint count, FontSize size)
Get some number that is suitable for string size computations.
const LanguageMetadata * GetLanguage(GRFLanguage newgrflangid)
Get the language with the given NewGRF language ID.
std::string_view GetEllipsis()
Get the ellipsis string for the current language.
static const Units _units_time_years_or_periods[]
Unit conversions for time in calendar years or economic periods.
Functions related to OTTD's strings.
StringTab GetStringTab(StringID str)
Extract the StringTab from a StringID.
auto MakeParameters(Args &&... args)
Helper to create the StringParameters with its own buffer with the given parameter values.
StringID MakeStringID(StringTab tab, StringIndexInTab index)
Create a StringID.
StringIndexInTab GetStringIndex(StringID str)
Extract the StringIndex from a StringID.
Types and functions related to the internal workings of formatting OpenTTD's strings.
void GenerateTownNameString(StringBuilder &builder, size_t lang, uint32_t seed)
Generates town name from given seed.
StrongType::Typedef< uint32_t, struct StringIndexInTabTag, StrongType::Compare, StrongType::Integer > StringIndexInTab
The index/offset of a string within a StringTab.
static constexpr StringID SPECSTR_COMPANY_NAME_START
Special strings for company names on the form "TownName transport".
static constexpr StringID SPECSTR_SILLY_NAME
Special string for silly company names.
static const uint TAB_SIZE_GAMESCRIPT
Number of strings for GameScripts.
static constexpr uint16_t SPECSTR_TOWNNAME_START
Special strings for town names.
static constexpr StringID SPECSTR_ANDCO_NAME
Special string for Surname & Co company names.
static constexpr StringID SPECSTR_PRESIDENT_NAME
Special string for the president's name.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
static const uint TAB_SIZE
Number of strings per StringTab.
StringTab
StringTabs to group StringIDs.
@ TEXT_TAB_NEWGRF_START
Start of NewGRF supplied strings.
@ TEXT_TAB_GAMESCRIPT_START
Start of GameScript supplied strings.
@ TEXT_TAB_END
End of language files.
TextDirection
Directions a text can go to.
@ TD_LTR
Text is written left-to-right by default.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
std::string name
Name of vehicle.
StringID string_id
Default name (town area) of station.
Town * town
The town this station is associated with.
std::string name
Custom name.
VehicleType type
Type of vehicle.
StringID units_volume
Name of a single unit of cargo of this type.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo type.
static size_t GetArraySize()
Total number of cargospecs, both valid and invalid.
std::string president_name
Name of the president if the user changed it.
uint32_t name_2
Parameter of name_1.
uint32_t president_name_2
Parameter of president_name_1.
StringID name_1
Name of the company if the user did not change it.
StringID president_name_1
Name of the president if the user did not change it.
std::string name
Name of the company if the user changed it.
static bool IsValidHumanID(auto index)
Is this company a valid company, not controlled by a NoAI program?
Specification of a currency.
std::string separator
The thousands separator for this currency.
CurrencySymbolPositions symbol_pos
Which currency symbols should we show?
std::string prefix
Prefix to apply when formatting money in this currency.
std::string suffix
Suffix to apply when formatting money in this currency.
uint16_t rate
The conversion rate compared to the base currency.
uint16_t town_cn
The N-1th depot for this town (consecutive number).
Settings for the four different fonts.
Dynamic data of a loaded NewGRF.
std::string name
Group Name.
uint16_t number
Per-company group number.
Defines the data structure for constructing industry.
StringID name
Displayed name of the industry.
StringID station_name
Default name for nearby station.
Defines the internal data of a functional industry.
IndustryType type
type of industry.
char data[]
List of strings.
std::string list_separator
Current list separator string.
std::string ellipsis
Current ellipsis string.
std::array< uint, TEXT_TAB_END > langtab_num
Offset into langpack offs.
std::array< uint, TEXT_TAB_END > langtab_start
Offset into langpack offs.
static Depot * Get(auto index)
static Company * GetIfValid(auto index)
static Station * GetIfValid(auto index)
The data required to format and validate a single parameter of a string.
std::string name
Custom town name. If empty, the town was not renamed and uses the generated name.
Helper for unit conversion.
double factor
Amount to multiply or divide upon conversion.
int64_t ToDisplay(int64_t input, bool round=true) const
Convert value from OpenTTD's internal unit into the displayed value.
int64_t FromDisplay(int64_t input, bool round=true, int64_t divider=1) const
Convert the displayed value back into a value of OpenTTD's internal unit.
Information about a specific unit system with a long variant.
StringID s
String for the short variant of the unit.
StringID l
String for the long variant of the unit.
unsigned int decimal_places
Number of decimal places embedded in the value. For example, 1 if the value is in tenths,...
UnitConversion c
Conversion.
Information about a specific unit system.
StringID s
String for the unit.
unsigned int decimal_places
Number of decimal places embedded in the value. For example, 1 if the value is in tenths,...
UnitConversion c
Conversion.
GroupID group_id
Index of group Pool array.
UnitID unitnumber
unit number, for display purposes only
Representation of a waypoint.
uint16_t town_cn
The N-1th waypoint for this town (consecutive number).
Definition of the game-calendar-timer.
std::pair< size_t, char32_t > DecodeUtf8(std::string_view buf)
Decode a character from UTF-8.
Handling of UTF-8 encoded data.
Base class for all vehicles.
PoolID< uint32_t, struct VehicleIDTag, 0xFF000, 0xFFFFF > VehicleID
The type all our vehicle IDs have.
VehicleType
Available vehicle types.
@ Aircraft
Aircraft vehicle type.
@ Train
Train vehicle type.
std::wstring OTTD2FS(std::string_view name)
Convert from OpenTTD's encoding to a wide string.
std::string FS2OTTD(std::wstring_view name)
Convert to OpenTTD's encoding from a wide string.
void InvalidateWindowClassesData(WindowClass cls, int data, bool gui_scope)
Mark window data of all windows of a given class as invalid (in need of re-computing) Note that by de...
Window functions not directly related to making/drawing windows.