strings.c
changeset 1853 a7b4892162f6
parent 1704 6054160187df
child 1891 862800791170
equal deleted inserted replaced
1852:a7f9f961c5e1 1853:a7b4892162f6
   122 		STR_LITERS,
   122 		STR_LITERS,
   123 		STR_NOTHING
   123 		STR_NOTHING
   124 	}
   124 	}
   125 };
   125 };
   126 
   126 
   127 static char *str_cat(char *dst, const char *src)
       
   128 {
       
   129 	while ((*dst++ = *src++) != '\0') {}
       
   130 	return dst - 1;
       
   131 }
       
   132 
   127 
   133 static const char *GetStringPtr(StringID string)
   128 static const char *GetStringPtr(StringID string)
   134 {
   129 {
   135 	return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)];
   130 	return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)];
   136 }
   131 }
   462 				break;
   457 				break;
   463 			case 1: /* {INT32} */
   458 			case 1: /* {INT32} */
   464 				buff = FormatNoCommaNumber(buff, GetParamInt32());
   459 				buff = FormatNoCommaNumber(buff, GetParamInt32());
   465 				break;
   460 				break;
   466 			case 2: /* {REV} */
   461 			case 2: /* {REV} */
   467 				buff = str_cat(buff, _openttd_revision);
   462 				buff = strecpy(buff, _openttd_revision, NULL);
   468 				break;
   463 				break;
   469 			case 3: { /* {SHORTCARGO} */
   464 			case 3: { /* {SHORTCARGO} */
   470 				// Short description of cargotypes. Layout:
   465 				// Short description of cargotypes. Layout:
   471 				// 8-bit = cargo type
   466 				// 8-bit = cargo type
   472 				// 16-bit = cargo count
   467 				// 16-bit = cargo count
   473 				const char *s;
       
   474 				StringID cargo_str = _cargo_string_list[_opt_ptr->landscape][(byte)GetParamInt8()];
   468 				StringID cargo_str = _cargo_string_list[_opt_ptr->landscape][(byte)GetParamInt8()];
   475 				uint16 multiplier = (cargo_str == STR_LITERS) ? 1000 : 1;
   469 				uint16 multiplier = (cargo_str == STR_LITERS) ? 1000 : 1;
   476 				// liquid type of cargo is multiplied by 100 to get correct amount
   470 				// liquid type of cargo is multiplied by 100 to get correct amount
   477 				buff = FormatCommaNumber(buff, GetParamInt16() * multiplier);
   471 				buff = FormatCommaNumber(buff, GetParamInt16() * multiplier);
   478 				s = GetStringPtr(cargo_str);
   472 				buff = strecpy(buff, " ", NULL);
   479 
   473 				buff = strecpy(buff, GetStringPtr(cargo_str), NULL);
   480 				memcpy(buff++, " ", 1);
       
   481 				while (*s) *buff++ = *s++;
       
   482 			} break;
   474 			} break;
   483 			case 4: /* {CURRCOMPACT64} */
   475 			case 4: /* {CURRCOMPACT64} */
   484 				// 64 bit compact currency-unit
   476 				// 64 bit compact currency-unit
   485 				buff = FormatGenericCurrency(buff, &_currency_specs[_opt_ptr->currency], GetParamInt64(), true);
   477 				buff = FormatGenericCurrency(buff, &_currency_specs[_opt_ptr->currency], GetParamInt64(), true);
   486 				break;
   478 				break;
   492 
   484 
   493 		case 0x86: // {SKIP}
   485 		case 0x86: // {SKIP}
   494 			GetParamInt16();
   486 			GetParamInt16();
   495 			//assert(0);
   487 			//assert(0);
   496 			break;
   488 			break;
   497 		case 0x87: { // {VOLUME}
   489 		case 0x87: // {VOLUME}
   498 			const char *s;
       
   499 			buff = FormatCommaNumber(buff, GetParamInt16() * 1000);
   490 			buff = FormatCommaNumber(buff, GetParamInt16() * 1000);
   500 			memcpy(buff++, " ", 1);
   491 			buff = strecpy(buff, " ", NULL);
   501 			s = GetStringPtr(STR_LITERS);
   492 			buff = strecpy(buff, GetStringPtr(STR_LITERS), NULL);
   502 			while (*s) *buff++ = *s++;
   493 			break;
   503 			break;
       
   504 		}
       
   505 
   494 
   506 		case 0x88: // {STRING}
   495 		case 0x88: // {STRING}
   507 			buff = GetString(buff, (uint16)GetParamUint16());
   496 			buff = GetString(buff, (uint16)GetParamUint16());
   508 			break;
   497 			break;
   509 
   498 
   682 	if (_opt_ptr->landscape == LT_CANDY) {
   671 	if (_opt_ptr->landscape == LT_CANDY) {
   683 		base = num;
   672 		base = num;
   684 		num = 12;
   673 		num = 12;
   685 	}
   674 	}
   686 
   675 
   687 	buff = str_cat(buff, _surname_list[base + ((num * (byte)(x >> 16)) >> 8)]);
   676 	buff = strecpy(buff, _surname_list[base + (num * GB(x, 16, 8) >> 8)], NULL);
   688 	buff = str_cat(buff, " & Co.");
   677 	buff = strecpy(buff, " & Co.", NULL);
   689 
   678 
   690 	return buff;
   679 	return buff;
   691 }
   680 }
   692 
   681 
   693 static char *GenPlayerName_4(char *buff)
   682 static char *GenPlayerName_4(char *buff)
   713 	if (_opt_ptr->landscape == LT_CANDY) {
   702 	if (_opt_ptr->landscape == LT_CANDY) {
   714 		base = num;
   703 		base = num;
   715 		num = 12;
   704 		num = 12;
   716 	}
   705 	}
   717 
   706 
   718 	buff = str_cat(buff, _surname_list[base + ((num * (byte)(x >> 16)) >> 8)]);
   707 	buff = strecpy(buff, _surname_list[base + (num * GB(x, 16, 8) >> 8)], NULL);
   719 
   708 
   720 	return buff;
   709 	return buff;
   721 }
   710 }
   722 
   711 
   723 static const char * const _song_names[] = {
   712 static const char * const _song_names[] = {
   747 
   736 
   748 static char *GetSpecialPlayerNameString(char *buff, int ind)
   737 static char *GetSpecialPlayerNameString(char *buff, int ind)
   749 {
   738 {
   750 	switch (ind) {
   739 	switch (ind) {
   751 		case 1: // not used
   740 		case 1: // not used
   752 			return str_cat(buff, _silly_company_names[GetParamInt32() & 0xFFFF]);
   741 			return strecpy(buff, _silly_company_names[GetParamInt32() & 0xFFFF], NULL);
   753 
   742 
   754 		case 2: // used for Foobar & Co company names
   743 		case 2: // used for Foobar & Co company names
   755 			return GenAndCoName(buff);
   744 			return GenAndCoName(buff);
   756 
   745 
   757 		case 3: // President name
   746 		case 3: // President name
   758 			return GenPlayerName_4(buff);
   747 			return GenPlayerName_4(buff);
   759 
   748 
   760 		case 4: // song names
   749 		case 4: // song names
   761 			return str_cat(buff, _song_names[GetParamUint16() - 1]);
   750 			return strecpy(buff, _song_names[GetParamUint16() - 1], NULL);
   762 	}
   751 	}
   763 
   752 
   764 	// town name?
   753 	// town name?
   765 	if (IS_INT_INSIDE(ind - 6, 0, SPECSTR_TOWNNAME_LAST-SPECSTR_TOWNNAME_START + 1)) {
   754 	if (IS_INT_INSIDE(ind - 6, 0, SPECSTR_TOWNNAME_LAST-SPECSTR_TOWNNAME_START + 1)) {
   766 		buff = GetSpecialTownNameString(buff, ind - 6);
   755 		buff = GetSpecialTownNameString(buff, ind - 6);
   767 		return str_cat(buff, " Transport");
   756 		return strecpy(buff, " Transport", NULL);
   768 	}
   757 	}
   769 
   758 
   770 	// language name?
   759 	// language name?
   771 	if (IS_INT_INSIDE(ind, (SPECSTR_LANGUAGE_START - 0x70E4), (SPECSTR_LANGUAGE_END - 0x70E4) + 1)) {
   760 	if (IS_INT_INSIDE(ind, (SPECSTR_LANGUAGE_START - 0x70E4), (SPECSTR_LANGUAGE_END - 0x70E4) + 1)) {
   772 		int i = ind - (SPECSTR_LANGUAGE_START - 0x70E4);
   761 		int i = ind - (SPECSTR_LANGUAGE_START - 0x70E4);
   773 		return str_cat(buff, i == _dynlang.curr ? _langpack->own_name : _dynlang.ent[i].name);
   762 		return strecpy(buff,
       
   763 			i == _dynlang.curr ? _langpack->own_name : _dynlang.ent[i].name, NULL);
   774 	}
   764 	}
   775 
   765 
   776 	// resolution size?
   766 	// resolution size?
   777 	if (IS_INT_INSIDE(ind, (SPECSTR_RESOLUTION_START - 0x70E4), (SPECSTR_RESOLUTION_END - 0x70E4) + 1)) {
   767 	if (IS_INT_INSIDE(ind, (SPECSTR_RESOLUTION_START - 0x70E4), (SPECSTR_RESOLUTION_END - 0x70E4) + 1)) {
   778 		int i = ind - (SPECSTR_RESOLUTION_START - 0x70E4);
   768 		int i = ind - (SPECSTR_RESOLUTION_START - 0x70E4);
   780 	}
   770 	}
   781 
   771 
   782 	// screenshot format name?
   772 	// screenshot format name?
   783 	if (IS_INT_INSIDE(ind, (SPECSTR_SCREENSHOT_START - 0x70E4), (SPECSTR_SCREENSHOT_END - 0x70E4) + 1)) {
   773 	if (IS_INT_INSIDE(ind, (SPECSTR_SCREENSHOT_START - 0x70E4), (SPECSTR_SCREENSHOT_END - 0x70E4) + 1)) {
   784 		int i = ind - (SPECSTR_SCREENSHOT_START - 0x70E4);
   774 		int i = ind - (SPECSTR_SCREENSHOT_START - 0x70E4);
   785 		return str_cat(buff, GetScreenshotFormatDesc(i));
   775 		return strecpy(buff, GetScreenshotFormatDesc(i), NULL);
   786 	}
   776 	}
   787 
   777 
   788 	assert(0);
   778 	assert(0);
   789 	return NULL;
   779 	return NULL;
   790 }
   780 }