newgrf_text.c
changeset 3646 291be46d399e
parent 3641 88699e48a03e
child 3821 57db5bab0f24
equal deleted inserted replaced
3645:7f950533d510 3646:291be46d399e
   117 static uint _num_grf_texts = 0;
   117 static uint _num_grf_texts = 0;
   118 static GRFTextEntry _grf_text[(1 << TABSIZE) * 3];
   118 static GRFTextEntry _grf_text[(1 << TABSIZE) * 3];
   119 static byte _currentLangID = GRFLX_ENGLISH;  //by default, english is used.
   119 static byte _currentLangID = GRFLX_ENGLISH;  //by default, english is used.
   120 
   120 
   121 
   121 
       
   122 static void TranslateTTDPatchCodes(char *str)
       
   123 {
       
   124 	char *c;
       
   125 
       
   126 	for (c = str; *c != '\0'; c++) {
       
   127 		switch ((byte)*c) {
       
   128 			case 0x01: c++; break;
       
   129 			case 0x0D: *c = 10; break;
       
   130 			case 0x0E: *c = 8; break;
       
   131 			case 0x0F: *c = 9; break;
       
   132 			case 0x1F: *c = 2; c += 2; break;
       
   133 			case 0x7B:
       
   134 			case 0x7C:
       
   135 			case 0x7D:
       
   136 			case 0x7E: *c = 0x8E; break;
       
   137 			case 0x81: c += 2; break;
       
   138 			case 0x85: *c = 0x86; break;
       
   139 			case 0x88: *c = 15; break;
       
   140 			case 0x89: *c = 16; break;
       
   141 			case 0x8A: *c = 17; break;
       
   142 			case 0x8B: *c = 18; break;
       
   143 			case 0x8C: *c = 19; break;
       
   144 			case 0x8D: *c = 20; break;
       
   145 			case 0x8E: *c = 21; break;
       
   146 			case 0x8F: *c = 22; break;
       
   147 			case 0x90: *c = 23; break;
       
   148 			case 0x91: *c = 24; break;
       
   149 			case 0x92: *c = 25; break;
       
   150 			case 0x93: *c = 26; break;
       
   151 			case 0x94: *c = 27; break;
       
   152 			case 0x95: *c = 28; break;
       
   153 			case 0x96: *c = 29; break;
       
   154 			case 0x97: *c = 30; break;
       
   155 			case 0x98: *c = 31; break;
       
   156 			default:
       
   157 				/* Validate any unhandled character */
       
   158 				if (!IsValidAsciiChar(*c)) *c = '?';
       
   159 				break;
       
   160 		}
       
   161 	}
       
   162 }
       
   163 
       
   164 
   122 /**
   165 /**
   123  * Add the new read string into our structure.
   166  * Add the new read string into our structure.
   124  */
   167  */
   125 StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool new_scheme, const char *text_to_add)
   168 StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool new_scheme, const char *text_to_add)
   126 {
   169 {
   148 	newtext = calloc(1, sizeof(*newtext));
   191 	newtext = calloc(1, sizeof(*newtext));
   149 	newtext->langid = GB(langid_to_add, 0, 6);
   192 	newtext->langid = GB(langid_to_add, 0, 6);
   150 	newtext->text   = strdup(text_to_add);
   193 	newtext->text   = strdup(text_to_add);
   151 	newtext->next   = NULL;
   194 	newtext->next   = NULL;
   152 
   195 
   153 	str_validate(newtext->text);
   196 	TranslateTTDPatchCodes(newtext->text);
   154 
   197 
   155 	for (id = 0; id < _num_grf_texts; id++) {
   198 	for (id = 0; id < _num_grf_texts; id++) {
   156 		if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
   199 		if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
   157 			break;
   200 			break;
   158 		}
   201 		}