newgrf_text.c
author Darkvater
Mon, 31 Jul 2006 22:40:55 +0000
changeset 4204 3aa39be759f2
parent 3868 2de0afd113ff
child 4299 91f5d2bedcff
permissions -rw-r--r--
(svn r5688) - Forward-port the release-changes from the 0.4 branch back to trunk. This ensures an updated changelog, known-bugs, etc.
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,
3856
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    48
	GRFLX_AFRIKAANS   = 0x1B,
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    49
	GRFLX_GREEK       = 0x1E,
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
    50
	GRFLX_DUTCH       = 0x1F,
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    51
	GRFLX_CATALAN     = 0x22,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    52
	GRFLX_HUNGARIAN   = 0x24,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    53
	GRFLX_ITALIAN     = 0x27,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    54
	GRFLX_ROMANIAN    = 0x28,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    55
	GRFLX_ICELANDIC   = 0x29,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    56
	GRFLX_LATVIAN     = 0x2A,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    57
	GRFLX_LITHUANIAN  = 0x2B,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    58
	GRFLX_SLOVENIAN   = 0x2C,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    59
	GRFLX_DANISH      = 0x2D,
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
    60
	GRFLX_SWEDISH     = 0x2E,
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    61
	GRFLX_NORWEGIAN   = 0x2F,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    62
	GRFLX_POLISH      = 0x30,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    63
	GRFLX_GALICIAN    = 0x31,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    64
	GRFLX_FRISIAN     = 0x32,
3856
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    65
	GRFLX_UKRAINIAN   = 0x33,
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    66
	GRFLX_ESTONIAN    = 0x34,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    67
	GRFLX_FINNISH     = 0x35,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    68
	GRFLX_PORTUGUESE  = 0x36,
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
    69
	GRFLX_BRAZILIAN   = 0x37,
3856
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    70
	GRFLX_CROATIAN    = 0x38,
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    71
	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
    72
	GRFLX_UNSPECIFIED = 0x7F,
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    73
} grf_language;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    74
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    75
3603
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
    76
typedef struct iso_grf {
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    77
	char code[6];
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    78
	byte grfLangID;
3603
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
    79
} iso_grf;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    80
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    81
/**
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    82
 * ISO code VS NewGrf langID conversion array.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    83
 * This array is used in two ways:
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    84
 * 1-its ISO part is matching OpenTTD dynamic language id
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    85
 *   with newgrf bit positionning language id
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    86
 * 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
    87
 *   watch for when inserting new strings, hence analysing newgrf langid
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    88
 */
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
    89
const iso_grf iso_codes[] = {
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    90
	{"en_US", GRFLX_AMERICAN},
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    91
	{"en_GB", GRFLX_ENGLISH},
3856
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    92
	{"de_DE", GRFLX_GERMAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    93
	{"fr_FR", GRFLX_FRENCH},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    94
	{"es_ES", GRFLX_SPANISH},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    95
	{"af_ZA", GRFLX_AFRIKAANS},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    96
	{"hr_HR", GRFLX_CROATIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    97
	{"cs_CS", GRFLX_CZECH},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    98
	{"ca_ES", GRFLX_CATALAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    99
	{"da_DA", GRFLX_DANISH},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   100
	{"nl_NL", GRFLX_DUTCH},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   101
	{"et_ET", GRFLX_ESTONIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   102
	{"fi_FI", GRFLX_FINNISH},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   103
	{"fy_NL", GRFLX_FRISIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   104
	{"gl_ES", GRFLX_GALICIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   105
	{"el_GR", GRFLX_GREEK},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   106
	{"hu_HU", GRFLX_HUNGARIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   107
	{"is_IS", GRFLX_ICELANDIC},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   108
	{"it_IT", GRFLX_ITALIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   109
	{"lv_LV", GRFLX_LATVIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   110
	{"lt_LT", GRFLX_LITHUANIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   111
	{"nb_NO", GRFLX_NORWEGIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   112
	{"pl_PL", GRFLX_POLISH},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   113
	{"pt_PT", GRFLX_PORTUGUESE},
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   114
	{"pt_BR", GRFLX_BRAZILIAN},
3856
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   115
	{"ro_RO", GRFLX_ROMANIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   116
	{"ru_RU", GRFLX_RUSSIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   117
	{"sk_SK", GRFLX_SLOVAK},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   118
	{"sl_SL", GRFLX_SLOVENIAN},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   119
	{"sv_SE", GRFLX_SWEDISH},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   120
	{"tr_TR", GRFLX_TURKISH},
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   121
	{"uk_UA", GRFLX_UKRAINIAN},
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   122
	{"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
   123
};
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   124
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   125
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   126
static uint _num_grf_texts = 0;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   127
static GRFTextEntry _grf_text[(1 << TABSIZE) * 3];
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   128
static byte _currentLangID = GRFLX_ENGLISH;  //by default, english is used.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   129
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   130
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
   131
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
   132
{
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
	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
   134
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
	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
   136
		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
   137
			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
   138
			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
   139
			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
   140
			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
   141
			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
   142
			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
   143
			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
   144
			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
   145
			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
   146
			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
   147
			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
   148
			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
   149
			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
   150
			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
   151
			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
   152
			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
   153
			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
   154
			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
   155
			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
   156
			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
   157
			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
   158
			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
   159
			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
   160
			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
   161
			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
   162
			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
   163
			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
   164
			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
   165
			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
   166
				/* 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
   167
				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
   168
				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
   169
		}
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
   170
	}
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
   171
}
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
   172
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
   173
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   174
/**
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
   175
 * Add the new read string into our structure.
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   176
 */
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
   177
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
   178
{
3603
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   179
	GRFText *newtext;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   180
	uint id;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   181
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
   182
	/* 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
   183
	 * 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
   184
	 * 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
   185
	 * 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
   186
	 * actually translated.
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   187
	 */
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
   188
	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
   189
		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
   190
			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
   191
		} else {
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   192
			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
   193
			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
   194
			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
   195
			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
   196
			return ret;
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   197
		}
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   198
	}
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   199
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   200
	for (id = 0; id < _num_grf_texts; id++) {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   201
		if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   202
			break;
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
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   206
	/* Too many strings allocated, return empty */
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   207
	if (id == lengthof(_grf_text)) return STR_EMPTY;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   208
3856
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   209
	newtext = calloc(1, sizeof(*newtext));
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   210
	newtext->langid = GB(langid_to_add, 0, 6);
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   211
	newtext->text   = strdup(text_to_add);
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   212
	newtext->next   = NULL;
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   213
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   214
	TranslateTTDPatchCodes(newtext->text);
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   215
3603
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   216
	/* 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
   217
	if (id == _num_grf_texts) _num_grf_texts++;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   218
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   219
	if (_grf_text[id].textholder == NULL) {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   220
		_grf_text[id].grfid      = grfid;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   221
		_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
   222
		_grf_text[id].def_string = def_string;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   223
		_grf_text[id].textholder = newtext;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   224
	} else {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   225
		GRFText *textptr = _grf_text[id].textholder;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   226
		while (textptr->next != NULL) textptr = textptr->next;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   227
		textptr->next = newtext;
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
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
   230
	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
   231
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   232
	return (GRFTAB << TABSIZE) + id;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   233
}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   234
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   235
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   236
/**
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   237
 * Returns the index for this stringid associated with its grfID
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
StringID GetGRFStringID(uint32 grfid, uint16 stringid)
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   240
{
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   241
	uint id;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   242
	for (id = 0; id < _num_grf_texts; id++) {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   243
		if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   244
			return (GRFTAB << TABSIZE) + id;
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
	}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   247
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   248
	return STR_UNDEFINED;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   249
}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   250
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   251
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   252
char *GetGRFString(char *buff, uint16 stringid)
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   253
{
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   254
	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
   255
	GRFText *default_text = NULL;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   256
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   257
	assert(_grf_text[stringid].grfid != 0);
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   258
	/*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
   259
	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
   260
		if (search_text->langid == _currentLangID) {
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   261
			return strecpy(buff, search_text->text, NULL);
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
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 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
   265
		 * 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
   266
		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
   267
			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
   268
		}
3601
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
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
   271
	/* 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
   272
	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
   273
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
   274
	/* 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
   275
	return GetString(buff, _grf_text[stringid].def_string);
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   276
}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   277
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   278
/**
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   279
 * Equivalence Setter function between game and newgrf langID.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   280
 * This function will adjust _currentLangID as to what is the LangID
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   281
 * of the current language set by the user.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   282
 * The array iso_codes will be used to find that match.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   283
 * If not found, it will have to be standard english
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   284
 * This function is called after the user changed language,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   285
 * from strings.c:ReadLanguagePack
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   286
 * @param iso code of current selection
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   287
 */
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   288
void SetCurrentGrfLangID(const char *iso_name)
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   289
{
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   290
	byte ret,i;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   291
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   292
	/* 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
   293
	ret = GRFLX_ENGLISH;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   294
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   295
	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
   296
		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
   297
			/* We found a match, so let's use it. */
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   298
			ret = i;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   299
			break;
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
	}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   302
	_currentLangID = ret;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   303
}
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
/**
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   306
 * House cleaning.
3602
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   307
 * Remove all strings and reset the text counter.
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   308
 */
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   309
void CleanUpStrings(void)
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   310
{
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   311
	uint id;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   312
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   313
	for (id = 0; id < _num_grf_texts; id++) {
3602
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   314
		GRFText *grftext = _grf_text[id].textholder;
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   315
		while (grftext != NULL) {
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   316
			GRFText *grftext2 = grftext->next;
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   317
			free(grftext->text);
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   318
			free(grftext);
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   319
			grftext = grftext2;
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   320
		}
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   321
		_grf_text[id].grfid      = 0;
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   322
		_grf_text[id].stringid   = 0;
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   323
		_grf_text[id].textholder = NULL;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   324
	}
3602
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   325
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   326
	_num_grf_texts = 0;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   327
}