|
@@ -44,22 +44,23 @@
|
|
|
char _config_language_file[MAX_PATH]; ///< The file (name) stored in the configuration.
|
|
|
LanguageList _languages; ///< The actual list of language meta data.
|
|
|
const LanguageMetadata *_current_language = NULL; ///< The currently loaded language.
|
|
|
|
|
|
TextDirection _current_text_dir; ///< Text direction of the currently selected language.
|
|
|
uint64 _decode_parameters[20]; ///< Global array of string parameters. To access, use #SetDParam.
|
|
|
WChar _parameter_type[20]; ///< Type of parameters stored in #_decode_parameters
|
|
|
|
|
|
#ifdef WITH_ICU
|
|
|
Collator *_current_collator = NULL; ///< Collator for the language currently in use.
|
|
|
#endif /* WITH_ICU */
|
|
|
|
|
|
static char *StationGetSpecialString(char *buff, int x, const char *last);
|
|
|
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char *last);
|
|
|
static char *GetSpecialNameString(char *buff, int ind, int64 *argv, const int64 *argve, const char *last);
|
|
|
static char *GetSpecialNameString(char *buff, int ind, int64 *argv, const int64 *argve, const char *last, WChar *argt = NULL);
|
|
|
|
|
|
static char *FormatString(char *buff, const char *str, int64 *argv, const int64 *argve, uint casei, const char *last, bool dry_run = false);
|
|
|
static char *FormatString(char *buff, const char *str, int64 *argv, const int64 *argve, uint casei, const char *last, WChar *argt = NULL, bool dry_run = false);
|
|
|
|
|
|
struct LanguagePack : public LanguagePackHeader {
|
|
|
char data[]; // list of strings
|
|
|
};
|
|
|
|
|
|
static char **_langpack_offs;
|
|
@@ -67,33 +68,39 @@ static LanguagePack *_langpack;
|
|
|
static uint _langtab_num[32]; ///< Offset into langpack offs
|
|
|
static uint _langtab_start[32]; ///< Offset into langpack offs
|
|
|
static bool _keep_gender_data = false; ///< Should we retain the gender data in the current string?
|
|
|
|
|
|
|
|
|
/** Read an int64 from the argv array. */
|
|
|
static inline int64 GetInt64(int64 **argv, const int64 *argve)
|
|
|
static inline int64 GetInt64(int64 **argv, const int64 *argve, WChar **argt, WChar type = 0)
|
|
|
{
|
|
|
assert(*argv != NULL);
|
|
|
assert(*argv < argve);
|
|
|
if (*argt != NULL) {
|
|
|
assert(**argt == 0 || **argt == type);
|
|
|
**argt = type;
|
|
|
(*argt)++;
|
|
|
}
|
|
|
return *(*argv)++;
|
|
|
}
|
|
|
|
|
|
/** Read an int32 from the argv array. */
|
|
|
static inline int32 GetInt32(int64 **argv, const int64 *argve)
|
|
|
static inline int32 GetInt32(int64 **argv, const int64 *argve, WChar **argt, WChar type = 0)
|
|
|
{
|
|
|
return (int32)GetInt64(argv, argve);
|
|
|
return (int32)GetInt64(argv, argve, argt, type);
|
|
|
}
|
|
|
|
|
|
/** Read an array from the argv array. */
|
|
|
static inline int64 *GetArgvPtr(int64 **argv, int n, const int64 *argve)
|
|
|
static inline int64 *GetArgvPtr(int64 **argv, int n, const int64 *argve, WChar **argt)
|
|
|
{
|
|
|
int64 *result;
|
|
|
assert(*argv != NULL);
|
|
|
assert((*argv + n) <= argve);
|
|
|
result = *argv;
|
|
|
(*argv) += n;
|
|
|
if (*argt != NULL) (*argt) += n;
|
|
|
return result;
|
|
|
}
|
|
|
|
|
|
|
|
|
const char *GetStringPtr(StringID string)
|
|
|
{
|
|
@@ -113,67 +120,68 @@ const char *GetStringPtr(StringID string
|
|
|
* @param buffr
|
|
|
* @param string
|
|
|
* @param argv
|
|
|
* @param last
|
|
|
* @return a formatted string of char
|
|
|
*/
|
|
|
char *GetStringWithArgs(char *buffr, uint string, int64 *argv, const int64 *argve, const char *last)
|
|
|
char *GetStringWithArgs(char *buffr, uint string, int64 *argv, const int64 *argve, const char *last, WChar *argt)
|
|
|
{
|
|
|
if (GB(string, 0, 16) == 0) return GetStringWithArgs(buffr, STR_UNDEFINED, argv, argve, last);
|
|
|
if (GB(string, 0, 16) == 0) return GetStringWithArgs(buffr, STR_UNDEFINED, argv, argve, last, argt);
|
|
|
|
|
|
uint index = GB(string, 0, 11);
|
|
|
uint tab = GB(string, 11, 5);
|
|
|
|
|
|
switch (tab) {
|
|
|
case 4:
|
|
|
if (index >= 0xC0) {
|
|
|
return GetSpecialTownNameString(buffr, index - 0xC0, GetInt32(&argv, argve), last);
|
|
|
return GetSpecialTownNameString(buffr, index - 0xC0, GetInt32(&argv, argve, &argt), last);
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case 14:
|
|
|
if (index >= 0xE4) {
|
|
|
return GetSpecialNameString(buffr, index - 0xE4, argv, argve, last);
|
|
|
return GetSpecialNameString(buffr, index - 0xE4, argv, argve, last, argt);
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case 15:
|
|
|
/* Old table for custom names. This is no longer used */
|
|
|
error("Incorrect conversion of custom name string.");
|
|
|
|
|
|
case 26:
|
|
|
/* Include string within newgrf text (format code 81) */
|
|
|
if (HasBit(index, 10)) {
|
|
|
StringID string = GetGRFStringID(0, 0xD000 + GB(index, 0, 10));
|
|
|
return GetStringWithArgs(buffr, string, argv, argve, last);
|
|
|
return GetStringWithArgs(buffr, string, argv, argve, last, argt);
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case 28:
|
|
|
return FormatString(buffr, GetGRFStringPtr(index), argv, argve, GB(string, 24, 8), last);
|
|
|
return FormatString(buffr, GetGRFStringPtr(index), argv, argve, GB(string, 24, 8), last, argt);
|
|
|
|
|
|
case 29:
|
|
|
return FormatString(buffr, GetGRFStringPtr(index + 0x0800), argv, argve, GB(string, 24, 8), last);
|
|
|
return FormatString(buffr, GetGRFStringPtr(index + 0x0800), argv, argve, GB(string, 24, 8), last, argt);
|
|
|
|
|
|
case 30:
|
|
|
return FormatString(buffr, GetGRFStringPtr(index + 0x1000), argv, argve, GB(string, 24, 8), last);
|
|
|
return FormatString(buffr, GetGRFStringPtr(index + 0x1000), argv, argve, GB(string, 24, 8), last, argt);
|
|
|
|
|
|
case 31:
|
|
|
NOT_REACHED();
|
|
|
}
|
|
|
|
|
|
if (index >= _langtab_num[tab]) {
|
|
|
error("String 0x%X is invalid. You are probably using an old version of the .lng file.\n", string);
|
|
|
}
|
|
|
|
|
|
return FormatString(buffr, GetStringPtr(GB(string, 0, 16)), argv, argve, GB(string, 24, 8), last);
|
|
|
return FormatString(buffr, GetStringPtr(GB(string, 0, 16)), argv, argve, GB(string, 24, 8), last, argt);
|
|
|
}
|
|
|
|
|
|
char *GetString(char *buffr, StringID string, const char *last)
|
|
|
{
|
|
|
return GetStringWithArgs(buffr, string, (int64*)_decode_parameters, (int64*)endof(_decode_parameters), last);
|
|
|
memset(_parameter_type, 0, sizeof(_parameter_type));
|
|
|
return GetStringWithArgs(buffr, string, (int64*)_decode_parameters, (int64*)endof(_decode_parameters), last, _parameter_type);
|
|
|
}
|
|
|
|
|
|
|
|
|
char *InlineString(char *buf, StringID string)
|
|
|
{
|
|
|
buf += Utf8Encode(buf, SCC_STRING_ID);
|
|
@@ -582,27 +590,30 @@ uint ConvertSpeedToDisplaySpeed(uint spe
|
|
|
*/
|
|
|
uint ConvertDisplaySpeedToSpeed(uint speed)
|
|
|
{
|
|
|
return ((speed << units[_settings_game.locale.units].s_s) + units[_settings_game.locale.units].s_m / 2) / units[_settings_game.locale.units].s_m;
|
|
|
}
|
|
|
|
|
|
static char *FormatString(char *buff, const char *str, int64 *argv, const int64 *argve, uint casei, const char *last, bool dry_run)
|
|
|
static char *FormatString(char *buff, const char *str, int64 *argv, const int64 *argve, uint casei, const char *last, WChar *argt, bool dry_run)
|
|
|
{
|
|
|
if (UsingNewGRFTextStack() && !dry_run) {
|
|
|
/* Values from the NewGRF text stack are only copied to the normal
|
|
|
* argv array at the time they are encountered. That means that if
|
|
|
* another string command references a value later in the string it
|
|
|
* would fail. We solve that by running FormatString twice. The first
|
|
|
* pass makes sure the argv array is correctly filled and the second
|
|
|
* pass can reference later values without problems. */
|
|
|
struct TextRefStack *backup = CreateTextRefStackBackup();
|
|
|
FormatString(buff, str, argv, argve, casei, last, true);
|
|
|
FormatString(buff, str, argv, argve, casei, last, argt, true);
|
|
|
RestoreTextRefStackBackup(backup);
|
|
|
} else if (!dry_run) {
|
|
|
FormatString(buff, str, argv, argve, casei, last, argt, true);
|
|
|
}
|
|
|
WChar b;
|
|
|
int64 *argv_orig = argv;
|
|
|
WChar *argt_orig = argt;
|
|
|
uint modifier = 0;
|
|
|
char *buf_start = buff;
|
|
|
|
|
|
while ((b = Utf8Consume(&str)) != '\0') {
|
|
|
if (SCC_NEWGRF_FIRST <= b && b <= SCC_NEWGRF_LAST) {
|
|
|
/* We need to pass some stuff as it might be modified; oh boy. */
|
|
@@ -625,131 +636,141 @@ static char *FormatString(char *buff, co
|
|
|
*buff++ = *str++;
|
|
|
*buff++ = *str++;
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case SCC_STRING_ID: // {STRINL}
|
|
|
buff = GetStringWithArgs(buff, Utf8Consume(&str), argv, argve, last);
|
|
|
buff = GetStringWithArgs(buff, Utf8Consume(&str), argv, argve, last, argt);
|
|
|
break;
|
|
|
|
|
|
case SCC_RAW_STRING_POINTER: { // {RAW_STRING}
|
|
|
const char *str = (const char*)(size_t)GetInt64(&argv, argve);
|
|
|
buff = FormatString(buff, str, argv, argve, casei, last);
|
|
|
const char *str = (const char*)(size_t)GetInt64(&argv, argve, &argt);
|
|
|
buff = FormatString(buff, str, argv, argve, casei, last, argt);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_DATE_LONG: // {DATE_LONG}
|
|
|
buff = FormatYmdString(buff, GetInt32(&argv, argve), last);
|
|
|
buff = FormatYmdString(buff, GetInt32(&argv, argve, &argt, SCC_DATE_LONG), last);
|
|
|
break;
|
|
|
|
|
|
case SCC_DATE_SHORT: // {DATE_SHORT}
|
|
|
buff = FormatMonthAndYear(buff, GetInt32(&argv, argve), last);
|
|
|
buff = FormatMonthAndYear(buff, GetInt32(&argv, argve, &argt, SCC_DATE_SHORT), last);
|
|
|
break;
|
|
|
|
|
|
case SCC_VELOCITY: { // {VELOCITY}
|
|
|
int64 args[1];
|
|
|
assert(_settings_game.locale.units < lengthof(units));
|
|
|
args[0] = ConvertSpeedToDisplaySpeed(GetInt32(&argv, argve) * 10 / 16);
|
|
|
args[0] = ConvertSpeedToDisplaySpeed(GetInt32(&argv, argve, &argt, SCC_VELOCITY) * 10 / 16);
|
|
|
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].velocity), args, endof(args), modifier >> 24, last);
|
|
|
modifier = 0;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_HEIGHT: { // {HEIGHT}
|
|
|
int64 args[1] = {GetInt32(&argv, argve) * units[_settings_game.locale.units].h_m >> units[_settings_game.locale.units].h_s};
|
|
|
int64 args[1] = {GetInt32(&argv, argve, &argt) * units[_settings_game.locale.units].h_m >> units[_settings_game.locale.units].h_s};
|
|
|
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].height), args, endof(args), modifier >> 24, last);
|
|
|
modifier = 0;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_CURRENCY_COMPACT: // {CURRCOMPACT}
|
|
|
buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv, argve), true, last);
|
|
|
buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv, argve, &argt), true, last);
|
|
|
break;
|
|
|
|
|
|
case SCC_REVISION: // {REV}
|
|
|
buff = strecpy(buff, _openttd_revision, last);
|
|
|
break;
|
|
|
|
|
|
case SCC_CARGO_SHORT: { // {SHORTCARGO}
|
|
|
/* Short description of cargotypes. Layout:
|
|
|
* 8-bit = cargo type
|
|
|
* 16-bit = cargo count */
|
|
|
StringID cargo_str = CargoSpec::Get(GetInt32(&argv, argve))->units_volume;
|
|
|
StringID cargo_str = CargoSpec::Get(GetInt32(&argv, argve, &argt, SCC_CARGO_SHORT))->units_volume;
|
|
|
switch (cargo_str) {
|
|
|
case STR_TONS: {
|
|
|
int64 args[1];
|
|
|
assert(_settings_game.locale.units < lengthof(units));
|
|
|
args[0] = GetInt32(&argv, argve) * units[_settings_game.locale.units].w_m >> units[_settings_game.locale.units].w_s;
|
|
|
args[0] = GetInt32(&argv, argve, &argt) * units[_settings_game.locale.units].w_m >> units[_settings_game.locale.units].w_s;
|
|
|
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].l_weight), args, endof(args), modifier >> 24, last);
|
|
|
modifier = 0;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case STR_LITERS: {
|
|
|
int64 args[1];
|
|
|
assert(_settings_game.locale.units < lengthof(units));
|
|
|
args[0] = GetInt32(&argv, argve) * units[_settings_game.locale.units].v_m >> units[_settings_game.locale.units].v_s;
|
|
|
args[0] = GetInt32(&argv, argve, &argt) * units[_settings_game.locale.units].v_m >> units[_settings_game.locale.units].v_s;
|
|
|
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].l_volume), args, endof(args), modifier >> 24, last);
|
|
|
modifier = 0;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
default:
|
|
|
buff = GetStringWithArgs(buff, cargo_str, argv++, argve, last);
|
|
|
buff = GetStringWithArgs(buff, cargo_str, argv++, argve, last, argt++);
|
|
|
break;
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_STRING1: { // {STRING1}
|
|
|
/* String that consumes ONE argument */
|
|
|
uint str = modifier + GetInt32(&argv, argve);
|
|
|
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 1, argve), argve, last);
|
|
|
uint str = modifier + GetInt32(&argv, argve, &argt, SCC_STRING1);
|
|
|
WChar *orig_argt = argt;
|
|
|
int64 *args = GetArgvPtr(&argv, 1, argve, &argt);
|
|
|
buff = GetStringWithArgs(buff, str, args, argve, last, orig_argt);
|
|
|
modifier = 0;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_STRING2: { // {STRING2}
|
|
|
/* String that consumes TWO arguments */
|
|
|
uint str = modifier + GetInt32(&argv, argve);
|
|
|
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 2, argve), argve, last);
|
|
|
uint str = modifier + GetInt32(&argv, argve, &argt, SCC_STRING2);
|
|
|
WChar *orig_argt = argt;
|
|
|
int64 *args = GetArgvPtr(&argv, 2, argve, &argt);
|
|
|
buff = GetStringWithArgs(buff, str, args, argve, last, orig_argt);
|
|
|
modifier = 0;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_STRING3: { // {STRING3}
|
|
|
/* String that consumes THREE arguments */
|
|
|
uint str = modifier + GetInt32(&argv, argve);
|
|
|
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 3, argve), argve, last);
|
|
|
uint str = modifier + GetInt32(&argv, argve, &argt, SCC_STRING3);
|
|
|
WChar *orig_argt = argt;
|
|
|
int64 *args = GetArgvPtr(&argv, 3, argve, &argt);
|
|
|
buff = GetStringWithArgs(buff, str, args, argve, last, orig_argt);
|
|
|
modifier = 0;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_STRING4: { // {STRING4}
|
|
|
/* String that consumes FOUR arguments */
|
|
|
uint str = modifier + GetInt32(&argv, argve);
|
|
|
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 4, argve), argve, last);
|
|
|
uint str = modifier + GetInt32(&argv, argve, &argt, SCC_STRING4);
|
|
|
WChar *orig_argt = argt;
|
|
|
int64 *args = GetArgvPtr(&argv, 4, argve, &argt);
|
|
|
buff = GetStringWithArgs(buff, str, args, argve, last, orig_argt);
|
|
|
modifier = 0;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_STRING5: { // {STRING5}
|
|
|
/* String that consumes FIVE arguments */
|
|
|
uint str = modifier + GetInt32(&argv, argve);
|
|
|
buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 5, argve), argve, last);
|
|
|
uint str = modifier + GetInt32(&argv, argve, &argt, SCC_STRING5);
|
|
|
WChar *orig_argt = argt;
|
|
|
int64 *args = GetArgvPtr(&argv, 5, argve, &argt);
|
|
|
buff = GetStringWithArgs(buff, str, args, argve, last, orig_argt);
|
|
|
modifier = 0;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_STATION_FEATURES: { // {STATIONFEATURES}
|
|
|
buff = StationGetSpecialString(buff, GetInt32(&argv, argve), last);
|
|
|
buff = StationGetSpecialString(buff, GetInt32(&argv, argve, &argt, SCC_STATION_FEATURES), last);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_INDUSTRY_NAME: { // {INDUSTRY}
|
|
|
const Industry *i = Industry::Get(GetInt32(&argv, argve));
|
|
|
const Industry *i = Industry::Get(GetInt32(&argv, argve, &argt, SCC_INDUSTRY_NAME));
|
|
|
int64 args[2];
|
|
|
|
|
|
/* industry not valid anymore? */
|
|
|
assert(i != NULL);
|
|
|
|
|
|
/* First print the town name and the industry type name. */
|
|
@@ -760,22 +781,24 @@ static char *FormatString(char *buff, co
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_VOLUME: { // {VOLUME}
|
|
|
int64 args[1];
|
|
|
assert(_settings_game.locale.units < lengthof(units));
|
|
|
args[0] = GetInt32(&argv, argve) * units[_settings_game.locale.units].v_m >> units[_settings_game.locale.units].v_s;
|
|
|
args[0] = GetInt32(&argv, argve, &argt, SCC_VOLUME) * units[_settings_game.locale.units].v_m >> units[_settings_game.locale.units].v_s;
|
|
|
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].l_volume), args, endof(args), modifier >> 24, last);
|
|
|
modifier = 0;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_GENDER_LIST: { // {G 0 Der Die Das}
|
|
|
/* First read the meta data from the language file. */
|
|
|
WChar fmt = SCC_CONTROL_START + (byte)*str++;
|
|
|
byte offset = (byte)*str++;
|
|
|
assert(argv_orig + offset < argve);
|
|
|
assert(dry_run || argt == NULL || argt_orig[offset] == fmt);
|
|
|
|
|
|
/* Now we need to figure out what text to resolve, i.e.
|
|
|
* what do we need to draw? So get the actual raw string
|
|
|
* first using the control code to get said string. */
|
|
|
char input[4 + 1];
|
|
|
char *p = input + Utf8Encode(input, fmt);
|
|
@@ -797,69 +820,69 @@ static char *FormatString(char *buff, co
|
|
|
if (c == SCC_GENDER_INDEX) gender = (byte)s[0];
|
|
|
str = ParseStringChoice(str, gender, &buff, last);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_DATE_TINY: { // {DATE_TINY}
|
|
|
buff = FormatTinyOrISODate(buff, GetInt32(&argv, argve), STR_FORMAT_DATE_TINY, last);
|
|
|
buff = FormatTinyOrISODate(buff, GetInt32(&argv, argve, &argt, SCC_DATE_TINY), STR_FORMAT_DATE_TINY, last);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_DATE_ISO: { // {DATE_ISO}
|
|
|
buff = FormatTinyOrISODate(buff, GetInt32(&argv, argve), STR_FORMAT_DATE_ISO, last);
|
|
|
buff = FormatTinyOrISODate(buff, GetInt32(&argv, argve, &argt), STR_FORMAT_DATE_ISO, last);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_CARGO: { // {CARGO}
|
|
|
/* First parameter is cargo type, second parameter is cargo count */
|
|
|
CargoID cargo = GetInt32(&argv, argve);
|
|
|
CargoID cargo = GetInt32(&argv, argve, &argt, SCC_CARGO);
|
|
|
StringID cargo_str = (cargo == CT_INVALID) ? STR_QUANTITY_N_A : CargoSpec::Get(cargo)->quantifier;
|
|
|
buff = GetStringWithArgs(buff, cargo_str, argv++, argve, last);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_POWER: { // {POWER}
|
|
|
int64 args[1];
|
|
|
assert(_settings_game.locale.units < lengthof(units));
|
|
|
args[0] = GetInt32(&argv, argve) * units[_settings_game.locale.units].p_m >> units[_settings_game.locale.units].p_s;
|
|
|
args[0] = GetInt32(&argv, argve, &argt) * units[_settings_game.locale.units].p_m >> units[_settings_game.locale.units].p_s;
|
|
|
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].power), args, endof(args), modifier >> 24, last);
|
|
|
modifier = 0;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_VOLUME_SHORT: { // {VOLUME_S}
|
|
|
int64 args[1];
|
|
|
assert(_settings_game.locale.units < lengthof(units));
|
|
|
args[0] = GetInt32(&argv, argve) * units[_settings_game.locale.units].v_m >> units[_settings_game.locale.units].v_s;
|
|
|
args[0] = GetInt32(&argv, argve, &argt) * units[_settings_game.locale.units].v_m >> units[_settings_game.locale.units].v_s;
|
|
|
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].s_volume), args, endof(args), modifier >> 24, last);
|
|
|
modifier = 0;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_WEIGHT: { // {WEIGHT}
|
|
|
int64 args[1];
|
|
|
assert(_settings_game.locale.units < lengthof(units));
|
|
|
args[0] = GetInt32(&argv, argve) * units[_settings_game.locale.units].w_m >> units[_settings_game.locale.units].w_s;
|
|
|
args[0] = GetInt32(&argv, argve, &argt, SCC_WEIGHT) * units[_settings_game.locale.units].w_m >> units[_settings_game.locale.units].w_s;
|
|
|
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].l_weight), args, endof(args), modifier >> 24, last);
|
|
|
modifier = 0;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_WEIGHT_SHORT: { // {WEIGHT_S}
|
|
|
int64 args[1];
|
|
|
assert(_settings_game.locale.units < lengthof(units));
|
|
|
args[0] = GetInt32(&argv, argve) * units[_settings_game.locale.units].w_m >> units[_settings_game.locale.units].w_s;
|
|
|
args[0] = GetInt32(&argv, argve, &argt) * units[_settings_game.locale.units].w_m >> units[_settings_game.locale.units].w_s;
|
|
|
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].s_weight), args, endof(args), modifier >> 24, last);
|
|
|
modifier = 0;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_FORCE: { // {FORCE}
|
|
|
int64 args[1];
|
|
|
assert(_settings_game.locale.units < lengthof(units));
|
|
|
args[0] = GetInt32(&argv, argve) * units[_settings_game.locale.units].f_m >> units[_settings_game.locale.units].f_s;
|
|
|
args[0] = GetInt32(&argv, argve, &argt) * units[_settings_game.locale.units].f_m >> units[_settings_game.locale.units].f_s;
|
|
|
buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].force), args, endof(args), modifier >> 24, last);
|
|
|
modifier = 0;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
/* This sets up the gender for the string.
|
|
@@ -871,23 +894,23 @@ static char *FormatString(char *buff, co
|
|
|
} else {
|
|
|
str++;
|
|
|
}
|
|
|
break;
|
|
|
|
|
|
case SCC_STRING: {// {STRING}
|
|
|
uint str = modifier + GetInt32(&argv, argve);
|
|
|
uint str = modifier + GetInt32(&argv, argve, &argt, SCC_STRING);
|
|
|
/* WARNING. It's prohibited for the included string to consume any arguments.
|
|
|
* For included strings that consume argument, you should use STRING1, STRING2 etc.
|
|
|
* To debug stuff you can set argv to NULL and it will tell you */
|
|
|
buff = GetStringWithArgs(buff, str, argv, argve, last);
|
|
|
modifier = 0;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_COMMA: // {COMMA}
|
|
|
buff = FormatCommaNumber(buff, GetInt64(&argv, argve), last);
|
|
|
buff = FormatCommaNumber(buff, GetInt64(&argv, argve, &argt, SCC_COMMA), last);
|
|
|
break;
|
|
|
|
|
|
case SCC_ARG_INDEX: // Move argument pointer
|
|
|
argv = argv_orig + (byte)*str++;
|
|
|
break;
|
|
|
|
|
@@ -898,35 +921,35 @@ static char *FormatString(char *buff, co
|
|
|
int64 v = argv_orig[idx]; // contains the number that determines plural
|
|
|
str = ParseStringChoice(str, DeterminePluralForm(v, plural_form), &buff, last);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_NUM: // {NUM}
|
|
|
buff = FormatNoCommaNumber(buff, GetInt64(&argv, argve), last);
|
|
|
buff = FormatNoCommaNumber(buff, GetInt64(&argv, argve, &argt, SCC_NUM), last);
|
|
|
break;
|
|
|
|
|
|
case SCC_ZEROFILL_NUM: { // {ZEROFILL_NUM}
|
|
|
int64 num = GetInt64(&argv, argve);
|
|
|
buff = FormatZerofillNumber(buff, num, GetInt64(&argv, argve), last);
|
|
|
int64 num = GetInt64(&argv, argve, &argt);
|
|
|
buff = FormatZerofillNumber(buff, num, GetInt64(&argv, argve, &argt), last);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_HEX: // {HEX}
|
|
|
buff = FormatHexNumber(buff, (uint64)GetInt64(&argv, argve), last);
|
|
|
buff = FormatHexNumber(buff, (uint64)GetInt64(&argv, argve, &argt, SCC_HEX), last);
|
|
|
break;
|
|
|
|
|
|
case SCC_BYTES: // {BYTES}
|
|
|
buff = FormatBytes(buff, GetInt64(&argv, argve), last);
|
|
|
buff = FormatBytes(buff, GetInt64(&argv, argve, &argt), last);
|
|
|
break;
|
|
|
|
|
|
case SCC_CURRENCY: // {CURRENCY}
|
|
|
buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv, argve), false, last);
|
|
|
buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv, argve, &argt, SCC_CURRENCY), false, last);
|
|
|
break;
|
|
|
|
|
|
case SCC_WAYPOINT_NAME: { // {WAYPOINT}
|
|
|
Waypoint *wp = Waypoint::Get(GetInt32(&argv, argve));
|
|
|
Waypoint *wp = Waypoint::Get(GetInt32(&argv, argve, &argt, SCC_WAYPOINT_NAME));
|
|
|
|
|
|
assert(wp != NULL);
|
|
|
|
|
|
if (wp->name != NULL) {
|
|
|
buff = strecpy(buff, wp->name, last);
|
|
|
} else {
|
|
@@ -938,13 +961,13 @@ static char *FormatString(char *buff, co
|
|
|
buff = GetStringWithArgs(buff, str, args, endof(args), last);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_STATION_NAME: { // {STATION}
|
|
|
StationID sid = GetInt32(&argv, argve);
|
|
|
StationID sid = GetInt32(&argv, argve, &argt, SCC_STATION_NAME);
|
|
|
const Station *st = Station::GetIfValid(sid);
|
|
|
|
|
|
if (st == NULL) {
|
|
|
/* The station doesn't exist anymore. The only place where we might
|
|
|
* be "drawing" an invalid station is in the case of cargo that is
|
|
|
* in transit. */
|
|
@@ -975,44 +998,44 @@ static char *FormatString(char *buff, co
|
|
|
buff = GetStringWithArgs(buff, str, args, endof(args), last);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_DEPOT_NAME: { // {DEPOT}
|
|
|
VehicleType vt = (VehicleType)GetInt32(&argv, argve);
|
|
|
VehicleType vt = (VehicleType)GetInt32(&argv, argve, &argt, SCC_DEPOT_NAME);
|
|
|
if (vt == VEH_AIRCRAFT) {
|
|
|
int64 args[] = { GetInt32(&argv, argve) };
|
|
|
int64 args[] = { GetInt32(&argv, argve, &argt) };
|
|
|
buff = GetStringWithArgs(buff, STR_FORMAT_DEPOT_NAME_AIRCRAFT, args, endof(args), last);
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
const Depot *d = Depot::Get(GetInt32(&argv, argve));
|
|
|
const Depot *d = Depot::Get(GetInt32(&argv, argve, &argt));
|
|
|
if (d->name != NULL) {
|
|
|
buff = strecpy(buff, d->name, last);
|
|
|
} else {
|
|
|
int64 args[] = { d->town->index, d->town_cn + 1 };
|
|
|
buff = GetStringWithArgs(buff, STR_FORMAT_DEPOT_NAME_TRAIN + 2 * vt + (d->town_cn == 0 ? 0 : 1), args, endof(args), last);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_TOWN_NAME: { // {TOWN}
|
|
|
const Town *t = Town::Get(GetInt32(&argv, argve));
|
|
|
const Town *t = Town::Get(GetInt32(&argv, argve, &argt, SCC_TOWN_NAME));
|
|
|
|
|
|
assert(t != NULL);
|
|
|
|
|
|
if (t->name != NULL) {
|
|
|
buff = strecpy(buff, t->name, last);
|
|
|
} else {
|
|
|
buff = GetTownName(buff, t, last);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_GROUP_NAME: { // {GROUP}
|
|
|
const Group *g = Group::Get(GetInt32(&argv, argve));
|
|
|
const Group *g = Group::Get(GetInt32(&argv, argve, &argt));
|
|
|
|
|
|
assert(g != NULL);
|
|
|
|
|
|
if (g->name != NULL) {
|
|
|
buff = strecpy(buff, g->name, last);
|
|
|
} else {
|
|
@@ -1022,13 +1045,13 @@ static char *FormatString(char *buff, co
|
|
|
buff = GetStringWithArgs(buff, STR_FORMAT_GROUP_NAME, args, endof(args), last);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_ENGINE_NAME: { // {ENGINE}
|
|
|
EngineID engine = (EngineID)GetInt32(&argv, argve);
|
|
|
EngineID engine = (EngineID)GetInt32(&argv, argve, &argt, SCC_ENGINE_NAME);
|
|
|
const Engine *e = Engine::Get(engine);
|
|
|
|
|
|
assert(e != NULL);
|
|
|
|
|
|
if (e->name != NULL && e->info.string_id != STR_NEWGRF_INVALID_ENGINE) {
|
|
|
buff = strecpy(buff, e->name, last);
|
|
@@ -1036,13 +1059,13 @@ static char *FormatString(char *buff, co
|
|
|
buff = GetStringWithArgs(buff, e->info.string_id, NULL, NULL, last);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_VEHICLE_NAME: { // {VEHICLE}
|
|
|
const Vehicle *v = Vehicle::Get(GetInt32(&argv, argve));
|
|
|
const Vehicle *v = Vehicle::Get(GetInt32(&argv, argve, &argt, SCC_VEHICLE_NAME));
|
|
|
|
|
|
assert(v != NULL);
|
|
|
|
|
|
if (v->name != NULL) {
|
|
|
buff = strecpy(buff, v->name, last);
|
|
|
} else {
|
|
@@ -1061,48 +1084,48 @@ static char *FormatString(char *buff, co
|
|
|
buff = GetStringWithArgs(buff, str, args, endof(args), last);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_SIGN_NAME: { // {SIGN}
|
|
|
const Sign *si = Sign::Get(GetInt32(&argv, argve));
|
|
|
const Sign *si = Sign::Get(GetInt32(&argv, argve, &argt));
|
|
|
if (si->name != NULL) {
|
|
|
buff = strecpy(buff, si->name, last);
|
|
|
} else {
|
|
|
buff = GetStringWithArgs(buff, STR_DEFAULT_SIGN_NAME, NULL, NULL, last);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_COMPANY_NAME: { // {COMPANY}
|
|
|
const Company *c = Company::Get((CompanyID)GetInt32(&argv, argve));
|
|
|
const Company *c = Company::Get((CompanyID)GetInt32(&argv, argve, &argt));
|
|
|
|
|
|
if (c->name != NULL) {
|
|
|
buff = strecpy(buff, c->name, last);
|
|
|
} else {
|
|
|
int64 args[1];
|
|
|
args[0] = c->name_2;
|
|
|
buff = GetStringWithArgs(buff, c->name_1, args, endof(args), last);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_COMPANY_NUM: { // {COMPANYNUM}
|
|
|
CompanyID company = (CompanyID)GetInt32(&argv, argve);
|
|
|
CompanyID company = (CompanyID)GetInt32(&argv, argve, &argt);
|
|
|
|
|
|
/* Nothing is added for AI or inactive companies */
|
|
|
if (Company::IsValidHumanID(company)) {
|
|
|
int64 args[1];
|
|
|
args[0] = company + 1;
|
|
|
buff = GetStringWithArgs(buff, STR_FORMAT_COMPANY_NUM, args, endof(args), last);
|
|
|
}
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
case SCC_PRESIDENT_NAME: { // {PRESIDENTNAME}
|
|
|
const Company *c = Company::Get((CompanyID)GetInt32(&argv, argve));
|
|
|
const Company *c = Company::Get((CompanyID)GetInt32(&argv, argve, &argt, SCC_PRESIDENT_NAME));
|
|
|
|
|
|
if (c->president_name != NULL) {
|
|
|
buff = strecpy(buff, c->president_name, last);
|
|
|
} else {
|
|
|
int64 args[1];
|
|
|
args[0] = c->president_name_2;
|
|
@@ -1274,28 +1297,28 @@ static char *GenPresidentName(char *buff
|
|
|
|
|
|
buff = strecpy(buff, base[num * GB(x, 16, 8) >> 8], last);
|
|
|
|
|
|
return buff;
|
|
|
}
|
|
|
|
|
|
static char *GetSpecialNameString(char *buff, int ind, int64 *argv, const int64 *argve, const char *last)
|
|
|
static char *GetSpecialNameString(char *buff, int ind, int64 *argv, const int64 *argve, const char *last, WChar *argt)
|
|
|
{
|
|
|
switch (ind) {
|
|
|
case 1: // not used
|
|
|
return strecpy(buff, _silly_company_names[GetInt32(&argv, argve) & 0xFFFF], last);
|
|
|
return strecpy(buff, _silly_company_names[GetInt32(&argv, argve, &argt) & 0xFFFF], last);
|
|
|
|
|
|
case 2: // used for Foobar & Co company names
|
|
|
return GenAndCoName(buff, GetInt32(&argv, argve), last);
|
|
|
return GenAndCoName(buff, GetInt32(&argv, argve, &argt), last);
|
|
|
|
|
|
case 3: // President name
|
|
|
return GenPresidentName(buff, GetInt32(&argv, argve), last);
|
|
|
return GenPresidentName(buff, GetInt32(&argv, argve, &argt), last);
|
|
|
}
|
|
|
|
|
|
/* town name? */
|
|
|
if (IsInsideMM(ind - 6, 0, SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1)) {
|
|
|
buff = GetSpecialTownNameString(buff, ind - 6, GetInt32(&argv, argve), last);
|
|
|
buff = GetSpecialTownNameString(buff, ind - 6, GetInt32(&argv, argve, &argt), last);
|
|
|
return strecpy(buff, " Transport", last);
|
|
|
}
|
|
|
|
|
|
/* language name? */
|
|
|
if (IsInsideMM(ind, (SPECSTR_LANGUAGE_START - 0x70E4), (SPECSTR_LANGUAGE_END - 0x70E4) + 1)) {
|
|
|
int i = ind - (SPECSTR_LANGUAGE_START - 0x70E4);
|