newgrf_text.c
author miham
Fri, 12 May 2006 16:42:06 +0000
changeset 3828 3b27abfedacf
parent 3821 57db5bab0f24
child 3856 00418a7438be
permissions -rw-r--r--
(svn r4850) [WebTranslator2] Updating languages to 2006-05-12 18:40 <<original commitlog lost, bug under investigation>>
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
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
     3
/** @file
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 "string.h"
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
    16
#include "strings.h"
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    17
#include "variables.h"
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    18
#include "macros.h"
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    19
#include "table/strings.h"
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    20
#include "newgrf_text.h"
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    21
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    22
#define GRFTAB  28
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    23
#define TABSIZE 11
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    24
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    25
/**
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    26
 * Explains the newgrf shift bit positionning.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    27
 * 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
    28
 * jumping from standard langID scheme to the new one.
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
typedef enum grf_base_languages {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    31
	GRFLB_AMERICAN    = 0x01,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    32
	GRFLB_ENGLISH     = 0x02,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    33
	GRFLB_GERMAN      = 0x04,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    34
	GRFLB_FRENCH      = 0x08,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    35
	GRFLB_SPANISH     = 0x10,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    36
	GRFLB_GENERIC     = 0x80,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    37
} grf_base_language;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    38
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    39
typedef enum grf_extended_languages {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    40
	GRFLX_AMERICAN    = 0x00,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    41
	GRFLX_ENGLISH     = 0x01,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    42
	GRFLX_GERMAN      = 0x02,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    43
	GRFLX_FRENCH      = 0x03,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    44
	GRFLX_SPANISH     = 0x04,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    45
	GRFLX_RUSSIAN     = 0x07,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    46
	GRFLX_CZECH       = 0x15,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    47
	GRFLX_SLOVAK      = 0x16,
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
    48
	GRFLX_DUTCH       = 0x1F,
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    49
	GRFLX_CATALAN     = 0x22,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    50
	GRFLX_HUNGARIAN   = 0x24,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    51
	GRFLX_ITALIAN     = 0x27,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    52
	GRFLX_ROMANIAN    = 0x28,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    53
	GRFLX_ICELANDIC   = 0x29,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    54
	GRFLX_LATVIAN     = 0x2A,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    55
	GRFLX_LITHUANIAN  = 0x2B,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    56
	GRFLX_SLOVENIAN   = 0x2C,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    57
	GRFLX_DANISH      = 0x2D,
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
    58
	GRFLX_SWEDISH     = 0x2E,
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    59
	GRFLX_NORWEGIAN   = 0x2F,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    60
	GRFLX_POLISH      = 0x30,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    61
	GRFLX_GALICIAN    = 0x31,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    62
	GRFLX_FRISIAN     = 0x32,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    63
	GRFLX_ESTONIAN    = 0x34,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    64
	GRFLX_FINNISH     = 0x35,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    65
	GRFLX_PORTUGUESE  = 0x36,
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
    66
	GRFLX_BRAZILIAN   = 0x37,
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    67
	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
    68
	GRFLX_UNSPECIFIED = 0x7F,
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    69
} grf_language;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    70
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    71
3603
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
    72
typedef struct iso_grf {
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    73
	char code[6];
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    74
	byte grfLangID;
3603
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
    75
} iso_grf;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    76
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    77
/**
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    78
 * ISO code VS NewGrf langID conversion array.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    79
 * This array is used in two ways:
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    80
 * 1-its ISO part is matching OpenTTD dynamic language id
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    81
 *   with newgrf bit positionning language id
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    82
 * 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
    83
 *   watch for when inserting new strings, hence analysing newgrf langid
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    84
 */
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
    85
const iso_grf iso_codes[] = {
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    86
	{"en_US", GRFLX_AMERICAN},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    87
	{"en_GB", GRFLX_ENGLISH},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    88
	{"de",    GRFLX_GERMAN},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    89
	{"fr",    GRFLX_FRENCH},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    90
	{"es",    GRFLX_SPANISH},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    91
	{"cs",    GRFLX_CZECH},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    92
	{"ca",    GRFLX_CATALAN},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    93
	{"da",    GRFLX_DANISH},
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
    94
	{"nl",    GRFLX_DUTCH},
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    95
	{"et",    GRFLX_ESTONIAN},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    96
	{"fi",    GRFLX_FINNISH},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    97
	{"fy",    GRFLX_FRISIAN},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    98
	{"gl",    GRFLX_GALICIAN},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    99
	{"hu",    GRFLX_HUNGARIAN},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   100
	{"is",    GRFLX_ICELANDIC},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   101
	{"it",    GRFLX_ITALIAN},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   102
	{"lv",    GRFLX_LATVIAN},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   103
	{"lt",    GRFLX_LITHUANIAN},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   104
	{"nb",    GRFLX_NORWEGIAN},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   105
	{"pl",    GRFLX_POLISH},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   106
	{"pt",    GRFLX_PORTUGUESE},
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   107
	{"pt_BR", GRFLX_BRAZILIAN},
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   108
	{"ro",    GRFLX_ROMANIAN},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   109
	{"ru",    GRFLX_RUSSIAN},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   110
	{"sk",    GRFLX_SLOVAK},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   111
	{"sl",    GRFLX_SLOVENIAN},
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   112
	{"sv",    GRFLX_SWEDISH},
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   113
	{"tr",    GRFLX_TURKISH},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   114
	{"gen",   GRFLB_GENERIC}   //this is not iso code, but there has to be something...
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   115
};
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   116
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   117
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   118
static uint _num_grf_texts = 0;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   119
static GRFTextEntry _grf_text[(1 << TABSIZE) * 3];
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   120
static byte _currentLangID = GRFLX_ENGLISH;  //by default, english is used.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   121
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   122
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
   123
static void TranslateTTDPatchCodes(char *str)
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
   124
{
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
   125
	char *c;
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
   126
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
   127
	for (c = str; *c != '\0'; c++) {
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
   128
		switch ((byte)*c) {
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
   129
			case 0x01: c++; 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
   130
			case 0x0D: *c = 10; 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
   131
			case 0x0E: *c = 8; 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
   132
			case 0x0F: *c = 9; 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
   133
			case 0x1F: *c = 2; c += 2; 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
   134
			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
   135
			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
   136
			case 0x7D:
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
   137
			case 0x7E: *c = 0x8E; 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
   138
			case 0x81: c += 2; 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
   139
			case 0x85: *c = 0x86; 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
   140
			case 0x88: *c = 15; 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
   141
			case 0x89: *c = 16; 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
   142
			case 0x8A: *c = 17; 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
   143
			case 0x8B: *c = 18; 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
   144
			case 0x8C: *c = 19; 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
   145
			case 0x8D: *c = 20; 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
   146
			case 0x8E: *c = 21; 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
   147
			case 0x8F: *c = 22; 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
   148
			case 0x90: *c = 23; 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
   149
			case 0x91: *c = 24; 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
   150
			case 0x92: *c = 25; 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
   151
			case 0x93: *c = 26; 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
   152
			case 0x94: *c = 27; 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
   153
			case 0x95: *c = 28; 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
   154
			case 0x96: *c = 29; 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
   155
			case 0x97: *c = 30; 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
   156
			case 0x98: *c = 31; 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
   157
			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
   158
				/* Validate any unhandled character */
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
   159
				if (!IsValidAsciiChar(*c)) *c = '?';
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
   160
				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
   161
		}
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
   162
	}
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
   163
}
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
   164
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
   165
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   166
/**
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
   167
 * Add the new read string into our structure.
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   168
 */
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
   169
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
   170
{
3603
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   171
	GRFText *newtext;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   172
	uint id;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   173
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
   174
	/* 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
   175
	 * 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
   176
	 * 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
   177
	 * 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
   178
	 * actually translated.
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   179
	 */
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
   180
	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
   181
		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
   182
			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
   183
		} else {
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   184
			StringID ret = STR_EMPTY;
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
   185
			if (langid_to_add & GRFLB_GERMAN)  ret = AddGRFString(grfid, stringid, 1 << 6 | GRFLX_GERMAN,  true, text_to_add, def_string);
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
   186
			if (langid_to_add & GRFLB_FRENCH)  ret = AddGRFString(grfid, stringid, 1 << 6 | GRFLX_FRENCH,  true, text_to_add, def_string);
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
   187
			if (langid_to_add & GRFLB_SPANISH) ret = AddGRFString(grfid, stringid, 1 << 6 | 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
   188
			return ret;
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   189
		}
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   190
	}
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   191
3603
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   192
	newtext = calloc(1, sizeof(*newtext));
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   193
	newtext->langid = GB(langid_to_add, 0, 6);
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   194
	newtext->text   = strdup(text_to_add);
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   195
	newtext->next   = NULL;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   196
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
	TranslateTTDPatchCodes(newtext->text);
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   198
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   199
	for (id = 0; id < _num_grf_texts; id++) {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   200
		if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   201
			break;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   202
		}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   203
	}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   204
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   205
	/* Too many strings allocated, return empty */
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   206
	if (id == lengthof(_grf_text)) return STR_EMPTY;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   207
3603
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   208
	/* 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
   209
	if (id == _num_grf_texts) _num_grf_texts++;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   210
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   211
	if (_grf_text[id].textholder == NULL) {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   212
		_grf_text[id].grfid      = grfid;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   213
		_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
   214
		_grf_text[id].def_string = def_string;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   215
		_grf_text[id].textholder = newtext;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   216
	} else {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   217
		GRFText *textptr = _grf_text[id].textholder;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   218
		while (textptr->next != NULL) textptr = textptr->next;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   219
		textptr->next = newtext;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   220
	}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   221
3630
13278b8ed023 (svn r4529) - Codechange: Use proper naming for hex numbers in debug prints eg. 0xF3A6. Use fixed lengths where applicable (newgrf). Unfortunately '%#X' is unusable since it gives 0XFF3 and '%#x' gives 0xff3 while we want 0xFF3 :P
Darkvater
parents: 3605
diff changeset
   222
	DEBUG(grf, 2)("Added 0x%X: grfid 0x%X 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
   223
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   224
	return (GRFTAB << TABSIZE) + id;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   225
}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   226
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   227
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   228
/**
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   229
 * Returns the index for this stringid associated with its grfID
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   230
 */
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   231
StringID GetGRFStringID(uint32 grfid, uint16 stringid)
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   232
{
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   233
	uint id;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   234
	for (id = 0; id < _num_grf_texts; id++) {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   235
		if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   236
			return (GRFTAB << TABSIZE) + id;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   237
		}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   238
	}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   239
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   240
	return STR_UNDEFINED;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   241
}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   242
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   243
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   244
char *GetGRFString(char *buff, uint16 stringid)
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   245
{
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   246
	GRFText *search_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
   247
	GRFText *default_text = NULL;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   248
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   249
	assert(_grf_text[stringid].grfid != 0);
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   250
	/*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
   251
	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
   252
		if (search_text->langid == _currentLangID) {
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   253
			return strecpy(buff, search_text->text, NULL);
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   254
		}
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
   255
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
   256
		/* 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
   257
		 * fallback language if the specific language isn't available. */
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
   258
		if (search_text->langid == GRFLX_ENGLISH || search_text->langid == GRFLX_AMERICAN) {
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
   259
			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
   260
		}
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   261
	}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   262
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
   263
	/* If there is a fallback string, return that */
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
   264
	if (default_text != NULL) return strecpy(buff, default_text->text, NULL);
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
   265
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
   266
	/* Use the default string ID if the fallback string isn't available */
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
   267
	return GetString(buff, _grf_text[stringid].def_string);
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   268
}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   269
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   270
/**
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   271
 * Equivalence Setter function between game and newgrf langID.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   272
 * This function will adjust _currentLangID as to what is the LangID
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   273
 * of the current language set by the user.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   274
 * The array iso_codes will be used to find that match.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   275
 * If not found, it will have to be standard english
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   276
 * This function is called after the user changed language,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   277
 * from strings.c:ReadLanguagePack
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   278
 * @param iso code of current selection
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   279
 */
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   280
void SetCurrentGrfLangID(const char *iso_name)
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   281
{
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   282
	byte ret,i;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   283
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   284
	/* Use English by default, if we can't match up the iso_code. */
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   285
	ret = GRFLX_ENGLISH;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   286
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   287
	for (i=0; i < lengthof(iso_codes); i++) {
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   288
		if (strcmp(iso_codes[i].code, iso_name) == 0) {
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   289
			/* We found a match, so let's use it. */
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   290
			ret = i;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   291
			break;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   292
		}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   293
	}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   294
	_currentLangID = ret;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   295
}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   296
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   297
/**
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   298
 * House cleaning.
3602
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   299
 * Remove all strings and reset the text counter.
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   300
 */
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   301
void CleanUpStrings(void)
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   302
{
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   303
	uint id;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   304
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   305
	for (id = 0; id < _num_grf_texts; id++) {
3602
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   306
		GRFText *grftext = _grf_text[id].textholder;
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   307
		while (grftext != NULL) {
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   308
			GRFText *grftext2 = grftext->next;
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   309
			free(grftext->text);
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   310
			free(grftext);
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   311
			grftext = grftext2;
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   312
		}
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   313
		_grf_text[id].grfid      = 0;
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   314
		_grf_text[id].stringid   = 0;
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   315
		_grf_text[id].textholder = NULL;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   316
	}
3602
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   317
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   318
	_num_grf_texts = 0;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   319
}