src/strings.cpp
branchnoai
changeset 9629 66dde6412125
parent 9628 b5c2449616b5
child 9686 d3c195c226f9
equal deleted inserted replaced
9628:b5c2449616b5 9629:66dde6412125
    26 #include "fileio.h"
    26 #include "fileio.h"
    27 #include "helpers.hpp"
    27 #include "helpers.hpp"
    28 #include "cargotype.h"
    28 #include "cargotype.h"
    29 #include "group.h"
    29 #include "group.h"
    30 #include "debug.h"
    30 #include "debug.h"
       
    31 #include "newgrf_townname.h"
       
    32 #include "signs.h"
       
    33 #include "vehicle.h"
       
    34 #include "newgrf_engine.h"
    31 
    35 
    32 /* for opendir/readdir/closedir */
    36 /* for opendir/readdir/closedir */
    33 # include "fios.h"
    37 # include "fios.h"
    34 
    38 
    35 DynamicLanguages _dynlang;
    39 DynamicLanguages _dynlang;
    36 char _userstring[128];
    40 char _userstring[128];
    37 
    41 
    38 static char *StationGetSpecialString(char *buff, int x, const char* last);
    42 static char *StationGetSpecialString(char *buff, int x, const char* last);
    39 static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char* last);
    43 static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char* last);
    40 static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv, const char* last);
    44 static char *GetSpecialPlayerNameString(char *buff, int ind, const int64 *argv, const char* last);
    41 
    45 
    42 static char *FormatString(char *buff, const char *str, const int32 *argv, uint casei, const char* last);
    46 static char *FormatString(char *buff, const char *str, const int64 *argv, uint casei, const char* last);
    43 
    47 
    44 struct LanguagePack {
    48 struct LanguagePack {
    45 	uint32 ident;       // 32-bits identifier
    49 	uint32 ident;       // 32-bits identifier
    46 	uint32 version;     // 32-bits of auto generated version info which is basically a hash of strings.h
    50 	uint32 version;     // 32-bits of auto generated version info which is basically a hash of strings.h
    47 	char name[32];      // the international name of this language
    51 	char name[32];      // the international name of this language
    58 static uint _langtab_num[32];   // Offset into langpack offs
    62 static uint _langtab_num[32];   // Offset into langpack offs
    59 static uint _langtab_start[32]; // Offset into langpack offs
    63 static uint _langtab_start[32]; // Offset into langpack offs
    60 
    64 
    61 
    65 
    62 /** Read an int64 from the argv array. */
    66 /** Read an int64 from the argv array. */
    63 static inline int64 GetInt64(const int32 **argv)
    67 static inline int64 GetInt64(const int64 **argv)
    64 {
       
    65 	int64 result;
       
    66 
       
    67 	assert(argv);
       
    68 	result = (uint32)(*argv)[0] + ((uint64)(uint32)(*argv)[1] << 32);
       
    69 	(*argv) += 2;
       
    70 	return result;
       
    71 }
       
    72 
       
    73 /** Read an int32 from the argv array. */
       
    74 static inline int32 GetInt32(const int32 **argv)
       
    75 {
    68 {
    76 	assert(argv);
    69 	assert(argv);
    77 	return *(*argv)++;
    70 	return *(*argv)++;
    78 }
    71 }
    79 
    72 
       
    73 /** Read an int32 from the argv array. */
       
    74 static inline int32 GetInt32(const int64 **argv)
       
    75 {
       
    76 	return (int32)GetInt64(argv);
       
    77 }
       
    78 
    80 /** Read an array from the argv array. */
    79 /** Read an array from the argv array. */
    81 static inline const int32 *GetArgvPtr(const int32 **argv, int n)
    80 static inline const int64 *GetArgvPtr(const int64 **argv, int n)
    82 {
    81 {
    83 	const int32 *result;
    82 	const int64 *result;
    84 	assert(*argv);
    83 	assert(*argv);
    85 	result = *argv;
    84 	result = *argv;
    86 	(*argv) += n;
    85 	(*argv) += n;
    87 	return result;
    86 	return result;
    88 }
    87 }
   112  * @param string
   111  * @param string
   113  * @param argv
   112  * @param argv
   114  * @param last
   113  * @param last
   115  * @return a formatted string of char
   114  * @return a formatted string of char
   116  */
   115  */
   117 static char *GetStringWithArgs(char *buffr, uint string, const int32 *argv, const char* last)
   116 static char *GetStringWithArgs(char *buffr, uint string, const int64 *argv, const char* last)
   118 {
   117 {
   119 	uint index = GB(string,  0, 11);
   118 	uint index = GB(string,  0, 11);
   120 	uint tab   = GB(string, 11,  5);
   119 	uint tab   = GB(string, 11,  5);
   121 	char buff[512];
   120 	char buff[512];
   122 
   121 
   177 	return FormatString(buffr, GetStringPtr(GB(string, 0, 16)), argv, GB(string, 24, 8), last);
   176 	return FormatString(buffr, GetStringPtr(GB(string, 0, 16)), argv, GB(string, 24, 8), last);
   178 }
   177 }
   179 
   178 
   180 char *GetString(char *buffr, StringID string, const char* last)
   179 char *GetString(char *buffr, StringID string, const char* last)
   181 {
   180 {
   182 	return GetStringWithArgs(buffr, string, (int32*)_decode_parameters, last);
   181 	return GetStringWithArgs(buffr, string, (int64*)_decode_parameters, last);
   183 }
   182 }
   184 
   183 
   185 
   184 
   186 char *InlineString(char *buf, StringID string)
   185 char *InlineString(char *buf, StringID string)
   187 {
   186 {
   219 	SetDParam(n, BindCString(str));
   218 	SetDParam(n, BindCString(str));
   220 }
   219 }
   221 
   220 
   222 void InjectDParam(int amount)
   221 void InjectDParam(int amount)
   223 {
   222 {
   224 	memmove(_decode_parameters + amount, _decode_parameters, sizeof(_decode_parameters) - amount * sizeof(uint32));
   223 	memmove(_decode_parameters + amount, _decode_parameters, sizeof(_decode_parameters) - amount * sizeof(uint64));
   225 }
   224 }
   226 
   225 
   227 static const uint32 _divisor_table[] = {
   226 static const uint32 _divisor_table[] = {
   228 	1000000000,
   227 	1000000000,
   229 	100000000,
   228 	100000000,
   309 static char *FormatYmdString(char *buff, Date date, const char* last)
   308 static char *FormatYmdString(char *buff, Date date, const char* last)
   310 {
   309 {
   311 	YearMonthDay ymd;
   310 	YearMonthDay ymd;
   312 	ConvertDateToYMD(date, &ymd);
   311 	ConvertDateToYMD(date, &ymd);
   313 
   312 
   314 	int32 args[3] = { ymd.day + STR_01AC_1ST - 1, STR_0162_JAN + ymd.month, ymd.year };
   313 	int64 args[3] = { ymd.day + STR_01AC_1ST - 1, STR_0162_JAN + ymd.month, ymd.year };
   315 	return FormatString(buff, GetStringPtr(STR_DATE_LONG), args, 0, last);
   314 	return FormatString(buff, GetStringPtr(STR_DATE_LONG), args, 0, last);
   316 }
   315 }
   317 
   316 
   318 static char *FormatMonthAndYear(char *buff, Date date, const char* last)
   317 static char *FormatMonthAndYear(char *buff, Date date, const char* last)
   319 {
   318 {
   320 	YearMonthDay ymd;
   319 	YearMonthDay ymd;
   321 	ConvertDateToYMD(date, &ymd);
   320 	ConvertDateToYMD(date, &ymd);
   322 
   321 
   323 	int32 args[2] = { STR_MONTH_JAN + ymd.month, ymd.year };
   322 	int64 args[2] = { STR_MONTH_JAN + ymd.month, ymd.year };
   324 	return FormatString(buff, GetStringPtr(STR_DATE_SHORT), args, 0, last);
   323 	return FormatString(buff, GetStringPtr(STR_DATE_SHORT), args, 0, last);
   325 }
   324 }
   326 
   325 
   327 static char *FormatTinyDate(char *buff, Date date, const char* last)
   326 static char *FormatTinyDate(char *buff, Date date, const char* last)
   328 {
   327 {
   333 	char month[3];
   332 	char month[3];
   334 	/* We want to zero-pad the days and months */
   333 	/* We want to zero-pad the days and months */
   335 	snprintf(day,   lengthof(day),   "%02i", ymd.day);
   334 	snprintf(day,   lengthof(day),   "%02i", ymd.day);
   336 	snprintf(month, lengthof(month), "%02i", ymd.month + 1);
   335 	snprintf(month, lengthof(month), "%02i", ymd.month + 1);
   337 
   336 
   338 	int32 args[3] = { BindCString(day), BindCString(month), ymd.year };
   337 	int64 args[3] = { BindCString(day), BindCString(month), ymd.year };
   339 	return FormatString(buff, GetStringPtr(STR_DATE_TINY), args, 0, last);
   338 	return FormatString(buff, GetStringPtr(STR_DATE_TINY), args, 0, last);
   340 }
   339 }
   341 
   340 
   342 static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 number, bool compact, const char* last)
   341 static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, Money number, bool compact, const char* last)
   343 {
   342 {
   344 	const char* multiplier = "";
   343 	const char* multiplier = "";
   345 	char buf[40];
   344 	char buf[40];
   346 	char* p;
   345 	char* p;
   347 	int j;
   346 	int j;
   348 
   347 
   349 	/* multiply by exchange rate */
   348 	/* Multiply by exchange rate, but do it safely. */
   350 	number *= spec->rate;
   349 	CommandCost cs(number);
       
   350 	cs.MultiplyCost(spec->rate);
       
   351 	number = cs.GetCost();
   351 
   352 
   352 	/* convert from negative */
   353 	/* convert from negative */
   353 	if (number < 0) {
   354 	if (number < 0) {
   354 		buff = strecpy(buff, "-", last);
   355 		buff = strecpy(buff, "-", last);
   355 		number = -number;
   356 		number = -number;
   520 		   1,  0, STR_UNITS_VOLUME_SHORT_SI, STR_UNITS_VOLUME_LONG_SI,
   521 		   1,  0, STR_UNITS_VOLUME_SHORT_SI, STR_UNITS_VOLUME_LONG_SI,
   521 		   1,  0, STR_UNITS_FORCE_SI,
   522 		   1,  0, STR_UNITS_FORCE_SI,
   522 	},
   523 	},
   523 };
   524 };
   524 
   525 
   525 static char* FormatString(char* buff, const char* str, const int32* argv, uint casei, const char* last)
   526 static char* FormatString(char* buff, const char* str, const int64* argv, uint casei, const char* last)
   526 {
   527 {
   527 	extern const char _openttd_revision[];
   528 	extern const char _openttd_revision[];
   528 	WChar b;
   529 	WChar b;
   529 	const int32 *argv_orig = argv;
   530 	const int64 *argv_orig = argv;
   530 	uint modifier = 0;
   531 	uint modifier = 0;
   531 
   532 
   532 	while ((b = Utf8Consume(&str)) != '\0') {
   533 	while ((b = Utf8Consume(&str)) != '\0') {
   533 		switch (b) {
   534 		switch (b) {
   534 			case SCC_SETX: // {SETX}
   535 			case SCC_SETX: // {SETX}
   557 			case SCC_DATE_SHORT: // {DATE_SHORT}
   558 			case SCC_DATE_SHORT: // {DATE_SHORT}
   558 				buff = FormatMonthAndYear(buff, GetInt32(&argv), last);
   559 				buff = FormatMonthAndYear(buff, GetInt32(&argv), last);
   559 				break;
   560 				break;
   560 
   561 
   561 			case SCC_VELOCITY: {// {VELOCITY}
   562 			case SCC_VELOCITY: {// {VELOCITY}
   562 				int32 args[1];
   563 				int64 args[1];
   563 				assert(_opt_ptr->units < lengthof(units));
   564 				assert(_opt_ptr->units < lengthof(units));
   564 				args[0] = GetInt32(&argv) * units[_opt_ptr->units].s_m >> units[_opt_ptr->units].s_s;
   565 				args[0] = GetInt32(&argv) * units[_opt_ptr->units].s_m >> units[_opt_ptr->units].s_s;
   565 				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].velocity), args, modifier >> 24, last);
   566 				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].velocity), args, modifier >> 24, last);
   566 				modifier = 0;
   567 				modifier = 0;
   567 				break;
   568 				break;
   568 			}
   569 			}
   569 
   570 
   570 			case SCC_CURRENCY_COMPACT: /* {CURRCOMPACT} */
   571 			case SCC_CURRENCY_COMPACT: /* {CURRCOMPACT} */
   571 				buff = FormatGenericCurrency(buff, _currency, GetInt32(&argv), true, last);
   572 				buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), true, last);
   572 				break;
   573 				break;
   573 
   574 
   574 			case SCC_REVISION: /* {REV} */
   575 			case SCC_REVISION: /* {REV} */
   575 				buff = strecpy(buff, _openttd_revision, last);
   576 				buff = strecpy(buff, _openttd_revision, last);
   576 				break;
   577 				break;
   580 				 * 8-bit = cargo type
   581 				 * 8-bit = cargo type
   581 				 * 16-bit = cargo count */
   582 				 * 16-bit = cargo count */
   582 				StringID cargo_str = GetCargo(GetInt32(&argv))->units_volume;
   583 				StringID cargo_str = GetCargo(GetInt32(&argv))->units_volume;
   583 				switch (cargo_str) {
   584 				switch (cargo_str) {
   584 					case STR_TONS: {
   585 					case STR_TONS: {
   585 						int32 args[1];
   586 						int64 args[1];
   586 						assert(_opt_ptr->units < lengthof(units));
   587 						assert(_opt_ptr->units < lengthof(units));
   587 						args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s;
   588 						args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s;
   588 						buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_weight), args, modifier >> 24, last);
   589 						buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_weight), args, modifier >> 24, last);
   589 						modifier = 0;
   590 						modifier = 0;
   590 						break;
   591 						break;
   591 					}
   592 					}
   592 
   593 
   593 					case STR_LITERS: {
   594 					case STR_LITERS: {
   594 						int32 args[1];
   595 						int64 args[1];
   595 						assert(_opt_ptr->units < lengthof(units));
   596 						assert(_opt_ptr->units < lengthof(units));
   596 						args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s;
   597 						args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s;
   597 						buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_volume), args, modifier >> 24, last);
   598 						buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_volume), args, modifier >> 24, last);
   598 						modifier = 0;
   599 						modifier = 0;
   599 						break;
   600 						break;
   611 						}
   612 						}
   612 						break;
   613 						break;
   613 				}
   614 				}
   614 			} break;
   615 			} break;
   615 
   616 
   616 			case SCC_CURRENCY_COMPACT_64: { /* {CURRCOMPACT64} */
       
   617 				/* 64 bit compact currency-unit */
       
   618 				buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), true, last);
       
   619 				break;
       
   620 			}
       
   621 
       
   622 			case SCC_STRING1: { /* {STRING1} */
   617 			case SCC_STRING1: { /* {STRING1} */
   623 				/* String that consumes ONE argument */
   618 				/* String that consumes ONE argument */
   624 				uint str = modifier + GetInt32(&argv);
   619 				uint str = modifier + GetInt32(&argv);
   625 				buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 1), last);
   620 				buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 1), last);
   626 				modifier = 0;
   621 				modifier = 0;
   664 				break;
   659 				break;
   665 			}
   660 			}
   666 
   661 
   667 			case SCC_INDUSTRY_NAME: { /* {INDUSTRY} */
   662 			case SCC_INDUSTRY_NAME: { /* {INDUSTRY} */
   668 				const Industry* i = GetIndustry(GetInt32(&argv));
   663 				const Industry* i = GetIndustry(GetInt32(&argv));
   669 				int32 args[2];
   664 				int64 args[2];
   670 
   665 
   671 				/* industry not valid anymore? */
   666 				/* industry not valid anymore? */
   672 				if (!IsValidIndustry(i)) break;
   667 				if (!IsValidIndustry(i)) break;
   673 
   668 
   674 				/* First print the town name and the industry type name
   669 				/* First print the town name and the industry type name
   679 				modifier = 0;
   674 				modifier = 0;
   680 				break;
   675 				break;
   681 			}
   676 			}
   682 
   677 
   683 			case SCC_VOLUME: { // {VOLUME}
   678 			case SCC_VOLUME: { // {VOLUME}
   684 				int32 args[1];
   679 				int64 args[1];
   685 				assert(_opt_ptr->units < lengthof(units));
   680 				assert(_opt_ptr->units < lengthof(units));
   686 				args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s;
   681 				args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s;
   687 				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_volume), args, modifier >> 24, last);
   682 				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_volume), args, modifier >> 24, last);
   688 				modifier = 0;
   683 				modifier = 0;
   689 				break;
   684 				break;
   713 				buff = GetStringWithArgs(buff, cargo_str, argv++, last);
   708 				buff = GetStringWithArgs(buff, cargo_str, argv++, last);
   714 				break;
   709 				break;
   715 			}
   710 			}
   716 
   711 
   717 			case SCC_POWER: { // {POWER}
   712 			case SCC_POWER: { // {POWER}
   718 				int32 args[1];
   713 				int64 args[1];
   719 				assert(_opt_ptr->units < lengthof(units));
   714 				assert(_opt_ptr->units < lengthof(units));
   720 				args[0] = GetInt32(&argv) * units[_opt_ptr->units].p_m >> units[_opt_ptr->units].p_s;
   715 				args[0] = GetInt32(&argv) * units[_opt_ptr->units].p_m >> units[_opt_ptr->units].p_s;
   721 				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].power), args, modifier >> 24, last);
   716 				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].power), args, modifier >> 24, last);
   722 				modifier = 0;
   717 				modifier = 0;
   723 				break;
   718 				break;
   724 			}
   719 			}
   725 
   720 
   726 			case SCC_VOLUME_SHORT: { // {VOLUME_S}
   721 			case SCC_VOLUME_SHORT: { // {VOLUME_S}
   727 				int32 args[1];
   722 				int64 args[1];
   728 				assert(_opt_ptr->units < lengthof(units));
   723 				assert(_opt_ptr->units < lengthof(units));
   729 				args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s;
   724 				args[0] = GetInt32(&argv) * units[_opt_ptr->units].v_m >> units[_opt_ptr->units].v_s;
   730 				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_volume), args, modifier >> 24, last);
   725 				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_volume), args, modifier >> 24, last);
   731 				modifier = 0;
   726 				modifier = 0;
   732 				break;
   727 				break;
   733 			}
   728 			}
   734 
   729 
   735 			case SCC_WEIGHT: { // {WEIGHT}
   730 			case SCC_WEIGHT: { // {WEIGHT}
   736 				int32 args[1];
   731 				int64 args[1];
   737 				assert(_opt_ptr->units < lengthof(units));
   732 				assert(_opt_ptr->units < lengthof(units));
   738 				args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s;
   733 				args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s;
   739 				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_weight), args, modifier >> 24, last);
   734 				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].l_weight), args, modifier >> 24, last);
   740 				modifier = 0;
   735 				modifier = 0;
   741 				break;
   736 				break;
   742 			}
   737 			}
   743 
   738 
   744 			case SCC_WEIGHT_SHORT: { // {WEIGHT_S}
   739 			case SCC_WEIGHT_SHORT: { // {WEIGHT_S}
   745 				int32 args[1];
   740 				int64 args[1];
   746 				assert(_opt_ptr->units < lengthof(units));
   741 				assert(_opt_ptr->units < lengthof(units));
   747 				args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s;
   742 				args[0] = GetInt32(&argv) * units[_opt_ptr->units].w_m >> units[_opt_ptr->units].w_s;
   748 				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_weight), args, modifier >> 24, last);
   743 				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].s_weight), args, modifier >> 24, last);
   749 				modifier = 0;
   744 				modifier = 0;
   750 				break;
   745 				break;
   751 			}
   746 			}
   752 
   747 
   753 			case SCC_FORCE: { // {FORCE}
   748 			case SCC_FORCE: { // {FORCE}
   754 				int32 args[1];
   749 				int64 args[1];
   755 				assert(_opt_ptr->units < lengthof(units));
   750 				assert(_opt_ptr->units < lengthof(units));
   756 				args[0] = GetInt32(&argv) * units[_opt_ptr->units].f_m >> units[_opt_ptr->units].f_s;
   751 				args[0] = GetInt32(&argv) * units[_opt_ptr->units].f_m >> units[_opt_ptr->units].f_s;
   757 				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].force), args, modifier >> 24, last);
   752 				buff = FormatString(buff, GetStringPtr(units[_opt_ptr->units].force), args, modifier >> 24, last);
   758 				modifier = 0;
   753 				modifier = 0;
   759 				break;
   754 				break;
   798 			case SCC_NUM: // {NUM}
   793 			case SCC_NUM: // {NUM}
   799 				buff = FormatNoCommaNumber(buff, GetInt32(&argv), last);
   794 				buff = FormatNoCommaNumber(buff, GetInt32(&argv), last);
   800 				break;
   795 				break;
   801 
   796 
   802 			case SCC_CURRENCY: // {CURRENCY}
   797 			case SCC_CURRENCY: // {CURRENCY}
   803 				buff = FormatGenericCurrency(buff, _currency, GetInt32(&argv), false, last);
   798 				buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), false, last);
   804 				break;
   799 				break;
   805 
   800 
   806 			case SCC_WAYPOINT_NAME: { // {WAYPOINT}
   801 			case SCC_WAYPOINT_NAME: { // {WAYPOINT}
   807 				int32 temp[2];
   802 				int64 temp[2];
   808 				Waypoint *wp = GetWaypoint(GetInt32(&argv));
   803 				Waypoint *wp = GetWaypoint(GetInt32(&argv));
   809 				StringID str;
   804 				StringID str;
   810 				if (wp->string != STR_NULL) {
   805 				if (wp->string != STR_NULL) {
   811 					str = wp->string;
   806 					str = wp->string;
   812 				} else {
   807 				} else {
   822 				const Station* st = GetStation(GetInt32(&argv));
   817 				const Station* st = GetStation(GetInt32(&argv));
   823 
   818 
   824 				if (!st->IsValid()) { // station doesn't exist anymore
   819 				if (!st->IsValid()) { // station doesn't exist anymore
   825 					buff = GetStringWithArgs(buff, STR_UNKNOWN_DESTINATION, NULL, last);
   820 					buff = GetStringWithArgs(buff, STR_UNKNOWN_DESTINATION, NULL, last);
   826 				} else {
   821 				} else {
   827 					int32 temp[2];
   822 					int64 temp[3];
   828 					temp[0] = st->town->townnametype;
   823 					temp[0] = STR_TOWN;
   829 					temp[1] = st->town->townnameparts;
   824 					temp[1] = st->town->index;
       
   825 					temp[2] = st->index;
   830 					buff = GetStringWithArgs(buff, st->string_id, temp, last);
   826 					buff = GetStringWithArgs(buff, st->string_id, temp, last);
   831 				}
   827 				}
   832 				break;
   828 				break;
   833 			}
   829 			}
   834 
   830 
   835 			case SCC_TOWN_NAME: { // {TOWN}
   831 			case SCC_TOWN_NAME: { // {TOWN}
   836 				const Town* t = GetTown(GetInt32(&argv));
   832 				const Town* t = GetTown(GetInt32(&argv));
   837 				int32 temp[1];
   833 				int64 temp[1];
   838 
   834 
   839 				assert(IsValidTown(t));
   835 				assert(IsValidTown(t));
   840 
   836 
   841 				temp[0] = t->townnameparts;
   837 				temp[0] = t->townnameparts;
   842 				buff = GetStringWithArgs(buff, t->townnametype, temp, last);
   838 				uint32 grfid = t->townnamegrfid;
       
   839 
       
   840 				if (grfid == 0) {
       
   841 					/* Original town name */
       
   842 					buff = GetStringWithArgs(buff, t->townnametype, temp, last);
       
   843 				} else {
       
   844 					/* Newgrf town name */
       
   845 					if (GetGRFTownName(grfid) != NULL) {
       
   846 						/* The grf is loaded */
       
   847 						buff = GRFTownNameGenerate(buff, t->townnamegrfid, t->townnametype, t->townnameparts, last);
       
   848 					} else {
       
   849 						/* Fallback to english original */
       
   850 						buff = GetStringWithArgs(buff, SPECSTR_TOWNNAME_ENGLISH, temp, last);
       
   851 					}
       
   852 				}
   843 				break;
   853 				break;
   844 			}
   854 			}
   845 
   855 
   846 			case SCC_GROUP_NAME: { // {GROUP}
   856 			case SCC_GROUP_NAME: { // {GROUP}
   847 				const Group *g = GetGroup(GetInt32(&argv));
   857 				const Group *g = GetGroup(GetInt32(&argv));
   848 				int32 args[1];
   858 				int64 args[1];
   849 
   859 
   850 				assert(IsValidGroup(g));
   860 				assert(IsValidGroup(g));
   851 
   861 
   852 				args[0] = g->index;
   862 				args[0] = g->index;
   853 				buff = GetStringWithArgs(buff, (g->string_id == STR_SV_GROUP_NAME) ? (StringID)STR_GROUP_NAME_FORMAT : g->string_id, args, last);
   863 				buff = GetStringWithArgs(buff, IsCustomName(g->string_id) ? g->string_id : (StringID)STR_GROUP_NAME_FORMAT, args, last);
   854 
   864 
   855 				break;
   865 				break;
   856 			}
   866 			}
   857 
   867 
   858 			case SCC_CURRENCY_64: { // {CURRENCY64}
   868 			case SCC_ENGINE_NAME: { // {ENGINE}
   859 				buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), false, last);
   869 				EngineID engine = (EngineID)GetInt32(&argv);
       
   870 
       
   871 				buff = GetString(buff, GetCustomEngineName(engine), last);
       
   872 				break;
       
   873 			}
       
   874 
       
   875 			case SCC_VEHICLE_NAME: { // {VEHICLE}
       
   876 				const Vehicle *v = GetVehicle(GetInt32(&argv));
       
   877 
       
   878 				int64 args[1];
       
   879 				args[0] = v->unitnumber;
       
   880 
       
   881 				buff = GetStringWithArgs(buff, v->string_id, args, last);
       
   882 				break;
       
   883 			}
       
   884 
       
   885 			case SCC_SIGN_NAME: { // {SIGN}
       
   886 				const Sign *si = GetSign(GetInt32(&argv));
       
   887 				buff = GetString(buff, si->str, last);
       
   888 				break;
       
   889 			}
       
   890 
       
   891 			case SCC_COMPANY_NAME: { // {COMPANY}
       
   892 				const Player *p = GetPlayer((PlayerID)GetInt32(&argv));
       
   893 				int64 args[1];
       
   894 				args[0] = p->name_2;
       
   895 				buff = GetStringWithArgs(buff, p->name_1, args, last);
       
   896 				break;
       
   897 			}
       
   898 
       
   899 			case SCC_COMPANY_NUM: { // {COMPANYNUM}
       
   900 				PlayerID player = (PlayerID)GetInt32(&argv);
       
   901 
       
   902 				/* Nothing is added for AI or inactive players */
       
   903 				if (IsHumanPlayer(player) && IsValidPlayer(player)) {
       
   904 					int64 args[1];
       
   905 					args[0] = player + 1;
       
   906 					buff = GetStringWithArgs(buff, STR_7002_PLAYER, args, last);
       
   907 				}
       
   908 				break;
       
   909 			}
       
   910 
       
   911 			case SCC_PLAYER_NAME: { // {PLAYERNAME}
       
   912 				const Player *p = GetPlayer((PlayerID)GetInt32(&argv));
       
   913 				int64 args[1];
       
   914 				args[0] = p->president_name_2;
       
   915 				buff = GetStringWithArgs(buff, p->president_name_1, args, last);
   860 				break;
   916 				break;
   861 			}
   917 			}
   862 
   918 
   863 			case SCC_SETCASE: { // {SETCASE}
   919 			case SCC_SETCASE: { // {SETCASE}
   864 				/* This is a pseudo command, it's outputted when someone does {STRING.ack}
   920 				/* This is a pseudo command, it's outputted when someone does {STRING.ack}
  1027 	buff = strecpy(buff, base[num * GB(x, 16, 8) >> 8], last);
  1083 	buff = strecpy(buff, base[num * GB(x, 16, 8) >> 8], last);
  1028 
  1084 
  1029 	return buff;
  1085 	return buff;
  1030 }
  1086 }
  1031 
  1087 
  1032 static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv, const char* last)
  1088 static char *GetSpecialPlayerNameString(char *buff, int ind, const int64 *argv, const char* last)
  1033 {
  1089 {
  1034 	switch (ind) {
  1090 	switch (ind) {
  1035 		case 1: // not used
  1091 		case 1: // not used
  1036 			return strecpy(buff, _silly_company_names[GetInt32(&argv) & 0xFFFF], last);
  1092 			return strecpy(buff, _silly_company_names[GetInt32(&argv) & 0xFFFF], last);
  1037 
  1093