src/strings.cpp
author translators
Mon, 08 Dec 2008 16:29:36 +0000
changeset 10411 4c9d49e5589a
parent 10372 ac1e34769a83
permissions -rw-r--r--
(svn r14662) -Update: WebTranslator2 update to 2008-12-08 16:28:15
frisian - 216 fixed, 14 changed by Frysl?n Boppe (230)
hebrew - 109 fixed, 2 changed by ybungalobill (111)
hungarian - 1 changed by oklmernok (1)
indonesian - 115 fixed by adjayanto (59), fanioz (56)
lithuanian - 24 fixed by Enternald (24)
malay - 41 fixed by Syed (41)
norwegian_nynorsk - 72 fixed by Thor (72)
turkish - 3 changed by Emin (3)
2186
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     1
/* $Id$ */
db48cf29b983 (svn r2701) Insert Id tags into all source files
tron
parents: 2163
diff changeset
     2
9111
48ce04029fe4 (svn r12971) -Documentation: add @file in files that missed them and add something more than whitespace as description of files that don't have a description.
rubidium
parents: 9085
diff changeset
     3
/** @file strings.cpp Handling of translated strings. */
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
     4
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
     5
#include "stdafx.h"
1891
862800791170 (svn r2397) - CodeChange: rename all "ttd" files to "openttd" files.
Darkvater
parents: 1853
diff changeset
     6
#include "openttd.h"
2291
c142846954ee (svn r2815) Store the currency information in one central place instead of scattering it in several unrelated files
tron
parents: 2257
diff changeset
     7
#include "currency.h"
8764
771b642c60e0 (svn r12460) -Change: rename src/namegen.h to src/namegen_func.h so MSVC can have both files in it's treelist.
rubidium
parents: 8763
diff changeset
     8
#include "namegen_func.h"
8785
871586967963 (svn r12489) -Codechange: split station.h into station_base.h and station_func.h.
rubidium
parents: 8764
diff changeset
     9
#include "station_base.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    10
#include "town.h"
430
2e9a2e9fcf11 (svn r631) Merge r440, r444, r485, r630 to trunk:
tron
parents: 425
diff changeset
    11
#include "screenshot.h"
1542
62a03537ad0b (svn r2046) -Codechange: moved all waypoint code to waypoint.c/waypoint.h
truelight
parents: 1376
diff changeset
    12
#include "waypoint.h"
2070
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
    13
#include "industry.h"
2159
f6284cf5fab0 (svn r2669) Shuffle some more stuff around to reduce dependencies
tron
parents: 2150
diff changeset
    14
#include "variables.h"
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3489
diff changeset
    15
#include "newgrf_text.h"
4120
b21fda0c260a (svn r5464) [Behaviour Fix] : When starting the game, the system will now verify the presence of music files in gm forlder.
belugas
parents: 3833
diff changeset
    16
#include "music.h"
4942
7fb6c39eb421 (svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents: 4920
diff changeset
    17
#include "industry.h"
10039
1f236afd6cd1 (svn r14199) -Codechange: split fileio.h into fileio_type.h and fileio_func.h so not everything that includes saveload.h needs to include everything else too.
rubidium
parents: 9768
diff changeset
    18
#include "fileio_func.h"
6091
c8827d9ae04a (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents: 6088
diff changeset
    19
#include "cargotype.h"
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6492
diff changeset
    20
#include "group.h"
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6492
diff changeset
    21
#include "debug.h"
6956
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
    22
#include "newgrf_townname.h"
8790
4a7a796b3976 (svn r12501) -Codechange: split signs.h.
rubidium
parents: 8786
diff changeset
    23
#include "signs_base.h"
7059
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7058
diff changeset
    24
#include "newgrf_engine.h"
8086
48da1cf8f7d1 (svn r11647) -Fix (r11646): it did not compile without freetype...
rubidium
parents: 8085
diff changeset
    25
#include "spritecache.h"
8085
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 7954
diff changeset
    26
#include "fontcache.h"
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 7954
diff changeset
    27
#include "gui.h"
8114
dd6d21dc99c1 (svn r11675) -Codechange: split the string types from the string functions.
rubidium
parents: 8087
diff changeset
    28
#include "strings_func.h"
8131
160939e24ed3 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8130
diff changeset
    29
#include "functions.h"
9085
8b3897a75aed (svn r12944) -Codechange: use rev.h instead of externs at many places
smatz
parents: 9070
diff changeset
    30
#include "rev.h"
8120
7128bb2b57a3 (svn r11681) -Fix (r11674): hopefully fix the compile error on big endian machines.
rubidium
parents: 8114
diff changeset
    31
#include "core/endian_func.hpp"
8140
0d0d8c94f84b (svn r11702) -Codechange: move all date related stuff to date*.
rubidium
parents: 8132
diff changeset
    32
#include "date_func.h"
8144
65cec0877b78 (svn r11706) -Codechange: split vehicle.h and remove another bunch of useless includes.
rubidium
parents: 8140
diff changeset
    33
#include "vehicle_base.h"
8214
971f861d5543 (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8202
diff changeset
    34
#include "string_func.h"
10208
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
    35
#include "company_func.h"
72c00af5c95d (svn r14422) -Codechange: also reflect the changes of r14421 in the filenames.
rubidium
parents: 10207
diff changeset
    36
#include "company_base.h"
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8258
diff changeset
    37
#include "fios.h"
8270
e7c342f6b14c (svn r11834) -Codechange: only include settings_type.h if needed.
rubidium
parents: 8264
diff changeset
    38
#include "settings_type.h"
8275
f17d0c863ee3 (svn r11839) -Codechange: move some variables from variables.h to a more logical location.
rubidium
parents: 8270
diff changeset
    39
#include "video/video_driver.hpp"
8786
1823ff88a054 (svn r12490) -Codechange: rename engine.h to engine_func.h and remove unneeded inclusions of engine.h and/or replace them with engine_type.h.
rubidium
parents: 8785
diff changeset
    40
#include "engine_func.h"
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 8998
diff changeset
    41
#include "engine_base.h"
8987
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
    42
#include "saveload.h"
10366
74b3472edfa4 (svn r14617) -Change: unduplicate the languagepack(header).
rubidium
parents: 10347
diff changeset
    43
#include "strgen/strgen.h"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    44
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8258
diff changeset
    45
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8258
diff changeset
    46
#include "table/control_codes.h"
4219
72768a8f3a97 (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
    47
6320
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
    48
DynamicLanguages _dynlang;
7266
b16e67e992b4 (svn r10587) -Codechange: move the string/dparam related stuff from variables.h to strings.h
rubidium
parents: 7059
diff changeset
    49
uint64 _decode_parameters[20];
2201
f240b3c7e2ec (svn r2717) Move _userstring to strings.[ch]
tron
parents: 2186
diff changeset
    50
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
    51
static char *StationGetSpecialString(char *buff, int x, const char *last);
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
    52
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char *last);
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
    53
static char *GetSpecialNameString(char *buff, int ind, const int64 *argv, const char *last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    54
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
    55
static char *FormatString(char *buff, const char *str, const int64 *argv, uint casei, const char *last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    56
10366
74b3472edfa4 (svn r14617) -Change: unduplicate the languagepack(header).
rubidium
parents: 10347
diff changeset
    57
struct LanguagePack : public LanguagePackHeader {
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
    58
	char data[VARARRAY_SIZE]; // list of strings
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
    59
};
1319
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    60
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    61
static char **_langpack_offs;
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    62
static LanguagePack *_langpack;
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
    63
static uint _langtab_num[32];   // Offset into langpack offs
1319
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
    64
static uint _langtab_start[32]; // Offset into langpack offs
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    65
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    66
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
    67
/** Read an int64 from the argv array. */
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
    68
static inline int64 GetInt64(const int64 **argv)
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    69
{
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    70
	assert(argv);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    71
	return *(*argv)++;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    72
}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    73
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
    74
/** Read an int32 from the argv array. */
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
    75
static inline int32 GetInt32(const int64 **argv)
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
    76
{
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
    77
	return (int32)GetInt64(argv);
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
    78
}
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
    79
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
    80
/** Read an array from the argv array. */
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
    81
static inline const int64 *GetArgvPtr(const int64 **argv, int n)
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    82
{
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
    83
	const int64 *result;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    84
	assert(*argv);
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    85
	result = *argv;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    86
	(*argv) += n;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    87
	return result;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    88
}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    89
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
    90
8445
54a5d84d1d7d (svn r12015) -Fix [FS#1716] (Revert r11422): Patch in FS#1430 avoided instead of fixed the problem. GetStringWithArgs() discards information that SCC_GENDER_LIST needs to work. Now use pointers to retrieve GRF strings, so that GetStringPtr() will work correctly. This is advantageous as now no buffer copy is made when using all GRF strings.
peter1138
parents: 8323
diff changeset
    91
const char *GetStringPtr(StringID string)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    92
{
8445
54a5d84d1d7d (svn r12015) -Fix [FS#1716] (Revert r11422): Patch in FS#1430 avoided instead of fixed the problem. GetStringWithArgs() discards information that SCC_GENDER_LIST needs to work. Now use pointers to retrieve GRF strings, so that GetStringPtr() will work correctly. This is advantageous as now no buffer copy is made when using all GRF strings.
peter1138
parents: 8323
diff changeset
    93
	switch (GB(string, 11, 5)) {
54a5d84d1d7d (svn r12015) -Fix [FS#1716] (Revert r11422): Patch in FS#1430 avoided instead of fixed the problem. GetStringWithArgs() discards information that SCC_GENDER_LIST needs to work. Now use pointers to retrieve GRF strings, so that GetStringPtr() will work correctly. This is advantageous as now no buffer copy is made when using all GRF strings.
peter1138
parents: 8323
diff changeset
    94
		case 28: return GetGRFStringPtr(GB(string, 0, 11));
54a5d84d1d7d (svn r12015) -Fix [FS#1716] (Revert r11422): Patch in FS#1430 avoided instead of fixed the problem. GetStringWithArgs() discards information that SCC_GENDER_LIST needs to work. Now use pointers to retrieve GRF strings, so that GetStringPtr() will work correctly. This is advantageous as now no buffer copy is made when using all GRF strings.
peter1138
parents: 8323
diff changeset
    95
		case 29: return GetGRFStringPtr(GB(string, 0, 11) + 0x0800);
54a5d84d1d7d (svn r12015) -Fix [FS#1716] (Revert r11422): Patch in FS#1430 avoided instead of fixed the problem. GetStringWithArgs() discards information that SCC_GENDER_LIST needs to work. Now use pointers to retrieve GRF strings, so that GetStringPtr() will work correctly. This is advantageous as now no buffer copy is made when using all GRF strings.
peter1138
parents: 8323
diff changeset
    96
		case 30: return GetGRFStringPtr(GB(string, 0, 11) + 0x1000);
54a5d84d1d7d (svn r12015) -Fix [FS#1716] (Revert r11422): Patch in FS#1430 avoided instead of fixed the problem. GetStringWithArgs() discards information that SCC_GENDER_LIST needs to work. Now use pointers to retrieve GRF strings, so that GetStringPtr() will work correctly. This is advantageous as now no buffer copy is made when using all GRF strings.
peter1138
parents: 8323
diff changeset
    97
		default: return _langpack_offs[_langtab_start[string >> 11] + (string & 0x7FF)];
54a5d84d1d7d (svn r12015) -Fix [FS#1716] (Revert r11422): Patch in FS#1430 avoided instead of fixed the problem. GetStringWithArgs() discards information that SCC_GENDER_LIST needs to work. Now use pointers to retrieve GRF strings, so that GetStringPtr() will work correctly. This is advantageous as now no buffer copy is made when using all GRF strings.
peter1138
parents: 8323
diff changeset
    98
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
    99
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   100
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   101
/** The highest 8 bits of string contain the "case index".
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   102
 * These 8 bits will only be set when FormatString wants to print
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   103
 * the string in a different case. No one else except FormatString
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   104
 * should set those bits, therefore string CANNOT be StringID, but uint32.
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   105
 * @param buffr
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   106
 * @param string
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   107
 * @param argv
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   108
 * @param last
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   109
 * @return a formatted string of char
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   110
 */
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
   111
static char *GetStringWithArgs(char *buffr, uint string, const int64 *argv, const char *last)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   112
{
7810
6b4a83fb86c8 (svn r11360) -Fix [FS#1375]: do not crash when trying to "draw" an invalid string, just draw a message saying it is invalid.
rubidium
parents: 7763
diff changeset
   113
	if (GB(string, 0, 16) == 0) return GetStringWithArgs(buffr, STR_UNDEFINED, argv, last);
6b4a83fb86c8 (svn r11360) -Fix [FS#1375]: do not crash when trying to "draw" an invalid string, just draw a message saying it is invalid.
rubidium
parents: 7763
diff changeset
   114
2140
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2131
diff changeset
   115
	uint index = GB(string,  0, 11);
a04d0142ad65 (svn r2650) Convert many explicit shifts+ands to extract bits to invocations of GB - should be a bit nicer to read
tron
parents: 2131
diff changeset
   116
	uint tab   = GB(string, 11,  5);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   117
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   118
	switch (tab) {
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   119
		case 4:
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   120
			if (index >= 0xC0)
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   121
				return GetSpecialTownNameString(buffr, index - 0xC0, GetInt32(&argv), last);
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   122
			break;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   123
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   124
		case 14:
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   125
			if (index >= 0xE4)
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10197
diff changeset
   126
				return GetSpecialNameString(buffr, index - 0xE4, argv, last);
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   127
			break;
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   128
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   129
		case 15:
8445
54a5d84d1d7d (svn r12015) -Fix [FS#1716] (Revert r11422): Patch in FS#1430 avoided instead of fixed the problem. GetStringWithArgs() discards information that SCC_GENDER_LIST needs to work. Now use pointers to retrieve GRF strings, so that GetStringPtr() will work correctly. This is advantageous as now no buffer copy is made when using all GRF strings.
peter1138
parents: 8323
diff changeset
   130
			/* Old table for custom names. This is no longer used */
54a5d84d1d7d (svn r12015) -Fix [FS#1716] (Revert r11422): Patch in FS#1430 avoided instead of fixed the problem. GetStringWithArgs() discards information that SCC_GENDER_LIST needs to work. Now use pointers to retrieve GRF strings, so that GetStringPtr() will work correctly. This is advantageous as now no buffer copy is made when using all GRF strings.
peter1138
parents: 8323
diff changeset
   131
			error("Incorrect conversion of custom name string.");
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   132
4710
1aa2b507818f (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4602
diff changeset
   133
		case 26:
1aa2b507818f (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4602
diff changeset
   134
			/* Include string within newgrf text (format code 81) */
7928
63e18de69e50 (svn r11481) -Codechange: Rename the HASBIT function to fit with the naming style
skidd13
parents: 7872
diff changeset
   135
			if (HasBit(index, 10)) {
4710
1aa2b507818f (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4602
diff changeset
   136
				StringID string = GetGRFStringID(0, 0xD000 + GB(index, 0, 10));
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   137
				return GetStringWithArgs(buffr, string, argv, last);
4710
1aa2b507818f (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4602
diff changeset
   138
			}
1aa2b507818f (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4602
diff changeset
   139
			break;
1aa2b507818f (svn r6622) - Add support for NewGRF text includes. (Based on mart3p's patch)
peter1138
parents: 4602
diff changeset
   140
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3489
diff changeset
   141
		case 28:
8445
54a5d84d1d7d (svn r12015) -Fix [FS#1716] (Revert r11422): Patch in FS#1430 avoided instead of fixed the problem. GetStringWithArgs() discards information that SCC_GENDER_LIST needs to work. Now use pointers to retrieve GRF strings, so that GetStringPtr() will work correctly. This is advantageous as now no buffer copy is made when using all GRF strings.
peter1138
parents: 8323
diff changeset
   142
			return FormatString(buffr, GetGRFStringPtr(index), argv, 0, last);
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3489
diff changeset
   143
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3489
diff changeset
   144
		case 29:
8445
54a5d84d1d7d (svn r12015) -Fix [FS#1716] (Revert r11422): Patch in FS#1430 avoided instead of fixed the problem. GetStringWithArgs() discards information that SCC_GENDER_LIST needs to work. Now use pointers to retrieve GRF strings, so that GetStringPtr() will work correctly. This is advantageous as now no buffer copy is made when using all GRF strings.
peter1138
parents: 8323
diff changeset
   145
			return FormatString(buffr, GetGRFStringPtr(index + 0x0800), argv, 0, last);
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3489
diff changeset
   146
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3489
diff changeset
   147
		case 30:
8445
54a5d84d1d7d (svn r12015) -Fix [FS#1716] (Revert r11422): Patch in FS#1430 avoided instead of fixed the problem. GetStringWithArgs() discards information that SCC_GENDER_LIST needs to work. Now use pointers to retrieve GRF strings, so that GetStringPtr() will work correctly. This is advantageous as now no buffer copy is made when using all GRF strings.
peter1138
parents: 8323
diff changeset
   148
			return FormatString(buffr, GetGRFStringPtr(index + 0x1000), argv, 0, last);
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3489
diff changeset
   149
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   150
		case 31:
9648
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9543
diff changeset
   151
			NOT_REACHED();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   152
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   153
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   154
	if (index >= _langtab_num[tab]) {
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   155
		error(
9470
08424e2e79e4 (svn r13390) -Codechange: introduce usererror() for fatal but not openttd related errors. Now all error() will 'crash' openttd after showing the message in win32 releases (MSVC), creating a crash.log and crash.dmp (like the '!' hack used before). On the other hand, usererror() will just close the game. So use error() only when it can be helpful to debugging, else use usererror().
glx
parents: 9466
diff changeset
   156
			"String 0x%X is invalid. "
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   157
			"Probably because an old version of the .lng file.\n", string
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
   158
		);
2639
eeaefdabfdfd (svn r3181) -Bracing
tron
parents: 2635
diff changeset
   159
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   160
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   161
	return FormatString(buffr, GetStringPtr(GB(string, 0, 16)), argv, GB(string, 24, 8), last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   162
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   163
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
   164
char *GetString(char *buffr, StringID string, const char *last)
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   165
{
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
   166
	return GetStringWithArgs(buffr, string, (int64*)_decode_parameters, last);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   167
}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   168
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   169
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   170
char *InlineString(char *buf, StringID string)
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   171
{
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   172
	buf += Utf8Encode(buf, SCC_STRING_ID);
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   173
	buf += Utf8Encode(buf, string);
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   174
	return buf;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   175
}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   176
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   177
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   178
/** This function is used to "bind" a C string to a OpenTTD dparam slot.
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   179
 * @param n slot of the string
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   180
 * @param str string to bind
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   181
 */
2055
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   182
void SetDParamStr(uint n, const char *str)
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   183
{
9768
0c0fb94c89df (svn r13904) -Fix (r13715): 'cast from/to pointer to/from integer of different size' warnings
glx
parents: 9659
diff changeset
   184
	SetDParam(n, (uint64)(size_t)str);
2055
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   185
}
4926ed1a7562 (svn r2564) Fix: Fixed conceptual issue in network_gui.c. AllocateName is not meant to be used by GUI-code, because it modifies the "game-state".
ludde
parents: 2053
diff changeset
   186
10197
fa185196aef1 (svn r14410) -Codechange: one can't inject a negative number of parameters, so enforce this by using a uint.
rubidium
parents: 10135
diff changeset
   187
void InjectDParam(uint amount)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   188
{
10197
fa185196aef1 (svn r14410) -Codechange: one can't inject a negative number of parameters, so enforce this by using a uint.
rubidium
parents: 10135
diff changeset
   189
	assert((uint)amount < lengthof(_decode_parameters));
7006
bfa3974da32b (svn r10262) -Fix (r10258): some places that needed to be changed to uint64 were hidden/forgotten, which caused memory corruptions and that in caused all kinds of assertions to trigger.
rubidium
parents: 7005
diff changeset
   190
	memmove(_decode_parameters + amount, _decode_parameters, sizeof(_decode_parameters) - amount * sizeof(uint64));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   191
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   192
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   193
// TODO
7356
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   194
static char *FormatCommaNumber(char *buff, int64 number, const char *last)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   195
{
7356
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   196
	uint64 divisor = 10000000000000000000ULL;
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   197
	uint64 quot;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   198
	int i;
7356
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   199
	uint64 tot;
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   200
	uint64 num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   201
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   202
	if (number < 0) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   203
		*buff++ = '-';
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   204
		number = -number;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   205
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   206
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   207
	num = number;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   208
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   209
	tot = 0;
7356
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   210
	for (i = 0; i < 20; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   211
		quot = 0;
7356
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   212
		if (num >= divisor) {
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   213
			quot = num / divisor;
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   214
			num = num % divisor;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   215
		}
7356
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   216
		if (tot |= quot || i == 19) {
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   217
			*buff++ = '0' + quot;
7356
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   218
			if ((i % 3) == 1 && i != 19) *buff++ = ',';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   219
		}
7356
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   220
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   221
		divisor /= 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   222
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   223
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   224
	*buff = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   225
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   226
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   227
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   228
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   229
// TODO
7356
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   230
static char *FormatNoCommaNumber(char *buff, int64 number, const char *last)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   231
{
7356
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   232
	uint64 divisor = 10000000000000000000ULL;
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   233
	uint64 quot;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   234
	int i;
7356
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   235
	uint64 tot;
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   236
	uint64 num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   237
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   238
	if (number < 0) {
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   239
		buff = strecpy(buff, "-", last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   240
		number = -number;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   241
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   242
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   243
	num = number;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   244
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   245
	tot = 0;
7356
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   246
	for (i = 0; i < 20; i++) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   247
		quot = 0;
7356
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   248
		if (num >= divisor) {
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   249
			quot = num / divisor;
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   250
			num = num % divisor;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   251
		}
7356
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   252
		if (tot |= quot || i == 19) {
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
   253
			*buff++ = '0' + quot;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   254
		}
7356
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   255
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   256
		divisor /= 10;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   257
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   258
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   259
	*buff = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   260
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   261
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   262
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   263
10135
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 10114
diff changeset
   264
static char *FormatHexNumber(char *buff, int64 number, const char *last)
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 10114
diff changeset
   265
{
10299
946c84fdc58e (svn r14540) -Codechange: introduce [v]seprintf which are like [v]snprintf but do return the number of characters written instead of the number of characters that would be written; as size_t is unsigned substraction can cause integer underflows quite quickly.
rubidium
parents: 10249
diff changeset
   266
	return buff + seprintf(buff, last, "0x%x", (uint32)number);
10135
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 10114
diff changeset
   267
}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   268
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
   269
static char *FormatYmdString(char *buff, Date date, const char *last)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   270
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   271
	YearMonthDay ymd;
4289
8981ce44336d (svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents: 4288
diff changeset
   272
	ConvertDateToYMD(date, &ymd);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   273
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
   274
	int64 args[3] = { ymd.day + STR_01AC_1ST - 1, STR_0162_JAN + ymd.month, ymd.year };
6158
346066286004 (svn r8906) -Feature: translation dependant formatting of dates.
rubidium
parents: 6091
diff changeset
   275
	return FormatString(buff, GetStringPtr(STR_DATE_LONG), args, 0, last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   276
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   277
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
   278
static char *FormatMonthAndYear(char *buff, Date date, const char *last)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   279
{
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   280
	YearMonthDay ymd;
4289
8981ce44336d (svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents: 4288
diff changeset
   281
	ConvertDateToYMD(date, &ymd);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   282
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
   283
	int64 args[2] = { STR_MONTH_JAN + ymd.month, ymd.year };
6158
346066286004 (svn r8906) -Feature: translation dependant formatting of dates.
rubidium
parents: 6091
diff changeset
   284
	return FormatString(buff, GetStringPtr(STR_DATE_SHORT), args, 0, last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   285
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   286
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
   287
static char *FormatTinyDate(char *buff, Date date, const char *last)
1097
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   288
{
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   289
	YearMonthDay ymd;
4289
8981ce44336d (svn r5919) -Cleanup: use the type Date when the variable really is a date
rubidium
parents: 4288
diff changeset
   290
	ConvertDateToYMD(date, &ymd);
1097
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   291
6158
346066286004 (svn r8906) -Feature: translation dependant formatting of dates.
rubidium
parents: 6091
diff changeset
   292
	char day[3];
346066286004 (svn r8906) -Feature: translation dependant formatting of dates.
rubidium
parents: 6091
diff changeset
   293
	char month[3];
346066286004 (svn r8906) -Feature: translation dependant formatting of dates.
rubidium
parents: 6091
diff changeset
   294
	/* We want to zero-pad the days and months */
346066286004 (svn r8906) -Feature: translation dependant formatting of dates.
rubidium
parents: 6091
diff changeset
   295
	snprintf(day,   lengthof(day),   "%02i", ymd.day);
346066286004 (svn r8906) -Feature: translation dependant formatting of dates.
rubidium
parents: 6091
diff changeset
   296
	snprintf(month, lengthof(month), "%02i", ymd.month + 1);
346066286004 (svn r8906) -Feature: translation dependant formatting of dates.
rubidium
parents: 6091
diff changeset
   297
9768
0c0fb94c89df (svn r13904) -Fix (r13715): 'cast from/to pointer to/from integer of different size' warnings
glx
parents: 9659
diff changeset
   298
	int64 args[3] = { (int64)(size_t)day, (int64)(size_t)month, ymd.year };
6158
346066286004 (svn r8906) -Feature: translation dependant formatting of dates.
rubidium
parents: 6091
diff changeset
   299
	return FormatString(buff, GetStringPtr(STR_DATE_TINY), args, 0, last);
1097
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   300
}
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   301
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
   302
static char *FormatGenericCurrency(char *buff, const CurrencySpec *spec, Money number, bool compact, const char *last)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   303
{
7763
342e5357b592 (svn r11312) -Codechange: implement a overflow safe integer and use that for money and don't misuses CommandCost to have a overflow safe integer. Based on a patch by Noldo.
rubidium
parents: 7616
diff changeset
   304
	/* We are going to make number absolute for printing, so
342e5357b592 (svn r11312) -Codechange: implement a overflow safe integer and use that for money and don't misuses CommandCost to have a overflow safe integer. Based on a patch by Noldo.
rubidium
parents: 7616
diff changeset
   305
	 * keep this piece of data as we need it later on */
342e5357b592 (svn r11312) -Codechange: implement a overflow safe integer and use that for money and don't misuses CommandCost to have a overflow safe integer. Based on a patch by Noldo.
rubidium
parents: 7616
diff changeset
   306
	bool negative = number < 0;
342e5357b592 (svn r11312) -Codechange: implement a overflow safe integer and use that for money and don't misuses CommandCost to have a overflow safe integer. Based on a patch by Noldo.
rubidium
parents: 7616
diff changeset
   307
	const char *multiplier = "";
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   308
	char buf[40];
7763
342e5357b592 (svn r11312) -Codechange: implement a overflow safe integer and use that for money and don't misuses CommandCost to have a overflow safe integer. Based on a patch by Noldo.
rubidium
parents: 7616
diff changeset
   309
	char *p;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   310
	int j;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   311
7763
342e5357b592 (svn r11312) -Codechange: implement a overflow safe integer and use that for money and don't misuses CommandCost to have a overflow safe integer. Based on a patch by Noldo.
rubidium
parents: 7616
diff changeset
   312
	number *= spec->rate;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   313
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   314
	/* convert from negative */
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   315
	if (number < 0) {
7422
fb7f6dc87b55 (svn r10820) -Codechange: make negative currencies red and restore the colour from before the currency was printed; this removes the need to make two strings for printing currencies (one for positive currencies and one for negative currencies).
rubidium
parents: 7411
diff changeset
   316
		if (buff + Utf8CharLen(SCC_RED) > last) return buff;
fb7f6dc87b55 (svn r10820) -Codechange: make negative currencies red and restore the colour from before the currency was printed; this removes the need to make two strings for printing currencies (one for positive currencies and one for negative currencies).
rubidium
parents: 7411
diff changeset
   317
		buff += Utf8Encode(buff, SCC_RED);
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   318
		buff = strecpy(buff, "-", last);
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   319
		number = -number;
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   320
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   321
4602
43c44f7df615 (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4505
diff changeset
   322
	/* Add prefix part, folowing symbol_pos specification.
43c44f7df615 (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4505
diff changeset
   323
	 * Here, it can can be either 0 (prefix) or 2 (both prefix anf suffix).
43c44f7df615 (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4505
diff changeset
   324
	 * The only remaining value is 1 (suffix), so everything that is not 1 */
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   325
	if (spec->symbol_pos != 1) buff = strecpy(buff, spec->prefix, last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   326
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   327
	/* for huge numbers, compact the number into k or M */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   328
	if (compact) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   329
		if (number >= 1000000000) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   330
			number = (number + 500000) / 1000000;
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   331
			multiplier = "M";
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   332
		} else if (number >= 1000000) {
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   333
			number = (number + 500) / 1000;
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   334
			multiplier = "k";
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   335
		}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   336
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   337
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   338
	/* convert to ascii number and add commas */
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   339
	p = endof(buf);
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   340
	*--p = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   341
	j = 4;
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
   342
	do {
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   343
		if (--j == 0) {
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   344
			*--p = spec->separator;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   345
			j = 3;
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   346
		}
7763
342e5357b592 (svn r11312) -Codechange: implement a overflow safe integer and use that for money and don't misuses CommandCost to have a overflow safe integer. Based on a patch by Noldo.
rubidium
parents: 7616
diff changeset
   347
		*--p = '0' + (char)(number % 10);
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   348
	} while ((number /= 10) != 0);
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   349
	buff = strecpy(buff, p, last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   350
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   351
	buff = strecpy(buff, multiplier, last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   352
4602
43c44f7df615 (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4505
diff changeset
   353
	/* Add suffix part, folowing symbol_pos specification.
43c44f7df615 (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4505
diff changeset
   354
	 * Here, it can can be either 1 (suffix) or 2 (both prefix anf suffix).
43c44f7df615 (svn r6454) -Fix(r6108) : Allow custom currency to display both prefix and suffix
belugas
parents: 4505
diff changeset
   355
	 * The only remaining value is 1 (prefix), so everything that is not 0 */
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   356
	if (spec->symbol_pos != 0) buff = strecpy(buff, spec->suffix, last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   357
7763
342e5357b592 (svn r11312) -Codechange: implement a overflow safe integer and use that for money and don't misuses CommandCost to have a overflow safe integer. Based on a patch by Noldo.
rubidium
parents: 7616
diff changeset
   358
	if (negative) {
7422
fb7f6dc87b55 (svn r10820) -Codechange: make negative currencies red and restore the colour from before the currency was printed; this removes the need to make two strings for printing currencies (one for positive currencies and one for negative currencies).
rubidium
parents: 7411
diff changeset
   359
		if (buff + Utf8CharLen(SCC_PREVIOUS_COLOUR) > last) return buff;
fb7f6dc87b55 (svn r10820) -Codechange: make negative currencies red and restore the colour from before the currency was printed; this removes the need to make two strings for printing currencies (one for positive currencies and one for negative currencies).
rubidium
parents: 7411
diff changeset
   360
		buff += Utf8Encode(buff, SCC_PREVIOUS_COLOUR);
fb7f6dc87b55 (svn r10820) -Codechange: make negative currencies red and restore the colour from before the currency was printed; this removes the need to make two strings for printing currencies (one for positive currencies and one for negative currencies).
rubidium
parents: 7411
diff changeset
   361
		*buff = '\0';
fb7f6dc87b55 (svn r10820) -Codechange: make negative currencies red and restore the colour from before the currency was printed; this removes the need to make two strings for printing currencies (one for positive currencies and one for negative currencies).
rubidium
parents: 7411
diff changeset
   362
	}
fb7f6dc87b55 (svn r10820) -Codechange: make negative currencies red and restore the colour from before the currency was printed; this removes the need to make two strings for printing currencies (one for positive currencies and one for negative currencies).
rubidium
parents: 7411
diff changeset
   363
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   364
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   365
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   366
8735
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   367
static int DeterminePluralForm(int64 count)
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   368
{
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   369
	/* The absolute value determines plurality */
8735
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   370
	uint64 n = abs(count);
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   371
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   372
	switch (_langpack->plural_form) {
8735
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   373
		default:
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   374
			NOT_REACHED();
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   375
8735
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   376
		/* Two forms, singular used for one only
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   377
		 * Used in:
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   378
		 *   Danish, Dutch, English, German, Norwegian, Swedish, Estonian, Finnish,
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   379
		 *   Greek, Hebrew, Italian, Portuguese, Spanish, Esperanto */
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   380
		case 0:
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   381
			return n != 1;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   382
8735
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   383
		/* Only one form
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   384
		 * Used in:
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   385
		 *   Hungarian, Japanese, Korean, Turkish */
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   386
		case 1:
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   387
			return 0;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   388
8735
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   389
		/* Two forms, singular used for zero and one
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   390
		 * Used in:
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   391
		 *   French, Brazilian Portuguese */
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   392
		case 2:
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   393
			return n > 1;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   394
8735
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   395
		/* Three forms, special case for zero
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   396
		 * Used in:
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   397
		 *   Latvian */
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   398
		case 3:
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   399
			return n % 10 == 1 && n % 100 != 11 ? 0 : n != 0 ? 1 : 2;
8733
e60ce9c3ae47 (svn r12417) -Fix: Add a new plural rule for Icelandic.
maedhros
parents: 8445
diff changeset
   400
8735
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   401
		/* Three forms, special case for one and two
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   402
		 * Used in:
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   403
		 *   Gaelige (Irish) */
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   404
		case 4:
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   405
			return n == 1 ? 0 : n == 2 ? 1 : 2;
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   406
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   407
		/* Three forms, special case for numbers ending in 1[2-9]
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   408
		 * Used in:
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   409
		 *   Lithuanian */
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   410
		case 5:
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   411
			return n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   412
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   413
		/* Three forms, special cases for numbers ending in 1 and 2, 3, 4, except those ending in 1[1-4]
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   414
		 * Used in:
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   415
		 *   Croatian, Czech, Russian, Slovak, Ukrainian */
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   416
		case 6:
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   417
			return n % 10 == 1 && n % 100 != 11 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   418
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   419
		/* Three forms, special case for one and some numbers ending in 2, 3, or 4
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   420
		 * Used in:
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   421
		 *   Polish */
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   422
		case 7:
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   423
			return n == 1 ? 0 : n % 10 >= 2 && n % 10 <= 4 && (n % 100 < 10 || n % 100 >= 20) ? 1 : 2;
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   424
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   425
		/* Four forms, special case for one and all numbers ending in 02, 03, or 04
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   426
		 * Used in:
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   427
		 *   Slovenian */
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   428
		case 8:
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   429
			return n % 100 == 1 ? 0 : n % 100 == 2 ? 1 : n % 100 == 3 || n % 100 == 4 ? 2 : 3;
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   430
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   431
		/* Two forms; singular used for everything ending in 1 but not in 11.
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   432
		 * Used in:
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   433
		 *   Icelandic */
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   434
		case 9:
d7e8cc159876 (svn r12420) -Cleanup: Fix the indentation, improve a variable name, and add a NOT_REACHED to DeterminePluralForm.
maedhros
parents: 8733
diff changeset
   435
			return n % 10 == 1 && n % 100 != 11 ? 0 : 1;
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   436
	}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   437
}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   438
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   439
static const char *ParseStringChoice(const char *b, uint form, char *dst, int *dstlen)
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   440
{
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   441
	//<NUM> {Length of each string} {each string}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   442
	uint n = (byte)*b++;
6491
00dc414c909d (svn r9672) -Cleanup: lots of coding style fixes around operands.
rubidium
parents: 6420
diff changeset
   443
	uint pos, i, mylen = 0, mypos = 0;
2952
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   444
58522ed8f0f1 (svn r3511) More whitespace ([FS#46] by Rubidium)
tron
parents: 2951
diff changeset
   445
	for (i = pos = 0; i != n; i++) {
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   446
		uint len = (byte)*b++;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   447
		if (i == form) {
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   448
			mypos = pos;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   449
			mylen = len;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   450
		}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   451
		pos += len;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   452
	}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   453
	*dstlen = mylen;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   454
	memcpy(dst, b + mypos, mylen);
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   455
	return b + pos;
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   456
}
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   457
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   458
struct Units {
3342
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   459
	int s_m;           ///< Multiplier for velocity
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   460
	int s_s;           ///< Shift for velocity
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   461
	StringID velocity; ///< String for velocity
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   462
	int p_m;           ///< Multiplier for power
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   463
	int p_s;           ///< Shift for power
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   464
	StringID power;    ///< String for velocity
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   465
	int w_m;           ///< Multiplier for weight
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   466
	int w_s;           ///< Shift for weight
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   467
	StringID s_weight; ///< Short string for weight
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   468
	StringID l_weight; ///< Long string for weight
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   469
	int v_m;           ///< Multiplier for volume
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   470
	int v_s;           ///< Shift for volume
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   471
	StringID s_volume; ///< Short string for volume
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   472
	StringID l_volume; ///< Long string for volume
3489
497361c60b90 (svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents: 3485
diff changeset
   473
	int f_m;           ///< Multiplier for force
497361c60b90 (svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents: 3485
diff changeset
   474
	int f_s;           ///< Shift for force
497361c60b90 (svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents: 3485
diff changeset
   475
	StringID force;    ///< String for force
6248
e4a2ed7e5613 (svn r9051) -Codechange: typedef [enum|struct] Y {} X; -> [enum|struct] X {};
rubidium
parents: 6247
diff changeset
   476
};
3342
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   477
3489
497361c60b90 (svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents: 3485
diff changeset
   478
/* Unit conversions */
3342
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   479
static const Units units[] = {
5402
3d37a300486e (svn r7596) -Codechange: Always display tractive effort in kN.
peter1138
parents: 5296
diff changeset
   480
	{ // Imperial (Original, mph, hp, metric ton, litre, kN)
5874
2db89a640b7a (svn r8464) -Revert (r4322): Change back to converting to mph in the GUI code, as 1 mph == 1.6 km/h is too far out for some people.
peter1138
parents: 5814
diff changeset
   481
		   1,  0, STR_UNITS_VELOCITY_IMPERIAL,
3342
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   482
		   1,  0, STR_UNITS_POWER_IMPERIAL,
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   483
		   1,  0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC,
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   484
		1000,  0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC,
5402
3d37a300486e (svn r7596) -Codechange: Always display tractive effort in kN.
peter1138
parents: 5296
diff changeset
   485
		   1,  0, STR_UNITS_FORCE_SI,
3342
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   486
	},
5402
3d37a300486e (svn r7596) -Codechange: Always display tractive effort in kN.
peter1138
parents: 5296
diff changeset
   487
	{ // Metric (km/h, hp, metric ton, litre, kN)
5874
2db89a640b7a (svn r8464) -Revert (r4322): Change back to converting to mph in the GUI code, as 1 mph == 1.6 km/h is too far out for some people.
peter1138
parents: 5814
diff changeset
   488
		 103,  6, STR_UNITS_VELOCITY_METRIC,
3342
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   489
		   1,  0, STR_UNITS_POWER_METRIC,
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   490
		   1,  0, STR_UNITS_WEIGHT_SHORT_METRIC, STR_UNITS_WEIGHT_LONG_METRIC,
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   491
		1000,  0, STR_UNITS_VOLUME_SHORT_METRIC, STR_UNITS_VOLUME_LONG_METRIC,
5402
3d37a300486e (svn r7596) -Codechange: Always display tractive effort in kN.
peter1138
parents: 5296
diff changeset
   492
		   1,  0, STR_UNITS_FORCE_SI,
3342
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   493
	},
3489
497361c60b90 (svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents: 3485
diff changeset
   494
	{ // SI (m/s, kilowatt, kilogram, cubic metres, kilonewton)
5874
2db89a640b7a (svn r8464) -Revert (r4322): Change back to converting to mph in the GUI code, as 1 mph == 1.6 km/h is too far out for some people.
peter1138
parents: 5814
diff changeset
   495
		1831, 12, STR_UNITS_VELOCITY_SI,
3342
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   496
		 764, 10, STR_UNITS_POWER_SI,
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   497
		1000,  0, STR_UNITS_WEIGHT_SHORT_SI, STR_UNITS_WEIGHT_LONG_SI,
3485
1c77f46830c9 (svn r4336) Fix units conversion of volume for SI
peter1138
parents: 3477
diff changeset
   498
		   1,  0, STR_UNITS_VOLUME_SHORT_SI, STR_UNITS_VOLUME_LONG_SI,
3489
497361c60b90 (svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents: 3485
diff changeset
   499
		   1,  0, STR_UNITS_FORCE_SI,
3342
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   500
	},
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   501
};
2082
1e289843fe0b (svn r2592) Feature: [strgen] New way to specify plural forms.
ludde
parents: 2075
diff changeset
   502
8898
f8b701997c01 (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 8790
diff changeset
   503
/**
f8b701997c01 (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 8790
diff changeset
   504
 * Convert the given (internal) speed to the display speed.
f8b701997c01 (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 8790
diff changeset
   505
 * @param speed the speed to convert
f8b701997c01 (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 8790
diff changeset
   506
 * @return the converted speed.
f8b701997c01 (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 8790
diff changeset
   507
 */
f8b701997c01 (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 8790
diff changeset
   508
uint ConvertSpeedToDisplaySpeed(uint speed)
f8b701997c01 (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 8790
diff changeset
   509
{
9466
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   510
 return (speed * units[_settings_game.locale.units].s_m) >> units[_settings_game.locale.units].s_s;
8898
f8b701997c01 (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 8790
diff changeset
   511
}
f8b701997c01 (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 8790
diff changeset
   512
f8b701997c01 (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 8790
diff changeset
   513
/**
f8b701997c01 (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 8790
diff changeset
   514
 * Convert the given display speed to the (internal) speed.
f8b701997c01 (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 8790
diff changeset
   515
 * @param speed the speed to convert
f8b701997c01 (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 8790
diff changeset
   516
 * @return the converted speed.
f8b701997c01 (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 8790
diff changeset
   517
 */
f8b701997c01 (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 8790
diff changeset
   518
uint ConvertDisplaySpeedToSpeed(uint speed)
f8b701997c01 (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 8790
diff changeset
   519
{
9466
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   520
	return ((speed << units[_settings_game.locale.units].s_s) + units[_settings_game.locale.units].s_m / 2) / units[_settings_game.locale.units].s_m;
8898
f8b701997c01 (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 8790
diff changeset
   521
}
f8b701997c01 (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 8790
diff changeset
   522
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
   523
static char *FormatString(char *buff, const char *str, const int64 *argv, uint casei, const char *last)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   524
{
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   525
	WChar b;
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
   526
	const int64 *argv_orig = argv;
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   527
	uint modifier = 0;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   528
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   529
	while ((b = Utf8Consume(&str)) != '\0') {
7616
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7435
diff changeset
   530
		if (SCC_NEWGRF_FIRST <= b && b <= SCC_NEWGRF_LAST) {
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7435
diff changeset
   531
			/* We need to pass some stuff as it might be modified; oh boy. */
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7435
diff changeset
   532
			b = RemapNewGRFStringControlCode(b, &buff, &str, (int64*)argv);
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7435
diff changeset
   533
			if (b == 0) continue;
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7435
diff changeset
   534
		}
ebf15b08ac38 (svn r11145) -Codechange: add support for "decoding" TTDPs string codes wrt to registers 0x100 to 0x10F.
rubidium
parents: 7435
diff changeset
   535
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   536
		switch (b) {
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   537
			case SCC_SETX: // {SETX}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   538
				if (buff + Utf8CharLen(SCC_SETX) + 1 < last) {
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   539
					buff += Utf8Encode(buff, SCC_SETX);
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   540
					*buff++ = *str++;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   541
				}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   542
				break;
2410
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   543
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   544
			case SCC_SETXY: // {SETXY}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   545
				if (buff + Utf8CharLen(SCC_SETXY) + 2 < last) {
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   546
					buff += Utf8Encode(buff, SCC_SETXY);
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   547
					*buff++ = *str++;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   548
					*buff++ = *str++;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   549
				}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   550
				break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   551
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   552
			case SCC_STRING_ID: // {STRINL}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   553
				buff = GetStringWithArgs(buff, Utf8Consume(&str), argv, last);
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   554
				break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   555
9648
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9543
diff changeset
   556
			case SCC_RAW_STRING_POINTER: { // {RAW_STRING}
9768
0c0fb94c89df (svn r13904) -Fix (r13715): 'cast from/to pointer to/from integer of different size' warnings
glx
parents: 9659
diff changeset
   557
				const char *str = (const char*)(size_t)GetInt64(&argv);
9648
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9543
diff changeset
   558
				buff = FormatString(buff, str, argv, casei, last);
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9543
diff changeset
   559
				break;
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9543
diff changeset
   560
			}
c79160082c0f (svn r13715) -Fix [FS#2129]: C-like strings had to be rebound each time they were printed, otherwise the text could change due to the few number of slots that could be used to bind.
rubidium
parents: 9543
diff changeset
   561
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   562
			case SCC_DATE_LONG: // {DATE_LONG}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   563
				buff = FormatYmdString(buff, GetInt32(&argv), last);
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   564
				break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   565
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   566
			case SCC_DATE_SHORT: // {DATE_SHORT}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   567
				buff = FormatMonthAndYear(buff, GetInt32(&argv), last);
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   568
				break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   569
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   570
			case SCC_VELOCITY: {// {VELOCITY}
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
   571
				int64 args[1];
9466
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   572
				assert(_settings_game.locale.units < lengthof(units));
8898
f8b701997c01 (svn r12665) -Codechange: make the internal speed <-> display speed conversions available to a bigger part of the code.
rubidium
parents: 8790
diff changeset
   573
				args[0] = ConvertSpeedToDisplaySpeed(GetInt32(&argv));
9466
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   574
				buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].velocity), args, modifier >> 24, last);
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   575
				modifier = 0;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   576
				break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   577
			}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   578
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
   579
			case SCC_CURRENCY_COMPACT: // {CURRCOMPACT}
6994
8eab245a77c3 (svn r10250) -Fix: money is always 64 bits, so always parse those 64 bits.
rubidium
parents: 6956
diff changeset
   580
				buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), true, last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   581
				break;
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   582
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
   583
			case SCC_REVISION: // {REV}
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   584
				buff = strecpy(buff, _openttd_revision, last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   585
				break;
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   586
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
   587
			case SCC_CARGO_SHORT: { // {SHORTCARGO}
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   588
				/* Short description of cargotypes. Layout:
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   589
				 * 8-bit = cargo type
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   590
				 * 16-bit = cargo count */
6091
c8827d9ae04a (svn r8826) -Codechange: Replace _cargoc's separate arrays with a regular struct array (with accessor) and implement new initialization method using cargo labels.
peter1138
parents: 6088
diff changeset
   591
				StringID cargo_str = GetCargo(GetInt32(&argv))->units_volume;
3342
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   592
				switch (cargo_str) {
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   593
					case STR_TONS: {
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
   594
						int64 args[1];
9466
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   595
						assert(_settings_game.locale.units < lengthof(units));
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   596
						args[0] = GetInt32(&argv) * units[_settings_game.locale.units].w_m >> units[_settings_game.locale.units].w_s;
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   597
						buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].l_weight), args, modifier >> 24, last);
3342
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   598
						modifier = 0;
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   599
						break;
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   600
					}
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   601
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   602
					case STR_LITERS: {
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
   603
						int64 args[1];
9466
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   604
						assert(_settings_game.locale.units < lengthof(units));
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   605
						args[0] = GetInt32(&argv) * units[_settings_game.locale.units].v_m >> units[_settings_game.locale.units].v_s;
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   606
						buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].l_volume), args, modifier >> 24, last);
3342
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   607
						modifier = 0;
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   608
						break;
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   609
					}
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   610
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   611
					default:
6359
8527262c4cf8 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6357
diff changeset
   612
						if (cargo_str >= 0xE000 && cargo_str < 0xF800) {
8527262c4cf8 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6357
diff changeset
   613
							/* NewGRF strings from Action 4 use a different format here,
8527262c4cf8 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6357
diff changeset
   614
							 * of e.g. "x tonnes of coal", so process accordingly. */
8527262c4cf8 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6357
diff changeset
   615
							buff = GetStringWithArgs(buff, cargo_str, argv++, last);
8527262c4cf8 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6357
diff changeset
   616
						} else {
8527262c4cf8 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6357
diff changeset
   617
							buff = FormatCommaNumber(buff, GetInt32(&argv), last);
8527262c4cf8 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6357
diff changeset
   618
							buff = strecpy(buff, " ", last);
8527262c4cf8 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6357
diff changeset
   619
							buff = strecpy(buff, GetStringPtr(cargo_str), last);
8527262c4cf8 (svn r9411) -Codechange: Add support for loading of newcargo data.
peter1138
parents: 6357
diff changeset
   620
						}
3342
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   621
						break;
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   622
				}
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
   623
			} break;
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   624
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
   625
			case SCC_STRING1: { // {STRING1}
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   626
				/* String that consumes ONE argument */
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   627
				uint str = modifier + GetInt32(&argv);
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   628
				buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 1), last);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   629
				modifier = 0;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   630
				break;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   631
			}
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   632
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
   633
			case SCC_STRING2: { // {STRING2}
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   634
				/* String that consumes TWO arguments */
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   635
				uint str = modifier + GetInt32(&argv);
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   636
				buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 2), last);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   637
				modifier = 0;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   638
				break;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   639
			}
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   640
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
   641
			case SCC_STRING3: { // {STRING3}
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   642
				/* String that consumes THREE arguments */
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   643
				uint str = modifier + GetInt32(&argv);
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   644
				buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 3), last);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   645
				modifier = 0;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   646
				break;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   647
			}
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   648
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
   649
			case SCC_STRING4: { // {STRING4}
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   650
				/* String that consumes FOUR arguments */
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   651
				uint str = modifier + GetInt32(&argv);
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   652
				buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 4), last);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   653
				modifier = 0;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   654
				break;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   655
			}
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   656
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
   657
			case SCC_STRING5: { // {STRING5}
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   658
				/* String that consumes FIVE arguments */
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   659
				uint str = modifier + GetInt32(&argv);
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   660
				buff = GetStringWithArgs(buff, str, GetArgvPtr(&argv, 5), last);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   661
				modifier = 0;
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   662
				break;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   663
			}
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   664
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
   665
			case SCC_STATION_FEATURES: { // {STATIONFEATURES}
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   666
				buff = StationGetSpecialString(buff, GetInt32(&argv), last);
2063
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   667
				break;
ae866a12f2df (svn r2572) - Codechange: [string] Changed string system so it's not as dependent on decode_parameters
ludde
parents: 2057
diff changeset
   668
			}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   669
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
   670
			case SCC_INDUSTRY_NAME: { // {INDUSTRY}
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
   671
				const Industry *i = GetIndustry(GetInt32(&argv));
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
   672
				int64 args[2];
2070
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   673
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   674
				/* industry not valid anymore? */
7390
16fb97ba8133 (svn r10759) -Codechange: make the industry struct use the pool item class as super class.
rubidium
parents: 7386
diff changeset
   675
				if (!i->IsValid()) break;
2070
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   676
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   677
				/* First print the town name and the industry type name
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   678
				 * The string STR_INDUSTRY_PATTERN controls the formatting */
2070
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   679
				args[0] = i->town->index;
4942
7fb6c39eb421 (svn r6930) -Codechange: Move industry name into IndustrySpec
belugas
parents: 4920
diff changeset
   680
				args[1] = GetIndustrySpec(i->type)->name;
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   681
				buff = FormatString(buff, GetStringPtr(STR_INDUSTRY_FORMAT), args, modifier >> 24, last);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   682
				modifier = 0;
2070
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   683
				break;
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   684
			}
47b1f29d4671 (svn r2580) Change: Added {INDUSTRY} command for printing industry names instead of the old {TOWN} {STRING} way.
ludde
parents: 2063
diff changeset
   685
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   686
			case SCC_VOLUME: { // {VOLUME}
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
   687
				int64 args[1];
9466
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   688
				assert(_settings_game.locale.units < lengthof(units));
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   689
				args[0] = GetInt32(&argv) * units[_settings_game.locale.units].v_m >> units[_settings_game.locale.units].v_s;
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   690
				buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].l_volume), args, modifier >> 24, last);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   691
				modifier = 0;
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   692
				break;
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   693
			}
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   694
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   695
			case SCC_GENDER_LIST: { // {G 0 Der Die Das}
8445
54a5d84d1d7d (svn r12015) -Fix [FS#1716] (Revert r11422): Patch in FS#1430 avoided instead of fixed the problem. GetStringWithArgs() discards information that SCC_GENDER_LIST needs to work. Now use pointers to retrieve GRF strings, so that GetStringPtr() will work correctly. This is advantageous as now no buffer copy is made when using all GRF strings.
peter1138
parents: 8323
diff changeset
   696
				const char *s = GetStringPtr(argv_orig[(byte)*str++]); // contains the string that determines gender.
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   697
				int len;
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   698
				int gender = 0;
7411
6aa1fd67a914 (svn r10792) -Fix [FS#1104]: when determining the gender of a string, do not assume that the gender is in the front of the string when there can be case switching code at that location.
rubidium
parents: 7393
diff changeset
   699
				if (s != NULL) {
6aa1fd67a914 (svn r10792) -Fix [FS#1104]: when determining the gender of a string, do not assume that the gender is in the front of the string when there can be case switching code at that location.
rubidium
parents: 7393
diff changeset
   700
					wchar_t c = Utf8Consume(&s);
6aa1fd67a914 (svn r10792) -Fix [FS#1104]: when determining the gender of a string, do not assume that the gender is in the front of the string when there can be case switching code at that location.
rubidium
parents: 7393
diff changeset
   701
					/* Switch case is always put before genders, so remove those bits */
6aa1fd67a914 (svn r10792) -Fix [FS#1104]: when determining the gender of a string, do not assume that the gender is in the front of the string when there can be case switching code at that location.
rubidium
parents: 7393
diff changeset
   702
					if (c == SCC_SWITCH_CASE) {
6aa1fd67a914 (svn r10792) -Fix [FS#1104]: when determining the gender of a string, do not assume that the gender is in the front of the string when there can be case switching code at that location.
rubidium
parents: 7393
diff changeset
   703
						/* Skip to the last (i.e. default) case */
6aa1fd67a914 (svn r10792) -Fix [FS#1104]: when determining the gender of a string, do not assume that the gender is in the front of the string when there can be case switching code at that location.
rubidium
parents: 7393
diff changeset
   704
						for (uint num = (byte)*s++; num != 0; num--) s += 3 + (s[1] << 8) + s[2];
6aa1fd67a914 (svn r10792) -Fix [FS#1104]: when determining the gender of a string, do not assume that the gender is in the front of the string when there can be case switching code at that location.
rubidium
parents: 7393
diff changeset
   705
6aa1fd67a914 (svn r10792) -Fix [FS#1104]: when determining the gender of a string, do not assume that the gender is in the front of the string when there can be case switching code at that location.
rubidium
parents: 7393
diff changeset
   706
						c = Utf8Consume(&s);
6aa1fd67a914 (svn r10792) -Fix [FS#1104]: when determining the gender of a string, do not assume that the gender is in the front of the string when there can be case switching code at that location.
rubidium
parents: 7393
diff changeset
   707
					}
6aa1fd67a914 (svn r10792) -Fix [FS#1104]: when determining the gender of a string, do not assume that the gender is in the front of the string when there can be case switching code at that location.
rubidium
parents: 7393
diff changeset
   708
					/* Does this string have a gender, if so, set it */
6aa1fd67a914 (svn r10792) -Fix [FS#1104]: when determining the gender of a string, do not assume that the gender is in the front of the string when there can be case switching code at that location.
rubidium
parents: 7393
diff changeset
   709
					if (c == SCC_GENDER_INDEX) gender = (byte)s[0];
6aa1fd67a914 (svn r10792) -Fix [FS#1104]: when determining the gender of a string, do not assume that the gender is in the front of the string when there can be case switching code at that location.
rubidium
parents: 7393
diff changeset
   710
				}
2084
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   711
				str = ParseStringChoice(str, gender, buff, &len);
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   712
				buff += len;
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   713
				break;
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   714
			}
65639f898a50 (svn r2594) Fix: [strgen] Misc updates to the string system.
ludde
parents: 2082
diff changeset
   715
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   716
			case SCC_DATE_TINY: { // {DATE_TINY}
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   717
				buff = FormatTinyDate(buff, GetInt32(&argv), last);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   718
				break;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   719
			}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   720
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   721
			case SCC_CARGO: { // {CARGO}
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   722
				/* Layout now is:
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   723
				 *   8bit   - cargo type
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   724
				 *   16-bit - cargo count */
4898
e3962fe14ef8 (svn r6858) - Fix (r6855): Handle rail vehicles with no capacity (N/A) by setting cargo type to CT_INVALID and handling it later. STR_8838_N_A is not a valid cargo type...
peter1138
parents: 4840
diff changeset
   725
				CargoID cargo = GetInt32(&argv);
7393
f3d27c82fec3 (svn r10762) -Codechange: Change enum StringIDEnum { to static const StringID = for
peter1138
parents: 7390
diff changeset
   726
				StringID cargo_str = (cargo == CT_INVALID) ? STR_8838_N_A : GetCargo(cargo)->quantifier;
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
   727
				buff = GetStringWithArgs(buff, cargo_str, argv++, last);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   728
				break;
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   729
			}
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   730
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   731
			case SCC_POWER: { // {POWER}
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
   732
				int64 args[1];
9466
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   733
				assert(_settings_game.locale.units < lengthof(units));
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   734
				args[0] = GetInt32(&argv) * units[_settings_game.locale.units].p_m >> units[_settings_game.locale.units].p_s;
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   735
				buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].power), args, modifier >> 24, last);
3342
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   736
				modifier = 0;
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   737
				break;
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   738
			}
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   739
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   740
			case SCC_VOLUME_SHORT: { // {VOLUME_S}
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
   741
				int64 args[1];
9466
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   742
				assert(_settings_game.locale.units < lengthof(units));
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   743
				args[0] = GetInt32(&argv) * units[_settings_game.locale.units].v_m >> units[_settings_game.locale.units].v_s;
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   744
				buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].s_volume), args, modifier >> 24, last);
3342
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   745
				modifier = 0;
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   746
				break;
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   747
			}
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   748
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   749
			case SCC_WEIGHT: { // {WEIGHT}
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
   750
				int64 args[1];
9466
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   751
				assert(_settings_game.locale.units < lengthof(units));
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   752
				args[0] = GetInt32(&argv) * units[_settings_game.locale.units].w_m >> units[_settings_game.locale.units].w_s;
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   753
				buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].l_weight), args, modifier >> 24, last);
3342
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   754
				modifier = 0;
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   755
				break;
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   756
			}
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   757
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   758
			case SCC_WEIGHT_SHORT: { // {WEIGHT_S}
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
   759
				int64 args[1];
9466
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   760
				assert(_settings_game.locale.units < lengthof(units));
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   761
				args[0] = GetInt32(&argv) * units[_settings_game.locale.units].w_m >> units[_settings_game.locale.units].w_s;
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   762
				buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].s_weight), args, modifier >> 24, last);
3342
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   763
				modifier = 0;
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   764
				break;
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   765
			}
cb9b5c6dd74c (svn r4126) - Feature: A new multi-lingual multi-measuring-unit system:
peter1138
parents: 3329
diff changeset
   766
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   767
			case SCC_FORCE: { // {FORCE}
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
   768
				int64 args[1];
9466
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   769
				assert(_settings_game.locale.units < lengthof(units));
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   770
				args[0] = GetInt32(&argv) * units[_settings_game.locale.units].f_m >> units[_settings_game.locale.units].f_s;
5a1d4eb2ae07 (svn r13386) -Fix: global currency/units setting being overriden when loading a savegame.
rubidium
parents: 9413
diff changeset
   771
				buff = FormatString(buff, GetStringPtr(units[_settings_game.locale.units].force), args, modifier >> 24, last);
3489
497361c60b90 (svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents: 3485
diff changeset
   772
				modifier = 0;
497361c60b90 (svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents: 3485
diff changeset
   773
				break;
497361c60b90 (svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents: 3485
diff changeset
   774
			}
497361c60b90 (svn r4340) Add force {FORCE} to the units system. This is currently unused.
peter1138
parents: 3485
diff changeset
   775
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   776
			case SCC_SKIP: // {SKIP}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   777
				argv++;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   778
				break;
2410
795225af3c72 (svn r2936) Move string commands to a non-printable range and remove stale comments
tron
parents: 2353
diff changeset
   779
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   780
			/* This sets up the gender for the string.
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   781
			 * We just ignore this one. It's used in {G 0 Der Die Das} to determine the case. */
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   782
			case SCC_GENDER_INDEX: // {GENDER 0}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   783
				str++;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   784
				break;
2630
7206058a7e82 (svn r3172) static, const
tron
parents: 2548
diff changeset
   785
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   786
			case SCC_STRING: {// {STRING}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   787
				uint str = modifier + GetInt32(&argv);
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   788
				/* WARNING. It's prohibited for the included string to consume any arguments.
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   789
				 * For included strings that consume argument, you should use STRING1, STRING2 etc.
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
   790
				 * To debug stuff you can set argv to NULL and it will tell you */
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   791
				buff = GetStringWithArgs(buff, str, argv, last);
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   792
				modifier = 0;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   793
				break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   794
			}
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   795
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   796
			case SCC_COMMA: // {COMMA}
7356
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   797
				buff = FormatCommaNumber(buff, GetInt64(&argv), last);
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   798
				break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   799
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   800
			case SCC_ARG_INDEX: // Move argument pointer
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   801
				argv = argv_orig + (byte)*str++;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   802
				break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   803
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   804
			case SCC_PLURAL_LIST: { // {P}
7356
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   805
				int64 v = argv_orig[(byte)*str++]; // contains the number that determines plural
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   806
				int len;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   807
				str = ParseStringChoice(str, DeterminePluralForm(v), buff, &len);
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   808
				buff += len;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   809
				break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   810
			}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   811
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   812
			case SCC_NUM: // {NUM}
7356
2f277ca36d46 (svn r10719) -Codechange: since DParams are now 64 bits we should make NUM and COMMA handle writing 64 bit integers to the strings.
rubidium
parents: 7348
diff changeset
   813
				buff = FormatNoCommaNumber(buff, GetInt64(&argv), last);
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   814
				break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   815
10135
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 10114
diff changeset
   816
			case SCC_HEX: // {HEX}
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 10114
diff changeset
   817
				buff = FormatHexNumber(buff, GetInt64(&argv), last);
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 10114
diff changeset
   818
				break;
21b4050a479b (svn r14321) -Add: support for newgrfs printing bytes/words/dwords as hexadecimals.
rubidium
parents: 10114
diff changeset
   819
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   820
			case SCC_CURRENCY: // {CURRENCY}
6994
8eab245a77c3 (svn r10250) -Fix: money is always 64 bits, so always parse those 64 bits.
rubidium
parents: 6956
diff changeset
   821
				buff = FormatGenericCurrency(buff, _currency, GetInt64(&argv), false, last);
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   822
				break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   823
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   824
			case SCC_WAYPOINT_NAME: { // {WAYPOINT}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   825
				Waypoint *wp = GetWaypoint(GetInt32(&argv));
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   826
10112
7e734c287259 (svn r14296) -Codechange: there is no case where an invalid waypoint index should be passed to be drawn as a string.
rubidium
parents: 10039
diff changeset
   827
				assert(wp->IsValid());
7e734c287259 (svn r14296) -Codechange: there is no case where an invalid waypoint index should be passed to be drawn as a string.
rubidium
parents: 10039
diff changeset
   828
7e734c287259 (svn r14296) -Codechange: there is no case where an invalid waypoint index should be passed to be drawn as a string.
rubidium
parents: 10039
diff changeset
   829
				if (wp->name != NULL) {
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   830
					buff = strecpy(buff, wp->name, last);
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   831
				} else {
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   832
					int64 temp[2];
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   833
					temp[0] = wp->town_index;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   834
					temp[1] = wp->town_cn + 1;
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   835
					StringID str = wp->town_cn == 0 ? STR_WAYPOINTNAME_CITY : STR_WAYPOINTNAME_CITY_SERIAL;
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   836
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   837
					buff = GetStringWithArgs(buff, str, temp, last);
2087
a03690e33b66 (svn r2597) Feature: [string system] Support cases.
ludde
parents: 2084
diff changeset
   838
				}
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   839
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
   840
			}
1097
196431cb50fe (svn r1598) Feature: Message history now is stickyable and resizeable
dominik
parents: 1093
diff changeset
   841
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   842
			case SCC_STATION_NAME: { // {STATION}
10113
2aabf259aaf3 (svn r14297) -Fix: one could be trying to get the station name of a station that is outside of the pool.
rubidium
parents: 10112
diff changeset
   843
				StationID sid = GetInt32(&argv);
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   844
10113
2aabf259aaf3 (svn r14297) -Fix: one could be trying to get the station name of a station that is outside of the pool.
rubidium
parents: 10112
diff changeset
   845
				if (!IsValidStationID(sid)) {
2aabf259aaf3 (svn r14297) -Fix: one could be trying to get the station name of a station that is outside of the pool.
rubidium
parents: 10112
diff changeset
   846
					/* The station doesn't exist anymore. The only place where we might
2aabf259aaf3 (svn r14297) -Fix: one could be trying to get the station name of a station that is outside of the pool.
rubidium
parents: 10112
diff changeset
   847
					 * be "drawing" an invalid station is in the case of cargo that is
2aabf259aaf3 (svn r14297) -Fix: one could be trying to get the station name of a station that is outside of the pool.
rubidium
parents: 10112
diff changeset
   848
					 * in transit. */
10114
1ce7c1597f10 (svn r14298) -Fix [FS#2214]: "{CARGO} from unknown destination".
rubidium
parents: 10113
diff changeset
   849
					buff = GetStringWithArgs(buff, STR_UNKNOWN_STATION, NULL, last);
10113
2aabf259aaf3 (svn r14297) -Fix: one could be trying to get the station name of a station that is outside of the pool.
rubidium
parents: 10112
diff changeset
   850
					break;
2aabf259aaf3 (svn r14297) -Fix: one could be trying to get the station name of a station that is outside of the pool.
rubidium
parents: 10112
diff changeset
   851
				}
2aabf259aaf3 (svn r14297) -Fix: one could be trying to get the station name of a station that is outside of the pool.
rubidium
parents: 10112
diff changeset
   852
2aabf259aaf3 (svn r14297) -Fix: one could be trying to get the station name of a station that is outside of the pool.
rubidium
parents: 10112
diff changeset
   853
				const Station *st = GetStation(sid);
2aabf259aaf3 (svn r14297) -Fix: one could be trying to get the station name of a station that is outside of the pool.
rubidium
parents: 10112
diff changeset
   854
				if (st->name != NULL) {
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   855
					buff = strecpy(buff, st->name, last);
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   856
				} else {
10347
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10310
diff changeset
   857
					StringID str = st->string_id;
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10310
diff changeset
   858
					if (st->indtype != IT_INVALID) {
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10310
diff changeset
   859
						/* Special case where the industry provides the name for the station */
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10310
diff changeset
   860
						const IndustrySpec *indsp = GetIndustrySpec(st->indtype);
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10310
diff changeset
   861
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10310
diff changeset
   862
						/* Industry GRFs can change which might remove the station name and
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10310
diff changeset
   863
						 * thus cause very strange things. Here we check for that before we
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10310
diff changeset
   864
						 * actually set the station name. */
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10310
diff changeset
   865
						if (indsp->station_name != STR_NULL && indsp->station_name != STR_UNDEFINED) {
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10310
diff changeset
   866
							str = indsp->station_name;
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10310
diff changeset
   867
						}
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10310
diff changeset
   868
					}
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10310
diff changeset
   869
7055
a98b5a273ddb (svn r10320) -Fix [FS#278]: one could only build a limited number of stations before one had to rename them.
rubidium
parents: 7051
diff changeset
   870
					int64 temp[3];
6956
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
   871
					temp[0] = STR_TOWN;
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
   872
					temp[1] = st->town->index;
7055
a98b5a273ddb (svn r10320) -Fix [FS#278]: one could only build a limited number of stations before one had to rename them.
rubidium
parents: 7051
diff changeset
   873
					temp[2] = st->index;
10347
6da2d30f2fe8 (svn r14598) -Feature: Action0Industries property 24 (industry suuplies default name for nearby station).
rubidium
parents: 10310
diff changeset
   874
					buff = GetStringWithArgs(buff, str, temp, last);
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   875
				}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   876
				break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   877
			}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   878
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   879
			case SCC_TOWN_NAME: { // {TOWN}
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
   880
				const Town *t = GetTown(GetInt32(&argv));
7002
1bf6a62b0fcb (svn r10258) -Codechange: as we are now using int64 all over the place, it's better to use int64 variables in the string generating too instead of packing them into two int32s.
rubidium
parents: 6996
diff changeset
   881
				int64 temp[1];
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   882
7386
93f6a042d1c3 (svn r10755) -Codechange: make the town struct use the pool item class as super class.
rubidium
parents: 7382
diff changeset
   883
				assert(t->IsValid());
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   884
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   885
				temp[0] = t->townnameparts;
6956
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
   886
				uint32 grfid = t->townnamegrfid;
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
   887
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   888
				if (t->name != NULL) {
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   889
					buff = strecpy(buff, t->name, last);
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   890
				} else if (grfid == 0) {
6956
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
   891
					/* Original town name */
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
   892
					buff = GetStringWithArgs(buff, t->townnametype, temp, last);
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
   893
				} else {
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
   894
					/* Newgrf town name */
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
   895
					if (GetGRFTownName(grfid) != NULL) {
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
   896
						/* The grf is loaded */
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
   897
						buff = GRFTownNameGenerate(buff, t->townnamegrfid, t->townnametype, t->townnameparts, last);
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
   898
					} else {
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
   899
						/* Fallback to english original */
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
   900
						buff = GetStringWithArgs(buff, SPECSTR_TOWNNAME_ENGLISH, temp, last);
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
   901
					}
3579bfc5157b (svn r10211) -Feature: [NewGRF] Add support for action 0F
glx
parents: 6929
diff changeset
   902
				}
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   903
				break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   904
			}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
   905
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6492
diff changeset
   906
			case SCC_GROUP_NAME: { // {GROUP}
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6492
diff changeset
   907
				const Group *g = GetGroup(GetInt32(&argv));
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6492
diff changeset
   908
7382
721b2d81ce91 (svn r10751) -Codechange: make the group struct use the pool item class as super class.
rubidium
parents: 7356
diff changeset
   909
				assert(g->IsValid());
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6492
diff changeset
   910
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   911
				if (g->name != NULL) {
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   912
					buff = strecpy(buff, g->name, last);
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   913
				} else {
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   914
					int64 args[1];
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6492
diff changeset
   915
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   916
					args[0] = g->index;
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   917
					buff = GetStringWithArgs(buff, STR_GROUP_NAME_FORMAT, args, last);
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   918
				}
6643
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6492
diff changeset
   919
				break;
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6492
diff changeset
   920
			}
f81bee57bc09 (svn r9874) -Feature: advanced vehicle lists a.k.a. group interface. Now you can make groups of vehicles and perform all kinds of tasks on that given group. Original code by nycom and graphics by skidd13.
rubidium
parents: 6492
diff changeset
   921
7059
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7058
diff changeset
   922
			case SCC_ENGINE_NAME: { // {ENGINE}
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7058
diff changeset
   923
				EngineID engine = (EngineID)GetInt32(&argv);
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   924
				const Engine *e = GetEngine(engine);
7059
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7058
diff changeset
   925
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   926
				if (e->name != NULL) {
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   927
					buff = strecpy(buff, e->name, last);
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   928
				} else {
9070
dd0121143eba (svn r12924) -Feature: Introducing the so called 'engine pool' which primarily removes the fixed engine type limits and also happens to allow (with the patch option 'dynamic_engines') multiple NewGRF vehicle sets to coexist.
peter1138
parents: 8998
diff changeset
   929
					buff = GetStringWithArgs(buff, e->info.string_id, NULL, last);
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   930
				}
7059
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7058
diff changeset
   931
				break;
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7058
diff changeset
   932
			}
c6d12e3de0dc (svn r10324) -Codechange: reference engine names by index
peter1138
parents: 7058
diff changeset
   933
7049
0ebe47348074 (svn r10314) -Codechange: Refer to vehicle names by index
peter1138
parents: 7006
diff changeset
   934
			case SCC_VEHICLE_NAME: { // {VEHICLE}
0ebe47348074 (svn r10314) -Codechange: Refer to vehicle names by index
peter1138
parents: 7006
diff changeset
   935
				const Vehicle *v = GetVehicle(GetInt32(&argv));
0ebe47348074 (svn r10314) -Codechange: Refer to vehicle names by index
peter1138
parents: 7006
diff changeset
   936
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   937
				if (v->name != NULL) {
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   938
					buff = strecpy(buff, v->name, last);
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   939
				} else {
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   940
					int64 args[1];
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   941
					args[0] = v->unitnumber;
7049
0ebe47348074 (svn r10314) -Codechange: Refer to vehicle names by index
peter1138
parents: 7006
diff changeset
   942
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   943
					StringID str;
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   944
					switch (v->type) {
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   945
						default: NOT_REACHED();
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   946
						case VEH_TRAIN:    str = STR_SV_TRAIN_NAME; break;
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   947
						case VEH_ROAD:     str = STR_SV_ROADVEH_NAME; break;
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   948
						case VEH_SHIP:     str = STR_SV_SHIP_NAME; break;
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   949
						case VEH_AIRCRAFT: str = STR_SV_AIRCRAFT_NAME; break;
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   950
					}
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   951
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   952
					buff = GetStringWithArgs(buff, str, args, last);
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   953
				}
7049
0ebe47348074 (svn r10314) -Codechange: Refer to vehicle names by index
peter1138
parents: 7006
diff changeset
   954
				break;
0ebe47348074 (svn r10314) -Codechange: Refer to vehicle names by index
peter1138
parents: 7006
diff changeset
   955
			}
0ebe47348074 (svn r10314) -Codechange: Refer to vehicle names by index
peter1138
parents: 7006
diff changeset
   956
7056
6daddeaa79df (svn r10321) -Codechange: refer to sign text by index
peter1138
parents: 7055
diff changeset
   957
			case SCC_SIGN_NAME: { // {SIGN}
6daddeaa79df (svn r10321) -Codechange: refer to sign text by index
peter1138
parents: 7055
diff changeset
   958
				const Sign *si = GetSign(GetInt32(&argv));
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   959
				if (si->name != NULL) {
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   960
					buff = strecpy(buff, si->name, last);
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   961
				} else {
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   962
					buff = GetStringWithArgs(buff, STR_280A_SIGN, NULL, last);
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   963
				}
7056
6daddeaa79df (svn r10321) -Codechange: refer to sign text by index
peter1138
parents: 7055
diff changeset
   964
				break;
6daddeaa79df (svn r10321) -Codechange: refer to sign text by index
peter1138
parents: 7055
diff changeset
   965
			}
6daddeaa79df (svn r10321) -Codechange: refer to sign text by index
peter1138
parents: 7055
diff changeset
   966
7058
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7056
diff changeset
   967
			case SCC_COMPANY_NAME: { // {COMPANY}
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10197
diff changeset
   968
				const Company *c = GetCompany((CompanyID)GetInt32(&argv));
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   969
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10197
diff changeset
   970
				if (c->name != NULL) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10197
diff changeset
   971
					buff = strecpy(buff, c->name, last);
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   972
				} else {
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   973
					int64 args[1];
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10197
diff changeset
   974
					args[0] = c->name_2;
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10197
diff changeset
   975
					buff = GetStringWithArgs(buff, c->name_1, args, last);
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   976
				}
7058
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7056
diff changeset
   977
				break;
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7056
diff changeset
   978
			}
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7056
diff changeset
   979
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7056
diff changeset
   980
			case SCC_COMPANY_NUM: { // {COMPANYNUM}
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10197
diff changeset
   981
				CompanyID company = (CompanyID)GetInt32(&argv);
7058
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7056
diff changeset
   982
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10197
diff changeset
   983
				/* Nothing is added for AI or inactive companies */
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10197
diff changeset
   984
				if (IsValidCompanyID(company) && IsHumanCompany(company)) {
7058
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7056
diff changeset
   985
					int64 args[1];
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10197
diff changeset
   986
					args[0] = company + 1;
10209
a1e7417bf1b7 (svn r14423) -Codechange: also do r14221 for the strings.
rubidium
parents: 10208
diff changeset
   987
					buff = GetStringWithArgs(buff, STR_7002_COMPANY, args, last);
7058
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7056
diff changeset
   988
				}
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7056
diff changeset
   989
				break;
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7056
diff changeset
   990
			}
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7056
diff changeset
   991
10209
a1e7417bf1b7 (svn r14423) -Codechange: also do r14221 for the strings.
rubidium
parents: 10208
diff changeset
   992
			case SCC_PRESIDENT_NAME: { // {PRESIDENTNAME}
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10197
diff changeset
   993
				const Company *c = GetCompany((CompanyID)GetInt32(&argv));
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   994
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10197
diff changeset
   995
				if (c->president_name != NULL) {
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10197
diff changeset
   996
					buff = strecpy(buff, c->president_name, last);
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   997
				} else {
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
   998
					int64 args[1];
10207
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10197
diff changeset
   999
					args[0] = c->president_name_2;
c291a21b304e (svn r14421) -Codechange: rename all player variables/types to company *or* client so it is immediatelly clear which one you are working with.
rubidium
parents: 10197
diff changeset
  1000
					buff = GetStringWithArgs(buff, c->president_name_1, args, last);
8258
9fa31acb07bc (svn r11822) -Codechange: Replaced fixed size custom name array. Names are now attached to their object directly and there is
peter1138
parents: 8254
diff changeset
  1001
				}
7058
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7056
diff changeset
  1002
				break;
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7056
diff changeset
  1003
			}
8105bb13ce3d (svn r10323) -Codechange: reference company name, number and player (president) name
peter1138
parents: 7056
diff changeset
  1004
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1005
			case SCC_SETCASE: { // {SETCASE}
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
  1006
				/* This is a pseudo command, it's outputted when someone does {STRING.ack}
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
  1007
				 * The modifier is added to all subsequent GetStringWithArgs that accept the modifier. */
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1008
				modifier = (byte)*str++ << 24;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1009
				break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1010
			}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1011
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1012
			case SCC_SWITCH_CASE: { // {Used to implement case switching}
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
  1013
				/* <0x9E> <NUM CASES> <CASE1> <LEN1> <STRING1> <CASE2> <LEN2> <STRING2> <CASE3> <LEN3> <STRING3> <STRINGDEFAULT>
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
  1014
				 * Each LEN is printed using 2 bytes in big endian order. */
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1015
				uint num = (byte)*str++;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1016
				while (num) {
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1017
					if ((byte)str[0] == casei) {
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
  1018
						/* Found the case, adjust str pointer and continue */
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1019
						str += 3;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1020
						break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1021
					}
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
  1022
					/* Otherwise skip to the next case */
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1023
					str += 3 + (str[1] << 8) + str[2];
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1024
					num--;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1025
				}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1026
				break;
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1027
			}
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1028
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1029
			default:
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1030
				if (buff + Utf8CharLen(b) < last) buff += Utf8Encode(buff, b);
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1031
				break;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1032
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1033
	}
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1034
	*buff = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1035
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1036
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1037
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1038
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
  1039
static char *StationGetSpecialString(char *buff, int x, const char *last)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1040
{
8998
2748f3d2a1f6 (svn r12793) -Codechange: Use enum values for station types instead of mysterious hex (ln)
peter1138
parents: 8991
diff changeset
  1041
	if ((x & FACIL_TRAIN)      && (buff + Utf8CharLen(SCC_TRAIN) < last)) buff += Utf8Encode(buff, SCC_TRAIN);
2748f3d2a1f6 (svn r12793) -Codechange: Use enum values for station types instead of mysterious hex (ln)
peter1138
parents: 8991
diff changeset
  1042
	if ((x & FACIL_TRUCK_STOP) && (buff + Utf8CharLen(SCC_LORRY) < last)) buff += Utf8Encode(buff, SCC_LORRY);
2748f3d2a1f6 (svn r12793) -Codechange: Use enum values for station types instead of mysterious hex (ln)
peter1138
parents: 8991
diff changeset
  1043
	if ((x & FACIL_BUS_STOP)   && (buff + Utf8CharLen(SCC_BUS)   < last)) buff += Utf8Encode(buff, SCC_BUS);
2748f3d2a1f6 (svn r12793) -Codechange: Use enum values for station types instead of mysterious hex (ln)
peter1138
parents: 8991
diff changeset
  1044
	if ((x & FACIL_AIRPORT)    && (buff + Utf8CharLen(SCC_PLANE) < last)) buff += Utf8Encode(buff, SCC_PLANE);
2748f3d2a1f6 (svn r12793) -Codechange: Use enum values for station types instead of mysterious hex (ln)
peter1138
parents: 8991
diff changeset
  1045
	if ((x & FACIL_DOCK)       && (buff + Utf8CharLen(SCC_SHIP)  < last)) buff += Utf8Encode(buff, SCC_SHIP);
5108
aeaef6fe53b7 (svn r7182) -Feature: Merge utf8 branch. This brings us support for Unicode/UTF-8 and the option for fonts rendered by FreeType. Language changes to come.
peter1138
parents: 4942
diff changeset
  1046
	*buff = '\0';
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1047
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1048
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1049
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
  1050
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char *last)
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1051
{
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1052
	char name[512];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1053
4920
67f6806ce054 (svn r6896) - Fix (r6895): Supply last position of the correct buffer *again*
peter1138
parents: 4919
diff changeset
  1054
	_town_name_generators[ind](name, seed, lastof(name));
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1055
	return strecpy(buff, name, last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1056
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1057
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
  1058
static const char * const _silly_company_names[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1059
	"Bloggs Brothers",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1060
	"Tiny Transport Ltd.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1061
	"Express Travel",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1062
	"Comfy-Coach & Co.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1063
	"Crush & Bump Ltd.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1064
	"Broken & Late Ltd.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1065
	"Sam Speedy & Son",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1066
	"Supersonic Travel",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1067
	"Mike's Motors",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1068
	"Lightning International",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1069
	"Pannik & Loozit Ltd.",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1070
	"Inter-City Transport",
2650
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
  1071
	"Getout & Pushit Ltd."
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1072
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1073
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
  1074
static const char * const _surname_list[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1075
	"Adams",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1076
	"Allan",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1077
	"Baker",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1078
	"Bigwig",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1079
	"Black",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1080
	"Bloggs",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1081
	"Brown",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1082
	"Campbell",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1083
	"Gordon",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1084
	"Hamilton",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1085
	"Hawthorn",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1086
	"Higgins",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1087
	"Green",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1088
	"Gribble",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1089
	"Jones",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1090
	"McAlpine",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1091
	"MacDonald",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1092
	"McIntosh",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1093
	"Muir",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1094
	"Murphy",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1095
	"Nelson",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1096
	"O'Donnell",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1097
	"Parker",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1098
	"Phillips",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1099
	"Pilkington",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1100
	"Quigley",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1101
	"Sharkey",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1102
	"Thomson",
2650
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
  1103
	"Watkins"
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
  1104
};
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
  1105
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
  1106
static const char * const _silly_surname_list[] = {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1107
	"Grumpy",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1108
	"Dozy",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1109
	"Speedy",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1110
	"Nosey",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1111
	"Dribble",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1112
	"Mushroom",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1113
	"Cabbage",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1114
	"Sniffle",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1115
	"Fishy",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1116
	"Swindle",
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1117
	"Sneaky",
2650
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
  1118
	"Nutkins"
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1119
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1120
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
  1121
static const char _initial_name_letters[] = {
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1122
	'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1123
	'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W',
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1124
};
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1125
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
  1126
static char *GenAndCoName(char *buff, uint32 arg, const char *last)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1127
{
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
  1128
	const char * const *base;
2650
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
  1129
	uint num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1130
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9358
diff changeset
  1131
	if (_settings_game.game_creation.landscape == LT_TOYLAND) {
2650
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
  1132
		base = _silly_surname_list;
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
  1133
		num  = lengthof(_silly_surname_list);
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
  1134
	} else {
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
  1135
		base = _surname_list;
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
  1136
		num  = lengthof(_surname_list);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1137
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1138
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1139
	buff = strecpy(buff, base[num * GB(arg, 16, 8) >> 8], last);
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1140
	buff = strecpy(buff, " & Co.", last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1141
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1142
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1143
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1144
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
  1145
static char *GenPresidentName(char *buff, uint32 x, const char *last)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1146
{
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1147
	char initial[] = "?. ";
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
  1148
	const char * const *base;
2650
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
  1149
	uint num;
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
  1150
	uint i;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1151
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1152
	initial[0] = _initial_name_letters[sizeof(_initial_name_letters) * GB(x, 0, 8) >> 8];
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1153
	buff = strecpy(buff, initial, last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1154
2150
f710b959b1c4 (svn r2660) Get rid of some more shifting/anding/casting
tron
parents: 2140
diff changeset
  1155
	i = (sizeof(_initial_name_letters) + 35) * GB(x, 8, 8) >> 8;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1156
	if (i < sizeof(_initial_name_letters)) {
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1157
		initial[0] = _initial_name_letters[i];
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1158
		buff = strecpy(buff, initial, last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1159
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1160
9413
7042a8ec3fa8 (svn r13325) -Codechange: split the client-side only settings from the settings stored in the savegame so there is no need to have a duplicate copy of it for new games.
rubidium
parents: 9358
diff changeset
  1161
	if (_settings_game.game_creation.landscape == LT_TOYLAND) {
2650
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
  1162
		base = _silly_surname_list;
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
  1163
		num  = lengthof(_silly_surname_list);
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
  1164
	} else {
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
  1165
		base = _surname_list;
cec7c95d039d (svn r3192) Split the surname list into two lists (non-toyland/toyland) and use lengthof() to get the number of names instead of using magic numbers
tron
parents: 2643
diff changeset
  1166
		num  = lengthof(_surname_list);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1167
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1168
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1169
	buff = strecpy(buff, base[num * GB(x, 16, 8) >> 8], last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1170
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1171
	return buff;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1172
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1173
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
  1174
static char *GetSpecialNameString(char *buff, int ind, const int64 *argv, const char *last)
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1175
{
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1176
	switch (ind) {
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1177
		case 1: // not used
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1178
			return strecpy(buff, _silly_company_names[GetInt32(&argv) & 0xFFFF], last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1179
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1180
		case 2: // used for Foobar & Co company names
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1181
			return GenAndCoName(buff, GetInt32(&argv), last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1182
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1183
		case 3: // President name
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1184
			return GenPresidentName(buff, GetInt32(&argv), last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1185
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1186
		case 4: // song names
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1187
			return strecpy(buff, origin_songs_specs[GetInt32(&argv) - 1].song_name, last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1188
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1189
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
  1190
	/* town name? */
8969
6d1c74e0e2cd (svn r12761) -Codechange: lots of minor whitespace coding style fixes around operators.
rubidium
parents: 8898
diff changeset
  1191
	if (IsInsideMM(ind - 6, 0, SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1)) {
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1192
		buff = GetSpecialTownNameString(buff, ind - 6, GetInt32(&argv), last);
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1193
		return strecpy(buff, " Transport", last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1194
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1195
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
  1196
	/* language name? */
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7928
diff changeset
  1197
	if (IsInsideMM(ind, (SPECSTR_LANGUAGE_START - 0x70E4), (SPECSTR_LANGUAGE_END - 0x70E4) + 1)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1198
		int i = ind - (SPECSTR_LANGUAGE_START - 0x70E4);
1853
a7b4892162f6 (svn r2359) Use strecpy instead of str_cat (which was rather a cpy than a cat, btw), remove the latter and simplify some constructs
tron
parents: 1704
diff changeset
  1199
		return strecpy(buff,
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1200
			i == _dynlang.curr ? _langpack->own_name : _dynlang.ent[i].name, last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1201
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1202
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
  1203
	/* resolution size? */
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7928
diff changeset
  1204
	if (IsInsideMM(ind, (SPECSTR_RESOLUTION_START - 0x70E4), (SPECSTR_RESOLUTION_END - 0x70E4) + 1)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1205
		int i = ind - (SPECSTR_RESOLUTION_START - 0x70E4);
10299
946c84fdc58e (svn r14540) -Codechange: introduce [v]seprintf which are like [v]snprintf but do return the number of characters written instead of the number of characters that would be written; as size_t is unsigned substraction can cause integer underflows quite quickly.
rubidium
parents: 10249
diff changeset
  1206
		buff += seprintf(
946c84fdc58e (svn r14540) -Codechange: introduce [v]seprintf which are like [v]snprintf but do return the number of characters written instead of the number of characters that would be written; as size_t is unsigned substraction can cause integer underflows quite quickly.
rubidium
parents: 10249
diff changeset
  1207
			buff, last, "%dx%d", _resolutions[i].width, _resolutions[i].height
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1208
		);
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1209
		return buff;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1210
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1211
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
  1212
	/* screenshot format name? */
7954
57b51c69c072 (svn r11510) -Codechange: merge the IS_*INSIDE* functions and rename them fitting to the naming style
skidd13
parents: 7928
diff changeset
  1213
	if (IsInsideMM(ind, (SPECSTR_SCREENSHOT_START - 0x70E4), (SPECSTR_SCREENSHOT_END - 0x70E4) + 1)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1214
		int i = ind - (SPECSTR_SCREENSHOT_START - 0x70E4);
4912
0f51b47cb983 (svn r6884) -Codechange: Add strict bounds checking in string formatting system.
Darkvater
parents: 4898
diff changeset
  1215
		return strecpy(buff, GetScreenshotFormatDesc(i), last);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1216
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1217
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1218
	assert(0);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1219
	return NULL;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1220
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1221
6898
d23c46e9a6ec (svn r10145) -Fix: make compiling with networking disabled (again) possible.
rubidium
parents: 6797
diff changeset
  1222
#ifdef ENABLE_NETWORK
6793
05d91fa1c75c (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6643
diff changeset
  1223
extern void SortNetworkLanguages();
6898
d23c46e9a6ec (svn r10145) -Fix: make compiling with networking disabled (again) possible.
rubidium
parents: 6797
diff changeset
  1224
#else /* ENABLE_NETWORK */
d23c46e9a6ec (svn r10145) -Fix: make compiling with networking disabled (again) possible.
rubidium
parents: 6797
diff changeset
  1225
static inline void SortNetworkLanguages() {}
d23c46e9a6ec (svn r10145) -Fix: make compiling with networking disabled (again) possible.
rubidium
parents: 6797
diff changeset
  1226
#endif /* ENABLE_NETWORK */
6793
05d91fa1c75c (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6643
diff changeset
  1227
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1228
bool ReadLanguagePack(int lang_index)
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1229
{
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1230
	int tot_count, i;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1231
	size_t len;
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
  1232
	char **langpack_offs;
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
  1233
	char *s;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1234
6320
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1235
	LanguagePack *lang_pack = (LanguagePack*)ReadFileToMem(_dynlang.ent[lang_index].file, &len, 200000);
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1236
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1237
	if (lang_pack == NULL) return false;
1319
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
  1238
	if (len < sizeof(LanguagePack) ||
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
  1239
			lang_pack->ident != TO_LE32(LANGUAGE_PACK_IDENT) ||
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
  1240
			lang_pack->version != TO_LE32(LANGUAGE_PACK_VERSION)) {
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1241
		free(lang_pack);
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1242
		return false;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1243
	}
193
0a7025304867 (svn r194) -Codechange: stripping trailing-spaces. Please keep this that way!
truelight
parents: 64
diff changeset
  1244
9543
a60fb4bacc66 (svn r13552) -Codechange: use TTD_ENDIAN comparations instead of tests if TTD_[BIG/LITTLE]_ENDIAN is defined
smatz
parents: 9533
diff changeset
  1245
#if TTD_ENDIAN == TTD_BIG_ENDIAN
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1246
	for (i = 0; i != 32; i++) {
2966
661554d683cd (svn r3529) - Fix: [ 1415782 ] crash in string code with openbsd/zaurus; alignment issues (thanks Tron for the help)
Darkvater
parents: 2957
diff changeset
  1247
		lang_pack->offsets[i] = ReadLE16Aligned(&lang_pack->offsets[i]);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1248
	}
9543
a60fb4bacc66 (svn r13552) -Codechange: use TTD_ENDIAN comparations instead of tests if TTD_[BIG/LITTLE]_ENDIAN is defined
smatz
parents: 9533
diff changeset
  1249
#endif /* TTD_ENDIAN == TTD_BIG_ENDIAN */
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1250
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1251
	tot_count = 0;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1252
	for (i = 0; i != 32; i++) {
1319
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
  1253
		uint num = lang_pack->offsets[i];
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1254
		_langtab_start[i] = tot_count;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1255
		_langtab_num[i] = num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1256
		tot_count += num;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1257
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1258
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
  1259
	/* Allocate offsets */
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5587
diff changeset
  1260
	langpack_offs = MallocT<char*>(tot_count);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1261
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
  1262
	/* Fill offsets */
1319
beeef5cce0e4 (svn r1823) Get rid of some ugly cast magic concerning language packs
tron
parents: 1318
diff changeset
  1263
	s = lang_pack->data;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1264
	for (i = 0; i != tot_count; i++) {
1312
594340ca5b87 (svn r1816) Use char instead of byte for string formatting
tron
parents: 1311
diff changeset
  1265
		len = (byte)*s;
1316
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1266
		*s++ = '\0'; // zero terminate the string before.
6fba7f66c1f4 (svn r1820) Style cleanup:
tron
parents: 1312
diff changeset
  1267
		if (len >= 0xC0) len = ((len & 0x3F) << 8) + (byte)*s++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1268
		langpack_offs[i] = s;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1269
		s += len;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1270
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1271
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1272
	free(_langpack);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1273
	_langpack = lang_pack;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1274
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1275
	free(_langpack_offs);
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1276
	_langpack_offs = langpack_offs;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1277
6344
e5edb531b27e (svn r9373) -Fix (r9271): the chosen language was not stored nor read properly in/from the cfg.
rubidium
parents: 6320
diff changeset
  1278
	const char *c_file = strrchr(_dynlang.ent[lang_index].file, PATHSEPCHAR) + 1;
10310
ca2eb5811a07 (svn r14555) -Codechange: replace ttd_strlcat and ttd_strlcpy with strecat and strecpy where direct conversion is possible
skidd13
parents: 10299
diff changeset
  1279
	strecpy(_dynlang.curr_file, c_file, lastof(_dynlang.curr_file));
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1280
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1281
	_dynlang.curr = lang_index;
10249
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1282
	_dynlang.text_dir = (TextDirection)lang_pack->text_dir;
3601
138bf309cf27 (svn r4493) Newgrf : Action 04. Beginning of implementation.
belugas
parents: 3489
diff changeset
  1283
	SetCurrentGrfLangID(_langpack->isocode);
6793
05d91fa1c75c (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6643
diff changeset
  1284
	SortNetworkLanguages();
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1285
	return true;
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1286
}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1287
7348
aca2f2517ec1 (svn r10711) -Fix [Win32]: take default language from current user's locale on Windows (In-)
KUDr
parents: 7316
diff changeset
  1288
/* Win32 implementation in win32.cpp. */
7435
c5d1a7a3235c (svn r10851) -Feature [OSX]: OpenTTD will now pick the same language as finder is set to if no config file is found (ln-)
bjarni
parents: 7422
diff changeset
  1289
/* OS X implementation in os/macosx/macos.mm. */
c5d1a7a3235c (svn r10851) -Feature [OSX]: OpenTTD will now pick the same language as finder is set to if no config file is found (ln-)
bjarni
parents: 7422
diff changeset
  1290
#if !(defined(WIN32) || defined(__APPLE__))
3329
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1291
/** Determine the current charset based on the environment
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1292
 * First check some default values, after this one we passed ourselves
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1293
 * and if none exist return the value for $LANG
6420
456c275f3313 (svn r9556) -Documentation: doxygen and comment-style changes. 'R', 'S'.. The end of the preliminary work is near
belugas
parents: 6359
diff changeset
  1294
 * @param param environment variable to check conditionally if default ones are not
3329
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1295
 *        set. Pass NULL if you don't want additional checks.
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1296
 * @return return string containing current charset, or NULL if not-determinable */
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1297
const char *GetCurrentLocale(const char *param)
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1298
{
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1299
	const char *env;
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1300
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1301
	env = getenv("LANGUAGE");
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1302
	if (env != NULL) return env;
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1303
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1304
	env = getenv("LC_ALL");
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1305
	if (env != NULL) return env;
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1306
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1307
	if (param != NULL) {
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1308
		env = getenv(param);
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1309
		if (env != NULL) return env;
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1310
	}
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1311
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1312
	return getenv("LANG");
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1313
}
8991
749d842945cc (svn r12786) -Change: remove more function from functions.h.
rubidium
parents: 8987
diff changeset
  1314
#else
749d842945cc (svn r12786) -Change: remove more function from functions.h.
rubidium
parents: 8987
diff changeset
  1315
const char *GetCurrentLocale(const char *param);
7435
c5d1a7a3235c (svn r10851) -Feature [OSX]: OpenTTD will now pick the same language as finder is set to if no config file is found (ln-)
bjarni
parents: 7422
diff changeset
  1316
#endif /* !(defined(WIN32) || defined(__APPLE__)) */
3329
9885789ecaf7 (svn r4105) - Feature: Add proper ISO-8859-15 <> LOCALCODE conversion. As the mess that is makefile can't properly support it at the moment, it is only available for MACOSX. Windows doesn't need FS conversion and I have no idea about OS/2 so it's disabled for them.
Darkvater
parents: 3033
diff changeset
  1317
6793
05d91fa1c75c (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6643
diff changeset
  1318
int CDECL StringIDSorter(const void *a, const void *b)
05d91fa1c75c (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6643
diff changeset
  1319
{
05d91fa1c75c (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6643
diff changeset
  1320
	const StringID va = *(const StringID*)a;
05d91fa1c75c (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6643
diff changeset
  1321
	const StringID vb = *(const StringID*)b;
05d91fa1c75c (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6643
diff changeset
  1322
	char stra[512];
05d91fa1c75c (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6643
diff changeset
  1323
	char strb[512];
05d91fa1c75c (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6643
diff changeset
  1324
	GetString(stra, va, lastof(stra));
05d91fa1c75c (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6643
diff changeset
  1325
	GetString(strb, vb, lastof(strb));
05d91fa1c75c (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6643
diff changeset
  1326
05d91fa1c75c (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6643
diff changeset
  1327
	return strcmp(stra, strb);
05d91fa1c75c (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6643
diff changeset
  1328
}
05d91fa1c75c (svn r10032) -Add: sort the strings in server language dropdown
glx
parents: 6643
diff changeset
  1329
6320
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1330
/**
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1331
 * Checks whether the given language is already found.
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1332
 * @param langs    languages we've found so fa
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1333
 * @param max      the length of the language list
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1334
 * @param language name of the language to check
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1335
 * @return true if and only if a language file with the same name has not been found
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1336
 */
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1337
static bool UniqueLanguageFile(const Language *langs, uint max, const char *language)
4219
72768a8f3a97 (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
  1338
{
6320
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1339
	for (uint i = 0; i < max; i++) {
6344
e5edb531b27e (svn r9373) -Fix (r9271): the chosen language was not stored nor read properly in/from the cfg.
rubidium
parents: 6320
diff changeset
  1340
		const char *f_name = strrchr(langs[i].file, PATHSEPCHAR) + 1;
6320
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1341
		if (strcmp(f_name, language) == 0) return false; // duplicates
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1342
	}
4219
72768a8f3a97 (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
  1343
6320
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1344
	return true;
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1345
}
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1346
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1347
/**
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1348
 * Reads the language file header and checks compatability.
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1349
 * @param file the file to read
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1350
 * @param hdr  the place to write the header information to
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1351
 * @return true if and only if the language file is of a compatible version
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1352
 */
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1353
static bool GetLanguageFileHeader(const char *file, LanguagePack *hdr)
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1354
{
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1355
	FILE *f = fopen(file, "rb");
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1356
	if (f == NULL) return false;
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1357
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1358
	size_t read = fread(hdr, sizeof(*hdr), 1, f);
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1359
	fclose(f);
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1360
10367
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1361
	bool ret = read == 1 &&
6320
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1362
			hdr->ident == TO_LE32(LANGUAGE_PACK_IDENT) &&
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1363
			hdr->version == TO_LE32(LANGUAGE_PACK_VERSION);
10367
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1364
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1365
	/* Convert endianness for the windows language ID */
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1366
	if (ret) hdr->winlangid = FROM_LE16(hdr->winlangid);
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1367
	return ret;
6320
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1368
}
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1369
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1370
/**
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1371
 * Gets a list of languages from the given directory.
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1372
 * @param langs the list to write to
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1373
 * @param start the initial offset in the list
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1374
 * @param max   the length of the language list
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1375
 * @param path  the base directory to search in
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1376
 * @return the number of added languages
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1377
 */
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1378
static int GetLanguageList(Language *langs, int start, int max, const char *path)
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1379
{
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1380
	int i = start;
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1381
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1382
	DIR *dir = ttd_opendir(path);
4219
72768a8f3a97 (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
  1383
	if (dir != NULL) {
6320
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1384
		struct dirent *dirent;
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1385
		while ((dirent = readdir(dir)) != NULL && i < max) {
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1386
			const char *d_name    = FS2OTTD(dirent->d_name);
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1387
			const char *extension = strrchr(d_name, '.');
4219
72768a8f3a97 (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
  1388
6320
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1389
			/* Not a language file */
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1390
			if (extension == NULL || strcmp(extension, ".lng") != 0) continue;
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1391
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1392
			/* Filter any duplicate language-files, first-come first-serve */
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1393
			if (!UniqueLanguageFile(langs, i, d_name)) continue;
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1394
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1395
			langs[i].file = str_fmt("%s%s", path, d_name);
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1396
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1397
			/* Check whether the file is of the correct version */
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1398
			LanguagePack hdr;
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1399
			if (!GetLanguageFileHeader(langs[i].file, &hdr)) {
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1400
				free(langs[i].file);
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1401
				continue;
4219
72768a8f3a97 (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
  1402
			}
6320
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1403
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1404
			i++;
4219
72768a8f3a97 (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
  1405
		}
72768a8f3a97 (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
  1406
		closedir(dir);
72768a8f3a97 (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
  1407
	}
6320
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1408
	return i - start;
4219
72768a8f3a97 (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
  1409
}
72768a8f3a97 (svn r5763) - Cleanup: Move the now unified GetLanguageList and comparator function to strings.c where it belongs.
Darkvater
parents: 4120
diff changeset
  1410
6320
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1411
/**
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1412
 * Make a list of the available language packs. put the data in
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1413
 * _dynlang struct.
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1414
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6158
diff changeset
  1415
void InitializeLanguagePacks()
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1416
{
6929
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6898
diff changeset
  1417
	Searchpath sp;
6320
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1418
	Language files[MAX_LANG];
6929
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6898
diff changeset
  1419
	uint language_count = 0;
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6898
diff changeset
  1420
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6898
diff changeset
  1421
	FOR_ALL_SEARCHPATHS(sp) {
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6898
diff changeset
  1422
		char path[MAX_PATH];
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6898
diff changeset
  1423
		FioAppendDirectory(path, lengthof(path), sp, LANG_DIR);
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6898
diff changeset
  1424
		language_count += GetLanguageList(files, language_count, lengthof(files), path);
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6898
diff changeset
  1425
	}
9470
08424e2e79e4 (svn r13390) -Codechange: introduce usererror() for fatal but not openttd related errors. Now all error() will 'crash' openttd after showing the message in win32 releases (MSVC), creating a crash.log and crash.dmp (like the '!' hack used before). On the other hand, usererror() will just close the game. So use error() only when it can be helpful to debugging, else use usererror().
glx
parents: 9466
diff changeset
  1426
	if (language_count == 0) usererror("No available language packs (invalid versions?)");
2257
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1427
6320
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1428
	/* Acquire the locale of the current system */
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1429
	const char *lang = GetCurrentLocale("LC_MESSAGES");
4505
abb08e94a1ea (svn r6290) -Feature: When automatically detecting the language try to first match language+territory (e.g. de_CH), then just language (e.g. de) and fall back to en_GB otherwise
tron
parents: 4503
diff changeset
  1430
	if (lang == NULL) lang = "en_GB";
2257
ea9008cb49ec (svn r2777) -Feature: When starting without a config file determine the language on basis of the current locale
tron
parents: 2201
diff changeset
  1431
6320
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1432
	int chosen_language   = -1; ///< Matching the language in the configuartion file or the current locale
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1433
	int language_fallback = -1; ///< Using pt_PT for pt_BR locale when pt_BR is not available
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1434
	int en_GB_fallback    =  0; ///< Fallback when no locale-matching language has been found
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1435
6320
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1436
	DynamicLanguages *dl = &_dynlang;
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1437
	dl->num = 0;
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1438
	/* Fill the dynamic languages structures */
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1439
	for (uint i = 0; i < language_count; i++) {
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1440
		/* File read the language header */
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1441
		LanguagePack hdr;
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1442
		if (!GetLanguageFileHeader(files[i].file, &hdr)) continue;
1321
1373f60f4b39 (svn r1825) Further style improvements:
tron
parents: 1319
diff changeset
  1443
6320
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1444
		dl->ent[dl->num].file = files[i].file;
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1445
		dl->ent[dl->num].name = strdup(hdr.name);
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1446
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1447
		/* We are trying to find a default language. The priority is by
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1448
		 * configuration file, local environment and last, if nothing found,
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1449
		 * english. If def equals -1, we have not picked a default language */
6344
e5edb531b27e (svn r9373) -Fix (r9271): the chosen language was not stored nor read properly in/from the cfg.
rubidium
parents: 6320
diff changeset
  1450
		const char *lang_file = strrchr(dl->ent[dl->num].file, PATHSEPCHAR) + 1;
e5edb531b27e (svn r9373) -Fix (r9271): the chosen language was not stored nor read properly in/from the cfg.
rubidium
parents: 6320
diff changeset
  1451
		if (strcmp(lang_file, dl->curr_file) == 0) chosen_language = dl->num;
6320
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1452
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1453
		if (chosen_language == -1) {
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1454
			if (strcmp (hdr.isocode, "en_GB") == 0) en_GB_fallback    = dl->num;
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1455
			if (strncmp(hdr.isocode, lang, 5) == 0) chosen_language   = dl->num;
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1456
			if (strncmp(hdr.isocode, lang, 2) == 0) language_fallback = dl->num;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1457
		}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1458
6320
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1459
		dl->num++;
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1460
	}
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1461
9470
08424e2e79e4 (svn r13390) -Codechange: introduce usererror() for fatal but not openttd related errors. Now all error() will 'crash' openttd after showing the message in win32 releases (MSVC), creating a crash.log and crash.dmp (like the '!' hack used before). On the other hand, usererror() will just close the game. So use error() only when it can be helpful to debugging, else use usererror().
glx
parents: 9466
diff changeset
  1462
	if (dl->num == 0) usererror("Invalid version of language packs");
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1463
6320
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1464
	/* We haven't found the language in the config nor the one in the locale.
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1465
	 * Now we set it to one of the fallback languages */
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1466
	if (chosen_language == -1) {
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1467
		chosen_language = (language_fallback != -1) ? language_fallback : en_GB_fallback;
32d0f299e2fd (svn r9271) -Codechange: make the language pack initialisation a little more clear and extendable (more language paths).
rubidium
parents: 6248
diff changeset
  1468
	}
0
29654efe3188 (svn r1) Import of revision 975 of old (crashed) SVN
truelight
parents:
diff changeset
  1469
9470
08424e2e79e4 (svn r13390) -Codechange: introduce usererror() for fatal but not openttd related errors. Now all error() will 'crash' openttd after showing the message in win32 releases (MSVC), creating a crash.log and crash.dmp (like the '!' hack used before). On the other hand, usererror() will just close the game. So use error() only when it can be helpful to debugging, else use usererror().
glx
parents: 9466
diff changeset
  1470
	if (!ReadLanguagePack(chosen_language)) usererror("Can't read language pack '%s'", dl->ent[chosen_language].file);
2075
21d2986569d1 (svn r2585) - Fix [Makefile]: some small cleanups, remove warnings, and add mersenne to makefile (Luca)
Darkvater
parents: 2070
diff changeset
  1471
}
8085
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 7954
diff changeset
  1472
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 7954
diff changeset
  1473
/**
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 7954
diff changeset
  1474
 * Check whether the currently loaded language pack
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 7954
diff changeset
  1475
 * uses characters that the currently loaded font
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 7954
diff changeset
  1476
 * does not support. If this is the case an error
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 7954
diff changeset
  1477
 * message will be shown in English. The error
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 7954
diff changeset
  1478
 * message will not be localized because that would
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 7954
diff changeset
  1479
 * mean it might use characters that are not in the
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 7954
diff changeset
  1480
 * font, which is the whole reason this check has
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 7954
diff changeset
  1481
 * been added.
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 7954
diff changeset
  1482
 */
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 7954
diff changeset
  1483
void CheckForMissingGlyphsInLoadedLanguagePack()
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 7954
diff changeset
  1484
{
10367
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1485
#ifdef WITH_FREETYPE
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1486
	/* Reset to the original state; switching languages might cause us to
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1487
	 * automatically choose another font. This resets that choice. */
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1488
	UninitFreeType();
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1489
	InitFreeType();
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
  1490
	bool retry = false;
10367
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1491
#endif
8201
92f3b5542ecb (svn r11764) -Change: make the 'do characters exist in the current font file(s)' more robust.
rubidium
parents: 8144
diff changeset
  1492
10367
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1493
	for (;;) {
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1494
		const Sprite *question_mark = GetGlyph(FS_NORMAL, '?');
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1495
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1496
		for (uint i = 0; i != 32; i++) {
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1497
			for (uint j = 0; j < _langtab_num[i]; j++) {
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1498
				const char *string = _langpack_offs[_langtab_start[i] + j];
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1499
				WChar c;
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1500
				while ((c = Utf8Consume(&string)) != '\0') {
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1501
					if (c == SCC_SETX) {
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1502
						/*
10372
ac1e34769a83 (svn r14623) -Codechange: a sprinkle of coding style.
rubidium
parents: 10367
diff changeset
  1503
						 * SetX is, together with SetXY as special character that
10367
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1504
						 * uses the next (two) characters as data points. We have
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1505
						 * to skip those, otherwise the UTF8 reading will go
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1506
						 * haywire.
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1507
						 */
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1508
						string++;
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1509
					} else if (c == SCC_SETXY) {
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1510
						string += 2;
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1511
					} else if (IsPrintable(c) && c != '?' && GetGlyph(FS_NORMAL, c) == question_mark) {
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1512
#ifdef WITH_FREETYPE
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1513
						if (!retry) {
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1514
							/* We found an unprintable character... lets try whether we can
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1515
							 * find a fallback font that can print the characters in the
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1516
							 * current language. */
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1517
							retry = true;
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1518
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1519
							FreeTypeSettings backup;
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1520
							memcpy(&backup, &_freetype, sizeof(backup));
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1521
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1522
							bool success = SetFallbackFont(&_freetype, _langpack->isocode, _langpack->winlangid);
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1523
							if (success) {
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1524
								UninitFreeType();
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1525
								InitFreeType();
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1526
							}
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1527
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1528
							memcpy(&_freetype, &backup, sizeof(backup));
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1529
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1530
							if (success) continue;
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1531
						} else {
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1532
							/* Our fallback font does miss characters too, so keep the
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1533
							 * user chosen font as that is more likely to be any good than
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1534
							 * the wild guess we made */
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1535
							UninitFreeType();
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1536
							InitFreeType();
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1537
						}
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1538
#endif
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1539
						/*
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1540
						 * The character is printable, but not in the normal font.
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1541
						 * This is the case we were testing for. In this case we
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1542
						 * have to show the error. As we do not want the string to
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1543
						 * be translated by the translators, we 'force' it into the
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1544
						 * binary and 'load' it via a BindCString. To do this
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1545
						 * properly we have to set the color of the string,
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1546
						 * otherwise we end up with a lot of artefacts. The color
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1547
						 * 'character' might change in the future, so for safety
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1548
						 * we just Utf8 Encode it into the string, which takes
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1549
						 * exactly three characters, so it replaces the "XXX" with
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1550
						 * the color marker.
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1551
						 */
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1552
						static char *err_str = strdup("XXXThe current font is missing some of the characters used in the texts for this language. Read the readme to see how to solve this.");
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1553
						Utf8Encode(err_str, SCC_YELLOW);
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1554
						SetDParamStr(0, err_str);
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1555
						ShowErrorMessage(INVALID_STRING_ID, STR_JUST_RAW_STRING, 0, 0);
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1556
						return;
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1557
					}
8085
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 7954
diff changeset
  1558
				}
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 7954
diff changeset
  1559
			}
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 7954
diff changeset
  1560
		}
10367
0098392a5560 (svn r14618) -Feature: when the chosen language isn't supported by the current font, try to find a font that does and use that instead. Thanks to glx/michi_cc for the Windows implementation.
rubidium
parents: 10366
diff changeset
  1561
		break;
8085
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 7954
diff changeset
  1562
	}
10249
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1563
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1564
#if !defined(WITH_ICU)
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1565
	/*
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1566
	 * For right-to-left languages we need the ICU library. If
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1567
	 * we do not have support for that library we warn the user
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1568
	 * about it with a message. As we do not want the string to
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1569
	 * be translated by the translators, we 'force' it into the
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1570
	 * binary and 'load' it via a BindCString. To do this
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1571
	 * properly we have to set the color of the string,
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1572
	 * otherwise we end up with a lot of artefacts. The color
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1573
	 * 'character' might change in the future, so for safety
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1574
	 * we just Utf8 Encode it into the string, which takes
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1575
	 * exactly three characters, so it replaces the "XXX" with
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1576
	 * the color marker.
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1577
	 */
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1578
	if (_dynlang.text_dir != TD_LTR) {
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1579
		static char *err_str = strdup("XXXThis version of OpenTTD does not support right-to-left languages. Recompile with icu enabled.");
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1580
		Utf8Encode(err_str, SCC_YELLOW);
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1581
		SetDParamStr(0, err_str);
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1582
		ShowErrorMessage(INVALID_STRING_ID, STR_JUST_RAW_STRING, 0, 0);
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1583
	}
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1584
#endif
77b68778b102 (svn r14480) -Add: warning when trying to use a right-to-left language without support for it in OpenTTD.
rubidium
parents: 10209
diff changeset
  1585
8085
5b58f6315fb8 (svn r11646) -Codechange: check whether (some) characters are missing in the current 'font' for the 'currently' chosen language and give a warning when that does happen.
rubidium
parents: 7954
diff changeset
  1586
}
8987
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1587
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1588
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1589
/* --- Handling of saving/loading string IDs from old savegames --- */
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1590
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1591
/**
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1592
 * Remap a string ID from the old format to the new format
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1593
 * @param s StringID that requires remapping
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1594
 * @return translated ID
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1595
 */
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1596
StringID RemapOldStringID(StringID s)
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1597
{
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1598
	switch (s) {
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1599
		case 0x0006: return STR_SV_EMPTY;
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1600
		case 0x7000: return STR_SV_UNNAMED;
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1601
		case 0x70E4: return SPECSTR_PLAYERNAME_ENGLISH;
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1602
		case 0x70E9: return SPECSTR_PLAYERNAME_ENGLISH;
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1603
		case 0x8864: return STR_SV_TRAIN_NAME;
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1604
		case 0x902B: return STR_SV_ROADVEH_NAME;
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1605
		case 0x9830: return STR_SV_SHIP_NAME;
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1606
		case 0xA02F: return STR_SV_AIRCRAFT_NAME;
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1607
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1608
		default:
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1609
			if (IsInsideMM(s, 0x300F, 0x3030)) {
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1610
				return s - 0x300F + STR_SV_STNAME;
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1611
			} else {
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1612
				return s;
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1613
			}
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1614
	}
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1615
}
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1616
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1617
/** Location to load the old names to. */
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1618
char *_old_name_array = NULL;
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1619
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1620
/**
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1621
 * Copy and convert old custom names to UTF-8.
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1622
 * They were all stored in a 512 by 32 long string array and are
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1623
 * now stored with stations, waypoints and other places with names.
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1624
 * @param id the StringID of the custom name to clone.
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1625
 * @return the clones custom name.
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1626
 */
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1627
char *CopyFromOldName(StringID id)
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1628
{
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1629
	/* Is this name an (old) custom name? */
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1630
	if (GB(id, 11, 5) != 15) return NULL;
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1631
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1632
	if (CheckSavegameVersion(37)) {
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1633
		/* Old names were 32 characters long, so 128 characters should be
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1634
		 * plenty to allow for expansion when converted to UTF-8. */
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1635
		char tmp[128];
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1636
		const char *strfrom = &_old_name_array[32 * GB(id, 0, 9)];
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1637
		char *strto = tmp;
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1638
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1639
		for (; *strfrom != '\0'; strfrom++) {
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1640
			WChar c = (byte)*strfrom;
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1641
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1642
			/* Map from non-ISO8859-15 characters to UTF-8. */
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1643
			switch (c) {
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1644
				case 0xA4: c = 0x20AC; break; // Euro
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1645
				case 0xA6: c = 0x0160; break; // S with caron
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1646
				case 0xA8: c = 0x0161; break; // s with caron
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1647
				case 0xB4: c = 0x017D; break; // Z with caron
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1648
				case 0xB8: c = 0x017E; break; // z with caron
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1649
				case 0xBC: c = 0x0152; break; // OE ligature
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1650
				case 0xBD: c = 0x0153; break; // oe ligature
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1651
				case 0xBE: c = 0x0178; break; // Y with diaresis
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1652
				default: break;
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1653
			}
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1654
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1655
			/* Check character will fit into our buffer. */
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1656
			if (strto + Utf8CharLen(c) > lastof(tmp)) break;
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1657
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1658
			strto += Utf8Encode(strto, c);
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1659
		}
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1660
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1661
		/* Terminate the new string and copy it back to the name array */
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1662
		*strto = '\0';
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1663
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1664
		return strdup(tmp);
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1665
	} else {
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1666
		/* Name will already be in UTF-8. */
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1667
		return strdup(&_old_name_array[32 * GB(id, 0, 9)]);
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1668
	}
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1669
}
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1670
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1671
/**
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1672
 * Free the memory of the old names array.
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1673
 * Should be called once the old names have all been converted.
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1674
 */
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1675
void ResetOldNames()
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1676
{
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1677
	free(_old_name_array);
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1678
	_old_name_array = NULL;
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1679
}
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1680
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1681
/**
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1682
 * Initialize the old names table memory.
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1683
 */
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1684
void InitializeOldNames()
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1685
{
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1686
	free(_old_name_array);
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1687
	_old_name_array = CallocT<char>(512 * 32);
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1688
}
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1689
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1690
static void Load_NAME()
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1691
{
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1692
	int index;
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1693
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1694
	while ((index = SlIterateArray()) != -1) {
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1695
		SlArray(&_old_name_array[32 * index], SlGetFieldLength(), SLE_UINT8);
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1696
	}
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1697
}
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1698
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1699
extern const ChunkHandler _name_chunk_handlers[] = {
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1700
	{ 'NAME', NULL, Load_NAME, CH_ARRAY | CH_LAST},
80d22b9c2a0c (svn r12782) -Codechange: remove some functions from functions.h and do not statically 'waste' memory when the old name array is not needed anymore.
rubidium
parents: 8969
diff changeset
  1701
};