src/strings.cpp
changeset 8445 54a5d84d1d7d
parent 8323 d5531c7645a7
child 8733 e60ce9c3ae47
equal deleted inserted replaced
8444:0bf94f3040be 8445:54a5d84d1d7d
   102  * slots for BindCString. NUM_BOUND_STRINGS slots are reserved.
   102  * slots for BindCString. NUM_BOUND_STRINGS slots are reserved.
   103  * Which means that after NUM_BOUND_STRINGS calls to BindCString,
   103  * Which means that after NUM_BOUND_STRINGS calls to BindCString,
   104  * the indices will be reused. */
   104  * the indices will be reused. */
   105 static int _bind_index;
   105 static int _bind_index;
   106 
   106 
   107 static const char *GetStringPtr(StringID string)
   107 const char *GetStringPtr(StringID string)
   108 {
   108 {
   109 	return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)];
   109 	switch (GB(string, 11, 5)) {
       
   110 		case 28: return GetGRFStringPtr(GB(string, 0, 11));
       
   111 		case 29: return GetGRFStringPtr(GB(string, 0, 11) + 0x0800);
       
   112 		case 30: return GetGRFStringPtr(GB(string, 0, 11) + 0x1000);
       
   113 		default: return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)];
       
   114 	}
   110 }
   115 }
   111 
   116 
   112 /** The highest 8 bits of string contain the "case index".
   117 /** The highest 8 bits of string contain the "case index".
   113  * These 8 bits will only be set when FormatString wants to print
   118  * These 8 bits will only be set when FormatString wants to print
   114  * the string in a different case. No one else except FormatString
   119  * the string in a different case. No one else except FormatString
   123 {
   128 {
   124 	if (GB(string, 0, 16) == 0) return GetStringWithArgs(buffr, STR_UNDEFINED, argv, last);
   129 	if (GB(string, 0, 16) == 0) return GetStringWithArgs(buffr, STR_UNDEFINED, argv, last);
   125 
   130 
   126 	uint index = GB(string,  0, 11);
   131 	uint index = GB(string,  0, 11);
   127 	uint tab   = GB(string, 11,  5);
   132 	uint tab   = GB(string, 11,  5);
   128 	char buff[512];
       
   129 
   133 
   130 	switch (tab) {
   134 	switch (tab) {
   131 		case 4:
   135 		case 4:
   132 			if (index >= 0xC0)
   136 			if (index >= 0xC0)
   133 				return GetSpecialTownNameString(buffr, index - 0xC0, GetInt32(&argv), last);
   137 				return GetSpecialTownNameString(buffr, index - 0xC0, GetInt32(&argv), last);
   137 			if (index >= 0xE4)
   141 			if (index >= 0xE4)
   138 				return GetSpecialPlayerNameString(buffr, index - 0xE4, argv, last);
   142 				return GetSpecialPlayerNameString(buffr, index - 0xE4, argv, last);
   139 			break;
   143 			break;
   140 
   144 
   141 		case 15:
   145 		case 15:
   142 			error("Boo!");
   146 			/* Old table for custom names. This is no longer used */
       
   147 			error("Incorrect conversion of custom name string.");
   143 
   148 
   144 		case 26:
   149 		case 26:
   145 			/* Include string within newgrf text (format code 81) */
   150 			/* Include string within newgrf text (format code 81) */
   146 			if (HasBit(index, 10)) {
   151 			if (HasBit(index, 10)) {
   147 				StringID string = GetGRFStringID(0, 0xD000 + GB(index, 0, 10));
   152 				StringID string = GetGRFStringID(0, 0xD000 + GB(index, 0, 10));
   148 				return GetStringWithArgs(buffr, string, argv, last);
   153 				return GetStringWithArgs(buffr, string, argv, last);
   149 			}
   154 			}
   150 			break;
   155 			break;
   151 
   156 
   152 		case 28:
   157 		case 28:
   153 			GetGRFString(buff, index, lastof(buff));
   158 			return FormatString(buffr, GetGRFStringPtr(index), argv, 0, last);
   154 			return FormatString(buffr, buff, argv, 0, last);
       
   155 
   159 
   156 		case 29:
   160 		case 29:
   157 			GetGRFString(buff, index + 0x800, lastof(buff));
   161 			return FormatString(buffr, GetGRFStringPtr(index + 0x0800), argv, 0, last);
   158 			return FormatString(buffr, buff, argv, 0, last);
       
   159 
   162 
   160 		case 30:
   163 		case 30:
   161 			GetGRFString(buff, index + 0x1000, lastof(buff));
   164 			return FormatString(buffr, GetGRFStringPtr(index + 0x1000), argv, 0, last);
   162 			return FormatString(buffr, buff, argv, 0, last);
       
   163 
   165 
   164 		case 31:
   166 		case 31:
   165 			/* dynamic strings. These are NOT to be passed through the formatter,
   167 			/* dynamic strings. These are NOT to be passed through the formatter,
   166 			 * but passed through verbatim. */
   168 			 * but passed through verbatim. */
   167 			if (index < (STR_SPEC_USERSTRING & 0x7FF)) {
   169 			if (index < (STR_SPEC_USERSTRING & 0x7FF)) {
   693 				modifier = 0;
   695 				modifier = 0;
   694 				break;
   696 				break;
   695 			}
   697 			}
   696 
   698 
   697 			case SCC_GENDER_LIST: { // {G 0 Der Die Das}
   699 			case SCC_GENDER_LIST: { // {G 0 Der Die Das}
   698 				char buffr[512];
   700 				const char *s = GetStringPtr(argv_orig[(byte)*str++]); // contains the string that determines gender.
   699 				const char *s = GetStringWithArgs(buffr, argv_orig[(byte)*str++], argv, last); // contains the string that determines gender.
       
   700 				int len;
   701 				int len;
   701 				int gender = 0;
   702 				int gender = 0;
   702 				if (s != NULL) {
   703 				if (s != NULL) {
   703 					wchar_t c = Utf8Consume(&s);
   704 					wchar_t c = Utf8Consume(&s);
   704 					/* Switch case is always put before genders, so remove those bits */
   705 					/* Switch case is always put before genders, so remove those bits */