strings.c
changeset 1704 6054160187df
parent 1625 c2849df304da
child 1853 a7b4892162f6
equal deleted inserted replaced
1703:7e1cdd971cb2 1704:6054160187df
   341 	return buff;
   341 	return buff;
   342 }
   342 }
   343 
   343 
   344 uint GetCurrentCurrencyRate(void)
   344 uint GetCurrentCurrencyRate(void)
   345 {
   345 {
   346 	return _currency_specs[_opt.currency].rate;
   346 	return _currency_specs[_opt_ptr->currency].rate;
   347 }
   347 }
   348 
   348 
   349 static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 number, bool compact)
   349 static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, int64 number, bool compact)
   350 {
   350 {
   351 	const char *s;
   351 	const char *s;
   425 			break;
   425 			break;
   426 		case 0x7E: // {NUMU16}
   426 		case 0x7E: // {NUMU16}
   427 			buff = FormatNoCommaNumber(buff, GetParamInt16());
   427 			buff = FormatNoCommaNumber(buff, GetParamInt16());
   428 			break;
   428 			break;
   429 		case 0x7F: // {CURRENCY}
   429 		case 0x7F: // {CURRENCY}
   430 			buff = FormatGenericCurrency(buff, &_currency_specs[_opt.currency], GetParamInt32(), false);
   430 			buff = FormatGenericCurrency(buff, &_currency_specs[_opt_ptr->currency], GetParamInt32(), false);
   431 			break;
   431 			break;
   432 		// 0x80 is reserved for EURO
   432 		// 0x80 is reserved for EURO
   433 		case 0x81: // {STRINL}
   433 		case 0x81: // {STRINL}
   434 			str += 2;
   434 			str += 2;
   435 			buff = GetString(buff, READ_LE_UINT16(str-2));
   435 			buff = GetString(buff, READ_LE_UINT16(str-2));
   440 		case 0x83: // {DATE_SHORT}
   440 		case 0x83: // {DATE_SHORT}
   441 			buff = FormatMonthAndYear(buff, GetParamUint16());
   441 			buff = FormatMonthAndYear(buff, GetParamUint16());
   442 			break;
   442 			break;
   443 		case 0x84: {// {VELOCITY}
   443 		case 0x84: {// {VELOCITY}
   444 			int value = GetParamInt16();
   444 			int value = GetParamInt16();
   445 			if (_opt.kilometers) value = value * 1648 >> 10;
   445 			if (_opt_ptr->kilometers) value = value * 1648 >> 10;
   446 			buff = FormatCommaNumber(buff, value);
   446 			buff = FormatCommaNumber(buff, value);
   447 			if (_opt.kilometers) {
   447 			if (_opt_ptr->kilometers) {
   448 				memcpy(buff, " km/h", 5);
   448 				memcpy(buff, " km/h", 5);
   449 				buff += 5;
   449 				buff += 5;
   450 			} else {
   450 			} else {
   451 				memcpy(buff, " mph", 4);
   451 				memcpy(buff, " mph", 4);
   452 				buff += 4;
   452 				buff += 4;
   456 
   456 
   457 		// 0x85 is used as escape character..
   457 		// 0x85 is used as escape character..
   458 		case 0x85:
   458 		case 0x85:
   459 			switch (*str++) {
   459 			switch (*str++) {
   460 			case 0: /* {CURRCOMPACT} */
   460 			case 0: /* {CURRCOMPACT} */
   461 				buff = FormatGenericCurrency(buff, &_currency_specs[_opt.currency], GetParamInt32(), true);
   461 				buff = FormatGenericCurrency(buff, &_currency_specs[_opt_ptr->currency], GetParamInt32(), true);
   462 				break;
   462 				break;
   463 			case 1: /* {INT32} */
   463 			case 1: /* {INT32} */
   464 				buff = FormatNoCommaNumber(buff, GetParamInt32());
   464 				buff = FormatNoCommaNumber(buff, GetParamInt32());
   465 				break;
   465 				break;
   466 			case 2: /* {REV} */
   466 			case 2: /* {REV} */
   469 			case 3: { /* {SHORTCARGO} */
   469 			case 3: { /* {SHORTCARGO} */
   470 				// Short description of cargotypes. Layout:
   470 				// Short description of cargotypes. Layout:
   471 				// 8-bit = cargo type
   471 				// 8-bit = cargo type
   472 				// 16-bit = cargo count
   472 				// 16-bit = cargo count
   473 				const char *s;
   473 				const char *s;
   474 				StringID cargo_str = _cargo_string_list[_opt.landscape][(byte)GetParamInt8()];
   474 				StringID cargo_str = _cargo_string_list[_opt_ptr->landscape][(byte)GetParamInt8()];
   475 				uint16 multiplier = (cargo_str == STR_LITERS) ? 1000 : 1;
   475 				uint16 multiplier = (cargo_str == STR_LITERS) ? 1000 : 1;
   476 				// liquid type of cargo is multiplied by 100 to get correct amount
   476 				// liquid type of cargo is multiplied by 100 to get correct amount
   477 				buff = FormatCommaNumber(buff, GetParamInt16() * multiplier);
   477 				buff = FormatCommaNumber(buff, GetParamInt16() * multiplier);
   478 				s = GetStringPtr(cargo_str);
   478 				s = GetStringPtr(cargo_str);
   479 
   479 
   480 				memcpy(buff++, " ", 1);
   480 				memcpy(buff++, " ", 1);
   481 				while (*s) *buff++ = *s++;
   481 				while (*s) *buff++ = *s++;
   482 			} break;
   482 			} break;
   483 			case 4: /* {CURRCOMPACT64} */
   483 			case 4: /* {CURRCOMPACT64} */
   484 				// 64 bit compact currency-unit
   484 				// 64 bit compact currency-unit
   485 				buff = FormatGenericCurrency(buff, &_currency_specs[_opt.currency], GetParamInt64(), true);
   485 				buff = FormatGenericCurrency(buff, &_currency_specs[_opt_ptr->currency], GetParamInt64(), true);
   486 				break;
   486 				break;
   487 
   487 
   488 			default:
   488 			default:
   489 				error("!invalid escape sequence in string");
   489 				error("!invalid escape sequence in string");
   490 			}
   490 			}
   539 			buff = GetString(buff, t->townnametype);
   539 			buff = GetString(buff, t->townnametype);
   540 			break;
   540 			break;
   541 		}
   541 		}
   542 
   542 
   543 		case 0x9C: { // {CURRENCY64}
   543 		case 0x9C: { // {CURRENCY64}
   544 			buff = FormatGenericCurrency(buff, &_currency_specs[_opt.currency], GetParamInt64(), false);
   544 			buff = FormatGenericCurrency(buff, &_currency_specs[_opt_ptr->currency], GetParamInt64(), false);
   545 			break;
   545 			break;
   546 		}
   546 		}
   547 
   547 
   548 		case 0x9D: { // {WAYPOINT}
   548 		case 0x9D: { // {WAYPOINT}
   549 			Waypoint *wp = GetWaypoint(GetDParam(0));
   549 			Waypoint *wp = GetWaypoint(GetDParam(0));
   677 	uint32 x = GetParamInt32();
   677 	uint32 x = GetParamInt32();
   678 	uint base,num;
   678 	uint base,num;
   679 
   679 
   680 	base = 0;
   680 	base = 0;
   681 	num = 29;
   681 	num = 29;
   682 	if (_opt.landscape == LT_CANDY) {
   682 	if (_opt_ptr->landscape == LT_CANDY) {
   683 		base = num;
   683 		base = num;
   684 		num = 12;
   684 		num = 12;
   685 	}
   685 	}
   686 
   686 
   687 	buff = str_cat(buff, _surname_list[base + ((num * (byte)(x >> 16)) >> 8)]);
   687 	buff = str_cat(buff, _surname_list[base + ((num * (byte)(x >> 16)) >> 8)]);
   708 		buff += 3;
   708 		buff += 3;
   709 	}
   709 	}
   710 
   710 
   711 	base = 0;
   711 	base = 0;
   712 	num = 29;
   712 	num = 29;
   713 	if (_opt.landscape == LT_CANDY) {
   713 	if (_opt_ptr->landscape == LT_CANDY) {
   714 		base = num;
   714 		base = num;
   715 		num = 12;
   715 		num = 12;
   716 	}
   716 	}
   717 
   717 
   718 	buff = str_cat(buff, _surname_list[base + ((num * (byte)(x >> 16)) >> 8)]);
   718 	buff = str_cat(buff, _surname_list[base + ((num * (byte)(x >> 16)) >> 8)]);