44 #include "table/strings.h"
46 #include "3rdparty/fmt/std.h"
48 #include "strings_internal.h"
70 for (
auto ¶m : this->
parameters) param.type = 0;
85 throw std::out_of_range(
"Trying to read invalid string parameter");
89 if (param.type != 0 && param.type != this->next_type) {
91 throw std::out_of_range(
"Trying to read string parameter with wrong type");
106 _global_string_params.SetParam(n, v);
116 return std::get<uint64_t>(_global_string_params.GetParam(n));
130 while (max_value >= 10) {
148 uint64_t val = count > 1 ? front : next;
149 for (; count > 1; count--) {
150 val = 10 * val + next;
161 for (
size_t i = 0; i < backup.size(); i++) {
162 _global_string_params.SetParam(i, backup[i]);
174 for (
size_t i = 0; i < backup.size(); i++) {
175 backup[i] = _global_string_params.GetParam(i);
186 for (
size_t i = 0; i < backup.size(); i++) {
187 if (backup[i] != _global_string_params.GetParam(i))
return true;
193 static void GetSpecialTownNameString(
StringBuilder &builder,
int ind, uint32_t seed);
206 delete[]
reinterpret_cast<char*
>(langpack);
211 std::unique_ptr<LanguagePack, LanguagePackDeleter> langpack;
213 std::vector<char *> offsets;
224 const char *GetStringPtr(
StringID string)
229 case TEXT_TAB_OLD_NEWGRF: NOT_REACHED();
255 if (index >= 0xC0 && !game_script) {
257 GetSpecialTownNameString(builder, index - 0xC0, args.
GetNextParameter<uint32_t>());
258 }
catch (
const std::runtime_error &e) {
259 Debug(misc, 0,
"GetStringWithArgs: {}", e.what());
260 builder +=
"(invalid string parameter)";
266 case TEXT_TAB_SPECIAL:
267 if (index >= 0xE4 && !game_script) {
269 GetSpecialNameString(builder, index - 0xE4, args);
270 }
catch (
const std::runtime_error &e) {
271 Debug(misc, 0,
"GetStringWithArgs: {}", e.what());
272 builder +=
"(invalid string parameter)";
278 case TEXT_TAB_OLD_CUSTOM:
281 FatalError(
"Incorrect conversion of custom name string.");
290 case TEXT_TAB_OLD_NEWGRF:
306 FatalError(
"String 0x{:X} is invalid. You are probably using an old version of the .lng file.\n",
string);
309 FormatString(builder, GetStringPtr(
string), args, case_index);
321 _global_string_params.PrepareForNextRun();
333 _global_string_params.PrepareForNextRun();
359 _global_string_params.SetParam(n, str);
370 _global_string_params.SetParam(n, str);
382 _global_string_params.SetParam(n, std::move(str));
385 static const char *GetDecimalSeparator()
388 if (
StrEmpty(decimal_separator)) decimal_separator = _langpack.langpack->digit_decimal_separator;
389 return decimal_separator;
400 static const int max_digits = 20;
401 uint64_t divisor = 10000000000000000000ULL;
402 int thousands_offset = (max_digits - 1) % 3;
409 uint64_t num = number;
411 for (
int i = 0; i < max_digits; i++) {
413 if (num >= divisor) {
414 quot = num / divisor;
417 if ((tot |= quot) || i == max_digits - 1) {
418 builder +=
'0' + quot;
419 if ((i % 3) == thousands_offset && i < max_digits - 1) builder += separator;
426 static void FormatCommaNumber(
StringBuilder &builder, int64_t number)
429 if (
StrEmpty(separator)) separator = _langpack.langpack->digit_group_separator;
433 static void FormatNoCommaNumber(
StringBuilder &builder, int64_t number)
435 fmt::format_to(builder,
"{}", number);
438 static void FormatZerofillNumber(
StringBuilder &builder, int64_t number,
int count)
440 fmt::format_to(builder,
"{:0{}d}", number, count);
443 static void FormatHexNumber(
StringBuilder &builder, uint64_t number)
445 fmt::format_to(builder,
"0x{:X}", number);
458 const char *
const iec_prefixes[] = {
"",
"Ki",
"Mi",
"Gi",
"Ti",
"Pi",
"Ei"};
460 while (number >= 1024 * 1024) {
467 fmt::format_to(builder,
"{}", number);
468 }
else if (number < 1024 * 10) {
469 fmt::format_to(builder,
"{}{}{:02}", number / 1024, GetDecimalSeparator(), (number % 1024) * 100 / 1024);
470 }
else if (number < 1024 * 100) {
471 fmt::format_to(builder,
"{}{}{:01}", number / 1024, GetDecimalSeparator(), (number % 1024) * 10 / 1024);
473 assert(number < 1024 * 1024);
474 fmt::format_to(builder,
"{}", number / 1024);
477 assert(
id <
lengthof(iec_prefixes));
478 fmt::format_to(builder,
NBSP "{}B", iec_prefixes[
id]);
481 static void FormatYmdString(
StringBuilder &builder, TimerGameCalendar::Date date, uint case_index)
485 auto tmp_params = MakeParameters(ymd.day + STR_DAY_NUMBER_1ST - 1, STR_MONTH_ABBREV_JAN + ymd.month, ymd.year);
486 FormatString(builder, GetStringPtr(STR_FORMAT_DATE_LONG), tmp_params, case_index);
489 static void FormatMonthAndYear(
StringBuilder &builder, TimerGameCalendar::Date date, uint case_index)
493 auto tmp_params = MakeParameters(STR_MONTH_JAN + ymd.month, ymd.year);
494 FormatString(builder, GetStringPtr(STR_FORMAT_DATE_SHORT), tmp_params, case_index);
502 auto tmp_params = MakeParameters(ymd.day, 2, ymd.month + 1, 2, ymd.year);
510 bool negative = number < 0;
512 number *= spec->
rate;
533 if (number >=
Money(1'000'000'000'000'000) - 500'000'000) {
534 number = (number +
Money(500'000'000'000)) /
Money(1'000'000'000'000);
535 number_str = STR_CURRENCY_SHORT_TERA;
536 }
else if (number >=
Money(1'000'000'000'000) - 500'000) {
537 number = (number + 500'000'000) / 1'000'000'000;
538 number_str = STR_CURRENCY_SHORT_GIGA;
539 }
else if (number >= 1'000'000'000 - 500) {
540 number = (number + 500'000) / 1'000'000;
541 number_str = STR_CURRENCY_SHORT_MEGA;
542 }
else if (number >= 1'000'000) {
543 number = (number + 500) / 1'000;
544 number_str = STR_CURRENCY_SHORT_KILO;
550 if (
StrEmpty(separator)) separator = _langpack.langpack->digit_group_separator_currency;
552 if (number_str != STR_NULL) {
554 FormatString(builder, GetStringPtr(number_str), tmp_params);
576 uint64_t n =
abs(count);
578 switch (plural_form) {
587 return n != 1 ? 1 : 0;
599 return n > 1 ? 1 : 0;
606 return n % 10 == 1 && n % 100 != 11 ? 0 : n != 0 ? 1 : 2;
612 return n == 1 ? 0 : n == 2 ? 1 : n < 7 ? 2 : n < 11 ? 3 : 4;
618 return n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
624 return n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
630 return n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
636 return n % 100 == 1 ? 0 : n % 100 == 2 ? 1 : n % 100 == 3 || n % 100 == 4 ? 2 : 3;
642 return n % 10 == 1 && n % 100 != 11 ? 0 : 1;
648 return n == 1 ? 0 : n >= 2 && n <= 4 ? 1 : 2;
679 return (n == 1 ? 0 : n == 0 || (n % 100 > 1 && n % 100 < 11) ? 1 : (n % 100 > 10 && n % 100 < 20) ? 2 : 3);
684 return ((n == 1 || n == 11) ? 0 : (n == 2 || n == 12) ? 1 : ((n > 2 && n < 11) || (n > 12 && n < 20)) ? 2 : 3);
690 return n == 1 ? 0 : (n == 0 || (n % 100 > 0 && n % 100 < 20)) ? 1 : 2;
694 static const char *ParseStringChoice(
const char *b, uint form,
StringBuilder &builder)
697 uint n = (uint8_t)*b++;
698 uint pos, i, mypos = 0;
700 for (i = pos = 0; i != n; i++) {
701 uint len = (uint8_t)*b++;
702 if (i == form) mypos = pos;
706 builder += b + mypos;
720 int64_t
ToDisplay(int64_t input,
bool round =
true)
const
723 ? (int64_t)std::round(input * this->factor)
724 : (int64_t)(input * this->factor);
734 int64_t
FromDisplay(int64_t input,
bool round =
true, int64_t divider = 1)
const
737 ? (int64_t)std::round(input / this->factor / divider)
738 : (int64_t)(input / this->factor / divider);
759 { { 1.0 }, STR_UNITS_VELOCITY_IMPERIAL, 0 },
760 { { 1.609344 }, STR_UNITS_VELOCITY_METRIC, 0 },
761 { { 0.44704 }, STR_UNITS_VELOCITY_SI, 0 },
762 { { 0.578125 }, STR_UNITS_VELOCITY_GAMEUNITS_DAY, 1 },
763 { { 0.868976 }, STR_UNITS_VELOCITY_KNOTS, 0 },
768 { { 1.0 }, STR_UNITS_VELOCITY_IMPERIAL, 0 },
769 { { 1.609344 }, STR_UNITS_VELOCITY_METRIC, 0 },
770 { { 0.44704 }, STR_UNITS_VELOCITY_SI, 0 },
771 { { 0.289352 }, STR_UNITS_VELOCITY_GAMEUNITS_SEC, 1 },
772 { { 0.868976 }, STR_UNITS_VELOCITY_KNOTS, 0 },
777 { { 1.0 }, STR_UNITS_POWER_IMPERIAL, 0 },
778 { { 1.01387 }, STR_UNITS_POWER_METRIC, 0 },
779 { { 0.745699 }, STR_UNITS_POWER_SI, 0 },
784 { { 0.907185 }, STR_UNITS_POWER_IMPERIAL_TO_WEIGHT_IMPERIAL, 1 },
785 { { 1.0 }, STR_UNITS_POWER_IMPERIAL_TO_WEIGHT_METRIC, 1 },
786 { { 1.0 }, STR_UNITS_POWER_IMPERIAL_TO_WEIGHT_SI, 1 },
787 { { 0.919768 }, STR_UNITS_POWER_METRIC_TO_WEIGHT_IMPERIAL, 1 },
788 { { 1.01387 }, STR_UNITS_POWER_METRIC_TO_WEIGHT_METRIC, 1 },
789 { { 1.01387 }, STR_UNITS_POWER_METRIC_TO_WEIGHT_SI, 1 },
790 { { 0.676487 }, STR_UNITS_POWER_SI_TO_WEIGHT_IMPERIAL, 1 },
791 { { 0.745699 }, STR_UNITS_POWER_SI_TO_WEIGHT_METRIC, 1 },
792 { { 0.745699 }, STR_UNITS_POWER_SI_TO_WEIGHT_SI, 1 },
797 { { 1.102311 }, STR_UNITS_WEIGHT_SHORT_IMPERIAL, STR_UNITS_WEIGHT_LONG_IMPERIAL, 0 },
798 { { 1.0 }, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC, 0 },
799 { { 1000.0 }, STR_UNITS_WEIGHT_SHORT_SI, STR_UNITS_WEIGHT_LONG_SI, 0 },
804 { { 264.172 }, STR_UNITS_VOLUME_SHORT_IMPERIAL, STR_UNITS_VOLUME_LONG_IMPERIAL, 0 },
805 { { 1000.0 }, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC, 0 },
806 { { 1.0 }, STR_UNITS_VOLUME_SHORT_SI, STR_UNITS_VOLUME_LONG_SI, 0 },
811 { { 0.224809 }, STR_UNITS_FORCE_IMPERIAL, 0 },
812 { { 0.101972 }, STR_UNITS_FORCE_METRIC, 0 },
813 { { 0.001 }, STR_UNITS_FORCE_SI, 0 },
818 { { 3.0 }, STR_UNITS_HEIGHT_IMPERIAL, 0 },
819 { { 1.0 }, STR_UNITS_HEIGHT_METRIC, 0 },
820 { { 1.0 }, STR_UNITS_HEIGHT_SI, 0 },
825 { { 1 }, STR_UNITS_DAYS, 0 },
826 { { 2 }, STR_UNITS_SECONDS, 0 },
831 { { 1 }, STR_UNITS_MONTHS, 0 },
832 { { 1 }, STR_UNITS_MINUTES, 0 },
837 { { 1 }, STR_UNITS_YEARS, 0 },
838 { { 1 }, STR_UNITS_PERIODS, 0 },
843 { { 1 }, STR_UNITS_YEARS, 0 },
844 { { 12 }, STR_UNITS_MINUTES, 0 },
937 FormatString(dry_run_builder, str_arg, args, case_index, game_script,
true);
940 FormatString(dry_run_builder, str_arg, args, case_index, game_script,
true);
946 uint next_substr_case_index = 0;
947 std::stack<const char *, std::vector<const char *>> str_stack;
948 str_stack.push(str_arg);
952 while (!str_stack.empty() && (b = Utf8Consume(&str_stack.top())) ==
'\0') {
955 if (str_stack.empty())
break;
956 const char *&str = str_stack.top();
962 if (b == 0)
continue;
965 if (b < SCC_CONTROL_START || b > SCC_CONTROL_END) {
970 args.SetTypeOfNextParameter(b);
976 uint32_t stringid = std::strtoul(str, &p, 16);
977 if (*p !=
':' && *p !=
'\0') {
978 while (*p !=
'\0') p++;
980 builder +=
"(invalid SCC_ENCODED)";
984 while (*p !=
'\0') p++;
986 builder +=
"(invalid StringID)";
991 while (*p !=
'\0' && i < 20) {
996 bool instring =
false;
1003 if (*p ==
'"' && escape) {
1010 instring = !instring;
1017 if (*p ==
':')
break;
1018 if (*p ==
'\0')
break;
1025 bool lookup = (l == SCC_ENCODED);
1026 if (lookup) s += len;
1028 param = std::strtoull(s, &p, 16);
1032 while (*p !=
'\0') p++;
1034 builder +=
"(invalid sub-StringID)";
1040 sub_args.SetParam(i++, param);
1043 sub_args.SetParam(i++, std::string(s, p - s - 1));
1055 StringID substr = Utf8Consume(&str);
1056 str_stack.push(GetStringPtr(substr));
1062 str_stack.push(GetStringPtr(substr));
1063 case_index = next_substr_case_index;
1064 next_substr_case_index = 0;
1069 case SCC_GENDER_LIST: {
1071 size_t offset = orig_offset + (uint8_t)*str++;
1091 const char *s = buffer.c_str();
1092 char32_t c = Utf8Consume(&s);
1094 if (c == SCC_GENDER_INDEX) gender = (uint8_t)s[0];
1096 str = ParseStringChoice(str, gender, builder);
1102 case SCC_GENDER_INDEX:
1111 case SCC_PLURAL_LIST: {
1112 int plural_form = *str++;
1113 size_t offset = orig_offset + (uint8_t)*str++;
1114 const uint64_t *v = std::get_if<uint64_t>(&args.GetParam(offset));
1116 str = ParseStringChoice(str,
DeterminePluralForm(
static_cast<int64_t
>(*v), plural_form), builder);
1118 builder +=
"(invalid PLURAL parameter)";
1123 case SCC_ARG_INDEX: {
1124 args.
SetOffset(orig_offset + (uint8_t)*str++);
1128 case SCC_SET_CASE: {
1131 next_substr_case_index = (uint8_t)*str++;
1135 case SCC_SWITCH_CASE: {
1138 uint num = (uint8_t)*str++;
1140 if ((uint8_t)str[0] == case_index) {
1146 str += 3 + (str[1] << 8) + str[2];
1153 builder += _openttd_revision;
1156 case SCC_RAW_STRING_POINTER: {
1159 if (raw_string ==
nullptr) {
1160 builder +=
"(invalid RAW_STRING parameter)";
1172 GetStringWithArgs(builder, string_id, tmp_params, next_substr_case_index, game_script);
1173 next_substr_case_index = 0;
1187 uint size = b - SCC_STRING1 + 1;
1189 builder +=
"(too many parameters)";
1192 GetStringWithArgs(builder, string_id, sub_args, next_substr_case_index, game_script);
1195 next_substr_case_index = 0;
1207 FormatCommaNumber(builder, number);
1212 int64_t fractional = number % divisor;
1214 FormatCommaNumber(builder, number);
1215 fmt::format_to(builder,
"{}{:0{}d}", GetDecimalSeparator(), fractional, digits);
1223 case SCC_ZEROFILL_NUM: {
1237 case SCC_CARGO_TINY: {
1246 switch (cargo_str) {
1261 FormatCommaNumber(builder, amount);
1265 case SCC_CARGO_SHORT: {
1273 switch (cargo_str) {
1277 auto tmp_params = MakeParameters(x.c.ToDisplay(args.
GetNextParameter<int64_t>()), x.decimal_places);
1285 auto tmp_params = MakeParameters(x.c.ToDisplay(args.
GetNextParameter<int64_t>()), x.decimal_places);
1299 case SCC_CARGO_LONG: {
1310 case SCC_CARGO_LIST: {
1315 if (!
HasBit(cmask, cs->Index()))
continue;
1324 GetStringWithArgs(builder, cs->name, args, next_substr_case_index, game_script);
1328 if (first)
GetStringWithArgs(builder, STR_JUST_NOTHING, args, next_substr_case_index, game_script);
1330 next_substr_case_index = 0;
1334 case SCC_CURRENCY_SHORT:
1338 case SCC_CURRENCY_LONG:
1343 FormatTinyOrISODate(builder, args.
GetNextParameter<TimerGameCalendar::Date>(), STR_FORMAT_DATE_TINY);
1346 case SCC_DATE_SHORT:
1347 FormatMonthAndYear(builder, args.
GetNextParameter<TimerGameCalendar::Date>(), next_substr_case_index);
1348 next_substr_case_index = 0;
1352 FormatYmdString(builder, args.
GetNextParameter<TimerGameCalendar::Date>(), next_substr_case_index);
1353 next_substr_case_index = 0;
1357 FormatTinyOrISODate(builder, args.
GetNextParameter<TimerGameCalendar::Date>(), STR_FORMAT_DATE_ISO);
1363 auto tmp_params = MakeParameters(x.c.ToDisplay(args.
GetNextParameter<int64_t>()), x.decimal_places);
1371 auto tmp_params = MakeParameters(x.c.ToDisplay(args.
GetNextParameter<int64_t>()), x.decimal_places);
1379 auto tmp_params = MakeParameters(x.c.ToDisplay(args.
GetNextParameter<int64_t>()), x.decimal_places);
1384 case SCC_POWER_TO_WEIGHT: {
1388 auto tmp_params = MakeParameters(x.c.ToDisplay(args.
GetNextParameter<int64_t>()), x.decimal_places);
1393 case SCC_VELOCITY: {
1403 case SCC_VOLUME_SHORT: {
1406 auto tmp_params = MakeParameters(x.c.ToDisplay(args.
GetNextParameter<int64_t>()), x.decimal_places);
1411 case SCC_VOLUME_LONG: {
1414 auto tmp_params = MakeParameters(x.c.ToDisplay(args.
GetNextParameter<int64_t>()), x.decimal_places);
1419 case SCC_WEIGHT_SHORT: {
1422 auto tmp_params = MakeParameters(x.c.ToDisplay(args.
GetNextParameter<int64_t>()), x.decimal_places);
1427 case SCC_WEIGHT_LONG: {
1430 auto tmp_params = MakeParameters(x.c.ToDisplay(args.
GetNextParameter<int64_t>()), x.decimal_places);
1435 case SCC_UNITS_DAYS_OR_SECONDS: {
1438 auto tmp_params = MakeParameters(x.c.ToDisplay(args.
GetNextParameter<int64_t>()), x.decimal_places);
1443 case SCC_UNITS_MONTHS_OR_MINUTES: {
1446 auto tmp_params = MakeParameters(x.c.ToDisplay(args.
GetNextParameter<int64_t>()), x.decimal_places);
1451 case SCC_UNITS_YEARS_OR_PERIODS: {
1454 auto tmp_params = MakeParameters(x.c.ToDisplay(args.
GetNextParameter<int64_t>()), x.decimal_places);
1459 case SCC_UNITS_YEARS_OR_MINUTES: {
1462 auto tmp_params = MakeParameters(x.c.ToDisplay(args.
GetNextParameter<int64_t>()), x.decimal_places);
1467 case SCC_COMPANY_NAME: {
1469 if (c ==
nullptr)
break;
1471 if (!c->
name.empty()) {
1472 auto tmp_params = MakeParameters(c->
name);
1475 auto tmp_params = MakeParameters(c->
name_2);
1481 case SCC_COMPANY_NUM: {
1486 auto tmp_params = MakeParameters(company + 1);
1492 case SCC_DEPOT_NAME: {
1501 if (!d->name.empty()) {
1502 auto tmp_params = MakeParameters(d->name);
1505 auto tmp_params = MakeParameters(d->town->
index, d->
town_cn + 1);
1511 case SCC_ENGINE_NAME: {
1514 if (e ==
nullptr)
break;
1516 if (!e->name.empty() && e->IsEnabled()) {
1517 auto tmp_params = MakeParameters(e->name);
1526 const GRFFile *grffile = e->GetGRF();
1527 assert(grffile !=
nullptr);
1543 case SCC_GROUP_NAME: {
1545 if (g ==
nullptr)
break;
1547 if (!g->
name.empty()) {
1548 auto tmp_params = MakeParameters(g->
name);
1551 auto tmp_params = MakeParameters(g->
number);
1557 case SCC_INDUSTRY_NAME: {
1559 if (i ==
nullptr)
break;
1561 static bool use_cache =
true;
1567 }
else if (use_cache) {
1569 builder += i->GetCachedName();
1573 FormatString(builder, GetStringPtr(STR_FORMAT_INDUSTRY_NAME), tmp_params, next_substr_case_index);
1575 next_substr_case_index = 0;
1579 case SCC_PRESIDENT_NAME: {
1581 if (c ==
nullptr)
break;
1593 case SCC_STATION_NAME: {
1597 if (st ==
nullptr) {
1606 static bool use_cache =
true;
1609 builder += st->GetCachedName();
1610 }
else if (!st->name.empty()) {
1611 auto tmp_params = MakeParameters(st->name);
1614 StringID string_id = st->string_id;
1615 if (st->indtype != IT_INVALID) {
1627 auto tmp_params = MakeParameters(STR_TOWN_NAME, st->town->index, st->index);
1633 case SCC_TOWN_NAME: {
1635 if (t ==
nullptr)
break;
1637 static bool use_cache =
true;
1640 builder += t->GetCachedName();
1641 }
else if (!t->
name.empty()) {
1642 auto tmp_params = MakeParameters(t->
name);
1650 case SCC_WAYPOINT_NAME: {
1652 if (wp ==
nullptr)
break;
1654 if (!wp->
name.empty()) {
1655 auto tmp_params = MakeParameters(wp->
name);
1659 StringID string_id = ((wp->
string_id == STR_SV_STNAME_BUOY) ? STR_FORMAT_BUOY_NAME : STR_FORMAT_WAYPOINT_NAME);
1660 if (wp->
town_cn != 0) string_id++;
1666 case SCC_VEHICLE_NAME: {
1668 if (v ==
nullptr)
break;
1670 if (!v->
name.empty()) {
1671 auto tmp_params = MakeParameters(v->
name);
1678 auto tmp_params = MakeParameters(v->
unitnumber);
1682 default: string_id = STR_INVALID_VEHICLE;
break;
1683 case VEH_TRAIN: string_id = STR_SV_TRAIN_NAME;
break;
1684 case VEH_ROAD: string_id = STR_SV_ROAD_VEHICLE_NAME;
break;
1685 case VEH_SHIP: string_id = STR_SV_SHIP_NAME;
break;
1686 case VEH_AIRCRAFT: string_id = STR_SV_AIRCRAFT_NAME;
break;
1694 case SCC_SIGN_NAME: {
1696 if (si ==
nullptr)
break;
1698 if (!si->name.empty()) {
1699 auto tmp_params = MakeParameters(si->name);
1708 case SCC_STATION_FEATURES: {
1723 }
catch (std::out_of_range &e) {
1724 Debug(misc, 0,
"FormatString: {}", e.what());
1725 builder +=
"(invalid parameter)";
1740 static void GetSpecialTownNameString(
StringBuilder &builder,
int ind, uint32_t seed)
1745 static const char *
const _silly_company_names[] = {
1747 "Tiny Transport Ltd.",
1749 "Comfy-Coach & Co.",
1750 "Crush & Bump Ltd.",
1751 "Broken & Late Ltd.",
1753 "Supersonic Travel",
1755 "Lightning International",
1756 "Pannik & Loozit Ltd.",
1757 "Inter-City Transport",
1758 "Getout & Pushit Ltd."
1761 static const char *
const _surname_list[] = {
1793 static const char *
const _silly_surname_list[] = {
1808 static const char _initial_name_letters[] = {
1809 'A',
'B',
'C',
'D',
'E',
'F',
'G',
'H',
'I',
'J',
1810 'K',
'L',
'M',
'N',
'P',
'R',
'S',
'T',
'W',
1813 static std::span<const char * const> GetSurnameOptions()
1816 return _surname_list;
1826 auto surname_options = GetSurnameOptions();
1827 return surname_options[surname_options.size() *
GB(seed, 16, 8) >> 8];
1830 static void GenAndCoName(
StringBuilder &builder, uint32_t seed)
1833 builder +=
" & Co.";
1836 static void GenPresidentName(
StringBuilder &builder, uint32_t seed)
1838 builder += _initial_name_letters[std::size(_initial_name_letters) *
GB(seed, 0, 8) >> 8];
1842 size_t index = (std::size(_initial_name_letters) + 35) *
GB(seed, 8, 8) >> 8;
1843 if (index < std::size(_initial_name_letters)) {
1844 builder += _initial_name_letters[index];
1855 builder += _silly_company_names[std::min<size_t>(args.
GetNextParameter<uint16_t>(), std::size(_silly_company_names) - 1)];
1868 if (
IsInsideMM(ind - 6, 0, SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1)) {
1869 GetSpecialTownNameString(builder, ind - 6, args.
GetNextParameter<uint32_t>());
1870 builder +=
" Transport";
1884 this->
version == TO_LE32(LANGUAGE_PACK_VERSION) &&
1904 return 4 * this->
missing < LANGUAGE_TOTAL_STRINGS;
1917 if (!lang_pack)
return false;
1920 const char *end = (
char *)lang_pack.get() + len + 1;
1923 if (end <= lang_pack->data || !lang_pack->IsValid()) {
1927 std::array<uint, TEXT_TAB_END> tab_start, tab_num;
1931 uint16_t num = FROM_LE16(lang_pack->offsets[i]);
1934 tab_start[i] = count;
1940 std::vector<char *> offs(count);
1943 char *s = lang_pack->data;
1944 len = (uint8_t)*s++;
1945 for (uint i = 0; i < count; i++) {
1946 if (s + len >= end)
return false;
1949 len = ((len & 0x3F) << 8) + (uint8_t)*s++;
1950 if (s + len >= end)
return false;
1958 _langpack.langpack = std::move(lang_pack);
1959 _langpack.offsets = std::move(offs);
1969 extern void Win32SetCurrentLocaleName(std::string iso_code);
1978 #ifdef WITH_ICU_I18N
1980 UErrorCode status = U_ZERO_ERROR;
1985 if (U_FAILURE(status)) {
2011 #if !(defined(_WIN32) || defined(__APPLE__))
2024 env = std::getenv(
"LANGUAGE");
2025 if (env !=
nullptr)
return env;
2027 env = std::getenv(
"LC_ALL");
2028 if (env !=
nullptr)
return env;
2030 if (param !=
nullptr) {
2031 env = std::getenv(param);
2032 if (env !=
nullptr)
return env;
2035 return std::getenv(
"LANG");
2049 if (newgrflangid == lang.newgrflangid)
return ⟨
2064 if (!f.has_value())
return false;
2066 size_t read = fread(hdr,
sizeof(*hdr), 1, *f);
2068 bool ret = read == 1 && hdr->
IsValid();
2084 std::error_code error_code;
2085 for (
const auto &dir_entry : std::filesystem::directory_iterator(
OTTD2FS(path), error_code)) {
2086 if (!dir_entry.is_regular_file())
continue;
2087 if (dir_entry.path().extension() !=
".lng")
continue;
2090 lmd.
file = dir_entry.path();
2102 Debug(misc, 9,
"Unable to open directory {}: {}", path, error_code.message());
2115 if (
_languages.empty()) UserError(
"No available language packs (invalid versions?)");
2119 if (lang ==
nullptr) lang =
"en_GB";
2131 chosen_language = &lng;
2135 if (strcmp (lng.isocode,
"en_GB") == 0) en_GB_fallback = &lng;
2138 if (!lng.IsReasonablyFinished())
continue;
2140 if (strncmp(lng.isocode, lang, 5) == 0) chosen_language = &lng;
2141 if (strncmp(lng.isocode, lang, 2) == 0) language_fallback = &lng;
2146 if (chosen_language ==
nullptr) {
2147 chosen_language = (language_fallback !=
nullptr) ? language_fallback : en_GB_fallback;
2159 return _langpack.langpack->isocode;
2172 auto src = text->cbegin();
2176 while (src != text->cend()) {
2177 char32_t c = Utf8Consume(src);
2179 if (c >= SCC_FIRST_FONT && c <= SCC_LAST_FONT) {
2180 size = (
FontSize)(c - SCC_FIRST_FONT);
2184 std::string size_name;
2187 case FS_NORMAL: size_name =
"medium";
break;
2188 case FS_SMALL: size_name =
"small";
break;
2189 case FS_LARGE: size_name =
"large";
break;
2190 case FS_MONO: size_name =
"mono";
break;
2191 default: NOT_REACHED();
2194 Debug(fontcache, 0,
"Font is missing glyphs to display char 0x{:X} in {} font size", (
int)c, size_name);
2222 const char *ret = _langpack.offsets[_langpack.
langtab_start[this->
i] + this->
j];
2225 while (this->i < TEXT_TAB_END && this->
j >= _langpack.
langtab_num[this->i]) {
2238 void SetFontNames([[maybe_unused]]
FontCacheSettings *
settings, [[maybe_unused]]
const char *font_name, [[maybe_unused]]
const void *os_data)
override
2240 #if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
2245 settings->small.os_handle = os_data;
2246 settings->medium.os_handle = os_data;
2247 settings->large.os_handle = os_data;
2268 if (searcher ==
nullptr) searcher = &pack_searcher;
2270 #if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
2274 bool any_font_configured = !_fcsettings.
medium.
font.empty();
2280 bad_font = !
SetFallbackFont(&_fcsettings, _langpack.langpack->isocode, _langpack.langpack->winlangid, searcher);
2282 _fcsettings = backup;
2284 if (!bad_font && any_font_configured) {
2291 static std::string err_str(
"XXXThe current font is missing some of the characters used in the texts for this language. Using system fallback font instead.");
2297 if (bad_font && base_font) {
2312 static std::string err_str(
"XXXThe current font is missing some of the characters used in the texts for this language. Read the readme to see how to solve this.");
2325 #if !(defined(WITH_ICU_I18N) && defined(WITH_HARFBUZZ)) && !defined(WITH_UNISCRIBE) && !defined(WITH_COCOA)
2340 static std::string err_str(
"XXXThis 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.
constexpr debug_inline bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr static debug_inline uint GB(const T x, const uint8_t s, const uint8_t n)
Fetch n bits from x, started at bit s.
uint8_t CargoID
Cargo slots to indicate a cargo type within a game.
bool IsValidCargoID(CargoID t)
Test whether cargo type is not INVALID_CARGO.
std::vector< const CargoSpec * > _sorted_cargo_specs
Cargo specifications sorted alphabetically by name.
void InitializeSortedCargoSpecs()
Initialize the list of sorted cargo specifications.
Extension of StringParameters with its own statically sized buffer for the parameters.
static std::optional< FileHandle > Open(const std::string &filename, const std::string &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 FontCache * Get(FontSize fs)
Get the font cache of a given font size.
Helper for searching through the language pack.
bool Monospace() override
Whether to search for a monospace font or not.
uint j
Iterator for the secondary language tables.
FontSize DefaultSize() override
Get the default (font) size of the string.
std::optional< std::string_view > NextString() override
Get the next string to search through.
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 Reset()=0
Reset the search, i.e.
virtual std::optional< std::string_view > NextString()=0
Get the next string to search through.
virtual FontSize DefaultSize()=0
Get the default (font) size of the string.
bool FindMissingGlyphs()
Check whether there are glyphs missing in the current language.
virtual bool Monospace()=0
Whether to search for a monospace font or not.
Equivalent to the std::back_insert_iterator in function, with some convenience helpers for string con...
void Utf8Encode(char32_t c)
Encode the given Utf8 character into the output buffer.
void SetOffset(size_t offset)
Set the offset within the string from where to return the next result of GetInt64 or GetInt32.
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.
void PrepareForNextRun()
Prepare the string parameters for the next formatting run.
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.
const char * GetNextParameterString()
Get the next string parameter from our parameters.
size_t offset
Current offset in the parameters span.
T GetNextParameter()
Get the next parameter from our parameters.
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 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.
Definition of stuff that is very close to a company, like the company struct itself.
Owner
Enum for all companies/owners.
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_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
Functions to handle different currencies.
const CurrencySpec & GetCurrency()
Get the currently selected currency.
Functions related to debugging.
#define Debug(category, level, format_string,...)
Ouptut a line of debugging information.
Base for all depots (except hangars)
uint16_t DepotID
Type for the unique identifier of depots.
Function to handling different endian machines.
uint16_t EngineID
Unique identification number of an engine.
Functions related to errors.
void ShowErrorMessage(StringID summary_msg, int x, int y, CommandCost cc)
Display an error message in a window.
@ WL_WARNING
Other information.
@ WL_ERROR
Errors (eg. saving/loading failed)
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_DIR
Subdirectory for all translation files.
fluid_settings_t * settings
FluidSynth settings handle.
void InitFontCache(bool monospace)
(Re)initialize the font cache related things, i.e.
Functions related to detecting/finding the right font.
bool SetFallbackFont(struct FontCacheSettings *settings, const std::string &language_isocode, int winlangid, class MissingGlyphSearcher *callback)
We would like to have a fallback font as the current one doesn't contain all characters we need.
void ReconsiderGameScriptLanguage()
Reconsider the game script language, so we use the right one.
const char * GetGameStringPtr(uint id)
Get the string pointer of a particular game string.
Base functions regarding game texts.
void GetBroadestDigit(uint *front, uint *next, FontSize size)
Determine the broadest digits for guessing the maximum width of a n-digit number.
void LoadStringWidthTable(bool monospace)
Initialize _stringwidth_table cache.
Functions related to laying out the texts.
FontSize
Available font sizes.
@ FS_MONO
Index of the monospaced font in the font tables.
@ FS_SMALL
Index of the small font in the font tables.
@ FS_NORMAL
Index of the normal font in the font tables.
@ FS_LARGE
Index of the large font in the font tables.
uint16_t GroupID
Type for all group identifiers.
static const 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.
Information about languages and their files.
static const uint8_t MAX_NUM_GENDERS
Maximum number of supported genders.
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 T abs(const T a)
Returns the absolute value of (scalar) variable.
constexpr uint64_t PowerOfTen(int power)
Computes ten to the given power.
constexpr bool IsInsideMM(const T x, const size_t min, const size_t max) noexcept
Checks if a value is in an interval.
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.
@ CBM_VEHICLE_NAME
Engine name.
static const uint CALLBACK_FAILED
Different values for Callback result evaluations.
uint16_t GetVehicleCallback(CallbackID callback, uint32_t param1, uint32_t param2, EngineID engine, const Vehicle *v)
Evaluate a newgrf callback for vehicles.
Functions for NewGRF engines.
void SetCurrentGrfLangID(uint8_t language_id)
Equivalence Setter function between game and newgrf langID.
void StartTextRefStackUsage(const GRFFile *grffile, uint8_t numEntries, const uint32_t *values)
Start using the TTDP compatible string code parsing.
struct TextRefStack * CreateTextRefStackBackup()
Create a backup of the current NewGRF text stack.
uint RemapNewGRFStringControlCode(uint scc, const char **str, StringParameters ¶meters, bool modify_parameters)
FormatString for NewGRF specific "magic" string control codes.
void RestoreTextRefStackBackup(struct TextRefStack *backup)
Restore a copy of the text stack to the used stack.
bool UsingNewGRFTextStack()
Check whether the NewGRF text stack is in use.
const char * GetGRFStringPtr(uint32_t stringid)
Get a C-string from a stringid set by a newgrf.
StringID GetGRFStringID(uint32_t grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
Header of Action 04 "universal holder" structure and functions.
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.
uint16_t SignID
The type of the IDs of signs.
void BuildIndustriesLegend()
Fills an array for the industries legends.
Base classes/functions for stations.
StationFacility
The facilities a station might be having.
@ FACIL_DOCK
Station with a dock.
@ FACIL_BUS_STOP
Station with bus stops.
@ FACIL_AIRPORT
Station with an airport.
@ FACIL_TRUCK_STOP
Station with truck stops.
@ FACIL_TRAIN
Station with train station.
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
bool StrValid(std::span< const char > str)
Checks whether the given string is valid, i.e.
size_t Utf8Decode(char32_t *c, const char *s)
Decode and consume the next UTF-8 encoded character.
size_t Utf8Encode(T buf, char32_t c)
Encode a unicode character and place it in the buffer.
Functions related to low-level strings.
bool StrEmpty(const char *s)
Check if a string buffer is empty.
bool IsTextDirectionChar(char32_t c)
Is the given character a text direction character.
void MacOSSetCurrentLocaleName(const char *iso_code)
Store current language locale as a CoreFoundation locale.
#define NBSP
A non-breaking space.
LanguageList _languages
The actual list of language meta data.
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.
static const Units _units_height[]
Unit conversions for height.
void SetDParamMaxValue(size_t n, uint64_t max_value, uint min_count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
const LanguageMetadata * _current_language
The currently loaded language.
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 all the associated D...
uint ConvertSpeedToDisplaySpeed(uint speed, VehicleType type)
Convert the given (internal) speed to the display speed.
const LanguageMetadata * GetLanguage(uint8_t newgrflangid)
Get the language with the given NewGRF language ID.
void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher)
Check whether the currently loaded language pack uses characters that the currently loaded font does ...
std::string _config_language_file
The file (name) stored in the configuration.
void SetDParam(size_t n, uint64_t v)
Set a string parameter v at index n in the global string parameter array.
static const Units GetVelocityUnits(VehicleType type)
Get the correct velocity units depending on the vehicle type and whether we're using real-time units.
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.
uint64_t GetDParam(size_t n)
Get the current string parameter at index n from the global string parameter array.
static void FormatNumber(StringBuilder &builder, int64_t number, const char *separator)
Format a number into a string.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with all the associated DParam lookups and formatting.
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 const UnitsLong _units_weight[]
Unit conversions for weight.
void CopyOutDParam(std::vector< StringParameterData > &backup, size_t num)
Copy num string parameters from the global string parameter array to the backup.
void CopyInDParam(const std::span< const StringParameterData > backup)
Copy the parameters from the backup into the global string parameter array.
static const Units _units_velocity_calendar[]
Unit conversions for velocity.
std::unique_ptr< icu::Collator > _current_collator
Collator for the language currently in use.
static void FormatString(StringBuilder &builder, const char *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 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.
bool HaveDParamChanged(const std::span< const StringParameterData > backup)
Checks whether the global string parameters have changed compared to the given backup.
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.
const char * GetCurrentLanguageIsoCode()
Get the ISO language code of the currently loaded language.
static const Units _units_velocity_realtime[]
Unit conversions for velocity.
static const char * GetSurname(uint32_t seed)
Get the surname of the president with the given seed.
const char * GetCurrentLocale(const char *param)
Determine the current charset based on the environment First check some default values,...
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 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.
void SetDParamStr(size_t n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
static const Units _units_time_years_or_periods[]
Unit conversions for time in calendar years or economic periods.
static int DeterminePluralForm(int64_t count, int plural_form)
Determine the "plural" index given a plural form and a number.
void SetDParamMaxDigits(size_t n, uint count, FontSize size)
Set DParam n to some number that is suitable for string size computations.
Functions related to OTTD's strings.
StringTab GetStringTab(StringID str)
Extract the StringTab from a StringID.
StringID MakeStringID(StringTab tab, uint index)
Create a StringID.
uint GetStringIndex(StringID str)
Extract the StringIndex from a StringID.
TextDirection
Directions a text can go to.
@ TD_LTR
Text is written left-to-right by default.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
static const uint TAB_SIZE_GAMESCRIPT
Number of strings for GameScripts.
static const uint MAX_LANG
Maximum number of languages supported by the game, and the NewGRF specs.
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.
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.
StringID quantifier
Text for multiple units of cargo of this type.
static CargoSpec * Get(size_t index)
Retrieve cargo details for the given cargo ID.
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(size_t 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.
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.
uint8_t symbol_pos
The currency symbol is represented by two possible values, prefix and suffix Usage of one or the othe...
uint16_t town_cn
The N-1th depot for this town (consecutive number)
Settings for the four different fonts.
FontCacheSubSetting mono
The mono space font used for license/readme viewers.
FontCacheSubSetting medium
The normal font size.
std::string font
The name of the font, or path to the font.
const void * os_handle
Optional native OS font info. Only valid during font search.
Dynamic data of a loaded NewGRF.
uint8_t landscape
the landscape we're currently in
LocaleSettings locale
settings related to used currency/unit system in the current game
GameCreationSettings game_creation
settings used during the creation of a game (map)
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.
std::array< uint, TEXT_TAB_END > langtab_num
Offset into langpack offs.
std::array< uint, TEXT_TAB_END > langtab_start
Offset into langpack offs.
uint8_t units_velocity_nautical
unit system for velocity of ships and aircraft
uint8_t units_velocity
unit system for velocity of trains and road vehicles
std::string digit_decimal_separator
decimal separator
std::string digit_group_separator_currency
thousand separator for currencies
uint8_t units_power
unit system for power
uint8_t units_height
unit system for height
uint8_t units_force
unit system for force
uint8_t units_volume
unit system for volume
uint8_t units_weight
unit system for weight
std::string digit_group_separator
thousand separator for non-currencies
Tindex index
Index of this pool item.
static Titem * Get(size_t index)
Returns Titem with given index.
static Titem * GetIfValid(size_t index)
Returns Titem with given index.
static Station * GetIfValid(size_t index)
Returns station if the index is a valid index for this station type.
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.
static void GetTownName(StringBuilder &builder, const TownNameParams *par, uint32_t townnameparts)
Fills builder with specified town name.
void GenerateTownNameString(StringBuilder &builder, size_t lang, uint32_t seed)
Generates town name from given seed.
Town name generator stuff.
Base class for all vehicles.
VehicleType
Available vehicle types.
@ VEH_ROAD
Road vehicle type.
@ VEH_AIRCRAFT
Aircraft vehicle type.
@ VEH_SHIP
Ship vehicle type.
@ VEH_TRAIN
Train vehicle type.
uint32_t VehicleID
The type all our vehicle IDs have.
std::wstring OTTD2FS(const std::string &name)
Convert from OpenTTD's encoding to a wide string.
std::string FS2OTTD(const std::wstring &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.
@ WC_STATION_LIST
Station list; Window numbers:
@ WC_ROADVEH_LIST
Road vehicle list; Window numbers:
@ WC_INDUSTRY_DIRECTORY
Industry directory; Window numbers:
@ WC_SHIPS_LIST
Ships list; Window numbers:
@ WC_TRAINS_LIST
Trains list; Window numbers:
@ WC_BUILD_VEHICLE
Build vehicle; Window numbers:
@ WC_AIRCRAFT_LIST
Aircraft list; Window numbers: