src/newgrf_text.cpp
author rubidium
Thu, 18 Dec 2008 12:23:08 +0000
changeset 10436 8d3a9fbe8f19
parent 10135 21b4050a479b
permissions -rw-r--r--
(svn r14689) -Change: make configure die on commonly made user mistakes, like not having SDL development files or zlib headers installed; you can still compile a dedicated server or a binary without zlib, but you have to explicitly force it.
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
     1
/* $Id$ */
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
     2
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6248
diff changeset
     3
/** @file newgrf_text.cpp
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
     4
 * Implementation of  Action 04 "universal holder" structure and functions.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
     5
 * This file implements a linked-lists of strings,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
     6
 * holding everything that the newgrf action 04 will send over to OpenTTD.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
     7
 * One of the biggest problems is that Dynamic lang Array uses ISO codes
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
     8
 * as way to identifying current user lang, while newgrf uses bit shift codes
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
     9
 * not related to ISO.  So equivalence functionnality had to be set.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    10
 */
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    11
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    12
#include "stdafx.h"
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    13
#include "debug.h"
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    14
#include "openttd.h"
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    15
#include "variables.h"
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5344
diff changeset
    16
#include "newgrf.h"
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    17
#include "newgrf_text.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8113
diff changeset
    18
#include "strings_func.h"
8213
7bdd7593eb9b (svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium
parents: 8140
diff changeset
    19
#include "core/alloc_func.hpp"
7bdd7593eb9b (svn r11776) -Codechange: more header splittings to reduce the dependencies.
rubidium
parents: 8140
diff changeset
    20
#include "newgrf_storage.h"
8214
971f861d5543 (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8213
diff changeset
    21
#include "string_func.h"
8787
41d9d5adbe87 (svn r12495) -Codechange: reduce the dependency on newgrf_station.h (especially because newgrf_station.h includes a lot of stuff).
rubidium
parents: 8784
diff changeset
    22
#include "date_type.h"
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    23
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8214
diff changeset
    24
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8214
diff changeset
    25
#include "table/control_codes.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8214
diff changeset
    26
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    27
#define GRFTAB  28
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    28
#define TABSIZE 11
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    29
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    30
/**
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    31
 * Explains the newgrf shift bit positionning.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    32
 * the grf base will not be used in order to find the string, but rather for
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    33
 * jumping from standard langID scheme to the new one.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    34
 */
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    35
enum grf_base_languages {
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    36
	GRFLB_AMERICAN    = 0x01,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    37
	GRFLB_ENGLISH     = 0x02,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    38
	GRFLB_GERMAN      = 0x04,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    39
	GRFLB_FRENCH      = 0x08,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    40
	GRFLB_SPANISH     = 0x10,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    41
	GRFLB_GENERIC     = 0x80,
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    42
};
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    43
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    44
enum grf_extended_languages {
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    45
	GRFLX_AMERICAN    = 0x00,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    46
	GRFLX_ENGLISH     = 0x01,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    47
	GRFLX_GERMAN      = 0x02,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    48
	GRFLX_FRENCH      = 0x03,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    49
	GRFLX_SPANISH     = 0x04,
6564
07bd66a5d176 (svn r9769) [newGRF] -Feature: Add translation support for Esperanto, Bulgarian, Japanese and Korean
belugas
parents: 6481
diff changeset
    50
	GRFLX_ESPERANTO   = 0x05,
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    51
	GRFLX_RUSSIAN     = 0x07,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    52
	GRFLX_CZECH       = 0x15,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    53
	GRFLX_SLOVAK      = 0x16,
6564
07bd66a5d176 (svn r9769) [newGRF] -Feature: Add translation support for Esperanto, Bulgarian, Japanese and Korean
belugas
parents: 6481
diff changeset
    54
	GRFLX_BULGARIAN   = 0x18,
3856
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    55
	GRFLX_AFRIKAANS   = 0x1B,
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    56
	GRFLX_GREEK       = 0x1E,
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
    57
	GRFLX_DUTCH       = 0x1F,
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    58
	GRFLX_CATALAN     = 0x22,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    59
	GRFLX_HUNGARIAN   = 0x24,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    60
	GRFLX_ITALIAN     = 0x27,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    61
	GRFLX_ROMANIAN    = 0x28,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    62
	GRFLX_ICELANDIC   = 0x29,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    63
	GRFLX_LATVIAN     = 0x2A,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    64
	GRFLX_LITHUANIAN  = 0x2B,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    65
	GRFLX_SLOVENIAN   = 0x2C,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    66
	GRFLX_DANISH      = 0x2D,
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
    67
	GRFLX_SWEDISH     = 0x2E,
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    68
	GRFLX_NORWEGIAN   = 0x2F,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    69
	GRFLX_POLISH      = 0x30,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    70
	GRFLX_GALICIAN    = 0x31,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    71
	GRFLX_FRISIAN     = 0x32,
3856
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    72
	GRFLX_UKRAINIAN   = 0x33,
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    73
	GRFLX_ESTONIAN    = 0x34,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    74
	GRFLX_FINNISH     = 0x35,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    75
	GRFLX_PORTUGUESE  = 0x36,
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
    76
	GRFLX_BRAZILIAN   = 0x37,
3856
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    77
	GRFLX_CROATIAN    = 0x38,
6564
07bd66a5d176 (svn r9769) [newGRF] -Feature: Add translation support for Esperanto, Bulgarian, Japanese and Korean
belugas
parents: 6481
diff changeset
    78
	GRFLX_JAPANESE    = 0x39,
07bd66a5d176 (svn r9769) [newGRF] -Feature: Add translation support for Esperanto, Bulgarian, Japanese and Korean
belugas
parents: 6481
diff changeset
    79
	GRFLX_KOREAN      = 0x3A,
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    80
	GRFLX_TURKISH     = 0x3E,
3641
88699e48a03e (svn r4550) - NewGRF: update string system to new rules: a grf version of less than 6 uses the old scheme, of 7 or more uses the new scheme. (Moving targets, yay...)
peter1138
parents: 3630
diff changeset
    81
	GRFLX_UNSPECIFIED = 0x7F,
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    82
};
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    83
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    84
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    85
struct iso_grf {
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    86
	char code[6];
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    87
	byte grfLangID;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    88
};
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    89
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    90
/**
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    91
 * ISO code VS NewGrf langID conversion array.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    92
 * This array is used in two ways:
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    93
 * 1-its ISO part is matching OpenTTD dynamic language id
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    94
 *   with newgrf bit positionning language id
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    95
 * 2-its shift part is used to know what is the shift to
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    96
 *   watch for when inserting new strings, hence analysing newgrf langid
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    97
 */
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
    98
const iso_grf iso_codes[] = {
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    99
	{"en_US", GRFLX_AMERICAN},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   100
	{"en_GB", GRFLX_ENGLISH},
3856
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   101
	{"de_DE", GRFLX_GERMAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   102
	{"fr_FR", GRFLX_FRENCH},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   103
	{"es_ES", GRFLX_SPANISH},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   104
	{"af_ZA", GRFLX_AFRIKAANS},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   105
	{"hr_HR", GRFLX_CROATIAN},
7437
27551f746064 (svn r10877) -Fix: some isocodes were wrong
glx
parents: 6887
diff changeset
   106
	{"cs_CZ", GRFLX_CZECH},
3856
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   107
	{"ca_ES", GRFLX_CATALAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   108
	{"da_DA", GRFLX_DANISH},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   109
	{"nl_NL", GRFLX_DUTCH},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   110
	{"et_ET", GRFLX_ESTONIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   111
	{"fi_FI", GRFLX_FINNISH},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   112
	{"fy_NL", GRFLX_FRISIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   113
	{"gl_ES", GRFLX_GALICIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   114
	{"el_GR", GRFLX_GREEK},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   115
	{"hu_HU", GRFLX_HUNGARIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   116
	{"is_IS", GRFLX_ICELANDIC},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   117
	{"it_IT", GRFLX_ITALIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   118
	{"lv_LV", GRFLX_LATVIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   119
	{"lt_LT", GRFLX_LITHUANIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   120
	{"nb_NO", GRFLX_NORWEGIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   121
	{"pl_PL", GRFLX_POLISH},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   122
	{"pt_PT", GRFLX_PORTUGUESE},
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   123
	{"pt_BR", GRFLX_BRAZILIAN},
3856
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   124
	{"ro_RO", GRFLX_ROMANIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   125
	{"ru_RU", GRFLX_RUSSIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   126
	{"sk_SK", GRFLX_SLOVAK},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   127
	{"sl_SL", GRFLX_SLOVENIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   128
	{"sv_SE", GRFLX_SWEDISH},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   129
	{"tr_TR", GRFLX_TURKISH},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   130
	{"uk_UA", GRFLX_UKRAINIAN},
6564
07bd66a5d176 (svn r9769) [newGRF] -Feature: Add translation support for Esperanto, Bulgarian, Japanese and Korean
belugas
parents: 6481
diff changeset
   131
	{"eo_EO", GRFLX_ESPERANTO},
07bd66a5d176 (svn r9769) [newGRF] -Feature: Add translation support for Esperanto, Bulgarian, Japanese and Korean
belugas
parents: 6481
diff changeset
   132
	{"bg_BG", GRFLX_BULGARIAN},
07bd66a5d176 (svn r9769) [newGRF] -Feature: Add translation support for Esperanto, Bulgarian, Japanese and Korean
belugas
parents: 6481
diff changeset
   133
	{"ja_JP", GRFLX_JAPANESE},
07bd66a5d176 (svn r9769) [newGRF] -Feature: Add translation support for Esperanto, Bulgarian, Japanese and Korean
belugas
parents: 6481
diff changeset
   134
	{"ko_KR", GRFLX_KOREAN},
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6248
diff changeset
   135
	{"gen",   GRFLB_GENERIC}   ///< this is not iso code, but there has to be something...
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   136
};
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   137
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   138
4305
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   139
/**
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   140
 * Element of the linked list.
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   141
 * Each of those elements represent the string,
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   142
 * but according to a different lang.
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   143
 */
5655
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   144
struct GRFText {
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   145
	public:
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   146
		static GRFText* New(byte langid, const char* text)
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   147
		{
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   148
			return new(strlen(text) + 1) GRFText(langid, text);
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   149
		}
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   150
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   151
	private:
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   152
		GRFText(byte langid_, const char* text_) : next(NULL), langid(langid_)
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   153
		{
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   154
			strcpy(text, text_);
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   155
		}
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   156
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   157
		void* operator new(size_t size, size_t extra)
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   158
		{
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   159
			return ::operator new(size + extra);
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   160
		}
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   161
5657
0d1c1303bb94 (svn r8117) -Fix (r8114): 'no matching operator delete found' warning on VC8
KUDr
parents: 5655
diff changeset
   162
public:
0d1c1303bb94 (svn r8117) -Fix (r8114): 'no matching operator delete found' warning on VC8
KUDr
parents: 5655
diff changeset
   163
		/* dummy operator delete to silence VC8:
0d1c1303bb94 (svn r8117) -Fix (r8114): 'no matching operator delete found' warning on VC8
KUDr
parents: 5655
diff changeset
   164
		 * 'void *GRFText::operator new(size_t,size_t)' : no matching operator delete found;
0d1c1303bb94 (svn r8117) -Fix (r8114): 'no matching operator delete found' warning on VC8
KUDr
parents: 5655
diff changeset
   165
		 *     memory will not be freed if initialization throws an exception */
0d1c1303bb94 (svn r8117) -Fix (r8114): 'no matching operator delete found' warning on VC8
KUDr
parents: 5655
diff changeset
   166
		void operator delete(void *p, size_t extra)
0d1c1303bb94 (svn r8117) -Fix (r8114): 'no matching operator delete found' warning on VC8
KUDr
parents: 5655
diff changeset
   167
		{
0d1c1303bb94 (svn r8117) -Fix (r8114): 'no matching operator delete found' warning on VC8
KUDr
parents: 5655
diff changeset
   168
			return ::operator delete(p);
0d1c1303bb94 (svn r8117) -Fix (r8114): 'no matching operator delete found' warning on VC8
KUDr
parents: 5655
diff changeset
   169
		}
0d1c1303bb94 (svn r8117) -Fix (r8114): 'no matching operator delete found' warning on VC8
KUDr
parents: 5655
diff changeset
   170
5655
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   171
	public:
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   172
		GRFText *next;
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   173
		byte langid;
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   174
		char text[VARARRAY_SIZE];
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   175
};
4305
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   176
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   177
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   178
/**
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   179
 * Holder of the above structure.
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   180
 * Putting both grfid and stringid together allows us to avoid duplicates,
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   181
 * since it is NOT SUPPOSED to happen.
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   182
 */
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   183
struct GRFTextEntry {
4305
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   184
	uint32 grfid;
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   185
	uint16 stringid;
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   186
	StringID def_string;
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   187
	GRFText *textholder;
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   188
};
4305
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   189
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   190
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   191
static uint _num_grf_texts = 0;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   192
static GRFTextEntry _grf_text[(1 << TABSIZE) * 3];
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6248
diff changeset
   193
static byte _currentLangID = GRFLX_ENGLISH;  ///< by default, english is used.
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   194
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   195
8656
9731ddde8722 (svn r12317) -Fix [FS#1815]: Map string IDs that are embedded from other strings.
peter1138
parents: 8445
diff changeset
   196
char *TranslateTTDPatchCodes(uint32 grfid, const char *str)
3646
291be46d399e (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   197
{
6348
6dd01da7a02b (svn r9385) -Cleanup: doxygen changes. Today, we are exploring the letter N.
belugas
parents: 6248
diff changeset
   198
	char *tmp = MallocT<char>(strlen(str) * 10 + 1); // Allocate space to allow for expansion
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   199
	char *d = tmp;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   200
	bool unicode = false;
5208
3875a79e5596 (svn r7323) -Fix (r7182): When translating NewGRF strings, look at the first
peter1138
parents: 5204
diff changeset
   201
	WChar c;
3875a79e5596 (svn r7323) -Fix (r7182): When translating NewGRF strings, look at the first
peter1138
parents: 5204
diff changeset
   202
	size_t len = Utf8Decode(&c, str);
3646
291be46d399e (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   203
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   204
	if (c == 0x00DE) {
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   205
		/* The thorn ('þ') indicates a unicode string to TTDPatch */
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   206
		unicode = true;
5208
3875a79e5596 (svn r7323) -Fix (r7182): When translating NewGRF strings, look at the first
peter1138
parents: 5204
diff changeset
   207
		str += len;
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   208
	}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   209
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   210
	for (;;) {
8061
47fa9f69cea8 (svn r11622) -Codechange: support the unicode version of the 'control' characters.
rubidium
parents: 7755
diff changeset
   211
		if (unicode && Utf8EncodedCharLen(*str) != 0) {
47fa9f69cea8 (svn r11622) -Codechange: support the unicode version of the 'control' characters.
rubidium
parents: 7755
diff changeset
   212
			c = Utf8Consume(&str);
47fa9f69cea8 (svn r11622) -Codechange: support the unicode version of the 'control' characters.
rubidium
parents: 7755
diff changeset
   213
			/* 'Magic' range of control codes. */
47fa9f69cea8 (svn r11622) -Codechange: support the unicode version of the 'control' characters.
rubidium
parents: 7755
diff changeset
   214
			if (GB(c, 8, 8) == 0xE0) c = GB(c, 0, 8);
47fa9f69cea8 (svn r11622) -Codechange: support the unicode version of the 'control' characters.
rubidium
parents: 7755
diff changeset
   215
		} else {
47fa9f69cea8 (svn r11622) -Codechange: support the unicode version of the 'control' characters.
rubidium
parents: 7755
diff changeset
   216
			c = (byte)*str++;
47fa9f69cea8 (svn r11622) -Codechange: support the unicode version of the 'control' characters.
rubidium
parents: 7755
diff changeset
   217
		}
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   218
		if (c == 0) break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   219
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   220
		switch (c) {
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   221
			case 0x01:
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   222
				d += Utf8Encode(d, SCC_SETX);
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   223
				*d++ = *str++;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   224
				break;
5344
7d75e667692a (svn r7515) -Codechange [newgrf]: Ignore ascii code 0x0A in text. Newline is 0x0D.
Darkvater
parents: 5228
diff changeset
   225
			case 0x0A: break;
7d75e667692a (svn r7515) -Codechange [newgrf]: Ignore ascii code 0x0A in text. Newline is 0x0D.
Darkvater
parents: 5228
diff changeset
   226
			case 0x0D: *d++ = 0x0A; break;
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   227
			case 0x0E: d += Utf8Encode(d, SCC_TINYFONT); break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   228
			case 0x0F: d += Utf8Encode(d, SCC_BIGFONT); break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   229
			case 0x1F:
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   230
				d += Utf8Encode(d, SCC_SETXY);
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   231
				*d++ = *str++;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   232
				*d++ = *str++;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   233
				break;
3646
291be46d399e (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   234
			case 0x7B:
291be46d399e (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   235
			case 0x7C:
291be46d399e (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   236
			case 0x7D:
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   237
			case 0x7E:
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   238
			case 0x7F:
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   239
			case 0x80: d += Utf8Encode(d, SCC_NEWGRF_PRINT_DWORD + c - 0x7B); break;
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   240
			case 0x81: {
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   241
				StringID string;
9932
510b6b701877 (svn r14087) -Fix [FS#2228]: flawed parsing of words (as in 2 bytes) in GRF strings due to sign extension (minime)
rubidium
parents: 9907
diff changeset
   242
				string  = ((uint8)*str++);
510b6b701877 (svn r14087) -Fix [FS#2228]: flawed parsing of words (as in 2 bytes) in GRF strings due to sign extension (minime)
rubidium
parents: 9907
diff changeset
   243
				string |= ((uint8)*str++) << 8;
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   244
				d += Utf8Encode(d, SCC_STRING_ID);
8656
9731ddde8722 (svn r12317) -Fix [FS#1815]: Map string IDs that are embedded from other strings.
peter1138
parents: 8445
diff changeset
   245
				d += Utf8Encode(d, MapGRFStringID(grfid, string));
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   246
				break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   247
			}
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   248
			case 0x82:
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   249
			case 0x83:
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   250
			case 0x84: d += Utf8Encode(d, SCC_NEWGRF_PRINT_WORD_SPEED + c - 0x82); break;
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   251
			case 0x85: d += Utf8Encode(d, SCC_NEWGRF_DISCARD_WORD);       break;
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   252
			case 0x86: d += Utf8Encode(d, SCC_NEWGRF_ROTATE_TOP_4_WORDS); break;
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   253
			case 0x87: d += Utf8Encode(d, SCC_NEWGRF_PRINT_WORD_LITRES);  break;
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   254
			case 0x88: d += Utf8Encode(d, SCC_BLUE);    break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   255
			case 0x89: d += Utf8Encode(d, SCC_SILVER);  break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   256
			case 0x8A: d += Utf8Encode(d, SCC_GOLD);    break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   257
			case 0x8B: d += Utf8Encode(d, SCC_RED);     break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   258
			case 0x8C: d += Utf8Encode(d, SCC_PURPLE);  break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   259
			case 0x8D: d += Utf8Encode(d, SCC_LTBROWN); break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   260
			case 0x8E: d += Utf8Encode(d, SCC_ORANGE);  break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   261
			case 0x8F: d += Utf8Encode(d, SCC_GREEN);   break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   262
			case 0x90: d += Utf8Encode(d, SCC_YELLOW);  break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   263
			case 0x91: d += Utf8Encode(d, SCC_DKGREEN); break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   264
			case 0x92: d += Utf8Encode(d, SCC_CREAM);   break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   265
			case 0x93: d += Utf8Encode(d, SCC_BROWN);   break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   266
			case 0x94: d += Utf8Encode(d, SCC_WHITE);   break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   267
			case 0x95: d += Utf8Encode(d, SCC_LTBLUE);  break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   268
			case 0x96: d += Utf8Encode(d, SCC_GRAY);    break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   269
			case 0x97: d += Utf8Encode(d, SCC_DKBLUE);  break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   270
			case 0x98: d += Utf8Encode(d, SCC_BLACK);   break;
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   271
			case 0x9A:
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   272
				switch (*str++) {
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   273
					case 0: /* FALL THROUGH */
9932
510b6b701877 (svn r14087) -Fix [FS#2228]: flawed parsing of words (as in 2 bytes) in GRF strings due to sign extension (minime)
rubidium
parents: 9907
diff changeset
   274
					case 1:
510b6b701877 (svn r14087) -Fix [FS#2228]: flawed parsing of words (as in 2 bytes) in GRF strings due to sign extension (minime)
rubidium
parents: 9907
diff changeset
   275
						d += Utf8Encode(d, SCC_NEWGRF_PRINT_QWORD_CURRENCY);
510b6b701877 (svn r14087) -Fix [FS#2228]: flawed parsing of words (as in 2 bytes) in GRF strings due to sign extension (minime)
rubidium
parents: 9907
diff changeset
   276
						break;
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   277
					case 3: {
9932
510b6b701877 (svn r14087) -Fix [FS#2228]: flawed parsing of words (as in 2 bytes) in GRF strings due to sign extension (minime)
rubidium
parents: 9907
diff changeset
   278
						uint16 tmp  = ((uint8)*str++);
510b6b701877 (svn r14087) -Fix [FS#2228]: flawed parsing of words (as in 2 bytes) in GRF strings due to sign extension (minime)
rubidium
parents: 9907
diff changeset
   279
						tmp        |= ((uint8)*str++) << 8;
510b6b701877 (svn r14087) -Fix [FS#2228]: flawed parsing of words (as in 2 bytes) in GRF strings due to sign extension (minime)
rubidium
parents: 9907
diff changeset
   280
						d += Utf8Encode(d, SCC_NEWGRF_PUSH_WORD);
510b6b701877 (svn r14087) -Fix [FS#2228]: flawed parsing of words (as in 2 bytes) in GRF strings due to sign extension (minime)
rubidium
parents: 9907
diff changeset
   281
						d += Utf8Encode(d, tmp);
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   282
					} break;
9932
510b6b701877 (svn r14087) -Fix [FS#2228]: flawed parsing of words (as in 2 bytes) in GRF strings due to sign extension (minime)
rubidium
parents: 9907
diff changeset
   283
					case 4:
510b6b701877 (svn r14087) -Fix [FS#2228]: flawed parsing of words (as in 2 bytes) in GRF strings due to sign extension (minime)
rubidium
parents: 9907
diff changeset
   284
						d += Utf8Encode(d, SCC_NEWGRF_UNPRINT);
510b6b701877 (svn r14087) -Fix [FS#2228]: flawed parsing of words (as in 2 bytes) in GRF strings due to sign extension (minime)
rubidium
parents: 9907
diff changeset
   285
						d += Utf8Encode(d, *str++);
510b6b701877 (svn r14087) -Fix [FS#2228]: flawed parsing of words (as in 2 bytes) in GRF strings due to sign extension (minime)
rubidium
parents: 9907
diff changeset
   286
						break;
10135
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 9932
diff changeset
   287
					case 6:
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 9932
diff changeset
   288
						d += Utf8Encode(d, SCC_NEWGRF_PRINT_HEX_BYTE);
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 9932
diff changeset
   289
						break;
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 9932
diff changeset
   290
					case 7:
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 9932
diff changeset
   291
						d += Utf8Encode(d, SCC_NEWGRF_PRINT_HEX_WORD);
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 9932
diff changeset
   292
						break;
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 9932
diff changeset
   293
					case 8:
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 9932
diff changeset
   294
						d += Utf8Encode(d, SCC_NEWGRF_PRINT_HEX_DWORD);
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 9932
diff changeset
   295
						break;
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 9932
diff changeset
   296
9932
510b6b701877 (svn r14087) -Fix [FS#2228]: flawed parsing of words (as in 2 bytes) in GRF strings due to sign extension (minime)
rubidium
parents: 9907
diff changeset
   297
					default:
510b6b701877 (svn r14087) -Fix [FS#2228]: flawed parsing of words (as in 2 bytes) in GRF strings due to sign extension (minime)
rubidium
parents: 9907
diff changeset
   298
						grfmsg(1, "missing handler for extended format code");
510b6b701877 (svn r14087) -Fix [FS#2228]: flawed parsing of words (as in 2 bytes) in GRF strings due to sign extension (minime)
rubidium
parents: 9907
diff changeset
   299
						break;
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   300
				}
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   301
				break;
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   302
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   303
			case 0x9E: d += Utf8Encode(d, 0x20AC); break; // Euro
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   304
			case 0x9F: d += Utf8Encode(d, 0x0178); break; // Y with diaeresis
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   305
			case 0xA0: d += Utf8Encode(d, SCC_UPARROW); break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   306
			case 0xAA: d += Utf8Encode(d, SCC_DOWNARROW); break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   307
			case 0xAC: d += Utf8Encode(d, SCC_CHECKMARK); break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   308
			case 0xAD: d += Utf8Encode(d, SCC_CROSS); break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   309
			case 0xAF: d += Utf8Encode(d, SCC_RIGHTARROW); break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   310
			case 0xB4: d += Utf8Encode(d, SCC_TRAIN); break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   311
			case 0xB5: d += Utf8Encode(d, SCC_LORRY); break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   312
			case 0xB6: d += Utf8Encode(d, SCC_BUS); break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   313
			case 0xB7: d += Utf8Encode(d, SCC_PLANE); break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   314
			case 0xB8: d += Utf8Encode(d, SCC_SHIP); break;
8411
591f0c085e10 (svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138
parents: 8264
diff changeset
   315
			case 0xB9: d += Utf8Encode(d, SCC_SUPERSCRIPT_M1); break;
591f0c085e10 (svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138
parents: 8264
diff changeset
   316
			case 0xBC: d += Utf8Encode(d, SCC_SMALLUPARROW); break;
591f0c085e10 (svn r11981) -Fix [FS#1698]: Use unicode glyph mapping to fix up missing/shuffled sprites in original data files instead of shuffling or skipping
peter1138
parents: 8264
diff changeset
   317
			case 0xBD: d += Utf8Encode(d, SCC_SMALLDOWNARROW); break;
3646
291be46d399e (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   318
			default:
291be46d399e (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   319
				/* Validate any unhandled character */
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   320
				if (!IsValidChar(c, CS_ALPHANUMERAL)) c = '?';
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   321
				d += Utf8Encode(d, c);
3646
291be46d399e (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   322
				break;
291be46d399e (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   323
		}
291be46d399e (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   324
	}
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   325
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   326
	*d = '\0';
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5587
diff changeset
   327
	tmp = ReallocT(tmp, strlen(tmp) + 1);
5587
167d9a91ef02 (svn r8038) -Merge: the cpp branch. Effort of KUDr, Celestar, glx, Smoovius, stillunknown and pv2b.
rubidium
parents: 5584
diff changeset
   328
	return tmp;
3646
291be46d399e (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   329
}
291be46d399e (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   330
291be46d399e (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   331
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   332
/**
3641
88699e48a03e (svn r4550) - NewGRF: update string system to new rules: a grf version of less than 6 uses the old scheme, of 7 or more uses the new scheme. (Moving targets, yay...)
peter1138
parents: 3630
diff changeset
   333
 * Add the new read string into our structure.
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   334
 */
3821
57db5bab0f24 (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3646
diff changeset
   335
StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool new_scheme, const char *text_to_add, StringID def_string)
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   336
{
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   337
	char *translatedtext;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   338
	uint id;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   339
3641
88699e48a03e (svn r4550) - NewGRF: update string system to new rules: a grf version of less than 6 uses the old scheme, of 7 or more uses the new scheme. (Moving targets, yay...)
peter1138
parents: 3630
diff changeset
   340
	/* When working with the old language scheme (grf_version is less than 7) and
3603
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   341
	 * English or American is among the set bits, simply add it as English in
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   342
	 * the new scheme, i.e. as langid = 1.
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   343
	 * If English is set, it is pretty safe to assume the translations are not
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   344
	 * actually translated.
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   345
	 */
3641
88699e48a03e (svn r4550) - NewGRF: update string system to new rules: a grf version of less than 6 uses the old scheme, of 7 or more uses the new scheme. (Moving targets, yay...)
peter1138
parents: 3630
diff changeset
   346
	if (!new_scheme) {
3603
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   347
		if (HASBITS(langid_to_add, GRFLB_AMERICAN | GRFLB_ENGLISH)) {
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   348
			langid_to_add = GRFLX_ENGLISH;
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   349
		} else {
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   350
			StringID ret = STR_EMPTY;
5047
05c7e74ff3e5 (svn r7096) -Fix (r6995 (sort-of)): Don't set bit 6 when convert grf ver 6 language ids to use ver 7 format
peter1138
parents: 4992
diff changeset
   351
			if (langid_to_add & GRFLB_GERMAN)  ret = AddGRFString(grfid, stringid, GRFLX_GERMAN,  true, text_to_add, def_string);
05c7e74ff3e5 (svn r7096) -Fix (r6995 (sort-of)): Don't set bit 6 when convert grf ver 6 language ids to use ver 7 format
peter1138
parents: 4992
diff changeset
   352
			if (langid_to_add & GRFLB_FRENCH)  ret = AddGRFString(grfid, stringid, GRFLX_FRENCH,  true, text_to_add, def_string);
05c7e74ff3e5 (svn r7096) -Fix (r6995 (sort-of)): Don't set bit 6 when convert grf ver 6 language ids to use ver 7 format
peter1138
parents: 4992
diff changeset
   353
			if (langid_to_add & GRFLB_SPANISH) ret = AddGRFString(grfid, stringid, GRFLX_SPANISH, true, text_to_add, def_string);
3603
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   354
			return ret;
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   355
		}
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   356
	}
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   357
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   358
	for (id = 0; id < _num_grf_texts; id++) {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   359
		if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   360
			break;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   361
		}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   362
	}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   363
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   364
	/* Too many strings allocated, return empty */
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   365
	if (id == lengthof(_grf_text)) return STR_EMPTY;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   366
8656
9731ddde8722 (svn r12317) -Fix [FS#1815]: Map string IDs that are embedded from other strings.
peter1138
parents: 8445
diff changeset
   367
	translatedtext = TranslateTTDPatchCodes(grfid, text_to_add);
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   368
5655
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   369
	GRFText *newtext = GRFText::New(langid_to_add, translatedtext);
3856
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   370
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   371
	free(translatedtext);
3856
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   372
3603
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   373
	/* If we didn't find our stringid and grfid in the list, allocate a new id */
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   374
	if (id == _num_grf_texts) _num_grf_texts++;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   375
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   376
	if (_grf_text[id].textholder == NULL) {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   377
		_grf_text[id].grfid      = grfid;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   378
		_grf_text[id].stringid   = stringid;
3821
57db5bab0f24 (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3646
diff changeset
   379
		_grf_text[id].def_string = def_string;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   380
		_grf_text[id].textholder = newtext;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   381
	} else {
4711
28fbbec5f258 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   382
		GRFText **ptext, *text;
28fbbec5f258 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   383
		bool replaced = false;
28fbbec5f258 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   384
28fbbec5f258 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   385
		/* Loop through all languages and see if we can replace a string */
28fbbec5f258 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   386
		for (ptext = &_grf_text[id].textholder; (text = *ptext) != NULL; ptext = &text->next) {
4992
bd2716c79584 (svn r6995) - Codechange: NewGRF; strip bit 7 of the language ID earlier and handle handle a language ID of 0x7F as the preferred default language.
peter1138
parents: 4915
diff changeset
   387
			if (text->langid != langid_to_add) continue;
4711
28fbbec5f258 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   388
			newtext->next = text->next;
28fbbec5f258 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   389
			*ptext = newtext;
5655
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   390
			delete text;
4711
28fbbec5f258 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   391
			replaced = true;
28fbbec5f258 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   392
			break;
28fbbec5f258 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   393
		}
28fbbec5f258 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   394
28fbbec5f258 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   395
		/* If a string wasn't replaced, then we must append the new string */
28fbbec5f258 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   396
		if (!replaced) *ptext = newtext;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   397
	}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   398
5380
8ea58542b6e0 (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5344
diff changeset
   399
	grfmsg(3, "Added 0x%X: grfid %08X string 0x%X lang 0x%X string '%s'", id, grfid, stringid, newtext->langid, newtext->text);
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   400
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   401
	return (GRFTAB << TABSIZE) + id;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   402
}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   403
4710
1aa2b507818f (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4624
diff changeset
   404
/* Used to remember the grfid that the last retrieved string came from */
1aa2b507818f (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4624
diff changeset
   405
static uint32 _last_grfid = 0;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   406
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   407
/**
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   408
 * Returns the index for this stringid associated with its grfID
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   409
 */
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   410
StringID GetGRFStringID(uint32 grfid, uint16 stringid)
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   411
{
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   412
	uint id;
4710
1aa2b507818f (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4624
diff changeset
   413
1aa2b507818f (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4624
diff changeset
   414
	/* grfid is zero when we're being called via an include */
1aa2b507818f (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4624
diff changeset
   415
	if (grfid == 0) grfid = _last_grfid;
1aa2b507818f (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4624
diff changeset
   416
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   417
	for (id = 0; id < _num_grf_texts; id++) {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   418
		if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   419
			return (GRFTAB << TABSIZE) + id;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   420
		}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   421
	}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   422
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   423
	return STR_UNDEFINED;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   424
}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   425
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   426
8445
54a5d84d1d7d (svn r12015) -Fix [FS#1716] (Revert r11422): Patch in FS#1430 avoided instead of fixed the problem. GetStringWithArgs() discards information that SCC_GENDER_LIST needs to work. Now use pointers to retrieve GRF strings, so that GetStringPtr() will work correctly. This is advantageous as now no buffer copy is made when using all GRF strings.
peter1138
parents: 8411
diff changeset
   427
const char *GetGRFStringPtr(uint16 stringid)
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   428
{
4305
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   429
	const GRFText *default_text = NULL;
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   430
	const GRFText *search_text;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   431
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   432
	assert(_grf_text[stringid].grfid != 0);
4710
1aa2b507818f (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4624
diff changeset
   433
1aa2b507818f (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4624
diff changeset
   434
	/* Remember this grfid in case the string has included text */
1aa2b507818f (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4624
diff changeset
   435
	_last_grfid = _grf_text[stringid].grfid;
1aa2b507818f (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4624
diff changeset
   436
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   437
	/*Search the list of lang-strings of this stringid for current lang */
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   438
	for (search_text = _grf_text[stringid].textholder; search_text != NULL; search_text = search_text->next) {
3821
57db5bab0f24 (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3646
diff changeset
   439
		if (search_text->langid == _currentLangID) {
8445
54a5d84d1d7d (svn r12015) -Fix [FS#1716] (Revert r11422): Patch in FS#1430 avoided instead of fixed the problem. GetStringWithArgs() discards information that SCC_GENDER_LIST needs to work. Now use pointers to retrieve GRF strings, so that GetStringPtr() will work correctly. This is advantageous as now no buffer copy is made when using all GRF strings.
peter1138
parents: 8411
diff changeset
   440
			return search_text->text;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   441
		}
3821
57db5bab0f24 (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3646
diff changeset
   442
57db5bab0f24 (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3646
diff changeset
   443
		/* If the current string is English or American, set it as the
57db5bab0f24 (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3646
diff changeset
   444
		 * fallback language if the specific language isn't available. */
4992
bd2716c79584 (svn r6995) - Codechange: NewGRF; strip bit 7 of the language ID earlier and handle handle a language ID of 0x7F as the preferred default language.
peter1138
parents: 4915
diff changeset
   445
		if (search_text->langid == GRFLX_UNSPECIFIED || (default_text == NULL && (search_text->langid == GRFLX_ENGLISH || search_text->langid == GRFLX_AMERICAN))) {
3821
57db5bab0f24 (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3646
diff changeset
   446
			default_text = search_text;
57db5bab0f24 (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3646
diff changeset
   447
		}
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   448
	}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   449
3821
57db5bab0f24 (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3646
diff changeset
   450
	/* If there is a fallback string, return that */
8445
54a5d84d1d7d (svn r12015) -Fix [FS#1716] (Revert r11422): Patch in FS#1430 avoided instead of fixed the problem. GetStringWithArgs() discards information that SCC_GENDER_LIST needs to work. Now use pointers to retrieve GRF strings, so that GetStringPtr() will work correctly. This is advantageous as now no buffer copy is made when using all GRF strings.
peter1138
parents: 8411
diff changeset
   451
	if (default_text != NULL) return default_text->text;
3821
57db5bab0f24 (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3646
diff changeset
   452
57db5bab0f24 (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3646
diff changeset
   453
	/* Use the default string ID if the fallback string isn't available */
8445
54a5d84d1d7d (svn r12015) -Fix [FS#1716] (Revert r11422): Patch in FS#1430 avoided instead of fixed the problem. GetStringWithArgs() discards information that SCC_GENDER_LIST needs to work. Now use pointers to retrieve GRF strings, so that GetStringPtr() will work correctly. This is advantageous as now no buffer copy is made when using all GRF strings.
peter1138
parents: 8411
diff changeset
   454
	return GetStringPtr(_grf_text[stringid].def_string);
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   455
}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   456
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   457
/**
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   458
 * Equivalence Setter function between game and newgrf langID.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   459
 * This function will adjust _currentLangID as to what is the LangID
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   460
 * of the current language set by the user.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   461
 * The array iso_codes will be used to find that match.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   462
 * If not found, it will have to be standard english
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   463
 * This function is called after the user changed language,
6481
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6348
diff changeset
   464
 * from strings.cpp:ReadLanguagePack
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6348
diff changeset
   465
 * @param iso_name iso code of current selection
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   466
 */
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   467
void SetCurrentGrfLangID(const char *iso_name)
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   468
{
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   469
	/* Use English by default, if we can't match up the iso_code. */
4305
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   470
	byte ret = GRFLX_ENGLISH;
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   471
	byte i;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   472
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   473
	for (i=0; i < lengthof(iso_codes); i++) {
3868
2de0afd113ff (svn r4905) - NewGRF: fix typo that prevented non-english NewGRF text from working.
peter1138
parents: 3856
diff changeset
   474
		if (strncmp(iso_codes[i].code, iso_name, strlen(iso_codes[i].code)) == 0) {
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   475
			/* We found a match, so let's use it. */
6887
6cda38027def (svn r10130) -Fix (r4493): SetCurrentGrfLangID returned the wrong language ids for most languages.
maedhros
parents: 6873
diff changeset
   476
			ret = iso_codes[i].grfLangID;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   477
			break;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   478
		}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   479
	}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   480
	_currentLangID = ret;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   481
}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   482
6873
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6564
diff changeset
   483
bool CheckGrfLangID(byte lang_id, byte grf_version)
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6564
diff changeset
   484
{
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6564
diff changeset
   485
	if (grf_version < 7) {
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6564
diff changeset
   486
		switch (_currentLangID) {
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6564
diff changeset
   487
			case GRFLX_GERMAN:  return (lang_id & GRFLB_GERMAN)  != 0;
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6564
diff changeset
   488
			case GRFLX_FRENCH:  return (lang_id & GRFLB_FRENCH)  != 0;
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6564
diff changeset
   489
			case GRFLX_SPANISH: return (lang_id & GRFLB_SPANISH) != 0;
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6564
diff changeset
   490
			default:            return (lang_id & (GRFLB_ENGLISH | GRFLB_AMERICAN)) != 0;
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6564
diff changeset
   491
		}
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6564
diff changeset
   492
	}
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6564
diff changeset
   493
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6564
diff changeset
   494
	return (lang_id == _currentLangID || lang_id == GRFLX_UNSPECIFIED);
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6564
diff changeset
   495
}
b4d0648edd29 (svn r10114) -Fix: Only load newgrf error messages if the language matches the current
maedhros
parents: 6564
diff changeset
   496
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   497
/**
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   498
 * House cleaning.
3602
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   499
 * Remove all strings and reset the text counter.
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   500
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 5657
diff changeset
   501
void CleanUpStrings()
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   502
{
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   503
	uint id;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   504
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   505
	for (id = 0; id < _num_grf_texts; id++) {
3602
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   506
		GRFText *grftext = _grf_text[id].textholder;
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   507
		while (grftext != NULL) {
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   508
			GRFText *grftext2 = grftext->next;
5655
bce99639ace0 (svn r8114) Allocate struct GRFText in the C++ way
tron
parents: 5609
diff changeset
   509
			delete grftext;
3602
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   510
			grftext = grftext2;
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   511
		}
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   512
		_grf_text[id].grfid      = 0;
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   513
		_grf_text[id].stringid   = 0;
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   514
		_grf_text[id].textholder = NULL;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   515
	}
3602
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   516
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   517
	_num_grf_texts = 0;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   518
}
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   519
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   520
struct TextRefStack {
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   521
	byte stack[0x30];
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   522
	byte position;
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   523
	bool used;
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   524
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   525
	TextRefStack() : used(false) {}
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   526
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   527
	uint8  PopUnsignedByte()  { assert(this->position < lengthof(this->stack)); return this->stack[this->position++]; }
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   528
	int8   PopSignedByte()    { return (int8)this->PopUnsignedByte(); }
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   529
8066
448c4e772893 (svn r11627) -Fix [FS#1532] (r11145): poping from text reference stack must be done in a precise order. But some compiler (MSVC) over optimised it and inverted this order.
glx
parents: 8061
diff changeset
   530
	uint16 PopUnsignedWord()
448c4e772893 (svn r11627) -Fix [FS#1532] (r11145): poping from text reference stack must be done in a precise order. But some compiler (MSVC) over optimised it and inverted this order.
glx
parents: 8061
diff changeset
   531
	{
448c4e772893 (svn r11627) -Fix [FS#1532] (r11145): poping from text reference stack must be done in a precise order. But some compiler (MSVC) over optimised it and inverted this order.
glx
parents: 8061
diff changeset
   532
		uint16 val = this->PopUnsignedByte();
448c4e772893 (svn r11627) -Fix [FS#1532] (r11145): poping from text reference stack must be done in a precise order. But some compiler (MSVC) over optimised it and inverted this order.
glx
parents: 8061
diff changeset
   533
		return val | (this->PopUnsignedByte() << 8);
448c4e772893 (svn r11627) -Fix [FS#1532] (r11145): poping from text reference stack must be done in a precise order. But some compiler (MSVC) over optimised it and inverted this order.
glx
parents: 8061
diff changeset
   534
	}
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   535
	int16  PopSignedWord()    { return (int32)this->PopUnsignedWord(); }
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   536
8066
448c4e772893 (svn r11627) -Fix [FS#1532] (r11145): poping from text reference stack must be done in a precise order. But some compiler (MSVC) over optimised it and inverted this order.
glx
parents: 8061
diff changeset
   537
	uint32 PopUnsignedDWord()
448c4e772893 (svn r11627) -Fix [FS#1532] (r11145): poping from text reference stack must be done in a precise order. But some compiler (MSVC) over optimised it and inverted this order.
glx
parents: 8061
diff changeset
   538
	{
448c4e772893 (svn r11627) -Fix [FS#1532] (r11145): poping from text reference stack must be done in a precise order. But some compiler (MSVC) over optimised it and inverted this order.
glx
parents: 8061
diff changeset
   539
		uint32 val = this->PopUnsignedWord();
448c4e772893 (svn r11627) -Fix [FS#1532] (r11145): poping from text reference stack must be done in a precise order. But some compiler (MSVC) over optimised it and inverted this order.
glx
parents: 8061
diff changeset
   540
		return val | (this->PopUnsignedWord() << 16);
448c4e772893 (svn r11627) -Fix [FS#1532] (r11145): poping from text reference stack must be done in a precise order. But some compiler (MSVC) over optimised it and inverted this order.
glx
parents: 8061
diff changeset
   541
	}
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   542
	int32  PopSignedDWord()   { return (int32)this->PopUnsignedDWord(); }
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   543
8066
448c4e772893 (svn r11627) -Fix [FS#1532] (r11145): poping from text reference stack must be done in a precise order. But some compiler (MSVC) over optimised it and inverted this order.
glx
parents: 8061
diff changeset
   544
	uint64 PopUnsignedQWord()
448c4e772893 (svn r11627) -Fix [FS#1532] (r11145): poping from text reference stack must be done in a precise order. But some compiler (MSVC) over optimised it and inverted this order.
glx
parents: 8061
diff changeset
   545
	{
448c4e772893 (svn r11627) -Fix [FS#1532] (r11145): poping from text reference stack must be done in a precise order. But some compiler (MSVC) over optimised it and inverted this order.
glx
parents: 8061
diff changeset
   546
		uint64 val = this->PopUnsignedDWord();
448c4e772893 (svn r11627) -Fix [FS#1532] (r11145): poping from text reference stack must be done in a precise order. But some compiler (MSVC) over optimised it and inverted this order.
glx
parents: 8061
diff changeset
   547
		return val | (((uint64)this->PopUnsignedDWord()) << 32);
448c4e772893 (svn r11627) -Fix [FS#1532] (r11145): poping from text reference stack must be done in a precise order. But some compiler (MSVC) over optimised it and inverted this order.
glx
parents: 8061
diff changeset
   548
	}
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   549
	int64  PopSignedQWord()   { return (int64)this->PopUnsignedQWord(); }
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   550
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   551
	/** Rotate the top four words down: W1, W2, W3, W4 -> W4, W1, W2, W3 */
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   552
	void RotateTop4Words()
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   553
	{
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   554
		byte tmp[2];
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   555
		for (int i = 0; i  < 2; i++) tmp[i] = this->stack[this->position + i + 6];
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   556
		for (int i = 5; i >= 0; i--) this->stack[this->position + i + 2] = this->stack[this->position + i];
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   557
		for (int i = 0; i  < 2; i++) this->stack[this->position + i] = tmp[i];
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   558
	}
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   559
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   560
	void PushWord(uint16 word)
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   561
	{
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   562
		if (this->position >= 2) {
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   563
			this->position -= 2;
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   564
		} else {
9907
4233d2e96ffc (svn r14057) -Fix: NewGRF text stack's "push word" didn't move the data around properly (minime)
rubidium
parents: 8787
diff changeset
   565
			for (int i = lengthof(stack) - 1; i >= this->position + 2; i--) {
4233d2e96ffc (svn r14057) -Fix: NewGRF text stack's "push word" didn't move the data around properly (minime)
rubidium
parents: 8787
diff changeset
   566
				this->stack[i] = this->stack[i - 2];
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   567
			}
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   568
		}
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   569
		this->stack[this->position]     = GB(word, 0, 8);
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   570
		this->stack[this->position + 1] = GB(word, 8, 8);
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   571
	}
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   572
7750
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   573
	void ResetStack()  { this->position = 0; this->used = true; }
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   574
	void RewindStack() { this->position = 0; }
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   575
};
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   576
7750
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   577
static TextRefStack _newgrf_normal_textrefstack;
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   578
static TextRefStack _newgrf_error_textrefstack;
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   579
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   580
/** The stack that is used for TTDP compatible string code parsing */
7750
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   581
static TextRefStack *_newgrf_textrefstack = &_newgrf_normal_textrefstack;
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   582
7750
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   583
/**
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   584
 * Prepare the TTDP compatible string code parsing
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   585
 * @param numEntries number of entries to copy from the registers
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   586
 */
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   587
void PrepareTextRefStackUsage(byte numEntries)
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   588
{
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   589
	extern TemporaryStorageArray<uint32, 0x110> _temp_store;
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   590
7750
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   591
	_newgrf_textrefstack->ResetStack();
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   592
7750
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   593
	byte *p = _newgrf_textrefstack->stack;
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   594
	for (uint i = 0; i < numEntries; i++) {
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   595
		for (uint j = 0; j < 32; j += 8) {
7722
8da8bafcdf12 (svn r11257) -Fix (r11145): wrong endian used when preparing text ref stack
glx
parents: 7616
diff changeset
   596
			*p = GB(_temp_store.Get(0x100 + i), j, 8);
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   597
			p++;
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   598
		}
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   599
	}
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   600
}
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   601
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   602
/** Stop using the TTDP compatible string code parsing */
7750
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   603
void StopTextRefStackUsage() { _newgrf_textrefstack->used = false; }
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   604
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   605
void SwitchToNormalRefStack()
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   606
{
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   607
	_newgrf_textrefstack = &_newgrf_normal_textrefstack;
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   608
}
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   609
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   610
void SwitchToErrorRefStack()
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   611
{
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   612
	_newgrf_textrefstack = &_newgrf_error_textrefstack;
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   613
}
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   614
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   615
void RewindTextRefStack()
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   616
{
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   617
	_newgrf_textrefstack->RewindStack();
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   618
}
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   619
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   620
/**
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   621
 * FormatString for NewGRF specific "magic" string control codes
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   622
 * @param scc   the string control code that has been read
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   623
 * @param stack the current "stack"
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   624
 * @return the string control code to "execute" now
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   625
 */
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   626
uint RemapNewGRFStringControlCode(uint scc, char **buff, const char **str, int64 *argv)
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   627
{
7750
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   628
	if (_newgrf_textrefstack->used) {
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   629
		switch (scc) {
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   630
			default: NOT_REACHED();
7750
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   631
			case SCC_NEWGRF_PRINT_SIGNED_BYTE:    *argv = _newgrf_textrefstack->PopSignedByte();    break;
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   632
			case SCC_NEWGRF_PRINT_SIGNED_WORD:    *argv = _newgrf_textrefstack->PopSignedWord();    break;
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   633
			case SCC_NEWGRF_PRINT_QWORD_CURRENCY: *argv = _newgrf_textrefstack->PopUnsignedQWord(); break;
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   634
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   635
			case SCC_NEWGRF_PRINT_DWORD_CURRENCY:
7750
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   636
			case SCC_NEWGRF_PRINT_DWORD:          *argv = _newgrf_textrefstack->PopSignedDWord();   break;
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   637
10135
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 9932
diff changeset
   638
			case SCC_NEWGRF_PRINT_HEX_BYTE:       *argv = _newgrf_textrefstack->PopUnsignedByte();  break;
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 9932
diff changeset
   639
			case SCC_NEWGRF_PRINT_HEX_DWORD:      *argv = _newgrf_textrefstack->PopUnsignedDWord(); break;
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 9932
diff changeset
   640
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 9932
diff changeset
   641
			case SCC_NEWGRF_PRINT_HEX_WORD:
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   642
			case SCC_NEWGRF_PRINT_WORD_SPEED:
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   643
			case SCC_NEWGRF_PRINT_WORD_LITRES:
7750
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   644
			case SCC_NEWGRF_PRINT_UNSIGNED_WORD:  *argv = _newgrf_textrefstack->PopUnsignedWord();  break;
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   645
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   646
			case SCC_NEWGRF_PRINT_DATE:
7750
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   647
			case SCC_NEWGRF_PRINT_MONTH_YEAR:     *argv = _newgrf_textrefstack->PopSignedWord() + DAYS_TILL_ORIGINAL_BASE_YEAR; break;
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   648
7750
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   649
			case SCC_NEWGRF_DISCARD_WORD:         _newgrf_textrefstack->PopUnsignedWord(); break;
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   650
7750
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   651
			case SCC_NEWGRF_ROTATE_TOP_4_WORDS:   _newgrf_textrefstack->RotateTop4Words(); break;
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   652
			case SCC_NEWGRF_PUSH_WORD:            _newgrf_textrefstack->PushWord(Utf8Consume(str)); break;
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   653
			case SCC_NEWGRF_UNPRINT:              *buff -= Utf8Consume(str); break;
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   654
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   655
			case SCC_NEWGRF_PRINT_STRING_ID:
7750
7afbef1235e0 (svn r11287) -Codechange: add support for pushing paramaters into NewIndustries' error messages. Patch by Csaboka.
rubidium
parents: 7722
diff changeset
   656
				*argv = _newgrf_textrefstack->PopUnsignedWord();
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   657
				if (*argv == STR_NULL) *argv = STR_EMPTY;
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   658
				break;
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   659
		}
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   660
	}
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   661
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   662
	switch (scc) {
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   663
		default: NOT_REACHED();
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   664
		case SCC_NEWGRF_PRINT_DWORD:
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   665
		case SCC_NEWGRF_PRINT_SIGNED_WORD:
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   666
		case SCC_NEWGRF_PRINT_SIGNED_BYTE:
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   667
		case SCC_NEWGRF_PRINT_UNSIGNED_WORD:
8784
c2e9d649a9ce (svn r12488) -Codechange: split order.h into order_base.h and order_func.h.
rubidium
parents: 8656
diff changeset
   668
			return SCC_COMMA;
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   669
10135
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 9932
diff changeset
   670
		case SCC_NEWGRF_PRINT_HEX_BYTE:
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 9932
diff changeset
   671
		case SCC_NEWGRF_PRINT_HEX_WORD:
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 9932
diff changeset
   672
		case SCC_NEWGRF_PRINT_HEX_DWORD:
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 9932
diff changeset
   673
			return SCC_HEX;
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 9932
diff changeset
   674
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   675
		case SCC_NEWGRF_PRINT_DWORD_CURRENCY:
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   676
		case SCC_NEWGRF_PRINT_QWORD_CURRENCY:
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   677
			return SCC_CURRENCY;
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   678
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   679
		case SCC_NEWGRF_PRINT_STRING_ID:
7755
7038d5001e0a (svn r11293) -Fix: newgrf defined industry news messages use TTD format for args, which is not the same as our. So we must detect those strings and pass them the right params
glx
parents: 7750
diff changeset
   680
			return SCC_STRING1;
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   681
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   682
		case SCC_NEWGRF_PRINT_DATE:
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   683
			return SCC_DATE_LONG;
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   684
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   685
		case SCC_NEWGRF_PRINT_MONTH_YEAR:
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   686
			return SCC_DATE_TINY;
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   687
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   688
		case SCC_NEWGRF_PRINT_WORD_SPEED:
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   689
			return SCC_VELOCITY;
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   690
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   691
		case SCC_NEWGRF_PRINT_WORD_LITRES:
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   692
			return SCC_VOLUME;
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   693
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   694
		case SCC_NEWGRF_DISCARD_WORD:
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   695
		case SCC_NEWGRF_ROTATE_TOP_4_WORDS:
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   696
		case SCC_NEWGRF_PUSH_WORD:
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   697
		case SCC_NEWGRF_UNPRINT:
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   698
			return 0;
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   699
	}
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7437
diff changeset
   700
}