strings.c
changeset 193 0a7025304867
parent 64 93656f16d50a
child 233 dd177a8c9f19
equal deleted inserted replaced
192:614bba52258d 193:0a7025304867
    66 	{ 480, ',', CF_TOEURO_2002, "GRD ", "" },
    66 	{ 480, ',', CF_TOEURO_2002, "GRD ", "" },
    67 	{ 2,   ',', 0,              "CHF ", "" },
    67 	{ 2,   ',', 0,              "CHF ", "" },
    68 	{ 3,   ',', CF_TOEURO_2002, "NLG ", "" },
    68 	{ 3,   ',', CF_TOEURO_2002, "NLG ", "" },
    69 	{ 2730,',', CF_TOEURO_2002, "ITL ", "" },
    69 	{ 2730,',', CF_TOEURO_2002, "ITL ", "" },
    70 	{ 13,  '.', 0,              "",     " kr" },
    70 	{ 13,  '.', 0,              "",     " kr" },
    71 	{ 5,   ' ', 0,              "",     " rur" },	
    71 	{ 5,   ' ', 0,              "",     " rur" },
    72 	{ 50,  ',', 0,              "",     " Kc" },
    72 	{ 50,  ',', 0,              "",     " Kc" },
    73 	{ 130, '.', 0,              "",     " kr" },
    73 	{ 130, '.', 0,              "",     " kr" },
    74 	{ 11,  '.', 0,              "",     " kr" },
    74 	{ 11,  '.', 0,              "",     " kr" },
    75 	{ 2,   ',', CF_ISEURO,      "€",    "" },
    75 	{ 2,   ',', CF_ISEURO,      "€",    "" },
    76 };
    76 };
   169 		error("!String 0x%X is invalid. Probably because an old version of the .lng file.\n", string);
   169 		error("!String 0x%X is invalid. Probably because an old version of the .lng file.\n", string);
   170 
   170 
   171 	return DecodeString(buffr, GetStringPtr(string));
   171 	return DecodeString(buffr, GetStringPtr(string));
   172 }
   172 }
   173 
   173 
   174 void InjectDparam(int amount) 
   174 void InjectDparam(int amount)
   175 {
   175 {
   176 	memmove(_decode_parameters + amount, _decode_parameters, sizeof(_decode_parameters) - amount * sizeof(uint32)); 
   176 	memmove(_decode_parameters + amount, _decode_parameters, sizeof(_decode_parameters) - amount * sizeof(uint32));
   177 }
   177 }
   178 
   178 
   179 
   179 
   180 int32 GetParamInt32()
   180 int32 GetParamInt32()
   181 {
   181 {
   299 	YearMonthDay ymd;
   299 	YearMonthDay ymd;
   300 
   300 
   301 	ConvertDayToYMD(&ymd, number);
   301 	ConvertDayToYMD(&ymd, number);
   302 
   302 
   303 	for(src = GetStringPtr(ymd.day+STR_01AC_1ST-1); (*buff++=*src++) != 0;) {}
   303 	for(src = GetStringPtr(ymd.day+STR_01AC_1ST-1); (*buff++=*src++) != 0;) {}
   304 	
   304 
   305 	buff[-1] = ' ';
   305 	buff[-1] = ' ';
   306 	memcpy(buff, GetStringPtr(STR_0162_JAN + ymd.month), 4);
   306 	memcpy(buff, GetStringPtr(STR_0162_JAN + ymd.month), 4);
   307 	buff[3] = ' ';
   307 	buff[3] = ' ';
   308 
   308 
   309 	return FormatNoCommaNumber(buff+4, ymd.year + 1920);
   309 	return FormatNoCommaNumber(buff+4, ymd.year + 1920);
   336 	// multiply by exchange rate
   336 	// multiply by exchange rate
   337 	number *= spec->rate;
   337 	number *= spec->rate;
   338 
   338 
   339 	// convert from negative
   339 	// convert from negative
   340 	if (number < 0) { *buff++ = '-'; number = -number; }
   340 	if (number < 0) { *buff++ = '-'; number = -number; }
   341 	
   341 
   342 	// add pre part
   342 	// add pre part
   343 	s = spec->pre;
   343 	s = spec->pre;
   344 	while (s != spec->pre + lengthof(spec->pre) && (c=*s++)) *buff++ = c;
   344 	while (s != spec->pre + lengthof(spec->pre) && (c=*s++)) *buff++ = c;
   345 
   345 
   346 	// for huge numbers, compact the number into k or M
   346 	// for huge numbers, compact the number into k or M
   350 			number = (number + 500000) / 1000000;
   350 			number = (number + 500000) / 1000000;
   351 			compact = 'M';
   351 			compact = 'M';
   352 		} else if (number >= 1000000) {
   352 		} else if (number >= 1000000) {
   353 			number = (number + 500) / 1000;
   353 			number = (number + 500) / 1000;
   354 			compact = 'k';
   354 			compact = 'k';
   355 		}	
   355 		}
   356 	}
   356 	}
   357 	
   357 
   358 	// convert to ascii number and add commas
   358 	// convert to ascii number and add commas
   359 	p = buf;
   359 	p = buf;
   360 	j = 4;
   360 	j = 4;
   361 	do { 
   361 	do {
   362 		if (--j == 0) { *p++ = spec->separator; j = 3; }
   362 		if (--j == 0) { *p++ = spec->separator; j = 3; }
   363 		*p++ = '0' + number % 10;
   363 		*p++ = '0' + number % 10;
   364 	} while (number /= 10);
   364 	} while (number /= 10);
   365 	do *buff++ = *--p; while (p != buf);
   365 	do *buff++ = *--p; while (p != buf);
   366 
   366 
   425 				memcpy(buff, " mph", 4);
   425 				memcpy(buff, " mph", 4);
   426 				buff += 4;
   426 				buff += 4;
   427 			}
   427 			}
   428 			break;
   428 			break;
   429 		}
   429 		}
   430 		
   430 
   431 		// 0x85 is used as escape character.. 
   431 		// 0x85 is used as escape character..
   432 		case 0x85:
   432 		case 0x85:
   433 			switch(*str++) {
   433 			switch(*str++) {
   434 			case 0:
   434 			case 0:
   435 				buff = FormatGenericCurrency(buff, &_currency_specs[_opt.currency], GetParamInt32(), true);
   435 				buff = FormatGenericCurrency(buff, &_currency_specs[_opt.currency], GetParamInt32(), true);
   436 				break;
   436 				break;
   451 				uint16 cargo_str = _cargo_string_list[_opt.landscape][(byte)GetParamInt8()];
   451 				uint16 cargo_str = _cargo_string_list[_opt.landscape][(byte)GetParamInt8()];
   452 				uint16 multiplier = (cargo_str == STR_LITERS) ? 1000 : 1;
   452 				uint16 multiplier = (cargo_str == STR_LITERS) ? 1000 : 1;
   453 				// liquid type of cargo is multiplied by 100 to get correct amount
   453 				// liquid type of cargo is multiplied by 100 to get correct amount
   454 				buff = FormatCommaNumber(buff, GetParamInt16() * multiplier );
   454 				buff = FormatCommaNumber(buff, GetParamInt16() * multiplier );
   455 				s = GetStringPtr(cargo_str);
   455 				s = GetStringPtr(cargo_str);
   456 				
   456 
   457 				memcpy(buff++, " ", 1);
   457 				memcpy(buff++, " ", 1);
   458 				while (*s) *buff++ = *s++;
   458 				while (*s) *buff++ = *s++;
   459 				break;
   459 				break;
   460 			}
   460 			}
   461 
   461 
   474 			memcpy(buff++, " ", 1);
   474 			memcpy(buff++, " ", 1);
   475 			s = GetStringPtr(STR_LITERS);
   475 			s = GetStringPtr(STR_LITERS);
   476 			while (*s) *buff++ = *s++;
   476 			while (*s) *buff++ = *s++;
   477 			break;
   477 			break;
   478 		}
   478 		}
   479 		
   479 
   480 		case 0x88: // {STRING}
   480 		case 0x88: // {STRING}
   481 			buff = GetString(buff, (uint16)GetParamUint16());
   481 			buff = GetString(buff, (uint16)GetParamUint16());
   482 			break;
   482 			break;
   483 
   483 
   484 		case 0x99: { // {CARGO}
   484 		case 0x99: { // {CARGO}
   513 			buff = GetString(buff, t->townnametype);
   513 			buff = GetString(buff, t->townnametype);
   514 			break;
   514 			break;
   515 		}
   515 		}
   516 
   516 
   517 		case 0x9C: { // {CURRENCY64}
   517 		case 0x9C: { // {CURRENCY64}
   518 			buff = FormatGenericCurrency(buff, &_currency_specs[_opt.currency], GetParamInt64(), false);	
   518 			buff = FormatGenericCurrency(buff, &_currency_specs[_opt.currency], GetParamInt64(), false);
   519 			break;
   519 			break;
   520 		}
   520 		}
   521 
   521 
   522 		case 0x9D: { // {CHECKPOINT}
   522 		case 0x9D: { // {CHECKPOINT}
   523 			Checkpoint *cp = &_checkpoints[GET_DPARAM16(0)];
   523 			Checkpoint *cp = &_checkpoints[GET_DPARAM16(0)];
   565 	return buff;
   565 	return buff;
   566 }
   566 }
   567 
   567 
   568 static byte *GetSpecialTownNameString(byte *buff, int ind) {
   568 static byte *GetSpecialTownNameString(byte *buff, int ind) {
   569 	uint32 x = GetParamInt32();
   569 	uint32 x = GetParamInt32();
   570 	
   570 
   571 	_town_name_generators[ind](buff, x);
   571 	_town_name_generators[ind](buff, x);
   572 
   572 
   573 	while (*buff != 0) buff++;
   573 	while (*buff != 0) buff++;
   574 	return buff;
   574 	return buff;
   575 }
   575 }
   667 
   667 
   668 	i = ((sizeof(_initial_name_letters) + 35) * (byte)(x >> 8)) >> 8;
   668 	i = ((sizeof(_initial_name_letters) + 35) * (byte)(x >> 8)) >> 8;
   669 	if (i < sizeof(_initial_name_letters)) {
   669 	if (i < sizeof(_initial_name_letters)) {
   670 		buff[0] = _initial_name_letters[i];
   670 		buff[0] = _initial_name_letters[i];
   671 		buff[1] = '.';
   671 		buff[1] = '.';
   672 		buff += 2;		
   672 		buff += 2;
   673 	}
   673 	}
   674 
   674 
   675 	base = 0;
   675 	base = 0;
   676 	num = 29;
   676 	num = 29;
   677 	if (_opt.landscape == LT_CANDY) {
   677 	if (_opt.landscape == LT_CANDY) {
   710 };
   710 };
   711 
   711 
   712 static byte *GetSpecialPlayerNameString(byte *buff, int ind)
   712 static byte *GetSpecialPlayerNameString(byte *buff, int ind)
   713 {
   713 {
   714 	switch(ind) {
   714 	switch(ind) {
   715 	
   715 
   716 	// not used
   716 	// not used
   717 	case 1: {
   717 	case 1: {
   718 		int i = GetParamInt32() & 0xFFFF;
   718 		int i = GetParamInt32() & 0xFFFF;
   719 		return str_cat(buff, _silly_company_names[i]);
   719 		return str_cat(buff, _silly_company_names[i]);
   720 	}
   720 	}
   787 		char *lang = str_fmt("%s%s", _path.lang_dir, _dynlang.ent[lang_index].file);
   787 		char *lang = str_fmt("%s%s", _path.lang_dir, _dynlang.ent[lang_index].file);
   788 		lang_pack = ReadFileToMem(lang, &len, 100000);
   788 		lang_pack = ReadFileToMem(lang, &len, 100000);
   789 		free(lang);
   789 		free(lang);
   790 	}
   790 	}
   791 	if (lang_pack == NULL) return false;
   791 	if (lang_pack == NULL) return false;
   792 	if (len < sizeof(LanguagePackHeader) || 
   792 	if (len < sizeof(LanguagePackHeader) ||
   793 			HDR->ident != TO_LE32(LANGUAGE_PACK_IDENT) ||
   793 			HDR->ident != TO_LE32(LANGUAGE_PACK_IDENT) ||
   794 			HDR->version != TO_LE32(LANGUAGE_PACK_VERSION)) {
   794 			HDR->version != TO_LE32(LANGUAGE_PACK_VERSION)) {
   795 		free(lang_pack);
   795 		free(lang_pack);
   796 		return false;
   796 		return false;
   797 	}
   797 	}
   798 #undef HDR
   798 #undef HDR
   799 	
   799 
   800 #if defined(TTD_BIG_ENDIAN)
   800 #if defined(TTD_BIG_ENDIAN)
   801 	for(i=0; i!=32; i++) {
   801 	for(i=0; i!=32; i++) {
   802 		((LanguagePackHeader*)lang_pack)->offsets[i] = READ_LE_UINT16(&((LanguagePackHeader*)lang_pack)->offsets[i]);
   802 		((LanguagePackHeader*)lang_pack)->offsets[i] = READ_LE_UINT16(&((LanguagePackHeader*)lang_pack)->offsets[i]);
   803 	}
   803 	}
   804 #endif
   804 #endif
   853 	// go through the language files and make sure that they are valid.
   853 	// go through the language files and make sure that they are valid.
   854 	for(i=m=0; i!=n; i++) {
   854 	for(i=m=0; i!=n; i++) {
   855 		char *s = str_fmt("%s%s", _path.lang_dir, files[i]);
   855 		char *s = str_fmt("%s%s", _path.lang_dir, files[i]);
   856 		in = fopen(s, "rb");
   856 		in = fopen(s, "rb");
   857 		free(s);
   857 		free(s);
   858 		if (!in || 
   858 		if (!in ||
   859 				(j = fread(&hdr, sizeof(hdr), 1, in), fclose(in), j) != 1 ||
   859 				(j = fread(&hdr, sizeof(hdr), 1, in), fclose(in), j) != 1 ||
   860 				hdr.ident != TO_LE32(LANGUAGE_PACK_IDENT) ||
   860 				hdr.ident != TO_LE32(LANGUAGE_PACK_IDENT) ||
   861 				hdr.version != TO_LE32(LANGUAGE_PACK_VERSION)) {
   861 				hdr.version != TO_LE32(LANGUAGE_PACK_VERSION)) {
   862 			free(files[i]);
   862 			free(files[i]);
   863 			continue;
   863 			continue;
   864 		}
   864 		}
   865 
   865 
   866 		dl->ent[m].file = files[i];
   866 		dl->ent[m].file = files[i];
   867 		dl->ent[m].name = strdup(hdr.name);
   867 		dl->ent[m].name = strdup(hdr.name);
   868 		
   868 
   869 		if (!strcmp(hdr.name, "English")) def = m;
   869 		if (!strcmp(hdr.name, "English")) def = m;
   870 
   870 
   871 		m++;
   871 		m++;
   872 	}
   872 	}
   873 
   873 
   874 	if (m == 0)
   874 	if (m == 0)
   875 		error(n == 0 ? "No available language packs" : "Invalid version of language packs");
   875 		error(n == 0 ? "No available language packs" : "Invalid version of language packs");
   876 		
   876 
   877 	dl->num = m;
   877 	dl->num = m;
   878 	for(i=0; i!=dl->num; i++)
   878 	for(i=0; i!=dl->num; i++)
   879 		dl->dropdown[i] = SPECSTR_LANGUAGE_START + i;
   879 		dl->dropdown[i] = SPECSTR_LANGUAGE_START + i;
   880 	dl->dropdown[i] = INVALID_STRING_ID;
   880 	dl->dropdown[i] = INVALID_STRING_ID;
   881 
   881