newgrf_text.c
author KUDr
Sat, 30 Dec 2006 18:25:01 +0000
branchcustombridgeheads
changeset 5609 ec38986d2c8e
parent 5568 75f13d7bfaed
permissions -rw-r--r--
(svn r7655) [cbh] - Fix: [YAPF] another assert (on opposite cbh when it contained choice). Now it is possible to reach choice when exiting wormhole. So the wormhole cost must be taken into consideration when starting new YAPF node.
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
     1
/* $Id$ */
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
     2
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
     3
/** @file
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
     4
 * Implementation of  Action 04 "universal holder" structure and functions.
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
     5
 * This file implements a linked-lists of strings,
ac6df06db648 (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.
ac6df06db648 (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
ac6df06db648 (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
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
     9
 * not related to ISO.  So equivalence functionnality had to be set.
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    10
 */
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    11
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    12
#include "stdafx.h"
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    13
#include "debug.h"
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    14
#include "openttd.h"
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    15
#include "string.h"
3821
2bb8a2643fdf (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
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    17
#include "variables.h"
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    18
#include "macros.h"
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    19
#include "table/strings.h"
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5344
diff changeset
    20
#include "newgrf.h"
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    21
#include "newgrf_text.h"
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
    22
#include "table/control_codes.h"
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    23
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    24
#define GRFTAB  28
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    25
#define TABSIZE 11
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    26
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    27
/**
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    28
 * Explains the newgrf shift bit positionning.
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    29
 * the grf base will not be used in order to find the string, but rather for
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    30
 * jumping from standard langID scheme to the new one.
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    31
 */
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    32
typedef enum grf_base_languages {
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    33
	GRFLB_AMERICAN    = 0x01,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    34
	GRFLB_ENGLISH     = 0x02,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    35
	GRFLB_GERMAN      = 0x04,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    36
	GRFLB_FRENCH      = 0x08,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    37
	GRFLB_SPANISH     = 0x10,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    38
	GRFLB_GENERIC     = 0x80,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    39
} grf_base_language;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    40
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    41
typedef enum grf_extended_languages {
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    42
	GRFLX_AMERICAN    = 0x00,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    43
	GRFLX_ENGLISH     = 0x01,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    44
	GRFLX_GERMAN      = 0x02,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    45
	GRFLX_FRENCH      = 0x03,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    46
	GRFLX_SPANISH     = 0x04,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    47
	GRFLX_RUSSIAN     = 0x07,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    48
	GRFLX_CZECH       = 0x15,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    49
	GRFLX_SLOVAK      = 0x16,
3856
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    50
	GRFLX_AFRIKAANS   = 0x1B,
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    51
	GRFLX_GREEK       = 0x1E,
3605
045805e70df0 (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
    52
	GRFLX_DUTCH       = 0x1F,
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    53
	GRFLX_CATALAN     = 0x22,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    54
	GRFLX_HUNGARIAN   = 0x24,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    55
	GRFLX_ITALIAN     = 0x27,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    56
	GRFLX_ROMANIAN    = 0x28,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    57
	GRFLX_ICELANDIC   = 0x29,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    58
	GRFLX_LATVIAN     = 0x2A,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    59
	GRFLX_LITHUANIAN  = 0x2B,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    60
	GRFLX_SLOVENIAN   = 0x2C,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    61
	GRFLX_DANISH      = 0x2D,
3605
045805e70df0 (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
    62
	GRFLX_SWEDISH     = 0x2E,
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    63
	GRFLX_NORWEGIAN   = 0x2F,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    64
	GRFLX_POLISH      = 0x30,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    65
	GRFLX_GALICIAN    = 0x31,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    66
	GRFLX_FRISIAN     = 0x32,
3856
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    67
	GRFLX_UKRAINIAN   = 0x33,
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    68
	GRFLX_ESTONIAN    = 0x34,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    69
	GRFLX_FINNISH     = 0x35,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    70
	GRFLX_PORTUGUESE  = 0x36,
3605
045805e70df0 (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
    71
	GRFLX_BRAZILIAN   = 0x37,
3856
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    72
	GRFLX_CROATIAN    = 0x38,
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    73
	GRFLX_TURKISH     = 0x3E,
3641
7dc47659e794 (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
    74
	GRFLX_UNSPECIFIED = 0x7F,
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    75
} grf_language;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    76
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    77
3603
b79fac8ba026 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
    78
typedef struct iso_grf {
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    79
	char code[6];
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    80
	byte grfLangID;
3603
b79fac8ba026 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
    81
} iso_grf;
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    82
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    83
/**
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    84
 * ISO code VS NewGrf langID conversion array.
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    85
 * This array is used in two ways:
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    86
 * 1-its ISO part is matching OpenTTD dynamic language id
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    87
 *   with newgrf bit positionning language id
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    88
 * 2-its shift part is used to know what is the shift to
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    89
 *   watch for when inserting new strings, hence analysing newgrf langid
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    90
 */
3605
045805e70df0 (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
    91
const iso_grf iso_codes[] = {
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    92
	{"en_US", GRFLX_AMERICAN},
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
    93
	{"en_GB", GRFLX_ENGLISH},
3856
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    94
	{"de_DE", GRFLX_GERMAN},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    95
	{"fr_FR", GRFLX_FRENCH},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    96
	{"es_ES", GRFLX_SPANISH},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    97
	{"af_ZA", GRFLX_AFRIKAANS},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    98
	{"hr_HR", GRFLX_CROATIAN},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
    99
	{"cs_CS", GRFLX_CZECH},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   100
	{"ca_ES", GRFLX_CATALAN},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   101
	{"da_DA", GRFLX_DANISH},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   102
	{"nl_NL", GRFLX_DUTCH},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   103
	{"et_ET", GRFLX_ESTONIAN},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   104
	{"fi_FI", GRFLX_FINNISH},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   105
	{"fy_NL", GRFLX_FRISIAN},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   106
	{"gl_ES", GRFLX_GALICIAN},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   107
	{"el_GR", GRFLX_GREEK},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   108
	{"hu_HU", GRFLX_HUNGARIAN},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   109
	{"is_IS", GRFLX_ICELANDIC},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   110
	{"it_IT", GRFLX_ITALIAN},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   111
	{"lv_LV", GRFLX_LATVIAN},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   112
	{"lt_LT", GRFLX_LITHUANIAN},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   113
	{"nb_NO", GRFLX_NORWEGIAN},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   114
	{"pl_PL", GRFLX_POLISH},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   115
	{"pt_PT", GRFLX_PORTUGUESE},
3605
045805e70df0 (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   116
	{"pt_BR", GRFLX_BRAZILIAN},
3856
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   117
	{"ro_RO", GRFLX_ROMANIAN},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   118
	{"ru_RU", GRFLX_RUSSIAN},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   119
	{"sk_SK", GRFLX_SLOVAK},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   120
	{"sl_SL", GRFLX_SLOVENIAN},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   121
	{"sv_SE", GRFLX_SWEDISH},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   122
	{"tr_TR", GRFLX_TURKISH},
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   123
	{"uk_UA", GRFLX_UKRAINIAN},
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   124
	{"gen",   GRFLB_GENERIC}   //this is not iso code, but there has to be something...
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   125
};
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   126
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   127
4305
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   128
/**
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   129
 * Element of the linked list.
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   130
 * Each of those elements represent the string,
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   131
 * but according to a different lang.
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   132
 */
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   133
typedef struct GRFText {
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   134
	struct GRFText *next;
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   135
	byte langid;
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   136
	char text[VARARRAY_SIZE];
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   137
} GRFText;
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   138
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   139
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   140
/**
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   141
 * Holder of the above structure.
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   142
 * Putting both grfid and stringid together allows us to avoid duplicates,
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   143
 * since it is NOT SUPPOSED to happen.
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   144
 */
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   145
typedef struct GRFTextEntry {
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   146
	uint32 grfid;
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   147
	uint16 stringid;
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   148
	StringID def_string;
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   149
	GRFText *textholder;
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   150
} GRFTextEntry;
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   151
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   152
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   153
static uint _num_grf_texts = 0;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   154
static GRFTextEntry _grf_text[(1 << TABSIZE) * 3];
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   155
static byte _currentLangID = GRFLX_ENGLISH;  //by default, english is used.
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   156
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   157
5228
c4a780348f66 (svn r7348) -Feature: Initial support for saving NewGRF settings with savegames. Back up your savegames...
peter1138
parents: 5208
diff changeset
   158
char *TranslateTTDPatchCodes(const char *str)
3646
4506e8954c11 (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
{
5204
4bd1f3793fed (svn r7319) -Fix (r7182): (NewGRF) Add space for terminator when translating TTDPatch strings (thanks eddi)
peter1138
parents: 5108
diff changeset
   160
	char *tmp = malloc(strlen(str) * 10 + 1); /* Allocate space to allow for expansion */
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   161
	char *d = tmp;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   162
	bool unicode = false;
5208
71f3d9cfed95 (svn r7323) -Fix (r7182): When translating NewGRF strings, look at the first
peter1138
parents: 5204
diff changeset
   163
	WChar c;
71f3d9cfed95 (svn r7323) -Fix (r7182): When translating NewGRF strings, look at the first
peter1138
parents: 5204
diff changeset
   164
	size_t len = Utf8Decode(&c, str);
3646
4506e8954c11 (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
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   166
	if (c == 0x00DE) {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   167
		/* The thorn ('þ') indicates a unicode string to TTDPatch */
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   168
		unicode = true;
5208
71f3d9cfed95 (svn r7323) -Fix (r7182): When translating NewGRF strings, look at the first
peter1138
parents: 5204
diff changeset
   169
		str += len;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   170
	}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   171
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   172
	for (;;) {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   173
		const char *tmp = str; /* Used for UTF-8 decoding */
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   174
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   175
		c = (byte)*str++;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   176
		if (c == 0) break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   177
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   178
		switch (c) {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   179
			case 0x01:
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   180
				d += Utf8Encode(d, SCC_SETX);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   181
				*d++ = *str++;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   182
				break;
5344
026148c4f06f (svn r7515) -Codechange [newgrf]: Ignore ascii code 0x0A in text. Newline is 0x0D.
Darkvater
parents: 5228
diff changeset
   183
			case 0x0A: break;
026148c4f06f (svn r7515) -Codechange [newgrf]: Ignore ascii code 0x0A in text. Newline is 0x0D.
Darkvater
parents: 5228
diff changeset
   184
			case 0x0D: *d++ = 0x0A; break;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   185
			case 0x0E: d += Utf8Encode(d, SCC_TINYFONT); break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   186
			case 0x0F: d += Utf8Encode(d, SCC_BIGFONT); break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   187
			case 0x1F:
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   188
				d += Utf8Encode(d, SCC_SETXY);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   189
				*d++ = *str++;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   190
				*d++ = *str++;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   191
				break;
3646
4506e8954c11 (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   192
			case 0x7B:
4506e8954c11 (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
			case 0x7C:
4506e8954c11 (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
			case 0x7D:
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   195
			case 0x7E: d += Utf8Encode(d, SCC_NUM); break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   196
			case 0x7F: d += Utf8Encode(d, SCC_CURRENCY); break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   197
			case 0x80: d += Utf8Encode(d, SCC_STRING); break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   198
			case 0x81: {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   199
				StringID string;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   200
				string  = *str++;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   201
				string |= *str++ << 8;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   202
				d += Utf8Encode(d, SCC_STRING_ID);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   203
				d += Utf8Encode(d, string);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   204
				break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   205
			}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   206
			case 0x82: d += Utf8Encode(d, SCC_DATE_TINY); break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   207
			case 0x83: d += Utf8Encode(d, SCC_DATE_SHORT); break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   208
			case 0x84: d += Utf8Encode(d, SCC_VELOCITY); break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   209
			case 0x85: d += Utf8Encode(d, SCC_SKIP);    break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   210
			case 0x86: /* "Rotate down top 4 words on stack" */ break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   211
			case 0x87: d += Utf8Encode(d, SCC_VOLUME);  break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   212
			case 0x88: d += Utf8Encode(d, SCC_BLUE);    break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   213
			case 0x89: d += Utf8Encode(d, SCC_SILVER);  break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   214
			case 0x8A: d += Utf8Encode(d, SCC_GOLD);    break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   215
			case 0x8B: d += Utf8Encode(d, SCC_RED);     break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   216
			case 0x8C: d += Utf8Encode(d, SCC_PURPLE);  break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   217
			case 0x8D: d += Utf8Encode(d, SCC_LTBROWN); break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   218
			case 0x8E: d += Utf8Encode(d, SCC_ORANGE);  break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   219
			case 0x8F: d += Utf8Encode(d, SCC_GREEN);   break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   220
			case 0x90: d += Utf8Encode(d, SCC_YELLOW);  break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   221
			case 0x91: d += Utf8Encode(d, SCC_DKGREEN); break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   222
			case 0x92: d += Utf8Encode(d, SCC_CREAM);   break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   223
			case 0x93: d += Utf8Encode(d, SCC_BROWN);   break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   224
			case 0x94: d += Utf8Encode(d, SCC_WHITE);   break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   225
			case 0x95: d += Utf8Encode(d, SCC_LTBLUE);  break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   226
			case 0x96: d += Utf8Encode(d, SCC_GRAY);    break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   227
			case 0x97: d += Utf8Encode(d, SCC_DKBLUE);  break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   228
			case 0x98: d += Utf8Encode(d, SCC_BLACK);   break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   229
			case 0x9E: d += Utf8Encode(d, 0x20AC); break; // Euro
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   230
			case 0x9F: d += Utf8Encode(d, 0x0178); break; // Y with diaeresis
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   231
			case 0xA0: d += Utf8Encode(d, SCC_UPARROW); break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   232
			case 0xAA: d += Utf8Encode(d, SCC_DOWNARROW); break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   233
			case 0xAC: d += Utf8Encode(d, SCC_CHECKMARK); break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   234
			case 0xAD: d += Utf8Encode(d, SCC_CROSS); break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   235
			case 0xAF: d += Utf8Encode(d, SCC_RIGHTARROW); break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   236
			case 0xB4: d += Utf8Encode(d, SCC_TRAIN); break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   237
			case 0xB5: d += Utf8Encode(d, SCC_LORRY); break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   238
			case 0xB6: d += Utf8Encode(d, SCC_BUS); break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   239
			case 0xB7: d += Utf8Encode(d, SCC_PLANE); break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   240
			case 0xB8: d += Utf8Encode(d, SCC_SHIP); break;
3646
4506e8954c11 (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   241
			default:
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   242
				if (unicode) {
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   243
					d += Utf8Encode(d, Utf8Consume(&tmp));
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   244
					str = tmp;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   245
					break;
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   246
				}
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   247
3646
4506e8954c11 (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   248
				/* Validate any unhandled character */
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   249
				if (!IsValidChar(c, CS_ALPHANUMERAL)) c = '?';
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   250
				d += Utf8Encode(d, c);
3646
4506e8954c11 (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   251
				break;
4506e8954c11 (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   252
		}
4506e8954c11 (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   253
	}
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   254
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   255
	*d = '\0';
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   256
	return realloc(tmp, strlen(tmp) + 1);
3646
4506e8954c11 (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   257
}
4506e8954c11 (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   258
4506e8954c11 (svn r4557) - NewGRF: translate from TTDPatch control codes to our own, instead of just simple validation. We still perform
peter1138
parents: 3641
diff changeset
   259
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   260
/**
3641
7dc47659e794 (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
   261
 * Add the new read string into our structure.
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   262
 */
3821
2bb8a2643fdf (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
StringID AddGRFString(uint32 grfid, uint16 stringid, byte langid_to_add, bool new_scheme, const char *text_to_add, StringID def_string)
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   264
{
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   265
	char *translatedtext;
3603
b79fac8ba026 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   266
	GRFText *newtext;
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   267
	uint id;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   268
3641
7dc47659e794 (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
   269
	/* When working with the old language scheme (grf_version is less than 7) and
3603
b79fac8ba026 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   270
	 * English or American is among the set bits, simply add it as English in
b79fac8ba026 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   271
	 * the new scheme, i.e. as langid = 1.
b79fac8ba026 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   272
	 * If English is set, it is pretty safe to assume the translations are not
b79fac8ba026 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   273
	 * actually translated.
b79fac8ba026 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   274
	 */
3641
7dc47659e794 (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
   275
	if (!new_scheme) {
3603
b79fac8ba026 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   276
		if (HASBITS(langid_to_add, GRFLB_AMERICAN | GRFLB_ENGLISH)) {
b79fac8ba026 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   277
			langid_to_add = GRFLX_ENGLISH;
b79fac8ba026 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   278
		} else {
b79fac8ba026 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   279
			StringID ret = STR_EMPTY;
5047
329bb4f145a9 (svn r7096) -Fix (r6995 (sort-of)): Don't set bit 6 when convert grf ver 6 language ids to use ver 7 format
peter1138
parents: 4992
diff changeset
   280
			if (langid_to_add & GRFLB_GERMAN)  ret = AddGRFString(grfid, stringid, GRFLX_GERMAN,  true, text_to_add, def_string);
329bb4f145a9 (svn r7096) -Fix (r6995 (sort-of)): Don't set bit 6 when convert grf ver 6 language ids to use ver 7 format
peter1138
parents: 4992
diff changeset
   281
			if (langid_to_add & GRFLB_FRENCH)  ret = AddGRFString(grfid, stringid, GRFLX_FRENCH,  true, text_to_add, def_string);
329bb4f145a9 (svn r7096) -Fix (r6995 (sort-of)): Don't set bit 6 when convert grf ver 6 language ids to use ver 7 format
peter1138
parents: 4992
diff changeset
   282
			if (langid_to_add & GRFLB_SPANISH) ret = AddGRFString(grfid, stringid, GRFLX_SPANISH, true, text_to_add, def_string);
3603
b79fac8ba026 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   283
			return ret;
b79fac8ba026 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   284
		}
b79fac8ba026 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   285
	}
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   286
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   287
	for (id = 0; id < _num_grf_texts; id++) {
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   288
		if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   289
			break;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   290
		}
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   291
	}
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   292
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   293
	/* Too many strings allocated, return empty */
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   294
	if (id == lengthof(_grf_text)) return STR_EMPTY;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   295
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   296
	translatedtext = TranslateTTDPatchCodes(text_to_add);
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   297
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   298
	newtext = malloc(sizeof(*newtext) + strlen(translatedtext) + 1);
4305
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   299
	newtext->next   = NULL;
4992
6d0a80c5c654 (svn r6995) - Codechange: NewGRF; strip bit 7 of the language ID earlier and handle handle a language ID of 0x7F as the preferred default language.
peter1138
parents: 4915
diff changeset
   300
	newtext->langid = langid_to_add;
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   301
	strcpy(newtext->text, translatedtext);
3856
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   302
5108
dc67d70b5a45 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 5047
diff changeset
   303
	free(translatedtext);
3856
6b6870aa2691 (svn r4888) CodeChange : Newgrf : little cleanup and additions
belugas
parents: 3821
diff changeset
   304
3603
b79fac8ba026 (svn r4495) - NewGRF: Implement conversion from old language IDs (bitmask) to new language IDs (value)
peter1138
parents: 3602
diff changeset
   305
	/* If we didn't find our stringid and grfid in the list, allocate a new id */
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   306
	if (id == _num_grf_texts) _num_grf_texts++;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   307
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   308
	if (_grf_text[id].textholder == NULL) {
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   309
		_grf_text[id].grfid      = grfid;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   310
		_grf_text[id].stringid   = stringid;
3821
2bb8a2643fdf (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
   311
		_grf_text[id].def_string = def_string;
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   312
		_grf_text[id].textholder = newtext;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   313
	} else {
4711
bfeaddae37c5 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   314
		GRFText **ptext, *text;
bfeaddae37c5 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   315
		bool replaced = false;
bfeaddae37c5 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   316
bfeaddae37c5 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   317
		/* Loop through all languages and see if we can replace a string */
bfeaddae37c5 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   318
		for (ptext = &_grf_text[id].textholder; (text = *ptext) != NULL; ptext = &text->next) {
4992
6d0a80c5c654 (svn r6995) - Codechange: NewGRF; strip bit 7 of the language ID earlier and handle handle a language ID of 0x7F as the preferred default language.
peter1138
parents: 4915
diff changeset
   319
			if (text->langid != langid_to_add) continue;
4711
bfeaddae37c5 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   320
			newtext->next = text->next;
bfeaddae37c5 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   321
			*ptext = newtext;
bfeaddae37c5 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   322
			free(text);
bfeaddae37c5 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   323
			replaced = true;
bfeaddae37c5 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   324
			break;
bfeaddae37c5 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   325
		}
bfeaddae37c5 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   326
bfeaddae37c5 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   327
		/* If a string wasn't replaced, then we must append the new string */
bfeaddae37c5 (svn r6623) - Codechange: When adding a NewGRF string, check to see if it can replace an existing string. Also remove string length check on load which was a quickfix for some grfs.
peter1138
parents: 4710
diff changeset
   328
		if (!replaced) *ptext = newtext;
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   329
	}
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   330
5568
75f13d7bfaed (svn r7565) -Codechange: Rework DEBUG functionality. Look for appropiate debugging levels to
Darkvater
parents: 5344
diff changeset
   331
	grfmsg(3, "Added 0x%X: grfid %08X string 0x%X lang 0x%X string '%s'", id, grfid, stringid, newtext->langid, newtext->text);
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   332
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   333
	return (GRFTAB << TABSIZE) + id;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   334
}
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   335
4710
a663b32b9f96 (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4624
diff changeset
   336
/* Used to remember the grfid that the last retrieved string came from */
a663b32b9f96 (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4624
diff changeset
   337
static uint32 _last_grfid = 0;
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   338
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   339
/**
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   340
 * Returns the index for this stringid associated with its grfID
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   341
 */
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   342
StringID GetGRFStringID(uint32 grfid, uint16 stringid)
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   343
{
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   344
	uint id;
4710
a663b32b9f96 (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4624
diff changeset
   345
a663b32b9f96 (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4624
diff changeset
   346
	/* grfid is zero when we're being called via an include */
a663b32b9f96 (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4624
diff changeset
   347
	if (grfid == 0) grfid = _last_grfid;
a663b32b9f96 (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4624
diff changeset
   348
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   349
	for (id = 0; id < _num_grf_texts; id++) {
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   350
		if (_grf_text[id].grfid == grfid && _grf_text[id].stringid == stringid) {
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   351
			return (GRFTAB << TABSIZE) + id;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   352
		}
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   353
	}
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   354
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   355
	return STR_UNDEFINED;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   356
}
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   357
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   358
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4711
diff changeset
   359
char *GetGRFString(char *buff, uint16 stringid, const char* last)
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   360
{
4305
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   361
	const GRFText *default_text = NULL;
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   362
	const GRFText *search_text;
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   363
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   364
	assert(_grf_text[stringid].grfid != 0);
4710
a663b32b9f96 (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4624
diff changeset
   365
a663b32b9f96 (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4624
diff changeset
   366
	/* Remember this grfid in case the string has included text */
a663b32b9f96 (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4624
diff changeset
   367
	_last_grfid = _grf_text[stringid].grfid;
a663b32b9f96 (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4624
diff changeset
   368
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   369
	/*Search the list of lang-strings of this stringid for current lang */
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   370
	for (search_text = _grf_text[stringid].textholder; search_text != NULL; search_text = search_text->next) {
3821
2bb8a2643fdf (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
   371
		if (search_text->langid == _currentLangID) {
4915
b3b625640fa6 (svn r6888) - Fix (r6884): Missed a couple of strecpy()s in newgrf text handling
peter1138
parents: 4912
diff changeset
   372
			return strecpy(buff, search_text->text, last);
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   373
		}
3821
2bb8a2643fdf (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
   374
2bb8a2643fdf (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
   375
		/* If the current string is English or American, set it as the
2bb8a2643fdf (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
   376
		 * fallback language if the specific language isn't available. */
4992
6d0a80c5c654 (svn r6995) - Codechange: NewGRF; strip bit 7 of the language ID earlier and handle handle a language ID of 0x7F as the preferred default language.
peter1138
parents: 4915
diff changeset
   377
		if (search_text->langid == GRFLX_UNSPECIFIED || (default_text == NULL && (search_text->langid == GRFLX_ENGLISH || search_text->langid == GRFLX_AMERICAN))) {
3821
2bb8a2643fdf (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
   378
			default_text = search_text;
2bb8a2643fdf (svn r4832) - NewGRF: add support for original string ID to newgrf text handling. So far, this is used for vehicles when no English or American translation is provided.
peter1138
parents: 3646
diff changeset
   379
		}
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   380
	}
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   381
3821
2bb8a2643fdf (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
   382
	/* If there is a fallback string, return that */
4915
b3b625640fa6 (svn r6888) - Fix (r6884): Missed a couple of strecpy()s in newgrf text handling
peter1138
parents: 4912
diff changeset
   383
	if (default_text != NULL) return strecpy(buff, default_text->text, last);
3821
2bb8a2643fdf (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
   384
2bb8a2643fdf (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
   385
	/* Use the default string ID if the fallback string isn't available */
4912
d04b3f2bca70 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4711
diff changeset
   386
	return GetString(buff, _grf_text[stringid].def_string, last);
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   387
}
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   388
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   389
/**
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   390
 * Equivalence Setter function between game and newgrf langID.
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   391
 * This function will adjust _currentLangID as to what is the LangID
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   392
 * of the current language set by the user.
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   393
 * The array iso_codes will be used to find that match.
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   394
 * If not found, it will have to be standard english
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   395
 * This function is called after the user changed language,
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   396
 * from strings.c:ReadLanguagePack
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   397
 * @param iso code of current selection
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   398
 */
3605
045805e70df0 (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   399
void SetCurrentGrfLangID(const char *iso_name)
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   400
{
3605
045805e70df0 (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   401
	/* Use English by default, if we can't match up the iso_code. */
4305
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   402
	byte ret = GRFLX_ENGLISH;
c25b05028b71 (svn r5952) - struct GRFText{Entry,} are private to newgrf_text.c
tron
parents: 4299
diff changeset
   403
	byte i;
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   404
3605
045805e70df0 (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   405
	for (i=0; i < lengthof(iso_codes); i++) {
3868
363ae2b6b55c (svn r4905) - NewGRF: fix typo that prevented non-english NewGRF text from working.
peter1138
parents: 3856
diff changeset
   406
		if (strncmp(iso_codes[i].code, iso_name, strlen(iso_codes[i].code)) == 0) {
3605
045805e70df0 (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   407
			/* We found a match, so let's use it. */
045805e70df0 (svn r4497) - NewGRF minor fixes: (Rubidium)
peter1138
parents: 3603
diff changeset
   408
			ret = i;
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   409
			break;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   410
		}
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   411
	}
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   412
	_currentLangID = ret;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   413
}
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   414
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   415
/**
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   416
 * House cleaning.
3602
7e1fe983f357 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   417
 * Remove all strings and reset the text counter.
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   418
 */
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   419
void CleanUpStrings(void)
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   420
{
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   421
	uint id;
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   422
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   423
	for (id = 0; id < _num_grf_texts; id++) {
3602
7e1fe983f357 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   424
		GRFText *grftext = _grf_text[id].textholder;
7e1fe983f357 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   425
		while (grftext != NULL) {
7e1fe983f357 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   426
			GRFText *grftext2 = grftext->next;
7e1fe983f357 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   427
			free(grftext);
7e1fe983f357 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   428
			grftext = grftext2;
7e1fe983f357 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   429
		}
7e1fe983f357 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   430
		_grf_text[id].grfid      = 0;
7e1fe983f357 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   431
		_grf_text[id].stringid   = 0;
7e1fe983f357 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   432
		_grf_text[id].textholder = NULL;
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   433
	}
3602
7e1fe983f357 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   434
7e1fe983f357 (svn r4494) - NewGRF: Clean up and reset custom texts
peter1138
parents: 3601
diff changeset
   435
	_num_grf_texts = 0;
3601
ac6df06db648 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents:
diff changeset
   436
}