OpenTTD Source: src/newgrf_text.cpp Source File

OpenTTD Source 1.11.0-RC1

newgrf_text.cpp
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
18 #include "stdafx.h"
19
20 #include <array>
21
22 #include "newgrf.h"
23 #include "strings_func.h"
24 #include "newgrf_storage.h"
25 #include "newgrf_text.h"
26 #include "newgrf_cargo.h"
27 #include "string_func.h"
28 #include "date_type.h"
29 #include "debug.h"
30 #include "core/alloc_type.hpp"
31 #include "core/smallmap_type.hpp"
32 #include "language.h"
33 #include <sstream>
34 #include <map>
35
36 #include "table/strings.h"
37 #include "table/control_codes.h"
38
39 #include "safeguards.h"
40
46 enum GRFBaseLanguages {
47 GRFLB_AMERICAN = 0x01,
48 GRFLB_ENGLISH = 0x02,
49 GRFLB_GERMAN = 0x04,
50 GRFLB_FRENCH = 0x08,
51 GRFLB_SPANISH = 0x10,
52 GRFLB_GENERIC = 0x80,
53 };
54
55 enum GRFExtendedLanguages {
56 GRFLX_AMERICAN = 0x00,
57 GRFLX_ENGLISH = 0x01,
58 GRFLX_GERMAN = 0x02,
59 GRFLX_FRENCH = 0x03,
60 GRFLX_SPANISH = 0x04,
61 GRFLX_UNSPECIFIED = 0x7F,
62 };
63
64
70 struct GRFTextEntry {
71 uint32 grfid;
72 uint16 stringid;
73 StringID def_string;
74 GRFTextList textholder;
75 };
76
77
78 static uint _num_grf_texts = 0;
79 static GRFTextEntry _grf_text[TAB_SIZE_NEWGRF];
80 static byte _currentLangID = GRFLX_ENGLISH;
81
88 int LanguageMap::GetMapping(int newgrf_id, bool gender) const
89 {
90 const std::vector<Mapping> &map = gender ? this->gender_map : this->case_map;
91 for (const Mapping &m : map) {
92 if (m.newgrf_id == newgrf_id) return m.openttd_id;
93 }
94 return -1;
95 }
96
103 int LanguageMap::GetReverseMapping(int openttd_id, bool gender) const
104 {
105 const std::vector<Mapping> &map = gender ? this->gender_map : this->case_map;
106 for (const Mapping &m : map) {
107 if (m.openttd_id == openttd_id) return m.newgrf_id;
108 }
109 return -1;
110 }
111
113 struct UnmappedChoiceList {
119 UnmappedChoiceList(StringControlCode type, int offset) :
120 type(type), offset(offset)
121 {
122 }
123
124 StringControlCode type;
125 int offset;
126
128 std::map<byte, std::stringstream> strings;
129
135 void Flush(const LanguageMap *lm, std::ostringstream &dest)
136 {
137 if (this->strings.find(0) == this->strings.end()) {
138 /* In case of a (broken) NewGRF without a default,
139 * assume an empty string. */
140 grfmsg(1, "choice list misses default value");
141 this->strings[0] = std::stringstream();
142 }
143
144 std::ostreambuf_iterator<char> d(dest);
145
146 if (lm == nullptr) {
147 /* In case there is no mapping, just ignore everything but the default.
148 * A probable cause for this happening is when the language file has
149 * been removed by the user and as such no mapping could be made. */
150 dest << this->strings[0].rdbuf();
151 return;
152 }
153
154 Utf8Encode(d, this->type);
155
156 if (this->type == SCC_SWITCH_CASE) {
157 /*
158 * Format for case switch:
159 * <NUM CASES> <CASE1> <LEN1> <STRING1> <CASE2> <LEN2> <STRING2> <CASE3> <LEN3> <STRING3> <STRINGDEFAULT>
160 * Each LEN is printed using 2 bytes in big endian order.
161 */
162
163 /* "<NUM CASES>" */
164 int count = 0;
165 for (uint8 i = 0; i < _current_language->num_cases; i++) {
166 /* Count the ones we have a mapped string for. */
167 if (this->strings.find(lm->GetReverseMapping(i, false)) != this->strings.end()) count++;
168 }
169 *d++ = count;
170
171 for (uint8 i = 0; i < _current_language->num_cases; i++) {
172 /* Resolve the string we're looking for. */
173 int idx = lm->GetReverseMapping(i, false);
174 if (this->strings.find(idx) == this->strings.end()) continue;
175 auto str = this->strings[idx].str();
176
177 /* "<CASEn>" */
178 *d++ = i + 1;
179
180 /* "<LENn>": Limit the length of the string to 0xFFFE to leave space for the '\0'. */
181 size_t len = std::min<size_t>(0xFFFE, str.size());
182 *d++ = GB(len + 1, 8, 8);
183 *d++ = GB(len + 1, 0, 8);
184
185 /* "<STRINGn>" */
186 dest.write(str.c_str(), len);
187 *d++ = '\0';
188 }
189
190 /* "<STRINGDEFAULT>" */
191 dest << this->strings[0].rdbuf() << '\0';
192 } else {
193 if (this->type == SCC_PLURAL_LIST) {
194 *d++ = lm->plural_form;
195 }
196
197 /*
198 * Format for choice list:
199 * <OFFSET> <NUM CHOICES> <LENs> <STRINGs>
200 */
201
202 /* "<OFFSET>" */
203 *d++ = this->offset - 0x80;
204
205 /* "<NUM CHOICES>" */
206 int count = (this->type == SCC_GENDER_LIST ? _current_language->num_genders : LANGUAGE_MAX_PLURAL_FORMS);
207 *d++ = count;
208
209 /* "<LENs>" */
210 for (int i = 0; i < count; i++) {
211 int idx = (this->type == SCC_GENDER_LIST ? lm->GetReverseMapping(i, true) : i + 1);
212 const auto &str = this->strings[this->strings.find(idx) != this->strings.end() ? idx : 0].str();
213 size_t len = str.size() + 1;
214 if (len > 0xFF) grfmsg(1, "choice list string is too long");
215 *d++ = GB(len, 0, 8);
216 }
217
218 /* "<STRINGs>" */
219 for (int i = 0; i < count; i++) {
220 int idx = (this->type == SCC_GENDER_LIST ? lm->GetReverseMapping(i, true) : i + 1);
221 const auto &str = this->strings[this->strings.find(idx) != this->strings.end() ? idx : 0].str();
222 /* Limit the length of the string we copy to 0xFE. The length is written above
223 * as a byte and we need room for the final '\0'. */
224 size_t len = std::min<size_t>(0xFE, str.size());
225 dest.write(str.c_str(), len);
226 *d++ = '\0';
227 }
228 }
229 }
230 };
231
241 std::string TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_newlines, const std::string &str, StringControlCode byte80)
242 {
243 /* Empty input string? Nothing to do here. */
244 if (str.empty()) return str;
245
246 std::string::const_iterator src = str.cbegin();
247
248 /* Is this an unicode string? */
249 bool unicode = false;
250 WChar marker;
251 size_t len = Utf8Decode(&marker, &*src);
252
253 if (marker == NFO_UTF8_IDENTIFIER) {
254 unicode = true;
255 src += len;
256 }
257
258 /* Helper variable for a possible (string) mapping. */
259 UnmappedChoiceList *mapping = nullptr;
260
261 std::ostringstream dest;
262 std::ostreambuf_iterator<char> d(dest);
263 while (src != str.cend()) {
264 WChar c;
265
266 if (unicode && Utf8EncodedCharLen(*src) != 0) {
267 c = Utf8Consume(src);
268 /* 'Magic' range of control codes. */
269 if (GB(c, 8, 8) == 0xE0) {
270 c = GB(c, 0, 8);
271 } else if (c >= 0x20) {
272 if (!IsValidChar(c, CS_ALPHANUMERAL)) c = '?';
273 Utf8Encode(d, c);
274 continue;
275 }
276 } else {
277 c = (byte)*src++;
278 }
279
280 if (c == '\0') break;
281
282 switch (c) {
283 case 0x01:
284 if (*src == '\0') goto string_end;
285 Utf8Encode(d, ' ');
286 src++;
287 break;
288 case 0x0A: break;
289 case 0x0D:
290 if (allow_newlines) {
291 *d++ = 0x0A;
292 } else {
293 grfmsg(1, "Detected newline in string that does not allow one");
294 }
295 break;
296 case 0x0E: Utf8Encode(d, SCC_TINYFONT); break;
297 case 0x0F: Utf8Encode(d, SCC_BIGFONT); break;
298 case 0x1F:
299 if (src[0] == '\0' || src[1] == '\0') goto string_end;
300 Utf8Encode(d, ' ');
301 src += 2;
302 break;
303 case 0x7B:
304 case 0x7C:
305 case 0x7D:
306 case 0x7E:
307 case 0x7F: Utf8Encode(d, SCC_NEWGRF_PRINT_DWORD_SIGNED + c - 0x7B); break;
308 case 0x80: Utf8Encode(d, byte80); break;
309 case 0x81:
310 {
311 if (src[0] == '\0' || src[1] == '\0') goto string_end;
312 StringID string;
313 string = ((uint8)* src++);
314 string |= ((uint8)* src++) << 8;
315 Utf8Encode(d, SCC_NEWGRF_STRINL);
316 Utf8Encode(d, MapGRFStringID(grfid, string));
317 break;
318 }
319 case 0x82:
320 case 0x83:
321 case 0x84: Utf8Encode(d, SCC_NEWGRF_PRINT_WORD_DATE_LONG + c - 0x82); break;
322 case 0x85: Utf8Encode(d, SCC_NEWGRF_DISCARD_WORD); break;
323 case 0x86: Utf8Encode(d, SCC_NEWGRF_ROTATE_TOP_4_WORDS); break;
324 case 0x87: Utf8Encode(d, SCC_NEWGRF_PRINT_WORD_VOLUME_LONG); break;
325 case 0x88: Utf8Encode(d, SCC_BLUE); break;
326 case 0x89: Utf8Encode(d, SCC_SILVER); break;
327 case 0x8A: Utf8Encode(d, SCC_GOLD); break;
328 case 0x8B: Utf8Encode(d, SCC_RED); break;
329 case 0x8C: Utf8Encode(d, SCC_PURPLE); break;
330 case 0x8D: Utf8Encode(d, SCC_LTBROWN); break;
331 case 0x8E: Utf8Encode(d, SCC_ORANGE); break;
332 case 0x8F: Utf8Encode(d, SCC_GREEN); break;
333 case 0x90: Utf8Encode(d, SCC_YELLOW); break;
334 case 0x91: Utf8Encode(d, SCC_DKGREEN); break;
335 case 0x92: Utf8Encode(d, SCC_CREAM); break;
336 case 0x93: Utf8Encode(d, SCC_BROWN); break;
337 case 0x94: Utf8Encode(d, SCC_WHITE); break;
338 case 0x95: Utf8Encode(d, SCC_LTBLUE); break;
339 case 0x96: Utf8Encode(d, SCC_GRAY); break;
340 case 0x97: Utf8Encode(d, SCC_DKBLUE); break;
341 case 0x98: Utf8Encode(d, SCC_BLACK); break;
342 case 0x9A:
343 {
344 int code = *src++;
345 switch (code) {
346 case 0x00: goto string_end;
347 case 0x01: Utf8Encode(d, SCC_NEWGRF_PRINT_QWORD_CURRENCY); break;
348 /* 0x02: ignore next colour byte is not supported. It works on the final
349 * string and as such hooks into the string drawing routine. At that
350 * point many things already happened, such as splitting up of strings
351 * when drawn over multiple lines or right-to-left translations, which
352 * make the behaviour peculiar, e.g. only happening at specific width
353 * of windows. Or we need to add another pass over the string to just
354 * support this. As such it is not implemented in OpenTTD. */
355 case 0x03:
356 {
357 if (src[0] == '\0' || src[1] == '\0') goto string_end;
358 uint16 tmp = ((uint8)* src++);
359 tmp |= ((uint8)* src++) << 8;
360 Utf8Encode(d, SCC_NEWGRF_PUSH_WORD);
361 Utf8Encode(d, tmp);
362 break;
363 }
364 case 0x04:
365 if (src[0] == '\0') goto string_end;
366 Utf8Encode(d, SCC_NEWGRF_UNPRINT);
367 Utf8Encode(d, *src++);
368 break;
369 case 0x06: Utf8Encode(d, SCC_NEWGRF_PRINT_BYTE_HEX); break;
370 case 0x07: Utf8Encode(d, SCC_NEWGRF_PRINT_WORD_HEX); break;
371 case 0x08: Utf8Encode(d, SCC_NEWGRF_PRINT_DWORD_HEX); break;
372 /* 0x09, 0x0A are TTDPatch internal use only string codes. */
373 case 0x0B: Utf8Encode(d, SCC_NEWGRF_PRINT_QWORD_HEX); break;
374 case 0x0C: Utf8Encode(d, SCC_NEWGRF_PRINT_WORD_STATION_NAME); break;
375 case 0x0D: Utf8Encode(d, SCC_NEWGRF_PRINT_WORD_WEIGHT_LONG); break;
376 case 0x0E:
377 case 0x0F:
378 {
379 if (str[0] == '\0') goto string_end;
380 const LanguageMap *lm = LanguageMap::GetLanguageMap(grfid, language_id);
381 int index = *src++;
382 int mapped = lm != nullptr ? lm->GetMapping(index, code == 0x0E) : -1;
383 if (mapped >= 0) {
384 Utf8Encode(d, code == 0x0E ? SCC_GENDER_INDEX : SCC_SET_CASE);
385 Utf8Encode(d, code == 0x0E ? mapped : mapped + 1);
386 }
387 break;
388 }
389
390 case 0x10:
391 case 0x11:
392 if (str[0] == '\0') goto string_end;
393 if (mapping == nullptr) {
394 if (code == 0x10) src++; // Skip the index
395 grfmsg(1, "choice list %s marker found when not expected", code == 0x10 ? "next" : "default");
396 break;
397 } else {
398 int index = (code == 0x10 ? *src++ : 0);
399 if (mapping->strings.find(index) != mapping->strings.end()) {
400 grfmsg(1, "duplicate choice list string, ignoring");
401 d++;
402 } else {
403 d = std::ostreambuf_iterator<char>(mapping->strings[index]);
404 }
405 }
406 break;
407
408 case 0x12:
409 if (mapping == nullptr) {
410 grfmsg(1, "choice list end marker found when not expected");
411 } else {
412 /* Now we can start flushing everything and clean everything up. */
413 mapping->Flush(LanguageMap::GetLanguageMap(grfid, language_id), dest);
414 delete mapping;
415 mapping = nullptr;
416
417 d = std::ostreambuf_iterator<char>(dest);
418 }
419 break;
420
421 case 0x13:
422 case 0x14:
423 case 0x15:
424 if (src[0] == '\0') goto string_end;
425 if (mapping != nullptr) {
426 grfmsg(1, "choice lists can't be stacked, it's going to get messy now...");
427 if (code != 0x14) src++;
428 } else {
429 static const StringControlCode mp[] = { SCC_GENDER_LIST, SCC_SWITCH_CASE, SCC_PLURAL_LIST };
430 mapping = new UnmappedChoiceList(mp[code - 0x13], code == 0x14 ? 0 : *src++);
431 }
432 break;
433
434 case 0x16:
435 case 0x17:
436 case 0x18:
437 case 0x19:
438 case 0x1A:
439 case 0x1B:
440 case 0x1C:
441 case 0x1D:
442 case 0x1E:
443 Utf8Encode(d, SCC_NEWGRF_PRINT_DWORD_DATE_LONG + code - 0x16);
444 break;
445
446 case 0x1F: Utf8Encode(d, SCC_PUSH_COLOUR); break;
447 case 0x20: Utf8Encode(d, SCC_POP_COLOUR); break;
448
449 default:
450 grfmsg(1, "missing handler for extended format code");
451 break;
452 }
453 break;
454 }
455
456 case 0x9E: Utf8Encode(d, 0x20AC); break; // Euro
457 case 0x9F: Utf8Encode(d, 0x0178); break; // Y with diaeresis
458 case 0xA0: Utf8Encode(d, SCC_UP_ARROW); break;
459 case 0xAA: Utf8Encode(d, SCC_DOWN_ARROW); break;
460 case 0xAC: Utf8Encode(d, SCC_CHECKMARK); break;
461 case 0xAD: Utf8Encode(d, SCC_CROSS); break;
462 case 0xAF: Utf8Encode(d, SCC_RIGHT_ARROW); break;
463 case 0xB4: Utf8Encode(d, SCC_TRAIN); break;
464 case 0xB5: Utf8Encode(d, SCC_LORRY); break;
465 case 0xB6: Utf8Encode(d, SCC_BUS); break;
466 case 0xB7: Utf8Encode(d, SCC_PLANE); break;
467 case 0xB8: Utf8Encode(d, SCC_SHIP); break;
468 case 0xB9: Utf8Encode(d, SCC_SUPERSCRIPT_M1); break;
469 case 0xBC: Utf8Encode(d, SCC_SMALL_UP_ARROW); break;
470 case 0xBD: Utf8Encode(d, SCC_SMALL_DOWN_ARROW); break;
471 default:
472 /* Validate any unhandled character */
473 if (!IsValidChar(c, CS_ALPHANUMERAL)) c = '?';
474 Utf8Encode(d, c);
475 break;
476 }
477 }
478
479 string_end:
480 if (mapping != nullptr) {
481 grfmsg(1, "choice list was incomplete, the whole list is ignored");
482 delete mapping;
483 }
484
485 return dest.str();
486 }
487
494 static void AddGRFTextToList(GRFTextList &list, byte langid, const std::string &text_to_add)
495 {
496 /* Loop through all languages and see if we can replace a string */
497 for (auto &text : list) {
498 if (text.langid == langid) {
499 text.text = text_to_add;
500 return;
501 }
502 }
503
504 /* If a string wasn't replaced, then we must append the new string */
505 list.push_back(GRFText{ langid, text_to_add });
506 }
507
517 void AddGRFTextToList(GRFTextList &list, byte langid, uint32 grfid, bool allow_newlines, const char *text_to_add)
518 {
519 AddGRFTextToList(list, langid, TranslateTTDPatchCodes(grfid, langid, allow_newlines, text_to_add));
520 }
521
531 void AddGRFTextToList(GRFTextWrapper &list, byte langid, uint32 grfid, bool allow_newlines, const char *text_to_add)
532 {
533 if (!list) list.reset(new GRFTextList());
534 AddGRFTextToList(*list, langid, grfid, allow_newlines, text_to_add);
535 }
536
543 void AddGRFTextToList(GRFTextWrapper &list, const char *text_to_add)
544 {
545 if (!list) list.reset(new GRFTextList());
546 AddGRFTextToList(*list, GRFLX_UNSPECIFIED, std::string(text_to_add));
547 }
548
552 StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool new_scheme, bool allow_newlines, const char *text_to_add, StringID def_string)
553 {
554 /* When working with the old language scheme (grf_version is less than 7) and
555 * English or American is among the set bits, simply add it as English in
556 * the new scheme, i.e. as langid = 1.
557 * If English is set, it is pretty safe to assume the translations are not
558 * actually translated.
559 */
560 if (!new_scheme) {
561 if (langid_to_add & (GRFLB_AMERICAN | GRFLB_ENGLISH)) {
562 langid_to_add = GRFLX_ENGLISH;
563 } else {
564 StringID ret = STR_EMPTY;
565 if (langid_to_add & GRFLB_GERMAN) ret = AddGRFString(grfid, stringid, GRFLX_GERMAN, true, allow_newlines, text_to_add, def_string);
566 if (langid_to_add & GRFLB_FRENCH) ret = AddGRFString(grfid, stringid, GRFLX_FRENCH, true, allow_newlines, text_to_add, def_string);
567 if (langid_to_add & GRFLB_SPANISH) ret = AddGRFString(grfid, stringid, GRFLX_SPANISH, true, allow_newlines, text_to_add, def_string);
568 return ret;
569 }
570 }
571
572 uint id;
573 for (id = 0; id < _num_grf_texts; id++) {
574 if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
575 break;
576 }
577 }
578
579 /* Too many strings allocated, return empty */
580 if (id == lengthof(_grf_text)) return STR_EMPTY;
581
582 std::string newtext = TranslateTTDPatchCodes(grfid, langid_to_add, allow_newlines, text_to_add);
583
584 /* If we didn't find our stringid and grfid in the list, allocate a new id */
585 if (id == _num_grf_texts) _num_grf_texts++;
586
587 if (_grf_text[id].textholder.empty()) {
588 _grf_text[id].grfid = grfid;
589 _grf_text[id].stringid = stringid;
590 _grf_text[id].def_string = def_string;
591 }
592 AddGRFTextToList(_grf_text[id].textholder, langid_to_add, newtext);
593
594 grfmsg(3, "Added 0x%X: grfid %08X string 0x%X lang 0x%X string '%s' (%X)", id, grfid, stringid, langid_to_add, newtext.c_str(), MakeStringID(TEXT_TAB_NEWGRF_START, id));
595
596 return MakeStringID(TEXT_TAB_NEWGRF_START, id);
597 }
598
602 StringID GetGRFStringID(uint32 grfid, StringID stringid)
603 {
604 for (uint id = 0; id < _num_grf_texts; id++) {
605 if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
606 return MakeStringID(TEXT_TAB_NEWGRF_START, id);
607 }
608 }
609
610 return STR_UNDEFINED;
611 }
612
613
621 const char *GetGRFStringFromGRFText(const GRFTextList &text_list)
622 {
623 const char *default_text = nullptr;
624
625 /* Search the list of lang-strings of this stringid for current lang */
626 for (const auto &text : text_list) {
627 if (text.langid == _currentLangID) return text.text.c_str();
628
629 /* If the current string is English or American, set it as the
630 * fallback language if the specific language isn't available. */
631 if (text.langid == GRFLX_UNSPECIFIED || (default_text == nullptr && (text.langid == GRFLX_ENGLISH || text.langid == GRFLX_AMERICAN))) {
632 default_text = text.text.c_str();
633 }
634 }
635
636 return default_text;
637 }
638
646 const char *GetGRFStringFromGRFText(const GRFTextWrapper &text)
647 {
648 return text ? GetGRFStringFromGRFText(*text) : nullptr;
649 }
650
654 const char *GetGRFStringPtr(uint16 stringid)
655 {
656 assert(_grf_text[stringid].grfid != 0);
657
658 const char *str = GetGRFStringFromGRFText(_grf_text[stringid].textholder);
659 if (str != nullptr) return str;
660
661 /* Use the default string ID if the fallback string isn't available */
662 return GetStringPtr(_grf_text[stringid].def_string);
663 }
664
673 void SetCurrentGrfLangID(byte language_id)
674 {
675 _currentLangID = language_id;
676 }
677
678 bool CheckGrfLangID(byte lang_id, byte grf_version)
679 {
680 if (grf_version < 7) {
681 switch (_currentLangID) {
682 case GRFLX_GERMAN: return (lang_id & GRFLB_GERMAN) != 0;
683 case GRFLX_FRENCH: return (lang_id & GRFLB_FRENCH) != 0;
684 case GRFLX_SPANISH: return (lang_id & GRFLB_SPANISH) != 0;
685 default: return (lang_id & (GRFLB_ENGLISH | GRFLB_AMERICAN)) != 0;
686 }
687 }
688
689 return (lang_id == _currentLangID || lang_id == GRFLX_UNSPECIFIED);
690 }
691
696 void CleanUpStrings()
697 {
698 uint id;
699
700 for (id = 0; id < _num_grf_texts; id++) {
701 _grf_text[id].grfid = 0;
702 _grf_text[id].stringid = 0;
703 _grf_text[id].textholder.clear();
704 }
705
706 _num_grf_texts = 0;
707 }
708
709 struct TextRefStack {
710 std::array<byte, 0x30> stack;
711 byte position;
712 const GRFFile *grffile;
713 bool used;
714
715 TextRefStack() : position(0), grffile(nullptr), used(false) {}
716
717 uint8 PopUnsignedByte() { assert(this->position < this->stack.size()); return this->stack[this->position++]; }
718 int8 PopSignedByte() { return (int8)this->PopUnsignedByte(); }
719
720 uint16 PopUnsignedWord()
721 {
722 uint16 val = this->PopUnsignedByte();
723 return val | (this->PopUnsignedByte() << 8);
724 }
725 int16 PopSignedWord() { return (int32)this->PopUnsignedWord(); }
726
727 uint32 PopUnsignedDWord()
728 {
729 uint32 val = this->PopUnsignedWord();
730 return val | (this->PopUnsignedWord() << 16);
731 }
732 int32 PopSignedDWord() { return (int32)this->PopUnsignedDWord(); }
733
734 uint64 PopUnsignedQWord()
735 {
736 uint64 val = this->PopUnsignedDWord();
737 return val | (((uint64)this->PopUnsignedDWord()) << 32);
738 }
739 int64 PopSignedQWord() { return (int64)this->PopUnsignedQWord(); }
740
742 void RotateTop4Words()
743 {
744 byte tmp[2];
745 for (int i = 0; i < 2; i++) tmp[i] = this->stack[this->position + i + 6];
746 for (int i = 5; i >= 0; i--) this->stack[this->position + i + 2] = this->stack[this->position + i];
747 for (int i = 0; i < 2; i++) this->stack[this->position + i] = tmp[i];
748 }
749
750 void PushWord(uint16 word)
751 {
752 if (this->position >= 2) {
753 this->position -= 2;
754 } else {
755 // Rotate right 2 positions
756 std::rotate(this->stack.rbegin(), this->stack.rbegin() + 2, this->stack.rend());
757 }
758 this->stack[this->position] = GB(word, 0, 8);
759 this->stack[this->position + 1] = GB(word, 8, 8);
760 }
761
762 void ResetStack(const GRFFile *grffile)
763 {
764 assert(grffile != nullptr);
765 this->position = 0;
766 this->grffile = grffile;
767 this->used = true;
768 }
769
770 void RewindStack() { this->position = 0; }
771 };
772
774 static TextRefStack _newgrf_textrefstack;
775
780 bool UsingNewGRFTextStack()
781 {
782 return _newgrf_textrefstack.used;
783 }
784
789 struct TextRefStack *CreateTextRefStackBackup()
790 {
791 return new TextRefStack(_newgrf_textrefstack);
792 }
793
798 void RestoreTextRefStackBackup(struct TextRefStack *backup)
799 {
800 _newgrf_textrefstack = *backup;
801 delete backup;
802 }
803
822 void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32 *values)
823 {
824 extern TemporaryStorageArray<int32, 0x110> _temp_store;
825
826 _newgrf_textrefstack.ResetStack(grffile);
827
828 auto stack_it = _newgrf_textrefstack.stack.begin();
829 for (uint i = 0; i < numEntries; i++) {
830 uint32 value = values != nullptr ? values[i] : _temp_store.GetValue(0x100 + i);
831 for (uint j = 0; j < 32; j += 8) {
832 *stack_it = GB(value, j, 8);
833 stack_it++;
834 }
835 }
836 }
837
839 void StopTextRefStackUsage()
840 {
841 _newgrf_textrefstack.used = false;
842 }
843
844 void RewindTextRefStack()
845 {
846 _newgrf_textrefstack.RewindStack();
847 }
848
859 uint RemapNewGRFStringControlCode(uint scc, char *buf_start, char **buff, const char **str, int64 *argv, uint argv_size, bool modify_argv)
860 {
861 switch (scc) {
862 default: break;
863
864 case SCC_NEWGRF_PRINT_DWORD_SIGNED:
865 case SCC_NEWGRF_PRINT_WORD_SIGNED:
866 case SCC_NEWGRF_PRINT_BYTE_SIGNED:
867 case SCC_NEWGRF_PRINT_WORD_UNSIGNED:
868 case SCC_NEWGRF_PRINT_BYTE_HEX:
869 case SCC_NEWGRF_PRINT_WORD_HEX:
870 case SCC_NEWGRF_PRINT_DWORD_HEX:
871 case SCC_NEWGRF_PRINT_QWORD_HEX:
872 case SCC_NEWGRF_PRINT_DWORD_CURRENCY:
873 case SCC_NEWGRF_PRINT_QWORD_CURRENCY:
874 case SCC_NEWGRF_PRINT_WORD_STRING_ID:
875 case SCC_NEWGRF_PRINT_WORD_DATE_LONG:
876 case SCC_NEWGRF_PRINT_DWORD_DATE_LONG:
877 case SCC_NEWGRF_PRINT_WORD_DATE_SHORT:
878 case SCC_NEWGRF_PRINT_DWORD_DATE_SHORT:
879 case SCC_NEWGRF_PRINT_WORD_SPEED:
880 case SCC_NEWGRF_PRINT_WORD_VOLUME_LONG:
881 case SCC_NEWGRF_PRINT_WORD_VOLUME_SHORT:
882 case SCC_NEWGRF_PRINT_WORD_WEIGHT_LONG:
883 case SCC_NEWGRF_PRINT_WORD_WEIGHT_SHORT:
884 case SCC_NEWGRF_PRINT_WORD_POWER:
885 case SCC_NEWGRF_PRINT_WORD_STATION_NAME:
886 case SCC_NEWGRF_PRINT_WORD_CARGO_NAME:
887 if (argv_size < 1) {
888 DEBUG(misc, 0, "Too many NewGRF string parameters.");
889 return 0;
890 }
891 break;
892
893 case SCC_NEWGRF_PRINT_WORD_CARGO_LONG:
894 case SCC_NEWGRF_PRINT_WORD_CARGO_SHORT:
895 case SCC_NEWGRF_PRINT_WORD_CARGO_TINY:
896 if (argv_size < 2) {
897 DEBUG(misc, 0, "Too many NewGRF string parameters.");
898 return 0;
899 }
900 break;
901 }
902
903 if (_newgrf_textrefstack.used && modify_argv) {
904 switch (scc) {
905 default: NOT_REACHED();
906 case SCC_NEWGRF_PRINT_BYTE_SIGNED: *argv = _newgrf_textrefstack.PopSignedByte(); break;
907 case SCC_NEWGRF_PRINT_QWORD_CURRENCY: *argv = _newgrf_textrefstack.PopSignedQWord(); break;
908
909 case SCC_NEWGRF_PRINT_DWORD_CURRENCY:
910 case SCC_NEWGRF_PRINT_DWORD_SIGNED: *argv = _newgrf_textrefstack.PopSignedDWord(); break;
911
912 case SCC_NEWGRF_PRINT_BYTE_HEX: *argv = _newgrf_textrefstack.PopUnsignedByte(); break;
913 case SCC_NEWGRF_PRINT_QWORD_HEX: *argv = _newgrf_textrefstack.PopUnsignedQWord(); break;
914
915 case SCC_NEWGRF_PRINT_WORD_SPEED:
916 case SCC_NEWGRF_PRINT_WORD_VOLUME_LONG:
917 case SCC_NEWGRF_PRINT_WORD_VOLUME_SHORT:
918 case SCC_NEWGRF_PRINT_WORD_SIGNED: *argv = _newgrf_textrefstack.PopSignedWord(); break;
919
920 case SCC_NEWGRF_PRINT_WORD_HEX:
921 case SCC_NEWGRF_PRINT_WORD_WEIGHT_LONG:
922 case SCC_NEWGRF_PRINT_WORD_WEIGHT_SHORT:
923 case SCC_NEWGRF_PRINT_WORD_POWER:
924 case SCC_NEWGRF_PRINT_WORD_STATION_NAME:
925 case SCC_NEWGRF_PRINT_WORD_UNSIGNED: *argv = _newgrf_textrefstack.PopUnsignedWord(); break;
926
927 case SCC_NEWGRF_PRINT_DWORD_DATE_LONG:
928 case SCC_NEWGRF_PRINT_DWORD_DATE_SHORT:
929 case SCC_NEWGRF_PRINT_DWORD_HEX: *argv = _newgrf_textrefstack.PopUnsignedDWord(); break;
930
931 case SCC_NEWGRF_PRINT_WORD_DATE_LONG:
932 case SCC_NEWGRF_PRINT_WORD_DATE_SHORT: *argv = _newgrf_textrefstack.PopUnsignedWord() + DAYS_TILL_ORIGINAL_BASE_YEAR; break;
933
934 case SCC_NEWGRF_DISCARD_WORD: _newgrf_textrefstack.PopUnsignedWord(); break;
935
936 case SCC_NEWGRF_ROTATE_TOP_4_WORDS: _newgrf_textrefstack.RotateTop4Words(); break;
937 case SCC_NEWGRF_PUSH_WORD: _newgrf_textrefstack.PushWord(Utf8Consume(str)); break;
938 case SCC_NEWGRF_UNPRINT: *buff = std::max(*buff - Utf8Consume(str), buf_start); break;
939
940 case SCC_NEWGRF_PRINT_WORD_CARGO_LONG:
941 case SCC_NEWGRF_PRINT_WORD_CARGO_SHORT:
942 case SCC_NEWGRF_PRINT_WORD_CARGO_TINY:
943 argv[0] = GetCargoTranslation(_newgrf_textrefstack.PopUnsignedWord(), _newgrf_textrefstack.grffile);
944 argv[1] = _newgrf_textrefstack.PopUnsignedWord();
945 break;
946
947 case SCC_NEWGRF_PRINT_WORD_STRING_ID:
948 *argv = MapGRFStringID(_newgrf_textrefstack.grffile->grfid, _newgrf_textrefstack.PopUnsignedWord());
949 break;
950
951 case SCC_NEWGRF_PRINT_WORD_CARGO_NAME: {
952 CargoID cargo = GetCargoTranslation(_newgrf_textrefstack.PopUnsignedWord(), _newgrf_textrefstack.grffile);
953 *argv = cargo < NUM_CARGO ? 1 << cargo : 0;
954 break;
955 }
956 }
957 } else {
958 /* Consume additional parameter characters */
959 switch (scc) {
960 default: break;
961
962 case SCC_NEWGRF_PUSH_WORD:
963 case SCC_NEWGRF_UNPRINT:
964 Utf8Consume(str);
965 break;
966 }
967 }
968
969 switch (scc) {
970 default: NOT_REACHED();
971 case SCC_NEWGRF_PRINT_DWORD_SIGNED:
972 case SCC_NEWGRF_PRINT_WORD_SIGNED:
973 case SCC_NEWGRF_PRINT_BYTE_SIGNED:
974 case SCC_NEWGRF_PRINT_WORD_UNSIGNED:
975 return SCC_COMMA;
976
977 case SCC_NEWGRF_PRINT_BYTE_HEX:
978 case SCC_NEWGRF_PRINT_WORD_HEX:
979 case SCC_NEWGRF_PRINT_DWORD_HEX:
980 case SCC_NEWGRF_PRINT_QWORD_HEX:
981 return SCC_HEX;
982
983 case SCC_NEWGRF_PRINT_DWORD_CURRENCY:
984 case SCC_NEWGRF_PRINT_QWORD_CURRENCY:
985 return SCC_CURRENCY_LONG;
986
987 case SCC_NEWGRF_PRINT_WORD_STRING_ID:
988 return SCC_NEWGRF_PRINT_WORD_STRING_ID;
989
990 case SCC_NEWGRF_PRINT_WORD_DATE_LONG:
991 case SCC_NEWGRF_PRINT_DWORD_DATE_LONG:
992 return SCC_DATE_LONG;
993
994 case SCC_NEWGRF_PRINT_WORD_DATE_SHORT:
995 case SCC_NEWGRF_PRINT_DWORD_DATE_SHORT:
996 return SCC_DATE_SHORT;
997
998 case SCC_NEWGRF_PRINT_WORD_SPEED:
999 return SCC_VELOCITY;
1000
1001 case SCC_NEWGRF_PRINT_WORD_VOLUME_LONG:
1002 return SCC_VOLUME_LONG;
1003
1004 case SCC_NEWGRF_PRINT_WORD_VOLUME_SHORT:
1005 return SCC_VOLUME_SHORT;
1006
1007 case SCC_NEWGRF_PRINT_WORD_WEIGHT_LONG:
1008 return SCC_WEIGHT_LONG;
1009
1010 case SCC_NEWGRF_PRINT_WORD_WEIGHT_SHORT:
1011 return SCC_WEIGHT_SHORT;
1012
1013 case SCC_NEWGRF_PRINT_WORD_POWER:
1014 return SCC_POWER;
1015
1016 case SCC_NEWGRF_PRINT_WORD_CARGO_LONG:
1017 return SCC_CARGO_LONG;
1018
1019 case SCC_NEWGRF_PRINT_WORD_CARGO_SHORT:
1020 return SCC_CARGO_SHORT;
1021
1022 case SCC_NEWGRF_PRINT_WORD_CARGO_TINY:
1023 return SCC_CARGO_TINY;
1024
1025 case SCC_NEWGRF_PRINT_WORD_CARGO_NAME:
1026 return SCC_CARGO_LIST;
1027
1028 case SCC_NEWGRF_PRINT_WORD_STATION_NAME:
1029 return SCC_STATION_NAME;
1030
1031 case SCC_NEWGRF_DISCARD_WORD:
1032 case SCC_NEWGRF_ROTATE_TOP_4_WORDS:
1033 case SCC_NEWGRF_PUSH_WORD:
1034 case SCC_NEWGRF_UNPRINT:
1035 return 0;
1036 }
1037 }
SCC_NEWGRF_ROTATE_TOP_4_WORDS
@ SCC_NEWGRF_ROTATE_TOP_4_WORDS
86: Rotate the top 4 words of the stack (W4 W1 W2 W3)
Definition: control_codes.h:153
GRFText
A GRF text with associated language ID.
Definition: newgrf_text.h:25
LanguageMap::case_map
std::vector< Mapping > case_map
Mapping of NewGRF and OpenTTD IDs for cases.
Definition: newgrf_text.h:72
WChar
char32_t WChar
Type for wide characters, i.e.
Definition: string_type.h:35
GRFTextList
std::vector< GRFText > GRFTextList
A GRF text with a list of translations.
Definition: newgrf_text.h:31
SCC_NEWGRF_STRINL
@ SCC_NEWGRF_STRINL
Inline another string at the current position, StringID is encoded in the string.
Definition: control_codes.h:156
GB
static uint GB(const T x, const uint8 s, const uint8 n)
Fetch n bits from x, started at bit s.
Definition: bitmath_func.hpp:32
SCC_NEWGRF_PRINT_WORD_SPEED
@ SCC_NEWGRF_PRINT_WORD_SPEED
84: Read 2 bytes from the stack as signed speed
Definition: control_codes.h:132
SCC_NEWGRF_PRINT_WORD_CARGO_SHORT
@ SCC_NEWGRF_PRINT_WORD_CARGO_SHORT
9A 1C: Read 2 + 2 bytes from the stack as cargo type (translated) and unsigned cargo amount
Definition: control_codes.h:147
TEXT_TAB_NEWGRF_START
@ TEXT_TAB_NEWGRF_START
Start of NewGRF supplied strings.
Definition: strings_type.h:40
MakeStringID
static StringID MakeStringID(StringTab tab, uint index)
Create a StringID.
Definition: strings_func.h:47
grfmsg
void CDECL grfmsg(int severity, const char *str,...)
DEBUG() function dedicated to newGRF debugging messages Function is essentially the same as DEBUG(grf...
Definition: newgrf.cpp:379
LanguageMap::plural_form
int plural_form
The plural form used for this language.
Definition: newgrf_text.h:73
SCC_BIGFONT
@ SCC_BIGFONT
Switch to large font.
Definition: control_codes.h:31
SCC_NEWGRF_PRINT_WORD_HEX
@ SCC_NEWGRF_PRINT_WORD_HEX
9A 07: Read 2 bytes from the stack and print it as hex
Definition: control_codes.h:138
GRFTextEntry
Holder of the above structure.
Definition: newgrf_text.cpp:70
Utf8Encode
size_t Utf8Encode(T buf, WChar c)
Encode a unicode character and place it in the buffer.
Definition: string.cpp:523
StartTextRefStackUsage
void StartTextRefStackUsage(const GRFFile *grffile, byte numEntries, const uint32 *values)
Start using the TTDP compatible string code parsing.
Definition: newgrf_text.cpp:822
LanguagePackHeader::num_cases
uint8 num_cases
the number of cases of this language
Definition: language.h:54
smallmap_type.hpp
StopTextRefStackUsage
void StopTextRefStackUsage()
Stop using the TTDP compatible string code parsing.
Definition: newgrf_text.cpp:839
TAB_SIZE_NEWGRF
static const uint TAB_SIZE_NEWGRF
Number of strings for NewGRFs.
Definition: strings_type.h:52
TranslateTTDPatchCodes
std::string TranslateTTDPatchCodes(uint32 grfid, uint8 language_id, bool allow_newlines, const std::string &str, StringControlCode byte80)
Translate TTDPatch string codes into something OpenTTD can handle (better).
Definition: newgrf_text.cpp:241
SCC_NEWGRF_PRINT_DWORD_DATE_LONG
@ SCC_NEWGRF_PRINT_DWORD_DATE_LONG
9A 16: Read 4 bytes from the stack as base 0 date
Definition: control_codes.h:141
GRFBaseLanguages
GRFBaseLanguages
Explains the newgrf shift bit positioning.
Definition: newgrf_text.cpp:46
RestoreTextRefStackBackup
void RestoreTextRefStackBackup(struct TextRefStack *backup)
Restore a copy of the text stack to the used stack.
Definition: newgrf_text.cpp:798
alloc_type.hpp
control_codes.h
SCC_NEWGRF_DISCARD_WORD
@ SCC_NEWGRF_DISCARD_WORD
85: Discard the next two bytes
Definition: control_codes.h:152
AddGRFString
StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool new_scheme, bool allow_newlines, const char *text_to_add, StringID def_string)
Add the new read string into our structure.
Definition: newgrf_text.cpp:552
SCC_NEWGRF_PUSH_WORD
@ SCC_NEWGRF_PUSH_WORD
9A 03: Pushes 2 bytes onto the stack
Definition: control_codes.h:150
NFO_UTF8_IDENTIFIER
static const WChar NFO_UTF8_IDENTIFIER
This character, the thorn ('þ'), indicates a unicode string to NFO.
Definition: newgrf_text.h:22
SCC_NEWGRF_PRINT_WORD_STRING_ID
@ SCC_NEWGRF_PRINT_WORD_STRING_ID
81: Read 2 bytes from the stack as String ID
Definition: control_codes.h:129
UnmappedChoiceList::Flush
void Flush(const LanguageMap *lm, std::ostringstream &dest)
Flush this choice list into the destination string.
Definition: newgrf_text.cpp:135
LanguageMap::GetLanguageMap
static const LanguageMap * GetLanguageMap(uint32 grfid, uint8 language_id)
Get the language map associated with a given NewGRF and language.
Definition: newgrf.cpp:2574
RemapNewGRFStringControlCode
uint RemapNewGRFStringControlCode(uint scc, char *buf_start, char **buff, const char **str, int64 *argv, uint argv_size, bool modify_argv)
FormatString for NewGRF specific "magic" string control codes.
Definition: newgrf_text.cpp:859
SCC_TINYFONT
@ SCC_TINYFONT
Switch to small font.
Definition: control_codes.h:30
DEBUG
#define DEBUG(name, level,...)
Output a line of debugging information.
Definition: debug.h:35
TextRefStack::RotateTop4Words
void RotateTop4Words()
Rotate the top four words down: W1, W2, W3, W4 -> W4, W1, W2, W3.
Definition: newgrf_text.cpp:742
GetGRFStringFromGRFText
const char * GetGRFStringFromGRFText(const GRFTextList &text_list)
Get a C-string from a GRFText-list.
Definition: newgrf_text.cpp:621
SCC_NEWGRF_PRINT_WORD_CARGO_NAME
@ SCC_NEWGRF_PRINT_WORD_CARGO_NAME
9A 1E: Read 2 bytes from the stack as cargo name
Definition: control_codes.h:149
CleanUpStrings
void CleanUpStrings()
House cleaning.
Definition: newgrf_text.cpp:696
_currentLangID
static byte _currentLangID
by default, english is used.
Definition: newgrf_text.cpp:80
SCC_NEWGRF_PRINT_WORD_CARGO_TINY
@ SCC_NEWGRF_PRINT_WORD_CARGO_TINY
9A 1D: Read 2 + 2 bytes from the stack as cargo type (translated) and unsigned cargo amount
Definition: control_codes.h:148
LanguageMap::gender_map
std::vector< Mapping > gender_map
Mapping of NewGRF and OpenTTD IDs for genders.
Definition: newgrf_text.h:71
SCC_NEWGRF_PRINT_DWORD_SIGNED
@ SCC_NEWGRF_PRINT_DWORD_SIGNED
7B: Read 4 bytes from the stack
Definition: control_codes.h:124
_current_language
const LanguageMetadata * _current_language
The currently loaded language.
Definition: strings.cpp:46
safeguards.h
GetGRFStringPtr
const char * GetGRFStringPtr(uint16 stringid)
Get a C-string from a stringid set by a newgrf.
Definition: newgrf_text.cpp:654
IsValidChar
bool IsValidChar(WChar key, CharSetFilter afilter)
Only allow certain keys.
Definition: string.cpp:383
GetGRFStringID
StringID GetGRFStringID(uint32 grfid, StringID stringid)
Returns the index for this stringid associated with its grfID.
Definition: newgrf_text.cpp:602
newgrf_text.h
UnmappedChoiceList
Helper structure for mapping choice lists.
Definition: newgrf_text.cpp:113
language.h
stdafx.h
SCC_NEWGRF_PRINT_WORD_STATION_NAME
@ SCC_NEWGRF_PRINT_WORD_STATION_NAME
9A 0C: Read 2 bytes from the stack as station name
Definition: control_codes.h:135
CS_ALPHANUMERAL
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition: string_type.h:27
UnmappedChoiceList::UnmappedChoiceList
UnmappedChoiceList(StringControlCode type, int offset)
Initialise the mapping.
Definition: newgrf_text.cpp:119
LanguageMap::Mapping
Mapping between NewGRF and OpenTTD IDs.
Definition: newgrf_text.h:60
Utf8Decode
size_t Utf8Decode(WChar *c, const char *s)
Decode and consume the next UTF-8 encoded character.
Definition: string.cpp:481
date_type.h
SCC_NEWGRF_PRINT_WORD_DATE_LONG
@ SCC_NEWGRF_PRINT_WORD_DATE_LONG
82: Read 2 bytes from the stack as base 1920 date
Definition: control_codes.h:130
string_func.h
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
SCC_NEWGRF_PRINT_QWORD_CURRENCY
@ SCC_NEWGRF_PRINT_QWORD_CURRENCY
9A 01: Read 8 bytes from the stack as currency
Definition: control_codes.h:136
UnmappedChoiceList::offset
int offset
The offset for the plural/gender form.
Definition: newgrf_text.cpp:125
strings_func.h
LanguageMap
Mapping of language data between a NewGRF and OpenTTD.
Definition: newgrf_text.h:58
UnmappedChoiceList::strings
std::map< byte, std::stringstream > strings
Mapping of NewGRF supplied ID to the different strings in the choice list.
Definition: newgrf_text.cpp:128
LanguageMap::GetMapping
int GetMapping(int newgrf_id, bool gender) const
Get the mapping from the NewGRF supplied ID to OpenTTD's internal ID.
Definition: newgrf_text.cpp:88
StringControlCode
StringControlCode
List of string control codes used for string formatting, displaying, and by strgen to generate the la...
Definition: control_codes.h:17
SCC_NEWGRF_PRINT_WORD_SIGNED
@ SCC_NEWGRF_PRINT_WORD_SIGNED
7C: Read 2 bytes from the stack as signed value
Definition: control_codes.h:125
SCC_NEWGRF_PRINT_WORD_VOLUME_SHORT
@ SCC_NEWGRF_PRINT_WORD_VOLUME_SHORT
9A 19: Read 2 bytes from the stack as short signed volume
Definition: control_codes.h:144
SCC_NEWGRF_PRINT_QWORD_HEX
@ SCC_NEWGRF_PRINT_QWORD_HEX
9A 0B: Read 8 bytes from the stack and print it as hex
Definition: control_codes.h:140
newgrf.h
SCC_NEWGRF_PRINT_DWORD_DATE_SHORT
@ SCC_NEWGRF_PRINT_DWORD_DATE_SHORT
9A 17: Read 4 bytes from the stack as base 0 date
Definition: control_codes.h:142
NUM_CARGO
@ NUM_CARGO
Maximal number of cargo types in a game.
Definition: cargo_type.h:64
GetCargoTranslation
CargoID GetCargoTranslation(uint8 cargo, const GRFFile *grffile, bool usebit)
Translate a GRF-local cargo slot/bitnum into a CargoID.
Definition: newgrf_cargo.cpp:91
SCC_NEWGRF_PRINT_DWORD_CURRENCY
@ SCC_NEWGRF_PRINT_DWORD_CURRENCY
8F: Read 4 bytes from the stack as currency
Definition: control_codes.h:128
SCC_NEWGRF_PRINT_BYTE_HEX
@ SCC_NEWGRF_PRINT_BYTE_HEX
9A 06: Read 1 byte from the stack and print it as hex
Definition: control_codes.h:137
UnmappedChoiceList::type
StringControlCode type
The type of choice list.
Definition: newgrf_text.cpp:124
SCC_NEWGRF_PRINT_WORD_CARGO_LONG
@ SCC_NEWGRF_PRINT_WORD_CARGO_LONG
9A 1B: Read 2 + 2 bytes from the stack as cargo type (translated) and unsigned cargo amount
Definition: control_codes.h:146
CreateTextRefStackBackup
struct TextRefStack * CreateTextRefStackBackup()
Create a backup of the current NewGRF text stack.
Definition: newgrf_text.cpp:789
SCC_NEWGRF_PRINT_WORD_DATE_SHORT
@ SCC_NEWGRF_PRINT_WORD_DATE_SHORT
83: Read 2 bytes from the stack as base 1920 date
Definition: control_codes.h:131
SetCurrentGrfLangID
void SetCurrentGrfLangID(byte language_id)
Equivalence Setter function between game and newgrf langID.
Definition: newgrf_text.cpp:673
LanguagePackHeader::num_genders
uint8 num_genders
the number of genders of this language
Definition: language.h:53
SCC_NEWGRF_PRINT_WORD_VOLUME_LONG
@ SCC_NEWGRF_PRINT_WORD_VOLUME_LONG
87: Read 2 bytes from the stack as long signed volume
Definition: control_codes.h:133
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:367
LanguageMap::GetReverseMapping
int GetReverseMapping(int openttd_id, bool gender) const
Get the mapping from OpenTTD's internal ID to the NewGRF supplied ID.
Definition: newgrf_text.cpp:103
SCC_NEWGRF_PRINT_WORD_UNSIGNED
@ SCC_NEWGRF_PRINT_WORD_UNSIGNED
7E: Read 2 bytes from the stack as unsigned value
Definition: control_codes.h:127
CargoID
byte CargoID
Cargo slots to indicate a cargo type within a game.
Definition: cargo_type.h:20
TemporaryStorageArray
Class for temporary storage of data.
Definition: newgrf_storage.h:150
SCC_NEWGRF_PRINT_WORD_WEIGHT_LONG
@ SCC_NEWGRF_PRINT_WORD_WEIGHT_LONG
9A 0D: Read 2 bytes from the stack as long unsigned weight
Definition: control_codes.h:134
GRFTextWrapper
std::shared_ptr< GRFTextList > GRFTextWrapper
Reference counted wrapper around a GRFText pointer.
Definition: newgrf_text.h:33
SCC_NEWGRF_PRINT_DWORD_HEX
@ SCC_NEWGRF_PRINT_DWORD_HEX
9A 08: Read 4 bytes from the stack and print it as hex
Definition: control_codes.h:139
MapGRFStringID
StringID MapGRFStringID(uint32 grfid, StringID str)
Used when setting an object's property to map to the GRF's strings while taking in consideration the ...
Definition: newgrf.cpp:551
SCC_NEWGRF_PRINT_WORD_POWER
@ SCC_NEWGRF_PRINT_WORD_POWER
9A 18: Read 2 bytes from the stack as unsigned power
Definition: control_codes.h:143
SCC_NEWGRF_PRINT_BYTE_SIGNED
@ SCC_NEWGRF_PRINT_BYTE_SIGNED
7D: Read 1 byte from the stack as signed value
Definition: control_codes.h:126
newgrf_storage.h
SCC_NEWGRF_UNPRINT
@ SCC_NEWGRF_UNPRINT
9A 04: "Unprints" the given number of bytes from the string
Definition: control_codes.h:151
newgrf_cargo.h
_newgrf_textrefstack
static TextRefStack _newgrf_textrefstack
The stack that is used for TTDP compatible string code parsing.
Definition: newgrf_text.cpp:774
AddGRFTextToList
static void AddGRFTextToList(GRFTextList &list, byte langid, const std::string &text_to_add)
Add a new text to a GRFText list.
Definition: newgrf_text.cpp:494
GRFFile
Dynamic data of a loaded NewGRF.
Definition: newgrf.h:105
UsingNewGRFTextStack
bool UsingNewGRFTextStack()
Check whether the NewGRF text stack is in use.
Definition: newgrf_text.cpp:780
debug.h
DAYS_TILL_ORIGINAL_BASE_YEAR
#define DAYS_TILL_ORIGINAL_BASE_YEAR
The offset in days from the '_date == 0' till 'ConvertYMDToDate(ORIGINAL_BASE_YEAR,...
Definition: date_type.h:80
SCC_NEWGRF_PRINT_WORD_WEIGHT_SHORT
@ SCC_NEWGRF_PRINT_WORD_WEIGHT_SHORT
9A 1A: Read 2 bytes from the stack as short unsigned weight
Definition: control_codes.h:145
Utf8EncodedCharLen
static int8 Utf8EncodedCharLen(char c)
Return the length of an UTF-8 encoded value based on a single char.
Definition: string_func.h:128
TextRefStack
Definition: newgrf_text.cpp:709