newgrf_text.c
author peter1138
Sun, 01 Oct 2006 12:00:32 +0000
changeset 4694 c917a3ad0dd2
parent 4624 aba74bb14e51
child 4710 1aa2b507818f
permissions -rw-r--r--
(svn r6601) - Codechange: Support cargo subtypes in the refit window. The refit window has been altered to support resizing and scrolling. Note that the cargo subtype isn't yet passed for actual refitting yet. (Based on mart3p's patch)
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
4305
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   126
/**
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   127
 * Element of the linked list.
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   128
 * Each of those elements represent the string,
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   129
 * but according to a different lang.
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   130
 */
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   131
typedef struct GRFText {
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   132
	struct GRFText *next;
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   133
	byte langid;
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   134
	char text[VARARRAY_SIZE];
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   135
} GRFText;
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   136
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   137
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   138
/**
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   139
 * Holder of the above structure.
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   140
 * Putting both grfid and stringid together allows us to avoid duplicates,
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   141
 * since it is NOT SUPPOSED to happen.
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   142
 */
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   143
typedef struct GRFTextEntry {
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   144
	uint32 grfid;
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   145
	uint16 stringid;
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   146
	StringID def_string;
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   147
	GRFText *textholder;
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   148
} GRFTextEntry;
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   149
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   150
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   151
static uint _num_grf_texts = 0;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   152
static GRFTextEntry _grf_text[(1 << TABSIZE) * 3];
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   153
static byte _currentLangID = GRFLX_ENGLISH;  //by default, english is used.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   154
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   155
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
   156
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
   157
{
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
	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
   159
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
	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
   161
		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
   162
			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
   163
			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
   164
			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
   165
			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
   166
			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
   167
			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
   168
			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
   169
			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
   170
			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
   171
			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
   172
			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
   173
			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
   174
			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
   175
			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
   176
			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
   177
			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
   178
			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
   179
			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
   180
			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
   181
			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
   182
			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
   183
			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
   184
			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
   185
			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
   186
			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
   187
			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
   188
			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
   189
			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
   190
			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
   191
				/* Validate any unhandled character */
4299
91f5d2bedcff (svn r5944) -Merge TGP (r5578, r5579, r5724, r5726): -Feature: filter for textboxes to only
truelight
parents: 3868
diff changeset
   192
				if (!IsValidAsciiChar(*c, CS_ALPHANUMERAL)) *c = '?';
3646
291be46d399e (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   193
				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
   194
		}
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
   195
	}
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
   196
}
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
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
   198
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   199
/**
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
   200
 * Add the new read string into our structure.
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   201
 */
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
   202
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
   203
{
3603
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   204
	GRFText *newtext;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   205
	uint id;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   206
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
   207
	/* 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
   208
	 * 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
   209
	 * 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
   210
	 * 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
   211
	 * actually translated.
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   212
	 */
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
   213
	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
   214
		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
   215
			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
   216
		} else {
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   217
			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
   218
			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
   219
			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
   220
			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
   221
			return ret;
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   222
		}
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   223
	}
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   224
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   225
	for (id = 0; id < _num_grf_texts; id++) {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   226
		if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   227
			break;
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
	}
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
	/* Too many strings allocated, return empty */
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   232
	if (id == lengthof(_grf_text)) return STR_EMPTY;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   233
4305
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   234
	newtext = malloc(sizeof(*newtext) + strlen(text_to_add) + 1);
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   235
	newtext->next   = NULL;
3856
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   236
	newtext->langid = GB(langid_to_add, 0, 6);
4305
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   237
	strcpy(newtext->text, text_to_add);
3856
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   238
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   239
	TranslateTTDPatchCodes(newtext->text);
00418a7438be (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   240
3603
245bd93ea8e5 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   241
	/* 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
   242
	if (id == _num_grf_texts) _num_grf_texts++;
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
	if (_grf_text[id].textholder == NULL) {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   245
		_grf_text[id].grfid      = grfid;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   246
		_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
   247
		_grf_text[id].def_string = def_string;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   248
		_grf_text[id].textholder = newtext;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   249
	} else {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   250
		GRFText *textptr = _grf_text[id].textholder;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   251
		while (textptr->next != NULL) textptr = textptr->next;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   252
		textptr->next = newtext;
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
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
   255
	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
   256
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   257
	return (GRFTAB << TABSIZE) + id;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   258
}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   259
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   260
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
 * Returns the index for this stringid associated with its grfID
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   263
 */
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   264
StringID GetGRFStringID(uint32 grfid, uint16 stringid)
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   265
{
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   266
	uint id;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   267
	for (id = 0; id < _num_grf_texts; id++) {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   268
		if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   269
			return (GRFTAB << TABSIZE) + id;
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
	}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   272
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   273
	return STR_UNDEFINED;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   274
}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   275
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
char *GetGRFString(char *buff, uint16 stringid)
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   278
{
4305
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   279
	const GRFText *default_text = NULL;
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   280
	const GRFText *search_text;
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
	assert(_grf_text[stringid].grfid != 0);
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   283
	/*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
   284
	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
   285
		if (search_text->langid == _currentLangID) {
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   286
			return strecpy(buff, search_text->text, NULL);
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   287
		}
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
   288
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
   289
		/* 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
   290
		 * 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
   291
		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
   292
			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
   293
		}
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   294
	}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   295
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
   296
	/* 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
   297
	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
   298
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
   299
	/* 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
   300
	return GetString(buff, _grf_text[stringid].def_string);
3601
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
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
 * Equivalence Setter function between game and newgrf langID.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   305
 * This function will adjust _currentLangID as to what is the LangID
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   306
 * of the current language set by the user.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   307
 * The array iso_codes will be used to find that match.
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   308
 * If not found, it will have to be standard english
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   309
 * This function is called after the user changed language,
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   310
 * from strings.c:ReadLanguagePack
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   311
 * @param iso code of current selection
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   312
 */
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   313
void SetCurrentGrfLangID(const char *iso_name)
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   314
{
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   315
	/* Use English by default, if we can't match up the iso_code. */
4305
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   316
	byte ret = GRFLX_ENGLISH;
a28f3849ceae (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   317
	byte i;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   318
3605
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   319
	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
   320
		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
   321
			/* We found a match, so let's use it. */
2caa3194832f (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   322
			ret = i;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   323
			break;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   324
		}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   325
	}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   326
	_currentLangID = ret;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   327
}
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   328
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   329
/**
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   330
 * House cleaning.
3602
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   331
 * Remove all strings and reset the text counter.
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   332
 */
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   333
void CleanUpStrings(void)
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   334
{
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   335
	uint id;
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   336
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   337
	for (id = 0; id < _num_grf_texts; id++) {
3602
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   338
		GRFText *grftext = _grf_text[id].textholder;
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   339
		while (grftext != NULL) {
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   340
			GRFText *grftext2 = grftext->next;
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   341
			free(grftext);
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   342
			grftext = grftext2;
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   343
		}
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   344
		_grf_text[id].grfid      = 0;
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   345
		_grf_text[id].stringid   = 0;
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   346
		_grf_text[id].textholder = NULL;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   347
	}
3602
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   348
cf57727a41d4 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   349
	_num_grf_texts = 0;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   350
}